annotate getan/states.py @ 246:2b2738c8c130

Redirect key event to GetanView Frame in DescriptionProjectsState
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 09 Apr 2013 22:18:52 +0200
parents 9bf0ad952c68
children ee04fc66891f
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
145
ccd47a2d37a6 Carefully handle non unicode strings for urwid
Björn Ricks <bjoern.ricks@intevation.de>
parents: 142
diff changeset
12 import locale
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
13 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
14 import signal
195
0c0d88ec53f9 Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
15
0c0d88ec53f9 Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
16 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
17
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
18 from getan.resources import gettext as _
195
0c0d88ec53f9 Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
19 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
20
9c4e8ba3c4fa 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 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
22
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
23 class State(object):
197
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
24 """ Represents a State of Getan
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
25
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
26 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
27 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
28 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
29 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
30 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
31 handle_input.
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
32
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
33 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
34 state.
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
35 """
196
2c4cfc79632c Fix coding style for State class
Björn Ricks <bjoern.ricks@intevation.de>
parents: 195
diff changeset
36
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
37 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
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
9c4e8ba3c4fa 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 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
41 self.controller = controller
196
2c4cfc79632c Fix coding style for State class
Björn Ricks <bjoern.ricks@intevation.de>
parents: 195
diff changeset
42 self.view = view
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
43 self.config = controller.get_config()
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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
67
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
68 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
69
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
70 def handle_input(self, input):
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
71 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
72 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
73 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
74 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
75 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
76
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
77 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
78 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
79 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
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_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
82 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
83 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
84 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
85 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
86 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
87 self.controller.view.set_focus(1)
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 self.controller.entries_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
89 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
90
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
91
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 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
93
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
94 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
95 '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
96 }
9c4e8ba3c4fa 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
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 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
99 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
100 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
101 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
102 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
103 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
104
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
105 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
106 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
107
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
108 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
109 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
110 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
111 return True
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
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_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
114 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
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
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
117
179
3374ff7e7388 Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 177
diff changeset
118 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
119 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
120 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
121 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
122 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
123 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
124 return True
179
3374ff7e7388 Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 177
diff changeset
125
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
126 else:
98
7c3f43bfc0a8 Only accept single keys for project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 97
diff changeset
127 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
128 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
129 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
130 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
131 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
132
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
133 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
134 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
135 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
136 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
137 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
138 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
139
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
140
94
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
141 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
142
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
143 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
144 super(SelectProjectState, self).__init__(controller, view)
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
145 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
146 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
147
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
148 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
149 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
150
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
151 def set_footer_text(self):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
152 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
153 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
154
155
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
155 def check_key(self, key):
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
156 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
157
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
158 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
159 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
160 if proj:
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
161 self.reset()
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
162 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
163 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
164 self.controller.update_entries(
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
165 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
166 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
167 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
168 return True
95
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
169
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
170 def handle_input(self, key):
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
171 keys = self.config.get_keybinding()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
172 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
173 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
174 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
175 return True
139
6a19e721fbd1 Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 138
diff changeset
176
6a19e721fbd1 Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 138
diff changeset
177 if 'backspace' in key:
6a19e721fbd1 Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 138
diff changeset
178 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
179 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
180 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
181 return True
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
182
155
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
183 if keys.get_enter() in key:
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
184 return self.select_project()
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
185
94
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
186 else:
98
7c3f43bfc0a8 Only accept single keys for project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 97
diff changeset
187 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
188 proj_key = self.proj_keys + key[0]
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
189 num = self.check_key(proj_key)
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
190 if num > 0:
155
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
191 self.proj_keys += key[0]
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
192 self.set_footer_text()
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
193 if num == 1:
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
194 # run project directly
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
195 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
196 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
197
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
198
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
199 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
200
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
201 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
202 'quit' : _(" Really quit? (y/n)"),
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
203 '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
204 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
205
9c4e8ba3c4fa 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 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
207 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
208 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
209
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
210 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
211 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
212 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
213 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
214 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
215
9c4e8ba3c4fa 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 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
217 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
218 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
219
9c4e8ba3c4fa 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 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
221 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
222 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
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
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
225 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
226
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
227
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
228 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
229
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
230 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
231 'description': _("Enter a description: "),
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
232 '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
233 '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
234 '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
235 '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
236 '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
237 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
238
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
239 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
240 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
241
89
3bea335c0f30 Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents: 88
diff changeset
242 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
243 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
244 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
245 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
246 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
247
9c4e8ba3c4fa 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 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
249 proj = self.project
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
250 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
251
135
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 134
diff changeset
252 if not proj:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 134
diff changeset
253 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
254
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
255 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
256 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
257 (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
258 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
259 'running')
194
cf98dc7f9354 Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents: 179
diff changeset
260 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
261 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
262 else:
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
263 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
264 (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
265 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
266 'paused_running')
194
cf98dc7f9354 Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents: 179
diff changeset
267 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
268
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
269 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
270 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
271
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
272 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
273 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
274 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
275 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
276 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
277 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
278
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
279 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
280 return self.stop()
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
281
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
282 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
283 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
284 'question', 1)
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
285 self.view.frame.set_focus('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
286 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
287 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
288
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
289 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
290 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
291 'question', 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
292 self.view.frame.set_focus('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
293 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
294 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
295 return True
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
296
171
a34693c5905f Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 170
diff changeset
297 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
298 if not self.break_start:
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
299 self.break_start = datetime.now()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
300 else:
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
301 self.view._total_time()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
302 proj = self.project
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
303 if proj:
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
304 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
305 self.break_start = None
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
306 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
307 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
308 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
309 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
310
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
311 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
312 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
313 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
314 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
315 proj = self.project
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
316 if proj:
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
317 proj.start += datetime.now() - self.break_start
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
318 self.controller.view.set_footer_text(self.msg('description'),'question',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
319 self.controller.view.get_frame().set_focus('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
320 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
321 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
322 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
323
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
324
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
325 class HandleUserInputState(State):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
326
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
327 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
328 super(HandleUserInputState, self).__init__(controller, view)
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
329 self.state = state
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
330 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
331
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
332 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
333 logger.debug("HandleUserInputState: handle key '%r'" % key)
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
334 pos = self.footer.edit_pos
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
335 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
336
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
337 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
338 return self.exit()
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
339 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
340 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
341 return False
39
d4ce02a33acd Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 37
diff changeset
342
d4ce02a33acd Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 37
diff changeset
343 def enter(self):
d4ce02a33acd Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 37
diff changeset
344 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
345
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
346 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
347 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
348 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
349
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
350
9c4e8ba3c4fa 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 class BaseTimeState(HandleUserInputState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
352
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
353 def __init__(self, controller, view, running_state):
44
f10126519797 Fixed super call
Sascha L. Teichmann <teichmann@intevation.de>
parents: 43
diff changeset
354 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
355 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
356 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
357
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
358 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
359 self.view._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
360 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
361
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
362 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
363 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
364 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
365 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
366 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
367 "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
368 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
369
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
370
9c4e8ba3c4fa 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 class AddTimeState(BaseTimeState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
372
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
373 def enter(self):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
374 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
375 project = self.project
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
376 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
377 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
378 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
379 % (minutes, project.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
380 self.view._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
381 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
382 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
383
9c4e8ba3c4fa 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
9c4e8ba3c4fa 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 class SubtractTimeState(BaseTimeState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
386
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
387 def enter(self):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
388 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
389 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
390 if sec > self.state.sec:
07394c6155e2 Don't crash if subtracted time is greater then the current time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 74
diff changeset
391 self.view._total_time()
07394c6155e2 Don't crash if subtracted time is greater then the current time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 74
diff changeset
392 return self.state
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
393 project = self.project
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
394 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
395 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
396 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
397 % (minutes, project.desc))
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
398 self.view._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
399 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
400 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
401
9c4e8ba3c4fa 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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
403 class DescriptionProjectsState(HandleUserInputState):
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
404 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
405 '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
406 }
9c4e8ba3c4fa 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
246
2b2738c8c130 Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 243
diff changeset
408 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
409 """ 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
410 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
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 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
413 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
414 if 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
415 return self
30
fea63a224065 Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 27
diff changeset
416 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
417 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
418 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
419 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
420
9c4e8ba3c4fa 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 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
422 project = self.view.item_in_focus()
43
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
423 if project:
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
424 time = (datetime.now() - project.start).seconds
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
425 self.state.sec = time
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
426 signal.signal(signal.SIGALRM, self.state.handle_signal)
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
427 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
428 return super(DescriptionProjectsState, self).exit()
106
a0779fb2ef4d Remove space
Björn Ricks <bjoern.ricks@intevation.de>
parents: 105
diff changeset
429
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 class EntryListState(State):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
432
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
433 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
434 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
435 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
436
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
437 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
438 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
439 keys = self.config.get_keybinding()
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
440
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
441 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
442 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
443 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
444 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
445 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
446
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
447 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
448 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
449 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
450
9c4e8ba3c4fa 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 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
452 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
453 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
454
9c4e8ba3c4fa 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 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
456 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
457 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
458 if f >= e_len:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 134
diff changeset
459 f = e_len - 1
207
910136052631 Fix setting the focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 206
diff changeset
460 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
461
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
462
9c4e8ba3c4fa 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 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
464
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
465 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
466 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
467 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
468 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
469 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
470
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
471 keys = self.config.get_keybinding()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
472 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
473 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
474 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
475 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
476 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
477
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
478 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
479 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
480 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
481 self.controller, self.view))
102
cd2456d0589e Add single entry deletion
Björn Ricks <bjoern.ricks@intevation.de>
parents: 101
diff changeset
482 else:
cd2456d0589e Add single entry deletion
Björn Ricks <bjoern.ricks@intevation.de>
parents: 101
diff changeset
483 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
484 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
485 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
486 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
487
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
488 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
489 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
490 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
491 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
492 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
493
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
494 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
495 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
496 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
497 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
498 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
499 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
500
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 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
502
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
503
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
504 class DeleteEntryState(EntryListState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
505
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
506 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
507 '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
508 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
509
100
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
510 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
511 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
512 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
513 self.entries = entries
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
514 if not self.entries:
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
515 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
516
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
517 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
518 if 'y' in key:
100
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
519 if self.entries:
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
520 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
521 self.renew_focus()
155b23da504b Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 23
diff changeset
522 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
523 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
524 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
525 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
526
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
527 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
528 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
529 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
530 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
531 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
532
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
533 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
534
9c4e8ba3c4fa 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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
536 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
537 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
538 'project': _(" Into which project do you want to move these entries?"),
103
9546120437c7 Fix question
Björn Ricks <bjoern.ricks@intevation.de>
parents: 102
diff changeset
539 '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
540 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
541
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
542 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
543
9c4e8ba3c4fa 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 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
545 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
546 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
547 self.proj_keys = ""
133
78992300f421 Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 130
diff changeset
548 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
549
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
550 def set_project_footer(self):
133
78992300f421 Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 130
diff changeset
551 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
552 "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
553
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
554 def reset_project_footer(self):
133
78992300f421 Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 130
diff changeset
555 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
556
169
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
557 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
558 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
559
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
560 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
561 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
562 if proj:
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
563 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
564 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
565 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
566 "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
567 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
568
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
569
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
570 def handle_input(self, key):
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
571 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
572 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
573 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
574 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
575 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
576 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
577 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
578 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
579 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
580 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
581
25
155b23da504b Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 23
diff changeset
582 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
583 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
584 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
585 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
586 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
587 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
588
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
589 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
590 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
591 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
592 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
593 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
594 return True
243
9bf0ad952c68 Add newline
Björn Ricks <bjoern.ricks@intevation.de>
parents: 236
diff changeset
595
134
c80c7fc6a8fc Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 133
diff changeset
596 if 'backspace' in key:
c80c7fc6a8fc Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 133
diff changeset
597 if len(self.proj_keys) > 0:
c80c7fc6a8fc Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 133
diff changeset
598 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
599 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
600 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
601
169
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
602 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
603 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
604 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
605
104
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
606 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
607 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
608 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
609 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
610 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
611 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
612 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
613 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
614 return True
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
615
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
616 return False
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
617
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
618
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
619 class AlterProjectState(HandleUserInputState):
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
620
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
621 messages = {
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
622 'choose_proj': _(' Choose a project.'),
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
623 }
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
624
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
625 def __init__(self, controller, view):
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
626 super(AlterProjectState, self).__init__(controller, view, None,
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
627 controller.view.view.get_footer())
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
628
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
629 def exit(self):
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
630 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
631 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
632 return True
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
633
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
634
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
635 class AddProjectKeyState(AlterProjectState):
172
b8abca7714fd Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 171
diff changeset
636
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
637 messages = {
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
638 'choose_proj': _(' Choose a project.'),
172
b8abca7714fd Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 171
diff changeset
639 '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
640 }
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 def __init__(self, controller, view):
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
643 controller.view.set_footer_text(self.msg('proj_key'),
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
644 'question', 1)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
645 super(AddProjectKeyState, self).__init__(controller, view)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
646 self.view.frame.set_focus('footer')
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
647
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
648 def enter(self):
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
649 key = self.footer.get_edit_text()
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
650 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
651 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
652 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
653 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
654 return True
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
655
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
656
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
657 class AddProjectDescriptionState(AlterProjectState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
658
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
659 messages = {
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
660 'proj_description': _('Insert a description for project: '),
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
661 'choose_proj': _(" Choose a project.")
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
662 }
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
663
172
b8abca7714fd Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 171
diff changeset
664 def __init__(self, controller, view, key):
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
665 controller.view.set_footer_text(self.msg('proj_description'),
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
666 'question', 1)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
667 super(AddProjectDescriptionState, self).__init__(controller, view)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
668 self.view.frame.set_focus('footer')
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
669 self.key = key
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
670
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
671 def enter(self):
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
672 description = self.footer.get_edit_text()
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
673 if description == '':
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
674 return self
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
675 self.controller.add_project(self.key, description)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
676 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
677 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
678 return True
73
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
679
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
680
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
681 class EditEntryState(HandleUserInputState):
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
682 messages = {
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
683 'edit_entry': _('Edit entry text: '),
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
684 }
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
685
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
686 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
687 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
688 'question', True)
73
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
689 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
690 None, view.footer)
73
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
691 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
692 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
693 self.view.frame.set_focus('footer')
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
694 self.entry = entry
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
695 self.state = state
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
696 logger.debug("EditEntryState: Entry %s" % entry)
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
697
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
698 def enter(self):
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
699 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
700 if entry_desc == '':
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
701 return self
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
702 entry = self.entry
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
703 entry.desc = entry_desc
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
704 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
705 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
706 return self.exit()
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
707
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
708 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
709 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
710 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
711 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
712 return True
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
713
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
714
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
715 class ProjectEditKeyState(AlterProjectState):
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
716
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
717 messages = {
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
718 '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
719 '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
720 '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
721 }
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
722
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
723 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
724 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
725 'question', 1)
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
726 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
727 self.project = project
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
728 self.view.frame.set_focus('footer')
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
729 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
730 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
731
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
732 def enter(self):
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
733 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
734 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
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 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
737 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
738 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
739 return True
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
740
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 ProjectEditDescriptionState(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_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
746 "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
747 }
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 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
750 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
751 "question", 1)
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
752 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
753 self.project = project
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
754 self.view.frame.set_focus("footer")
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.desc)
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 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
760 if description == '':
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
761 return self
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
762 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
763 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
764 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
765 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
766 return True
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)