Example #1
0
class RightColumnView(urwid.Frame):
    """
    Displays the users list on the right side of the app.
    """
    def __init__(self, view: Any) -> None:
        self.view = view
        self.user_search = UserSearchBox(self)
        urwid.connect_signal(self.user_search, 'change', self.update_user_list)
        self.view.user_search = self.user_search
        search_box = urwid.LineBox(self.user_search)
        self.search_lock = threading.Lock()
        super(RightColumnView, self).__init__(self.users_view(),
                                              header=search_box)

    @async
    def update_user_list(self, search_box: Any, new_text: str) -> None:
        if not self.view.controller.editor_mode:
            return
        # wait for any previously started search to finish to avoid
        # displaying wrong user list.
        self.search_lock.acquire()
        users_display = self.users_btn_list.copy()
        for user in self.users_btn_list:
            if not match_user(user, new_text):
                users_display.remove(user)
        self.body = UsersView(urwid.SimpleFocusListWalker(users_display))
        self.set_body(self.body)
        self.view.controller.loop.draw_screen()
        self.search_lock.release()

    def users_view(self) -> Any:
        self.users_btn_list = list()  # type: List[Any]
        for user in self.view.users:
            unread_count = self.view.model.unread_counts.get(
                user['user_id'], 0)
            self.users_btn_list.append(
                UserButton(user,
                           controller=self.view.controller,
                           view=self.view,
                           color=user['status'],
                           count=unread_count))
        self.user_w = UsersView(
            urwid.SimpleFocusListWalker(self.users_btn_list))
        self.view.user_w = self.user_w
        return self.user_w

    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if key == 'w':
            self.set_focus('header')
            return key
        elif key == 'esc':
            self.user_search.set_edit_text("Search People")
            self.body = UsersView(
                urwid.SimpleFocusListWalker(self.users_btn_list))
            self.set_body(self.body)
            self.set_focus('body')
            self.view.controller.loop.draw_screen()
            return key
        return super(RightColumnView, self).keypress(size, key)
Example #2
0
 def __init__(self, view: Any) -> None:
     self.view = view
     self.user_search = UserSearchBox(self)
     urwid.connect_signal(self.user_search, 'change', self.update_user_list)
     self.view.user_search = self.user_search
     search_box = urwid.LineBox(self.user_search)
     self.search_lock = threading.Lock()
     super(RightColumnView, self).__init__(self.users_view(),
                                           header=search_box)
Example #3
0
 def __init__(self, width: int, view: Any) -> None:
     self.width = width
     self.view = view
     self.user_search = UserSearchBox(self)
     urwid.connect_signal(self.user_search, 'change',
                          self.update_user_list)
     self.view.user_search = self.user_search
     search_box = urwid.LineBox(
         self.user_search, tlcorner=u'─', tline=u'─', lline=u'',
         trcorner=u'─', blcorner=u'─', rline=u'',
         bline=u'─', brcorner=u'─'
         )
     self.search_lock = threading.Lock()
     super(RightColumnView, self).__init__(self.users_view(),
                                           header=search_box)
Example #4
0
class RightColumnView(urwid.Frame):
    """
    Displays the users list on the right side of the app.
    """
    def __init__(self, width: int, view: Any) -> None:
        self.width = width
        self.view = view
        self.user_search = UserSearchBox(self)
        urwid.connect_signal(self.user_search, 'change', self.update_user_list)
        self.view.user_search = self.user_search
        search_box = urwid.LineBox(self.user_search,
                                   tlcorner=u'─',
                                   tline=u'─',
                                   lline=u'',
                                   trcorner=u'─',
                                   blcorner=u'─',
                                   rline=u'',
                                   bline=u'─',
                                   brcorner=u'─')
        self.search_lock = threading.Lock()
        super(RightColumnView, self).__init__(self.users_view(),
                                              header=search_box)

    @asynch
    def update_user_list(self, search_box: Any, new_text: str) -> None:
        if not self.view.controller.editor_mode:
            return
        # wait for any previously started search to finish to avoid
        # displaying wrong user list.
        self.search_lock.acquire()
        users = self.view.users.copy()
        users_display = users.copy()
        for user in users:
            if not match_user(user, new_text):
                users_display.remove(user)
        self.body = self.users_view(users_display)
        self.set_body(self.body)
        self.view.controller.update_screen()
        self.search_lock.release()

    def users_view(self, users: Any = None) -> Any:
        reset_default_view_users = False
        if users is None:
            users = self.view.users.copy()
            reset_default_view_users = True
        users_btn_list = list()  # type: List[Any]
        for user in users:
            # Only include `inactive` users in search result.
            if user['status'] == 'inactive' and\
                    not self.view.controller.editor_mode:
                continue
            unread_count = self.view.model.unread_counts.get(
                user['user_id'], 0)
            users_btn_list.append(
                UserButton(user,
                           controller=self.view.controller,
                           view=self.view,
                           width=self.width,
                           color=user['status'],
                           count=unread_count))
        user_w = UsersView(urwid.SimpleFocusListWalker(users_btn_list))
        # Donot reset them while searching.
        if reset_default_view_users:
            self.users_btn_list = users_btn_list
            self.view.user_w = user_w
        return user_w

    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if is_command_key('SEARCH_PEOPLE', key):
            self.set_focus('header')
            return key
        elif is_command_key('GO_BACK', key):
            self.user_search.set_edit_text("Search People")
            self.body = UsersView(
                urwid.SimpleFocusListWalker(self.users_btn_list))
            self.set_body(self.body)
            self.set_focus('body')
            self.view.controller.update_screen()
            return key
        elif is_command_key('GO_LEFT', key):
            self.view.show_right_panel(visible=False)
        return super(RightColumnView, self).keypress(size, key)