diff options
author | manfraid <manfraid@gmail.com> | 2011-12-08 16:22:43 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-12-09 13:56:55 +0100 |
commit | 02099123b0f2272954e91b737f50a797e4df0420 (patch) | |
tree | 65bc917cd6e7bebce79d728de369b09008df4a42 | |
parent | a0404f3077c9ec932f0272b770a9c985ccda25cc (diff) | |
download | poezio-02099123b0f2272954e91b737f50a797e4df0420.tar.gz poezio-02099123b0f2272954e91b737f50a797e4df0420.tar.bz2 poezio-02099123b0f2272954e91b737f50a797e4df0420.tar.xz poezio-02099123b0f2272954e91b737f50a797e4df0420.zip |
Fixe 2104
-rw-r--r-- | src/tabs.py | 22 | ||||
-rw-r--r-- | src/theming.py | 3 | ||||
-rw-r--r-- | src/windows.py | 64 |
3 files changed, 84 insertions, 5 deletions
diff --git a/src/tabs.py b/src/tabs.py index d41bf9d3..ab803553 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -2286,6 +2286,9 @@ class MucListTab(Tab): self.key_func['j'] = self.join_selected self.key_func['J'] = self.join_selected_no_focus self.key_func['^M'] = self.join_selected + self.key_func['KEY_LEFT'] = self.list_header.sel_column_left + self.key_func['KEY_RIGHT'] = self.list_header.sel_column_right + self.key_func[' '] = self.sort_by self.commands['close'] = (self.close, _("Usage: /close\nClose: Just close this tab."), None) self.resize() self.update_keys() @@ -2307,9 +2310,9 @@ class MucListTab(Tab): return self.need_resize = False self.upper_message.resize(1, self.width, 0, 0) - column_size = {'node-part': (self.width-5)//4, - 'name': (self.width-5)//4*3, - 'users': 5} + column_size = {'node-part': int(self.width*2/8) , + 'name': int(self.width*5/8), + 'users': self.width-int(self.width*2/8)-int(self.width*5/8)} self.list_header.resize_columns(column_size) self.list_header.resize(1, self.width, 1, 0) self.listview.resize_columns(column_size) @@ -2351,12 +2354,23 @@ class MucListTab(Tab): return items = [{'node-part': JID(item[0]).user if JID(item[0]).server == self.name else JID(item[0]).bare, 'jid': item[0], - 'name': item[2]} for item in iq['disco_items'].get_items()] + 'name': item[2],'users': ''} for item in iq['disco_items'].get_items()] self.listview.add_lines(items) self.upper_message.set_message('Chatroom list on server %s' % self.name) self.upper_message.refresh() curses.doupdate() + def sort_by(self): + if self.list_header.get_order(): + self.listview.sort_by_column(col_name=self.list_header.get_sel_column(),asc=False) + self.list_header.set_order(False) + self.list_header.refresh() + else: + self.listview.sort_by_column(col_name=self.list_header.get_sel_column(),asc=True) + self.list_header.set_order(True) + self.list_header.refresh() + curses.doupdate() + def join_selected(self): row = self.listview.get_selected_row() if not row: diff --git a/src/theming.py b/src/theming.py index e09d4530..7e90a5a7 100644 --- a/src/theming.py +++ b/src/theming.py @@ -154,12 +154,15 @@ class Theme(object): COLOR_CONVERSATION_NAME = (2, 4) COLOR_GROUPCHAT_NAME = (7, 4) COLOR_COLUMN_HEADER = (36, 4) + COLOR_COLUMN_HEADER_SEL = (4, 36) # Strings for special messages (like join, quit, nick change, etc) # Special messages CHAR_JOIN = '--->' CHAR_QUIT = '<---' CHAR_KICK = '-!-' + CHAR_COLUMN_ASC = ' ▲' + CHAR_COLUMN_DESC =' ▼' COLOR_JOIN_CHAR = (4, -1) COLOR_QUIT_CHAR = (1, -1) diff --git a/src/windows.py b/src/windows.py index a13efdf5..6c3c8b5c 100644 --- a/src/windows.py +++ b/src/windows.py @@ -1642,6 +1642,12 @@ class ListWin(Win): """ Sort the list by the given column, ascendant or descendant """ + if asc: + self.lines.sort(key=lambda x: x[col_name]) + else: + self.lines.sort(key=lambda x: x[col_name],reverse=True) + self.refresh() + curses.doupdate() pass # TODO def add_lines(self, lines): @@ -1741,6 +1747,9 @@ class ColumnHeaderWin(Win): Win.__init__(self) self._columns = columns self._columns_sizes = {} + self._column_sel = '' + self._column_order = '' + self._column_order_asc = False def resize_columns(self, dic): self._columns_sizes = dic @@ -1755,12 +1764,65 @@ class ColumnHeaderWin(Win): x = 0 for col in self._columns: txt = col + if col in self._column_order: + if self._column_order_asc: + txt += get_theme().CHAR_COLUMN_ASC + else: + txt += get_theme().CHAR_COLUMN_DESC + #⇓⇑↑↓⇧⇩▲▼ size = self._columns_sizes[col] txt += ' ' * (size-len(txt)) - self.addstr(0, x, txt, to_curses_attr(get_theme().COLOR_COLUMN_HEADER)) + if col in self._column_sel: + self.addstr(0, x, txt, to_curses_attr(get_theme().COLOR_COLUMN_HEADER_SEL)) + else: + self.addstr(0, x, txt, to_curses_attr(get_theme().COLOR_COLUMN_HEADER)) x += size self._refresh() + def sel_column(self,dic): + self._column_sel = dic + + def get_sel_column(self): + return self._column_sel + + def set_order(self,order): + self._column_order = self._column_sel + self._column_order_asc = order + + def get_order(self): + if self._column_sel == self._column_order: + return self._column_order_asc + else: + return False + + def sel_column_left(self): + if self._column_sel in self._columns: + index = self._columns.index(self._column_sel) + if index > 1: + index = index -1 + else: + index = 0 + else: + index = 0 + self._column_sel = self._columns[index] + self.refresh() + return + + def sel_column_right(self): + if self._column_sel in self._columns: + index = self._columns.index(self._column_sel) + if index < len(self._columns)-2: + index = index +1 + else: + index = len(self._columns) -1 + else: + index = len(self._columns) - 1 + self._column_sel = self._columns[index] + self.refresh() + return + + + class SimpleTextWin(Win): def __init__(self, text): Win.__init__(self) |