changeset 194:cf98dc7f9354

Move mainloop related code to GetanController
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 23 Jan 2013 15:04:43 +0100
parents e7466f3210c6
children 0c0d88ec53f9
files getan/controller.py getan/states.py getan/view.py
diffstat 3 files changed, 21 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/getan/controller.py	Thu Jan 17 11:44:33 2013 +0100
+++ b/getan/controller.py	Wed Jan 23 15:04:43 2013 +0100
@@ -10,6 +10,8 @@
 #
 
 import logging
+import urwid
+
 from   datetime import datetime
 
 from getan.view import GetanView
@@ -39,7 +41,12 @@
         self.state = PausedProjectsState(self, self.project_view)
 
     def main(self):
-        self.view.run()
+        self.loop = urwid.MainLoop(self.view.get_frame(),
+                                   self.view.get_palette(),
+                                   screen=urwid.raw_display.Screen(),
+                                   unhandled_input=self.unhandled_keypress,
+                                   input_filter=self.input_filter)
+        self.loop.run()
 
     def unhandled_keypress(self, key):
         self.state = self.state.keypress(key)
@@ -107,9 +114,6 @@
         self.project_view.update()
         self.view.update_view()
 
-    def exit(self):
-        self.view.exit()
-
     def project_by_key(self, key):
         for proj in self.projects:
             if proj.key == key:
@@ -180,3 +184,7 @@
 
     def get_config(self):
         return self.config
+
+    def exit(self):
+        logger.info("GetanController: exit.")
+        raise urwid.ExitMainLoop()
--- a/getan/states.py	Thu Jan 17 11:44:33 2013 +0100
+++ b/getan/states.py	Wed Jan 23 15:04:43 2013 +0100
@@ -219,7 +219,7 @@
                                                  (human_time(self.sec),
                                                   proj.desc),
                                                  'running')
-            self.controller.view.loop.draw_screen()
+            self.controller.loop.draw_screen()
             self.sec = self.sec + 1
         else:
             self.view.set_footer_text(
@@ -227,7 +227,7 @@
                 (human_time((datetime.now()-self.break_start).seconds),
                  self.msg('continue') % keys.get_project_pause()),
                 'paused_running')
-            self.controller.view.loop.draw_screen()
+            self.controller.loop.draw_screen()
 
         signal.signal(signal.SIGALRM, self.handle_signal)
         signal.alarm(1)
--- a/getan/view.py	Thu Jan 17 11:44:33 2013 +0100
+++ b/getan/view.py	Wed Jan 23 15:04:43 2013 +0100
@@ -16,7 +16,7 @@
 
 from getan.resources import gettext as _
 from getan.states    import *
-from getan.utils     import short_time, format_datetime, format_time
+from getan.utils     import short_time, format_datetime
 
 logger = logging.getLogger()
 
@@ -298,21 +298,21 @@
         if len(self.rows) > 0:
             self.rows[self.focused].update()
             self._total_time()
-            self.controller.view.loop.draw_screen()
+            self.controller.loop.draw_screen()
 
     def update_all(self):
         logger.debug("ProjectList: update all project rows now.")
         for proj in self.rows:
             proj.update()
         self._total_time()
-        self.controller.view.loop.draw_screen()
+        self.controller.loop.draw_screen()
 
     def switch_time_mode(self):
         logger.debug("ProjectList: switch time mode now.")
         for proj in self.rows:
             proj.switch_time_mode()
         self._total_time()
-        self.controller.view.loop.draw_screen()
+        self.controller.loop.draw_screen()
 
     def unhandled_keypress(self, key):
         logger.debug("ProjectList: unhandled keypress '%r'" % key)
@@ -459,7 +459,7 @@
         logger.debug("GetanView: update view now.")
         view = urwid.AttrWrap(self.columns, 'body')
         self.view.set_body(view)
-        self.loop.draw_screen()
+        self.controller.loop.draw_screen()
 
     def get_frame(self):
         return self.view
@@ -472,16 +472,5 @@
             logger.debug("GetanView: set footer text: '%s'" % text)
             self.view.set_footer(urwid.AttrWrap(urwid.Text(text),attr))
 
-    def run(self):
-        self.loop = urwid.MainLoop(self.view, self.palette,
-                                   screen=urwid.raw_display.Screen(),
-                                   unhandled_input=self.controller.unhandled_keypress,
-                                   input_filter=self.controller.input_filter)
-        self.loop.run()
-
-    def unhandled_keypress(self, k):
-        logger.warn("GetanView: unhandled keypress '%r'" % k)
-
-    def exit(self):
-        logger.info("GetanView: shutdown view.")
-        raise urwid.ExitMainLoop()
+    def get_palette(self):
+        return self.palette
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)