Пример #1
0
    def __init__(self,
                 parent_mode,
                 title,
                 selection_cb,
                 close_cb=None,
                 input_cb=None,
                 allow_rearrange=False,
                 immediate_action=False,
                 **kwargs):
        """
        Args:
            parent_mode (basemode subclass): The mode which the popup will be drawn over
            title (str): the title of the popup window
            selection_cb (func): Function to be called on selection
            close_cb (func, optional): Function to be called when the popup is closed
            input_cb (func, optional): Function to be called on every keyboard input
            allow_rearrange (bool): Allow rearranging the selectable value
            immediate_action (bool): If immediate_action_cb should be called for every action
            kwargs (dict): Arguments passed to Popup

        """
        Popup.__init__(self, parent_mode, title, close_cb=close_cb, **kwargs)
        kwargs.update({
            'allow_rearrange': allow_rearrange,
            'immediate_action': immediate_action
        })
        BaseInputPane.__init__(self, self, **kwargs)
        self.selection_cb = selection_cb
        self.input_cb = input_cb
        self.hotkeys = {}
        self.cb_arg = {}
        self.cb_args = kwargs.get('cb_args', {})
        if 'base_popup' not in self.cb_args:
            self.cb_args['base_popup'] = self
Пример #2
0
 def refresh(self):
     self.screen.erase()
     height = self.get_content_height()
     self.ensure_content_pane_height(height + self.border_off_north +
                                     self.border_off_south)
     BaseInputPane.render_inputs(self, focused=True)
     BaseWindow.refresh(self)
Пример #3
0
    def __init__(self,
                 parent_mode,
                 title,
                 message,
                 align=ALIGN.DEFAULT,
                 height_req=0.75,
                 width_req=0.5,
                 **kwargs):
        self.message = message
        Popup.__init__(self,
                       parent_mode,
                       title,
                       align=align,
                       height_req=height_req,
                       width_req=width_req)
        BaseInputPane.__init__(self, self, immediate_action=True, **kwargs)
        lns = format_utils.wrap_string(self.message, self.width - 3, 3, True)

        if isinstance(self.height_req, float):
            self.height_req = min(
                len(lns) + 2, int(parent_mode.rows * self.height_req))

        self.handle_resize()
        self.no_refresh = False
        self.add_text_area('TextMessage', message)
Пример #4
0
    def __init__(self, name, preferences):
        PopupsHandler.__init__(self)
        self.preferences = preferences
        BaseWindow.__init__(self, '%s' % name, self.pane_width, preferences.height, posy=1, posx=self.pane_x_pos)
        BaseInputPane.__init__(self, preferences, border_off_east=1)
        self.name = name

        # have we scrolled down in the list
        self.input_offset = 0
Пример #5
0
 def __init__(self,
              torrentlist,
              width,
              height,
              title=None,
              allow_resize=False,
              **kwargs):
     BaseWindow.__init__(self, title, width, height, posy=1)
     BaseInputPane.__init__(self, self, immediate_action=True, **kwargs)
     self.parent = torrentlist
     self.focused = False
     self.allow_resize = allow_resize
Пример #6
0
    def __init__(self, name, preferences):
        PopupsHandler.__init__(self)
        self.preferences = preferences
        BaseWindow.__init__(self,
                            '%s' % name,
                            self.pane_width,
                            preferences.height,
                            posy=1,
                            posx=self.pane_x_pos)
        BaseInputPane.__init__(self, preferences, border_off_east=1)
        self.name = name

        # have we scrolled down in the list
        self.input_offset = 0
Пример #7
0
 def handle_read(self, c):
     if self.popup:
         ret = self.popup.handle_read(c)
         if self.popup and self.popup.closed():
             self.pop_popup()
         self.refresh()
         return ret
     return BaseInputPane.handle_read(self, c)
Пример #8
0
 def handle_read(self, c):
     if self.popup:
         ret = self.popup.handle_read(c)
         if self.popup and self.popup.closed():
             self.pop_popup()
         self.refresh()
         return ret
     return BaseInputPane.handle_read(self, c)
