annotate getan/view.py @ 379:47890f38e558

Let getan crash if entry _get_time doesn't return an int It's better to have a traceback when _get_time doesn't return an int then to silently ignore the time.
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 12 Mar 2014 10:57:21 +0100
parents 014ce0220763
children 050ffdec60d9
rev   line source
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
2 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
3 # (c) 2010 by Ingo Weinzierl <ingo.weinzierl@intevation.de>
138
bb6ddef4f88f Update copyright and add my name
Björn Ricks <bjoern.ricks@intevation.de>
parents: 137
diff changeset
4 # (c) 2012 by Björn Ricks <bjoern.ricks@intevation.de>
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
5 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
6 # This is Free Software licensed under the terms of GPLv3 or later.
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
7 # For details see LICENSE coming with the source of 'getan'.
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
8 #
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
9
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
10 import logging
43
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 41
diff changeset
11 import locale
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
12
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
13 import urwid
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
14 import urwid.raw_display
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
15
252
8be9c557e4b5 Show version number in getan header
Björn Ricks <bjoern.ricks@intevation.de>
parents: 245
diff changeset
16 import getan
8be9c557e4b5 Show version number in getan header
Björn Ricks <bjoern.ricks@intevation.de>
parents: 245
diff changeset
17
212
9badfbb04ac9 Add set_focus method to GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 211
diff changeset
18 from getan.nodes import ProjectNode, EntryNode
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 34
diff changeset
19 from getan.resources import gettext as _
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
20 from getan.utils import human_time
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
21 from getan.walker import ListWalker
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
22
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
23 logger = logging.getLogger()
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
24
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
25
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
26 class ListWidget(urwid.BoxWidget):
62
2b600cccf95e Add scrolling in entry list to be able to select all entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 43
diff changeset
27
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
28 node_class = None
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
29
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
30 def __init__(self, title, rows, header=None, footer=None):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
31 self.title = title
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
32 self.rows = [self.node_class(x) for x in rows]
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
33 self.header = header
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
34 self.footer = footer or urwid.Text("")
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
35 self.selection = []
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
36 self.set_node_rows(self.rows)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
37 self.set_focus(0)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
38
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
39 def set_title(self, title):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
40 self.title = title
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
41 self.body.set_title(self.title)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
42
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
43 def set_header(self, header):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
44 self.header = header
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
45 self.frame.set_header(header)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
46
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
47 def set_footer(self, footer):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
48 self.footer = footer
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
49 self.frame.set_footer(footer)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
50
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
51 def set_body(self, body):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
52 self.body = body
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
53 self.frame.set_body(body)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
54
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
55 def set_focus(self, idx):
285
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
56 if not idx:
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
57 idx = 0
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
58
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
59 self.frame.set_focus("body")
285
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
60
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
61 if self.rows:
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
62 self.listbox.set_focus(idx)
983c4279e08d Only set focus in ListBox if rows are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 275
diff changeset
63
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
64 self._invalidate()
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
65
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
66 def keypress(self, size, key):
230
8e9e894552e8 Lower debug output
Björn Ricks <bjoern.ricks@intevation.de>
parents: 228
diff changeset
67 logger.debug("Handling keypres for %r" % self)
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
68 return self.frame.keypress(size, key)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
69
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
70 def set_rows(self, rows):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
71 logger.info("ListView setting rows %s" % rows)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
72 if rows:
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
73 self.rows = [self.node_class(x) for x in rows]
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
74 else:
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
75 self.rows = []
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
76 self.set_node_rows(self.rows)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
77
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
78 def set_node_rows(self, rows):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
79 """ Sets node_class rows in the walker """
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
80 self.walker = ListWalker(self.rows, self)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
81 self.listbox = urwid.ListBox(self.walker)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
82 self.body = urwid.LineBox(self.listbox, title=self.title)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
83 self.frame = urwid.Frame(self.body, header=self.header,
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
84 footer=self.footer)
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
85 self._invalidate()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
86
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
87 def render(self, size, focus=False):
217
7d6615ac2453 Shorten code
Björn Ricks <bjoern.ricks@intevation.de>
parents: 216
diff changeset
88 return self.frame.render(size, focus)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
89
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
90 def set_footer_text(self, text, attr, edit=False):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
91 if edit:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
92 logger.debug("ListWidget: set footer text (edit) = '%s'" % text)
214
6d5c8e205872 Fix coding style
Björn Ricks <bjoern.ricks@intevation.de>
parents: 213
diff changeset
93 self.footer = urwid.AttrWrap(urwid.Edit(text), attr)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
94 else:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
95 logger.debug("ListWidget: set footer text = '%s'" % text)
218
29e1a68589a0 Update code to set the current footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 217
diff changeset
96 self.footer = urwid.AttrWrap(urwid.Text(text), attr)
29e1a68589a0 Update code to set the current footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 217
diff changeset
97 self.frame.set_footer(self.footer)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
98
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
99 def row_count(self):
135
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 132
diff changeset
100 if not self.rows:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 132
diff changeset
101 return 0
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
102 return len(self.rows)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
103
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
104 def item_in_focus(self):
215
a16c2c42d998 Use node_in_focus to get item_in_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 214
diff changeset
105 node = self.node_in_focus()
a16c2c42d998 Use node_in_focus to get item_in_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 214
diff changeset
106 if node:
a16c2c42d998 Use node_in_focus to get item_in_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 214
diff changeset
107 return node.get_item()
41
f44f808e7d47 Make getan runnable if there is no project in database.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 36
diff changeset
108 return None
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
109
86
c9684f6d54ea Add new method in ListWidget to get the current node element
Björn Ricks <bjoern.ricks@intevation.de>
parents: 71
diff changeset
110 def node_in_focus(self):
c9684f6d54ea Add new method in ListWidget to get the current node element
Björn Ricks <bjoern.ricks@intevation.de>
parents: 71
diff changeset
111 if self.rows:
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
112 return self.listbox.get_focus()[0]
86
c9684f6d54ea Add new method in ListWidget to get the current node element
Björn Ricks <bjoern.ricks@intevation.de>
parents: 71
diff changeset
113 return None
c9684f6d54ea Add new method in ListWidget to get the current node element
Björn Ricks <bjoern.ricks@intevation.de>
parents: 71
diff changeset
114
233
68fa56dacbcd Add new get_focus_pos method to ListView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 230
diff changeset
115 def get_focus_pos(self):
68fa56dacbcd Add new get_focus_pos method to ListView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 230
diff changeset
116 return self.listbox.get_focus()[1]
68fa56dacbcd Add new get_focus_pos method to ListView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 230
diff changeset
117
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
118 def select(self):
135
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 132
diff changeset
119 if not self.rows:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 132
diff changeset
120 return None
219
71638dcc5a0f Remove self.focused usage
Björn Ricks <bjoern.ricks@intevation.de>
parents: 218
diff changeset
121 node = self.node_in_focus()
71638dcc5a0f Remove self.focused usage
Björn Ricks <bjoern.ricks@intevation.de>
parents: 218
diff changeset
122 logger.info("ListWidget: select row '%s'" % node)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
123 if node.selected:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
124 self.selection.append(node)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
125 else:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
126 if node in self.selection:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
127 self.selection.pop()
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
128 logger.debug("ListWidget: all selected rows: %r" % self.selection)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
129 return node
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
130
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
131 def clear(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
132 logger.debug("EntryList: clear focus and selection of all entries.")
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
133 for node in self.selection:
135
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 132
diff changeset
134 if node.selected:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 132
diff changeset
135 node.select()
219
71638dcc5a0f Remove self.focused usage
Björn Ricks <bjoern.ricks@intevation.de>
parents: 218
diff changeset
136 self.set_focus(0)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
137
224
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
138 def content_focus_changed(self):
c8f85809607b Implement a more generalized ListWidget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 223
diff changeset
139 pass
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
140
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
141
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
142 class ProjectList(ListWidget):
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
143
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
144 PROJECT_MODES = {
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
145 0: "id",
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
146 1: "key",
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
147 2: "desc",
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
148 3: "tree",
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
149 }
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
150
227
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
151 node_class = ProjectNode
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
152
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
153 def __init__(self, controller, rows):
220
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
154 self.selection = []
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
155 self.size = ()
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
156 self.top = 0
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
157 self.controller = controller
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
158 self.project_mode = 0
306
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
159 self.selection_deactivated = False
220
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
160 self.set_raw_rows(rows)
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
161 super(ProjectList, self).__init__("Projects", rows)
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
162 self.create_node_rows()
263
077c2ce02f93 Refactor ProjectList setting the total_time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 260
diff changeset
163 self.show_total_time()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
164
107
a23e8191c6bc Update project list when a new project was created
Björn Ricks <bjoern.ricks@intevation.de>
parents: 86
diff changeset
165 def load_rows(self, rows):
220
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
166 self.set_raw_rows(rows)
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
167 self.update_rows()
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
168
220
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
169 def set_raw_rows(self, rows):
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
170 self.raw_rows = rows
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
171
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
172 def update_rows(self):
220
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
173 self.create_node_rows()
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
174 self.set_node_rows(self.rows)
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
175
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
176 def create_node_rows(self):
54e8b355164c Refactor ProjecList node initialisation
Björn Ricks <bjoern.ricks@intevation.de>
parents: 219
diff changeset
177 """ Sets self.rows to node_class rows depending on the project_mode """
163
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
178 if self.project_mode == 3:
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
179 self.rows = self.create_project_tree()
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
180 else:
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
181 self.rows = self.create_project_list()
107
a23e8191c6bc Update project list when a new project was created
Björn Ricks <bjoern.ricks@intevation.de>
parents: 86
diff changeset
182
163
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
183 def create_project_list(self):
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
184 return [ProjectNode(x) for x in sorted(
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
185 self.raw_rows, key=lambda row: self._get_project_sort_key(row))]
163
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
186
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
187 def create_project_tree(self):
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
188 # create a simple one child tree until now
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
189 # this should be extended and improved in future
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
190 nodes = []
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
191 keys = []
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
192 for proj in sorted(self.raw_rows, key=lambda proj: proj.key):
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
193 k = proj.key[0]
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
194 if k in keys:
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
195 nodes.append(ProjectNode(proj, indent=3))
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
196 else:
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
197 keys.append(k)
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
198 nodes.append(ProjectNode(proj))
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
199 return nodes
1c01c061dfb3 Add new project mode to display a project tree
Björn Ricks <bjoern.ricks@intevation.de>
parents: 162
diff changeset
200
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
201 def _get_project_sort_key(self, proj):
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
202 return getattr(proj, self.PROJECT_MODES[self.project_mode])
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
203
263
077c2ce02f93 Refactor ProjectList setting the total_time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 260
diff changeset
204 def show_total_time(self):
077c2ce02f93 Refactor ProjectList setting the total_time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 260
diff changeset
205 self.total_time()
077c2ce02f93 Refactor ProjectList setting the total_time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 260
diff changeset
206 self.reset_footer()
077c2ce02f93 Refactor ProjectList setting the total_time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 260
diff changeset
207
077c2ce02f93 Refactor ProjectList setting the total_time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 260
diff changeset
208 def total_time(self):
129
c8ae4ec4ba61 Put return statement on the next line
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
209 if not self.rows:
260
e206ab753a26 Set empty project_footer if no projects are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 257
diff changeset
210 self.set_footer_text("", "project_footer")
129
c8ae4ec4ba61 Put return statement on the next line
Björn Ricks <bjoern.ricks@intevation.de>
parents: 107
diff changeset
211 return
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
212 logger.debug("ProjectList: update projects total time.")
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
213 total = 0
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
214 for proj in self.rows:
34
a9f2e8fd8970 'NoneType' time values don't break getan while switching time mode anymore (issue1575).
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 28
diff changeset
215 tmp = proj._get_time()
379
47890f38e558 Let getan crash if entry _get_time doesn't return an int
Björn Ricks <bjoern.ricks@intevation.de>
parents: 322
diff changeset
216 if tmp:
34
a9f2e8fd8970 'NoneType' time values don't break getan while switching time mode anymore (issue1575).
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 28
diff changeset
217 total += tmp
131
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
218 self.set_footer_info("All projects: %s %s"
64
94c2c3eeac9a Use set_footer_text method to set the footer text instead of
Björn Ricks <bjoern.ricks@intevation.de>
parents: 63
diff changeset
219 % (proj.mode[1], human_time(total)),
94c2c3eeac9a Use set_footer_text method to set the footer text instead of
Björn Ricks <bjoern.ricks@intevation.de>
parents: 63
diff changeset
220 "project_footer")
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
221
131
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
222 def set_footer_info(self, text, attr):
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
223 logger.debug("ProjectList: set_footer_info to '%s'" % text)
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
224 self._footer_info = (text, attr)
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
225
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
226 def reset_footer(self):
260
e206ab753a26 Set empty project_footer if no projects are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 257
diff changeset
227 if not self.rows:
e206ab753a26 Set empty project_footer if no projects are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 257
diff changeset
228 self.set_footer_text("", "project_footer")
e206ab753a26 Set empty project_footer if no projects are available
Björn Ricks <bjoern.ricks@intevation.de>
parents: 257
diff changeset
229 return
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
230 logger.debug("ProjectList: reset_footer to '%s'" %
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
231 self._footer_info[0])
131
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
232 self.set_footer_text(*self._footer_info)
3d5232dad59a Add methods to reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 129
diff changeset
233
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
234 def switch_time_mode(self):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
235 logger.debug("ProjectList: switch time mode now.")
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
236 for proj in self.rows:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
237 proj.switch_time_mode()
274
1477a5fbf0cd Fix showing the total time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 264
diff changeset
238 self.show_total_time()
194
cf98dc7f9354 Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents: 168
diff changeset
239 self.controller.loop.draw_screen()
228
37010cd332d9 Invalidate view to redraw it when time is changed
Björn Ricks <bjoern.ricks@intevation.de>
parents: 227
diff changeset
240 self._invalidate()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
241
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
242 def unhandled_keypress(self, key):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
243 logger.debug("ProjectList: unhandled keypress '%r'" % key)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
244
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
245 def select_project(self, project):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
246 for proj_node in self.rows:
27
1a90a126c415 Bugfix: fixed wrong attribute name while accessing raw projects of a ProjectNode.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 25
diff changeset
247 if proj_node.item.key == project.key:
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
248 idx = self.rows.index(proj_node)
223
aa7b1efb7689 Fix setting the focus in the ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 222
diff changeset
249 self.set_focus(idx)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
250 self.select()
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
251 break
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
252
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
253 def switch_project_order(self):
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
254 self.project_mode += 1
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
255 if self.project_mode >= len(self.PROJECT_MODES):
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
256 self.project_mode = 0
162
7e6f92773b03 Log when switching the project mode
Björn Ricks <bjoern.ricks@intevation.de>
parents: 161
diff changeset
257 logger.debug("Switching project mode to %s" % self.project_mode)
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
258 self.update_rows()
223
aa7b1efb7689 Fix setting the focus in the ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 222
diff changeset
259 self.set_focus(0)
141
dafff6c3fa12 Add code to be able to sort the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents: 140
diff changeset
260
226
f8571308abef Move ProjectNode and EntryNode to its own module
Björn Ricks <bjoern.ricks@intevation.de>
parents: 224
diff changeset
261 def content_focus_changed(self):
f8571308abef Move ProjectNode and EntryNode to its own module
Björn Ricks <bjoern.ricks@intevation.de>
parents: 224
diff changeset
262 item = self.item_in_focus()
230
8e9e894552e8 Lower debug output
Björn Ricks <bjoern.ricks@intevation.de>
parents: 228
diff changeset
263 logger.debug("Conten in focus changed %s" % item)
226
f8571308abef Move ProjectNode and EntryNode to its own module
Björn Ricks <bjoern.ricks@intevation.de>
parents: 224
diff changeset
264 if item:
f8571308abef Move ProjectNode and EntryNode to its own module
Björn Ricks <bjoern.ricks@intevation.de>
parents: 224
diff changeset
265 self.controller.update_entries(item)
71
c1664ea5a83b Add get_item method also for EntryNode to be able to receive an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents: 70
diff changeset
266
306
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
267 def keypress(self, size, key):
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
268 if key == "enter" and self.is_selection_deactivated():
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
269 return
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
270 else:
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
271 return super(ProjectList, self).keypress(size, key)
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
272
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
273 def is_selection_deactivated(self):
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
274 return self.selection_deactivated
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
275
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
276 def deactivate_selection(self):
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
277 self.selection_deactivated = True
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
278
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
279 def enable_selection(self):
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
280 self.selection_deactivated = False
afe36c18417f Allow to deactivate the selection of projects
Björn Ricks <bjoern.ricks@intevation.de>
parents: 299
diff changeset
281
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
282
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
283 class EntryList(ListWidget):
137
5a4946fd9e6d Update whitespace
Björn Ricks <bjoern.ricks@intevation.de>
parents: 135
diff changeset
284
227
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
285 node_class = EntryNode
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
286
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
287 def __init__(self, rows):
227
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
288 logger.debug("Init EntryList %s" % id(self))
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
289 super(EntryList, self).__init__("Entries", rows)
1b29cc99f457 Use ListWidget for EntryList and ProjectList
Björn Ricks <bjoern.ricks@intevation.de>
parents: 226
diff changeset
290 self.set_footer_text("", "entry_footer")
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
291
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
292
210
43e8befd5dd9 Convert GetanView into a urwid widget
Björn Ricks <bjoern.ricks@intevation.de>
parents: 209
diff changeset
293 class GetanView(urwid.WidgetWrap):
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
294
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
295 def __init__(self, controller, proj_list, entr_list):
43
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 41
diff changeset
296 encoding = locale.getpreferredencoding()
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 41
diff changeset
297 urwid.set_encoding(encoding)
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 41
diff changeset
298 logger.debug("used encoding: %s" % encoding)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
299 self.controller = controller
209
bffca92237b8 Update coding style in GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 208
diff changeset
300 self.proj_list = proj_list
bffca92237b8 Update coding style in GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 208
diff changeset
301 self.entr_list = entr_list
bffca92237b8 Update coding style in GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 208
diff changeset
302 self.columns = urwid.Columns([
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
303 urwid.Padding(
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
304 self.proj_list, ('fixed left', 0), ('fixed right', 1)),
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
305 self.entr_list], 0)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
306
252
8be9c557e4b5 Show version number in getan header
Björn Ricks <bjoern.ricks@intevation.de>
parents: 245
diff changeset
307 getan_header = urwid.AttrWrap(urwid.Text('%s' % _('.: getan :.')),
8be9c557e4b5 Show version number in getan header
Björn Ricks <bjoern.ricks@intevation.de>
parents: 245
diff changeset
308 'header')
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
309 version_header = urwid.AttrWrap(urwid.Text(
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
310 "Version %s" % getan.__version__, align="right"), "header")
252
8be9c557e4b5 Show version number in getan header
Björn Ricks <bjoern.ricks@intevation.de>
parents: 245
diff changeset
311
8be9c557e4b5 Show version number in getan header
Björn Ricks <bjoern.ricks@intevation.de>
parents: 245
diff changeset
312 self.header = urwid.Columns([getan_header, version_header])
209
bffca92237b8 Update coding style in GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 208
diff changeset
313 self.footer = urwid.AttrWrap(urwid.Text(_('Choose a project:')),
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
314 'question')
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
315 self.col_list = self.columns.widget_list
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
316 view = urwid.AttrWrap(self.columns, 'body')
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
317 self.frame = urwid.Frame(view, header=self.header, footer=self.footer)
244
6aed37250c35 Rename GetanView member variable view to frame
Björn Ricks <bjoern.ricks@intevation.de>
parents: 241
diff changeset
318 self._w = self.frame
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
319
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
320 def get_frame(self):
244
6aed37250c35 Rename GetanView member variable view to frame
Björn Ricks <bjoern.ricks@intevation.de>
parents: 241
diff changeset
321 return self.frame
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
322
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
323 def set_footer_text(self, text, attr, edit=False):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
324 if edit:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
325 logger.debug("GetanView: set footer text (edit): '%s'" % text)
244
6aed37250c35 Rename GetanView member variable view to frame
Björn Ricks <bjoern.ricks@intevation.de>
parents: 241
diff changeset
326 self.frame.set_footer(urwid.AttrWrap(urwid.Edit(text), attr))
6aed37250c35 Rename GetanView member variable view to frame
Björn Ricks <bjoern.ricks@intevation.de>
parents: 241
diff changeset
327 self.frame.set_focus("footer")
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
328 else:
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
329 logger.debug("GetanView: set footer text: '%s'" % text)
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
330 self.frame.set_footer(urwid.AttrWrap(urwid.Text(text), attr))
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
331
208
e1e885b88baf Implement keypress in GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
332 def keypress(self, size, key):
e1e885b88baf Implement keypress in GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
333 self.controller.state.keypress(size, key)
211
b71dc50fbd51 Add GetanView update_entries method
Björn Ricks <bjoern.ricks@intevation.de>
parents: 210
diff changeset
334
254
70e4f59f991c Ignore mouse events for the moment
Björn Ricks <bjoern.ricks@intevation.de>
parents: 252
diff changeset
335 def mouse_event(self, size, event, button, col, row, focus):
299
a437bbc507a9 Fix codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 298
diff changeset
336 # TODO currently ignore mouse events
254
70e4f59f991c Ignore mouse events for the moment
Björn Ricks <bjoern.ricks@intevation.de>
parents: 252
diff changeset
337 return True
70e4f59f991c Ignore mouse events for the moment
Björn Ricks <bjoern.ricks@intevation.de>
parents: 252
diff changeset
338
211
b71dc50fbd51 Add GetanView update_entries method
Björn Ricks <bjoern.ricks@intevation.de>
parents: 210
diff changeset
339 def update_entries(self, entries):
b71dc50fbd51 Add GetanView update_entries method
Björn Ricks <bjoern.ricks@intevation.de>
parents: 210
diff changeset
340 self.entr_list.set_rows(entries)
212
9badfbb04ac9 Add set_focus method to GetanView
Björn Ricks <bjoern.ricks@intevation.de>
parents: 211
diff changeset
341
245
4ecc6bdf0698 Allow to set focus on column or frame element in GetanView set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 244
diff changeset
342 def set_focus(self, elem):
4ecc6bdf0698 Allow to set focus on column or frame element in GetanView set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 244
diff changeset
343 if elem in [0, 1]:
4ecc6bdf0698 Allow to set focus on column or frame element in GetanView set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 244
diff changeset
344 self.columns.set_focus_column(elem)
257
2df167b07763 Allow to set focus to the project or entry list in getan view via strings
Björn Ricks <bjoern.ricks@intevation.de>
parents: 254
diff changeset
345 elif elem == "projects":
275
822c4facbb65 Set focus of the frame to body when set_focus in GetanView is called to set the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 274
diff changeset
346 self.frame.set_focus("body")
264
915456b53f34 Fix typo
Björn Ricks <bjoern.ricks@intevation.de>
parents: 263
diff changeset
347 self.columns.set_focus_column(0)
257
2df167b07763 Allow to set focus to the project or entry list in getan view via strings
Björn Ricks <bjoern.ricks@intevation.de>
parents: 254
diff changeset
348 elif elem == "entries":
275
822c4facbb65 Set focus of the frame to body when set_focus in GetanView is called to set the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 274
diff changeset
349 self.frame.set_focus("body")
264
915456b53f34 Fix typo
Björn Ricks <bjoern.ricks@intevation.de>
parents: 263
diff changeset
350 self.columns.set_focus_column(1)
245
4ecc6bdf0698 Allow to set focus on column or frame element in GetanView set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 244
diff changeset
351 else:
4ecc6bdf0698 Allow to set focus on column or frame element in GetanView set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 244
diff changeset
352 self.frame.set_focus(elem)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)