Mercurial > getan
changeset 151:1e35c24708dd
Allow to configure the action keys
Use new config and keybinding classes to allow to configure the action keys in
the states. This change decouples the actual action keys from the state
transtitions.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 06 Dec 2012 12:30:27 +0100 (2012-12-06) |
parents | 7ab5b887a7c5 |
children | 7ffcd2ea92e3 |
files | getan/states.py |
diffstat | 1 files changed, 46 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/getan/states.py Thu Dec 06 12:28:31 2012 +0100 +++ b/getan/states.py Thu Dec 06 12:30:27 2012 +0100 @@ -26,6 +26,7 @@ def __init__(self, controller, view): self.controller = controller self.view = view + self.config = controller.get_config() def msg(self, key): return self.messages[key] @@ -33,16 +34,17 @@ class ProjectState(State): def keypress(self, key): + keys = self.config.get_keybinding() logger.debug("ProjectState: handle key '%r'" % key) - if 'f1' in key: + if keys.get_switch_time_mode() in key: self.view.switch_time_mode() return self - if 'f2' in key: + if keys.get_switch_project_order() in key: self.view.switch_project_order() return self - if 'tab' in key: + if keys.get_switch_lists() in key: if not self.controller.entries_view.rows: return self self.controller.entries_view.focused = 0 @@ -50,10 +52,10 @@ return DefaultEntryListState(self, self.controller, self.controller.entries_view) - if 'up' in key: + if keys.get_entry_up() in key: return self.up() - if 'down' in key: + if keys.get_entry_down() in key: return self.down() def up(self): @@ -73,17 +75,18 @@ def keypress(self, key): logger.debug("PausedProjectsState: handle key '%r'" % key) + keys = self.config.get_keybinding() ret = super(PausedProjectsState, self).keypress(key) if ret: return ret - if 'enter' in key: + if keys.get_enter() in key: return self.select() - if 'insert' in key: + if keys.get_insert() in key: return AddProjectNameState(self.controller, self.view) - if 'esc' in key: + if keys.get_escape() in key: return ExitState(self.controller, self.view) else: @@ -123,7 +126,8 @@ return self def keypress(self, key): - if 'esc' in key: + keys = self.config.get_keybinding() + if keys.get_escape() in key: self.reset() return PausedProjectsState(self.controller, self.view) @@ -187,6 +191,7 @@ def handle_signal(self, signum, frame): proj = self.project + keys = self.config.get_keybinding() if not proj: return if not self.break_start: @@ -209,33 +214,36 @@ def keypress(self, key): logger.debug("RunningProjectsState: handle key '%r'" % key) + keys = self.config.get_keybinding() ret = super(RunningProjectsState, self).keypress(key) if ret: return ret - if 'enter' in key: + if keys.get_enter() in key: return self.stop() - if '+' in key: + if keys.get_add_time() in key: self.view.set_footer_text(self.msg('add_time'), 'question', 1) self.view.frame.set_focus('footer') return AddTimeState(self.controller, self.view, self) - if '-' in key: + if keys.get_subtract_time() in key: self.view.set_footer_text(self.msg('min_time'), 'question', 1) self.view.frame.set_focus('footer') return SubtractTimeState(self.controller, self.view, self) - if ' ' in key and not self.break_start: - self.break_start = datetime.now() - return self - if ' ' in key and self.break_start: - self.view._total_time() - proj = self.project - if proj: - proj.start += datetime.now() - self.break_start - self.break_start = None - signal.signal(signal.SIGALRM, self.handle_signal) - signal.alarm(1) + + if keys.get_pause_project() in key: + if not self.break_start: + self.break_start = datetime.now() + return self + else: + self.view._total_time() + proj = self.project + if proj: + proj.start += datetime.now() - self.break_start + self.break_start = None + signal.signal(signal.SIGALRM, self.handle_signal) + signal.alarm(1) return self def stop(self): @@ -260,10 +268,11 @@ def keypress(self, key): logger.debug("HandleUserInputState: handle key '%r'" % key) pos = self.footer.edit_pos + keys = self.config.get_keybinding() - if 'esc' in key: + if keys.get_escape() in key: return self.exit() - elif 'enter' in key: + elif keys.get_enter() in key: return self.enter() elif 'left' in key: self.footer.set_edit_pos(pos-1) @@ -378,14 +387,15 @@ def keypress(self, key): logger.debug("EntryListState: pressed key '%r'" % key) - if 'tab' in key: + keys = self.config.get_keybinding() + if keys.get_switch_lists() in key: self.view.clear() return self.projectlist_state - if 'up' in key: + if keys.get_entry_up() in key: return self.up() - if 'down' in key: + if keys.get_entry_down() in key: return self.down() - if 'enter' in key: + if keys.get_enter() in key: return self.select() return None @@ -416,11 +426,12 @@ if ret: return ret - if 'esc' in key: + keys = self.config.get_keybinding() + if keys.get_escape() in key: self.view.clear() return self.projectlist_state - if 'd' in key: + if keys.get_entry_delete() in key: if self.view.selection: return DeleteEntryState(self.projectlist_state, self.controller, self.view) @@ -428,11 +439,11 @@ entry = self.view.item_in_focus() return DeleteEntryState(self.projectlist_state, self.controller, self.view, [entry]) - if 'm' in key: + if keys.get_entry_move() in key: if self.view.selection: return MoveEntryState(self.projectlist_state, self.controller, self.view) - if 'e' in key: + if keys.get_entry_edit() in key: entry = self.view.item_in_focus() if entry: return EditEntryState(self.projectlist_state, @@ -491,6 +502,7 @@ self.project_view.reset_footer() def keypress(self, key): + keys = self.config.get_keybinding() if 'y' in key and self.proj: logger.debug("MoveEntryState: move selected entries.") self.controller.move_selected_entries(self.proj) @@ -506,7 +518,7 @@ return DefaultEntryListState(self.projectlist_state, self.controller, self.view) - if 'esc' in key: + if keys.get_escape() in key: self.view.set_footer_text('', 'entry_footer') self.reset_project_footer() return DefaultEntryListState(self.projectlist_state,