Пример #9
0
 def handle_read(self, c):
     if c == curses.KEY_UP:
         self.move_active_up(1)
     elif c == curses.KEY_DOWN:
         self.move_active_down(1)
     elif self.allow_resize and c in [ord('+'), ord('-')]:
         width = self.visible_content_pane_width + (1 if c == ord('+') else - 1)
         self.on_resize(width)
     else:
         return BaseInputPane.handle_read(self, c)
     return util.ReadState.READ
Пример #10
0
 def handle_read(self, c):
     if c == curses.KEY_UP:
         self.move_active_up(1)
     elif c == curses.KEY_DOWN:
         self.move_active_down(1)
     elif self.allow_resize and c in [ord('+'), ord('-')]:
         width = self.visible_content_pane_width + (1 if c == ord('+') else
                                                    -1)
         self.on_resize(width)
     else:
         return BaseInputPane.handle_read(self, c)
     return util.ReadState.READ
Пример #11
0
    def handle_read(self, c):
        ret = BaseInputPane.handle_read(self, c)
        if ret != util.ReadState.IGNORED:
            return ret

        if c in [curses.KEY_ENTER, util.KEY_ENTER2]:
            if self.close_cb:
                self._handle_callback(state_changed=False, close=False)
                util.safe_curs_set(util.Curser.INVISIBLE)
            return util.ReadState.READ
        elif c == util.KEY_ESC:  # close on esc, no action
            self._handle_callback(state_changed=False, close=True)
            self.close(None)
            return util.ReadState.READ

        self.refresh()
        return util.ReadState.READ
Пример #12
0
    def handle_read(self, c):
        if c in [curses.KEY_ENTER, util.KEY_ENTER2]:
            for k, v in self.get_values().items():
                if v['active']:
                    if self.selection_cb(
                            k, **dict(self.cb_args, data=self.cb_arg)):
                        self.close(None)
            return util.ReadState.READ
        else:
            ret = BaseInputPane.handle_read(self, c)
            if ret != util.ReadState.IGNORED:
                return ret
            ret = Popup.handle_read(self, c)
            if ret != util.ReadState.IGNORED:
                if self.selection_cb(None):
                    self.close(None)
                return ret

            if self.input_cb:
                self.input_cb(c)

        self.refresh()
        return util.ReadState.IGNORED
Пример #13
0
 def refresh(self):
     height = self.get_content_height()
     self.ensure_content_pane_height(height + self.border_off_north +
                                     self.border_off_south)
     BaseInputPane.render_inputs(self, focused=self.has_focus())
     BaseWindow.refresh(self)
Пример #14
0
 def __init__(self, parent_mode, title, **kwargs):
     Popup.__init__(self, parent_mode, title, **kwargs)
     BaseInputPane.__init__(self, self, **kwargs)
     # We need to replicate some things in order to wrap our inputs
     self.encoding = parent_mode.encoding
Пример #15
0
 def handle_read(self, c):
     ret = BaseInputPane.handle_read(self, c)
     if ret != util.ReadState.IGNORED:
         return ret
     return Popup.handle_read(self, c)
Пример #16
0
 def __init__(self, torrentlist, width, height, title=None, allow_resize=False, **kwargs):
     BaseWindow.__init__(self, title, width, height, posy=1)
     BaseInputPane.__init__(self, self, immediate_action=True, **kwargs)
     self.parent = torrentlist
     self.focused = False
     self.allow_resize = allow_resize
Пример #17
0
 def refresh(self):
     height = self.get_content_height()
     self.ensure_content_pane_height(height + self.border_off_north + self.border_off_south)
     BaseInputPane.render_inputs(self, focused=self.has_focus())
     BaseWindow.refresh(self)
Пример #18
0
 def _refresh(self):
     self.screen.erase()
     height = self.get_content_height()
     self.ensure_content_pane_height(height + self.border_off_north + self.border_off_south)
     BaseInputPane.render_inputs(self, focused=True)
     BaseWindow.refresh(self)