18
18
# this program. If not, see <http://www.gnu.org/licenses/>.
19
19
# -----------------------------------------------------------------------------
23
Implements a context (pop-up) menu for the tag item in the sidebar.
24
Right now it is just a void shell It is supposed to become a more generic
25
sidebar context for all kind of item displayed there.
26
Also, it is supposed to handle more complex menus (with non-std widgets,
22
31
pygtk.require('2.0')
27
from GTG.gtk.browser import GnomeConfig
29
class TagContextMenu(gtk.Menu):
31
def __init__(self, req, tag=None):
36
class TagContextMenu(gtk.Menu): # pylint: disable-msg=R0904
37
"""Context menu fo the tag i the sidebar"""
39
def __init__(self, req, vmanager, tag=None):
32
40
self.__gobject_init__()
41
gtk.Menu.__init__(self)
43
self.vmanager = vmanager
35
45
# Build up the menu
49
def __build_menu(self):
50
"""Build up the widget"""
55
if self.tag is not None:
56
# Color chooser FIXME: SHOULD BECOME A COLOR PICKER
57
self.mi_cc = gtk.MenuItem()
58
self.mi_cc.set_label(_("Edit Tag..."))
59
self.append(self.mi_cc)
60
self.mi_cc.connect('activate', self.on_mi_cc_activate)
61
if self.tag.is_search_tag():
62
self.mi_del = gtk.MenuItem()
63
self.mi_del.set_label(_("Delete"))
64
self.append(self.mi_del)
65
self.mi_del.connect('activate', self.on_mi_del_activate)
41
def __build_menu(self):
42
# Color chooser FIXME: SHOULD BECOME A COLOR PICKER
43
self.mi_cc = gtk.MenuItem()
44
self.mi_cc.set_label(_("Set color..."))
45
self.append(self.mi_cc)
47
self.mi_rc = gtk.MenuItem()
48
self.mi_rc.set_label(_("Reset color"))
49
self.append(self.mi_rc)
50
# Don't display in work view mode
51
self.mi_wv = gtk.CheckMenuItem()
52
self.mi_wv.set_label(GnomeConfig.TAG_IN_WORKVIEW_TOGG)
53
self.append(self.mi_wv)
55
self.mi_cc.connect('activate', self.on_mi_cc_activate)
56
self.mi_rc.connect('activate', self.on_mi_rc_activate)
57
self.mi_wv_toggle_hid = self.mi_wv.connect('activate', self.on_mi_wv_activate)
59
def __set_default_values(self):
60
# Don't set "Hide in workview" as active
61
self.mi_wv.set_active(False)
63
def __disable_all(self):
66
def __enable_all(self):
71
71
def set_tag(self, tag):
72
72
"""Update the context menu items using the tag attributes."""
73
# set_active emit the 'toggle' signal, so we have to disable the handler
74
# when we update programmatically
75
self.mi_wv.handler_block(self.mi_wv_toggle_hid)
78
self.__set_default_values()
83
is_hidden_in_wv = (self.tag.get_attribute("nonworkview") == "True")
84
self.mi_wv.set_active(is_hidden_in_wv)
85
self.mi_wv.handler_unblock(self.mi_wv_toggle_hid)
89
def on_mi_wv_activate(self, widget):
90
"""Toggle the nonworkview attribute of the tag, update the view"""
91
is_hidden_in_wv = not (self.tag.get_attribute("nonworkview") == "True")
92
self.tag.set_attribute("nonworkview", str(is_hidden_in_wv))
94
def on_mi_cc_activate(self, widget):
95
color_dialog = gtk.ColorSelectionDialog('Choose color')
96
colorsel = color_dialog.colorsel
99
color = self.tag.get_attribute("color")
100
if color is not None:
101
colorspec = gtk.gdk.color_parse(color)
102
colorsel.set_previous_color(colorspec)
103
colorsel.set_current_color(colorspec)
104
response = color_dialog.run()
105
new_color = colorsel.get_current_color()
107
# Check response_id and set color if required
108
if response == gtk.RESPONSE_OK and new_color:
109
strcolor = gtk.color_selection_palette_to_string([new_color])
110
self.tag.set_attribute("color", strcolor)
111
color_dialog.destroy()
113
def on_mi_rc_activate(self, widget):
115
handler for the right click popup menu item from tag tree, when its a @tag
117
self.tag.del_attribute("color")
78
def on_mi_cc_activate(self, widget): # pylint: disable-msg=W0613
79
"""Callback: show the tag editor upon request"""
80
self.vmanager.open_tag_editor(self.tag)
82
def on_mi_del_activate(self, widget): # pylint: disable-msg=W0613
83
""" delete a selected search """
84
self.req.remove_tag(self.tag.get_name())