Exemplo n.º 1
0
 def do_command(self, key, raw=False):
     if not self.edition_input:
         if key == 'KEY_LEFT':
             if self.val_pos > 0:
                 self.val_pos -= 1
         elif key == 'KEY_RIGHT':
             if self.val_pos < len(self.options) - 1:
                 self.val_pos += 1
         elif key == '^M':
             self.edition_input = Input()
             self.edition_input.color = self.color
             self.edition_input.resize(self.height, self.width, self.y,
                                       self.x)
             self.edition_input.text = self.options[self.val_pos]
             self.edition_input.key_end()
     else:
         if key == '^M':
             self.options[self.val_pos] = self.edition_input.get_text()
             if not self.options[self.val_pos] and self.val_pos != len(
                     self.options) - 1:
                 del self.options[self.val_pos]
                 if self.val_pos == len(self.options) - 1:
                     self.val_pos -= 1
             self.edition_input = None
             if not self.options or self.options[-1] != '':
                 self.options.append('')
         else:
             self.edition_input.do_command(key)
     self.refresh()
Exemplo n.º 2
0
 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.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 3
0
 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.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 4
0
 def __init__(self, field) -> None:
     FieldInput.__init__(self, field)
     Input.__init__(self)
     jid = safeJID(field.jid)
     jid.resource = field.nick or None
     self.text = jid.full
     self.pos = len(self.text)
     self.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 5
0
 def __init__(self, field) -> None:
     FieldInput.__init__(self, field)
     Input.__init__(self)
     jid = safeJID(field.jid)
     jid.resource = field.nick or None
     self.text = jid.full
     self.pos = len(self.text)
     self.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 6
0
 def do_command(self, key, raw=False):
     if not self.edition_input:
         if key == 'KEY_LEFT':
             if self.val_pos > 0:
                 self.val_pos -= 1
         elif key == 'KEY_RIGHT':
             if self.val_pos < len(self.options) - 1:
                 self.val_pos += 1
         elif key == '^M':
             self.edition_input = Input()
             self.edition_input.color = self.color
             self.edition_input.resize(self.height, self.width, self.y,
                                       self.x)
             self.edition_input.text = self.options[self.val_pos]
             self.edition_input.key_end()
     else:
         if key == '^M':
             self.options[self.val_pos] = self.edition_input.get_text()
             if not self.options[self.val_pos] and self.val_pos != len(
                     self.options) - 1:
                 del self.options[self.val_pos]
                 if self.val_pos == len(self.options) - 1:
                     self.val_pos -= 1
             self.edition_input = None
             if not self.options or self.options[-1] != '':
                 self.options.append('')
         else:
             self.edition_input.do_command(key)
     self.refresh()
Exemplo n.º 7
0
class TextMultiWin(FieldInputMixin):
    def __init__(self, field):
        FieldInputMixin.__init__(self, field)
        options = field.get_value()
        if isinstance(options, list):
            self.options = options
        else:
            self.options = options.split('\n') if options else []
        self.val_pos = 0
        self.edition_input = None
        if not isinstance(self.options, list):
            if isinstance(self.options, str):
                self.options = [self.options]
            else:
                self.options = []
        self.options.append('')

    def do_command(self, key, raw=False):
        if not self.edition_input:
            if key == 'KEY_LEFT':
                if self.val_pos > 0:
                    self.val_pos -= 1
            elif key == 'KEY_RIGHT':
                if self.val_pos < len(self.options) - 1:
                    self.val_pos += 1
            elif key == '^M':
                self.edition_input = Input()
                self.edition_input.color = self.color
                self.edition_input.resize(self.height, self.width, self.y,
                                          self.x)
                self.edition_input.text = self.options[self.val_pos]
                self.edition_input.key_end()
        else:
            if key == '^M':
                self.options[self.val_pos] = self.edition_input.get_text()
                if not self.options[self.val_pos] and self.val_pos != len(
                        self.options) - 1:
                    del self.options[self.val_pos]
                    if self.val_pos == len(self.options) - 1:
                        self.val_pos -= 1
                self.edition_input = None
                if not self.options or self.options[-1] != '':
                    self.options.append('')
            else:
                self.edition_input.do_command(key)
        self.refresh()

    def refresh(self):
        if not self.edition_input:
            self._win.erase()
            self._win.attron(to_curses_attr(self.color))
            self.addnstr(0, 0, ' ' * self.width, self.width)
            option = self.options[self.val_pos]
            self.addstr(0, self.width // 2 - len(option) // 2, option)
            if self.val_pos > 0:
                self.addstr(0, 0, '←')
            if self.val_pos < len(self.options) - 1:
                self.addstr(0, self.width - 1, '→')
            self._win.attroff(to_curses_attr(self.color))
            self._refresh()
        else:
            self.edition_input.refresh()

    def reply(self):
        values = [val for val in self.options if val]
        self._field.set_answer(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
Exemplo n.º 8
0
 def __init__(self, field) -> None:
     FieldInput.__init__(self, field)
     Input.__init__(self)
     self.text = field.password or ''
     self.pos = len(self.text)
     self.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 9
0
 def __init__(self, field) -> None:
     FieldInput.__init__(self, field)
     Input.__init__(self)
     self.text = field.password or ''
     self.pos = len(self.text)
     self.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 10
0
 def __init__(self, field):
     FieldInput.__init__(self, field)
     Input.__init__(self)
     self.text = field.name
     self.pos = len(self.text)
     self.color = get_theme().COLOR_NORMAL_TEXT
Exemplo n.º 11
0
class TextMultiWin(FieldInputMixin):
    __slots__ = ('options', 'val_pos', 'edition_input')

    def __init__(self, field):
        FieldInputMixin.__init__(self, field)
        options = field.get_value()
        if isinstance(options, list):
            self.options = options
        else:
            self.options = options.split('\n') if options else []
        self.val_pos = 0
        self.edition_input = None
        if not isinstance(self.options, list):
            if isinstance(self.options, str):
                self.options = [self.options]
            else:
                self.options = []
        self.options.append('')

    def do_command(self, key, raw=False):
        if not self.edition_input:
            if key == 'KEY_LEFT':
                if self.val_pos > 0:
                    self.val_pos -= 1
            elif key == 'KEY_RIGHT':
                if self.val_pos < len(self.options) - 1:
                    self.val_pos += 1
            elif key == '^M':
                self.edition_input = Input()
                self.edition_input.color = self.color
                self.edition_input.resize(self.height, self.width, self.y,
                                          self.x)
                self.edition_input.text = self.options[self.val_pos]
                self.edition_input.key_end()
        else:
            if key == '^M':
                self.options[self.val_pos] = self.edition_input.get_text()
                if not self.options[self.val_pos] and self.val_pos != len(
                        self.options) - 1:
                    del self.options[self.val_pos]
                    if self.val_pos == len(self.options) - 1:
                        self.val_pos -= 1
                self.edition_input = None
                if not self.options or self.options[-1] != '':
                    self.options.append('')
            else:
                self.edition_input.do_command(key)
        self.refresh()

    def refresh(self):
        if not self.edition_input:
            self._win.erase()
            self._win.attron(to_curses_attr(self.color))
            self.addnstr(0, 0, ' ' * self.width, self.width)
            option = self.options[self.val_pos]
            self.addstr(0, self.width // 2 - len(option) // 2, option)
            if self.val_pos > 0:
                self.addstr(0, 0, '←')
            if self.val_pos < len(self.options) - 1:
                self.addstr(0, self.width - 1, '→')
            self._win.attroff(to_curses_attr(self.color))
            self._refresh()
        else:
            self.edition_input.refresh()

    def reply(self):
        values = [val for val in self.options if val]
        self._field.set_answer(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