summaryrefslogtreecommitdiffstats
path: root/pyanaconda/ui/tui/simpleline
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2012-07-31 14:27:35 +0200
committerMartin Sivak <msivak@redhat.com>2012-08-06 13:32:21 +0200
commit1ddd40a0a01c5cffe519382cf5a9429bcedab7e0 (patch)
tree61cd353c623732e57e137734ca7323443c93105f /pyanaconda/ui/tui/simpleline
parentbd1979fb922bfeda015d0874065746c9e237fc6e (diff)
downloadanaconda-1ddd40a0a01c5cffe519382cf5a9429bcedab7e0.tar.gz
anaconda-1ddd40a0a01c5cffe519382cf5a9429bcedab7e0.tar.xz
anaconda-1ddd40a0a01c5cffe519382cf5a9429bcedab7e0.zip
Fix bits and pieces to make TUI hub and spoke model work + example Hub and Password spoke
Diffstat (limited to 'pyanaconda/ui/tui/simpleline')
-rw-r--r--pyanaconda/ui/tui/simpleline/base.py46
-rw-r--r--pyanaconda/ui/tui/simpleline/widgets.py8
2 files changed, 35 insertions, 19 deletions
diff --git a/pyanaconda/ui/tui/simpleline/base.py b/pyanaconda/ui/tui/simpleline/base.py
index 715b097f5..573f28b23 100644
--- a/pyanaconda/ui/tui/simpleline/base.py
+++ b/pyanaconda/ui/tui/simpleline/base.py
@@ -21,6 +21,8 @@
__all__ = ["ExitMainLoop", "App", "UIScreen", "Widget"]
+import readline
+
class ExitAllMainLoops(Exception):
pass
@@ -29,9 +31,10 @@ class ExitMainLoop(Exception):
class App(object):
- def __init__(self, title, yes_or_no_question = None):
+ def __init__(self, title, yes_or_no_question = None, width = 80):
self._header = title
- self._spacer = "\n".join(2*[80*"="])
+ self._spacer = "\n".join(2*[width*"="])
+ self._width = width
self.quit_question = yes_or_no_question
# screen stack contains triplets
@@ -54,7 +57,7 @@ class App(object):
def switch_screen_modal(self, ui, args = None):
"""Starts a new screen right away, so the caller can collect data back. When the new screen is closed, the caller is redisplayed."""
self._screens.append((ui, args, True))
- self.redraw()
+ self._do_redraw()
def schedule_screen(self, ui, args = None):
"""Add screen to the bottom of the stack."""
@@ -82,8 +85,6 @@ class App(object):
raise ExitMainLoop()
screen, args, newloop = self._screens[-1]
- input_needed = screen.refresh(args)
- screen.window.show_all()
if newloop == True:
self._screens.pop()
@@ -91,8 +92,10 @@ class App(object):
self.mainloop()
self.redraw()
input_needed = False # we have to skip input once, to redisplay the screen first
-
- self._redraw = False
+ else:
+ input_needed = screen.refresh(args)
+ screen.window.show_all()
+ self._redraw = False
return input_needed
@@ -107,14 +110,23 @@ class App(object):
last_screen = None
error_counter = 0
while self._screens:
+ if self._redraw:
+ print self._spacer
+
try:
if self._redraw or last_screen != self._screens[-1]:
if not self._do_redraw():
continue
- last_screen = self._screens[-1]
+ last_screen = self._screens[-1][0]
+
+ prompt = last_screen.prompt()
+ if prompt is None:
+ self.redraw()
+ continue
+
+ c = raw_input(prompt)
- c = raw_input(last_screen.prompt())
if not self.input(c):
error_counter += 1
@@ -123,7 +135,6 @@ class App(object):
if self._redraw:
error_counter = 0
- print self._spacer
except ExitMainLoop:
break
except ExitAllMainLoops:
@@ -140,10 +151,11 @@ class App(object):
self.close_screen()
return True
- elif self._screens and (key == 'quit'):
+ elif self._screens and (key == 'q'):
if self.quit_question:
- self.switch_screen_modal(self.quit_question(u"Do you really want to quit?"))
- if self.quit_question.answer:
+ d = self.quit_question(self, u"Do you really want to quit?")
+ self.switch_screen_modal(d)
+ if d.answer:
raise ExitAllMainLoops()
return True
@@ -160,6 +172,9 @@ class App(object):
def store(self):
return self._store
+ @property
+ def width(self):
+ return self._width
class UIScreen(object):
title = u"Screen.."
@@ -170,7 +185,7 @@ class UIScreen(object):
def refresh(self, args = None):
"""Method which prepares the screen to self._window. If user input is requested, return True."""
- self.window = [self.title, u""]
+ self._window = [self.title, u""]
@property
def window(self):
@@ -179,7 +194,7 @@ class UIScreen(object):
def show_all(self):
for w in self._window:
if hasattr(w, "render"):
- w.render(app.width)
+ w.render(self.app.width)
print unicode(w)
show = show_all
@@ -192,6 +207,7 @@ class UIScreen(object):
return key
def prompt(self):
+ """Return the text to be shown as prompt or handle the prompt and return None."""
return u"\tPlease make your choice from above ['q' to quit]: "
@property
diff --git a/pyanaconda/ui/tui/simpleline/widgets.py b/pyanaconda/ui/tui/simpleline/widgets.py
index 2d79e3f1a..8dde0433b 100644
--- a/pyanaconda/ui/tui/simpleline/widgets.py
+++ b/pyanaconda/ui/tui/simpleline/widgets.py
@@ -31,7 +31,7 @@ class TextWidget(base.Widget):
self._text = text
def render(self, width):
- self.clear()
+ base.Widget.render(self, width)
self.write(self._text, width = width)
class CenterWidget(base.Widget):
@@ -40,7 +40,7 @@ class CenterWidget(base.Widget):
self._w = w
def render(self, width):
- self.clear()
+ base.Widget.render(self, width)
self._w.render(width)
self.draw(self._w, col = (width - self._w.width) / 2)
@@ -60,7 +60,7 @@ class ColumnWidget(base.Widget):
self._columns = columns
def render(self, width):
- self.clear()
+ base.Widget.render(self, width)
x = 0
for col_width,col in self._columns:
@@ -87,7 +87,7 @@ class CheckboxWidget(base.Widget):
self._completed = completed
def render(self, width):
- self.clear()
+ base.Widget.render(self, width)
if self.completed:
checkchar = "x"