Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack.
authorRadek Brich <radek.brich@devl.cz>
Sun, 27 Jan 2013 23:51:59 +0100
changeset 70 db2eab0beb45
parent 69 4e7be77bafff
child 71 cfd3445107b4
Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack. Application: Add overridable startup() method. Fix Widget draw clipping.
demo_colors.py
demo_layout.py
tuikit/__init__.py
tuikit/application.py
tuikit/container.py
tuikit/driver_curses.py
tuikit/driver_dummy.py
tuikit/driver_sdl.py
tuikit/widget.py
--- a/demo_colors.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/demo_colors.py	Sun Jan 27 23:51:59 2013 +0100
@@ -25,10 +25,10 @@
 
     def apply_theme(self):
         Application.apply_theme(self)
-        self.driver.setcolor('test-blink',              'cyan on blue, blink')
-        self.driver.setcolor('test-bold',               'cyan on blue, bold')
-        self.driver.setcolor('test-standout',           'cyan on blue, standout')
-        self.driver.setcolor('test-underline',          'cyan on blue, underline')
+        self.driver.defcolor('test-blink',              'cyan on blue, blink')
+        self.driver.defcolor('test-bold',               'cyan on blue, bold')
+        self.driver.defcolor('test-standout',           'cyan on blue, standout')
+        self.driver.defcolor('test-underline',          'cyan on blue, underline')
 
     def on_top_keypress(self, ev):
         if ev.keyname == 'escape':
--- a/demo_layout.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/demo_layout.py	Sun Jan 27 23:51:59 2013 +0100
@@ -4,7 +4,7 @@
 import locale
 locale.setlocale(locale.LC_ALL, '')
 
-from tuikit import *
+from tuikit import Application, VerticalLayout, HorizontalLayout, Button
 
 
 class MyApplication(Application):
--- a/tuikit/__init__.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/__init__.py	Sun Jan 27 23:51:59 2013 +0100
@@ -4,7 +4,7 @@
 from tuikit.button import Button
 from tuikit.checkbox import Checkbox
 from tuikit.combobox import ComboBox
-from tuikit.common import Rect, Size, Coords
+from tuikit.common import Rect, Size, Coords, Borders
 from tuikit.container import Container
 from tuikit.editbox import EditBox
 from tuikit.editfield import EditField
--- a/tuikit/application.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/application.py	Sun Jan 27 23:51:59 2013 +0100
@@ -102,7 +102,7 @@
 
     def main_loop(self):
         '''The main loop.'''
-        self.apply_theme()
+        self.startup()
         self._top._size = self.driver.size  # link top widget size to screen size
         self._top.emit('resize')
         timer = self._timer
@@ -125,23 +125,26 @@
                 break
         self.log.info('=== quit ===')
 
+    def startup(self):
+        """This is called after startup, before entering event loop."""
+        self.apply_theme()
 
     def apply_theme(self):
         #TODO: allow custom colors:
         #    e.g. "blue (#2020FF) on black (#101010), underline"
         #    color in brackets is used when driver supports custom colors
-        driver = self.driver
-        driver.setcolor('normal',                  'lightgray on black')
-        driver.setcolor('strong',                  'white on black, bold')
-        driver.setcolor('active',                  'black on cyan')
-        driver.setcolor('window:normal',           'lightgray on blue')
-        driver.setcolor('window:controls',         'white on blue, bold')
-        driver.setcolor('window:controls-active',  'cyan on blue, bold')
-        driver.setcolor('button',                  'black on white')
-        driver.setcolor('button-active',           'black on cyan')
-        driver.setcolor('menu',                    'black on cyan')
-        driver.setcolor('menu-active',             'white on cyan, bold')
-        driver.setcolor('combo:normal',            'black on green')
+        drv = self.driver
+        drv.defcolor('normal',                  'lightgray on black')
+        drv.defcolor('strong',                  'white on black, bold')
+        drv.defcolor('active',                  'black on cyan')
+        drv.defcolor('window:normal',           'lightgray on blue')
+        drv.defcolor('window:controls',         'white on blue, bold')
+        drv.defcolor('window:controls-active',  'cyan on blue, bold')
+        drv.defcolor('button',                  'black on white')
+        drv.defcolor('button-active',           'black on cyan')
+        drv.defcolor('menu',                    'black on cyan')
+        drv.defcolor('menu-active',             'white on cyan, bold')
+        drv.defcolor('combo:normal',            'black on green')
 
 
     def get_driver_instance(self, name):
