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 the QTest helpers of zoo.libs.pyqt.testing and 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

buttonpages

push, styled, extended, aligned, icon menu and toggle buttons, radio groups

inputpages

line edits, string edits, sliders, spin boxes, text edits, labels

combopages

combo boxes and the combo edit widget

colorpages

color buttons, the color popup and sliders

containerpages

collapsable frames, stacks, tabs, flow layouts, sliding widgets, resizers

viewpages

tree, list, table views, the view search widget

groupedtreepages

the grouped tree with item widgets, groups and drag and drop

pathpages

path widgets and lists, breadcrumb, thumbnail widget

browserpages

the mini browser with a folder of generated thumbnails

popuppages

Zoo message boxes and dialogs

tooltippages

expanded tooltips

menupages

menus: searchable, extended, mouse button aware

framelesspages

frameless windows, snapshot window, dialog and overlay, DPI scaling

miscpages

spinner, log output, menu actions, button list, main window and docks, layout helpers

editorpages

the source code editor

graphicspages

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:

zoo.libs.pyqt.demo.window.DemoWindow

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).

register(pageClass)

Class decorator which adds the page to the demo

Return type:

type(DemoPage)

allPages()

Every registered page class, sorted by category then title

Return type:

list[type(DemoPage)]

class EventLog(*args, **kwargs)

Bases: QPlainTextEdit

Read only log shown at the bottom of a page, one line per event

class DemoPage(*args, **kwargs)

Bases: QWidget

Subclass, set title and category and implement build()

@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 widget under name and add it to the layout, with an optional caption on its left

Parameters:
  • name (str) – unique on the page

  • label (str or None) – caption shown to the left of the widget

Returns:

the widget

register(name, obj)

Register a non widget object (model, action, layout) or an already placed widget by name

Returns:

obj

widget(name)
Raises:

KeyError – for an unknown name

widgetNames()
Return type:

list[str]

connectLog(name, signal)

Record every emission of signal in events and the on screen log

Parameters:

name (str) – label of the event

eventNames()
Return type:

list[str]

eventsNamed(name)
Returns:

the args of each event called name

Return type:

list[tuple]

Window

The demo window, a frameless ZooWindow which lists every demo page and shows the selected one.

class DemoWindow(*args, **kwargs)

Bases: ZooWindow

Shows 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")
pageChanged

alias of str

pageTitles()
Returns:

all page titles, in sidebar order

Return type:

list[str]

visiblePageTitles()
Returns:

the page titles the filter currently shows

Return type:

list[str]

currentTitle()
Returns:

the shown page title, empty when the welcome text is shown

Return type:

str

page(title)

The page for title, built on first use

Return type:

zoo.libs.pyqt.demo.page.DemoPage

Raises:

KeyError – for an unknown title

showPage(title)

Select and show a page

Return type:

zoo.libs.pyqt.demo.page.DemoPage

discardPage(title)

Remove and delete the built page for title, the next page() 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:

list[zoo.libs.pyqt.demo.page.DemoPage]

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

sharedWindow()

The demo window shared by the tests, created and shown on first use, shown again if a test hid it

Return type:

zoo.libs.pyqt.demo.window.DemoWindow

closeSharedWindow()

Close and delete the shared demo window, the next sharedWindow() call opens a new one

class DemoPageTestCase(methodName='runTest')

Bases: QtTestCase

openPage(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:

zoo.libs.pyqt.demo.page.DemoPage

openWindow()

The shared demo window, reset: no filter, no built page, the welcome text shown

Return type:

zoo.libs.pyqt.demo.window.DemoWindow