Commit 8b6c0c5a authored by louiz’'s avatar louiz’

data-forms: an help message

parent 6a0346a1
...@@ -41,8 +41,9 @@ class DataFormsTab(Tab): ...@@ -41,8 +41,9 @@ class DataFormsTab(Tab):
self.fields.append(field) self.fields.append(field)
self.topic_win = windows.Topic() self.topic_win = windows.Topic()
self.tab_win = windows.GlobalInfoBar() 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 = 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_UP'] = self.form_win.go_to_previous_input
self.key_func['KEY_DOWN'] = self.form_win.go_to_next_input self.key_func['KEY_DOWN'] = self.form_win.go_to_next_input
self.key_func['^G'] = self.on_cancel self.key_func['^G'] = self.on_cancel
...@@ -59,21 +60,27 @@ class DataFormsTab(Tab): ...@@ -59,21 +60,27 @@ class DataFormsTab(Tab):
def on_input(self, key): def on_input(self, key):
if key in self.key_func: if key in self.key_func:
return self.key_func[key]() res = self.key_func[key]()
self.form_win.on_input(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): def resize(self):
Tab.resize(self) Tab.resize(self)
self.topic_win.resize(1, self.width, 0, 0, self.core.stdscr) 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.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.resize(1, self.width, self.height-1, 0, None)
self.help_win_dyn.resize(1, self.width, self.height-3, 0, None)
self.lines = [] self.lines = []
def refresh(self, tabs, informations, _): def refresh(self, tabs, informations, _):
self.topic_win.refresh(self._form['title']) self.topic_win.refresh(self._form['title'])
self.tab_win.refresh(tabs, tabs[0]) self.tab_win.refresh(tabs, tabs[0])
self.help_win.refresh() self.help_win.refresh()
self.help_win_dyn.refresh(self.form_win.get_help_message())
self.form_win.refresh() self.form_win.refresh()
class FieldInput(object): class FieldInput(object):
...@@ -105,6 +112,13 @@ class FieldInput(object): ...@@ -105,6 +112,13 @@ class FieldInput(object):
""" """
raise NotImplementedError 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): class DummyInput(FieldInput, windows.Win):
def __init__(self, field): def __init__(self, field):
FieldInput.__init__(self, field) FieldInput.__init__(self, field)
...@@ -150,6 +164,9 @@ class BooleanWin(FieldInput, windows.Win): ...@@ -150,6 +164,9 @@ class BooleanWin(FieldInput, windows.Win):
self._field['label'] = '' self._field['label'] = ''
self._field.setAnswer(self.value) self._field.setAnswer(self.value)
def get_help_message(self):
return '← and →: change the value between True and False'
class TextMultiWin(FieldInput, windows.Win): class TextMultiWin(FieldInput, windows.Win):
def __init__(self, field): def __init__(self, field):
FieldInput.__init__(self, field) FieldInput.__init__(self, field)
...@@ -212,6 +229,17 @@ class TextMultiWin(FieldInput, windows.Win): ...@@ -212,6 +229,17 @@ class TextMultiWin(FieldInput, windows.Win):
values = [val for val in self.options if val] values = [val for val in self.options if val]
self._field.setAnswer(values) 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): class ListMultiWin(FieldInput, windows.Win):
def __init__(self, field): def __init__(self, field):
FieldInput.__init__(self, field) FieldInput.__init__(self, field)
...@@ -254,6 +282,9 @@ class ListMultiWin(FieldInput, windows.Win): ...@@ -254,6 +282,9 @@ class ListMultiWin(FieldInput, windows.Win):
values = [option[0]['value'] for option in self.options if option[1] is True] values = [option[0]['value'] for option in self.options if option[1] is True]
self._field.setAnswer(values) 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): class ListSingleWin(FieldInput, windows.Win):
def __init__(self, field): def __init__(self, field):
FieldInput.__init__(self, field) FieldInput.__init__(self, field)
...@@ -295,6 +326,9 @@ class ListSingleWin(FieldInput, windows.Win): ...@@ -295,6 +326,9 @@ class ListSingleWin(FieldInput, windows.Win):
self._field.delOptions() self._field.delOptions()
self._field.setAnswer(self.options[self.val_pos]['value']) 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): class TextSingleWin(FieldInput, windows.Input):
def __init__(self, field): def __init__(self, field):
FieldInput.__init__(self, field) FieldInput.__init__(self, field)
...@@ -308,6 +342,9 @@ class TextSingleWin(FieldInput, windows.Input): ...@@ -308,6 +342,9 @@ class TextSingleWin(FieldInput, windows.Input):
self._field['label'] = '' self._field['label'] = ''
self._field.setAnswer(self.get_text()) self._field.setAnswer(self.get_text())
def get_help_message(self):
return 'Edit the text'
class TextPrivateWin(TextSingleWin): class TextPrivateWin(TextSingleWin):
def __init__(self, field): def __init__(self, field):
TextSingleWin.__init__(self, field) TextSingleWin.__init__(self, field)
...@@ -327,6 +364,9 @@ class TextPrivateWin(TextSingleWin): ...@@ -327,6 +364,9 @@ class TextPrivateWin(TextSingleWin):
self._win.attroff(curses.color_pair(self.color)) self._win.attroff(curses.color_pair(self.color))
self._refresh() self._refresh()
def get_help_message(self):
return 'Edit the secret text'
class FormWin(object): class FormWin(object):
""" """
A window, with some subwins (the various inputs). A window, with some subwins (the various inputs).
...@@ -439,3 +479,8 @@ class FormWin(object): ...@@ -439,3 +479,8 @@ class FormWin(object):
inp['input'].refresh() inp['input'].refresh()
self.inputs[self.current_input]['input'].set_color(13) self.inputs[self.current_input]['input'].set_color(13)
self.inputs[self.current_input]['input'].refresh() 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 ''
...@@ -650,7 +650,9 @@ class HelpText(Win): ...@@ -650,7 +650,9 @@ class HelpText(Win):
def resize(self, height, width, y, x, stdscr): def resize(self, height, width, y, x, stdscr):
self._resize(height, width, y, x, stdscr) self._resize(height, width, y, x, stdscr)
def refresh(self): def refresh(self, txt=None):
if txt:
self.txt = txt
with g_lock: with g_lock:
self._win.erase() self._win.erase()
self.addstr(0, 0, self.txt[:self.width-1], curses.color_pair(theme.COLOR_INFORMATION_BAR)) self.addstr(0, 0, self.txt[:self.width-1], curses.color_pair(theme.COLOR_INFORMATION_BAR))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment