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 elif is_command_key('GO_LEFT', key): self.view.show_left_panel(visible=True) elif is_command_key('GO_RIGHT', key): self.view.show_right_panel(visible=True) return super(MiddleColumnView, self).keypress(size, key)
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('TOGGLE_TOPIC', key): # Exit topic view self.view.left_panel.contents[1] = (self.view.left_panel.stream_v, self.view.left_panel.options( height_type="weight")) self.view.left_panel.is_in_topic_view = False elif is_command_key('GO_RIGHT', key): self.view.show_left_panel(visible=False) self.view.body.focus_col = 1 if is_command_key('SEARCH_TOPICS', key): self.set_focus('header') self.header_list.set_focus(2) return key elif is_command_key('GO_BACK', key): self.topic_search_box.reset_search_text() self.log.clear() self.log.extend(self.topics_btn_list) self.set_focus('body') self.log.set_focus(self.focus_index_before_search) self.view.controller.update_screen() return key return_value = super().keypress(size, key) _, self.focus_index_before_search = self.log.get_focus() return return_value
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('SEND_MESSAGE', key): if not self.to_write_box: success = self.model.send_stream_message( stream=self.stream_write_box.edit_text, topic=self.title_write_box.edit_text, content=self.msg_write_box.edit_text ) else: success = self.model.send_private_message( recipients=self.to_write_box.edit_text, content=self.msg_write_box.edit_text ) if 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
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 elif is_command_key('GO_RIGHT', key): self.view.show_left_panel(visible=False) return super(LeftColumnView, self).keypress(size, key)
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('TOGGLE_TOPIC', key): self.view.left_panel.show_topic_view(self) elif is_command_key('TOGGLE_MUTE_STREAM', key): self.controller.stream_muting_confirmation_popup(self) elif is_command_key('STREAM_DESC', key): self.model.controller.show_stream_info(self.stream_id) return super().keypress(size, key)
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('ALL_STARRED', key): self.model.controller.show_all_starred(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
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if self.is_in_typeahead_mode: if not (is_command_key('AUTOCOMPLETE', key) or is_command_key('AUTOCOMPLETE_REVERSE', key)): # set default footer when done with autocomplete self.is_in_typeahead_mode = False self.view.set_footer_text() if is_command_key('SEND_MESSAGE', key): if self.msg_edit_id: if not self.to_write_box: success = self.model.update_stream_message( topic=self.title_write_box.edit_text, content=self.msg_write_box.edit_text, msg_id=self.msg_edit_id, ) else: success = self.model.update_private_message( content=self.msg_write_box.edit_text, msg_id=self.msg_edit_id, ) else: if not self.to_write_box: success = self.model.send_stream_message( stream=self.stream_write_box.edit_text, topic=self.title_write_box.edit_text, content=self.msg_write_box.edit_text) else: success = self.model.send_private_message( recipients=self.to_write_box.edit_text, content=self.msg_write_box.edit_text) if success: self.msg_write_box.edit_text = '' if self.msg_edit_id: self.msg_edit_id = None self.keypress(size, 'esc') elif is_command_key('GO_BACK', key): self.msg_edit_id = None self.view.controller.exit_editor_mode() 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().keypress(size, key) return key
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('TOGGLE_TOPIC', key): topic_view = self.view.left_panel.topics_view(self) self.view.left_panel.is_in_topic_view = True self.view.left_panel.contents[1] = (topic_view, self.view.left_panel.options( height_type="weight")) elif is_command_key('TOGGLE_MUTE_STREAM', key): self.controller.stream_muting_confirmation_popup(self) return super().keypress(size, key)
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.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)
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)
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('TOGGLE_TOPIC', key): # Exit topic view self.view.left_panel.contents[1] = (self.view.left_panel.stream_v, self.view.left_panel.options( height_type="weight")) self.view.left_panel.is_in_topic_view = False elif is_command_key('GO_RIGHT', key): self.view.show_left_panel(visible=False) self.view.body.focus_col = 1 return super(TopicsView, self).keypress(size, key)
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('ENTER', key): self.panel_view.view.controller.editor_mode = False self.panel_view.set_focus("body") if hasattr(self.panel_view, 'log') and len(self.panel_view.log): self.panel_view.body.set_focus(0) elif is_command_key('GO_BACK', key): self.panel_view.view.controller.editor_mode = False self.set_edit_text(self.search_text) self.panel_view.set_focus("body") self.panel_view.keypress(size, 'esc') return super().keypress(size, key)
def keypress(self, size: Tuple[int, int], key: str) -> str: if (is_command_key('SEARCH_STREAMS', key) or is_command_key('SEARCH_TOPICS', key)): self.focus_position = 1 if self.is_in_topic_view: self.view.topic_w.keypress(size, key) else: self.view.stream_w.keypress(size, key) return key elif is_command_key('GO_RIGHT', key): self.view.show_left_panel(visible=False) return super().keypress(size, key)
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('TOGGLE_TOPIC', key): topic_view = self.view.left_panel.topics_view(self) self.view.left_panel.is_in_topic_view = True self.view.left_panel.contents[1] = (topic_view, self.view.left_panel.options( height_type="weight")) elif is_command_key('TOGGLE_MUTE_STREAM', key): self.controller.stream_muting_confirmation_popup(self) elif is_command_key('STREAM_DESC', key): self.model.controller.show_stream_info(self.stream_id) return super().keypress(size, key)
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('ENTER', key): self.panel_view.view.controller.editor_mode = False self.panel_view.set_focus("body") if hasattr(self.panel_view, 'log') and len(self.panel_view.log): self.panel_view.body.set_focus(0) elif is_command_key('GO_BACK', key): self.panel_view.view.controller.editor_mode = False self.set_edit_text(self.search_text) self.panel_view.set_focus("body") self.panel_view.keypress(size, 'esc') return super(PanelSearchBox, self).keypress(size, key)
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('ENTER', key): self.panel_view.view.controller.exit_editor_mode() self.set_caption([('filter_results', 'Search Results'), ' ']) self.panel_view.set_focus("body") if hasattr(self.panel_view, 'log') and len(self.panel_view.log): self.panel_view.body.set_focus(0) elif is_command_key('GO_BACK', key): self.panel_view.view.controller.exit_editor_mode() self.reset_search_text() self.panel_view.set_focus("body") self.panel_view.keypress(size, 'esc') return super().keypress(size, key)
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.log.clear() self.log.extend(self.streams_btn_list) self.set_focus('body') self.log.set_focus(self.focus_index_before_search) self.view.controller.update_screen() return key return_value = super().keypress(size, key) _, self.focus_index_before_search = self.log.get_focus() return return_value
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('SEARCH_PEOPLE', key): self.allow_update_user_list = False self.set_focus('header') return key elif is_command_key('GO_BACK', key): self.allow_update_user_list = True self.body = UsersView(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().keypress(size, key)
def keypress(self, size: urwid_Size, key: str) -> Optional[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.search_messages(self.text_box.edit_text) self.controller.view.middle_column.set_focus('body') return key key = super().keypress(size, key) return key
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)
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.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
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('SEARCH_PEOPLE', key): self.allow_update_user_list = False self.set_focus('header') return key elif is_command_key('GO_BACK', key): self.user_search.reset_search_text() self.allow_update_user_list = True self.body = UsersView(self.view.controller, 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().keypress(size, key)
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) return key return super(UserButton, self).keypress(size, key)
def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('TOGGLE_TOPIC', key): # Exit topic view self.view.left_panel.contents[1] = (self.view.left_panel.stream_v, self.view.left_panel.options( height_type="weight")) self.view.left_panel.is_in_topic_view = False elif is_command_key('GO_RIGHT', key): self.view.show_left_panel(visible=False) self.view.body.focus_col = 1 if is_command_key('SEARCH_TOPICS', key): self.header_list.set_focus(2) return key elif is_command_key('GO_BACK', key): self.log.clear() self.log.extend(self.topics_btn_list) self.set_focus('body') self.view.controller.update_screen() return key return super().keypress(size, key)
def test_keypress_navigation(self, mocker, widget_size, navigation_key_expected_key_pair): key, expected_key = navigation_key_expected_key_pair size = widget_size(self.pop_up_view) # Patch `is_command_key` to not raise an 'Invalid Command' exception # when its parameters are (self.command, key) as there is no # self.command='COMMAND' command in keys.py. mocker.patch( VIEWS + '.is_command_key', side_effect=( lambda command, key: False if command == self.command else is_command_key(command, key))) self.pop_up_view.keypress(size, key) self.super_keypress.assert_called_once_with(size, expected_key)
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, } 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
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: if is_command_key('GO_DOWN', 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('GO_UP', 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_UP', key) and not self.old_loading: if (self.focus is not None and self.focus_position == 0): return self.keypress(size, 'up') else: return super().keypress(size, 'page up') elif is_command_key('SCROLL_DOWN', key) and not self.old_loading: if (self.focus is not None and self.focus_position == len(self.log) - 1): return self.keypress(size, 'down') else: return super().keypress(size, 'page down') elif is_command_key('THUMBS_UP', key): if self.focus is not None: self.model.react_to_message( self.focus.original_widget.message, reaction_to_toggle='thumbs_up') elif is_command_key('TOGGLE_STAR_STATUS', key): if self.focus is not None: message = self.focus.original_widget.message self.model.toggle_message_star_status(message) key = super().keypress(size, key) return key
def keypress(self, size: urwid_Size, key: str) -> str: if is_command_key('GO_BACK', key) or is_command_key(self.command, key): self.controller.exit_popup() elif is_command_key('GO_UP', key): key = 'up' elif is_command_key('GO_DOWN', key): key = 'down' elif is_command_key('SCROLL_UP', key): key = 'page up' elif is_command_key('SCROLL_DOWN', key): key = 'page down' elif is_command_key('GO_TO_BOTTOM', key): key = 'end' return super().keypress(size, key)
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 is not None and \ 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 is not None and \ 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): if self.focus is not None: self.model.react_to_message( self.focus.original_widget.message, reaction_to_toggle='thumbs_up') elif is_command_key('TOGGLE_STAR_STATUS', key): if self.focus is not None: message = self.focus.original_widget.message self.model.toggle_message_star_status(message) key = super(MessageView, self).keypress(size, key) return key
def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]: self.model.new_user_input = True if self.controller.is_in_editor_mode(): return self.controller.current_editor().keypress((size[1], ), key) # Redirect commands to message_view. 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('ALL_PM', key): self.model.controller.show_all_pm(self) self.body.focus_col = 1 elif is_command_key('ALL_STARRED', key): self.model.controller.show_all_starred(self) self.body.focus_col = 1 elif is_command_key('ALL_MENTIONS', key): self.model.controller.show_all_mentions(self) self.body.focus_col = 1 elif is_command_key('SEARCH_PEOPLE', key): # Start User Search if not in editor_mode self.body.focus_position = 2 self.users_view.keypress(size, 'w') self.show_left_panel(visible=False) self.show_right_panel(visible=True) self.user_search.set_edit_text("") self.controller.enter_editor_mode_with(self.user_search) return key elif (is_command_key('SEARCH_STREAMS', key) or is_command_key('SEARCH_TOPICS', key)): # jump stream search self.body.focus_position = 0 self.left_panel.keypress(size, 'q') self.show_right_panel(visible=False) self.show_left_panel(visible=True) if self.left_panel.is_in_topic_view: search_box = self.topic_w.topic_search_box else: search_box = self.stream_w.stream_search_box search_box.set_edit_text("") self.controller.enter_editor_mode_with(search_box) return key elif is_command_key('ABOUT', key): self.controller.show_about() 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('GO_UP', key): key = 'up' elif is_command_key('GO_DOWN', 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_UP', key): key = 'page up' elif is_command_key('SCROLL_DOWN', key): key = 'page down' elif is_command_key('GO_TO_BOTTOM', key): key = 'end' return super().keypress(size, key)