Commit 41e29926 authored by louiz’'s avatar louiz’

Properly consider the size of the window on data-form tab

parent 8b6c0c5a
...@@ -177,7 +177,7 @@ class Core(object): ...@@ -177,7 +177,7 @@ class Core(object):
self.add_tab(tb_tab, focus=True) self.add_tab(tb_tab, focus=True)
except Exception: # If an exception is raised in this code, except Exception: # If an exception is raised in this code,
# this is fatal, so we exit cleanly and display the traceback # this is fatal, so we exit cleanly and display the traceback
curses.endwin() self.reset_curses()
raise raise
def grow_information_win(self): def grow_information_win(self):
...@@ -678,7 +678,7 @@ class Core(object): ...@@ -678,7 +678,7 @@ class Core(object):
# Cancel the programmed software resize # Cancel the programmed software resize
self.resize_timer.cancel() self.resize_timer.cancel()
# add the new timer # add the new timer
self.resize_timer = threading.Timer(0.2, self.resize_window) self.resize_timer = threading.Timer(0.05, self.resize_window)
self.resize_timer.start() self.resize_timer.start()
def resize_window(self): def resize_window(self):
......
...@@ -52,23 +52,28 @@ class DataFormsTab(Tab): ...@@ -52,23 +52,28 @@ class DataFormsTab(Tab):
def on_cancel(self): def on_cancel(self):
self._on_cancel(self._form) self._on_cancel(self._form)
return True
def on_send(self): def on_send(self):
self._form.reply() self._form.reply()
self.form_win.reply() self.form_win.reply()
self._on_send(self._form) self._on_send(self._form)
return True
def on_input(self, key): def on_input(self, key):
if key in self.key_func: if key in self.key_func:
res = self.key_func[key]() res = self.key_func[key]()
if res:
return res
self.help_win_dyn.refresh(self.form_win.get_help_message()) self.help_win_dyn.refresh(self.form_win.get_help_message())
self.form_win.refresh() self.form_win.refresh_current_input()
return res
else: else:
self.form_win.on_input(key) self.form_win.on_input(key)
def resize(self): def resize(self):
Tab.resize(self) Tab.resize(self)
if not self.visible:
return
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-4, self.width, 1, 0) self.form_win.resize(self.height-4, self.width, 1, 0)
...@@ -77,6 +82,8 @@ class DataFormsTab(Tab): ...@@ -77,6 +82,8 @@ class DataFormsTab(Tab):
self.lines = [] self.lines = []
def refresh(self, tabs, informations, _): def refresh(self, tabs, informations, _):
if not self.visible:
return
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()
...@@ -396,19 +403,21 @@ class FormWin(object): ...@@ -396,19 +403,21 @@ class FormWin(object):
input_class = self.input_classes[field['type']] input_class = self.input_classes[field['type']]
except: except:
continue continue
instructions = field['instructions']
label = field['label'] label = field['label']
desc = field['desc']
if field['type'] == 'fixed': if field['type'] == 'fixed':
label = field.getValue() label = field.getValue()
inp = input_class(field) inp = input_class(field)
self.inputs.append({'label':label, self.inputs.append({'label':label,
'instructions':instructions, 'description': desc,
'input':inp}) 'input':inp})
def resize(self, height, width, y, x): def resize(self, height, width, y, x):
self._win.resize(height, width) self._win.resize(height, width)
self.height = height self.height = height
self.width = width self.width = width
if self.current_input >= self.height-2:
self.current_input = self.height-1
def reply(self): def reply(self):
""" """
...@@ -426,7 +435,7 @@ class FormWin(object): ...@@ -426,7 +435,7 @@ class FormWin(object):
def go_to_next_input(self): def go_to_next_input(self):
if not self.inputs: if not self.inputs:
return return
if self.current_input == len(self.inputs) - 1: if self.current_input == len(self.inputs) - 1 or self.current_input >= self.height-1:
return return
self.inputs[self.current_input]['input'].set_color(14) self.inputs[self.current_input]['input'].set_color(14)
self.current_input += 1 self.current_input += 1
...@@ -469,18 +478,26 @@ class FormWin(object): ...@@ -469,18 +478,26 @@ class FormWin(object):
label = self.inputs[i]['label'] label = self.inputs[i]['label']
self._win.addstr(y, 0, label) self._win.addstr(y, 0, label)
self.inputs[i]['input'].resize(1, self.width//3, y+1, 2*self.width//3) self.inputs[i]['input'].resize(1, self.width//3, y+1, 2*self.width//3)
if field['instructions']: # if field['description']:
y += 1 # y += 1
self._win.addstr(y, 0, field['instructions']) # self._win.addstr(y, 0, field['description'])
y += 1 y += 1
i += 1 i += 1
if y >= self.height:
break
self._win.refresh() self._win.refresh()
for inp in self.inputs: for i, inp in enumerate(self.inputs):
if i >= self.height:
break
inp['input'].refresh() inp['input'].refresh()
self.inputs[self.current_input]['input'].set_color(13) if self.current_input < self.height-1:
self.inputs[self.current_input]['input'].set_color(13)
self.inputs[self.current_input]['input'].refresh()
def refresh_current_input(self):
self.inputs[self.current_input]['input'].refresh() self.inputs[self.current_input]['input'].refresh()
def get_help_message(self): def get_help_message(self):
if self.inputs[self.current_input]['input']: if self.current_input < self.height-1 and self.inputs[self.current_input]['input']:
return self.inputs[self.current_input]['input'].get_help_message() return self.inputs[self.current_input]['input'].get_help_message()
return '' return ''
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