summaryrefslogtreecommitdiff
path: root/src/data_forms.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-01-25 21:38:31 +0100
committerFlorent Le Coz <louiz@louiz.org>2011-01-25 21:38:31 +0100
commit8b6c0c5a2e73e35921ff108fd2b81aaa4286b855 (patch)
tree6d2a317061752f3abeb016fc6cb492d4215b2a4c /src/data_forms.py
parent6a0346a12ae30a9449a1964260be26dc042195ce (diff)
downloadpoezio-8b6c0c5a2e73e35921ff108fd2b81aaa4286b855.tar.gz
poezio-8b6c0c5a2e73e35921ff108fd2b81aaa4286b855.tar.bz2
poezio-8b6c0c5a2e73e35921ff108fd2b81aaa4286b855.tar.xz
poezio-8b6c0c5a2e73e35921ff108fd2b81aaa4286b855.zip
data-forms: an help message
Diffstat (limited to 'src/data_forms.py')
-rw-r--r--src/data_forms.py53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/data_forms.py b/src/data_forms.py
index dad5a456..28fee1df 100644
--- a/src/data_forms.py
+++ b/src/data_forms.py
@@ -41,8 +41,9 @@ class DataFormsTab(Tab):
self.fields.append(field)
self.topic_win = windows.Topic()
self.tab_win = windows.GlobalInfoBar()
- self.form_win = FormWin(form, self.height-3, self.width, 1, 0)
+ self.form_win = FormWin(form, self.height-4, self.width, 1, 0)
self.help_win = windows.HelpText("Ctrl+Y: send form, Ctrl+G: cancel")
+ self.help_win_dyn = windows.HelpText()
self.key_func['KEY_UP'] = self.form_win.go_to_previous_input
self.key_func['KEY_DOWN'] = self.form_win.go_to_next_input
self.key_func['^G'] = self.on_cancel
@@ -59,21 +60,27 @@ class DataFormsTab(Tab):
def on_input(self, key):
if key in self.key_func:
- return self.key_func[key]()
- self.form_win.on_input(key)
+ res = self.key_func[key]()
+ self.help_win_dyn.refresh(self.form_win.get_help_message())
+ self.form_win.refresh()
+ return res
+ else:
+ self.form_win.on_input(key)
def resize(self):
Tab.resize(self)
self.topic_win.resize(1, self.width, 0, 0, self.core.stdscr)
self.tab_win.resize(1, self.width, self.height-2, 0, self.core.stdscr)
- self.form_win.resize(self.height-3, self.width, 1, 0)
+ self.form_win.resize(self.height-4, self.width, 1, 0)
self.help_win.resize(1, self.width, self.height-1, 0, None)
+ self.help_win_dyn.resize(1, self.width, self.height-3, 0, None)
self.lines = []
def refresh(self, tabs, informations, _):
self.topic_win.refresh(self._form['title'])
self.tab_win.refresh(tabs, tabs[0])
self.help_win.refresh()
+ self.help_win_dyn.refresh(self.form_win.get_help_message())
self.form_win.refresh()
class FieldInput(object):
@@ -105,6 +112,13 @@ class FieldInput(object):
"""
raise NotImplementedError
+ def get_help_message(self):
+ """
+ Should return a string explaining the keys of the input.
+ Will be displayed at each refresh on a line at the bottom of the tab.
+ """
+ return ''
+
class DummyInput(FieldInput, windows.Win):
def __init__(self, field):
FieldInput.__init__(self, field)
@@ -150,6 +164,9 @@ class BooleanWin(FieldInput, windows.Win):
self._field['label'] = ''
self._field.setAnswer(self.value)
+ def get_help_message(self):
+ return '← and →: change the value between True and False'
+
class TextMultiWin(FieldInput, windows.Win):
def __init__(self, field):
FieldInput.__init__(self, field)
@@ -212,6 +229,17 @@ class TextMultiWin(FieldInput, windows.Win):
values = [val for val in self.options if val]
self._field.setAnswer(values)
+ def get_help_message(self):
+ if not self.edition_input:
+ help_msg = '← and →: browse the available entries. '
+ if self.val_pos == len(self.options)-1:
+ help_msg += 'Enter: add an entry'
+ else:
+ help_msg += 'Enter: edit this entry'
+ else:
+ help_msg = 'Enter: finish editing this entry.'
+ return help_msg
+
class ListMultiWin(FieldInput, windows.Win):
def __init__(self, field):
FieldInput.__init__(self, field)
@@ -254,6 +282,9 @@ class ListMultiWin(FieldInput, windows.Win):
values = [option[0]['value'] for option in self.options if option[1] is True]
self._field.setAnswer(values)
+ def get_help_message(self):
+ return '←, →: Switch between the value. Space: select or unselect a value'
+
class ListSingleWin(FieldInput, windows.Win):
def __init__(self, field):
FieldInput.__init__(self, field)
@@ -295,6 +326,9 @@ class ListSingleWin(FieldInput, windows.Win):
self._field.delOptions()
self._field.setAnswer(self.options[self.val_pos]['value'])
+ def get_help_message(self):
+ return '←, →: Select a value amongst the others'
+
class TextSingleWin(FieldInput, windows.Input):
def __init__(self, field):
FieldInput.__init__(self, field)
@@ -308,6 +342,9 @@ class TextSingleWin(FieldInput, windows.Input):
self._field['label'] = ''
self._field.setAnswer(self.get_text())
+ def get_help_message(self):
+ return 'Edit the text'
+
class TextPrivateWin(TextSingleWin):
def __init__(self, field):
TextSingleWin.__init__(self, field)
@@ -327,6 +364,9 @@ class TextPrivateWin(TextSingleWin):
self._win.attroff(curses.color_pair(self.color))
self._refresh()
+ def get_help_message(self):
+ return 'Edit the secret text'
+
class FormWin(object):
"""
A window, with some subwins (the various inputs).
@@ -439,3 +479,8 @@ class FormWin(object):
inp['input'].refresh()
self.inputs[self.current_input]['input'].set_color(13)
self.inputs[self.current_input]['input'].refresh()
+
+ def get_help_message(self):
+ if self.inputs[self.current_input]['input']:
+ return self.inputs[self.current_input]['input'].get_help_message()
+ return ''