bigboard r7312 - trunk/bigboard/stocks/search



Author: otaylor
Date: Wed Apr 23 23:30:37 2008
New Revision: 7312
URL: http://svn.gnome.org/viewvc/bigboard?rev=7312&view=rev

Log:
Fix rendering of header rows: pack the treeview inside a canvas
  rather than inside a VBox so we have a style to use to
  draw header rows with. Change around the themed cell renderers
  to be a bit more generic and fit in with how theme engines
  work in the CSS styling system.


Modified:
   trunk/bigboard/stocks/search/SearchStock.py

Modified: trunk/bigboard/stocks/search/SearchStock.py
==============================================================================
--- trunk/bigboard/stocks/search/SearchStock.py	(original)
+++ trunk/bigboard/stocks/search/SearchStock.py	Wed Apr 23 23:30:37 2008
@@ -8,7 +8,7 @@
 from bigboard.libbig.imagecache import URLImageCache
 from bigboard.libbig.http import AsyncHTTPFetcher
 from bigboard.stock import Stock
-from bigboard.big_widgets import CanvasMugshotURLImage, CanvasVBox, ThemeManager, ThemeManager
+from bigboard.big_widgets import CanvasMugshotURLImage, CanvasVBox, ThemeManager, ThemeManager, BigWindow
 import bigboard.search as search
 
 if __name__ == '__main__':
@@ -20,62 +20,64 @@
 
 class ThemedTextRenderer(gtk.CellRendererText):
     __gproperties__ = {
-        'themed': (gobject.TYPE_BOOLEAN, 'Themed', 'Whether or not we are themed', False, gobject.PARAM_READWRITE)
+        'theme-part': (str, 'Theme Part', 'Part name to pass to theme engine', None, gobject.PARAM_READWRITE)
     }
     def __init__(self, *args, **kwargs):
         gtk.CellRendererText.__init__(self, *args, **kwargs)
         self.__tm = ThemeManager.getInstance()
-        self.__themed = False
+        self.__theme_part = False
         
-    def do_render(self, window, widget, bg, cell_area, expose_area, flags):
-        if self.__themed:
-            tm = self.__tm.get_theme()
+    def do_render(self, window, widget, background_area, cell_area, expose_area, flags):
+        if self.__theme_part:
+            item = widget.get_data('canvas-item')
+            style = item.get_style()
             cr = window.cairo_create()
-            tm.draw_header(cr, bg)
-        gtk.CellRendererText.do_render(self, window, widget, bg, cell_area, expose_area, flags)
+            style.paint(cr, self.__theme_part, background_area.x, background_area.y, background_area.width, background_area.height)
+        gtk.CellRendererText.do_render(self, window, widget, background_area, cell_area, expose_area, flags)
         
    # override
     def do_set_property(self, pspec, value):
-        if pspec.name == 'themed':
-            self.__themed = value          
+        if pspec.name == 'theme-part':
+            self.__theme_part = value          
         else:
             raise AttributeError, 'unknown property %s' % pspec.name
 
     # override
     def do_get_property(self, pspec):
-        if pspec.name == 'themed':
-            return self.__themed
+        if pspec.name == 'theme-part':
+            return self.__theme_part
         else:
             raise AttributeError, 'unknown property %s' % pspec.name           
 gobject.type_register(ThemedTextRenderer)
 
 class ThemedPixbufRenderer(gtk.CellRendererPixbuf):
     __gproperties__ = {
-        'themed': (gobject.TYPE_BOOLEAN, 'Themed', 'Whether or not we are themed', False, gobject.PARAM_READWRITE)
+        'theme-part': (str, 'Theme Part', 'Part name to pass to theme engine', None, gobject.PARAM_READWRITE)
     }
     def __init__(self, *args, **kwargs):
         gtk.CellRendererPixbuf.__init__(self, *args, **kwargs)
         self.__tm = ThemeManager.getInstance()
-        self.__themed = False
+        self.__theme_part = False
         
-    def do_render(self, window, widget, bg, cell_area, expose_area, flags):
-        if self.__themed:
-            tm = self.__tm.get_theme()
+    def do_render(self, window, widget, background_area, cell_area, expose_area, flags):
+        if self.__theme_part:
+            item = widget.get_data('canvas-item')
+            style = item.get_style()
             cr = window.cairo_create()
-            tm.draw_header(cr, bg)
-        gtk.CellRendererPixbuf.do_render(self, window, widget, bg, cell_area, expose_area, flags)
+            style.paint(cr, self.__theme_part, background_area.x, background_area.y, background_area.width, background_area.height)
+        gtk.CellRendererPixbuf.do_render(self, window, widget, background_area, cell_area, expose_area, flags)
         
    # override
     def do_set_property(self, pspec, value):
-        if pspec.name == 'themed':
-            self.__themed = value          
+        if pspec.name == 'theme-part':
+            self.__theme_part = value          
         else:
             raise AttributeError, 'unknown property %s' % pspec.name
 
     # override
     def do_get_property(self, pspec):
-        if pspec.name == 'themed':
-            return self.__themed
+        if pspec.name == 'theme-part':
+            return self.__theme_part
         else:
             raise AttributeError, 'unknown property %s' % pspec.name           
 gobject.type_register(ThemedTextRenderer)   
@@ -168,19 +170,19 @@
         if result:
             renderer.set_property('background', None)
             renderer.set_property('weight', pango.WEIGHT_NORMAL)            
+            renderer.set_property('theme-part', None)
         else:
             # this is a heading
             renderer.set_property('weight', pango.WEIGHT_BOLD)
-#            bg = self.__tm.get_theme().background
-#            bg_color = gtk.gdk.color_parse('#%02X%02X%02X' % ((bg >> 24) & 0xFF,
-#                                                              (bg >> 16) & 0xFF,
-#                                                              (bg >> 8) & 0xFF,))
-#            renderer.set_property('background-gdk', bg_color)
-        renderer.set_property('themed', not result)
+            renderer.set_property('theme-part', 'header')
             
     def __render_icon(self, col, cell, model, iter):
         result = model.get_value(iter, 0)
-        cell.set_property('themed', not result)      
+        if result:
+            theme_part = None
+        else:
+            theme_part = 'header'
+        cell.set_property('theme-part', theme_part)
         pixbuf = model.get(iter, 1)[0]  
         if isinstance(pixbuf, gtk.gdk.Pixbuf):
             cell.set_property('pixbuf', pixbuf)
@@ -418,21 +420,23 @@
 
         self.__current_consumer = None
 
-        self.__results_window = gtk.Window(gtk.WINDOW_POPUP)
+        
+        self.__results_window = BigWindow(type=gtk.WINDOW_POPUP, themed=True)
         self.__results_window.set_resizable(False)
         self.__results_window.set_focus_on_map(False)
         self.__results_window.set_size_request(500, -1)
         
-        vbox = gtk.VBox()
-        self.__results_window.add(vbox)
-        
         self.__results_view = ResultsView()
         self.__results_view.connect('match-selected', lambda obj: self.emit('match-selected'))
         
         treeview = self.__results_view.get_widget()
-        vbox.add(treeview)
-        vbox.show_all()
+        treeview.show()
 
+        item  = hippo.CanvasWidget(widget=treeview)
+        # Set user data so our cell renderer can go back from the widget to the canvas item
+        treeview.set_data('canvas-item', item)
+        self.__results_window.set_root(item)
+        
         self.__idle_search_id = 0
         self.connect('changed', self.__on_changed)
         self.connect('key-press-event', self.__on_key_press)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]