Esempio n. 1
0
    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if is_command_key('ENTER', key):
            self.user_view.view.controller.editor_mode = False
            self.user_view.set_focus("body")
        if is_command_key('GO_BACK', key):
            self.user_view.view.controller.editor_mode = False
            self.set_edit_text("Search people")
            self.user_view.set_focus("body")
            self.user_view.keypress(size, 'esc')

        return super(UserSearchBox, self).keypress(size, key)
Esempio n. 2
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     if is_command_key('SEARCH_STREAMS', key):
         self.set_focus('header')
         return key
     elif is_command_key('GO_BACK', key):
         self.search_box.set_edit_text("Search streams")
         self.log.clear()
         self.log.extend(self.streams_btn_list)
         self.set_focus('body')
         self.view.controller.update_screen()
         return key
     return super(StreamsView, self).keypress(size, key)
Esempio n. 3
0
 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
     return super(RightColumnView, self).keypress(size, key)
Esempio n. 4
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     if is_command_key('ENTER', key):
         if self.message['type'] == 'private':
             self.model.controller.view.write_box.private_box_view(
                 email=self.get_recipients()
             )
         elif self.message['type'] == 'stream':
             self.model.controller.view.write_box.stream_box_view(
                 caption=self.message['display_recipient'],
                 title=self.message['subject']
             )
     elif is_command_key('STREAM_MESSAGE', key):
         if self.message['type'] == 'private':
             self.model.controller.view.write_box.private_box_view(
                 email=self.get_recipients()
             )
         elif self.message['type'] == 'stream':
             self.model.controller.view.write_box.stream_box_view(
                 caption=self.message['display_recipient']
             )
     elif is_command_key('STREAM_NARROW', key):
         if self.message['type'] == 'private':
             self.model.controller.narrow_to_user(self)
         elif self.message['type'] == 'stream':
             self.model.controller.narrow_to_stream(self)
     elif is_command_key('TOPIC_NARROW', key):
         if self.message['type'] == 'private':
             self.model.controller.narrow_to_user(self)
         elif self.message['type'] == 'stream':
             self.model.controller.narrow_to_topic(self)
     elif is_command_key('GO_BACK', key):
         self.model.controller.show_all_messages(self)
     elif is_command_key('REPLY_AUTHOR', key):
         self.model.controller.view.write_box.private_box_view(
             email=self.message['sender_email']
         )
     elif is_command_key('ALL_PM', key):
         self.model.controller.show_all_pm(self)
     elif is_command_key('MENTION_REPLY', key):
         self.keypress(size, 'enter')
         mention = '@**' + self.message['sender_full_name'] + '** '
         self.model.controller.view.write_box.msg_write_box.set_edit_text(
             mention)
         self.model.controller.view.write_box.msg_write_box.set_edit_pos(
             len(mention))
         self.model.controller.view.middle_column.set_focus('footer')
     elif is_command_key('QUOTE_REPLY', key):
         self.keypress(size, 'enter')
         quote = '```quote\n' + self.message['content'] + '\n```\n'
         self.model.controller.view.write_box.msg_write_box.set_edit_text(
             quote)
         self.model.controller.view.write_box.msg_write_box.set_edit_pos(
             len(quote))
         self.model.controller.view.middle_column.set_focus('footer')
     return key
Esempio n. 5
0
    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if is_command_key('GO_BACK', key):
            self.text_box.set_edit_text("")
            self.controller.editor_mode = False
            self.controller.view.middle_column.set_focus('body')
            return key

        elif is_command_key('ENTER', key):
            self.controller.editor_mode = False
            self.controller.model.index['search'] = set()
            self.controller.search_messages(self.text_box.edit_text)
            self.controller.view.middle_column.set_focus('body')
            return key

        key = super(SearchBox, self).keypress(size, key)
        return key
