Settings
UI Settings
The UI behaviour might be modified via an settings object. This can be passed to the run function or defined through a config file. Settings defined in the config file have bigger priority. Every interface has its own settings object.
Passing the settings to the run
method:
from mininterface.settings import MininterfaceSettings
opt = MininterfaceSettings()
run(settings=opt)
Specifying only the GuiSettings:
from mininterface.settings import MininterfaceSettings, GuiSettings
opt = MininterfaceSettings(gui=GuiSettings(combobox_since=1))
run(settings=opt)
Config file special section
In a YAML config file, use a special section 'mininterface' to set up the UI. For example, this stub will enforce your program to use the Tui interface.
Complete example
Source of program.py
, we have one single attribute foo
:
from typing import Annotated
from dataclasses import dataclass
from mininterface import run, Options
@dataclass
class Env:
foo: Annotated["str", Options("one", "two")] = "one"
m = run(Env)
m.form()
Source of program.yaml
will enforce the comboboxes:
The difference when using such configuration file.
Inheritance
The individual setting items are inherited, while the descendants have the higher priority. Ex. TuiSettings
works as a default for TextSettings
and TextualSettings
.
graph LR
GuiSettings --> UiSettings
TuiSettings --> UiSettings
TextualSettings --> TuiSettings
TextSettings --> TuiSettings
Ex. this config file sets the UiSettings
item mnemonic
to None
for TuiSettings
and more specifically to False
for TextSettings
.
For the different interfaces, the value varies this way:
interface | mnemonic value |
---|---|
gui | True (the UiSettings item default) |
textual | None |
text | False |
The settings object
MininterfaceSettings
interface: Optional[InterfaceName] = None
Enforce an interface. By default, we choose automatically.
UiSettings
toggle_widget: str = 'f4'
Shortcuts to toggle ex. calendar or file picker.
mnemonic: Optional[bool] = True
Allow users to access fields with the Alt+char
shortcut.
True
: All Tags withTag(mnemonic=char|True|None)
will have a mnemonic enabled.False
: All mnemonic is disabled, even if configured viaTag(mnemonic=char)
.None
: All Tags withTag(mnemonic=char|True)
will have a mnemonic enabled.
mnemonic_hidden: bool = False
If True, the field label is not underlined to mark the mnemonic.
GuiSettings
combobox_since: int = 10
The threshold to switch from radio buttons to a combobox.
radio_select_on_focus: bool = False
Select the radio button on focus. Ex. when navigating by arrows.
TuiSettings
TextualSettings
TextSettings
mnemonic_over_number: Optional[bool] = None
Even when mnemonic can be determined, use rather number as a shortcut.
By default if None
, determine those with Tag(mnemonic=char|True)
:
If True
, determine also those having Tag(mnemonic=None)
:
If False
, we prefer numbers:
The original code:
from dataclasses import dataclass
from typing import Annotated
from mininterface import Tag, run
from mininterface.settings import MininterfaceSettings, TextSettings
@dataclass
class Env:
foo1: bool = False
foo2: bool = False
foo3: Annotated[bool, Tag(mnemonic="g")] = False
m = run(Env, settings=MininterfaceSettings(text=TextSettings(mnemonic_over_number=True)))
m.form()
quit()