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:
AttrMap
Virtual widget class for editing option values.
- Parameters
widget¶ –
urwid.Widget
toattr_map¶ –
dict
orstr
forurwid.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 areurwid
examples 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:
MesonEdit
MesonEdit
widget to modifyOption
of typeSTRING
. Usesurwid.Edit
as base.- Parameters
- activated
bool
that 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
activated
member, which is toggled whenenter
is pressed. If theactivated
isTrue
, keypresses are forwarded to the containing widget (urwid.Edit
). Additionally, when theactivated
member is changed fromTrue
toFalse
, achanged
signal is emitted. Ifactivated
isFalse
,key
is returned. This tellsurwid
that it is not used by the widget.
- class mmeson.tui.BooleanEdit(init_state: bool)
Bases:
MesonEdit
MesonEdit
widget to modifyOption
of typeBOOLEAN
. Usesurwid.SelectableIcon
as base.- set_state(state: bool) None
Set a new state, change color of the
urwid.AttrMap
and emit achanged
signal.
- keypress(size, key)
Keypress handler for this widget. Taken from
urwid.CheckBox
.
- class mmeson.tui.ComboEdit(init_choice: str, choices: list[str])
Bases:
MesonEdit
MesonEdit
widget to modifyOption
of typeCOMBO
. Usesurwid.SelectableIcon
as 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
,disabled
andfalse
the color is defined inPALETTE
, for other choices use thechoice
color defined inPALETTE
.
- set_choice(choice_index: int) None
Set a new choice, change color of the
urwid.AttrMap
and emit achanged
signal.- Parameters
choice_index¶ –
int
new choice index forchoice_index
.
- keypress(size, key)
Keypress handler for this widget. Same as
BooleanEdit.keypress()
.
- class mmeson.tui.IntegerEdit(value: int)
Bases:
MesonEdit
MesonEdit
widget to modifyOption
of typeINTEGER
. Usesurwid.IntEdit
as 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:
StringEdit
MesonEdit
widget to modifyOption
of typeARRAY
. UsesStringEdit
as base.- Parameters
value¶ – Initial value of the widget.
- class mmeson.tui.OptionRow(option: Option)
Bases:
Columns
Widget for a single row in the
OptionList
, consiting of a urwid.Text widget on the left (40% width) and aMesonEdit
widget on the right (60% width).- changed
bool
that will be set toTrue
inset_changed()
.
- name_widget
urwid.Text
containing the option name on the left.
- build_value_widget(option: Option) MesonEdit
Build the corresponding
MesonEdit
subclass depending in the option type.
- get_value()
- Returns
Value of the widget (in the option’s type).
- class mmeson.tui.OptionList
Bases:
ListBox
Body of the main frame.
urwid.ListBox
containing aOptionRow
for everyOption
.- walker
urwid.SimpleFocusListWalker
managing the focusing of the contained widgets.
- build_option_rows() list[mmeson.tui.OptionRow]
Creates an
OptionRow
for everyOption
from theOptionsManager
and connects theirchanged
signal toentry_modified_callback()
with the widget and index as arguments.
- focus_modified_callback() None
Callback for the
modified
signal fromwalker
. Forwards the signal asfocus-modified
signal with the index of the currently focusedOptionRow
.
- entry_modified_callback(option_row: OptionRow, option_index: int) None
Callback for the
changed
signal from anOptionRow
. Sets theOption
as modified in theOptionsManager
with the new value viaMesonEdit.get_value()
.
- class mmeson.tui.Header(project_name: str, project_version: str, meson_version: str)
Bases:
Text
Header of the main frame.
urwid.Text
containing the project name, version and the Meson version used to configure the project.
Bases:
Pile
Footer of the main frame.
urwid.Pile
a one line divider, a three line info text and a single line help text containing the keyboard controls. The third line of thetext_info
is only filled when choices are available.urwid.Text
containing 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.MainLoop
object. After the loop exists, it run theExitAction
from theMesonManager
.- Parameters
top_level_widget¶ – top-level urwid widget for the
urwid.MainLoop
object.- Returns
Exit code from
run_exit_action()
.