Demo¶
The demo is one frameless window which holds every widget of zoo_pyside with its behaviour. It has two jobs:
a showcase for developers: pick a page in the sidebar, use the widgets and read the signals they emit in the event log under them,
the fixture of the widget tests: every page registers its widgets by name and every signal it logs is kept in
page.events, so a test drives the widget with theQTesthelpers ofzoo.libs.pyqt.testingand asserts on what happened.
Running the demo¶
In Maya use the Developer shelf button menu or Zoo Tools Pro > Developer > PySide Widget Demo (the
zoo.pyside.demo action of zoo_dev_utilities). From code, in any session where Zoo is running:
from zoo.libs.pyqt import demo
window = demo.show()
window.showPage("Push buttons")
Without Maya, with the Zoo environment on PYTHONPATH (the engine and the preferences are stubbed, the theme is the
real Zoo style sheet):
python -m zoo.libs.pyqt.demo
Running the tests¶
The pages are tested by tests/test_demo_*.py. They run offscreen with plain Python and in mayapy:
bin\run_unittests.bat --package zoo_pyside
bin\run_unittests.bat --package zoo_pyside --test tests.test_demo_buttons
tests/test_demo_coverage.py fails when a public class of widgets or extended is neither named in a page or
a demo test, nor listed in its NOT_DEMOED table with the reason it has no page of its own.
Adding a page¶
Create (or extend) a module in zoo/libs/pyqt/demo/pages, add its name to pages.MODULES and register a
DemoPage:
from zoo.libs.pyqt.demo.page import DemoPage, register
@register
class MyWidgetPage(DemoPage):
title = "My widget"
category = "Buttons"
description = "What the widget does and how to use it."
modules = ("mywidget",)
def build(self, layout):
widget = self.add("myWidget", MyWidget(), layout, "MyWidget")
self.connectLog("myWidget.clicked", widget.clicked)
and a test:
from zoo.libs.pyqt import testing
from zoo.libs.pyqt.demo.testcase import DemoPageTestCase
class TestMyWidget(DemoPageTestCase):
pageClass = MyWidgetPage
def test_clickEmitsClicked(self):
page = self.openPage()
testing.click(page.widget("myWidget"))
self.assertEqual(page.eventNames(), ["myWidget.clicked"])
The tests share one demo window: the first openPage() opens it and later tests reuse it, so a test run does not
open (and flash) a window per test. Each openPage() builds a new page in that window, and the page is deleted after
the test, so tests stay independent. The pages get the Zoo stylesheet of the window, as artists see them. openWindow()
returns the same window reset to its welcome text, for tests of the window itself.
Blocking popups (menus, dialogs, Zoo message boxes) are driven with testing.runWithPopup and
testing.runWithWindow. Pages which open windows or write files clean up through a method such as
closeWindows() or cleanup() which the test registers with self.addCleanup.
Pages¶
Module |
Shows |
|---|---|
|
push, styled, extended, aligned, icon menu and toggle buttons, radio groups |
|
line edits, string edits, sliders, spin boxes, text edits, labels |
|
combo boxes and the combo edit widget |
|
color buttons, the color popup and sliders |
|
collapsable frames, stacks, tabs, flow layouts, sliding widgets, resizers |
|
tree, list, table views, the view search widget |
|
the grouped tree with item widgets, groups and drag and drop |
|
path widgets and lists, breadcrumb, thumbnail widget |
|
the mini browser with a folder of generated thumbnails |
|
Zoo message boxes and dialogs |
|
expanded tooltips |
|
menus: searchable, extended, mouse button aware |
|
frameless windows, snapshot window, dialog and overlay, DPI scaling |
|
spinner, log output, menu actions, button list, main window and docks, layout helpers |
|
the source code editor |
|
the graphics view, backdrop, thumbnails, text, edges |
API¶
Demo window with every zoo_pyside widget: a showcase for developers and the fixture of the widget tests.
from zoo.libs.pyqt import demo
window = demo.show()
Standalone (no Maya): python -m zoo.libs.pyqt.demo
- show(parent=None)¶
Create and show the demo window
- Return type:
Page¶
The base class and registry of demo pages.
A page shows one family of widgets with their behaviour. It is a showcase for developers (read the build method
to learn how to use the widgets) and the fixture of the tests (find widgets by name with DemoPage.widget(),
assert on DemoPage.events).
- allPages()¶
Every registered page class, sorted by category then title
- class EventLog(*args, **kwargs)¶
Bases:
QPlainTextEditRead only log shown at the bottom of a page, one line per event
- class DemoPage(*args, **kwargs)¶
Bases:
QWidgetSubclass, set
titleandcategoryand implementbuild()@register class MyPage(DemoPage): title = "My widgets" category = "Buttons" description = "What is shown" def build(self, layout): button = self.add("button", QtWidgets.QPushButton("Click"), layout) self.connectLog("clicked", button.clicked)
- title = ''¶
sidebar entry, unique across pages
- category = ''¶
sidebar group
- description = ''¶
one or two sentences shown at the top of the page
- modules = ()¶
the zoo_pyside modules the page covers, used by the coverage test
- events¶
(name, args)for every logged signal
- build(layout)¶
Create the widgets and add them to
layout
- add(name, widget, layout=None, label=None)¶
Register
widgetundernameand add it to the layout, with an optional caption on its left
- register(name, obj)¶
Register a non widget object (model, action, layout) or an already placed widget by name
- Returns:
obj
Window¶
The demo window, a frameless ZooWindow which lists every demo page and shows the selected one.
- class DemoWindow(*args, **kwargs)¶
Bases:
ZooWindowShows every zoo_pyside widget, grouped in categories. Pages are built the first time they are shown.
from zoo.libs.pyqt import demo window = demo.show() window.showPage("Push buttons")
- currentTitle()¶
- Returns:
the shown page title, empty when the welcome text is shown
- Return type:
- page(title)¶
The page for
title, built on first use- Return type:
- Raises:
KeyError – for an unknown title
- showPage(title)¶
Select and show a page
- Return type:
- discardPage(title)¶
Remove and delete the built page for
title, the nextpage()call builds a new one. Shows the welcome text when the page was the shown one. Does nothing when the page isn’t built.
- discardAll()¶
Remove and delete every built page and show the welcome text
- showWidget(widget)¶
Show a widget which isn’t a registered page (ie. a page class made by a test) in the page area. Remove it with
removePageWidget().- Returns:
widget
- removePageWidget(widget)¶
Remove a widget from the page area and delete it, shows the welcome text when it was the shown one
- buildAll()¶
Build every page, returns them in sidebar order
- Return type:
- applyFilter(text)¶
Show only the pages whose title, category, description or module contains
text(case insensitive)
Test case¶
Base class for the demo page tests.
Every test shares one zoo.libs.pyqt.demo.window.DemoWindow, opened by the first test which needs it and
closed once the demo tests are done (or by closeSharedWindow()). Each test gets a newly built page in that window,
so tests stay independent without opening a window per test.
- PAGE_WIDTH = 900¶
the page area size the pages were written against
The demo window shared by the tests, created and shown on first use, shown again if a test hid it
- Return type:
Close and delete the shared demo window, the next
sharedWindow()call opens a new one
- class DemoPageTestCase(methodName='runTest')¶
Bases:
QtTestCaseopenPage(PageClass)builds the page in the shared demo window, shows it and returns it. The page is deleted after the test.- tearDown()¶
Closes and deletes the tracked widgets, then runs the event loop once
- openPage(pageClass=None)¶
- Return type:
- openWindow()¶
The shared demo window, reset: no filter, no built page, the welcome text shown
- Return type: