1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# -*- coding: utf-8 -*-
# pylint: disable-msg=W0201
# -----------------------------------------------------------------------------
# Getting Things Gnome! - a personal organizer for the GNOME desktop
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
import pygtk
pygtk.require('2.0')
import gobject
import gtk
from GTG import _
from GTG.gtk.browser import GnomeConfig
class TagContextMenu(gtk.Menu):
def __init__(self, req, tag=None):
self.__gobject_init__()
self.req = req
self.tag = tag
# Build up the menu
self.__build_menu()
self.set_tag(tag)
# Make it visible
self.show_all()
def __build_menu(self):
# Color chooser FIXME: SHOULD BECOME A COLOR PICKER
self.mi_cc = gtk.MenuItem()
self.mi_cc.set_label(_("Set color..."))
self.append(self.mi_cc)
# Reset color
self.mi_rc = gtk.MenuItem()
self.mi_rc.set_label(_("Reset color"))
self.append(self.mi_rc)
# Don't display in work view mode
self.mi_wv = gtk.CheckMenuItem()
self.mi_wv.set_label(GnomeConfig.TAG_IN_WORKVIEW_TOGG)
self.append(self.mi_wv)
# Set the callbacks
self.mi_cc.connect('activate', self.on_mi_cc_activate)
self.mi_rc.connect('activate', self.on_mi_rc_activate)
self.mi_wv_toggle_hid = self.mi_wv.connect('activate', self.on_mi_wv_activate)
def __set_default_values(self):
# Don't set "Hide in workview" as active
self.mi_wv.set_active(False)
def __disable_all(self):
pass
def __enable_all(self):
pass
### PUBLIC API ###
def set_tag(self, tag):
"""Update the context menu items using the tag attributes."""
# set_active emit the 'toggle' signal, so we have to disable the handler
# when we update programmatically
self.mi_wv.handler_block(self.mi_wv_toggle_hid)
if tag is None:
self.tag = None
self.__set_default_values()
self.__disable_all()
else:
self.tag = tag
self.__enable_all()
is_hidden_in_wv = (self.tag.get_attribute("nonworkview") == "True")
self.mi_wv.set_active(is_hidden_in_wv)
self.mi_wv.handler_unblock(self.mi_wv_toggle_hid)
### CALLBACKS ###
def on_mi_wv_activate(self, widget):
"""Toggle the nonworkview attribute of the tag, update the view"""
is_hidden_in_wv = not (self.tag.get_attribute("nonworkview") == "True")
self.tag.set_attribute("nonworkview", str(is_hidden_in_wv))
def on_mi_cc_activate(self, widget):
color_dialog = gtk.ColorSelectionDialog('Choose color')
colorsel = color_dialog.colorsel
# Get previous color
color = self.tag.get_attribute("color")
if color is not None:
colorspec = gtk.gdk.color_parse(color)
colorsel.set_previous_color(colorspec)
colorsel.set_current_color(colorspec)
response = color_dialog.run()
new_color = colorsel.get_current_color()
# Check response_id and set color if required
if response == gtk.RESPONSE_OK and new_color:
strcolor = gtk.color_selection_palette_to_string([new_color])
self.tag.set_attribute("color", strcolor)
color_dialog.destroy()
def on_mi_rc_activate(self, widget):
"""
handler for the right click popup menu item from tag tree, when its a @tag
"""
self.tag.del_attribute("color")
|