def handle_read(self, c): affected_lines = None if c == curses.KEY_UP: if self.cursel != 0: affected_lines = self._scroll_up(1) elif c == curses.KEY_PPAGE: affected_lines = self._scroll_up(int(self.torrent_rows / 2)) elif c == curses.KEY_DOWN: if self.cursel < self.numtorrents: affected_lines = self._scroll_down(1) elif c == curses.KEY_NPAGE: affected_lines = self._scroll_down(int(self.torrent_rows / 2)) elif c == curses.KEY_HOME: affected_lines = self._scroll_up(self.cursel) elif c == curses.KEY_END: affected_lines = self._scroll_down(self.numtorrents - self.cursel) elif c == curses.KEY_DC: # DEL added = self.update_marked(self.cursel) def on_close(**kwargs): if added: self.marked.pop() torrent_actions_popup(self.torrentlist, self._selected_torrent_ids(), action=ACTION.REMOVE, close_cb=on_close) elif c in [curses.KEY_ENTER, util.KEY_ENTER2] and self.numtorrents: added = self.update_marked(self.cursel) def on_close(data, **kwargs): if added: self.marked.remove(self.cursel) torrent_actions_popup(self.torrentlist, self._selected_torrent_ids(), details=True, close_cb=on_close) self.torrentlist.refresh() elif c == ord('j'): affected_lines = self._scroll_up(1) elif c == ord('k'): affected_lines = self._scroll_down(1) elif c == ord('m'): self.mark_unmark(self.cursel) affected_lines = [self.cursel] elif c == ord('M'): if self.last_mark >= 0: if self.cursel > self.last_mark: mrange = list(range(self.last_mark, self.cursel + 1)) else: mrange = list(range(self.cursel, self.last_mark)) self.add_marked(mrange, self.cursel) affected_lines = mrange else: self.mark_unmark(self.cursel) affected_lines = [self.cursel] elif c == ord('c'): self.clear_marked() elif c == ord('o'): if not self.marked: added = self.update_marked(self.cursel, clear=True) else: self.last_mark = -1 torrent_actions_popup(self.torrentlist, self._selected_torrent_ids(), action=ACTION.TORRENT_OPTIONS) elif c in [ord('>'), ord('<')]: try: i = self.cols_to_show.index( self.config['torrentview']['sort_primary']) except ValueError: i = 0 if chr(c) == '<' else len(self.cols_to_show) else: i += 1 if chr(c) == '>' else -1 i = max(0, min(len(self.cols_to_show) - 1, i)) self.config['torrentview']['sort_primary'] = self.cols_to_show[i] self.config.save() self.on_config_changed() self.update_columns() self.torrentlist.refresh([]) else: return util.ReadState.IGNORED self.set_input_result(affected_lines) return util.ReadState.CHANGED if affected_lines else util.ReadState.READ
def handle_read(self, c): cname = self.torrentview.torrent_names[self.torrentview.cursel] refresh = True if c in [ util.KEY_ESC, util.KEY_BELL, ]: # If Escape key or CTRL-g, we abort search self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c in [curses.KEY_BACKSPACE, util.KEY_BACKSPACE2]: if self.search_string: self.search_string = self.search_string[:-1] if cname.lower().find(self.search_string.lower()) != -1: self.search_state = SEARCH_SUCCESS else: self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c == curses.KEY_DC: self.search_string = '' self.search_state = SEARCH_SUCCESS elif c == curses.KEY_UP: self.do_search('previous') elif c == curses.KEY_DOWN: self.do_search('next') elif c == curses.KEY_LEFT: self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c == ord('/'): self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c == curses.KEY_RIGHT: tid = self.torrentview.current_torrent_id() self.torrentlist.show_torrent_details(tid) refresh = False elif c == curses.KEY_HOME: self.do_search('first') elif c == curses.KEY_END: self.do_search('last') elif c in [10, curses.KEY_ENTER]: self.last_mark = -1 tid = self.torrentview.current_torrent_id() torrent_actions_popup(self.torrentlist, [tid], details=True) refresh = False elif c == util.KEY_ESC: self.search_string = '' self.search_state = SEARCH_EMPTY elif c > 31 and c < 256: old_search_string = self.search_string stroke = chr(c) uchar = '' if PY2 else stroke while not uchar: try: uchar = stroke.decode(self.torrentlist.encoding) except UnicodeDecodeError: c = self.torrentlist.stdscr.getch() stroke += chr(c) if uchar: self.search_string += uchar still_matching = ( cname.lower().find(self.search_string.lower()) == cname.lower().find(old_search_string.lower()) and cname.lower().find(self.search_string.lower()) != -1) if self.search_string and not still_matching: self.do_search() elif self.search_string: self.search_state = SEARCH_SUCCESS else: refresh = False if not self.search_string: self.search_state = SEARCH_EMPTY refresh = True if refresh: self.torrentlist.refresh([]) return util.ReadState.READ
def handle_read(self, c): affected_lines = None if c == curses.KEY_UP: if self.cursel != 0: affected_lines = self._scroll_up(1) elif c == curses.KEY_PPAGE: affected_lines = self._scroll_up(int(self.torrent_rows / 2)) elif c == curses.KEY_DOWN: if self.cursel < self.numtorrents: affected_lines = self._scroll_down(1) elif c == curses.KEY_NPAGE: affected_lines = self._scroll_down(int(self.torrent_rows / 2)) elif c == curses.KEY_HOME: affected_lines = self._scroll_up(self.cursel) elif c == curses.KEY_END: affected_lines = self._scroll_down(self.numtorrents - self.cursel) elif c == curses.KEY_DC: # DEL added = self.update_marked(self.cursel) def on_close(**kwargs): if added: self.marked.pop() torrent_actions_popup(self.torrentlist, self._selected_torrent_ids(), action=ACTION.REMOVE, close_cb=on_close) elif c in [curses.KEY_ENTER, util.KEY_ENTER2] and self.numtorrents: added = self.update_marked(self.cursel) def on_close(data, **kwargs): if added: self.marked.remove(self.cursel) torrent_actions_popup(self.torrentlist, self._selected_torrent_ids(), details=True, close_cb=on_close) self.torrentlist.refresh() elif c == ord('j'): affected_lines = self._scroll_up(1) elif c == ord('k'): affected_lines = self._scroll_down(1) elif c == ord('m'): self.mark_unmark(self.cursel) affected_lines = [self.cursel] elif c == ord('M'): if self.last_mark >= 0: if self.cursel > self.last_mark: mrange = list(range(self.last_mark, self.cursel + 1)) else: mrange = list(range(self.cursel, self.last_mark)) self.add_marked(mrange, self.cursel) affected_lines = mrange else: self.mark_unmark(self.cursel) affected_lines = [self.cursel] elif c == ord('c'): self.clear_marked() elif c == ord('o'): if not self.marked: added = self.update_marked(self.cursel, clear=True) else: self.last_mark = -1 torrent_actions_popup(self.torrentlist, self._selected_torrent_ids(), action=ACTION.TORRENT_OPTIONS) elif c in [ord('>'), ord('<')]: try: i = self.cols_to_show.index(self.config['torrentview']['sort_primary']) except ValueError: i = 0 if chr(c) == '<' else len(self.cols_to_show) else: i += 1 if chr(c) == '>' else -1 i = max(0, min(len(self.cols_to_show) - 1, i)) self.config['torrentview']['sort_primary'] = self.cols_to_show[i] self.config.save() self.on_config_changed() self.update_columns() self.torrentlist.refresh([]) else: return util.ReadState.IGNORED self.set_input_result(affected_lines) return util.ReadState.CHANGED if affected_lines else util.ReadState.READ
def handle_read(self, c): cname = self.torrentview.torrent_names[self.torrentview.cursel] refresh = True if c in [util.KEY_ESC, util.KEY_BELL]: # If Escape key or CTRL-g, we abort search self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c in [curses.KEY_BACKSPACE, util.KEY_BACKSPACE2]: if self.search_string: self.search_string = self.search_string[:-1] if cname.lower().find(self.search_string.lower()) != -1: self.search_state = SEARCH_SUCCESS else: self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c == curses.KEY_DC: self.search_string = '' self.search_state = SEARCH_SUCCESS elif c == curses.KEY_UP: self.do_search('previous') elif c == curses.KEY_DOWN: self.do_search('next') elif c == curses.KEY_LEFT: self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c == ord('/'): self.torrentlist.set_minor_mode(None) self.search_state = SEARCH_EMPTY elif c == curses.KEY_RIGHT: tid = self.torrentview.current_torrent_id() self.torrentlist.show_torrent_details(tid) refresh = False elif c == curses.KEY_HOME: self.do_search('first') elif c == curses.KEY_END: self.do_search('last') elif c in [10, curses.KEY_ENTER]: self.last_mark = -1 tid = self.torrentview.current_torrent_id() torrent_actions_popup(self.torrentlist, [tid], details=True) refresh = False elif c == util.KEY_ESC: self.search_string = '' self.search_state = SEARCH_EMPTY elif c > 31 and c < 256: old_search_string = self.search_string stroke = chr(c) uchar = '' while not uchar: try: uchar = stroke.decode(self.torrentlist.encoding) except UnicodeDecodeError: c = self.torrentlist.stdscr.getch() stroke += chr(c) if uchar: self.search_string += uchar still_matching = ( cname.lower().find(self.search_string.lower()) == cname.lower().find(old_search_string.lower()) and cname.lower().find(self.search_string.lower()) != -1 ) if self.search_string and not still_matching: self.do_search() elif self.search_string: self.search_state = SEARCH_SUCCESS else: refresh = False if not self.search_string: self.search_state = SEARCH_EMPTY refresh = True if refresh: self.torrentlist.refresh([]) return util.ReadState.READ
def read_input(self): c = self.stdscr.getch() if self.popup: ret = self.popup.handle_read(c) if ret != util.ReadState.IGNORED and self.popup.closed(): self.pop_popup() self.refresh() return if c in [util.KEY_ESC, curses.KEY_LEFT, ord('q')]: self.back_to_overview() return util.ReadState.READ if not self.torrent_state: # actions below only make sense if there is a torrent state return # Navigate the torrent list if c == curses.KEY_UP: self.file_list_up() elif c == curses.KEY_PPAGE: self.file_list_up(self._listing_space - 2) elif c == curses.KEY_HOME: self.file_off = 0 self.current_file_idx = 0 elif c == curses.KEY_DOWN: self.file_list_down() elif c == curses.KEY_NPAGE: self.file_list_down(self._listing_space - 2) elif c == curses.KEY_END: self.current_file_idx = self.__get_file_list_length() - 1 self.file_off = self.current_file_idx - (self._listing_space - 3) elif c == curses.KEY_DC: torrent_actions_popup(self, [self.torrentid], action=ACTION.REMOVE) elif c in [curses.KEY_ENTER, util.KEY_ENTER2]: was_empty = self.marked == {} self.__mark_tree(self.file_list, self.current_file[1]) self.show_priority_popup(was_empty) elif c == util.KEY_SPACE: self.expcol_cur_file() elif c == ord('m'): if self.current_file: self.__mark_unmark(self.current_file[1]) elif c == ord('r'): self._show_rename_popup() elif c == ord('c'): self.marked = {} elif c == ord('a'): torrent_actions_popup(self, [self.torrentid], details=False) return elif c == ord('o'): torrent_actions_popup(self, [self.torrentid], action=ACTION.TORRENT_OPTIONS) return elif c == ord('h'): self.push_popup( MessagePopup(self, 'Help', HELP_STR, width_req=0.75)) elif c == ord('j'): self.file_list_up() elif c == ord('k'): self.file_list_down() self.refresh()
def read_input(self): c = self.stdscr.getch() if self.popup: ret = self.popup.handle_read(c) if ret != util.ReadState.IGNORED and self.popup.closed(): self.pop_popup() self.refresh() return if c in [util.KEY_ESC, curses.KEY_LEFT, ord('q')]: self.back_to_overview() return util.ReadState.READ if not self.torrent_state: # actions below only make sense if there is a torrent state return # Navigate the torrent list if c == curses.KEY_UP: self.file_list_up() elif c == curses.KEY_PPAGE: self.file_list_up(self._listing_space - 2) elif c == curses.KEY_HOME: self.file_off = 0 self.current_file_idx = 0 elif c == curses.KEY_DOWN: self.file_list_down() elif c == curses.KEY_NPAGE: self.file_list_down(self._listing_space - 2) elif c == curses.KEY_END: self.current_file_idx = self.__get_file_list_length() - 1 self.file_off = self.current_file_idx - (self._listing_space - 3) elif c == curses.KEY_DC: torrent_actions_popup(self, [self.torrentid], action=ACTION.REMOVE) elif c in [curses.KEY_ENTER, util.KEY_ENTER2]: was_empty = (self.marked == {}) self.__mark_tree(self.file_list, self.current_file[1]) self.show_priority_popup(was_empty) elif c == util.KEY_SPACE: self.expcol_cur_file() elif c == ord('m'): if self.current_file: self.__mark_unmark(self.current_file[1]) elif c == ord('r'): self._show_rename_popup() elif c == ord('c'): self.marked = {} elif c == ord('a'): torrent_actions_popup(self, [self.torrentid], details=False) return elif c == ord('o'): torrent_actions_popup(self, [self.torrentid], action=ACTION.TORRENT_OPTIONS) return elif c == ord('h'): self.push_popup(MessagePopup(self, 'Help', HELP_STR, width_req=0.75)) elif c == ord('j'): self.file_list_up() elif c == ord('k'): self.file_list_down() self.refresh()