1
# -*- coding: utf-8 -*-
2
# pylint: disable-msg=W0201
3
# -----------------------------------------------------------------------------
4
# Getting Things Gnome! - a personal organizer for the GNOME desktop
5
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
7
# This program is free software: you can redistribute it and/or modify it under
8
# the terms of the GNU General Public License as published by the Free Software
9
# Foundation, either version 3 of the License, or (at your option) any later
12
# This program is distributed in the hope that it will be useful, but WITHOUT
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17
# You should have received a copy of the GNU General Public License along with
18
# this program. If not, see <http://www.gnu.org/licenses/>.
19
# -----------------------------------------------------------------------------
27
from GTG.gtk.browser import GnomeConfig
29
class TagContextMenu(gtk.Menu):
31
def __init__(self, req, tag=None):
32
self.__gobject_init__()
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
def set_tag(self, tag):
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")