Skip to content

Commit 3b888f5

Browse files
committed
textual upgrade
1 parent 36633c3 commit 3b888f5

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

mininterface/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MininterfaceConfig:
2121
gui: Gui
2222
tui: Tui
2323
interface: Literal["gui"] | Literal["tui"] | None = None
24-
""" Choose the interface """
24+
""" Enforce an interface. By default, we choose automatically. """
2525

2626

2727
Config = MininterfaceConfig(Gui(), Tui())

mininterface/showcase.py

+3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ class Subcommand1(SharedArgs):
2626
my_local: int = 1
2727

2828
def run(self):
29+
print("Subcommand 1 clicked")
2930
print("Common:", self.common) # user input
3031
print("Number:", self.my_local) # 1 or user input
3132
print("Internal:", self.internal)
33+
print("The submit button blocked!")
3234
raise ValidationFail("The submit button blocked!")
3335

3436

3537
@dataclass
3638
class Subcommand2(SharedArgs):
3739
def run(self):
40+
print("Subcommand 2 clicked")
3841
self._facet.set_title("Button clicked") # you can access internal self._facet: Facet
3942
print("Common files", self.files)
4043

mininterface/textual_interface/textual_adaptor.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,11 @@ def run_dialog(self, form: TagDict, title: str = "", submit: bool | str = True)
8282
if title:
8383
app.title = title
8484

85-
widgets: WidgetList = [f for f in flatten(formdict_to_widgetdict(
86-
form, self.widgetize), include_keys=self.header)]
87-
if len(widgets) and isinstance(widgets[0], Rule):
88-
# there are multiple sections in the list, <hr>ed by Rule elements. However, the first takes much space.
89-
widgets.pop(0)
90-
app.widgets = widgets
91-
9285
if not app.run():
9386
raise Cancelled
9487

9588
# validate and store the UI value → Tag value → original value
96-
vals = ((field._link, field.get_ui_value()) for field in widgets if hasattr(field, "_link"))
89+
vals = ((field._link, field.get_ui_value()) for field in app.widgets if hasattr(field, "_link"))
9790
if not Tag._submit_values(vals) or not self.submit_done():
9891
return self.run_dialog(form, title, submit)
9992

mininterface/textual_interface/textual_app.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
from textual.containers import VerticalScroll
66
from textual.widget import Widget
77
from textual.widgets import (Checkbox, Footer, Header, Input, Label,
8-
RadioButton, Static)
8+
RadioButton, Static, Rule)
99

1010

1111
from .widgets import (Changeable, MyButton, MyCheckbox, MyInput, MyRadioSet,
1212
MySubmitButton)
1313

14+
from ..form_dict import formdict_to_widgetdict
15+
16+
from ..auxiliary import flatten
1417
from ..facet import BackendAdaptor
1518

1619
if TYPE_CHECKING:
@@ -52,6 +55,16 @@ def __init__(self, adaptor: "TextualAdaptor", submit: str | bool = True):
5255
self.bind("escape", "exit", description="Cancel")
5356

5457
def compose(self) -> ComposeResult:
58+
# prepare widgets
59+
# since textual 1.0.0 we have to build widgets not earlier than the context app is ready
60+
self.widgets = list(flatten(formdict_to_widgetdict(
61+
self.adaptor.facet._form, self.adaptor.widgetize), include_keys=self.adaptor.header))
62+
63+
# there are multiple sections in the list, <hr>ed by Rule elements. However, the first takes much space.
64+
if len(self.widgets) and isinstance(self.widgets[0], Rule):
65+
self.widgets.pop(0)
66+
67+
# start yielding widgets
5568
if self.title:
5669
yield Header()
5770
yield self.output # NOTE not used

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pyyaml = "*"
2020
# Standard requirements
2121
autocombobox = "1.4.2"
2222
humanize = "*" # used only in the TkInterface, hence it is not a minimal requirement
23-
textual = "~0.84"
23+
textual = "<2.0.0"
2424
tkinter-tooltip = "*"
2525
tkinter_form = "0.2.1"
2626
tkscrollableframe = "*"

0 commit comments

Comments
 (0)