bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
211
by Jelmer Vernooij
Move notification area code into separate file. |
1 |
# Copyright (C) 2007 by Robert Collins
|
2 |
# Jelmer Vernooij
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
||
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
||
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
"""Notification area icon and notification for Bazaar."""
|
|
18 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
19 |
from gi.repository import Gtk |
619.1.1
by Vincent Ladeuil
Fix bug #290618 by using the right facilities. |
20 |
import bzrlib |
21 |
||
619
by Jelmer Vernooij
Add notifications tab in preferences dialog. |
22 |
|
23 |
def has_dbus(): |
|
24 |
return (getattr(bzrlib.plugins, "dbus", None) is not None) |
|
25 |
||
619.1.1
by Vincent Ladeuil
Fix bug #290618 by using the right facilities. |
26 |
|
619
by Jelmer Vernooij
Add notifications tab in preferences dialog. |
27 |
def has_avahi(): |
28 |
return (getattr(bzrlib.plugins, "avahi", None) is not None) |
|
211
by Jelmer Vernooij
Move notification area code into separate file. |
29 |
|
619.1.1
by Vincent Ladeuil
Fix bug #290618 by using the right facilities. |
30 |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
31 |
class NotifyPopupMenu(Gtk.Menu): |
713
by Jelmer Vernooij
Remove some unused imports, fix some formatting. |
32 |
|
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
33 |
SHOW_WIDGETS = True |
34 |
||
211
by Jelmer Vernooij
Move notification area code into separate file. |
35 |
def __init__(self): |
36 |
super(NotifyPopupMenu, self).__init__() |
|
37 |
self.create_items() |
|
38 |
||
39 |
def create_items(self): |
|
683.1.2
by Jelmer Vernooij
Don't crash when there is already a lan-notify instance running. |
40 |
from bzrlib import errors |
734.1.38
by Curtis Hovey
Menu fixes. |
41 |
item = Gtk.CheckMenuItem.new_with_mnemonic('_Gateway to LAN') |
619
by Jelmer Vernooij
Add notifications tab in preferences dialog. |
42 |
item.connect('toggled', self.toggle_lan_gateway) |
43 |
self.append(item) |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
44 |
self.append(Gtk.SeparatorMenuItem()) |
211
by Jelmer Vernooij
Move notification area code into separate file. |
45 |
try: |
46 |
from bzrlib.plugins.dbus.activity import LanGateway |
|
47 |
self.langateway = LanGateway() |
|
48 |
except ImportError: |
|
619
by Jelmer Vernooij
Add notifications tab in preferences dialog. |
49 |
item.set_sensitive(False) |
683.1.2
by Jelmer Vernooij
Don't crash when there is already a lan-notify instance running. |
50 |
except errors.BzrError: |
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
51 |
# FIXME: Should only catch errors that indicate a lan-notify
|
683.1.2
by Jelmer Vernooij
Don't crash when there is already a lan-notify instance running. |
52 |
# process is already running.
|
53 |
item.set_sensitive(False) |
|
211
by Jelmer Vernooij
Move notification area code into separate file. |
54 |
|
734.1.38
by Curtis Hovey
Menu fixes. |
55 |
item = Gtk.CheckMenuItem.new_with_mnemonic( |
56 |
'Announce _branches on LAN') |
|
619
by Jelmer Vernooij
Add notifications tab in preferences dialog. |
57 |
item.connect('toggled', self.toggle_announce_branches) |
58 |
self.append(item) |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
59 |
self.append(Gtk.SeparatorMenuItem()) |
211
by Jelmer Vernooij
Move notification area code into separate file. |
60 |
try: |
61 |
from bzrlib.plugins.avahi.share import ZeroConfServer |
|
62 |
from bzrlib import urlutils |
|
63 |
self.zeroconfserver = ZeroConfServer(urlutils.normalize_url('.')) |
|
64 |
except ImportError: |
|
619
by Jelmer Vernooij
Add notifications tab in preferences dialog. |
65 |
item.set_sensitive(False) |
211
by Jelmer Vernooij
Move notification area code into separate file. |
66 |
|
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
67 |
item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_PREFERENCES, None) |
211
by Jelmer Vernooij
Move notification area code into separate file. |
68 |
item.connect('activate', self.show_preferences) |
69 |
self.append(item) |
|
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
70 |
item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_ABOUT, None) |
221
by Jelmer Vernooij
Add simple about dialog. |
71 |
item.connect('activate', self.show_about) |
72 |
self.append(item) |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
73 |
self.append(Gtk.SeparatorMenuItem()) |
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
74 |
item = Gtk.ImageMenuItem.new_from_stock(Gtk.STOCK_QUIT, None) |
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
75 |
item.connect('activate', Gtk.main_quit) |
211
by Jelmer Vernooij
Move notification area code into separate file. |
76 |
self.append(item) |
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
77 |
if self.SHOW_WIDGETS: |
78 |
self.show_all() |
|
211
by Jelmer Vernooij
Move notification area code into separate file. |
79 |
|
80 |
def display(self, icon, event_button, event_time): |
|
772.1.2
by Curtis Hovey
Verify the menu and its items are created. |
81 |
self.popup(None, None, Gtk.status_icon_position_menu, |
211
by Jelmer Vernooij
Move notification area code into separate file. |
82 |
event_button, event_time, icon) |
83 |
||
84 |
def toggle_lan_gateway(self, item): |
|
85 |
if item.get_active(): |
|
86 |
self.langateway.start() |
|
87 |
else: |
|
88 |
self.langateway.stop() |
|
89 |
||
90 |
def toggle_announce_branches(self, item): |
|
91 |
if item.get_active(): |
|
92 |
self.zeroconfserver.start() |
|
93 |
else: |
|
94 |
self.zeroconfserver.close() |
|
95 |
||
221
by Jelmer Vernooij
Add simple about dialog. |
96 |
def show_about(self, item): |
553.1.3
by Jelmer Vernooij
Use absolute imports. |
97 |
from bzrlib.plugins.gtk.about import AboutDialog |
221
by Jelmer Vernooij
Add simple about dialog. |
98 |
dialog = AboutDialog() |
99 |
dialog.run() |
|
100 |
||
211
by Jelmer Vernooij
Move notification area code into separate file. |
101 |
def show_preferences(self, item): |
553.1.3
by Jelmer Vernooij
Use absolute imports. |
102 |
from bzrlib.plugins.gtk.preferences import PreferencesWindow |
213
by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display. |
103 |
prefs = PreferencesWindow() |
104 |
prefs.run() |