← Back to team overview

gtg team mailing list archive

[Merge] lp:~kpytang/gtg/remove-tag-color into lp:gtg

 

kpytang has proposed merging lp:~kpytang/gtg/remove-tag-color into lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~kpytang/gtg/remove-tag-color/+merge/192466

Adds an extra button that allows user to remove tag colors. The original method required users to click on the tag color to select/unselect the color. Adding the extra button provides a more explicit way for users to clear the selected color.
-- 
https://code.launchpad.net/~kpytang/gtg/remove-tag-color/+merge/192466
Your team Gtg developers is requested to review the proposed merge of lp:~kpytang/gtg/remove-tag-color into lp:gtg.
=== modified file 'GTG/gtk/browser/simple_color_selector.py'
--- GTG/gtk/browser/simple_color_selector.py	2013-02-25 08:29:31 +0000
+++ GTG/gtk/browser/simple_color_selector.py	2013-10-24 07:41:51 +0000
@@ -229,13 +229,24 @@
             cc_hbox.set_spacing(4)
             self.cc_buttons.append(img)
         # Draw the add button
+        buttons_hbox = gtk.HBox()
+        cc_vbox.pack_start(buttons_hbox)
         img = gtk.Image()
         img.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
         self.add_button = gtk.Button()
         self.add_button.set_image(img)
         self.add_button.set_label(_("Add custom color"))
-        cc_vbox.pack_start(self.add_button, expand=True, fill=True)
+        buttons_hbox.pack_start(self.add_button, expand=True, fill=False)
         self.add_button.connect("clicked", self.on_color_add)
+        # Draw the clear selected color button
+        img = gtk.Image()
+        img.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_BUTTON)
+        self.clear_button = gtk.Button()
+        self.clear_button.set_image(img)
+        self.clear_button.set_label(_("Clear selected color"))
+        buttons_hbox.pack_start(self.clear_button, expand=True, fill=False)
+        self.clear_button.connect("clicked", self.on_color_clear)
+        self.clear_button.set_sensitive(False)
         # hide the custom palette if no custom color is defined
         if len(self.custom_colors) == 0:
             self.custom_palette.hide()
@@ -250,14 +261,26 @@
         if self.selected_col == widget:
             self.selected_col.set_selected(False)
             self.selected_col = None
+            self.clear_button.set_sensitive(False)
         else:
             # if previous selection: unselect
             if self.selected_col is not None:
                 self.selected_col.set_selected(False)
             self.selected_col = widget
             self.selected_col.set_selected(True)
+            self.clear_button.set_sensitive(True)
         self.emit("color-changed")
 
+    def on_color_clear(self, widget):
+        """Callback: when clearing the color, reset any selected
+        color, update the model and notify the parent"""
+        # unselect current selection
+        if self.selected_col is not None:
+            self.selected_col.set_selected(False)
+            self.selected_col = None
+            self.clear_button.set_sensitive(False)
+            self.emit("color-changed")
+
     def on_color_add(self, widget):
         """Callback: when adding a new color, show the color definition
         window, update the model, notifies the parent."""
@@ -318,18 +341,20 @@
             return self.selected_col.color
 
     def set_selected_color(self, col):
-        """Defines the selected state of a displayed color"""
+        """Defines the selected state of a displayed color,
+        enables clear button when a color is selected"""
         self.unselect_color()
         if self.has_color(col):
             self.buttons_lookup[col].set_selected(True)
             self.selected_col = self.buttons_lookup[col]
+        self.clear_button.set_sensitive(True)
 
     def unselect_color(self):
         """Deselect all colors"""
         if self.selected_col is not None:
             self.selected_col.set_selected(False)
             self.selected_col = None
-
+        self.clear_button.set_sensitive(False)
 
 gobject.type_register(SimpleColorSelector)
 gobject.signal_new("color-changed", SimpleColorSelector,


Follow ups