improve layout of keyboard detection dialogs
This commit is contained in:
parent
d4fa1d006a
commit
5d42ace4c9
|
@ -19,6 +19,7 @@ from urwid import (
|
||||||
connect_signal,
|
connect_signal,
|
||||||
LineBox,
|
LineBox,
|
||||||
Text,
|
Text,
|
||||||
|
Padding as UrwidPadding
|
||||||
)
|
)
|
||||||
|
|
||||||
from subiquitycore.ui.buttons import (
|
from subiquitycore.ui.buttons import (
|
||||||
|
@ -54,7 +55,13 @@ class AutoDetectBase(WidgetWrap):
|
||||||
# step is an instance of pc105.Step
|
# step is an instance of pc105.Step
|
||||||
self.keyboard_detector = keyboard_detector
|
self.keyboard_detector = keyboard_detector
|
||||||
self.step = step
|
self.step = step
|
||||||
lb = LineBox(self.make_body(), _("Keyboard auto-detection"))
|
lb = LineBox(
|
||||||
|
Pile([
|
||||||
|
('pack', Text("")),
|
||||||
|
('pack', UrwidPadding(self.make_body(), left=2, right=2)),
|
||||||
|
('pack', Text(""))
|
||||||
|
]),
|
||||||
|
_("Keyboard auto-detection"))
|
||||||
super().__init__(lb)
|
super().__init__(lb)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
@ -150,14 +157,13 @@ class AutoDetectPressKey(AutoDetectBase):
|
||||||
|
|
||||||
def make_body(self):
|
def make_body(self):
|
||||||
self.error_text = Text("", align="center")
|
self.error_text = Text("", align="center")
|
||||||
return Pile([
|
self.pile = Pile([
|
||||||
Text(_("Please press one of the following keys:")),
|
('pack', Text(_("Please press one of the following keys:"))),
|
||||||
Text(""),
|
('pack', Text("")),
|
||||||
Columns([Text(s, align="center")
|
('pack', Columns([Text(s, align="center")
|
||||||
for s in self.step.symbols], dividechars=1),
|
for s in self.step.symbols], dividechars=1)),
|
||||||
Text(""),
|
|
||||||
Color.info_error(self.error_text),
|
|
||||||
])
|
])
|
||||||
|
return self.pile
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def input_filter(self):
|
def input_filter(self):
|
||||||
|
@ -169,6 +175,13 @@ class AutoDetectPressKey(AutoDetectBase):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.input_filter.exit_keycodes_mode()
|
self.input_filter.exit_keycodes_mode()
|
||||||
|
|
||||||
|
def error(self, message):
|
||||||
|
t = Color.info_error(Text(message, align='center'))
|
||||||
|
self.pile.contents.extend([
|
||||||
|
(Text(""), self.pile.options('pack')),
|
||||||
|
(t, self.pile.options('pack')),
|
||||||
|
])
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
log.debug('keypress %r %r', size, key)
|
log.debug('keypress %r %r', size, key)
|
||||||
if key.startswith('release '):
|
if key.startswith('release '):
|
||||||
|
@ -181,14 +194,16 @@ class AutoDetectPressKey(AutoDetectBase):
|
||||||
elif key.startswith('press '):
|
elif key.startswith('press '):
|
||||||
code = int(key[len('press '):])
|
code = int(key[len('press '):])
|
||||||
if code not in self.step.keycodes:
|
if code not in self.step.keycodes:
|
||||||
self.error_text.set_text(_("Input was not recognized, "
|
self.error(_("Input was not recognized, try again"))
|
||||||
"try again"))
|
|
||||||
return
|
return
|
||||||
v = self.step.keycodes[code]
|
v = self.step.keycodes[code]
|
||||||
else:
|
else:
|
||||||
# If we're not on a linux tty, the filtering won't have
|
# If we're not on a linux tty, the filtering won't have
|
||||||
# happened and so there's no way to get the keycodes. Do
|
# happened and so there's no way to get the keycodes. Do
|
||||||
# something literally random instead.
|
# something literally random instead.
|
||||||
|
if key == 'e':
|
||||||
|
self.error(_("Input was not recognized, try again"))
|
||||||
|
return
|
||||||
import random
|
import random
|
||||||
v = random.choice(list(self.step.keycodes.values()))
|
v = random.choice(list(self.step.keycodes.values()))
|
||||||
self.keyboard_detector.do_step(v)
|
self.keyboard_detector.do_step(v)
|
||||||
|
|
Loading…
Reference in New Issue