annotate getan/states.py @ 563:5ec211c172ed

Removed the filter_input step in the processing of states. As far as I see it is not used anywhere.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 22 Sep 2020 17:30:02 +0200
parents 93e740bc730f
children 2c6ff55be046
rev   line source
482
999a438474f2 Changed Hashbangs to python3.
Magnus Schieder <mschieder@intevation.de>
parents: 479
diff changeset
1 #!/usr/bin/env python3
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
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>
385
cf0406ed424a Update copyright and remove empty lines
Björn Ricks <bjoern.ricks@intevation.de>
parents: 384
diff changeset
5 # (c) 2011, 2012, 2014 by Björn Ricks <bjoern.ricks@intevation.de>
488
463894654d77 Prepares for release 3.0
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
6 # (c) 2017, 2018 Intevation GmbH
463894654d77 Prepares for release 3.0
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
7 # Authors:
463894654d77 Prepares for release 3.0
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
8 # * Bernhard Reiter <Bernhard.Reiter@intevation.de>
463894654d77 Prepares for release 3.0
Magnus Schieder <mschieder@intevation.de>
parents: 482
diff changeset
9 # * Magnus Schieder <magnus.schieder@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
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 # 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
12 # 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
13
9c4e8ba3c4fa 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 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
15 import signal
195
0c0d88ec53f9 Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
16
0c0d88ec53f9 Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
17 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
18
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
19 from getan.resources import gettext as _
195
0c0d88ec53f9 Change coding style for imports
Björn Ricks <bjoern.ricks@intevation.de>
parents: 194
diff changeset
20 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
21
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
22 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
23
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
24
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
25 class State(object):
197
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
26 """ Represents a State of Getan
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
27
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
28 A State can be used to handle user input. The user input handling is done
563
5ec211c172ed Removed the filter_input step in the processing of states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 530
diff changeset
29 in two phases.
5ec211c172ed Removed the filter_input step in the processing of states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 530
diff changeset
30 First it is possible to redirect a key to a specific widget in keypress.
5ec211c172ed Removed the filter_input step in the processing of states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 530
diff changeset
31 In the second phase it is possible
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
32 to act on user input which isn't handled by a widget yet. The corresponing
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
33 method is handle_input.
197
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
34
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
35 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
36 state.
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
37 """
196
2c4cfc79632c Fix coding style for State class
Björn Ricks <bjoern.ricks@intevation.de>
parents: 195
diff changeset
38
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
39 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
40 }
9c4e8ba3c4fa 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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
42 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
43 self.controller = controller
196
2c4cfc79632c Fix coding style for State class
Björn Ricks <bjoern.ricks@intevation.de>
parents: 195
diff changeset
44 self.view = view
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
45 self.config = controller.get_config()
276
dd575513ee1b Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 271
diff changeset
46 self.set_focus()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
47
197
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
48 def keypress(self, size, key):
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
49 """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
50 self.view.keypress(size, key)
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 handle_input(self, input):
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
53 """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
54 raise NotImplementedError()
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 set_next_state(self, state):
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
57 """Sets the next state"""
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
58 self.controller.set_state(state)
2eb2bbf042b3 Inplement new State user input handling
Björn Ricks <bjoern.ricks@intevation.de>
parents: 196
diff changeset
59
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
60 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
61 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
62
276
dd575513ee1b Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 271
diff changeset
63 def set_focus(self):
dd575513ee1b Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 271
diff changeset
64 """ Override this method to set the focus when the state is created """
dd575513ee1b Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 271
diff changeset
65 pass
dd575513ee1b Add new State method set_focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 271
diff changeset
66
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
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
479
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
81 if 'ctrl l' in input:
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
82 self.controller.redraw()
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
83 return True
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
84
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
85 if keys.get_switch_lists() in input:
72
90b61a24742b Don't switch to EntryView if it doesn't contain any row/entry
Björn Ricks <bjoern.ricks@intevation.de>
parents: 56
diff changeset
86 if not self.controller.entries_view.rows:
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
87 return True
469
050ffdec60d9 Fix the orientation problem
Magnus Schieder <mschieder@intevation.de>
parents: 468
diff changeset
88 self.view.highlight_open_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
89 new_state = DefaultEntryListState(self, self.controller,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
90 self.controller.entries_view)
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
91 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
92 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
93
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
94 def set_focus(self):
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
95 self.controller.view.set_focus("projects")
303
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
96 self.view.frame.set_focus("body")
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
97
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
98
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
99 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
100
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
101 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
102 '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
103 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
104
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
105 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
106 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
107 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
108 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
109 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
110 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
111
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
112 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
113 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
114
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
115 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
116 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
117 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
118 return True
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
119
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
120 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
121 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
122 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
123 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
124
179
3374ff7e7388 Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 177
diff changeset
125 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
126 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
127 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
128 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
129 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
130 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
131 return True
179
3374ff7e7388 Bind project edit key to the actual ProjectEditKeyState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 177
diff changeset
132
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
133 else:
98
7c3f43bfc0a8 Only accept single keys for project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 97
diff changeset
134 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
135 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
136 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
137 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
138 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
139
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
140 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
141 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
142 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
143 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
144 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
145 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
146
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
147
94
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
148 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
149
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
150 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
151 super(SelectProjectState, self).__init__(controller, view)
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
152 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
153 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
154
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
155 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
156 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
157
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
158 def set_footer_text(self):
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
159 self.view.set_footer_text("Selecting project from key: %s" %
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
160 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
161
155
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
162 def check_key(self, key):
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
163 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
164
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
165 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
166 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
167 if proj:
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
168 self.reset()
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
169 self.view.select_project(proj)
307
b97d18d58f85 We already have the project here therefore pass it directly to the methods
Björn Ricks <bjoern.ricks@intevation.de>
parents: 303
diff changeset
170 self.controller.start_project(proj)
b97d18d58f85 We already have the project here therefore pass it directly to the methods
Björn Ricks <bjoern.ricks@intevation.de>
parents: 303
diff changeset
171 self.controller.update_entries(proj)
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
172 self.set_next_state(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
173 RunningProjectsState(self.controller, self.view,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
174 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
175 return True
95
19e9d76a10fb Fix: Recognize first letter to choose a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 94
diff changeset
176
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
177 def handle_input(self, key):
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
178 keys = self.config.get_keybinding()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
179 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
180 self.reset()
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
181 self.set_next_state(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
182 PausedProjectsState(self.controller, self.view))
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
183 return True
139
6a19e721fbd1 Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 138
diff changeset
184
479
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
185 if 'ctrl l' in key:
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
186 self.controller.redraw()
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
187 return True
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
188
139
6a19e721fbd1 Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 138
diff changeset
189 if 'backspace' in key:
6a19e721fbd1 Allow to use backspace to change selecting project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 138
diff changeset
190 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
191 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
192 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
193 return True
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
194
155
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
195 if keys.get_enter() in key:
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
196 return self.select_project()
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
197
94
159a1ef0fd7c Add new state to select projects with keys larger then one
Björn Ricks <bjoern.ricks@intevation.de>
parents: 93
diff changeset
198 else:
98
7c3f43bfc0a8 Only accept single keys for project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 97
diff changeset
199 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
200 proj_key = self.proj_keys + key[0]
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
201 num = self.check_key(proj_key)
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
202 if num > 0:
155
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
203 self.proj_keys += key[0]
497ed1991e85 Modify project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 152
diff changeset
204 self.set_footer_text()
167
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
205 if num == 1:
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
206 # run project directly
be9acb00cd97 Update project selection
Björn Ricks <bjoern.ricks@intevation.de>
parents: 155
diff changeset
207 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
208 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
209
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
210
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 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
212
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 messages = {
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
214 'quit': _(" Really quit? (y/n)"),
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
215 '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
216 }
9c4e8ba3c4fa 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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
218 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
219 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
220 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
221
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 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
223 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
224 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
225 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
226 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
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 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
229 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
230 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
231
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
232 if 'n' in key or 'N' in key:
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
233 self.controller.view.set_footer_text(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
234 self.msg('choose'), 'question')
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
235 self.set_next_state(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
236 PausedProjectsState(self.controller, self.view))
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
237 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
238
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
239 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
240
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
241
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
242 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
243
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
244 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
245 'description': _("Enter a description: "),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
246 'add_time': _("Enter time to add [min]: "),
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
247 'min_time': _("Enter time to subtract [min]: "),
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
248 'continue': _("Press '%s' to continue."),
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
249 'running': _("Running ( %s ) on '%s'."),
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
250 '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
251 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
252
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
253 sec = 0
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
254 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
255
89
3bea335c0f30 Save the current project when switching to Running state
Björn Ricks <bjoern.ricks@intevation.de>
parents: 88
diff changeset
256 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
257 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
258 self.project = project
309
bff4877c3e58 Deactivate selection of projects when changing to RunningProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 308
diff changeset
259 self.view.deactivate_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
260 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
261 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
262
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
263 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
264 proj = self.project
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
265 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
266
135
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 134
diff changeset
267 if not proj:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 134
diff changeset
268 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
269
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
270 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
271 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
272 (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
273 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
274 'running')
194
cf98dc7f9354 Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents: 179
diff changeset
275 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
276 self.sec = self.sec + 1
501
f5e1a78173cb Old databases can now be read in. Added comments.
Magnus Schieder <mschieder@intevation.de>
parents: 499
diff changeset
277 # The time is stored every minute to be able to restore them in
f5e1a78173cb Old databases can now be read in. Added comments.
Magnus Schieder <mschieder@intevation.de>
parents: 499
diff changeset
278 # case of a crash.
499
199b3e3657aa Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents: 488
diff changeset
279 if self.sec % 60 == 0:
199b3e3657aa Every minute the time of the current entry is saved.
Magnus Schieder <mschieder@intevation.de>
parents: 488
diff changeset
280 self.controller.save_recovery_data()
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
281 else:
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
282 self.view.set_footer_text(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
283 self.msg('paused') %
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
284 (human_time((datetime.now() - self.break_start).seconds),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
285 self.msg(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
286 '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
287 'paused_running')
194
cf98dc7f9354 Move mainloop related code to GetanController
Björn Ricks <bjoern.ricks@intevation.de>
parents: 179
diff changeset
288 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
289
9c4e8ba3c4fa 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 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
291 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
292
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 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
294 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
295 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
296 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
297 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
298 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
299
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
300 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
301 return self.stop()
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
302
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
303 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
304 self.view.set_footer_text(self.msg('add_time'),
384
3d428f8d6ee5 Update calling set_footer_text
Björn Ricks <bjoern.ricks@intevation.de>
parents: 316
diff changeset
305 'question', edit=True)
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
306 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
307 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
308
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
309 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
310 self.view.set_footer_text(self.msg('min_time'),
384
3d428f8d6ee5 Update calling set_footer_text
Björn Ricks <bjoern.ricks@intevation.de>
parents: 316
diff changeset
311 'question', edit=True)
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
312 self.set_next_state(SubtractTimeState(self.controller, self.view,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
313 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
314 return True
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
315
171
a34693c5905f Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 170
diff changeset
316 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
317 if not self.break_start:
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
318 self.break_start = datetime.now()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
319 else:
278
96037ad10cff Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 277
diff changeset
320 self.view.show_total_time()
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
321 proj = self.project
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
322 if proj:
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
323 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
324 self.break_start = None
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
325 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
326 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
327 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
328 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
329
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
330 def 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
331 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
332 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
333 proj = self.project
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
334 if proj:
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
335 proj.start += datetime.now() - self.break_start
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
336 self.controller.view.set_footer_text(self.msg('description'),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
337 'question', edit=True)
309
bff4877c3e58 Deactivate selection of projects when changing to RunningProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 308
diff changeset
338 self.view.enable_selection()
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
339 self.set_next_state(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
340 DescriptionProjectsState(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
341 self.controller, self.view,
308
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
342 self, self.controller.view.get_frame().get_footer(),
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
343 self.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
344 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
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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
347 class HandleUserInputState(State):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
348
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 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
350 super(HandleUserInputState, self).__init__(controller, view)
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
351 self.state = state
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
352 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
353
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
354 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
355 logger.debug("HandleUserInputState: handle key '%r'" % key)
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
356 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
357
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
358 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
359 return self.exit()
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
360 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
361 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
362 return False
39
d4ce02a33acd Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 37
diff changeset
363
d4ce02a33acd Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 37
diff changeset
364 def enter(self):
d4ce02a33acd Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 37
diff changeset
365 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
366
9c4e8ba3c4fa 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 def exit(self):
303
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
368 # restore old focus
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
369 self.state.set_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
370 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
371 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
372
9c4e8ba3c4fa 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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
374 class BaseTimeState(HandleUserInputState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
375
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
376 def __init__(self, controller, view, running_state):
44
f10126519797 Fixed super call
Sascha L. Teichmann <teichmann@intevation.de>
parents: 43
diff changeset
377 super(BaseTimeState, self).__init__(controller, view, running_state,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
378 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
379 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
380
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
381 def exit(self):
278
96037ad10cff Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 277
diff changeset
382 self.view.show_total_time()
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
383 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
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 def insert(self, key):
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
386 if key[0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
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 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
388 else:
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
389 logger.debug("BaseTimeState: invalid character for "
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
390 "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
391 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
392
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
393 def set_focus(self):
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
394 self.controller.view.set_focus("projects")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
395 self.view.frame.set_focus("footer")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
396
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
397
9c4e8ba3c4fa 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 class AddTimeState(BaseTimeState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
399
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
400 def enter(self):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
401 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
402 project = self.project
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
403 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
404 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
405 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
406 % (minutes, project.desc))
278
96037ad10cff Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 277
diff changeset
407 self.view.show_total_time()
303
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
408 # set focus to the original element
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
409 self.state.set_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
410 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
411 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
412
9c4e8ba3c4fa 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
9c4e8ba3c4fa 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 class SubtractTimeState(BaseTimeState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
415
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
416 def enter(self):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
417 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
418 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
419 if sec > self.state.sec:
278
96037ad10cff Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 277
diff changeset
420 self.view.show_total_time()
303
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
421 # set focus to the original element
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
422 self.state.set_focus()
294
fdd086acdf9b Set correct next state if to be subtracted seconds are greater then the actual
Björn Ricks <bjoern.ricks@intevation.de>
parents: 286
diff changeset
423 self.set_next_state(self.state)
fdd086acdf9b Set correct next state if to be subtracted seconds are greater then the actual
Björn Ricks <bjoern.ricks@intevation.de>
parents: 286
diff changeset
424 return False
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
425 project = self.project
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
426 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
427 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
428 logger.info("SubtractTimeState: subtract %d minutes from project '%s'"
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
429 % (minutes, project.desc))
278
96037ad10cff Fix showing the total time in the project list footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 277
diff changeset
430 self.view.show_total_time()
303
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
431 # set focus to the original element
c75eed90ae01 Set focus to project list body when changing from adding and subtracting time
Björn Ricks <bjoern.ricks@intevation.de>
parents: 296
diff changeset
432 self.state.set_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
433 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
434 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
435
9c4e8ba3c4fa 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
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
437 class DescriptionProjectsState(HandleUserInputState):
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
438
279
2cef4ba1207a Add docstring to DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 278
diff changeset
439 """ Adds a description to a stopped running project """
2cef4ba1207a Add docstring to DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 278
diff changeset
440
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
441 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
442 '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
443 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
444
308
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
445 def __init__(self, controller, view, state, footer, project):
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
446 super(DescriptionProjectsState, self).__init__(controller, view, state,
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
447 footer)
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
448 self.project = project
528
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
449 self.history_position = - 1
308
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
450
530
93e740bc730f Clean up the source code
Magnus Schieder <mschieder@intevation.de>
parents: 528
diff changeset
451
246
2b2738c8c130 Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 243
diff changeset
452 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
453 """ Direct key to frame of GetanView """
528
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
454
246
2b2738c8c130 Redirect key event to GetanView Frame in DescriptionProjectsState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 243
diff changeset
455 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
456
530
93e740bc730f Clean up the source code
Magnus Schieder <mschieder@intevation.de>
parents: 528
diff changeset
457 entries = self.project.entries
528
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
458 if key == 'up':
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
459 if self.history_position < len(entries) - 1:
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
460 self.history_position = self.history_position + 1
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
461 self.controller.view.frame.footer.set_edit_text(
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
462 entries[self.history_position].desc)
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
463 self.controller.view.frame.footer.set_edit_pos(
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
464 len(entries[self.history_position].desc))
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
465
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
466 if key == 'down':
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
467 if self.history_position >= 0:
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
468 self.history_position = self.history_position - 1
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
469 if self.history_position == -1:
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
470 self.controller.view.frame.footer.set_edit_text("")
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
471 self.controller.view.frame.footer.set_edit_pos(0)
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
472 else:
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
473 self.controller.view.frame.footer.set_edit_text(
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
474 entries[self.history_position].desc)
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
475 self.controller.view.frame.footer.set_edit_pos(
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
476 len(entries[self.history_position].desc))
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
477
210bd796829e Updates the description of an entry
Magnus Schieder <mschieder@intevation.de>
parents: 501
diff changeset
478
23
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
479 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
480 text = self.footer.get_edit_text()
30
fea63a224065 Stop still running projects before getan quits - even if getan crashes.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 27
diff changeset
481 self.controller.stop_project(text)
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
482 self.controller.view.set_footer_text(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
483 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
484 self.set_next_state(PausedProjectsState(self.controller, self.view))
286
96843aedcf5e Update rows when stopping a running project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 282
diff changeset
485 self.view.update_rows()
280
44a5fe190ab6 Show total when a entry is changed
Björn Ricks <bjoern.ricks@intevation.de>
parents: 279
diff changeset
486 self.view.show_total_time()
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
487 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
488
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
489 def exit(self):
308
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
490 if self.project:
a7ece2df59a2 Also don't use item_in_focus when adding a entry description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 307
diff changeset
491 time = (datetime.now() - self.project.start).seconds
43
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
492 self.state.sec = time
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
493 signal.signal(signal.SIGALRM, self.state.handle_signal)
39d845d3fec4 Fix for #1638
Sascha L. Teichmann <teichmann@intevation.de>
parents: 42
diff changeset
494 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
495 return super(DescriptionProjectsState, self).exit()
106
a0779fb2ef4d Remove space
Björn Ricks <bjoern.ricks@intevation.de>
parents: 105
diff changeset
496
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
497 def set_focus(self):
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
498 self.controller.view.set_focus("footer")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
499
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
500
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
501 class EntryListState(State):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
502
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
503 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
504 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
505 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
506
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
507 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
508 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
509 keys = self.config.get_keybinding()
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
510
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
511 if keys.get_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
512 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
513 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
514 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
515 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
516
479
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
517 if 'ctrl l' in key:
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
518 self.controller.redraw()
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
519 return True
75131561d098 Add a redraw function on key Control-L.
Magnus Schieder <mschieder@intevation.de>
parents: 478
diff changeset
520
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
521 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
522 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
523 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
524
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
525 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
526 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
527 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
528
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
529 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
530 e_len = self.view.row_count()
468
74e550aa3b6a Fixes focus error.
Magnus Schieder <mschieder@intevation.de>
parents: 447
diff changeset
531 if e_len == 0:
473
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
532 return False
235
263fe6ee0e4e Fix crash when deleting an entry
Björn Ricks <bjoern.ricks@intevation.de>
parents: 232
diff changeset
533 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
534 if f >= e_len:
ce707fbb9666 Change coding style of if clauses
Björn Ricks <bjoern.ricks@intevation.de>
parents: 134
diff changeset
535 f = e_len - 1
207
910136052631 Fix setting the focus
Björn Ricks <bjoern.ricks@intevation.de>
parents: 206
diff changeset
536 self.view.set_focus(f)
473
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
537 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
538
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
539 def set_focus(self):
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
540 self.controller.view.set_focus("entries")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
541 self.controller.entries_view.set_focus(0)
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
542
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
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 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
545
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
546 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
547 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
548 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
549 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
550 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
551
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
552 keys = self.config.get_keybinding()
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
553 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
554 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
555 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
556 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
557 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
558
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
559 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
560 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
561 self.set_next_state(DeleteEntryState(self.projectlist_state,
312
dc92981ec591 Avoid resetting the focus when changing from DeleteEntryState back to the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 310
diff changeset
562 self,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
563 self.controller,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
564 self.view))
102
cd2456d0589e Add single entry deletion
Björn Ricks <bjoern.ricks@intevation.de>
parents: 101
diff changeset
565 else:
cd2456d0589e Add single entry deletion
Björn Ricks <bjoern.ricks@intevation.de>
parents: 101
diff changeset
566 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
567 self.set_next_state(DeleteEntryState(self.projectlist_state,
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
568 self, self.controller,
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
569 self.view, [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
570 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
571
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
572 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
573 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
574 self.set_next_state(MoveEntryState(self.projectlist_state,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
575 self.controller, self.view))
439
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
576 else:
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
577 entry = self.view.item_in_focus()
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
578 self.set_next_state(MoveEntryState(self.projectlist_state,
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
579 self.controller,
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
580 self.view, [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
581 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
582
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
583 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
584 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
585 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
586 self.set_next_state(EditEntryState(self.projectlist_state,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
587 self.controller, self.view,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
588 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
589 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
590
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
591 if keys.get_entry_adjust() in key:
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
592 entry = self.view.item_in_focus()
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
593 if entry:
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
594 self.set_next_state(AdjustEntryState(self.projectlist_state,
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
595 self.controller,
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
596 self.view, entry))
405
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
597 return True
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
598
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
599 if keys.get_entry_length() in key:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
600 entry = self.view.item_in_focus()
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
601 if entry:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
602 self.set_next_state(LengthEntryState(self.projectlist_state,
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
603 self.controller,
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
604 self.view, entry))
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
605 return True
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
606
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
607 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
608
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
609
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
610 class DeleteEntryState(EntryListState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
611
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
612 messages = {
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
613 '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
614 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
615
312
dc92981ec591 Avoid resetting the focus when changing from DeleteEntryState back to the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 310
diff changeset
616 def __init__(self, state, old_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
617 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
618 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
619 self.entries = entries
312
dc92981ec591 Avoid resetting the focus when changing from DeleteEntryState back to the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 310
diff changeset
620 self.old_state = old_state
100
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
621 if not self.entries:
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
622 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
623
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
624 def handle_input(self, key):
310
2667bdef021f Allow to abort deletion of entries with escape key
Björn Ricks <bjoern.ricks@intevation.de>
parents: 309
diff changeset
625 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
626 if 'y' in key:
100
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
627 if self.entries:
8f433e3c2f21 Allow to pass entries to the DeleteEntryState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 98
diff changeset
628 self.controller.delete_entries(self.entries)
473
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
629 new_focus = self.renew_focus()
470
d379f8098bb3 Update project time when deleting an entrie.
Magnus Schieder <mschieder@intevation.de>
parents: 469
diff changeset
630 self.projectlist_state.view.update_rows()
474
0d831a9f547b Better multi-selection bugfix. Solves mistakes from the old fix. (ca6d11781e2f)
Magnus Schieder <mschieder@intevation.de>
parents: 473
diff changeset
631 self.view.clear()
25
155b23da504b Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 23
diff changeset
632 self.view.set_footer_text("", 'entry_footer')
312
dc92981ec591 Avoid resetting the focus when changing from DeleteEntryState back to the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 310
diff changeset
633 # avoid creating new DefaultEntryListState and setting focus
473
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
634 if new_focus:
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
635 self.set_next_state(self.old_state)
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
636 else:
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
637 self.set_next_state(self.projectlist_state)
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
638 self.controller.view.set_focus(0)
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
639
280
44a5fe190ab6 Show total when a entry is changed
Björn Ricks <bjoern.ricks@intevation.de>
parents: 279
diff changeset
640 self.controller.project_view.show_total_time()
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
641 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
642
310
2667bdef021f Allow to abort deletion of entries with escape key
Björn Ricks <bjoern.ricks@intevation.de>
parents: 309
diff changeset
643 if 'n' in key or 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
644 self.view.set_footer_text("", 'entry_footer')
312
dc92981ec591 Avoid resetting the focus when changing from DeleteEntryState back to the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 310
diff changeset
645 # avoid creating new DefaultEntryListState and setting focus
dc92981ec591 Avoid resetting the focus when changing from DeleteEntryState back to the
Björn Ricks <bjoern.ricks@intevation.de>
parents: 310
diff changeset
646 self.set_next_state(self.old_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
647 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
648
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
649 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
650
313
eb05d803249e Avoid resetting the focus in the entry list if the DeletEntryListState is
Björn Ricks <bjoern.ricks@intevation.de>
parents: 312
diff changeset
651 def set_focus(self):
eb05d803249e Avoid resetting the focus in the entry list if the DeletEntryListState is
Björn Ricks <bjoern.ricks@intevation.de>
parents: 312
diff changeset
652 self.controller.view.set_focus("entries")
eb05d803249e Avoid resetting the focus in the entry list if the DeletEntryListState is
Björn Ricks <bjoern.ricks@intevation.de>
parents: 312
diff changeset
653
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
654
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
655 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
656 messages = {
36
e6f81aa329b1 Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 30
diff changeset
657 '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
658 '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
659 }
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
660
9c4e8ba3c4fa Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff changeset
661 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
662
439
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
663 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
664 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
665 self.view.set_footer_text(self.msg('project'), 'question')
439
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
666 self.entries = entries
104
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
667 self.proj_keys = ""
133
78992300f421 Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 130
diff changeset
668 self.project_view = controller.project_view
439
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
669 if not self.entries:
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
670 self.entries = [x.item for x in self.view.selection]
104
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
671
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
672 def set_project_footer(self):
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
673 self.project_view.set_footer_text("Selecting project from "
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
674 "key: %s" % self.proj_keys,
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
675 "running")
104
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
676
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
677 def reset_project_footer(self):
133
78992300f421 Reset the ProjectList footer
Björn Ricks <bjoern.ricks@intevation.de>
parents: 130
diff changeset
678 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
679
169
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
680 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
681 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
682
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
683 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
684 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
685 if proj:
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
686 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
687 self.reset_project_footer()
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
688 logger.debug("MoveEntryState: prepared entries to be "
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
689 "moved to project '%s'" % self.proj.desc)
169
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
690 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
691
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
692 def handle_input(self, key):
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
693 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
694 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
695 logger.debug("MoveEntryState: move selected entries.")
439
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
696 self.controller.move_entries(self.entries, self.proj)
473
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
697 new_focus = self.renew_focus()
474
0d831a9f547b Better multi-selection bugfix. Solves mistakes from the old fix. (ca6d11781e2f)
Magnus Schieder <mschieder@intevation.de>
parents: 473
diff changeset
698 self.view.clear()
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
699 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
700 self.proj = None
473
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
701 if new_focus:
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
702 self.set_next_state(DefaultEntryListState(self.projectlist_state,
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
703 self.controller,
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
704 self.view))
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
705 else:
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
706 self.set_next_state(self.projectlist_state)
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
707 self.controller.view.set_focus(0)
b9e30e556844 Switch to projects when entries are empty.
Magnus Schieder <mschieder@intevation.de>
parents: 472
diff changeset
708
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
709 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
710
25
155b23da504b Bugfix and improvements in the process to move/delete entries.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents: 23
diff changeset
711 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
712 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
713 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
714 self.set_next_state(DefaultEntryListState(self.projectlist_state,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
715 self.controller,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
716 self.view))
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
717 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
718
151
1e35c24708dd Allow to configure the action keys
Björn Ricks <bjoern.ricks@intevation.de>
parents: 150
diff changeset
719 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
720 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
721 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
722 self.set_next_state(DefaultEntryListState(self.projectlist_state,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
723 self.controller,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
724 self.view))
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
725 return True
243
9bf0ad952c68 Add newline
Björn Ricks <bjoern.ricks@intevation.de>
parents: 236
diff changeset
726
134
c80c7fc6a8fc Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 133
diff changeset
727 if 'backspace' in key:
c80c7fc6a8fc Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 133
diff changeset
728 if len(self.proj_keys) > 0:
c80c7fc6a8fc Handle backspace when selecting a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 133
diff changeset
729 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
730 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
731 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
732
169
d10a0e35b982 Fix: Allow to move entries to projects with similar names
Björn Ricks <bjoern.ricks@intevation.de>
parents: 167
diff changeset
733 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
734 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
735 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
736
104
36204a42bd79 Allow to select projects with keys > 1 letters while moving entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 103
diff changeset
737 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
738 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
739 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
740 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
741 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
742 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
743 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
744 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
745 return True
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
746
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
747 return False
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
748
439
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
749 def set_focus(self):
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
750 self.controller.view.set_focus("entries")
3103429ec963 Makes 'move' operation more consistent.
Bernhard Reiter <bernhard@intevation.de>
parents: 411
diff changeset
751
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
752
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
753 class AlterProjectState(HandleUserInputState):
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
754
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
755 messages = {
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
756 'choose_proj': _(' Choose a project.'),
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
757 }
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
758
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
759 def __init__(self, controller, view):
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
760 super(AlterProjectState, self).__init__(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
761 controller, view, None,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
762 controller.view.get_frame().get_footer())
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
763
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
764 def exit(self):
268
06157568d287 Use kwarg for edit and boolean instead of int
Björn Ricks <bjoern.ricks@intevation.de>
parents: 267
diff changeset
765 self.controller.view.set_footer_text(self.msg('choose_proj'),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
766 '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
767 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
768 return True
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
769
267
9fce005e5fc6 Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 262
diff changeset
770 def keypress(self, size, key):
9fce005e5fc6 Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 262
diff changeset
771 """ Direct key to frame of GetanView """
9fce005e5fc6 Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 262
diff changeset
772 self.controller.view.frame.keypress(size, key)
9fce005e5fc6 Redirect keyinput to GetanView footer when adding a new project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 262
diff changeset
773
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
774 def set_focus(self):
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
775 self.controller.view.set_focus("footer")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
776
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
777
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
778 class AddProjectKeyState(AlterProjectState):
172
b8abca7714fd Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 171
diff changeset
779
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
780 messages = {
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
781 'choose_proj': _(' Choose a project.'),
172
b8abca7714fd Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 171
diff changeset
782 '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
783 }
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
784
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
785 def __init__(self, controller, view):
268
06157568d287 Use kwarg for edit and boolean instead of int
Björn Ricks <bjoern.ricks@intevation.de>
parents: 267
diff changeset
786 controller.view.set_footer_text(self.msg('proj_key'), 'question',
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
787 edit=True)
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
788 super(AddProjectKeyState, self).__init__(controller, view)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
789
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
790 def enter(self):
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
791 key = self.footer.get_edit_text()
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
792 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
793 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
794 self.set_next_state(AddProjectDescriptionState(self.controller,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
795 self.view, 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
796 return True
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
797
170
fa3f6cd394db Formatting
Björn Ricks <bjoern.ricks@intevation.de>
parents: 169
diff changeset
798
173
a5319bb1ac13 Rename CreateProjectState into AlterProjectState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 172
diff changeset
799 class AddProjectDescriptionState(AlterProjectState):
206
9f1c45a2126e Update coding style for states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 205
diff changeset
800
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
801 messages = {
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
802 'proj_description': _('Insert a description for project: '),
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
803 'choose_proj': _(" Choose a project.")
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
804 }
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
805
172
b8abca7714fd Drop AddProjectNameState
Björn Ricks <bjoern.ricks@intevation.de>
parents: 171
diff changeset
806 def __init__(self, controller, view, key):
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
807 controller.view.set_footer_text(self.msg('proj_description'),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
808 'question', edit=True)
54
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
809 super(AddProjectDescriptionState, self).__init__(controller, view)
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
810 self.key = key
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
811
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
812 def enter(self):
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
813 description = self.footer.get_edit_text()
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
814 if description == '':
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
815 return self
d747563dff03 add create project related states
Björn Ricks <bjoern.ricks@intevation.de>
parents: 44
diff changeset
816 self.controller.add_project(self.key, description)
271
60725e0bcddb Use exit when returning from adding a project
Björn Ricks <bjoern.ricks@intevation.de>
parents: 270
diff changeset
817 self.exit()
205
a1b00ffea269 Use handle_input instead of keypress to act on user input in States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 197
diff changeset
818 return True
73
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
819
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
820
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
821 class EditEntryState(HandleUserInputState):
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
822 messages = {
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
823 'edit_entry': _('Edit entry text: '),
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
824 }
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
825
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
826 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
827 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
828 'question', True)
73
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
829 super(EditEntryState, self).__init__(controller, view,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
830 None, view.footer)
73
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
831 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
832 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
833 self.entry = entry
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
834 self.state = state
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
835 logger.debug("EditEntryState: Entry %s" % entry)
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
836
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
837 def enter(self):
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
838 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
839 if entry_desc == '':
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
840 return self
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
841 entry = self.entry
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
842 entry.desc = entry_desc
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
843 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
844 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
845 return self.exit()
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
846
745c644d9564 Add new state for editing entries
Björn Ricks <bjoern.ricks@intevation.de>
parents: 72
diff changeset
847 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
848 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
849 self.set_next_state(DefaultEntryListState(self.state, self.controller,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
850 self.view))
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
851 return True
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
852
277
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
853 def set_focus(self):
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
854 self.controller.view.set_focus("entries")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
855 self.view.frame.set_focus("footer")
3d6315be2251 Use new set_focus method in all States
Björn Ricks <bjoern.ricks@intevation.de>
parents: 276
diff changeset
856
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
857
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
858 class AdjustEntryState(HandleUserInputState):
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
859 messages = {
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
860 'adjust_entry': _('Adjust datetime of entry: '),
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
861 }
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
862
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
863 def __init__(self, state, controller, view, entry):
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
864 view.set_footer_text(self.msg('adjust_entry'),
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
865 'question', True)
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
866 super(AdjustEntryState, self).__init__(controller, view,
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
867 None, view.footer)
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
868
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
869 # we only care up to seconds (which is 19 characters).
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
870 # for usability the default value has to match the strptime fmt below.
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
871 self.footer.set_edit_text(str(entry.start)[:19])
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
872 self.footer.set_edit_pos(len(self.footer.edit_text))
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
873 self.entry = entry
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
874 self.state = state
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
875 logger.debug("AdjustEntryState: Entry %s" % entry)
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
876
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
877 def enter(self):
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
878 entry_datetime = self.footer.get_edit_text()
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
879
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
880 entry = self.entry
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
881 duration = entry.get_duration()
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
882
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
883 try:
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
884 entry.start = datetime.strptime(entry_datetime,
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
885 "%Y-%m-%d %H:%M:%S")
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
886 except:
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
887 return self
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
888
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
889 entry.end = entry.start + duration
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
890
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
891 self.controller.update_entry(entry)
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
892 self.view.node_in_focus().update()
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
893 return self.exit()
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
894
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
895 def exit(self):
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
896 self.view.set_footer_text("", 'entry_footer', False)
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
897 self.set_next_state(DefaultEntryListState(self.state, self.controller,
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
898 self.view))
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
899 return True
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
900
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
901 def set_focus(self):
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
902 self.controller.view.set_focus("entries")
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
903 self.view.frame.set_focus("footer")
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
904
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
905
405
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
906 class LengthEntryState(HandleUserInputState):
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
907 messages = {
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
908 'adjust_length_entry': _('Adjust length of entry: '),
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
909 }
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
910
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
911 def __init__(self, state, controller, view, entry):
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
912 view.set_footer_text(self.msg('adjust_length_entry'),
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
913 'question', True)
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
914 super(LengthEntryState, self).__init__(controller, view,
410
7e27d2145007 Code-cleanup: improves style.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
915 None, view.footer)
405
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
916
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
917 # format current duration as string that is also accepted by enter()
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
918 total_minutes = int(entry.get_duration().total_seconds()/60)
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
919 hours = int(total_minutes // 60)
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
920
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
921 if hours > 0:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
922 self.footer.set_edit_text(
409
ac4dead31672 Improves editing of length for saved entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 407
diff changeset
923 "{:d}:{:02d}".format(hours, int(total_minutes % 60)))
405
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
924 else:
407
ee98d0b45967 Fixes ability to change length of saved entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 406
diff changeset
925 self.footer.set_edit_text("{:d}".format(total_minutes))
405
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
926
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
927 self.footer.set_edit_pos(len(self.footer.edit_text))
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
928 self.entry = entry
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
929 self.state = state
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
930 logger.debug("LengthEntryState: Entry %s" % entry)
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
931
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
932 def enter(self):
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
933 """Changed the length of an entry.
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
934
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
935 Works for total minutes or HH:MM.
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
936 """
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
937 entry_duration = self.footer.get_edit_text()
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
938
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
939 # avoid unexpected behavior if minus signs are given in the new length
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
940 if '-' in entry_duration:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
941 return self
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
942
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
943 if ':' in entry_duration:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
944 hours, minutes = entry_duration.split(':')
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
945 else:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
946 hours = 0
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
947 minutes = entry_duration
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
948
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
949 try:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
950 duration = timedelta(minutes=int(minutes), hours=int(hours))
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
951 except:
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
952 return self
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
953
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
954 entry = self.entry
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
955 entry.end = entry.start + duration
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
956
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
957 self.controller.update_entry(entry)
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
958 self.view.node_in_focus().update()
476
63ce8e017828 Updates the project time when the entrie time is adjusted.
Magnus Schieder <mschieder@intevation.de>
parents: 474
diff changeset
959 self.controller.view.proj_list.update_rows()
478
950bfe89ec3d Updates "All project" time when the entrie time is adjusted.
Magnus Schieder <mschieder@intevation.de>
parents: 476
diff changeset
960 self.controller.project_view.show_total_time()
405
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
961 return self.exit()
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
962
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
963 def exit(self):
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
964 self.view.set_footer_text("", 'entry_footer', False)
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
965 self.set_next_state(DefaultEntryListState(self.state, self.controller,
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
966 self.view))
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
967 return True
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
968
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
969 def set_focus(self):
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
970 self.controller.view.set_focus("entries")
150180e972d3 Adds ability to adjust the length of (saved) entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 400
diff changeset
971 self.view.frame.set_focus("footer")
400
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
972
527168c08ae4 Added possibility to move starting datetime of entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 385
diff changeset
973
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
974 class ProjectEditKeyState(AlterProjectState):
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
975
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
976 messages = {
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
977 '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
978 '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
979 '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
980 }
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
981
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
982 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
983 controller.view.set_footer_text(self.msg('proj_key'),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
984 'question', 1)
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
985 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
986 self.project = project
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
987 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
988 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
989
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
990 def enter(self):
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
991 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
992 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
993 return True
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
994 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
995 self.set_next_state(ProjectEditDescriptionState(self.controller,
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
996 self.view,
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
997 self.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
998 return True
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
999
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1000
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1001 class ProjectEditDescriptionState(AlterProjectState):
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1002
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1003 messages = {
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
1004 "proj_description": _("Insert description for project: "),
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
1005 "choose_proj": _(" Choose a project.")
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1006 }
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1007
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1008 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
1009 controller.view.set_footer_text(self.msg("proj_description"),
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
1010 "question", 1)
177
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1011 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
1012 self.project = project
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1013 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
1014 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
1015
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1016 def enter(self):
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1017 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
1018 if description == '':
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1019 return self
c37fb8223762 Add new States to edit project key and description
Björn Ricks <bjoern.ricks@intevation.de>
parents: 173
diff changeset
1020 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
1021 self.controller.update_project(self.project)
296
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
1022 self.controller.view.set_footer_text(
c7a867c16ff2 Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents: 294
diff changeset
1023 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
1024 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
1025 return True
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)