Mercurial > getan
changeset 163:1c01c061dfb3
Add new project mode to display a project tree
The project tree is sorted by the key
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 06 Dec 2012 14:57:55 +0100 |
parents | 7e6f92773b03 |
children | 90abd423fc0c |
files | getan/view.py |
diffstat | 1 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/getan/view.py Thu Dec 06 14:56:08 2012 +0100 +++ b/getan/view.py Thu Dec 06 14:57:55 2012 +0100 @@ -212,7 +212,8 @@ PROJECT_MODES = { 0: "id", 1: "key", - 2: "desc" + 2: "desc", + 3: "tree", } def __init__(self, controller, rows): @@ -239,11 +240,30 @@ self.update_rows() def update_rows(self): - rows = self.raw_rows - self.rows = [ProjectNode(x) for x in \ - sorted(rows, key=lambda row: self._get_project_sort_key(row))] + if self.project_mode == 3: + self.rows = self.create_project_tree() + else: + self.rows = self.create_project_list() self.listbox = urwid.ListBox(urwid.SimpleListWalker(self.rows)) + def create_project_list(self): + return [ProjectNode(x) for x in sorted(self.raw_rows, + key=lambda row: self._get_project_sort_key(row))] + + def create_project_tree(self): + # create a simple one child tree until now + # this should be extended and improved in future + nodes = [] + keys = [] + for proj in sorted(self.raw_rows, key=lambda proj: proj.key): + k = proj.key[0] + if k in keys: + nodes.append(ProjectNode(proj, indent=3)) + else: + keys.append(k) + nodes.append(ProjectNode(proj)) + return nodes + def _get_project_sort_key(self, proj): return getattr(proj, self.PROJECT_MODES[self.project_mode])