@@ -72,10 +74,148 @@ class TUISpoke(TUIObject, tui.Widget, Spoke):
c.render(width)
self.draw(c)
-class StandaloneTUISpoke(TUISpoke, StandaloneSpoke):
+class NormalTUISpoke(TUISpoke, NormalSpoke):
pass
-class NormalTUISpoke(TUISpoke, NormalSpoke):
+class EditTUIDialog(NormalTUISpoke):
+ title = _("New value")
+ PASSWORD = re.compile(".*")
+
+ def __init__(self, app, data, storage, payload, instclass):
+ NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
+ self.value = None
+
+ def refresh(self, args):
+ self._window = []
+ self.value = None
+ return True
+
+ def prompt(self, (title, value, regex)):
+ if regex == self.PASSWORD:
+ pw = self._app.raw_input(_("%s: ") % title, hidden=True)
+ confirm = self._app.raw_input(_("%s (confirm): ") % title,
hidden=True)
You need to do the substitutions outside of the _() call, or this will
not get translated the way you want it to. There's a couple other
placews this happens, by the way.
+class OneShotEditTUIDialog(EditTUIDialog):
+ def prompt(self, (title, value, regex)):
+ ret = EditTUIDialog.prompt(self, (title, value, regex))
+ if ret is None:
+ self.close()
+ return ret
+
+class EditTUISpoke(NormalTUISpoke):
+ # self.data's subattribute name
+ edit_data = ""
I'd like to see docstrings for these new classes.
+ def refresh(self, args = None):
+ NormalTUISpoke.refresh(self, args)
+
+ if args:
+ self.args = args
+ elif self.edit_data:
+ self.args = self.data
+ for key in self.edit_data.split("."):
+ self.args = getattr(self.args, key)
+
+ def _prep_text(i, (title, field, regexp)):
+ number = tui.TextWidget("%2d)" % i)
+ title = tui.TextWidget(title)
+ value = self.args
+ for key in field.split("."):
+ value = getattr(self.args, key)
+ value = tui.TextWidget(value)
+
+ return tui.ColumnWidget([(3, [number]), (None, [title, value])], 1)
+
+ def _prep_check(i, (title, field, regexp)):
+ number = tui.TextWidget("%2d)" % i)
+ value = self.args
+ for key in field.split("."):
+ value = getattr(self.args, key)
+ ch = tui.CheckboxWidget(title=title, completed=bool(value))
+
+ return tui.ColumnWidget([(3, [number]), (None, [ch])], 1)
+
+ def _prep_password(i, (title, field, regexp)):
+ number = tui.TextWidget("%2d)" % i)
+ title = tui.TextWidget(title)
+ value = self.args
+ for key in field.split("."):
+ value = getattr(self.args, key)
+ value = tui.TextWidget("".join(["*"] * len(value)))
+
+ return tui.ColumnWidget([(3, [number]), (None, [title, value])], 1)
+
+ for idx,field in enumerate(self.edit_fields):
+ field_type = field[2]
+ if field_type == self.PASSWORD:
+ w = _prep_password(idx+1, field)
+ elif field_type == self.CHECK:
+ w = _prep_check(idx+1, field)
+ else:
+ w = _prep_text(idx+1, field)
+
+ self._window.append(w)
+
+ return True
These methods might be another great candidate for namedtuple.
diff --git a/pyanaconda/ui/tui/spokes/user.py
b/pyanaconda/ui/tui/spokes/user.py
new file mode 100644
index 0000000..f4ee6f8
--- /dev/null
+++ b/pyanaconda/ui/tui/spokes/user.py
Remember to add this new file to po/POTFILES.in.
- Chris