Atit Anand has proposed merging lp:~atit-anand-cs/gtg/random_tag_color into 
lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~atit-anand-cs/gtg/random_tag_color/+merge/208450

Fix for the bug #644993. Automatic generation of tag color
-- 
https://code.launchpad.net/~atit-anand-cs/gtg/random_tag_color/+merge/208450
Your team Gtg developers is requested to review the proposed merge of 
lp:~atit-anand-cs/gtg/random_tag_color into lp:gtg.
=== modified file 'AUTHORS'
--- AUTHORS	2014-02-25 18:19:31 +0000
+++ AUTHORS	2014-02-26 18:23:44 +0000
@@ -131,3 +131,5 @@
 * Pawan Hegde <h.pa...@gmail.com>
 * Sagar Ghuge <ghuge...@gmail.com>
 * Sushant Raikar <sushanttheco...@gmail.com>
+* Atit Anand <atit.anand...@gmail.com>
+

=== modified file 'CHANGELOG'
--- CHANGELOG	2014-02-25 18:38:16 +0000
+++ CHANGELOG	2014-02-26 18:23:44 +0000
@@ -14,6 +14,8 @@
     * Fix for bug #1248185: due label in task editor says "Due for" should say "Due on", by Pawan Hegde
     * Fix for bug #1282955: Clicking out side the calender widget should close the widget by Sagar Ghuge
     * Fix for bug #1033268: Mouseover String Incorrect, by Sushant Raikar
+    * Fix for bug #644993 : Automatic generation of tag color, by Atit Anand
+
 
 2013-11-24 Getting Things GNOME! 0.3.1
     * Fix for bug #1024473: Have 'Show Main Window' in notification area, by Antonio Roquentin
@@ -43,7 +45,7 @@
     * Fix for bug #1242384: send-email: toolbar item is not removed from an opened task, by Fabiano Fidencio
     * Fix for bug #1029342: Give an option to remove tag color, by kpytang
     * Fixed Hamster Plugin: bugs #487582, #487585, #1236066, #1242083 and #1242279, by Parin Porecha
-
+    
 2012-11-06 Getting Things GNOME! 0.3
     * Hide tasks with due date someday, #931376
     * New Date class by Paul Kishimoto and Izidor MatuĊĦov

=== modified file 'GTG/gtk/browser/CellRendererTags.py'
--- GTG/gtk/browser/CellRendererTags.py	2013-11-25 02:37:46 +0000
+++ GTG/gtk/browser/CellRendererTags.py	2014-02-26 18:23:44 +0000
@@ -61,7 +61,6 @@
     def __count_viewable_tags(self):
 
         count = 0
-
         if self.tag_list is not None:
             for my_tag in self.tag_list:
                 my_tag_color = my_tag.get_attribute("color")

