Skip to content
This repository was archived by the owner on Sep 10, 2026. It is now read-only.

v0.1.4: Better syntax!

Choose a tag to compare

@bczsalba bczsalba released this 04 Aug 12:41
· 1219 commits to master since this release

Overview:

This version brings some great improvements for creating Widget-s, along with some utilities.

  • Improve method auto(): Better conversions & implicit calling by Container
  • Rewrite method WindowManager.run(): More modular, has better performance & stability
  • New method WindowManager.bind(key, action): Assign a callback for a keypress
  • New feature setting arbitrary attributes in Widget construction

Details:

auto()

  • Implicit calling whenever a non-widget is added to a Container (or subclass, as long as its _add_widget() method is not overwritten)
  • Better conversions:
    "text" -> Label("text")
    ["label", lambda target, button: ...] -> Button(label="label", onclick=lambda target, button: ...)
    ("Any", ["widget"], ...) -> Splitter(Label("Any"), Button("widget", onclick=None), ...)
  • Note: There are some additional conversion models, but they are likely to change in the next release.

WindowManager.bind(key, action)

  • key - str: The trigger key
  • action - Callable[[WindowManager], Any]: The method to be called
  • Note: If the WindowManager could find & execute a binding it assumes the key to be handled, and does not do any built-in handling.

Arbitrary attribute setting for Widget

  • Widget is now passed **attrs on construction
  • All of these attributes are applied using setattr(), regardless of their respective fields
  • These changes should be integrated into custom Widget subclasses:
class MyWidget(Widget):
    def __init__(self) -> None:
        super().__init__()

⬇️

class MyWidget(Widget):
    def __init__(self, **attrs: Any) -> None:
        super().__init__(**attrs)

End result

All of this combined results in the syntax for creating a simple window going from:

root = Window()
root.forced_width = 50
root.id = "root"

root += Label("[157 italic]This is a title")
root += Label()
root += Button("Exit", lambda *_: sys.exit()]

To:

root = (
    Window(forced_width=50, id="root")
    + "[157 italic]This is a title"
    + ""
    + ["Exit", lambda *_: sys.exit()]
)

Do note, however, that the traditional syntax is still available. For more information on this version, check out the linked commit.

ok, bye 🚀