87
87
bzrlib.ui.ui_factory = GtkUIFactory()
90
class cmd_gbranch(Command):
90
class GTKCommand(Command):
91
"""Abstract class providing GTK specific run commands."""
93
def open_display(self):
94
pygtk = import_pygtk()
97
except RuntimeError, e:
98
if str(e) == "could not open display":
105
dialog = self.get_gtk_dialog(os.path.abspath('.'))
109
class cmd_gbranch(GTKCommand):
91
110
"""GTK+ branching.
96
pygtk = import_pygtk()
99
except RuntimeError, e:
100
if str(e) == "could not open display":
114
def get_gtk_dialog(self, path):
103
115
from bzrlib.plugins.gtk.branch import BranchDialog
106
dialog = BranchDialog(os.path.abspath('.'))
109
class cmd_gcheckout(Command):
116
return BranchDialog(path)
119
class cmd_gcheckout(GTKCommand):
110
120
""" GTK+ checkout.
115
pygtk = import_pygtk()
118
except RuntimeError, e:
119
if str(e) == "could not open display":
124
def get_gtk_dialog(self, path):
122
125
from bzrlib.plugins.gtk.checkout import CheckoutDialog
125
dialog = CheckoutDialog(os.path.abspath('.'))
129
class cmd_gpush(Command):
126
return CheckoutDialog(path)
130
class cmd_gpush(GTKCommand):
135
136
def run(self, location="."):
136
137
(br, path) = branch.Branch.open_containing(location)
138
pygtk = import_pygtk()
141
except RuntimeError, e:
142
if str(e) == "could not open display":
145
139
from push import PushDialog
148
140
dialog = PushDialog(br)
152
class cmd_gdiff(Command):
145
class cmd_gdiff(GTKCommand):
153
146
"""Show differences in working tree in a GTK+ Window.
155
148
Otherwise, all changes for the tree are listed.
388
class cmd_gconflicts(Command):
361
class cmd_gconflicts(GTKCommand):
393
366
(wt, path) = workingtree.WorkingTree.open_containing('.')
395
pygtk = import_pygtk()
398
except RuntimeError, e:
399
if str(e) == "could not open display":
402
368
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
405
369
dialog = ConflictsDialog(wt)
409
class cmd_gpreferences(Command):
374
class cmd_gpreferences(GTKCommand):
410
375
""" GTK+ preferences dialog.
414
pygtk = import_pygtk()
417
except RuntimeError, e:
418
if str(e) == "could not open display":
421
380
from bzrlib.plugins.gtk.preferences import PreferencesWindow
424
381
dialog = PreferencesWindow()
479
436
for cmd in commands:
480
437
register_command(cmd)
440
class cmd_commit_notify(GTKCommand):
441
"""Run the bzr commit notifier.
443
This is a background program which will pop up a notification on the users
444
screen when a commit occurs.
448
gtk = self.open_display()
453
from bzrlib.bzrdir import BzrDir
454
from bzrlib import errors
455
from bzrlib.osutils import format_date
456
from bzrlib.transport import get_transport
457
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
459
from bzrlib.plugins.dbus import activity
460
bus = dbus.SessionBus()
461
# get the object so we can subscribe to callbacks from it.
462
broadcast_service = bus.get_object(
463
activity.Broadcast.DBUS_NAME,
464
activity.Broadcast.DBUS_PATH)
465
def catch_branch(revision_id, url):
467
if isinstance(revision_id, unicode):
468
revision_id = revision_id.encode('utf8')
469
transport = get_transport(url)
471
transport.local_abspath('.')
472
except errors.TransportNotPossible:
473
# dont show remote urls for now.
476
a_dir = BzrDir.open_from_transport(transport)
477
branch = a_dir.open_branch()
478
revno = branch.revision_id_to_revno(revision_id)
479
revision = branch.repository.get_revision(revision_id)
480
summary = 'New revision %d in %s' % (revno, url)
481
body = 'Committer: %s\n' % revision.committer
482
body += 'Date: %s\n' % format_date(revision.timestamp,
485
body += revision.message
486
body = cgi.escape(body)
488
nw = pynotify.Notification(summary, body)
494
broadcast_service.connect_to_signal("Revision", catch_branch,
495
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
496
pynotify.init("bzr commit-notify")
499
register_command(cmd_commit_notify)
483
503
gettext.install('olive-gtk')
485
506
class NoDisplayError(BzrCommandError):
486
507
"""gtk could not find a proper display"""
488
509
def __str__(self):
489
510
return "No DISPLAY. Unable to run GTK+ application."
491
513
def test_suite():
492
514
from unittest import TestSuite