=== modified file 'GTG/gtk/browser/tag_context_menu.py'
--- GTG/gtk/browser/tag_context_menu.py	2013-11-25 02:37:46 +0000
+++ GTG/gtk/browser/tag_context_menu.py	2014-02-26 18:23:44 +0000
@@ -27,7 +27,7 @@
 """
 
 from gi.repository import Gtk
-
+from GTG.gtk.colors import generate_tag_color, color_add, color_remove
 from GTG import _
 
 
@@ -53,8 +53,12 @@
             # Color chooser FIXME: SHOULD BECOME A COLOR PICKER
             self.mi_cc = Gtk.MenuItem()
             self.mi_cc.set_label(_("Edit Tag..."))
+            self.mi_ctag = Gtk.MenuItem()
+            self.mi_ctag.set_label(_("Generate Color"))
             self.append(self.mi_cc)
+            self.append(self.mi_ctag)
             self.mi_cc.connect('activate', self.on_mi_cc_activate)
+            self.mi_ctag.connect('activate', self.on_mi_ctag_activate)
             if self.tag.is_search_tag():
                 self.mi_del = Gtk.MenuItem()
                 self.mi_del.set_label(_("Delete"))
@@ -74,6 +78,14 @@
         """Callback: show the tag editor upon request"""
         self.vmanager.open_tag_editor(self.tag)
 
+    def on_mi_ctag_activate(self, widget):
+        random_color = generate_tag_color()
+        present_color = self.tag.get_attribute('color')
+        if(present_color is not None):
+                color_remove(present_color)
+        self.tag.set_attribute('color', random_color)
+        color_add(random_color)
+
     def on_mi_del_activate(self, widget):
         """ delete a selected search """
         self.req.remove_tag(self.tag.get_name())

=== modified file 'GTG/gtk/browser/tag_editor.py'
--- GTG/gtk/browser/tag_editor.py	2014-01-15 10:40:09 +0000
+++ GTG/gtk/browser/tag_editor.py	2014-02-26 18:23:44 +0000
@@ -32,6 +32,7 @@
 from GTG import _
 from GTG.gtk.browser.simple_color_selector import SimpleColorSelector
 from GTG.tools.logger import Log
+from GTG.gtk.colors import color_add, color_remove
 
 
 class TagIconSelector(Gtk.Window):
@@ -469,6 +470,13 @@
         """Callback: update the tag color depending on the current color
         selection"""
         color = self.tc_cc_colsel.get_selected_color()
+        if (color is None):
+                color_remove(self.tag.get_attribute('color'))
+        else:
+                my_color = Gdk.color_parse(color)
+                color = Gdk.Color(my_color.red, my_color.green, my_color.blue).to_string()
+                color_add(color)
+
         if self.tag is not None:
             if color is not None:
                 self.tag.set_attribute('color', color)

=== modified file 'GTG/gtk/browser/treeview_factory.py'
--- GTG/gtk/browser/treeview_factory.py	2013-11-25 02:37:46 +0000
+++ GTG/gtk/browser/treeview_factory.py	2014-02-26 18:23:44 +0000
@@ -77,9 +77,7 @@
         search_parent = self.req.get_tag(CoreConfig.SEARCH_TAG)
         for search_tag in search_parent.get_children():
             tag = self.req.get_tag(search_tag)
-            match = search_filter(node,
-                                  parse_search_query(
-                                  tag.get_attribute('query')))
+            match = search_filter(node, parse_search_query(tag.get_attribute('query')))
             if match and search_tag not in tags:
                 tags.append(tag)
 

=== modified file 'GTG/gtk/colors.py'
--- GTG/gtk/colors.py	2013-11-25 02:37:46 +0000
+++ GTG/gtk/colors.py	2014-02-26 18:23:44 +0000
@@ -19,10 +19,12 @@
 
 from gi.repository import Gdk
 from functools import reduce
-
+import random
 # Take list of Tags and give the background color that should be applied
 # The returned color might be None (in which case, the default is used)
 
+used_color = []
+
 
 def background_color(tags, bgcolor=None):
     if not bgcolor:
@@ -35,6 +37,8 @@
     blue = 0
     for my_tag in tags:
         my_color_str = my_tag.get_attribute("color")
+        if my_color_str is not None and my_color_str not in used_color:
+            used_color.append(my_color_str)
         if my_color_str:
             my_color = Gdk.color_parse(my_color_str)
             color_count = color_count + 1
@@ -90,4 +94,30 @@
         tags_txt = reduce(lambda a, b: a + ", " + b, tag_markups)
     return tags_txt
 
+
+def generate_tag_color():
+
+    maxvalue = 65535
+    flag = 0
+    while(flag == 0):
+        red = random.randint(0, maxvalue)
+        green = random.randint(0, maxvalue)
+        blue = random.randint(0, maxvalue)
+        my_color = Gdk.Color(red, green, blue).to_string()
+        if my_color not in used_color:
+            flag = 1
+    used_color.append(my_color)
+    return my_color
+
+
+def color_add(present_color):
+
+    if present_color not in used_color:
+        used_color.append(present_color)
+
+
+def color_remove(present_color):
+
+    if present_color in used_color:
+        used_color.remove(present_color)
 # -----------------------------------------------------------------------------

_______________________________________________
Mailing list: https://launchpad.net/~gtg
Post to     : gtg@lists.launchpad.net
Unsubscribe : https://launchpad.net/~gtg
More help   : https://help.launchpad.net/ListHelp

Reply via email to