--- a/tuikit/container.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/container.py	Sun Jan 27 23:51:59 2013 +0100
@@ -144,7 +144,6 @@
         if self.hidden:
             return True
 
-        driver.clipstack.push(x, y, self.width, self.height)
         if self.colorprefix:
             driver.pushcolorprefix(self.colorprefix)
 
@@ -166,7 +165,6 @@
 
         if self.colorprefix:
             driver.popcolorprefix()
-        driver.clipstack.pop()
 
     def draw_floaters(self, driver, x, y):
         #logging.getLogger('tuikit').info('draw_floaters %s %r %r', self, x ,y )
--- a/tuikit/driver_curses.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/driver_curses.py	Sun Jan 27 23:51:59 2013 +0100
@@ -131,7 +131,8 @@
             res = res | self.attr_map[a]
         return res
 
-    def setcolor(self, name, desc):
+    def defcolor(self, name, desc):
+        """Define color name."""
         parts = desc.split(',')
         fgbg = parts[0].split(' on ', 1)
         fg = fgbg[0]
@@ -143,6 +144,10 @@
         attr = self._parseattrs(attrs)
         self.colors[name] = curses.color_pair(col) | fgattr | attr
 
+    def setcolor(self, name):
+        """Set defined color. Previous color is forgotten."""
+        self.screen.attrset(self.colors[name])
+
     def pushcolor(self, name):
         # add prefix if such color is available
         if len(self.colorprefix):
--- a/tuikit/driver_dummy.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/driver_dummy.py	Sun Jan 27 23:51:59 2013 +0100
@@ -59,7 +59,7 @@
 
     ## colors ##
 
-    def setcolor(self, name, desc):
+    def defcolor(self, name, desc):
         '''Define color name.
 
         Args:
@@ -69,7 +69,18 @@
                 eg. 'white on black, bold'
 
         '''
-        self.log.info('DummyDriver.setcolor(name=%r, desc=%r)', name, desc)
+        self.log.info('DummyDriver.defcolor(name=%r, desc=%r)', name, desc)
+
+    def setcolor(self, name):
+        """Set defined color.
+
+        Previous color is forgotten.
+        Color prefix is ignored.
+
+        See pushcolor, popcolor for more advanced work with colors.
+
+        """
+        self.log.info('DummyDriver.setcolor(name=%r)', name)
 
     def pushcolor(self, name):
         '''Add color on top of stack and use this color for following output.'''
--- a/tuikit/driver_sdl.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/driver_sdl.py	Sun Jan 27 23:51:59 2013 +0100
@@ -99,13 +99,8 @@
 
     ## colors ##
 
-    def setcolor(self, name, desc):
-        '''Define color name.
-
-        name - name of color (e.g. 'normal', 'active')
-        desc - color description - foreground, background, attributes (e.g. 'black on white, bold')
-
-        '''
+    def defcolor(self, name, desc):
+        '''Define color name.'''
         parts = desc.split(',')
         fgbg = parts[0].split(' on ', 1)
         fg = fgbg[0]
@@ -116,6 +111,10 @@
         style = self._style_by_names(style)
         self.colors[name] = self.sdlterm.prepare_attr(fg, bg, style);
 
+    def setcolor(self, name):
+        """Set defined color. Previous color is forgotten."""
+        self.sdlterm.set_attr(self.colors[name])
+
     def pushcolor(self, name):
         '''Add color on top of stack and use this color for following output.'''
         if len(self.colorprefix):
--- a/tuikit/widget.py	Sun Jan 27 12:54:52 2013 +0100
+++ b/tuikit/widget.py	Sun Jan 27 23:51:59 2013 +0100
@@ -172,7 +172,9 @@
         if self.hidden:
             return True
 
+        driver.clipstack.push(x, y, self.width, self.height)
         self.emit('draw', driver, x, y)
+        driver.clipstack.pop()
 
         if self.has_focus():
             if self.cursor: