← Back to team overview

gtg team mailing list archive

[Merge] lp:~bertrand-rousseau/gtg/new-tag-label-in-taskviews into lp:gtg

 

Bertrand Rousseau has proposed merging lp:~bertrand-rousseau/gtg/new-tag-label-in-taskviews into lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~bertrand-rousseau/gtg/new-tag-label-in-taskviews/+merge/74364

Provide improved tag widget for the task views
-- 
https://code.launchpad.net/~bertrand-rousseau/gtg/new-tag-label-in-taskviews/+merge/74364
Your team Gtg developers is requested to review the proposed merge of lp:~bertrand-rousseau/gtg/new-tag-label-in-taskviews into lp:gtg.
=== modified file 'GTG/gtk/browser/CellRendererTags.py'
--- GTG/gtk/browser/CellRendererTags.py	2010-06-02 18:12:23 +0000
+++ GTG/gtk/browser/CellRendererTags.py	2011-09-07 09:02:15 +0000
@@ -34,6 +34,10 @@
             "Tag list", "A list of tags", gobject.PARAM_READWRITE),
         'tag': (gobject.TYPE_PYOBJECT, "Tag",\
              "Tag", gobject.PARAM_READWRITE),
+        'show_text': (gobject.TYPE_PYOBJECT, 'Show text', \
+                          'Show tag name', gobject.PARAM_READWRITE),
+        'font_size': (gobject.TYPE_PYOBJECT, 'Font size', \
+                          'Tag name font size', gobject.PARAM_READWRITE),
     }
 
     # Private methods
@@ -78,20 +82,32 @@
     def __init__(self): #pylint: disable-msg=W0231
         self.__gobject_init__()
         self.tag_list = None
-        self.tag      = None
-        self.xpad     = 1
-        self.ypad     = 1
-        self.PADDING  = 1
+        self.show_text = False
+        self.tag = None
+        self.xpad = 1
+        self.ypad = 1
+        self.PADDING = 1
+        self.HEIGHT = 16
+        self.MINWIDTH = 16
+        self.font_size = 8.0
 
     def do_set_property(self, pspec, value):
         if pspec.name == "tag-list":
             self.tag_list = value
+        elif pspec.name == 'show-text':
+            self.show_text = True
+        elif pspec.name == 'font-size':
+            self.font_size = int(value)
         else:
             setattr(self, pspec.name, value)
 
     def do_get_property(self, pspec):
         if pspec.name == "tag-list":
             return self.tag_list
+        elif pspec.name == "show-text":
+            return self.show_text
+        elif pspec.name == "font-size":
+            return self.font_size
         else:
             return getattr(self, pspec.name)
 
@@ -114,45 +130,87 @@
         gdkcontext = gtk.gdk.CairoContext(cr)
         gdkcontext.set_antialias(cairo.ANTIALIAS_NONE)
 
-        # Coordinates of the origin point
-        x_align = self.get_property("xalign")
-        y_align = self.get_property("yalign")
-        orig_x  = cell_area.x + int((cell_area.width  - 16*vw_tags -\
-            self.PADDING*2*(vw_tags-1)) * x_align)
-        orig_y  = cell_area.y + int((cell_area.height - 16) * y_align)
+        rect = gtk.gdk.Rectangle()
+        rect.x, rect.y, rect.width, rect.height = \
+         self.on_get_size(widget, cell_area)
+
+        rect.x += cell_area.x + self.get_property("xpad")
+        rect.y += cell_area.y + self.get_property("ypad")
 
         # We draw the icons & squares
+
         for my_tag in tags:
 
             my_tag_icon  = my_tag.get_attribute("icon")
             my_tag_color = my_tag.get_attribute("color")
-
-            rect_x  = orig_x + self.PADDING*2*count + 16*count
-            rect_y  = orig_y
+            my_tag_name  = my_tag.get_attribute("name")[1:]
 
             if my_tag_icon:
