summaryrefslogtreecommitdiff
path: root/src/data_forms.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2011-09-26 09:35:58 +0200
committermathieui <mathieui@mathieui.net>2011-09-26 09:35:58 +0200
commita80338f25ba1f63a31e0675eb213a06ec9172032 (patch)
treea15a6b587dc9f97eb5802133eb1eb8a9364a3f0d /src/data_forms.py
parent4f96907653d80cf39ae5ae63cdfc45ccb40d7e62 (diff)
downloadpoezio-a80338f25ba1f63a31e0675eb213a06ec9172032.tar.gz
poezio-a80338f25ba1f63a31e0675eb213a06ec9172032.tar.bz2
poezio-a80338f25ba1f63a31e0675eb213a06ec9172032.tar.xz
poezio-a80338f25ba1f63a31e0675eb213a06ec9172032.zip
[teisenbe] Make the data forms more usable (highlight of the selected row) + theme colors instead of hardcoded ones
Diffstat (limited to 'src/data_forms.py')
-rw-r--r--src/data_forms.py45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/data_forms.py b/src/data_forms.py
index 4fcb41cf..873aef85 100644
--- a/src/data_forms.py
+++ b/src/data_forms.py
@@ -16,7 +16,7 @@ import curses
from windows import g_lock
import windows
from tabs import Tab
-from theming import to_curses_attr
+from theming import to_curses_attr, get_theme
class DataFormsTab(Tab):
"""
@@ -114,6 +114,27 @@ class FieldInput(object):
"""
return ''
+class ColoredLabel(windows.Win):
+ def __init__(self, text):
+ self.text = text
+ self.color = get_theme().COLOR_NORMAL_TEXT
+ windows.Win.__init__(self)
+
+ def resize(self, height, width, y, x):
+ self._resize(height, width, y, x)
+
+ def set_color(self, color):
+ self.color = color
+ self.refresh()
+
+ def refresh(self):
+ with g_lock:
+ self._win.attron(to_curses_attr(self.color))
+ self.addstr(0, 0, self.text)
+ self._win.attroff(to_curses_attr(self.color))
+ self._refresh()
+
+
class DummyInput(FieldInput, windows.Win):
"""
Used for fields that do not require any input ('fixed')
@@ -399,7 +420,7 @@ class FormWin(object):
if field['type'] == 'fixed':
label = field.getValue()
inp = input_class(field)
- self.inputs.append({'label':label,
+ self.inputs.append({'label':ColoredLabel(label),
'description': desc,
'input':inp})
@@ -428,7 +449,8 @@ class FormWin(object):
return
if self.current_input == len(self.inputs) - 1 or self.current_input >= self.height-1:
return
- self.inputs[self.current_input]['input'].set_color((14, -1))
+ self.inputs[self.current_input]['input'].set_color(get_theme().COLOR_NORMAL_TEXT)
+ self.inputs[self.current_input]['label'].set_color(get_theme().COLOR_NORMAL_TEXT)
self.current_input += 1
jump = 0
while self.current_input+jump != len(self.inputs) - 1 and self.inputs[self.current_input+jump]['input'].is_dummy():
@@ -436,14 +458,16 @@ class FormWin(object):
if self.inputs[self.current_input+jump]['input'].is_dummy():
return
self.current_input += jump
- self.inputs[self.current_input]['input'].set_color((13, -1))
+ self.inputs[self.current_input]['input'].set_color(get_theme().COLOR_SELECTED_ROW)
+ self.inputs[self.current_input]['label'].set_color(get_theme().COLOR_SELECTED_ROW)
def go_to_previous_input(self):
if not self.inputs:
return
if self.current_input == 0:
return
- self.inputs[self.current_input]['input'].set_color((14, -1))
+ self.inputs[self.current_input]['input'].set_color(get_theme().COLOR_NORMAL_TEXT)
+ self.inputs[self.current_input]['label'].set_color(get_theme().COLOR_NORMAL_TEXT)
self.current_input -= 1
jump = 0
while self.current_input-jump > 0 and self.inputs[self.current_input+jump]['input'].is_dummy():
@@ -451,7 +475,8 @@ class FormWin(object):
if self.inputs[self.current_input+jump]['input'].is_dummy():
return
self.current_input -= jump
- self.inputs[self.current_input]['input'].set_color((13, -1))
+ self.inputs[self.current_input]['input'].set_color(get_theme().COLOR_SELECTED_ROW)
+ self.inputs[self.current_input]['label'].set_color(get_theme().COLOR_SELECTED_ROW)
def on_input(self, key):
if not self.inputs:
@@ -466,8 +491,7 @@ class FormWin(object):
for name, field in self._form.getFields():
if field['type'] == 'hidden':
continue
- label = self.inputs[i]['label']
- self._win.addstr(y, 0, label)
+ self.inputs[i]['label'].resize(1, self.width//3, y + 1, 0)
self.inputs[i]['input'].resize(1, self.width//3, y+1, 2*self.width//3)
# TODO: display the field description
y += 1
@@ -479,9 +503,12 @@ class FormWin(object):
if i >= self.height:
break
inp['input'].refresh()
+ inp['label'].refresh()
if self.current_input < self.height-1:
- self.inputs[self.current_input]['input'].set_color((13, -1))
+ self.inputs[self.current_input]['input'].set_color(get_theme().COLOR_SELECTED_ROW)
self.inputs[self.current_input]['input'].refresh()
+ self.inputs[self.current_input]['label'].set_color(get_theme().COLOR_SELECTED_ROW)
+ self.inputs[self.current_input]['label'].refresh()
def refresh_current_input(self):
self.inputs[self.current_input]['input'].refresh()