diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-06-21 01:58:24 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-06-21 01:58:24 +0200 |
commit | 06f4dd783ed946168be00abdfdf4ffc127ba21e5 (patch) | |
tree | 2253e7b5bc0c4a4bf7dd60e24591280bd53e8a4f /src | |
parent | 511ecf6195597ceda94730bf66017645d368ea5f (diff) | |
download | poezio-06f4dd783ed946168be00abdfdf4ffc127ba21e5.tar.gz poezio-06f4dd783ed946168be00abdfdf4ffc127ba21e5.tar.bz2 poezio-06f4dd783ed946168be00abdfdf4ffc127ba21e5.tar.xz poezio-06f4dd783ed946168be00abdfdf4ffc127ba21e5.zip |
Nodes can be scrolled and the item list is updated accordingly
Diffstat (limited to 'src')
-rw-r--r-- | src/pubsub.py | 83 | ||||
-rw-r--r-- | src/windows.py | 3 |
2 files changed, 78 insertions, 8 deletions
diff --git a/src/pubsub.py b/src/pubsub.py index 1b4a8e1e..0b8b02c5 100644 --- a/src/pubsub.py +++ b/src/pubsub.py @@ -47,9 +47,17 @@ class CollectionNode(PubsubNode): class PubsubItem(object): def __init__(self, idd, content): - self.idd = idd + self.id = idd self.content = content + def to_dict(self, columns): + """ + returns a dict of the values listed in columns + """ + ret = {} + for col in columns: + ret[col] = self.__dict__.get(col) or '' + return ret class PubsubBrowserTab(tabs.Tab): """ @@ -69,7 +77,7 @@ class PubsubBrowserTab(tabs.Tab): self.tab_win = windows.GlobalInfoBar() self.upper_message = windows.Topic() - self.upper_message.set_message('Pubsub server: %s' % (self.server,)) + self.upper_message.set_message('Pubsub server: %s/%s' % (self.server,self.current_node or '')) # Node List View node_columns = ('node', 'name',) @@ -77,7 +85,7 @@ class PubsubBrowserTab(tabs.Tab): self.node_listview = windows.ListWin(node_columns) # Item List View - item_columns = ('name',) + item_columns = ('id',) self.item_list_header = windows.ColumnHeaderWin(item_columns) self.item_listview = windows.ListWin(item_columns) @@ -85,8 +93,8 @@ class PubsubBrowserTab(tabs.Tab): self.input = self.default_help_message self.key_func['c'] = self.command_create_node - self.key_func["M-KEY_DOWN"] = self.node_listview.move_cursor_down - self.key_func["M-KEY_UP"] = self.node_listview.move_cursor_up + self.key_func["M-KEY_DOWN"] = self.scroll_node_down + self.key_func["M-KEY_UP"] = self.scroll_node_up self.key_func["KEY_DOWN"] = self.item_listview.move_cursor_down self.key_func["KEY_UP"] = self.item_listview.move_cursor_up self.resize() @@ -104,11 +112,11 @@ class PubsubBrowserTab(tabs.Tab): self.node_listview.resize_columns(column_size) self.node_listview.resize(self.height//2-2, self.width//2, 2, 0) - column_size = {'name': self.width//2,} + column_size = {'id': self.width//2,} self.item_list_header.resize_columns(column_size) self.item_list_header.resize(self.height//2+1, self.width//2, self.height//2, 0) self.item_listview.resize_columns(column_size) - self.item_listview.resize(self.height//2-4, self.width//2, self.height//2+3, 0) + self.item_listview.resize(self.height//2-3, self.width//2, self.height//2+1, 0) self.input.resize(1, self.width, self.height-1, 0) @@ -134,6 +142,26 @@ class PubsubBrowserTab(tabs.Tab): if key in self.key_func: return self.key_func[key]() + def get_selected_node_name(self): + """ + From the node_view_list, returns the node name of the selected + one. None can be returned + """ + line = self.node_listview.get_selected_row() + if not line: + return None + return line['node'] + + def get_node_by_name(self, name): + """ + in the current browsed node (or on the root), return the node with that name + """ + nodes = self.current_node and self.current_node.subnodes or self.nodes + for node in nodes: + if node.name == name: + return node + return None + def get_items(self, node): """ Get all items in the given node @@ -144,8 +172,22 @@ class PubsubBrowserTab(tabs.Tab): for it in items: item_list.append(PubsubItem(it.attrib['id'], it)) node.items = item_list + log.debug('get_selected_node_name: %s' % self.get_selected_node_name()) + if self.get_selected_node_name() == node.name: + self.display_items_from_node(node) log.debug('Item on node %s: %s' % (node.name, item_list)) + def display_items_from_node(self, node): + """ + takes a node, and set fill the item_listview with that + node’s items + """ + columns = self.item_list_header.get_columns() + self.item_listview.lines = [] + log.debug('display_items_from_node: %s' % node.items) + for item in node.items: + self.item_listview.lines.append(item.to_dict(columns)) + def add_nodes(self, node_list, parent=None): """ Add Node objects to the list of the parent. @@ -158,11 +200,11 @@ class PubsubBrowserTab(tabs.Tab): list_to_append = self.nodes else: list_to_append = parent.nodes + self.node_listview.add_lines(node_list) for node in node_list: new_node = LeafNode(node['node']) list_to_append.append(new_node) self.get_items(new_node) - self.node_listview.add_lines(node_list) def get_nodes(self, node=None): """ @@ -198,3 +240,28 @@ class PubsubBrowserTab(tabs.Tab): self.input = windows.CommandInput("[Create node]", self.reset_help_message, self.create_node, None) self.input.resize(1, self.width, self.height-1, 0) return True + + def scroll_node_up(self): + """ + scroll the node up, and update the item list if needed + """ + selected_node_before = self.get_selected_node_name() + self.node_listview.move_cursor_up() + selected_node_after = self.get_selected_node_name() + if selected_node_after is not selected_node_before: + self.display_items_from_node(self.get_node_by_name(selected_node_after)) + return True + return False + + def scroll_node_down(self): + """ + scroll the node down, and update the item list if needed + """ + selected_node_before = self.get_selected_node_name() + self.node_listview.move_cursor_down() + selected_node_after = self.get_selected_node_name() + if selected_node_after is not selected_node_before: + self.display_items_from_node(self.get_node_by_name(selected_node_after)) + return True + return False + diff --git a/src/windows.py b/src/windows.py index eb6dde43..512b6f01 100644 --- a/src/windows.py +++ b/src/windows.py @@ -1603,6 +1603,9 @@ class ColumnHeaderWin(Win): def resize_columns(self, dic): self._columns_sizes = dic + def get_columns(self): + return self._columns + def refresh(self): log.debug('Refresh: %s'%self.__class__.__name__) with g_lock: |