Advanced Usage

Dictionary Descriptions

Building Atomically From Text Descriptions

Registering Item Classes

Callbacks

When an item allows a callback to be assigned, the callback can be defined in three ways:

Give the function/method.

This is the classic vanilla way of defining a callback. It s simple and # direct, but makes code less portable.

class ExampleController(ezui.WindowController):

    def build(self):
        buttonDescription = dict(
            type="PushButton",
            text="Example",
            callback=self.exampleCallback
        )
        # Now do the rest of the building...

    def exampleCallback(self, sender):
        print("The button was pushed.")

Give the name of the function/method.

This allows you to define the function/method without linking to it.

class ExampleController(ezui.WindowController):

    def build(self):
        buttonDescription = dict(
            type="PushButton",
            text="Example",
            callback="exampleCallback"
        )
        # Now do the rest of the building...

    def exampleCallback(self, sender):
        print("The button was pushed.")

Working with Vanilla

If you need something from vanilla that is not available in ezui, you can easily incorporate vanilla objects with ezui. In fact, ezui items are vanilla objects with ezui handling the cumbersome setup process of the vanilla objects for you. To do this, instantiate the vanilla object with "auto" as the posSize value and then use it as you would an instantiated ezui object.

import vanilla
import ezui

class Demo(ezui.WindowController):

    def build(self):
        self.datePicker = vanilla.DatePicker(
            posSize="auto",
            mode="graphical",
            timeDisplay=None,
            callback=self.datePickerCallback
        )
        datePickerDescription = dict(
            identifier="datePicker",
            item=self.datePicker
        )
        buttonDescription = "(Set Date) @setDateButton"
        stackDescription = dict(
            type="VerticalStack",
            contentDescriptions=[
                datePickerDescription,
                buttonDescription
            ]
        )
        windowDescription = dict(
            type="Window",
            title="Demo",
            contentDescription=stackDescription
        )
        self.w = ezui.makeItem(
            windowDescription,
            controller=self
        )

    def started(self):
        self.w.open()

    def datePickerCallback(self, sender):
        print("Picked date:", sender.get())

    def setDateButtonCallback(self, sender):
        date = self.datePicker.get()
        print("Set date:", date)

Demo()