pypi PyTermGUI 0.2.0
v0.2.0: The Widget update!

latest releases: 7.8.1, 7.8.0, 7.7.4...
5 years ago

Overview:

This version primarily focuses on improving the included Widget subclasses and their interactions

  • New module: pytermgui.widgets.buttons to store all the Button subclasses

    • Button(Widget) : Same as before
    • Checkbox(Button) : A button with a checked and unchecked state, and toggles between them
    • Toggle(Button) : A button that toggles between two labels
    • Dropdown(Container) : Essentially a proof of concept. Will need support for printing lines at custom locations as overlays.
  • Rewrite Splitter:

    • Increase stability
    • Fix various spacing issues
    • Properly inherit from Container
    • 2 new auto() structures
    • Note: Currently Splitter-s only really work with widgets of the same height. Check below for more info.
  • Rewrite InputField:

    • Inherit from Label, use its get_lines()
    • Support keybinding (more info below)
    • Rework styles, support full line styles
  • Rewrite pytermgui.cmd:

    • Use WindowManager with a custom Application framework
    • Implement old utilities as Application subclasses
    • Support launching a specific app and dumping its output, as well as running as long as the User wants it to
  • Remove unmaintained widgets:

    • Some, like ProgressBar will come back in the future.

Details:

Widget.bind(key, action, description)

Assign an action and a description to a dictionary of bindings, which is called by Widget._execute_binding(key).

  • key: str - The key that activates the binding
  • action: Callable[[Widget, str], Any] - The function that gets called
  • description: Optional[str] - Description of the binding
  • WindowManager implements & handles this, but otherwise the user should implement it.

Splitter()

  • The auto() method now takes two new forms to create a Splitter()

    • {left: right} -> What used to be Prompt, run auto() on both sides and align them to the outside
    • (item1, item2, item3, ...) -> Shorthand for Splitter(item1, item2, item3, ...)
  • For now, you should use line lists of equal length to display multi-length Widget-s in Splitter.

  • As such, the itertools.zip_longest method is really useful for creating Splitter-s:

    from itertools import zip_longest
    from pytermgui import Container, Splitter
    
    left = ["one", "two", "three"]
    right = ["one", "two", "three", "four", "five"]
    
    container = (
        Container()
        + Splitter(
            *[{lhs: rhs for lhs, rhs in zip_longest(left, right, fillvalue="")]
        )
    )

cmd.py rewrite

  • A cleaner implementation, including a whole Application framework
  • Better cli:
    • ptg -> open WindowManager with all the utilities, exit on CTRL_C
    • ptg --app {MarkApp, Getch} -> launch either of the utilities, dump their output once input has finished

End result

Combining all of the aforementioned changes, this is how ptg looks at the moment:

end result

ok, bye. 🚀

Don't miss a new PyTermGUI release

NewReleases is sending notifications on new releases.