~ubuntu-branches/ubuntu/utopic/awn-extras-applets/utopic

« back to all changes in this revision

Viewing changes to applets/maintained/tomboy-applet/tomboy-applet.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-04-11 22:38:55 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100411223855-mamzuv887xyms08b
Tags: 0.4.0-0ubuntu1
* New upstream release.
 - Close cairo-menu after a click (LP: #511256)
 - Fix crash of awn-system-monitor (LP: #545164)
 - Fix crash when removing a volume >1 or adding volume >1 or using prefs
   while > 1 volumes is present (LP: #556175)
 - Fix crash of media-control when Rhythmbox quit (LP: #558463)
 - Fix crash of file-browser-launcher when there is no .gtk-bookmarks
   (LP: #551119)
* debian/awn-c-extras.install: 
 - Install icons and ini files for webapplets
* debian/awn-python-core.install:
 - Install ui file for comics (LP: #552376)
* debian/patches:
 - 03-remove-cairo-menu-pref.patch: Merged upstream.
 - 04-tomboy-threading-free.patch: Merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
import os
18
 
import threading
19
18
 
20
19
import pygtk
21
20
pygtk.require("2.0")
22
21
import gtk
23
22
 
24
 
from awn.extras import awnlib, __version__
25
 
 
26
 
try:
27
 
    import dbus
28
 
except ImportError:
29
 
    dbus = None
30
 
 
31
 
applet_name = "Tomboy Applet"
32
 
applet_description = "Control Tomboy with D-Bus"
 
23
from awn.extras import awnlib, __version__, _
 
24
 
 
25
import dbus
 
26
from dbus.mainloop.glib import DBusGMainLoop
 
27
 
 
28
DBusGMainLoop(set_as_default=True)
 
29
 
 
30
applet_name = _("Tomboy Applet")
 
31
applet_description = _("Control Tomboy with D-Bus")
33
32
applet_system_notebook = "system:notebook:"
34
33
applet_system_template = "system:template"
35
34
 
36
 
# Logo of the applet, shown in the GTK About dialog
37
 
applet_logo = os.path.join(os.path.dirname(__file__), "icons", "tomboy.png")
 
35
# Applet's themed icon, also shown in the GTK About dialog
 
36
applet_logo = "tomboy"
38
37
 
39
38
bus_name = "org.gnome.Tomboy"
40
39
object_name = "/org/gnome/Tomboy/RemoteControl"
45
44
 
46
45
    __interface = None
47
46
    tags = None
 
47
    __dialog = None
48
48
 
49
49
    def __init__(self, awnlib):
50
50
        self.awn = awnlib
51
51
 
52
 
        awnlib.icon.file(applet_logo)
53
 
 
54
 
        if dbus is not None:
55
 
            def run_tomboy():
56
 
                try:
57
 
                    bus = dbus.SessionBus()
58
 
                    if bus_name not in bus.list_names():
59
 
                        bus.start_service_by_name(bus_name)
60
 
                    self.connect(bus)
61
 
                except dbus.DBusException, e:
62
 
                    awnlib.errors.general("Could not connect to Tomboy: %s" % e)
63
 
            threading.Thread(target=run_tomboy).start()
 
52
        try:
 
53
            bus = dbus.SessionBus()
 
54
            if bus_name not in bus.list_names():
 
55
                bus.start_service_by_name(bus_name)
 
56
            self.connect(bus)
 
57
        except dbus.DBusException, e:
 
58
            awnlib.errors.general(("Could not connect to Tomboy", e.args[0]))
64
59
 
65
60
    def connect(self, bus):
66
61
        object = bus.get_object(bus_name, object_name)
67
62
        self.__interface = dbus.Interface(object, if_name)
 
63
        self.__interface.connect_to_signal("NoteAdded", self.notes_changed)
 
64
        self.__interface.connect_to_signal("NoteDeleted", self.notes_changed)
68
65
        self.__version = self.__interface.Version()
69
66
        if self.__interface is not None:
70
67
            self.main_dialog()
71
68
 
 
69
    def notes_changed(self, *args, **kwargs):
 
70
        self.main_dialog()
 
71
 
72
72
    def display_search(self, widget):
73
73
        self.__interface.DisplaySearch()
74
74
 
103
103
 
104
104
    def create_from_tag_dialog(self, widget):
105
105
        dialog = self.awn.dialog.new("create_from_tag")
106
 
        dialog.add(gtk.Label("Select a tag:"))
107
 
        for tag in self.collect_tags():
108
 
            button = gtk.Button(tag)
109
 
            button.connect("clicked", self.create_from_tag, tag)
110
 
            dialog.add(button)
 
106
        available_tags = self.collect_tags()
 
107
        if len(available_tags) > 0:
 
108
            dialog.add(gtk.Label(_("Select a tag:")))
 
109
            for tag in available_tags:
 
110
                button = gtk.Button(tag)
 
111
                button.connect("clicked", self.create_from_tag, tag)
 
112
                dialog.add(button)
 
113
        else:
 
114
            dialog.add(gtk.Label(_("No tags were created yet")))
111
115
        dialog.show_all()
112
116
 
113
117
    def view_from_tag(self, widget, tag):
114
118
        dialog = self.awn.dialog.new("view_from_tag")
115
 
        dialog.add(gtk.Label("Select a note:"))
 
119
        dialog.add(gtk.Label(_("Select a note:")))
116
120
 
117
121
        for note in self.__interface.GetAllNotesWithTag(applet_system_notebook + tag):
118
122
            if applet_system_template not in self.__interface.GetTagsForNote(note):
123
127
 
124
128
    def view_from_tag_dialog(self, widget):
125
129
        dialog = self.awn.dialog.new("view_from_tag_select")
126
 
        dialog.add(gtk.Label("Select a tag:"))
 
130
        dialog.add(gtk.Label(_("Select a tag:")))
127
131
        for tag in self.collect_tags():
128
132
            button = gtk.Button(tag)
129
133
            button.connect("clicked", self.view_from_tag, tag)
131
135
        dialog.show_all()
132
136
 
133
137
    def main_dialog(self):
134
 
        dialog = self.awn.dialog.new("main")
 
138
        if self.__dialog is not None:
 
139
            self.awn.dialog.unregister("main")
 
140
            self.__dialog = None
 
141
 
 
142
        self.__dialog = dialog = self.awn.dialog.new("main")
135
143
 
136
144
        for note in self.list_all_notes()[:10]:
137
145
            self.button = gtk.Button(self.__interface.GetNoteTitle(note))
138
146
            self.button.connect("clicked", self.button_display, note)
139
147
            dialog.add(self.button)
140
148
 
141
 
        dialog.add(gtk.Label("Version : " + self.__version))
 
149
        dialog.add(gtk.Label(_("Version: %s") % self.__version))
142
150
 
143
 
        button1 = gtk.Button("Search")
 
151
        button1 = gtk.Button(_("Search"))
144
152
        button1.connect("clicked", self.display_search)
145
153
        dialog.add(button1)
146
154
 
147
 
        button2 = gtk.Button("New Note")
 
155
        button2 = gtk.Button(_("New Note"))
148
156
        button2.connect("clicked", self.create_note)
149
157
        dialog.add(button2)
150
158
 
151
 
        button3 = gtk.Button("New Tagged Note")
 
159
        button3 = gtk.Button(_("New Tagged Note"))
152
160
        button3.connect("clicked", self.create_from_tag_dialog)
153
161
        dialog.add(button3)
154
162
 
155
 
        button4 = gtk.Button("View Tagged Note")
 
163
        button4 = gtk.Button(_("View Tagged Note"))
156
164
        button4.connect("clicked", self.view_from_tag_dialog)
157
165
        dialog.add(button4)
158
166
 
161
169
    awnlib.init_start(TomboyApplet, {"name": applet_name, "short": "tomboy",
162
170
        "version": __version__,
163
171
        "description": applet_description,
164
 
        "logo": applet_logo,
 
172
        "theme": applet_logo,
165
173
        "author": "Julien Lavergne",
166
174
        "copyright-year": "2008 - 2009",
167
175
        "authors": ["Julien Lavergne <julien.lavergne@gmail.com>",