diff options
Diffstat (limited to 'poezio/windows/data_forms.py')
-rw-r--r-- | poezio/windows/data_forms.py | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/poezio/windows/data_forms.py b/poezio/windows/data_forms.py index dc954bd7..db174703 100644 --- a/poezio/windows/data_forms.py +++ b/poezio/windows/data_forms.py @@ -6,6 +6,7 @@ does not inherit from the Win base class), as it will create the others when needed. """ +from typing import Type from poezio.windows import base_wins from poezio.windows.base_wins import Win from poezio.windows.inputs import Input @@ -20,6 +21,9 @@ class FieldInput: 'windows' library. """ + # XXX: This conflicts with Win in the FieldInputMixin. + #__slots__ = ('_field', 'color') + def __init__(self, field): self._field = field self.color = get_theme().COLOR_NORMAL_TEXT @@ -47,6 +51,8 @@ class FieldInput: class FieldInputMixin(FieldInput, Win): "Mix both FieldInput and Win" + __slots__ = () + def __init__(self, field): FieldInput.__init__(self, field) Win.__init__(self) @@ -60,6 +66,8 @@ class FieldInputMixin(FieldInput, Win): class ColoredLabel(Win): + __slots__ = ('text', 'color') + def __init__(self, text): self.text = text self.color = get_theme().COLOR_NORMAL_TEXT @@ -85,6 +93,8 @@ class DummyInput(FieldInputMixin): Used for fields that do not require any input ('fixed') """ + __slots__ = () + def __init__(self, field): FieldInputMixin.__init__(self, field) @@ -99,6 +109,8 @@ class DummyInput(FieldInputMixin): class BooleanWin(FieldInputMixin): + __slots__ = ('last_key', 'value') + def __init__(self, field): FieldInputMixin.__init__(self, field) self.last_key = 'KEY_RIGHT' @@ -133,6 +145,8 @@ class BooleanWin(FieldInputMixin): class TextMultiWin(FieldInputMixin): + __slots__ = ('options', 'val_pos', 'edition_input') + def __init__(self, field): FieldInputMixin.__init__(self, field) options = field.get_value() @@ -176,7 +190,7 @@ class TextMultiWin(FieldInputMixin): if not self.options or self.options[-1] != '': self.options.append('') else: - self.edition_input.do_command(key) + self.edition_input.do_command(key, raw=raw) self.refresh() def refresh(self): @@ -212,6 +226,8 @@ class TextMultiWin(FieldInputMixin): class ListMultiWin(FieldInputMixin): + __slots__ = ('options', 'val_pos') + def __init__(self, field): FieldInputMixin.__init__(self, field) values = field.get_value() or [] @@ -257,10 +273,12 @@ class ListMultiWin(FieldInputMixin): self._field.set_answer(values) def get_help_message(self): - return '←, →: Switch between the value. Space: select or unselect a value' + return '←, →: Switch between the value. Space: select or deselect a value' class ListSingleWin(FieldInputMixin): + __slots__ = ('options', 'val_pos') + def __init__(self, field): FieldInputMixin.__init__(self, field) # the option list never changes @@ -306,12 +324,15 @@ class ListSingleWin(FieldInputMixin): class TextSingleWin(FieldInputMixin, Input): + __slots__ = ('text', 'pos') + def __init__(self, field): FieldInputMixin.__init__(self, field) Input.__init__(self) self.text = field.get_value() if isinstance(field.get_value(), str)\ else "" - self.pos = len(self.text) + self.pos = 0 + self.view_pos = 0 self.color = get_theme().COLOR_NORMAL_TEXT def reply(self): @@ -323,6 +344,8 @@ class TextSingleWin(FieldInputMixin, Input): class TextPrivateWin(TextSingleWin): + __slots__ = () + def __init__(self, field): TextSingleWin.__init__(self, field) @@ -352,6 +375,8 @@ class FormWin: On resize, move and resize all the subwin and define how the text will be written On refresh, write all the text, and refresh all the subwins """ + __slots__ = ('_win', 'height', 'width', '_form', 'scroll_pos', 'current_input', 'inputs') + input_classes = { 'boolean': BooleanWin, 'fixed': DummyInput, @@ -373,10 +398,10 @@ class FormWin: for (name, field) in self._form.getFields().items(): if field['type'] == 'hidden': continue - try: + if field['type'] not in self.input_classes: + input_class: Type[FieldInputMixin] = TextSingleWin + else: input_class = self.input_classes[field['type']] - except IndexError: - continue label = field['label'] desc = field['desc'] if field['type'] == 'fixed': @@ -415,10 +440,11 @@ class FormWin: return if self.current_input == len(self.inputs) - 1: return + theme = get_theme() self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_input += 1 jump = 0 while self.current_input + jump != len( @@ -437,19 +463,20 @@ class FormWin: self.scroll_pos += 1 self.refresh() self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def go_to_previous_input(self): if not self.inputs: return if self.current_input == 0: return + theme = get_theme() self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_NORMAL_TEXT) + theme.COLOR_NORMAL_TEXT) self.current_input -= 1 jump = 0 while self.current_input - jump > 0 and self.inputs[self.current_input @@ -466,9 +493,9 @@ class FormWin: self.refresh() self.current_input -= jump self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) self.inputs[self.current_input]['label'].set_color( - get_theme().COLOR_SELECTED_ROW) + theme.COLOR_SELECTED_ROW) def on_input(self, key, raw=False): if not self.inputs: @@ -498,11 +525,10 @@ class FormWin: inp['input'].refresh() inp['label'].refresh() if self.inputs and self.current_input < self.height - 1: - self.inputs[self.current_input]['input'].set_color( - get_theme().COLOR_SELECTED_ROW) + color = get_theme().COLOR_SELECTED_ROW + self.inputs[self.current_input]['input'].set_color(color) 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'].set_color(color) self.inputs[self.current_input]['label'].refresh() def refresh_current_input(self): |