Esempio n. 6
0
    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if is_command_key('NEXT_MESSAGE', key) and not self.new_loading:
            try:
                position = self.log.next_position(self.focus_position)
                self.set_focus(position, 'above')
                self.set_focus_valign('middle')

                return key
            except Exception:
                if self.focus:
                    id = self.focus.original_widget.message['id']
                    self.load_new_messages(id)
                return key

        elif is_command_key('PREVIOUS_MESSAGE', key) and not self.old_loading:
            try:
                position = self.log.prev_position(self.focus_position)
                self.set_focus(position, 'below')
                self.set_focus_valign('middle')
                return key
            except Exception:
                if self.focus:
                    id = self.focus.original_widget.message['id']
                    self.load_old_messages(id)
                else:
                    self.load_old_messages()
                return key

        elif is_command_key('SCROLL_TO_TOP', key) and not self.old_loading:
            if self.focus_position == 0:
                return self.keypress(size, 'up')
            else:
                return super(MessageView, self).keypress(size, 'page up')

        elif is_command_key('SCROLL_TO_BOTTOM', key) and not self.old_loading:
            if self.focus_position == len(self.log) - 1:
                return self.keypress(size, 'down')
            else:
                return super(MessageView, self).keypress(size, 'page down')

        elif is_command_key('THUMBS_UP', key):
            self.model.react_to_message(self.focus.original_widget.message,
                                        reaction_to_toggle='thumbs_up')
            return key

        key = super(MessageView, self).keypress(size, key)
        return key
Esempio n. 7
0
    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if is_command_key('GO_BACK', key):
            self.header.keypress(size, 'esc')
            self.footer.keypress(size, 'esc')
            self.set_focus('body')

        elif self.focus_position in ['footer', 'header']:
            return super(MiddleColumnView, self).keypress(size, key)

        elif is_command_key('SEARCH_MESSAGES', key):
            self.controller.editor_mode = True
            self.controller.editor = self.search_box
            self.set_focus('header')
            return key

        elif is_command_key('REPLY_MESSAGE', key):
            self.body.keypress(size, 'enter')
            self.set_focus('footer')
            self.footer.focus_position = 1
            return key

        elif is_command_key('STREAM_MESSAGE', key):
            self.body.keypress(size, 'c')
            self.set_focus('footer')
            self.footer.focus_position = 0
            return key

        elif is_command_key('REPLY_AUTHOR', key):
            self.body.keypress(size, 'R')
            self.set_focus('footer')
            self.footer.focus_position = 1
            return key

        elif is_command_key('NEXT_UNREAD_TOPIC', key):
            # narrow to next unread topic
            stream_topic = self.get_next_unread_topic()
            if stream_topic is None:
                return key
            stream, topic = stream_topic
            self.controller.narrow_to_topic(TopicButton(stream, topic,
                                                        self.model))
            return key
        elif is_command_key('NEXT_UNREAD_PM', key):
            # narrow to next unread pm
            pm = self.get_next_unread_pm()
            if pm is None:
                return key
            email = self.model.user_id_email_dict[pm]
            self.controller.narrow_to_user(UnreadPMButton(pm, email))
        elif is_command_key('PRIVATE_MESSAGE', key):
            # Create new PM message
            self.footer.private_box_view()
            self.set_focus('footer')
            self.footer.focus_position = 0
            return key
        return super(MiddleColumnView, self).keypress(size, key)
Esempio n. 8
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     if is_command_key('ENTER', key):
         self.controller.narrow_to_user(self)
         self.view.body.focus_col = 1
         self.view.body.focus.original_widget.set_focus('footer')
         self.view.write_box.private_box_view(self)
         self.view.toggle_left_panel()
     return super(UserButton, self).keypress(size, key)
