mmeson.tui module
Module implementing the urwid TUI (terminal user interface).
If you are unfamilir with urwid, take a look at the excellent documentation at http://urwid.org/.
The basic design consits of a urwid.Frame with Header as header and Footer as footer. The
body consits of OptionList, which is a urwid.ListBox containing the OptionRow widgets. The
urwid.ListBox widget requires a urwid.SimpleFocusListWalker, which emits a modified signal when
the focused OptionRow changes. This is used to update the information in the Footer.
The OptionRow is a urwid.Columns with a urwid.Text showing the option name on the left and
a custom MesonEdit widget on the to change the option value.
Currently, the MesonEdit class is a subclass of urwid.AttrMap to force the colored output, but this
is a just an ugly workaround, in theory using TextMarkup (http://urwid.org/manual/displayattributes.html#text-markup)
should suffice.
- mmeson.tui.PALETTE = [('true', 'dark green', ''), ('false', 'dark red', ''), ('choice', 'light blue', ''), ('enabled', 'dark green', ''), ('disabled', 'dark red', ''), ('string', 'yellow', ''), ('integer', 'light magenta', ''), ('array', 'brown', '')]
Color Palette, see urwid’s manual for details.
- class mmeson.tui.MesonEdit(widget: Widget, attr_map: dict)
Bases:
AttrMapVirtual widget class for editing option values.
- Parameters
widget¶ –
urwid.Widgettoattr_map¶ –
dictorstrforurwid.AttrMap. Workaround to change the color of the widget.
- attr_map_from_str(color_name: str)
Creates an attribute map from a string to color the widget in a given color from
PALETTE. This is a workaround to get colors working, there areurwidexamples that do not need this for colored widgets.
- get_value()
Virtual function to return the value contained in the widget.
- class mmeson.tui.StringEdit(value: str, widget_color_name: str = 'string')
Bases:
MesonEditMesonEditwidget to modifyOptionof typeSTRING. Usesurwid.Editas base.- Parameters
- activated
boolthat control whether input is used for editing or not. Seekeypress().
- keypress(size, key)
Keypress handler for this widget.
The widget needs to be activated to forward keypresses. This is handled via the
activatedmember, which is toggled whenenteris pressed. If theactivatedisTrue, keypresses are forwarded to the containing widget (urwid.Edit). Additionally, when theactivatedmember is changed fromTruetoFalse, achangedsignal is emitted. IfactivatedisFalse,keyis returned. This tellsurwidthat it is not used by the widget.
- class mmeson.tui.BooleanEdit(init_state: bool)
Bases:
MesonEditMesonEditwidget to modifyOptionof typeBOOLEAN. Usesurwid.SelectableIconas base.- set_state(state: bool) None
Set a new state, change color of the
urwid.AttrMapand emit achangedsignal.
- keypress(size, key)
Keypress handler for this widget. Taken from
urwid.CheckBox.
- class mmeson.tui.ComboEdit(init_choice: str, choices: list[str])
Bases:
MesonEditMesonEditwidget to modifyOptionof typeCOMBO. Usesurwid.SelectableIconas base.- Parameters
init_choice¶ – Value used for the initial value of
choice_index.choices¶ – List of valid choices.
- choices
List of valid choices.
- create_attr_map(choice: str) dict
Creates an attribute map for the widget. Workaround to adjust the color of the widget depending on the choice. For
enabled,true,disabledandfalsethe color is defined inPALETTE, for other choices use thechoicecolor defined inPALETTE.
- set_choice(choice_index: int) None
Set a new choice, change color of the
urwid.AttrMapand emit achangedsignal.- Parameters
choice_index¶ –
intnew choice index forchoice_index.
- keypress(size, key)
Keypress handler for this widget. Same as
BooleanEdit.keypress().
- class mmeson.tui.IntegerEdit(value: int)
Bases:
MesonEditMesonEditwidget to modifyOptionof typeINTEGER. Usesurwid.IntEditas base.- Parameters
value¶ – Initial value of the widget.
- activated
See
StringEdit.activated.
- keypress(size, key)
Keypress handler for this widget. Similar to
StringEdit.keypress().
- class mmeson.tui.ArrayEdit(value: list[str])
Bases:
StringEditMesonEditwidget to modifyOptionof typeARRAY. UsesStringEditas base.- Parameters
value¶ – Initial value of the widget.
- class mmeson.tui.OptionRow(option: Option)
Bases:
ColumnsWidget for a single row in the
OptionList, consiting of a urwid.Text widget on the left (40% width) and aMesonEditwidget on the right (60% width).- changed
boolthat will be set toTrueinset_changed().
- name_widget
urwid.Textcontaining the option name on the left.
- build_value_widget(option: Option) MesonEdit
Build the corresponding
MesonEditsubclass depending in the option type.
- get_value()
- Returns
Value of the widget (in the option’s type).
- class mmeson.tui.OptionList
Bases:
ListBoxBody of the main frame.
urwid.ListBoxcontaining aOptionRowfor everyOption.- walker
urwid.SimpleFocusListWalkermanaging the focusing of the contained widgets.
- build_option_rows() list[mmeson.tui.OptionRow]
Creates an
OptionRowfor everyOptionfrom theOptionsManagerand connects theirchangedsignal toentry_modified_callback()with the widget and index as arguments.
- focus_modified_callback() None
Callback for the
modifiedsignal fromwalker. Forwards the signal asfocus-modifiedsignal with the index of the currently focusedOptionRow.
- entry_modified_callback(option_row: OptionRow, option_index: int) None
Callback for the
changedsignal from anOptionRow. Sets theOptionas modified in theOptionsManagerwith the new value viaMesonEdit.get_value().
- class mmeson.tui.Header(project_name: str, project_version: str, meson_version: str)
Bases:
TextHeader of the main frame.
urwid.Textcontaining the project name, version and the Meson version used to configure the project.
Bases:
PileFooter of the main frame.
urwid.Pilea one line divider, a three line info text and a single line help text containing the keyboard controls. The third line of thetext_infois only filled when choices are available.urwid.Textcontaining the option meta info (seeoption_list_callback()).
Callback changing the option meta information in the footer.
- Parameters
option_index¶ – index of the option for the
OptionsManager.
- mmeson.tui.build_ui(project_name: str, project_version: str, meson_version: str) Widget
Build the TUI tree and returns the top-level widget.
- mmeson.tui.global_key_handler(key: str) None
Global key handler for unhandled key presses.
- Parameters
key¶ – key name (given from
urwid).
- mmeson.tui.main_loop(top_level_widget: Widget) int
Creates and runs the
urwid.MainLoopobject. After the loop exists, it run theExitActionfrom theMesonManager.- Parameters
top_level_widget¶ – top-level urwid widget for the
urwid.MainLoopobject.- Returns
Exit code from
run_exit_action().