-
-#                pixbuf     = gtk.gdk.pixbuf_new_from_file(my_tag_icon)
                 pixbuf = gtk.icon_theme_get_default().load_icon(\
-                    my_tag_icon, 16, 0)
-                gdkcontext.set_source_pixbuf(pixbuf, rect_x, rect_y)
+                    my_tag_icon, self.HEIGHT, 0)
+                gdkcontext.set_source_pixbuf(pixbuf, rect.x, rect.y)
                 gdkcontext.paint()
-                count = count + 1
-
+                rect.x = rect.x + 2 * self.PADDING + self.MINWIDTH
             elif my_tag_color:
-
-                # Draw rounded rectangle
-                my_color = gtk.gdk.color_parse(my_tag_color)
-                gdkcontext.set_source_color(my_color)
-                self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
-                gdkcontext.fill()
-                count = count + 1
-
-                # Outer line
-                gdkcontext.set_source_rgba(0, 0, 0, 0.20)
-                gdkcontext.set_line_width(1.0)
-                self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
-                gdkcontext.stroke()
+                if self.show_text:
+                    box_padding = 3
+
+                    # text
+                    gdkcontext.set_font_size(self.font_size)
+                    xb, yb_ref, fw, fh_ref = cr.text_extents("peoplemoney")[:4]
+                    x_bearing, y_bearing, f_width, f_height = cr.text_extents(my_tag_name)[:4]
+
+                    # decide size
+                    height = self.HEIGHT
+                    width = max(f_width, self.MINWIDTH) + 2 * box_padding
+
+                    # Draw rounded rectangle
+                    my_color = gtk.gdk.color_parse(my_tag_color)
+#                    gdkcontext.set_source_rgba(my_color.red/65535.0, \
+#                                               my_color.green/65535.0, \
+#                                               my_color.blue/65535.0, 0.75)
+                    gdkcontext.set_source_color(my_color)
+                    self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 6)
+                    gdkcontext.fill()
+
+#                    # Outer line
+#                    gdkcontext.set_source_rgba(0, 0, 0, 0.20)
+#                    gdkcontext.set_line_width(1.0)
+#                    self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 8)
+#                    gdkcontext.stroke()
+
+                    # draw text
+                    b = (my_color.red*299.0 + my_color.green*587 + \
+                         my_color.blue*114) / 65535.0 / 1000.0
+                    if b > 0.5:
+                        c = 0.0
+                    else:
+                        c = 1.0
+                    gdkcontext.set_source_rgba(c, c, c, 1.0)
+                    gdkcontext.move_to(rect.x + width/2 - f_width/2,\
+                                       rect.y + (height - fh_ref)/2 - yb_ref)
+                    gdkcontext.show_text(my_tag_name)
+
+                    rect.x = rect.x + 2 * self.PADDING + width
+
+                else:
+                    # decide size
+                    height = self.HEIGHT
+                    width = self.MINWIDTH
+
+                    # Draw rounded rectangle
+                    my_color = gtk.gdk.color_parse(my_tag_color)
+                    gdkcontext.set_source_color(my_color)
+                    self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 8)
+                    gdkcontext.fill()
+
+                    # Outer line
+                    gdkcontext.set_source_rgba(0, 0, 0, 0.20)
+                    gdkcontext.set_line_width(1.0)
+                    self.__roundedrec(gdkcontext, rect.x, rect.y, width, height, 8)
+                    gdkcontext.stroke()
+
+                    rect.x = rect.x + 2 * self.PADDING + width
 
         if self.tag and my_tag: #pylint: disable-msg=W0631
 
@@ -163,24 +221,67 @@
 
                 # Draw rounded rectangle
                 gdkcontext.set_source_rgba(0.95, 0.95, 0.95, 1)
-                self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
+                self.__roundedrec(gdkcontext, rect.x, rect.y, 16, 16, 8)
                 gdkcontext.fill()
 
                 # Outer line
                 gdkcontext.set_source_rgba(0, 0, 0, 0.20)
                 gdkcontext.set_line_width(1.0)
-                self.__roundedrec(gdkcontext, rect_x, rect_y, 16, 16, 8)
+                self.__roundedrec(gdkcontext, rect.x, rect.y, 16, 16, 8)
                 gdkcontext.stroke()
 
     def on_get_size(self, widget, cell_area=None): #pylint: disable-msg=W0613
 
