Mercurial > getan > getan
annotate getan/states.py @ 286:96843aedcf5e
Update rows when stopping a running project
Update rows to show new time when stopping a project.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 10 May 2013 09:51:43 +0200 |
parents | 12aa8208bb36 |
children | fdd086acdf9b |
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 #!/usr/bin/env python |
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 # -*- 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
|
3 # |
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
|
4 # (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
|
5 # (c) 2011, 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
|
6 # |
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 # 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
|
8 # 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
|
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 |
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
|
11 |
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 import logging |
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 signal |
195
0c0d88ec53f9
Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents:
194
diff
changeset
|
14 |
0c0d88ec53f9
Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents:
194
diff
changeset
|
15 from datetime import datetime, timedelta |
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
|
16 |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
17 from getan.resources import gettext as _ |
195
0c0d88ec53f9
Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents:
194
diff
changeset
|
18 from getan.utils import human_time, safe_int |
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
|
19 |
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
|
20 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
|
21 |
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 class State(object): |
197
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
23 """ Represents a State of Getan |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
24 |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
25 A State can be used to handle user input. The user input handling is done in |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
26 three phases. First it is possible to filter keys that shouldn't be passed |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
27 to a widget in input_filter. Afterwards it is possible to redirect a key to |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
28 a specific widget in keypress. In the third phase it is possible to act on |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
29 user input which isn't handled by a widget yet. The corresponing method is |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
30 handle_input. |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
31 |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
32 Normally handle_input should be used to act on user input and change a |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
33 state. |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
34 """ |
196
2c4cfc79632c
Fix coding style for State class
Björn Ricks <bjoern.ricks@intevation.de>
parents:
195
diff
changeset
|
35 |
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
|
36 messages = { |
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
|
37 } |
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
|
38 |
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
|
39 def __init__(self, controller, view): |
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
|
40 self.controller = controller |
196
2c4cfc79632c
Fix coding style for State class
Björn Ricks <bjoern.ricks@intevation.de>
parents:
195
diff
changeset
|
41 self.view = view |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
42 self.config = controller.get_config() |
276
dd575513ee1b
Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents:
271
diff
changeset
|
43 self.set_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
|
44 |
197
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
45 def input_filter(self, input, raw): |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
46 """Filters input that should not be passed to widget elements |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
47 |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
48 By default no input is filtered and input is returned unchanged. |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
49 """ |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
50 return input |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
51 |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
52 def keypress(self, size, key): |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
53 """Redirects user input to the current view""" |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
54 self.view.keypress(size, key) |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
55 |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
56 def handle_input(self, input): |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
57 """A derived State must implement handle_input""" |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
58 raise NotImplementedError() |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
59 |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
60 def set_next_state(self, state): |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
61 """Sets the next state""" |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
62 self.controller.set_state(state) |
2eb2bbf042b3
Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents:
196
diff
changeset
|
63 |
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
|
64 def msg(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
|
65 return self.messages[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
|
66 |
276
dd575513ee1b
Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents:
271
diff
changeset
|
67 def set_focus(self): |
dd575513ee1b
Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents:
271
diff
changeset
|
68 """ Override this method to set the focus when the state is created """ |
dd575513ee1b
Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents:
271
diff
changeset
|
69 pass |
dd575513ee1b
Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents:
271
diff
changeset
|
70 |
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
|
71 |
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
|
72 class ProjectState(State): |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
73 |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
74 def handle_input(self, input): |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
75 keys = self.config.get_keybinding() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
76 logger.debug("ProjectState: handle input '%r'" % input) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
77 if keys.get_switch_time_mode() in input: |
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
|
78 self.view.switch_time_mode() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
79 return True |
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
|
80 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
81 if keys.get_switch_project_order() in input: |
142
d88240a3a065
Add global key to switch sorting of the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents:
139
diff
changeset
|
82 self.view.switch_project_order() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
83 return True |
142
d88240a3a065
Add global key to switch sorting of the project list
Björn Ricks <bjoern.ricks@intevation.de>
parents:
139
diff
changeset
|
84 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
85 if keys.get_switch_lists() in input: |
72
90b61a24742b
Don't switch to EntryView if it doesn't contain any row/entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
56
diff
changeset
|
86 if not self.controller.entries_view.rows: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
87 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
88 new_state = DefaultEntryListState(self, self.controller, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
89 self.controller.entries_view) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
90 self.set_next_state(new_state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
91 return True |
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
|
92 |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
93 def set_focus(self): |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
94 self.controller.view.set_focus("projects") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
95 |
170 | 96 |
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
|
97 class PausedProjectsState(ProjectState): |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
98 |
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
|
99 messages = { |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
100 'choose_proj': _('Choose a project: '), |
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
|
101 } |
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 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
103 def handle_input(self, 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
|
104 logger.debug("PausedProjectsState: handle key '%r'" % key) |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
105 keys = self.config.get_keybinding() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
106 ret = super(PausedProjectsState, self).handle_input(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
|
107 if ret: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
108 return True |
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 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
110 if keys.get_enter() in 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
|
111 return 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
|
112 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
113 if keys.get_insert() in key: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
114 state = AddProjectKeyState(self.controller, self.view) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
115 self.set_next_state(state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
116 return True |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
117 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
118 if keys.get_escape() in key: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
119 state = ExitState(self.controller, self.view) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
120 self.set_next_state(state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
121 return True |
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
|
122 |
179
3374ff7e7388
Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
177
diff
changeset
|
123 if keys.get_project_edit() in key: |
3374ff7e7388
Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
177
diff
changeset
|
124 proj = self.view.item_in_focus() |
3374ff7e7388
Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
177
diff
changeset
|
125 if not proj: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
126 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
127 state = ProjectEditKeyState(self.controller, self.view, proj) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
128 self.set_next_state(state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
129 return True |
179
3374ff7e7388
Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
177
diff
changeset
|
130 |
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
|
131 else: |
98
7c3f43bfc0a8
Only accept single keys for project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
132 if len(key) > 0 and len(key[0]) == 1: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
133 state = SelectProjectState(self.controller, self.view) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
134 self.set_next_state(state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
135 return state.handle_input(key) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
136 return False |
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 |
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
|
138 def select(self): |
89
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
139 proj = self.view.item_in_focus() |
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
140 self.controller.start_project(proj) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
141 state = RunningProjectsState(self.controller, self.view, proj) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
142 self.set_next_state(state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
143 return True |
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
|
144 |
170 | 145 |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
146 class SelectProjectState(State): |
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
147 |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
148 def __init__(self, controller, view): |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
149 super(SelectProjectState, self).__init__(controller, view) |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
150 self.proj_keys = "" |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
151 self.set_footer_text() |
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
152 |
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
153 def reset(self): |
231
2c944fd2cd0c
Reset footer after project is selected instead of clearing the footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
207
diff
changeset
|
154 self.view.reset_footer() |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
155 |
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
156 def set_footer_text(self): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
157 self.view.set_footer_text("Selecting project from key: %s" % \ |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
158 self.proj_keys, "running") |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
159 |
155
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
160 def check_key(self, key): |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
161 return len(self.controller.find_projects_by_key(key)) |
155
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
162 |
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
163 def select_project(self): |
95
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
164 proj = self.controller.project_by_key(self.proj_keys) |
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
165 if proj: |
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
166 self.reset() |
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
167 self.view.select_project(proj) |
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
168 self.controller.start_project(self.view.item_in_focus()) |
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
169 self.controller.update_entries( |
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
170 self.view.item_in_focus()) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
171 self.set_next_state(RunningProjectsState(self.controller, self.view, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
172 proj)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
173 return True |
95
19e9d76a10fb
Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
94
diff
changeset
|
174 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
175 def handle_input(self, key): |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
176 keys = self.config.get_keybinding() |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
177 if keys.get_escape() in key: |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
178 self.reset() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
179 self.set_next_state(PausedProjectsState(self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
180 return True |
139
6a19e721fbd1
Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
138
diff
changeset
|
181 |
6a19e721fbd1
Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
138
diff
changeset
|
182 if 'backspace' in key: |
6a19e721fbd1
Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
138
diff
changeset
|
183 if len(self.proj_keys) > 0: |
6a19e721fbd1
Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
138
diff
changeset
|
184 self.proj_keys = self.proj_keys[:-1] |
6a19e721fbd1
Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
138
diff
changeset
|
185 self.set_footer_text() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
186 return True |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
187 |
155
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
188 if keys.get_enter() in key: |
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
189 return self.select_project() |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
190 |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
191 else: |
98
7c3f43bfc0a8
Only accept single keys for project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
97
diff
changeset
|
192 if len(key) > 0 and len(key[0]) == 1: |
155
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
193 proj_key = self.proj_keys + key[0] |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
194 num = self.check_key(proj_key) |
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
195 if num > 0: |
155
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
196 self.proj_keys += key[0] |
497ed1991e85
Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
152
diff
changeset
|
197 self.set_footer_text() |
167
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
198 if num == 1: |
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
199 # run project directly |
be9acb00cd97
Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents:
155
diff
changeset
|
200 return self.select_project() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
201 return False |
94
159a1ef0fd7c
Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents:
93
diff
changeset
|
202 |
170 | 203 |
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
|
204 class ExitState(ProjectState): |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
205 |
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
|
206 messages = { |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
207 'quit' : _(" Really quit? (y/n)"), |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
208 'choose': _(" Choose a project:") |
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
|
209 } |
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
|
210 |
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
|
211 def __init__(self, controller, view): |
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 super(ExitState, self).__init__(controller, view) |
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 self.controller.view.set_footer_text(self.msg('quit'), 'question') |
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 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
215 def handle_input(self, 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
|
216 logger.debug("ExitState: handle key '%r'" % key) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
217 ret = super(ExitState, self).handle_input(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
|
218 if ret: |
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
|
219 return ret |
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
|
220 |
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 if 'y' in key or 'Y' in 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
|
222 self.controller.exit() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
223 return True |
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
|
224 |
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
|
225 if 'n' in key or 'N' in 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
|
226 self.controller.view.set_footer_text(self.msg('choose'), 'question') |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
227 self.set_next_state(PausedProjectsState(self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
228 return True |
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
|
229 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
230 return False |
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
|
231 |
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
|
232 |
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
|
233 class RunningProjectsState(ProjectState): |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
234 |
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
|
235 messages = { |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
236 'description': _("Enter a description: "), |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
237 'add_time' : _("Enter time to add [min]: "), |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
238 'min_time' : _("Enter time to subtract [min]: "), |
152
7ffcd2ea92e3
Fix messages when a project is paused
Björn Ricks <bjoern.ricks@intevation.de>
parents:
151
diff
changeset
|
239 'continue' : _("Press '%s' to continue."), |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
240 'running' : _("Running ( %s ) on '%s'."), |
152
7ffcd2ea92e3
Fix messages when a project is paused
Björn Ricks <bjoern.ricks@intevation.de>
parents:
151
diff
changeset
|
241 'paused' : _(" Break ( %s ) %s."), |
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
|
242 } |
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 |
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 sec = 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
|
245 break_start = None |
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 |
89
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
247 def __init__(self, controller, view, project): |
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 super(RunningProjectsState, self).__init__(controller, view) |
89
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
249 self.project = project |
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 signal.signal(signal.SIGALRM, self.handle_signal) |
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 signal.alarm(1) |
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 |
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
|
253 def handle_signal(self, signum, frame): |
89
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
254 proj = self.project |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
255 keys = self.config.get_keybinding() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
256 |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
134
diff
changeset
|
257 if not proj: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
134
diff
changeset
|
258 return |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
259 |
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
|
260 if not self.break_start: |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
261 self.controller.view.set_footer_text(self.msg('running') % |
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
|
262 (human_time(self.sec), |
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
|
263 proj.desc), |
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
|
264 'running') |
194
cf98dc7f9354
Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents:
179
diff
changeset
|
265 self.controller.loop.draw_screen() |
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
|
266 self.sec = self.sec + 1 |
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
|
267 else: |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
268 self.view.set_footer_text(self.msg('paused') % |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
269 (human_time((datetime.now() - self.break_start).seconds), |
171
a34693c5905f
Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
170
diff
changeset
|
270 self.msg('continue') % keys.get_project_pause()), |
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
|
271 'paused_running') |
194
cf98dc7f9354
Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents:
179
diff
changeset
|
272 self.controller.loop.draw_screen() |
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
|
273 |
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
|
274 signal.signal(signal.SIGALRM, self.handle_signal) |
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
|
275 signal.alarm(1) |
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
|
276 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
277 def handle_input(self, 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
|
278 logger.debug("RunningProjectsState: handle key '%r'" % key) |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
279 keys = self.config.get_keybinding() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
280 ret = super(RunningProjectsState, self).handle_input(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
|
281 if ret: |
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 return ret |
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 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
284 if keys.get_enter() in 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
|
285 return self.stop() |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
286 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
287 if keys.get_add_time() in 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
|
288 self.view.set_footer_text(self.msg('add_time'), |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
289 'question', 1) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
290 self.set_next_state(AddTimeState(self.controller, self.view, self)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
291 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
292 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
293 if keys.get_subtract_time() in 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
|
294 self.view.set_footer_text(self.msg('min_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
|
295 'question', 1) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
296 self.set_next_state(SubtractTimeState(self.controller, self.view, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
297 self)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
298 return True |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
299 |
171
a34693c5905f
Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
170
diff
changeset
|
300 if keys.get_project_pause() in key: |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
301 if not self.break_start: |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
302 self.break_start = datetime.now() |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
303 else: |
278
96037ad10cff
Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
277
diff
changeset
|
304 self.view.show_total_time() |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
305 proj = self.project |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
306 if proj: |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
307 proj.start += datetime.now() - self.break_start |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
308 self.break_start = None |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
309 signal.signal(signal.SIGALRM, self.handle_signal) |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
310 signal.alarm(1) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
311 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
312 return False |
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
|
313 |
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
|
314 def stop(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
|
315 signal.alarm(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
|
316 self.view.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
|
317 if self.break_start: |
89
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
318 proj = self.project |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
319 if proj: |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
320 proj.start += datetime.now() - self.break_start |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
321 self.controller.view.set_footer_text(self.msg('description'), |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
322 'question', edit=True) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
323 self.set_next_state(DescriptionProjectsState(self.controller, self.view, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
324 self, self.controller.view.get_frame().get_footer())) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
325 return True |
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
|
326 |
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
|
327 |
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 class HandleUserInputState(State): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
329 |
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
|
330 def __init__(self, controller, view, state, footer): |
150
7ab5b887a7c5
Always call super constructor of states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
145
diff
changeset
|
331 super(HandleUserInputState, self).__init__(controller, view) |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
332 self.state = state |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
333 self.footer = 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
|
334 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
335 def handle_input(self, 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
|
336 logger.debug("HandleUserInputState: handle key '%r'" % key) |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
337 keys = self.config.get_keybinding() |
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
|
338 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
339 if keys.get_escape() in 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
|
340 return self.exit() |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
341 elif keys.get_enter() in 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
|
342 return self.enter() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
343 return False |
39
d4ce02a33acd
Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
37
diff
changeset
|
344 |
d4ce02a33acd
Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
37
diff
changeset
|
345 def enter(self): |
d4ce02a33acd
Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
37
diff
changeset
|
346 raise Exception("Not implemented") |
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
|
347 |
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
|
348 def exit(self): |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
349 self.set_next_state(self.state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
350 return True |
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
|
351 |
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
|
352 |
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
|
353 class BaseTimeState(HandleUserInputState): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
354 |
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
|
355 def __init__(self, controller, view, running_state): |
44
f10126519797
Fixed super call
Sascha L. Teichmann <teichmann@intevation.de>
parents:
43
diff
changeset
|
356 super(BaseTimeState, self).__init__(controller, view, running_state, |
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
|
357 view.frame.get_footer()) |
89
3bea335c0f30
Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents:
88
diff
changeset
|
358 self.project = running_state.project |
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
|
359 |
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
|
360 def exit(self): |
278
96037ad10cff
Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
277
diff
changeset
|
361 self.view.show_total_time() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
362 return super(BaseTimeState, self).exit() |
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
|
363 |
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
|
364 def insert(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
|
365 if key[0] in ['0','1','2','3','4','5','6','7','8','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
|
366 self.footer.insert_text(key[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
|
367 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
|
368 logger.debug("BaseTimeState: invalid character for "\ |
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
|
369 "adding/subtracting time: '%r'" % key) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
370 return True |
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
|
371 |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
372 def set_focus(self): |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
373 self.controller.view.set_focus("projects") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
374 self.view.frame.set_focus("footer") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
375 |
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
|
376 |
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
|
377 class AddTimeState(BaseTimeState): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
378 |
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
|
379 def enter(self): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
380 minutes = safe_int(self.view.frame.get_footer().get_edit_text()) |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
381 project = self.project |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
382 project.start -= timedelta(minutes=minutes) |
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
|
383 self.state.sec += minutes * 60 |
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
|
384 logger.info("AddTimeState: add %d minutes to project '%s'" |
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
|
385 % (minutes, project.desc)) |
278
96037ad10cff
Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
277
diff
changeset
|
386 self.view.show_total_time() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
387 self.set_next_state(self.state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
388 return True |
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
|
389 |
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
|
390 |
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
|
391 class SubtractTimeState(BaseTimeState): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
392 |
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
|
393 def enter(self): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
394 minutes = safe_int(self.view.frame.get_footer().get_edit_text()) |
76
07394c6155e2
Don't crash if subtracted time is greater then the current time
Björn Ricks <bjoern.ricks@intevation.de>
parents:
74
diff
changeset
|
395 sec = minutes * 60 |
07394c6155e2
Don't crash if subtracted time is greater then the current time
Björn Ricks <bjoern.ricks@intevation.de>
parents:
74
diff
changeset
|
396 if sec > self.state.sec: |
278
96037ad10cff
Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
277
diff
changeset
|
397 self.view.show_total_time() |
76
07394c6155e2
Don't crash if subtracted time is greater then the current time
Björn Ricks <bjoern.ricks@intevation.de>
parents:
74
diff
changeset
|
398 return self.state |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
399 project = self.project |
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
400 project.start += timedelta(minutes=minutes) |
76
07394c6155e2
Don't crash if subtracted time is greater then the current time
Björn Ricks <bjoern.ricks@intevation.de>
parents:
74
diff
changeset
|
401 self.state.sec -= sec |
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
|
402 logger.info("SubtractTimeState: subtract %d minutes from project '%s'" |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
403 % (minutes, project.desc)) |
278
96037ad10cff
Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
277
diff
changeset
|
404 self.view.show_total_time() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
405 self.set_next_state(self.state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
406 return True |
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
|
407 |
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
|
408 |
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
|
409 class DescriptionProjectsState(HandleUserInputState): |
279
2cef4ba1207a
Add docstring to DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
278
diff
changeset
|
410 """ Adds a description to a stopped running project """ |
2cef4ba1207a
Add docstring to DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
278
diff
changeset
|
411 |
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
|
412 messages = { |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
413 'choose_proj': _(" Choose a project."), |
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
|
414 } |
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
|
415 |
246
2b2738c8c130
Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
243
diff
changeset
|
416 def keypress(self, size, key): |
2b2738c8c130
Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
243
diff
changeset
|
417 """ Direct key to frame of GetanView """ |
2b2738c8c130
Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
243
diff
changeset
|
418 self.controller.view.frame.keypress(size, key) |
2b2738c8c130
Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
243
diff
changeset
|
419 |
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
|
420 def enter(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
|
421 text = self.footer.get_edit_text() |
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
|
422 if text == '': |
247
ee04fc66891f
Return True here instead of self
Björn Ricks <bjoern.ricks@intevation.de>
parents:
246
diff
changeset
|
423 return True |
30
fea63a224065
Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
27
diff
changeset
|
424 self.controller.stop_project(text) |
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
|
425 self.controller.view.set_footer_text(self.msg('choose_proj'), 'question') |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
426 self.set_next_state(PausedProjectsState(self.controller, self.view)) |
286
96843aedcf5e
Update rows when stopping a running project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
282
diff
changeset
|
427 self.view.update_rows() |
280
44a5fe190ab6
Show total when a entry is changed
Björn Ricks <bjoern.ricks@intevation.de>
parents:
279
diff
changeset
|
428 self.view.show_total_time() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
429 return True |
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
|
430 |
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
|
431 def exit(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
|
432 project = self.view.item_in_focus() |
43 | 433 if project: |
434 time = (datetime.now() - project.start).seconds | |
435 self.state.sec = time | |
436 signal.signal(signal.SIGALRM, self.state.handle_signal) | |
437 signal.alarm(1) | |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
438 return super(DescriptionProjectsState, self).exit() |
106 | 439 |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
440 def set_focus(self): |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
441 self.controller.view.set_focus("footer") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
442 |
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
|
443 |
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
|
444 class EntryListState(State): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
445 |
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
|
446 def __init__(self, state, controller, view): |
150
7ab5b887a7c5
Always call super constructor of states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
145
diff
changeset
|
447 super(EntryListState, self).__init__(controller, view) |
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
|
448 self.projectlist_state = state |
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
|
449 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
450 def handle_input(self, 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
|
451 logger.debug("EntryListState: pressed key '%r'" % key) |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
452 keys = self.config.get_keybinding() |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
453 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
454 if keys.get_switch_lists() in 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
|
455 self.view.clear() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
456 self.set_next_state(self.projectlist_state) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
457 self.controller.view.set_focus(0) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
458 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
459 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
460 if keys.get_enter() in 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
|
461 return self.select() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
462 return False |
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
|
463 |
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
|
464 def select(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
|
465 self.view.select() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
466 return True |
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
|
467 |
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
|
468 def renew_focus(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
|
469 e_len = self.view.row_count() |
235
263fe6ee0e4e
Fix crash when deleting an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
232
diff
changeset
|
470 f = self.view.get_focus_pos() |
135
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
134
diff
changeset
|
471 if f >= e_len: |
ce707fbb9666
Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents:
134
diff
changeset
|
472 f = e_len - 1 |
207
910136052631
Fix setting the focus
Björn Ricks <bjoern.ricks@intevation.de>
parents:
206
diff
changeset
|
473 self.view.set_focus(f) |
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
|
474 |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
475 def set_focus(self): |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
476 self.controller.view.set_focus("entries") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
477 self.controller.entries_view.set_focus(0) |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
478 |
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
|
479 |
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
|
480 class DefaultEntryListState(EntryListState): |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
481 |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
482 def handle_input(self, key): |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
483 logger.info("Handling DefaultEntryListState input") |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
484 ret = super(DefaultEntryListState, self).handle_input(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
|
485 if ret: |
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
|
486 return ret |
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
|
487 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
488 keys = self.config.get_keybinding() |
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
489 if keys.get_escape() in key: |
105
4bf17975acca
Also move back to ProjectListState if esc is pressed not only when tab
Björn Ricks <bjoern.ricks@intevation.de>
parents:
104
diff
changeset
|
490 self.view.clear() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
491 self.set_next_state(self.projectlist_state) |
236
8caa74da6a53
Reset focus to project list when pressing escape in entry list
Björn Ricks <bjoern.ricks@intevation.de>
parents:
235
diff
changeset
|
492 self.controller.view.set_focus(0) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
493 return True |
105
4bf17975acca
Also move back to ProjectListState if esc is pressed not only when tab
Björn Ricks <bjoern.ricks@intevation.de>
parents:
104
diff
changeset
|
494 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
495 if keys.get_entry_delete() in key: |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
496 if self.view.selection: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
497 self.set_next_state(DeleteEntryState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
498 self.controller, self.view)) |
102
cd2456d0589e
Add single entry deletion
Björn Ricks <bjoern.ricks@intevation.de>
parents:
101
diff
changeset
|
499 else: |
cd2456d0589e
Add single entry deletion
Björn Ricks <bjoern.ricks@intevation.de>
parents:
101
diff
changeset
|
500 entry = self.view.item_in_focus() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
501 self.set_next_state(DeleteEntryState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
502 self.controller, self.view, [entry])) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
503 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
504 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
505 if keys.get_entry_move() in key: |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
506 if self.view.selection: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
507 self.set_next_state(MoveEntryState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
508 self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
509 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
510 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
511 if keys.get_entry_edit() in key: |
74
057e0fc8a74d
switch to EditEntryState when 'e' is pressed in the EntryList to be able
Björn Ricks <bjoern.ricks@intevation.de>
parents:
73
diff
changeset
|
512 entry = self.view.item_in_focus() |
057e0fc8a74d
switch to EditEntryState when 'e' is pressed in the EntryList to be able
Björn Ricks <bjoern.ricks@intevation.de>
parents:
73
diff
changeset
|
513 if entry: |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
514 self.set_next_state(EditEntryState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
515 self.controller, self.view, entry)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
516 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
517 |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
518 return False |
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
|
519 |
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
|
520 |
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
|
521 class DeleteEntryState(EntryListState): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
522 |
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
|
523 messages = { |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
524 'delete' : _("Really delete this entry? (y/n)"), |
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
|
525 } |
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
|
526 |
100
8f433e3c2f21
Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
98
diff
changeset
|
527 def __init__(self, state, controller, view, entries=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
|
528 super(DeleteEntryState, self).__init__(state, controller, view) |
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
|
529 self.view.set_footer_text(self.msg('delete'), 'question') |
100
8f433e3c2f21
Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
98
diff
changeset
|
530 self.entries = entries |
8f433e3c2f21
Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
98
diff
changeset
|
531 if not self.entries: |
8f433e3c2f21
Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
98
diff
changeset
|
532 self.entries = [x.item for x in self.view.selection] |
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
|
533 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
534 def handle_input(self, 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
|
535 if 'y' in key: |
100
8f433e3c2f21
Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
98
diff
changeset
|
536 if self.entries: |
8f433e3c2f21
Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
98
diff
changeset
|
537 self.controller.delete_entries(self.entries) |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
538 self.renew_focus() |
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
539 self.view.set_footer_text("", 'entry_footer') |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
540 self.set_next_state(DefaultEntryListState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
541 self.controller, self.view)) |
280
44a5fe190ab6
Show total when a entry is changed
Björn Ricks <bjoern.ricks@intevation.de>
parents:
279
diff
changeset
|
542 self.controller.project_view.show_total_time() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
543 return True |
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
|
544 |
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
|
545 if 'n' in 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
|
546 self.view.set_footer_text("", 'entry_footer') |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
547 self.set_next_state(DefaultEntryListState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
548 self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
549 return True |
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
|
550 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
551 return False |
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
|
552 |
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
|
553 |
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
|
554 class MoveEntryState(EntryListState): |
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
|
555 messages = { |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
30
diff
changeset
|
556 'project': _(" Into which project do you want to move these entries?"), |
103 | 557 'really': _(" Are you sure? (y/n)"), |
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
|
558 } |
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
|
559 |
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
|
560 proj = None |
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
|
561 |
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
|
562 def __init__(self, state, controller, view): |
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
|
563 super(MoveEntryState, self).__init__(state, controller, view) |
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
|
564 self.view.set_footer_text(self.msg('project'), 'question') |
104
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
565 self.proj_keys = "" |
133
78992300f421
Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
130
diff
changeset
|
566 self.project_view = controller.project_view |
104
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
567 |
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
568 def set_project_footer(self): |
133
78992300f421
Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
130
diff
changeset
|
569 self.project_view.set_footer_text("Selecting project from " \ |
104
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
570 "key: %s" % self.proj_keys, "running") |
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
571 |
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
572 def reset_project_footer(self): |
133
78992300f421
Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents:
130
diff
changeset
|
573 self.project_view.reset_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
|
574 |
169
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
575 def check_key(self, key): |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
576 return len(self.controller.find_projects_by_key(key)) |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
577 |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
578 def select_project(self): |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
579 proj = self.controller.project_by_key(self.proj_keys) |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
580 if proj: |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
581 self.proj = proj |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
582 self.reset_project_footer() |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
583 logger.debug("MoveEntryState: prepared entries to be " \ |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
584 "moved to project '%s'" % self.proj.desc) |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
585 self.view.set_footer_text(self.msg('really'), 'question') |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
586 |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
587 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
588 def handle_input(self, key): |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
589 keys = self.config.get_keybinding() |
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
|
590 if 'y' in key and self.proj: |
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
|
591 logger.debug("MoveEntryState: move selected 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
|
592 self.controller.move_selected_entries(self.proj) |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
593 self.renew_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
|
594 self.view.set_footer_text('', 'entry_footer') |
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
|
595 self.proj = None |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
596 self.set_next_state(DefaultEntryListState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
597 self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
598 return True |
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
|
599 |
25
155b23da504b
Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
600 if 'n' in key and self.proj: |
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
|
601 self.view.set_footer_text('', 'entry_footer') |
104
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
602 self.reset_project_footer() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
603 self.set_next_state(DefaultEntryListState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
604 self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
605 return True |
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
|
606 |
151
1e35c24708dd
Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents:
150
diff
changeset
|
607 if keys.get_escape() in 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
|
608 self.view.set_footer_text('', 'entry_footer') |
104
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
609 self.reset_project_footer() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
610 self.set_next_state(DefaultEntryListState(self.projectlist_state, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
611 self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
612 return True |
243 | 613 |
134
c80c7fc6a8fc
Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
133
diff
changeset
|
614 if 'backspace' in key: |
c80c7fc6a8fc
Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
133
diff
changeset
|
615 if len(self.proj_keys) > 0: |
c80c7fc6a8fc
Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
133
diff
changeset
|
616 self.proj_keys = self.proj_keys[:-1] |
c80c7fc6a8fc
Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
133
diff
changeset
|
617 self.set_project_footer() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
618 return True |
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
|
619 |
169
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
620 if keys.get_enter() in key and self.proj is None: |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
621 self.select_project() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
622 return True |
169
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
623 |
104
36204a42bd79
Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
103
diff
changeset
|
624 if len(key) > 0 and len(key[0]) == 1 and self.proj is None: |
169
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
625 proj_key = self.proj_keys + key[0] |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
626 num = self.check_key(proj_key) |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
627 if num > 0: |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
628 self.proj_keys = proj_key |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
629 self.set_project_footer() |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
630 if num == 1: |
d10a0e35b982
Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
167
diff
changeset
|
631 self.select_project() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
632 return True |
170 | 633 |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
634 return False |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
635 |
170 | 636 |
173
a5319bb1ac13
Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
172
diff
changeset
|
637 class AlterProjectState(HandleUserInputState): |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
638 |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
639 messages = { |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
640 'choose_proj': _(' Choose a project.'), |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
641 } |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
642 |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
643 def __init__(self, controller, view): |
173
a5319bb1ac13
Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
172
diff
changeset
|
644 super(AlterProjectState, self).__init__(controller, view, None, |
262
438f6ce81e3d
Fix don't crash when adding a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
253
diff
changeset
|
645 controller.view.get_frame().get_footer()) |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
646 |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
647 def exit(self): |
268
06157568d287
Use kwarg for edit and boolean instead of int
Björn Ricks <bjoern.ricks@intevation.de>
parents:
267
diff
changeset
|
648 self.controller.view.set_footer_text(self.msg('choose_proj'), |
06157568d287
Use kwarg for edit and boolean instead of int
Björn Ricks <bjoern.ricks@intevation.de>
parents:
267
diff
changeset
|
649 'question') |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
650 self.set_next_state(PausedProjectsState(self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
651 return True |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
652 |
267
9fce005e5fc6
Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
262
diff
changeset
|
653 def keypress(self, size, key): |
9fce005e5fc6
Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
262
diff
changeset
|
654 """ Direct key to frame of GetanView """ |
9fce005e5fc6
Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
262
diff
changeset
|
655 self.controller.view.frame.keypress(size, key) |
9fce005e5fc6
Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
262
diff
changeset
|
656 |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
657 def set_focus(self): |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
658 self.controller.view.set_focus("footer") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
659 |
170 | 660 |
173
a5319bb1ac13
Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
172
diff
changeset
|
661 class AddProjectKeyState(AlterProjectState): |
172
b8abca7714fd
Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
662 |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
663 messages = { |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
664 'choose_proj': _(' Choose a project.'), |
172
b8abca7714fd
Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
665 'proj_key': _('Insert key for new project: '), |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
666 } |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
667 |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
668 def __init__(self, controller, view): |
268
06157568d287
Use kwarg for edit and boolean instead of int
Björn Ricks <bjoern.ricks@intevation.de>
parents:
267
diff
changeset
|
669 controller.view.set_footer_text(self.msg('proj_key'), 'question', |
06157568d287
Use kwarg for edit and boolean instead of int
Björn Ricks <bjoern.ricks@intevation.de>
parents:
267
diff
changeset
|
670 edit=True) |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
671 super(AddProjectKeyState, self).__init__(controller, view) |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
672 |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
673 def enter(self): |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
674 key = self.footer.get_edit_text() |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
675 if key == '': |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
676 return True |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
677 self.set_next_state(AddProjectDescriptionState(self.controller, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
678 self.view, key)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
679 return True |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
680 |
170 | 681 |
173
a5319bb1ac13
Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
172
diff
changeset
|
682 class AddProjectDescriptionState(AlterProjectState): |
206
9f1c45a2126e
Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
205
diff
changeset
|
683 |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
684 messages = { |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
685 'proj_description': _('Insert a description for project: '), |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
686 'choose_proj': _(" Choose a project.") |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
687 } |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
688 |
172
b8abca7714fd
Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
689 def __init__(self, controller, view, key): |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
690 controller.view.set_footer_text(self.msg('proj_description'), |
270
8a3dd18a0b61
Update coding style
Björn Ricks <bjoern.ricks@intevation.de>
parents:
269
diff
changeset
|
691 'question', edit=True) |
54
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
692 super(AddProjectDescriptionState, self).__init__(controller, view) |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
693 self.key = key |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
694 |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
695 def enter(self): |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
696 description = self.footer.get_edit_text() |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
697 if description == '': |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
698 return self |
d747563dff03
add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents:
44
diff
changeset
|
699 self.controller.add_project(self.key, description) |
271
60725e0bcddb
Use exit when returning from adding a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
270
diff
changeset
|
700 self.exit() |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
701 return True |
73
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
702 |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
703 |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
704 class EditEntryState(HandleUserInputState): |
281
7efdacb66dee
Add newline to update coding style
Björn Ricks <bjoern.ricks@intevation.de>
parents:
280
diff
changeset
|
705 |
73
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
706 messages = { |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
707 'edit_entry': _('Edit entry text: '), |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
708 } |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
709 |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
710 def __init__(self, state, controller, view, entry): |
87
0e5b6826a4ef
Use footer of EntryList to display the editable description of an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
76
diff
changeset
|
711 view.set_footer_text(self.msg('edit_entry'), |
0e5b6826a4ef
Use footer of EntryList to display the editable description of an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
76
diff
changeset
|
712 'question', True) |
73
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
713 super(EditEntryState, self).__init__(controller, view, |
87
0e5b6826a4ef
Use footer of EntryList to display the editable description of an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
76
diff
changeset
|
714 None, view.footer) |
73
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
715 self.footer.set_edit_text(entry.desc) |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
716 self.footer.set_edit_pos(len(self.footer.edit_text)) |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
717 self.entry = entry |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
718 self.state = state |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
719 logger.debug("EditEntryState: Entry %s" % entry) |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
720 |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
721 def enter(self): |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
722 entry_desc = self.footer.get_edit_text() |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
723 if entry_desc == '': |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
724 return self |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
725 entry = self.entry |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
726 entry.desc = entry_desc |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
727 self.controller.update_entry(entry) |
87
0e5b6826a4ef
Use footer of EntryList to display the editable description of an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
76
diff
changeset
|
728 self.view.node_in_focus().update() |
73
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
729 return self.exit() |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
730 |
745c644d9564
Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents:
72
diff
changeset
|
731 def exit(self): |
87
0e5b6826a4ef
Use footer of EntryList to display the editable description of an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents:
76
diff
changeset
|
732 self.view.set_footer_text("", 'entry_footer', False) |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
733 self.set_next_state(DefaultEntryListState(self.state, self.controller, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
734 self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
735 return True |
177
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
736 |
277
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
737 def set_focus(self): |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
738 self.controller.view.set_focus("entries") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
739 self.view.frame.set_focus("footer") |
3d6315be2251
Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
276
diff
changeset
|
740 |
177
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
741 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
742 class ProjectEditKeyState(AlterProjectState): |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
743 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
744 messages = { |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
745 'proj_key': _('Insert key for project: '), |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
746 'proj_description': _('Insert description for project: '), |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
747 'choose_proj': _(" Choose a project.") |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
748 } |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
749 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
750 def __init__(self, controller, view, project): |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
751 controller.view.set_footer_text(self.msg('proj_key'), |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
752 'question', 1) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
753 super(ProjectEditKeyState, self).__init__(controller, view) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
754 self.project = project |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
755 self.footer.set_edit_text(project.key) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
756 self.footer.set_edit_pos(len(self.footer.edit_text)) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
757 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
758 def enter(self): |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
759 key = self.footer.get_edit_text() |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
760 if key == '': |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
761 return True |
177
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
762 self.project.key = key |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
763 self.set_next_state(ProjectEditDescriptionState(self.controller, |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
764 self.view, self.project)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
765 return True |
177
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
766 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
767 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
768 class ProjectEditDescriptionState(AlterProjectState): |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
769 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
770 messages = { |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
771 "proj_description" : _("Insert description for project: "), |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
772 "choose_proj" : _(" Choose a project.") |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
773 } |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
774 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
775 def __init__(self, controller, view, project): |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
776 controller.view.set_footer_text(self.msg("proj_description"), |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
777 "question", 1) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
778 super(ProjectEditDescriptionState, self).__init__(controller, view) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
779 self.project = project |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
780 self.footer.set_edit_text(project.desc) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
781 self.footer.set_edit_pos(len(self.footer.edit_text)) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
782 |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
783 def enter(self): |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
784 description = self.footer.get_edit_text() |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
785 if description == '': |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
786 return self |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
787 self.project.desc = description |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
788 self.controller.update_project(self.project) |
c37fb8223762
Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents:
173
diff
changeset
|
789 self.controller.view.set_footer_text(self.msg('choose_proj'), 'question') |
205
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
790 self.set_next_state(PausedProjectsState(self.controller, self.view)) |
a1b00ffea269
Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents:
197
diff
changeset
|
791 return True |