changeset 296:c7a867c16ff2

Update codingstyle for pep8
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 11 Oct 2013 09:22:01 +0200
parents abfa55c7c2b2
children b9f4cd43f341
files getan/states.py
diffstat 1 files changed, 83 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/getan/states.py	Wed Aug 28 10:44:34 2013 +0200
+++ b/getan/states.py	Fri Oct 11 09:22:01 2013 +0200
@@ -19,7 +19,9 @@
 
 logger = logging.getLogger()
 
+
 class State(object):
+
     """ Represents a State of Getan
 
     A State can be used to handle user input. The user input handling is done in
@@ -86,7 +88,7 @@
             if not self.controller.entries_view.rows:
                 return True
             new_state = DefaultEntryListState(self, self.controller,
-                    self.controller.entries_view)
+                                              self.controller.entries_view)
             self.set_next_state(new_state)
             return True
 
@@ -154,8 +156,8 @@
         self.view.reset_footer()
 
     def set_footer_text(self):
-        self.view.set_footer_text("Selecting project from key: %s" % \
-                self.proj_keys, "running")
+        self.view.set_footer_text("Selecting project from key: %s" %
+                                  self.proj_keys, "running")
 
     def check_key(self, key):
         return len(self.controller.find_projects_by_key(key))
@@ -167,16 +169,18 @@
             self.view.select_project(proj)
             self.controller.start_project(self.view.item_in_focus())
             self.controller.update_entries(
-                    self.view.item_in_focus())
-            self.set_next_state(RunningProjectsState(self.controller, self.view,
-                proj))
+                self.view.item_in_focus())
+            self.set_next_state(
+                RunningProjectsState(self.controller, self.view,
+                                     proj))
         return True
 
     def handle_input(self, key):
         keys = self.config.get_keybinding()
         if keys.get_escape() in key:
             self.reset()
-            self.set_next_state(PausedProjectsState(self.controller, self.view))
+            self.set_next_state(
+                PausedProjectsState(self.controller, self.view))
             return True
 
         if 'backspace' in key:
@@ -204,7 +208,7 @@
 class ExitState(ProjectState):
 
     messages = {
-        'quit'  : _(" Really quit? (y/n)"),
+        'quit': _(" Really quit? (y/n)"),
         'choose': _(" Choose a project:")
     }
 
@@ -223,8 +227,10 @@
             return True
 
         if 'n' in key or 'N' in key:
-            self.controller.view.set_footer_text(self.msg('choose'), 'question')
-            self.set_next_state(PausedProjectsState(self.controller, self.view))
+            self.controller.view.set_footer_text(
+                self.msg('choose'), 'question')
+            self.set_next_state(
+                PausedProjectsState(self.controller, self.view))
             return True
 
         return False
@@ -234,14 +240,14 @@
 
     messages = {
         'description': _("Enter a description: "),
-        'add_time'   : _("Enter time to add [min]: "),
-        'min_time'   : _("Enter time to subtract [min]: "),
-        'continue'   : _("Press '%s' to continue."),
-        'running'    : _("Running ( %s ) on '%s'."),
-        'paused'     : _(" Break   ( %s ) %s."),
+        'add_time': _("Enter time to add [min]: "),
+        'min_time': _("Enter time to subtract [min]: "),
+        'continue': _("Press '%s' to continue."),
+        'running': _("Running ( %s ) on '%s'."),
+        'paused': _(" Break   ( %s ) %s."),
     }
 
-    sec         = 0
+    sec = 0
     break_start = None
 
     def __init__(self, controller, view, project):
@@ -265,9 +271,11 @@
             self.controller.loop.draw_screen()
             self.sec = self.sec + 1
         else:
-            self.view.set_footer_text(self.msg('paused') %
+            self.view.set_footer_text(
+                self.msg('paused') %
                 (human_time((datetime.now() - self.break_start).seconds),
-                 self.msg('continue') % keys.get_project_pause()),
+                 self.msg(
+                     'continue') % keys.get_project_pause()),
                 'paused_running')
             self.controller.loop.draw_screen()
 
@@ -286,15 +294,15 @@
 
         if keys.get_add_time() in key:
             self.view.set_footer_text(self.msg('add_time'),
-                                               'question', 1)
+                                      'question', 1)
             self.set_next_state(AddTimeState(self.controller, self.view, self))
             return True
 
         if keys.get_subtract_time() in key:
             self.view.set_footer_text(self.msg('min_time'),
-                                                 'question', 1)
+                                      'question', 1)
             self.set_next_state(SubtractTimeState(self.controller, self.view,
-                self))
+                                                  self))
             return True
 
         if keys.get_project_pause() in key:
@@ -319,9 +327,11 @@
             if proj:
                 proj.start += datetime.now() - self.break_start
         self.controller.view.set_footer_text(self.msg('description'),
-                'question', edit=True)
-        self.set_next_state(DescriptionProjectsState(self.controller, self.view,
-            self, self.controller.view.get_frame().get_footer()))
+                                             'question', edit=True)
+        self.set_next_state(
+            DescriptionProjectsState(
+                self.controller, self.view,
+                self, self.controller.view.get_frame().get_footer()))
         return True
 
 
@@ -354,7 +364,7 @@
 
     def __init__(self, controller, view, running_state):
         super(BaseTimeState, self).__init__(controller, view, running_state,
-                                           view.frame.get_footer())
+                                            view.frame.get_footer())
         self.project = running_state.project
 
     def exit(self):
@@ -362,10 +372,10 @@
         return super(BaseTimeState, self).exit()
 
     def insert(self, key):
-        if key[0] in ['0','1','2','3','4','5','6','7','8','9']:
+        if key[0] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
             self.footer.insert_text(key[0])
         else:
-            logger.debug("BaseTimeState: invalid character for "\
+            logger.debug("BaseTimeState: invalid character for "
                          "adding/subtracting time: '%r'" % key)
         return True
 
@@ -401,13 +411,14 @@
         project.start += timedelta(minutes=minutes)
         self.state.sec -= sec
         logger.info("SubtractTimeState: subtract %d minutes from project '%s'"
-                % (minutes, project.desc))
+                    % (minutes, project.desc))
         self.view.show_total_time()
         self.set_next_state(self.state)
         return True
 
 
 class DescriptionProjectsState(HandleUserInputState):
+
     """ Adds a description to a stopped running project """
 
     messages = {
@@ -423,7 +434,8 @@
         if text == '':
             return True
         self.controller.stop_project(text)
-        self.controller.view.set_footer_text(self.msg('choose_proj'), 'question')
+        self.controller.view.set_footer_text(
+            self.msg('choose_proj'), 'question')
         self.set_next_state(PausedProjectsState(self.controller, self.view))
         self.view.update_rows()
         self.view.show_total_time()
@@ -496,24 +508,27 @@
         if keys.get_entry_delete() in key:
             if self.view.selection:
                 self.set_next_state(DeleteEntryState(self.projectlist_state,
-                    self.controller, self.view))
+                                                     self.controller,
+                                                     self.view))
             else:
                 entry = self.view.item_in_focus()
                 self.set_next_state(DeleteEntryState(self.projectlist_state,
-                    self.controller, self.view, [entry]))
+                                                     self.controller, self.view,
+                                                     [entry]))
             return True
 
         if keys.get_entry_move() in key:
             if self.view.selection:
                 self.set_next_state(MoveEntryState(self.projectlist_state,
-                    self.controller, self.view))
+                                                   self.controller, self.view))
             return True
 
         if keys.get_entry_edit() in key:
             entry = self.view.item_in_focus()
             if entry:
                 self.set_next_state(EditEntryState(self.projectlist_state,
-                    self.controller, self.view, entry))
+                                                   self.controller, self.view,
+                                                   entry))
             return True
 
         return False
@@ -522,7 +537,7 @@
 class DeleteEntryState(EntryListState):
 
     messages = {
-        'delete'  : _("Really delete this entry? (y/n)"),
+        'delete': _("Really delete this entry? (y/n)"),
     }
 
     def __init__(self, state, controller, view, entries=None):
@@ -539,14 +554,16 @@
                 self.renew_focus()
             self.view.set_footer_text("", 'entry_footer')
             self.set_next_state(DefaultEntryListState(self.projectlist_state,
-                self.controller, self.view))
+                                                      self.controller,
+                                                      self.view))
             self.controller.project_view.show_total_time()
             return True
 
         if 'n' in key:
             self.view.set_footer_text("", 'entry_footer')
             self.set_next_state(DefaultEntryListState(self.projectlist_state,
-                self.controller, self.view))
+                                                      self.controller,
+                                                      self.view))
             return True
 
         return False
@@ -567,8 +584,8 @@
         self.project_view = controller.project_view
 
     def set_project_footer(self):
-        self.project_view.set_footer_text("Selecting project from " \
-           "key: %s" % self.proj_keys, "running")
+        self.project_view.set_footer_text("Selecting project from "
+                                          "key: %s" % self.proj_keys, "running")
 
     def reset_project_footer(self):
         self.project_view.reset_footer()
@@ -581,11 +598,10 @@
         if proj:
             self.proj = proj
             self.reset_project_footer()
-            logger.debug("MoveEntryState: prepared entries to be " \
-                            "moved to project '%s'" % self.proj.desc)
+            logger.debug("MoveEntryState: prepared entries to be "
+                         "moved to project '%s'" % self.proj.desc)
             self.view.set_footer_text(self.msg('really'), 'question')
 
-
     def handle_input(self, key):
         keys = self.config.get_keybinding()
         if 'y' in key and self.proj:
@@ -595,21 +611,24 @@
             self.view.set_footer_text('', 'entry_footer')
             self.proj = None
             self.set_next_state(DefaultEntryListState(self.projectlist_state,
-                self.controller, self.view))
+                                                      self.controller,
+                                                      self.view))
             return True
 
         if 'n' in key and self.proj:
             self.view.set_footer_text('', 'entry_footer')
             self.reset_project_footer()
             self.set_next_state(DefaultEntryListState(self.projectlist_state,
-                self.controller, self.view))
+                                                      self.controller,
+                                                      self.view))
             return True
 
         if keys.get_escape() in key:
             self.view.set_footer_text('', 'entry_footer')
             self.reset_project_footer()
             self.set_next_state(DefaultEntryListState(self.projectlist_state,
-                self.controller, self.view))
+                                                      self.controller,
+                                                      self.view))
             return True
 
         if 'backspace' in key:
@@ -638,16 +657,17 @@
 class AlterProjectState(HandleUserInputState):
 
     messages = {
-            'choose_proj': _(' Choose a project.'),
-            }
+        'choose_proj': _(' Choose a project.'),
+    }
 
     def __init__(self, controller, view):
-        super(AlterProjectState, self).__init__(controller, view, None,
-                controller.view.get_frame().get_footer())
+        super(AlterProjectState, self).__init__(
+            controller, view, None,
+            controller.view.get_frame().get_footer())
 
     def exit(self):
         self.controller.view.set_footer_text(self.msg('choose_proj'),
-                'question')
+                                             'question')
         self.set_next_state(PausedProjectsState(self.controller, self.view))
         return True
 
@@ -668,7 +688,7 @@
 
     def __init__(self, controller, view):
         controller.view.set_footer_text(self.msg('proj_key'), 'question',
-                edit=True)
+                                        edit=True)
         super(AddProjectKeyState, self).__init__(controller, view)
 
     def enter(self):
@@ -676,7 +696,7 @@
         if key == '':
             return True
         self.set_next_state(AddProjectDescriptionState(self.controller,
-            self.view, key))
+                                                       self.view, key))
         return True
 
 
@@ -685,11 +705,11 @@
     messages = {
         'proj_description': _('Insert a description for project: '),
         'choose_proj': _(" Choose a project.")
-        }
+    }
 
     def __init__(self, controller, view, key):
         controller.view.set_footer_text(self.msg('proj_description'),
-                'question', edit=True)
+                                        'question', edit=True)
         super(AddProjectDescriptionState, self).__init__(controller, view)
         self.key = key
 
@@ -712,7 +732,7 @@
         view.set_footer_text(self.msg('edit_entry'),
                              'question', True)
         super(EditEntryState, self).__init__(controller, view,
-                None, view.footer)
+                                             None, view.footer)
         self.footer.set_edit_text(entry.desc)
         self.footer.set_edit_pos(len(self.footer.edit_text))
         self.entry = entry
@@ -732,7 +752,7 @@
     def exit(self):
         self.view.set_footer_text("", 'entry_footer', False)
         self.set_next_state(DefaultEntryListState(self.state, self.controller,
-            self.view))
+                                                  self.view))
         return True
 
     def set_focus(self):
@@ -750,7 +770,7 @@
 
     def __init__(self, controller, view, project):
         controller.view.set_footer_text(self.msg('proj_key'),
-                                             'question', 1)
+                                        'question', 1)
         super(ProjectEditKeyState, self).__init__(controller, view)
         self.project = project
         self.footer.set_edit_text(project.key)
@@ -762,20 +782,21 @@
             return True
         self.project.key = key
         self.set_next_state(ProjectEditDescriptionState(self.controller,
-            self.view, self.project))
+                                                        self.view,
+                                                        self.project))
         return True
 
 
 class ProjectEditDescriptionState(AlterProjectState):
 
     messages = {
-        "proj_description" : _("Insert description for project: "),
-        "choose_proj" : _(" Choose a project.")
+        "proj_description": _("Insert description for project: "),
+        "choose_proj": _(" Choose a project.")
     }
 
     def __init__(self, controller, view, project):
         controller.view.set_footer_text(self.msg("proj_description"),
-                                             "question", 1)
+                                        "question", 1)
         super(ProjectEditDescriptionState, self).__init__(controller, view)
         self.project = project
         self.footer.set_edit_text(project.desc)
@@ -787,6 +808,7 @@
             return self
         self.project.desc = description
         self.controller.update_project(self.project)
-        self.controller.view.set_footer_text(self.msg('choose_proj'), 'question')
+        self.controller.view.set_footer_text(
+            self.msg('choose_proj'), 'question')
         self.set_next_state(PausedProjectsState(self.controller, self.view))
         return True
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)