Changelog¶
All notable changes to this project are documented in this file. The format follows Keep a Changelog 1.1.0, and the project follows Semantic Versioning. The Versions and compatibility page says what counts as the public API.
Every user-facing pull request adds one entry under [Unreleased], below the matching heading: ### Breaking, ### Added,
### Changed, ### Fixed, ### Removed, ### Deprecated or ### Security. ### Breaking comes first, and a minor release before 1.0
that breaks the public API lists the break there. A release section is named ## [X.Y.Z] - YYYY-MM-DD; release candidates get no section
of their own.
Unreleased¶
Added¶
StoryContext.log_signals(obj, exclude=...)logs every signal that the object's classes declare (belowQWidgetfor a widget) in the Actions panel.pyside6-storybook --debug-infoprints the versions of pyside6-storybook, PySide6, Qt, Python and the platform for a bug report.- Version policy: the documentation page Versions and compatibility says what the public API is, what a minor and a patch release before
1.0 may change, and which Python and PySide6 versions are supported.
RELEASING.mddescribes how a release is made. The changelog header states the format, and### Breakingis the first heading of a release that breaks the public API. - Documentation site (Zensical, with Material's classic look, and mkdocstrings) at https://youth-research-center.github.io/pyside6-storybook/: a home
page, a page for each part of the guide (writing stories, controls, finding stories, the command line, the gallery, themes, testing stories and
troubleshooting), the API reference generated from the docstrings, the changelog and the roadmap. The README is now a short front page that
links to them. The
docsdependency group installs the generator;docs.ymlbuilds it withzensical build --strictand deploys it to GitHub Pages frommain. - PyPI metadata: the licence files (
LICENSE,THIRD_PARTY_NOTICES.md), authors, keywords, classifiers (Python 3.11 to 3.14, Pytest, Typed) and the project URLs (homepage, documentation, repository, issues, changelog). The sdist has an explicit include list: the package, the tests with the workflows they read, the docs and the scripts, withoutdocs/specs/and.github/dependabot.yml. - Screenshot snapshots:
pytest --storybook-snapshots(inistorybook_snapshots) addsstorybook::<id>[<theme>-snapshot]for every story and theme, which compares a screenshot of the rendered story with the baselinetests/storybook_snapshots/<platform>/<id with / as __>[<theme>].png.--storybook-update-snapshotswrites or replaces the baselines; a missing baseline fails and is never created silently. A mismatch (another size, or more differing pixels thanstorybook_snapshot_max_diff, where a pixel differs when a channel differs by more thanstorybook_snapshot_tolerance) writes the actual and diff images tostorybook-snapshot-failures/<platform>/and names them.storybook_snapshot_dirandstorybook_snapshot_failuresmove the folders.checks_ignoreaccepts"snapshot". See Screenshot snapshots in the Testing stories page of the documentation. - Text contrast check:
pyside6_storybook.checks.check_text_contrast(widget, *, normal=4.5, large=3.0, include_disabled=False)renders a shown widget and returns aCheckIssuefor each text (labels, buttons, line edits, spin boxes, combo boxes and items of item views) whose contrast against its background, measured on the pixels, is below 4.5:1 (3:1 for large text).pytest --storybook-a11yruns it asstorybook::<id>[<theme>-contrast]for every story and theme;--storybook-no-contrast(inistorybook_contrast = false) turns it off,storybook_contrast_normalandstorybook_contrast_largeset the ratios, and--storybook-contrast-disabled(inistorybook_contrast_disabled) includes disabled widgets.checks_ignoreaccepts"contrast". See Text contrast in the Testing stories page of the documentation. - Accessibility checks:
pyside6_storybook.checkshascheck_accessible_names(widget)andcheck_keyboard_focus(widget), which return aCheckIssue(rule,widget_class,object_name,path,message) for each control without an accessible name or without Tab focus.pytest --storybook-a11y(inistorybook_a11y) runs them on every story asstorybook::<id>[a11y-name]andstorybook::<id>[a11y-focus].story(),StoryRegistry.story(),StoryandStory.variant()takechecks_ignore, a mapping from a rule ("name"or"focus") to the reason the story opts out; the test is skipped with that reason, and a variant inherits it. - pytest plugin: install the
pytestextra (pyside6-storybook[pytest], which addspytestandpytest-qt) and runpytest --storybook(or setstorybook = true) to render every story in every theme as one test,storybook::<story id>[<theme>], which fails when the story or a decorator raises (with the story's own traceback, also from apaintEventor a slot, with or without pytest-qt), the story returns no widget, the theme provider fails, or Qt logs a warning (--storybook-qt-warnings,storybook_qt_warnings_ignore;propagateSizeHintsis ignored by default). A story file that fails to import, or was imported before collection so its stories cannot be tested, is a failingstorybook::load-error[...]test, a provider or theme that cannot be used is a failingstorybook::configurationtest, and a project without configured stories is a usage error instead of testing the built-in examples. Options and ini keys:--storybook-stories,--storybook-theme-provider,--storybook-themes. The tests carry thestorybookmarker and work with-k,--deselect,--lfand pytest-xdist. The newrender_story(story_id, *, args=None, theme=None)fixture renders a story by id in a test you write yourself. The plugin imports neither Qt nor the library unless it is enabled, and an option that only shapes the story tests is a usage error while it is off (#94).StorySourceshas the keyword-onlyfallback, true for the built-in examples fallback. See Testing stories in the documentation. - Theming guide (now the Themes page of the documentation,
docs/themes.md), with two screenshots (rendered byscripts/docs/render_theming_images.py), and the worked exampleexamples/themed_app: an application with two themes, a pill button, a token-painted gauge and aThemeProviderfor them. Run it from its folder withuv run --project ../.. pyside6-storybook. - Choosing a theme provider:
--theme-provider module:attributeon the command line, ortheme_provider = "module:attribute"in[tool.pyside6-storybook], loads an application's ownThemeProvider(an instance, a class or a no-argument function; the attribute may be dotted), andthemeinpyproject.tomlchooses the starting theme like--theme. The command line wins. The provider is loaded before the stories, an error in it or an unknown theme exits with code 1 and never falls back to the built-in themes, and--listnames the provider and its themes on standard error without activating it. A reload keeps the provider's modules (and those it imports inactivate) instead of re-importing them, so the stories and the provider share the application's theme manager; restart the gallery after editing the provider. - System theme:
BuiltinThemeProviderhas a third theme, System, which restores the style, palette and style sheet the application had when the gallery started and lets the colour scheme follow the operating system (unless the application forced one), including a change while the gallery runs.Ctrl+Tcycles Light, Dark, System.StoryContext.color_scheme(aQt.ColorScheme,Unknownby default) tells a story whether the theme is light or dark; a provider supplies it with an optionalcolor_scheme()method, and the gallery guesses from the application palette without one. On the offscreen platform and where Qt has no colour-scheme setting, System is whatever Qt defaults to. - Design tokens:
StoryContext.tokensis a read-only mapping of the active theme's tokens, empty by default. A theme provider supplies it through an optionaltokens()method, which the gallery reads after activation and after every change notification (a provider without it, or one that raises, gives an empty mapping).BuiltinThemeProvider.tokens()returns twelve#rrggbbcolours read from the application palette (window,accent,borderand others), and the newDisplay/Token Badgeexample paints a widget from them. - Theme providers: the new
ThemeProviderprotocol lets an application supply its own themes to the gallery (theme_names,current_theme,activate,set_theme,on_changed,deactivate), andBuiltinThemeProvideris the default Light and Dark provider.run, which opens the gallery, is now exported from the package and takes the keyword-onlytheme_provider; it validatesthemeagainst the provider's names and logs a warning for each of the application's style, palette, style sheet and font that the provider did not restore. The theme switch lists the provider's names, and an exception from the provider is shown in the preview instead of closing the gallery. - Keyboard navigation and accessibility: Tab follows reading order (search, tree, preview tabs, canvas controls, the preview, then the
theme switch, the side tabs and the controls),
F6andShift+F6move between the three panes and return to the widget that had focus there,Ctrl+Alt+DownandCtrl+Alt+Upopen the next and previous story in the list, andCtrl+Tswitches to the next theme. A Help menu has "Keyboard shortcuts" (F1), a dialog that lists every shortcut of the window. The panes are named "Story list", "Preview" and "Controls and actions", and the preview area "Preview of". A rebuilt preview never takes focus from the control being edited, and when focus was inside the story's own widget it moves to the preview area. - Hot reload: the gallery loads the stories again when a story file or a module of the project changes, so an edit shows without a restart.
It drops the project's modules and loads the targets into a fresh registry; a reload that finds no story, or in which a source fails
that was not already failing, is rejected and leaves the previous stories in place, with the errors in the preview. After a good reload
the selected story (or the one now at its position) and its control values stay, a status bar shows "Reloaded HH:MM:SS" or "Reload
failed HH:MM:SS: ...", and
LoadResult.moduleslists a dotted-name target itself, including a package.--no-reloadturns it off, and--listnever reloads. - Actions panel: the side pane has "Controls" and "Actions" tabs. A story shows what happens to its widget with
ctx.log_signal(button.clicked)(the signal's name, orname=) orctx.log("name", *args); each emission is a row with the time, the action and its arguments (QPushButton.clickeddelivers none,valueChangeddelivers the value), newest first, at most 500 rows, with a Clear button and an "N actions logged" count that is announced to assistive technology. The log clears when another story is selected and stays when the same story is built again. Both methods do nothing under a plainStoryContext. New publicActionSink(the protocol behindStoryContext.actions), exported from the package;StoryContextgains the keyword-onlyactionsfield, which does not take part in equality orrepr. The push button and slider examples log their signals. - Zoom: buttons for zoom out, zoom in and reset in the canvas toolbar, with the level (50, 67, 100, 150, 200, 300 and 400%) between them,
the shortcuts
Ctrl++,Ctrl+=,Ctrl+-andCtrl+0while focus is in the preview pane, andCtrl+wheel, also over the story's own widgets. A level that would need more than 64 million pixels is skipped. At 100% the live widget is shown as before; at another level the preview is an image of the widget scaled without smoothing, which is not interactive, and a line says so. - Canvas controls: a Background menu (Window, Base, Alternate Base or Checkerboard) and a Size menu (Fit, Phone portrait 320 by 480,
Phone landscape 480 by 320, Dialog 800 by 600, the registry's presets, or a Custom width and height) above the preview. With a size
selected, the area a story is placed in is exactly that size, and the preview scrolls when it does not fit. The choices stay while
the story, the theme or the registry changes. New public
SizePreset(name, width, height), exported from the package, andStoryRegistry.size_presets, the list of presets the Size menu shows after the built-in sizes; the window reads it when it is built and inGalleryWindow.set_registry, and a size whose preset is gone returns to Fit. - The Docs tab: the preview pane has "Canvas" and "Docs" tabs. Docs shows the story module's and the story's docstrings, a table of the
controls (type, starting value, range or options), links to the stories of the same component, and the story's source with a Copy
button.
Story.functionis the callable the story was created with, as a read-only property. - The story list is a tree built from the story ids, with a search field that keeps the stories whose id contains the text, a
placeholder when nothing matches, and the shortcuts
Ctrl+Fand/that focus the search.GalleryWindow.select_story(story_id)opens a story, clearing the search if it hides the story, andGalleryWindow.set_registry(registry, *, load_errors=())shows another set of stories, keeping the selected story and its control values when it still exists. - Story decorators:
decorators=on@storyandStory.variant()takes functions that wrap the story's widget, the first one outermost (decorators=[padding(24), fixed_size(320, 200)]is a 320 by 200 widget inside 24 pixels of padding).StoryRegistry.decoratorswraps every story of a registry, outside the story's own, and a variant keeps its story's decorators unless it gives a list. The built-inspadding,frameandfixed_sizeare inpyside6_storybook.decorators, andDecoratoris exported from the package. A decorator that fails, or does not return a widget containing the widget it received, shows an error in the preview that names it.Storygainsdecorators, andGalleryWindow.current_preview_widget()still returns the story's own widget. The sign-in form example usespadding. - Preview layouts:
layout=on@storyandStory.variant()takes aLayout(CENTERED,PADDEDorFILL) or its string value, andStoryRegistry.default_layout(Layout.PADDEDby default) applies to stories that declare none; a variant keeps its story's layout unless it gives another. The preview scrolls a widget larger than the pane inPADDEDandCENTERED, andFILLgrows the widget with the pane.Layoutis exported from the package. Example stories show all three (Display/Tablefills the preview). ColorControl(a hex string default,alpha=Truefor#RRGGBBAA; the story receives aQColor),EnumControl(a Python or Qt enum member;optionslists the named members) andFileControl(the story receives aPath, orNonewhile empty;filter=is the Browse dialog's name filter), with editors in the gallery and example stories.- Story variants:
Story.variant(name, *, args=None)registers the same story with other starting values under the id<component>/<name>, andStorygainscomponent,variant_ofandargs(a read-only mapping).Story.default_args()uses a variant'sargs, and the gallery shows variants as stories of their own. - Control options:
labelanddescriptionon every control (the form label and the editor's tooltip and accessible description),TextControl(multiline=True),IntControl(step=..., slider=True)andFloatControl(step=..., decimals=..., slider=True). Every control also has a read-onlydisplay_label, acoerce(value)method that returns the value in the control's type or raisesValueErrororTypeErrornaming the control, andFloatControlhas the read-onlyeffective_step,effective_decimalsandslider_steps. - In the gallery, spin boxes, sliders and combo boxes only react to the mouse wheel while they have keyboard focus, and the controls pane scrolls when a story has many controls.
- Story model:
storydecorator,Story,StoryContext,StoryRegistry,default_registryand theTextControl,BoolControl,ChoiceControl,IntControlandFloatControlcontrols. - Gallery window with a story list, a preview, a theme switch and a controls panel.
- Built-in Light and Dark themes.
- The gallery shows a story that raises, or returns something that is not a widget, as an error in the preview with its traceback
(starting at the story's own code) instead of failing, and lists story sources that failed to load under a "Load errors" entry.
run()and the command line pass the load errors to it. load_storiesimports story modules from folders (*_story.pyand*_stories.pyfiles), single files and dotted module names, and returns aLoadResultwith the registry, the loaded modules and aLoadErrorfor each source that failed.LoadError.target_errortells a target that does not exist apart from a story module that failed to import.pyside6-storybookcommand (alsopython -m pyside6_storybook):pyside6-storybook TARGET...opens the gallery with the stories in the given folders, files or modules;--listprints the story ids without opening a window, also without a display;--themepicks the starting theme. Story modules that fail to import are reported and the gallery opens with the rest; a target that does not exist, or no stories at all, exits with code 1.- Default story sources: run without targets,
pyside6-storybookloads thestorieslisted under[tool.pyside6-storybook]inpyproject.toml(with an optionalpythonpath), then the modules advertised by installed packages under thepyside6_storybook.storiesentry-point group, and only when neither is configured the built-in examples.--listsays on standard error which source it used. - Example stories built from stock Qt widgets (buttons, inputs, display widgets, the active palette and a small form), shown by
pyside6-storybook --examples.
Changed¶
- The Color Swatch example chooses black or white text against the swatch colour blended over the window colour, so its text reaches 4.5:1 for opaque and translucent colours in Light and Dark (the default colour measured 4.24:1 in Dark).
- The built-in examples set accessible names on the Line Edit, Spin Box, Double Spin Box, Combo Box, Slider and Table widgets, so they pass the accessibility checks.
--themeno longer limits its value with argparse: an unknown name prints an error and exits with code 1 (was 2) after the theme provider has loaded, and the valid names are the provider's.pythonpath,theme_providerandthemeinpyproject.tomlare read also when the command line names targets, so an invalidpyproject.tomlis an error then too (it was ignored).- The Light theme's
HighlightandAccentare#1F5FC4(was#2A6FDB). Fusion draws the focus ring in a colour derived fromHighlight, which was#5391EDand reached only 2.77:1 against the LightWindow; the ring is now#194C9D(7.2:1), and selected text on the highlight is 6.0:1. The Dark theme's ring was already above 3:1 and its colours are unchanged. - The Docs tab's controls table and source view get their height from their rows and lines instead of a fixed pixel height, so they follow the application font.
- The story list is no longer a flat list of ids: stories are grouped by the segments of their ids, and a component below the top level with a single story is shown as that story's row.
- The error panel shows a warning icon beside its title. The gallery now bundles Phosphor Icons (MIT) and tints them from the active palette, so the icon follows the theme.
- The example stories
Buttons/Push ButtonandInputs/Line Editare nowButtons/Push Button/DefaultandInputs/Line Edit/Default, each with variants. - A control's default must have the control's value type:
BoolControltakes only abool,IntControlanint(not abool),FloatControlanintorfloat(not abool),TextControlandChoiceControla string.Story.default_args()returns each default passed through the control'scoerce, so aFloatControldefault given as1starts as1.0. FloatControlrejects a default or bound that needs more than 10 decimals, which the editor used to show rounded.- The gallery's widgets are styleable from an application style sheet. Their object names now have the prefix
sbkin camel case (storySidebarissbkStorySidebar,previewSurfaceissbkPreviewSurface, and so on; the Themes page of the documentation lists all 53), so a style sheet or a test that looked a widget up by its old name must use the new one. The widgets that an application might style, and none that contain a story's widget, carry the propertysbkChrome, so*[sbkChrome="true"] QPushButtonreaches the gallery's buttons and not a story's. The selected story's text stays readable when a style sheet colours the selected row.
Fixed¶
- Calling
run()again in the same process with a theme provider that sets a style sheet crashed Qt:run()now deletes its window before the provider restores the application's look. - The package no longer installs PySide6 6.12.0 on Python 3.11. That release drops a reference to
None,TrueorFalseon many calls under Python 3.11, and a long session aborted the interpreter on exit ("none_dealloc"). Python 3.12 and newer still get 6.12.0. - The gallery could crash when the application style sheet was cleared and set again, for example by a theme that sets a style sheet: Qt crashes when a widget that was never shown is deleted after such a change. The gallery now polishes its widgets after building them, and the built-in themes polish every widget before they change the style sheet.
- Return and Enter in the story list did not open the selected story on macOS, where Qt's item views start editing on Return instead.
- Choosing the Custom canvas size, or zooming in, could make the window wider with wide fonts (the Windows default font grew it from 1100 to 1244 pixels): the Width and Height boxes now have a row of their own, and the zoom note wraps.
pyside6_storybook.app.runleft a Quit event posted when it returned, so every later event loop in the same process (a secondrun(), or a test's wait) stopped at once.- The Dark theme's input fields, unchecked check boxes and alternate table rows were almost invisible in the preview. The preview
surface now uses the window background, where a stock widget sits in an application, and the Dark palette separates
Window,BaseandAlternateBasefurther; the Light theme's alternate rows are a little stronger too.