Import only one driver from application.
authorRadek Brich <radek.brich@devl.cz>
Mon, 20 Feb 2012 18:15:13 +0100
changeset 29 c0cdef06fd16
parent 28 feee783d4fc5
child 30 05500124d7fb
Import only one driver from application.
.hgignore
demo_window.py
tuikit/application.py
tuikit/driver_curses.py
tuikit/driver_dummy.py
tuikit/driver_pygame.py
--- a/.hgignore	Wed Oct 12 10:11:27 2011 +0200
+++ b/.hgignore	Mon Feb 20 18:15:13 2012 +0100
@@ -6,3 +6,4 @@
 \.project
 \.pydevproject
 \.settings
+.*\.appstats
--- a/demo_window.py	Wed Oct 12 10:11:27 2011 +0200
+++ b/demo_window.py	Mon Feb 20 18:15:13 2012 +0100
@@ -48,7 +48,7 @@
     app = MyApplication()
     #app.start()
     
-    cProfile.run('app.start()', 'appstats')
-    p = pstats.Stats('appstats')
+    cProfile.run('app.start()', 'demo_window.appstats')
+    p = pstats.Stats('demo_window.appstats')
     p.sort_stats('time', 'cumulative').print_stats(20)
 
--- a/tuikit/application.py	Wed Oct 12 10:11:27 2011 +0200
+++ b/tuikit/application.py	Mon Feb 20 18:15:13 2012 +0100
@@ -5,9 +5,6 @@
 import math
 
 from tuikit.container import Container
-from tuikit.driver_curses import DriverCurses
-from tuikit.driver_pygame import DriverPygame
-from tuikit.driver_dummy import DriverDummy
 
 
 class TopWindow(Container):
@@ -85,11 +82,9 @@
         
         self.quit = False
         
-        #FIXME: import only selected driver, not all
-        driver_dict = {'dummy': DriverDummy, 'curses': DriverCurses, 'pygame': DriverPygame}
-        self.driver = driver_dict[driver]()
-        '''Driver class (render + input), e.g. DriverCurses.'''
-
+        self.driver = self.get_driver_instance(driver)
+        '''Driver class instance (render + input), e.g. DriverCurses.'''
+        
         self.log = logging.getLogger('tuikit')
         self.log.setLevel(logging.DEBUG)
         handler = logging.FileHandler('./tuikit.log')
@@ -148,3 +143,8 @@
         driver.setcolor('menu',                    'black on cyan')
         driver.setcolor('menu-active',             'white on cyan, bold')
 
+
+    def get_driver_instance(self, name):
+        module = __import__('tuikit.driver_' + name, fromlist=['driverclass'])
+        return module.driverclass()
+
--- a/tuikit/driver_curses.py	Wed Oct 12 10:11:27 2011 +0200
+++ b/tuikit/driver_curses.py	Mon Feb 20 18:15:13 2012 +0100
@@ -409,3 +409,7 @@
             raise Exception('Unknown mouse event: %x' % t)
 
         return out
+
+
+driverclass = DriverCurses
+
--- a/tuikit/driver_dummy.py	Wed Oct 12 10:11:27 2011 +0200
+++ b/tuikit/driver_dummy.py	Mon Feb 20 18:15:13 2012 +0100
@@ -83,3 +83,6 @@
         '''Hide cursor.'''
         self.log.info('DummyDriver.hidecursor()')
 
+
+driverclass = DriverDummy
+
--- a/tuikit/driver_pygame.py	Wed Oct 12 10:11:27 2011 +0200
+++ b/tuikit/driver_pygame.py	Mon Feb 20 18:15:13 2012 +0100
@@ -339,3 +339,6 @@
     def hidecursor(self):
         '''Hide cursor.'''
 
+
+driverclass = DriverPygame
+