Esempio n. 9
0
    def keypress(self, size: Tuple[int, int], key: str) -> str:
        if is_command_key('SEND_MESSAGE', key):
            if not self.to_write_box:
                request = {
                    'type': 'stream',
                    'to': self.stream_write_box.edit_text,
                    'subject': self.title_write_box.edit_text,
                    'content': self.msg_write_box.edit_text,
                }
                response = self.client.send_message(request)
            else:
                request = {
                    'type': 'private',
                    'to': self.to_write_box.edit_text,
                    'content': self.msg_write_box.edit_text,
                }
                response = self.client.send_message(request)
            if response['result'] == 'success':
                self.msg_write_box.edit_text = ''
        elif is_command_key('GO_BACK', key):
            self.view.controller.editor_mode = False
            self.main_view(False)
            self.view.middle_column.set_focus('body')
        elif is_command_key('TAB', key):
            if len(self.contents) == 0:
                return key
            # toggle focus position
            if self.focus_position == 0 and self.to_write_box is None:
                if self.contents[0][0].focus_col == 0:
                    self.contents[0][0].focus_col = 1
                    return key
                else:
                    self.contents[0][0].focus_col = 0
            self.focus_position = self.focus_position == 0
            self.contents[0][0].focus_col = 0

        key = super(WriteBox, self).keypress(size, key)
        return key
Esempio n. 10
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     if is_command_key('QUIT_HELP', key):
         self.controller.exit_help()
     return super(HelpView, self).keypress(size, key)
Esempio n. 11
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     if is_command_key('SEARCH_STREAMS', key):
         self.focus_position = 1
         self.view.stream_w.keypress(size, key)
         return key
     return super(LeftColumnView, self).keypress(size, key)
Esempio n. 12
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     if is_command_key('ENTER', key):
         self.controller.view.toggle_left_panel()
     return super(StreamButton, self).keypress(size, key)
Esempio n. 13
0
 def keypress(self, size: Tuple[int, int], key: str) -> str:
     self.model.new_user_input = True
     if self.controller.editor_mode:
         return self.controller.editor.keypress((size[1], ), key)
     # Redirect commands to message_view.
     elif is_command_key('GO_BACK', key):
         self.toggle_left_panel()
     elif is_command_key('SEARCH_MESSAGES', key) or\
             is_command_key('NEXT_UNREAD_TOPIC', key) or\
             is_command_key('NEXT_UNREAD_PM', key) or\
             is_command_key('PRIVATE_MESSAGE', key):
         self.body.focus_col = 1
         self.middle_column.keypress(size, key)
         return key
     elif is_command_key('SEARCH_PEOPLE', key):
         self.body.contents[0] = (
             self.right_column,
             self.body.options(width_type='given', width_amount=25),
         )
         # Start User Search if not in editor_mode
         self.users_view.keypress(size, 'w')
         self.body.focus_col = 0
         self.user_search.set_edit_text("")
         self.controller.editor_mode = True
         self.controller.editor = self.user_search
         return key
     elif is_command_key('SEARCH_STREAMS', key):
         self.body.contents[0] = (
             self.left_column,
             self.body.options(width_type='given', width_amount=25),
         )
         # jump stream search
         self.left_col_w.keypress(size, 'q')
         self.body.focus_col = 0
         self.stream_w.search_box.set_edit_text("")
         self.controller.editor_mode = True
         self.controller.editor = self.stream_w.search_box
         return key
     elif is_command_key('HELP', key):
         # Show help menu
         self.controller.show_help()
         return key
     # replace alternate keys with arrow/functional keys
     # This is needed for navigating in widgets
     # other than message_view.
     elif is_command_key('PREVIOUS_MESSAGE', key):
         key = 'up'
     elif is_command_key('NEXT_MESSAGE', key):
         key = 'down'
     elif is_command_key('GO_LEFT', key):
         key = 'left'
     elif is_command_key('GO_RIGHT', key):
         key = 'right'
     elif is_command_key('SCROLL_TO_TOP', key):
         key = 'page up'
     elif is_command_key('SCROLL_TO_BOTTOM', key):
         key = 'page down'
     elif is_command_key('END_MESSAGE', key):
         key = 'end'
     return super(View, self).keypress(size, key)