[PATCH 12/13] Pass screen args argument to prompt and input methods + fix for run-text-spoke

Martin Sivak msivak at redhat.com
Wed Aug 8 08:52:50 UTC 2012


---
 pyanaconda/ui/tui/__init__.py             |    8 ++++----
 pyanaconda/ui/tui/hubs/__init__.py        |    2 +-
 pyanaconda/ui/tui/simpleline/base.py      |   23 ++++++++++++++++-------
 pyanaconda/ui/tui/spokes/__init__.py      |    2 +-
 pyanaconda/ui/tui/spokes/password.py      |    2 +-
 pyanaconda/ui/tui/tools/run-text-spoke.py |    4 ++--
 6 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/pyanaconda/ui/tui/__init__.py b/pyanaconda/ui/tui/__init__.py
index 5f45c57..9b49d66 100644
--- a/pyanaconda/ui/tui/__init__.py
+++ b/pyanaconda/ui/tui/__init__.py
@@ -26,10 +26,10 @@ class ErrorDialog(tui.UIScreen):
         text = tui.TextWidget(self._message)
         self._window.append(tui.CenterWidget(text))
 
-    def prompt(self):
+    def prompt(self, args = None):
         return u"Press enter to exit."
 
-    def input(self, key):
+    def input(self, args, key):
         """This dialog is closed by any input."""
         self.close()
 
@@ -58,10 +58,10 @@ class YesNoDialog(tui.UIScreen):
         self._window.append(u"")
         return True
 
-    def prompt(self):
+    def prompt(self, args):
         return u"Please respond 'yes' or 'no': "
 
-    def input(self, key):
+    def input(self, args, key):
         if key == "yes":
             self._response = True
             self.close()
diff --git a/pyanaconda/ui/tui/hubs/__init__.py b/pyanaconda/ui/tui/hubs/__init__.py
index 9d4937a..d6ee5b2 100644
--- a/pyanaconda/ui/tui/hubs/__init__.py
+++ b/pyanaconda/ui/tui/hubs/__init__.py
@@ -64,7 +64,7 @@ class TUIHub(TUIObject, common.Hub):
 
         return True
 
-    def input(self, key):
+    def input(self, args, key):
         """Handle user input. Numbers are used to show a spoke, the rest is passed
         to the higher level for processing."""
         try:
diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py
index 1a07211..a79adbc 100644
--- a/pyanaconda/ui/tui/simpleline/base.py
+++ b/pyanaconda/ui/tui/simpleline/base.py
@@ -234,7 +234,7 @@ class App(object):
                 last_screen = self._screens[-1][0]
 
                 # get the screen's prompt
-                prompt = last_screen.prompt()
+                prompt = last_screen.prompt(self._screens[-1][1])
 
                 # None means prompt handled the input by itself
                 # ask for redraw and continue
@@ -247,7 +247,7 @@ class App(object):
 
                 # process the input, if it wasn't processed (valid)
                 # increment the error counter
-                if not self.input(c):
+                if not self.input(self._screens[-1][1], c):
                     error_counter += 1
 
                 # redraw the screen after 5 bad inputs
@@ -269,10 +269,13 @@ class App(object):
         but we might need to override it for more complex apps or testing."""
         return raw_input(prompt)
 
-    def input(self, key):
+    def input(self, args, key):
         """Method called internally to process unhandled input key presses.
         Also handles the main quit and close commands.
 
+        :param args: optional argument passed from switch_screen calls
+        :type args: anything
+
         :param key: the string entered by user
         :type key: unicode
 
@@ -283,7 +286,7 @@ class App(object):
 
         # delegate the handling to active screen first
         if self._screens:
-            key = self._screens[-1][0].input(key)
+            key = self._screens[-1][0].input(args, key)
             if key is None:
                 return True
 
@@ -368,12 +371,15 @@ class UIScreen(object):
         """This does nothing in TUI, it is here to make API similar."""
         pass
 
-    def input(self, key):
+    def input(self, args, key):
         """Method called to process input. If the input is not handled here, return it.
 
         :param key: input string to process
         :type key: unicode
 
+        :param args: optional argument passed from switch_screen calls
+        :type args: anything
+
         :return: return True or None if key was handled, False if the screen should not
                  process input on the App and key if you want it to.
         :rtype: True|False|None|unicode
@@ -381,13 +387,16 @@ class UIScreen(object):
 
         return key
 
-    def prompt(self):
+    def prompt(self, args = None):
         """Return the text to be shown as prompt or handle the prompt and return None.
 
+        :param args: optional argument passed from switch_screen calls
+        :type args: anything
+
         :return: returns text to be shown next to the prompt for input or None
                  to skip further input processing
         :rtype: unicode|None
-"""
+        """
         return u"\tPlease make your choice from above ['q' to quit]: "
 
     @property
diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py
index 07fc3d1..fc61248 100644
--- a/pyanaconda/ui/tui/spokes/__init__.py
+++ b/pyanaconda/ui/tui/spokes/__init__.py
@@ -38,7 +38,7 @@ class TUISpoke(TUIObject, tui.Widget, Spoke):
         TUIObject.refresh(self, args)
         return True
 
-    def input(self, key):
+    def input(self, args, key):
         """Handle the input, the base class just forwards it to the App level."""
         return key
 
diff --git a/pyanaconda/ui/tui/spokes/password.py b/pyanaconda/ui/tui/spokes/password.py
index db65b25..64ed170 100644
--- a/pyanaconda/ui/tui/spokes/password.py
+++ b/pyanaconda/ui/tui/spokes/password.py
@@ -28,7 +28,7 @@ class PasswordSpoke(NormalTUISpoke):
 
         return True
 
-    def prompt(self):
+    def prompt(self, args = None):
         """Overriden prompt as password typing is special."""
         p1 = getpass.getpass("Password: ")
         p2 = getpass.getpass("Password (confirm): ")
diff --git a/pyanaconda/ui/tui/tools/run-text-spoke.py b/pyanaconda/ui/tui/tools/run-text-spoke.py
index d5e9c57..b542fcb 100755
--- a/pyanaconda/ui/tui/tools/run-text-spoke.py
+++ b/pyanaconda/ui/tui/tools/run-text-spoke.py
@@ -30,13 +30,13 @@ initThreading()
 
 # Figure out the part we are about to show: hub/spoke?
 # And get the name of the module which represents it
-if os.path.basename(sys.argv[0]) == "run-spoke.py":
+if os.path.basename(sys.argv[0]) == "run-text-spoke.py":
     spokeModuleName = "pyanaconda.ui.tui.spokes.%s" % sys.argv[1]
     from pyanaconda.ui.common import Spoke
     spokeBaseClass = Spoke
     spokeText = "spoke"
     SpokeText = "Spoke"
-elif os.path.basename(sys.argv[0]) == "run-hub.py":
+elif os.path.basename(sys.argv[0]) == "run-text-hub.py":
     spokeModuleName = "pyanaconda.ui.tui.hubs.%s" % sys.argv[1]
     from pyanaconda.ui.common import Hub
     spokeBaseClass = Hub
-- 
1.7.10.4



More information about the anaconda-patches mailing list