Configure logging for demos.
authorRadek Brich <radek.brich@devl.cz>
Wed, 26 Mar 2014 21:26:39 +0100
changeset 92 b97c4e25ed6d
parent 91 de80e140b0ec
child 93 c1e79acb9fcb
Configure logging for demos.
.hgignore
demos/01_buffer.py
demos/02_curses.py
demos/03_application.py
demos/demobase.py
tuikit/core/application.py
tuikit/core/container.py
tuikit/core/widget.py
--- a/.hgignore	Wed Mar 26 09:08:10 2014 +0100
+++ b/.hgignore	Wed Mar 26 21:26:39 2014 +0100
@@ -1,7 +1,7 @@
 .*~$
 ^tuikit/.*\.pyc$
 ^docs/_build
-^tuikit\.log
+tuikit\.log
 ^build
 ^sdlterm/build
 ^sdlterm/font
--- a/demos/01_buffer.py	Wed Mar 26 09:08:10 2014 +0100
+++ b/demos/01_buffer.py	Wed Mar 26 21:26:39 2014 +0100
@@ -1,7 +1,6 @@
 #!/usr/bin/env python3
 
-import sys
-sys.path.append('..')
+import demobase
 
 from tuikit.core.buffer import Buffer
 from tuikit.driver.driver import Driver
--- a/demos/02_curses.py	Wed Mar 26 09:08:10 2014 +0100
+++ b/demos/02_curses.py	Wed Mar 26 21:26:39 2014 +0100
@@ -1,7 +1,6 @@
 #!/usr/bin/env python3
 
-import sys
-sys.path.append('..')
+import demobase
 
 from tuikit.core.buffer import Buffer
 from tuikit.driver.curses import CursesDriver
--- a/demos/03_application.py	Wed Mar 26 09:08:10 2014 +0100
+++ b/demos/03_application.py	Wed Mar 26 21:26:39 2014 +0100
@@ -1,7 +1,6 @@
 #!/usr/bin/env python3
 
-import sys
-sys.path.append('..')
+import demobase
 
 from tuikit.core.application import Application
 from tuikit.widgets.label import Label
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demos/demobase.py	Wed Mar 26 21:26:39 2014 +0100
@@ -0,0 +1,13 @@
+import sys
+sys.path.append('..')
+
+import logging
+
+# Setup logging
+logger = logging.getLogger('tuikit')
+logger.setLevel(logging.DEBUG)
+handler = logging.FileHandler(filename='tuikit.log')
+handler.setLevel(logging.DEBUG)
+formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
+handler.setFormatter(formatter)
+logger.addHandler(handler)
--- a/tuikit/core/application.py	Wed Mar 26 09:08:10 2014 +0100
+++ b/tuikit/core/application.py	Wed Mar 26 21:26:39 2014 +0100
@@ -16,7 +16,7 @@
     """
 
     def __init__(self, driver='curses'):
-        self.log = logging.getLogger('tuikit')
+        self.log = logging.getLogger(__name__)
         self.driver = None
         self.timer = Timer()
         self.window_manager = WindowManager(timer=self.timer)
@@ -45,7 +45,7 @@
 
     def start(self):
         """Start application. Runs main loop."""
-        self.log.info('=== start ===')
+        self.log.info('=== Start ===')
         with self.driver:
             self.main_loop()
 
@@ -71,5 +71,5 @@
                 self.window_manager.handle_event(event[0], *event[1:])
 
         self._started = False
-        self.log.info('=== quit ===')
+        self.log.info('=== End ===')
 
--- a/tuikit/core/container.py	Wed Mar 26 09:08:10 2014 +0100
+++ b/tuikit/core/container.py	Wed Mar 26 21:26:39 2014 +0100
@@ -24,10 +24,10 @@
     def draw(self, buffer, x=0, y=0):
         """Draw child widgets."""
         for child in self.children:
-            with buffer.clip(x, y, child.width, child.height):
-                child.draw(buffer,
-                           x + child.x,
-                           y + child.y)
+            cx = x + child.x
+            cy = y + child.y
+            with buffer.clip(cx, cy, child.width, child.height):
+                child.draw(buffer, cx, cy)
 
     def set_theme(self, theme):
         Widget.set_theme(self, theme)
--- a/tuikit/core/widget.py	Wed Mar 26 09:08:10 2014 +0100
+++ b/tuikit/core/widget.py	Wed Mar 26 21:26:39 2014 +0100
@@ -55,7 +55,7 @@
 
     ## appearance ##
 
-    def draw(self, buffer, x=0, y=0):
+    def draw(self, buffer, x, y):
         pass
 
     def set_theme(self, theme):