~nmu-sscheel/gtg/rework-task-editor

« back to all changes in this revision

Viewing changes to GTG/gtk/browser/tag_context_menu.py

  • Committer: Bertrand Rousseau
  • Date: 2012-05-09 22:33:25 UTC
  • mfrom: (1178 trunk)
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: bertrand.rousseau@gmail.com-20120509223325-a53d8nwo0x9g93bc
Merge nimit branch and trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
6
#
 
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
 
10
# version.
 
11
#
 
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
 
15
# details.
 
16
#
 
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
# -----------------------------------------------------------------------------
 
20
 
 
21
import pygtk
 
22
pygtk.require('2.0')
 
23
import gobject
 
24
import gtk
 
25
 
 
26
from GTG import _
 
27
from GTG.gtk.browser import GnomeConfig
 
28
 
 
29
class TagContextMenu(gtk.Menu):
 
30
 
 
31
    def __init__(self, req, tag=None):
 
32
        self.__gobject_init__()
 
33
        self.req = req
 
34
        self.tag = tag
 
35
        # Build up the menu
 
36
        self.__build_menu()
 
37
        self.set_tag(tag)
 
38
        # Make it visible
 
39
        self.show_all()
 
40
 
 
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)
 
46
        # Reset color
 
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)
 
54
        # Set the callbacks
 
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)
 
58
 
 
59
    def __set_default_values(self):
 
60
        # Don't set "Hide in workview" as active
 
61
        self.mi_wv.set_active(False)
 
62
 
 
63
    def __disable_all(self):
 
64
        pass
 
65
 
 
66
    def __enable_all(self):
 
67
        pass
 
68
 
 
69
    ### PUBLIC API ###
 
70
 
 
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)
 
76
        if tag is None:
 
77
            self.tag = None
 
78
            self.__set_default_values()
 
79
            self.__disable_all()
 
80
        else:
 
81
            self.tag = tag
 
82
            self.__enable_all()
 
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)
 
86
 
 
87
    ### CALLBACKS ###
 
88
 
 
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))
 
93
 
 
94
    def on_mi_cc_activate(self, widget):
 
95
        color_dialog = gtk.ColorSelectionDialog('Choose color')
 
96
        colorsel = color_dialog.colorsel
 
97
 
 
98
        # Get previous color
 
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()
 
106
        
 
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()
 
112
 
 
113
    def on_mi_rc_activate(self, widget):
 
114
        """
 
115
        handler for the right click popup menu item from tag tree, when its a @tag
 
116
        """
 
117
        self.tag.del_attribute("color")
 
118