Tk Widgets

Several modules provide Tk widgets for an application’s user interface. They fit with the rest of the library – the attribute editor edits Attributes, and the terminal runs Commands – but can be used on their own.

The terminal

util.terminal gives an application a command line:

TerminalWidget

A Tk text widget that behaves like a terminal: a prompt, typed lines (with a history), and output. Each line typed is handed to an onLine callback – eg: a TopCommandParser’s parseLine() – and the result printed.

PlainTextTerminal

The same, on the real console: a read-evaluate-print loop.

TerminalRegistry, installGlobalIORouting()

An application with several windows, each with its own terminal, wants each window’s output to go to its terminal. Installed once, the routing sends print() output, stderr, logging and input() to the terminal of whichever window is active; inputAsync() asks for input without blocking the GUI.

The attribute editor

util.attributeEditor edits an AttributedObject’s attributes in a dialog. Each attribute gets a row – its name (with its note as a tooltip), its value, its type and its inheritance restrictions – and each value an editor to suit its type: a checkbox for a bool, a colour swatch (opening the system’s colour chooser) for a color, a menu for choices[...], a list editor for a list[str] (see below), a text box for text, other lists and dicts, and an entry otherwise.

A list[str] – a list of strings, in order – is edited with a ListEditor: its items in a list box, with Add…, Remove, and ▲/▼ to move the selected item (the order may matter: eg: models are searched in order). Double-click an item to edit it. By default Add… asks for a string; the editor’s listItemMakers gives it something else per attribute – eg: a file chooser. HierarchicalAttrEditor also shows the values each attribute inherits, greyed, above its own. Attributes can be added and deleted, and their types and restrictions changed. Each has a note button, which opens its note (its description, also shown as its name’s tooltip) in a small pop-up editor.

Attributes whose names have a “/” in them are grouped like folders (see treeOrder()): eg: gui/label and gui/colors/fill go under a gui group, the latter in a colors group inside it. Each group has a grey header line with a triangle that collapses or expands it (the collapsed groups are remembered for the next editor), and each attribute is labelled with just the last part of its name, indented under its group. Names without a “/” come first. Attributes the program uses for itself are hidden from the editor by starting their name – or the name of a group they’re in – with “.” (see isHiddenKey()): eg: .openWindows, gui/.cache, or everything in .internal/.

Columns can be left out with hideColumns – any of "type", "qualifiers" (the restrictions, in a HierarchicalAttrEditor), "note" and "actions" (see HIDEABLE_COLUMNS): eg: preferences, whose types and restrictions are fixed and whose notes are documentation, show just their names and values (the notes are still their names’ tooltips).

editAttrsBox() returns the edits (for the caller to apply – eg: as an undoable command); applyEditAttrsBox() applies them itself (eg: for preferences).

Dialogs and tooltips

ActionDialog

A pop-up that renders a small subset of HTML – bold, italic, underline, line breaks, lists – with links that run actions. ErrorReportingObject, a mix-in for objects that check themselves, uses it to show a validation report whose entries offer to fix the problems they describe.

CreateToolTip

A tooltip for a widget – or for one item on a canvas. Its text can be a function, so it’s worked out when it’s shown; it appears after a delay, and can be given a font (eg: a fixed-width one, to line up a table).

RTValueDialog

A dialog of sliders, each described by a Param, for adjusting a running program’s parameters. (It needs matplotlib.)