+        retval = (0, 0, 0, 0)
+
+        xpad = self.get_property("xpad")
+        ypad = self.get_property("ypad")
+
         count = self.__count_viewable_tags()
 
         if count != 0:
-            return (self.xpad, self.ypad, self.xpad*2 + 16*count +\
-                 2*count*self.PADDING, 16 + 2*self.ypad)
-        else:
-            return (self.xpad, self.ypad, self.xpad*2, self.ypad*2)
+
+            # Select source
+            if self.tag_list != None:
+                tags = self.tag_list
+            elif self.tag != None:
+                tags = [self.tag]
+
+            # accumulate squares/rectangles/icons widths
+            acc_width = 0
+            for my_tag in tags:
+                my_tag_color = my_tag.get_attribute("color")
+                my_tag_icon  = my_tag.get_attribute("icon")
+                if self.show_text:
+                    if my_tag_color is not None:
+                    # it's a tag "rectangle"
+                        surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, 1, 1)
+                        cr = cairo.Context (surface)
+                        gdkcontext = gtk.gdk.CairoContext(cr)
+                        gdkcontext.set_font_size(self.font_size)
+                        # compute text extents
+                        my_tag_name  = my_tag.get_attribute("name")[1:]
+                        x_bearing, y_bearing, f_width, f_height = cr.text_extents(my_tag_name)[:4]
+                        # decide size
+                        width = max(int(f_width), self.MINWIDTH) + 2 * self.PADDING + 2 * 3
+                        acc_width = acc_width + width
+                    if my_tag_icon is not None:
+                    # it's a square on an icon
+                        acc_width = acc_width + 16 + 2 * self.PADDING
+                else:
+                    acc_width = acc_width + 16 + 2 * self.PADDING
+
+           # compute width, height and offsets
+            width = acc_width + 2 * xpad
+            height = self.HEIGHT + 2 * ypad
+            if cell_area:   
+                xoffset = max(self.get_property("xalign") * (cell_area.width - width), 0)
+                yoffset = max(self.get_property("yalign") * (cell_area.height - height), 0)
+            else:
+                xoffset = 0
+                yoffset = 0
+            retval = (xoffset, yoffset, width, height)
+        return retval
 
 gobject.type_register(CellRendererTags)
 

=== modified file 'GTG/gtk/browser/treeview_factory.py'
--- GTG/gtk/browser/treeview_factory.py	2011-08-24 22:13:48 +0000
+++ GTG/gtk/browser/treeview_factory.py	2011-09-07 09:02:15 +0000
@@ -394,18 +394,6 @@
         col['order'] = 0
         col['sorting_func'] = self.title_sorting
         desc[col_name] = col
-        
-        # "tags" column (no title)
-        col_name = 'tags'
-        col = {}
-        render_tags = CellRendererTags()
-        render_tags.set_property('xalign', 0.0)
-        col['renderer'] = ['tag_list',render_tags]
-        col['value'] = [gobject.TYPE_PYOBJECT,self.task_tags_column]
-        col['expandable'] = False
-        col['resizable'] = False
-        col['order'] = 1
-        desc[col_name] = col
 
         # "label" column
         col_name = 'label'
@@ -418,8 +406,23 @@
         col['expandable'] = True
         col['resizable'] = True
         col['sorting'] = 'title'
+        col['order'] = 1
+        desc[col_name] = col
+
+        # "tags" column (no title)
+        col_name = 'tags'
+        col = {}
+        render_tags = CellRendererTags()
+        render_tags.set_property('xalign', 1.0)
+        render_tags.set_property('show_text', True)
+        col['renderer'] = ['tag_list',render_tags]
+        col['value'] = [gobject.TYPE_PYOBJECT,self.task_tags_column]
+        col['expandable'] = True
+        col['resizable'] = True
         col['order'] = 2
+        col['new_column'] = False
         desc[col_name] = col
+
         return desc
         
     def build_task_treeview(self,tree,desc):