Skip to content

Commit 46ca687

Browse files
committed
gui: Let Enter move on from every text field
Enter in a field did nothing, so a card that "checks out" still needed a click on Continue. The CLI takes Enter as the answer to every prompt. _page now wires every text field it holds, once: Enter moves to the next shown field, and from the last presses the first page action that is switched on (the last action by default). Card entry falls back to "Suggest a repair", as the CLI offers a correction for a card that does not check out. Covers card entry, read-back, wallet record, new wallet, unlock, the YES gate and the custom layout numbers. Claude-Session: https://claude.ai/code/session_01N8jLK7DpgY81q3JWXK4Zvz
1 parent ae9d360 commit 46ca687

3 files changed

Lines changed: 60 additions & 9 deletions

File tree

‎src/codex32_gui/pages.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def _page(
107107
content: Gtk.Widget,
108108
*,
109109
actions: Gtk.Widget | None = None,
110+
enter: Sequence[Gtk.Widget] = (),
110111
can_pop: bool = True,
111112
) -> Adw.NavigationPage:
112113
scroller = Gtk.ScrolledWindow(hscrollbar_policy=Gtk.PolicyType.NEVER, vexpand=True)
@@ -116,11 +117,35 @@ def _page(
116117
bars.set_content(scroller)
117118
if actions is not None:
118119
bars.add_bottom_bar(actions)
120+
_on_enter(content, enter or (actions.get_last_child(),))
119121
page = Adw.NavigationPage(title=title, child=bars)
120122
page.set_can_pop(can_pop)
121123
return page
122124

123125

126+
def _texts(widget: Gtk.Widget) -> list[Gtk.Widget]:
127+
found, child = [widget] if isinstance(widget, Gtk.Text) else [], widget.get_first_child()
128+
while child is not None:
129+
found, child = found + _texts(child), child.get_next_sibling()
130+
return found
131+
132+
133+
def _on_enter(content: Gtk.Widget, buttons: Sequence[Gtk.Widget]) -> None:
134+
"""Enter moves on as at a CLI prompt: to the next field, and from the last to the first button that can act."""
135+
texts = _texts(content)
136+
137+
def press(text: Gtk.Widget) -> None:
138+
later = [item for item in texts[texts.index(text) + 1 :] if item.get_mapped()]
139+
ready = [button for button in buttons if button.is_sensitive()]
140+
if later:
141+
later[0].grab_focus()
142+
elif ready:
143+
ready[0].emit("clicked")
144+
145+
for text in texts:
146+
text.connect("activate", press)
147+
148+
124149
def _column(*children: Gtk.Widget) -> Gtk.Box:
125150
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=14, margin_top=18, margin_bottom=18)
126151
for child in children:
@@ -1310,7 +1335,7 @@ def following() -> Adw.NavigationPage:
13101335
)
13111336
)
13121337
content = _column(_title(heading, body), *progress, field, status)
1313-
page = _page(title, content, actions=_actions(fix, go))
1338+
page = _page(title, content, actions=_actions(fix, go), enter=(go, fix))
13141339
_forget_when_gone(view, page, field.clear)
13151340
update()
13161341
return page

‎tests/test_gui_boundaries.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
}
3434
)
3535
CORE_ADAPTER = "codex32._bitcoin_core"
36-
BUDGET = 2050
36+
BUDGET = 2070
3737

3838

3939
def _package() -> Path:

‎tools/gui_walkthrough.py‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
gi.require_version("Adw", "1")
2121
gi.require_version("Gtk", "4.0")
2222

23-
from gi.repository import Gdk, GLib, Gtk
23+
from gi.repository import Adw, Gdk, GLib, Gtk
2424

2525
from codex32_gui import app, pages, reading, wallet_setup
2626

@@ -82,6 +82,12 @@ def press(page: Any, label: str) -> None:
8282
)
8383

8484

85+
def enter(field: Any) -> None:
86+
"""Press Enter in a text field, as its key binding does."""
87+
field.get_delegate().emit("activate")
88+
settle()
89+
90+
8591
def labels(page: Any) -> list[str]:
8692
return [item.get_label() for item in walk(page) if isinstance(item, Gtk.Label) and item.get_label()]
8793

@@ -147,6 +153,7 @@ def do_activate(self) -> None:
147153
self.new_card_done,
148154
self.seed_entry,
149155
self.seed_shown,
156+
self.form,
150157
]
151158
GLib.timeout_add(300, self.pump)
152159

@@ -177,6 +184,8 @@ def typing(self) -> bool:
177184
item for item in walk(page) if isinstance(item, Gtk.Button) and item.get_label() == "Continue"
178185
)
179186
check("nothing may be submitted yet", not go.get_sensitive())
187+
enter(field)
188+
check("so Enter stays on the page", self.page() is page)
180189
field.set_text("ms12nameacd")
181190
settle()
182191
check("text is uppercased and grouped", field.get_text() == "MS12 NAME ACD", field.get_text())
@@ -199,7 +208,7 @@ def typing(self) -> bool:
199208
field.set_text(SHARE_C)
200209
settle()
201210
check("a valid card may be submitted", go.get_sensitive())
202-
go.emit("clicked")
211+
enter(field)
203212
return True
204213

205214
def intact(self) -> bool:
@@ -229,7 +238,8 @@ def damaged(self) -> bool:
229238
if isinstance(item, Gtk.Button) and item.get_label() == "Suggest a repair"
230239
)
231240
check("a repair is offered for an unreadable character", fix.get_sensitive())
232-
fix.emit("clicked")
241+
enter(field)
242+
check("and Enter asks for it", self.page() is not page)
233243
return True
234244

235245
def candidate(self) -> bool:
@@ -375,15 +385,15 @@ def read_back(self) -> bool:
375385
check("selecting a card does not publish it", _primary_is_empty(), _primary())
376386
field.set_text(self.made[:-4] + "QQQQ")
377387
settle()
378-
press(page, "Confirm card")
388+
enter(field)
379389
check(
380390
"a mistyped group is named and refused",
381391
any("Group 12 does not match" in text for text in labels(page)),
382392
[text for text in labels(page) if "Group" in text],
383393
)
384394
field.set_text(self.made.lower())
385395
settle()
386-
press(page, "Confirm card")
396+
enter(field)
387397
return True
388398

389399
def new_card_done(self) -> bool:
@@ -406,21 +416,37 @@ def seed_entry(self) -> bool:
406416
page = self.page()
407417
field_of(page).set_text(text)
408418
settle()
409-
press(page, "Continue")
419+
enter(field_of(page))
410420
return True
411421

412422
def seed_shown(self) -> bool:
413423
page = self.page()
414424
if page.get_title() != "Master seed":
415425
return False
416-
check("two cards recover the published secret", card(page) == SECRET_S, card(page))
426+
check("two cards recover the published secret by Enter alone", card(page) == SECRET_S, card(page))
417427
check(
418428
"and the screen warns before anything else",
419429
any("take every coin" in text for text in labels(page)),
420430
[text for text in labels(page) if "coin" in text],
421431
)
422432
return True
423433

434+
def form(self) -> bool:
435+
pressed: list[bool] = []
436+
first, second, hidden = Adw.EntryRow(), Adw.PasswordEntryRow(), Adw.EntryRow(visible=False)
437+
action = pages._button("Create", lambda: pressed.append(True))
438+
content = pages._column(first, hidden, second)
439+
self.view.push(pages._page("Form", content, actions=pages._actions(action)))
440+
settle()
441+
enter(first)
442+
check("Enter moves on to the next shown field", second.get_delegate().has_focus() and not pressed)
443+
enter(second)
444+
check("and in the last field presses the page's action", pressed == [True])
445+
action.set_sensitive(False)
446+
enter(second)
447+
check("but never an action that is switched off", pressed == [True])
448+
return True
449+
424450

425451
def main() -> int:
426452
wallet_setup.connect = _connect # type: ignore[assignment]

0 commit comments

Comments
 (0)