=== modified file 'GTG/gtk/browser/browser.py' --- GTG/gtk/browser/browser.py 2013-12-18 16:20:01 +0000 +++ GTG/gtk/browser/browser.py 2014-02-22 05:52:40 +0000 @@ -1210,7 +1210,7 @@ settings_undismiss = {"label": GnomeConfig.MARK_UNDISMISS, "tooltip": GnomeConfig.MARK_UNDISMISS_TOOLTIP, "icon-name": "gtg-task-undismiss"} - + def update_button(button, settings): button.set_icon_name(settings["icon-name"]) button.set_label(settings["label"]) === 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-22 00:55:12 +0000 @@ -27,6 +27,7 @@ """ from gi.repository import Gtk +from GTG.gtk.colors import * from GTG import _ @@ -53,8 +54,12 @@ # Color chooser FIXME: SHOULD BECOME A COLOR PICKER self.mi_cc = Gtk.MenuItem() self.mi_cc.set_label(_("Edit Tag...")) + self.mi_cc1=Gtk.MenuItem() + self.mi_cc1.set_label(_("Generate Color")) self.append(self.mi_cc) + self.append(self.mi_cc1) self.mi_cc.connect('activate', self.on_mi_cc_activate) + self.mi_cc1.connect('activate', self.on_mi_cc1_activate) if self.tag.is_search_tag(): self.mi_del = Gtk.MenuItem() self.mi_del.set_label(_("Delete")) @@ -73,7 +78,12 @@ def on_mi_cc_activate(self, widget): """Callback: show the tag editor upon request""" self.vmanager.open_tag_editor(self.tag) - + + def on_mi_cc1_activate(self, widget): + #self.tag.set_attribute('color', "#FCAF3E") + my_color=generate_tag_color() + self.tag.set_attribute('color',my_color) + def on_mi_del_activate(self, widget): """ delete a selected search """ self.req.remove_tag(self.tag.get_name()) === modified file 'GTG/gtk/colors.py' --- GTG/gtk/colors.py 2013-11-25 02:37:46 +0000 +++ GTG/gtk/colors.py 2014-02-22 06:03:31 +0000 @@ -19,6 +19,8 @@ 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) @@ -90,4 +92,37 @@ tags_txt = reduce(lambda a, b: a + ", " + b, tag_markups) return tags_txt + +def generate_tag_color(): + ''' This HSV to RBG conversion is taken directly from http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV + ''' + + h,s,v=random.random()*6,.5,243.2 + color_set=[] + rgb_color=[] + prev_hex_value="#5C3566" #this will be used when invalid color is generated + n=20 + for i in range(int(n)): + h+=3.708; # 6/golden ratio=3.708 + + c=v*s;m=v-c;x=c-c*abs(1-h%2)+m;c+=m; + rgb_set=[(c,x,m),(x,c,m),(m,c,x),(m,x,c),(x,m,c),(c,m,x)] + + rgb_value=rgb_set[int(h)%6] + rgb_color.append(rgb_value) + hex_value='#'+'%02x'*3%(rgb_value[:3]) + hex_value=hex_value.upper() + + if(hex_value.find('-')!=-1): #invalid color generated,use previous color + hex_value=prev_hex_value + color_set.append(hex_value) + prev_hex_value=random.choice(color_set) # change previous color,to increase randomness + + if i%5/4:s+=.1;v-=.2 + final_color=random.choice(color_set) + #print(final_color) + return final_color + + + # -----------------------------------------------------------------------------