bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
699.2.7
by Andrew Starr-Bochicchio
Fix accidental shebang change in bzr-notify. |
1 |
#!/usr/bin/env python
|
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
2 |
|
3 |
"""Run the bzr tray icon.
|
|
4 |
||
5 |
This is a background program which will pop up a notification on the users
|
|
6 |
screen when a commit occurs.
|
|
7 |
"""
|
|
8 |
||
9 |
from bzrlib.plugin import load_plugins |
|
10 |
load_plugins() |
|
11 |
||
722
by Jelmer Vernooij
Fix imports. |
12 |
from bzrlib.plugins.gtk.commands import open_display |
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
13 |
|
553.1.1
by Jelmer Vernooij
Fix notify import. |
14 |
from bzrlib.plugins.gtk.notify import NotifyPopupMenu |
734.1.2
by Curtis Hovey
Removed import_pygtk because gi does not impicitly call Main(). Inlined checks for gtk availablility. |
15 |
Gtk = open_display() |
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
16 |
|
17 |
import cgi |
|
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
18 |
import sys |
19 |
||
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
20 |
import dbus |
21 |
import dbus.service |
|
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
22 |
from gi.repository import GObject |
23 |
from gi.repository import Notify |
|
24 |
||
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
25 |
from bzrlib.bzrdir import BzrDir |
26 |
from bzrlib.osutils import format_date |
|
27 |
from bzrlib.transport import get_transport |
|
674.1.1
by Sense Hofstede
* Use Indicator Application rather than GtkStatusIcon |
28 |
|
29 |
menu = NotifyPopupMenu() |
|
682
by Jelmer Vernooij
Merge qense's indicator application work, but don't require appindicator to be installed. |
30 |
try: |
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
31 |
from gi.repository import AppIndicator3 |
682
by Jelmer Vernooij
Merge qense's indicator application work, but don't require appindicator to be installed. |
32 |
except ImportError: |
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
33 |
icon = Gtk.StatusIcon.new_from_icon_name("bzr-panel") |
683.1.1
by Jelmer Vernooij
Fix formatting. |
34 |
icon.connect('popup-menu', menu.display) |
35 |
icon.set_visible(False) |
|
36 |
hide_icon = lambda: icon.set_visible(False) |
|
37 |
show_icon = lambda: icon.set_visible(True) |
|
682
by Jelmer Vernooij
Merge qense's indicator application work, but don't require appindicator to be installed. |
38 |
else: |
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
39 |
indicator = AppIndicator3.Indicator.new( |
40 |
"bzr-gtk-notify", "bzr-panel", AppIndicator3.IndicatorCategory.OTHER) |
|
41 |
indicator.set_status (AppIndicator3.IndicatorStatus.PASSIVE) |
|
699.2.2
by Andrew Starr-Bochicchio
Use panel icon. |
42 |
indicator.set_attention_icon("bzr-panel") |
683.1.1
by Jelmer Vernooij
Fix formatting. |
43 |
indicator.set_menu(menu) |
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
44 |
hide_icon = lambda: indicator.set_status ( |
45 |
AppIndicator3.IndicatorStatus.PASSIVE) |
|
46 |
show_icon = lambda: indicator.set_status ( |
|
47 |
AppIndicator3.IndicatorStatus.ATTENTION) |
|
674.1.1
by Sense Hofstede
* Use Indicator Application rather than GtkStatusIcon |
48 |
|
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
49 |
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): |
683.1.1
by Jelmer Vernooij
Fix formatting. |
50 |
import dbus.glib |
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
51 |
BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast" |
52 |
bus = dbus.SessionBus() |
|
53 |
||
54 |
def catch_branch(revision_id, urls): |
|
683.1.1
by Jelmer Vernooij
Fix formatting. |
55 |
# TODO: show all the urls, or perhaps choose the 'best'.
|
56 |
url = urls[0] |
|
57 |
try: |
|
58 |
if isinstance(revision_id, unicode): |
|
59 |
revision_id = revision_id.encode('utf8') |
|
60 |
transport = get_transport(url) |
|
61 |
a_dir = BzrDir.open_from_transport(transport) |
|
62 |
branch = a_dir.open_branch() |
|
63 |
revno = branch.revision_id_to_revno(revision_id) |
|
64 |
revision = branch.repository.get_revision(revision_id) |
|
65 |
summary = 'New revision %d in %s' % (revno, url) |
|
66 |
body = 'Committer: %s\n' % revision.committer |
|
67 |
body += 'Date: %s\n' % format_date(revision.timestamp, |
|
68 |
revision.timezone) |
|
69 |
body += '\n' |
|
70 |
body += revision.message |
|
71 |
body = cgi.escape(body) |
|
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
72 |
nw = Notify.Notification.new(summary, body, None) |
683.1.1
by Jelmer Vernooij
Fix formatting. |
73 |
def start_viz(notification=None, action=None, data=None): |
74 |
"""Start the viz program.""" |
|
75 |
from bzrlib.plugins.gtk.commands import start_viz_window |
|
76 |
pp = start_viz_window(branch, revision_id) |
|
77 |
pp.show() |
|
78 |
def start_branch(notification=None, action=None, data=None): |
|
79 |
"""Start a Branch dialog""" |
|
80 |
from bzrlib.plugins.gtk.branch import BranchDialog |
|
81 |
bd = BranchDialog(remote_path=url) |
|
82 |
bd.run() |
|
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
83 |
if "actions" in Notify.get_server_caps(): |
683.1.1
by Jelmer Vernooij
Fix formatting. |
84 |
nw.add_action("inspect", "Inspect", start_viz, None) |
85 |
nw.add_action("branch", "Branch", start_branch, None) |
|
86 |
show_icon() |
|
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
87 |
GObject.timeout_add(5000, hide_icon) |
683.1.1
by Jelmer Vernooij
Fix formatting. |
88 |
nw.set_timeout(5000) |
89 |
nw.show() |
|
90 |
except Exception, e: |
|
91 |
print e |
|
92 |
raise
|
|
505.1.3
by Jelmer Vernooij
Move notify icon to a separate script so it's easier to add to startup scripts. |
93 |
bus.add_signal_receiver(catch_branch, |
683.1.1
by Jelmer Vernooij
Fix formatting. |
94 |
dbus_interface=BROADCAST_INTERFACE, |
95 |
signal_name="Revision") |
|
772.1.3
by Curtis Hovey
Updated bzr-notify to gtk3. |
96 |
Notify.init("bzr-notify") |
97 |
||
98 |
if sys.argv[-1] == 'test': |
|
99 |
# Exit before main loop.
|
|
100 |
sys.exit(0) |
|
101 |
||
102 |
Gtk.main() |