15
15
"""Graphical support for Bazaar using GTK.
17
17
This plugin includes:
18
commit-notify Start the graphical notifier of commits.
19
18
gannotate GTK+ annotate.
20
19
gbranch GTK+ branching.
21
20
gcheckout GTK+ checkout.
22
21
gcommit GTK+ commit dialog.
23
22
gconflicts GTK+ conflicts.
24
23
gdiff Show differences in working tree in a GTK+ Window.
25
ghandle-patch Display and optionally merge a merge directive or patch.
26
24
ginit Initialise a new branch.
25
gmerge GTK+ merge dialog
27
26
gmissing GTK+ missing revisions dialog.
28
27
gpreferences GTK+ preferences dialog.
105
104
bzrlib.ui.ui_factory = GtkUIFactory()
109
return os.path.dirname(__file__)
108
return [os.path.dirname(__file__),
109
"/usr/share/bzr-gtk",
110
"/usr/local/share/bzr-gtk"]
113
def data_path(*args):
114
for basedir in data_basedirs():
115
path = os.path.join(basedir, *args)
116
if os.path.exists(path):
121
def icon_path(*args):
122
return data_path(os.path.join('icons', *args))
126
pygtk = import_pygtk()
129
except RuntimeError, e:
130
if str(e) == "could not open display":
112
136
class GTKCommand(Command):
113
137
"""Abstract class providing GTK specific run commands."""
115
def open_display(self):
116
pygtk = import_pygtk()
119
except RuntimeError, e:
120
if str(e) == "could not open display":
127
141
dialog = self.get_gtk_dialog(os.path.abspath('.'))
182
196
if revision is not None:
183
197
if len(revision) == 1:
185
revision_id = revision[0].in_history(branch).rev_id
199
revision_id = revision[0].as_revision_id(tree1.branch)
186
200
tree2 = branch.repository.revision_tree(revision_id)
187
201
elif len(revision) == 2:
188
revision_id_0 = revision[0].in_history(branch).rev_id
202
revision_id_0 = revision[0].as_revision_id(branch)
189
203
tree2 = branch.repository.revision_tree(revision_id_0)
190
revision_id_1 = revision[1].in_history(branch).rev_id
204
revision_id_1 = revision[1].as_revision_id(branch)
191
205
tree1 = branch.repository.revision_tree(revision_id_1)
218
def start_viz_window(branch, revision, limit=None):
232
def start_viz_window(branch, revisions, limit=None):
219
233
"""Start viz on branch with revision revision.
221
235
:return: The viz window object.
223
237
from viz import BranchWindow
224
return BranchWindow(branch, revision, limit)
238
return BranchWindow(branch, revisions, limit)
227
241
class cmd_visualise(Command):
238
252
Option('limit', "Maximum number of revisions to display.",
240
takes_args = [ "location?" ]
254
takes_args = [ "locations*" ]
241
255
aliases = [ "visualize", "vis", "viz" ]
243
def run(self, location=".", revision=None, limit=None):
257
def run(self, locations_list, revision=None, limit=None):
245
(br, path) = branch.Branch.open_containing(location)
247
revid = br.last_revision()
251
(revno, revid) = revision[0].in_history(br)
259
if locations_list is None:
260
locations_list = ["."]
262
for location in locations_list:
263
(br, path) = branch.Branch.open_containing(location)
265
revids.append(br.last_revision())
267
revids.append(revision[0].as_revision_id(br))
254
pp = start_viz_window(br, revid, limit)
269
pp = start_viz_window(br, revids, limit)
255
270
pp.connect("destroy", lambda w: gtk.main_quit())
299
314
if revision is not None:
300
315
if len(revision) != 1:
301
316
raise BzrCommandError("Only 1 revion may be specified.")
302
revision_id = revision[0].in_history(br).rev_id
317
revision_id = revision[0].as_revision_id(br)
303
318
tree = br.repository.revision_tree(revision_id)
305
320
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
307
window = GAnnotateWindow(all, plain)
322
window = GAnnotateWindow(all, plain, branch=br)
308
323
window.connect("destroy", lambda w: gtk.main_quit())
309
324
config = GAnnotateConfig(window)
371
386
aliases = [ "gst" ]
372
387
takes_args = ['PATH?']
388
takes_options = ['revision']
375
def run(self, path='.'):
390
def run(self, path='.', revision=None):
377
gtk = self.open_display()
378
393
from status import StatusDialog
379
394
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
380
status = StatusDialog(wt, wt_path)
396
if revision is not None:
398
revision_id = revision[0].as_revision_id(wt.branch)
400
from bzrlib.errors import BzrError
401
raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
405
status = StatusDialog(wt, wt_path, revision_id)
381
406
status.connect("destroy", gtk.main_quit)
425
450
from bzrlib.plugins.gtk.preferences import PreferencesWindow
426
451
dialog = PreferencesWindow()
455
class cmd_gmerge(Command):
456
""" GTK+ merge dialog
459
takes_args = ["merge_from_path?"]
460
def run(self, merge_from_path=None):
461
from bzrlib import workingtree
462
from bzrlib.plugins.gtk.dialog import error_dialog
463
from bzrlib.plugins.gtk.merge import MergeDialog
465
(wt, path) = workingtree.WorkingTree.open_containing('.')
466
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
467
delta = wt.changes_from(old_tree)
468
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
469
error_dialog(_i18n('There are local changes in the branch'),
470
_i18n('Please commit or revert the changes before merging.'))
472
parent_branch_path = wt.branch.get_parent()
473
merge = MergeDialog(wt, path, parent_branch_path)
474
response = merge.run()
430
478
class cmd_gmissing(Command):
431
479
""" GTK+ missing revisions dialog.
503
552
register_command(cmd)
506
class cmd_commit_notify(GTKCommand):
507
"""Run the bzr commit notifier.
509
This is a background program which will pop up a notification on the users
510
screen when a commit occurs.
514
from notify import NotifyPopupMenu
515
gtk = self.open_display()
516
menu = NotifyPopupMenu()
517
icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
518
icon.connect('popup-menu', menu.display)
524
from bzrlib.bzrdir import BzrDir
525
from bzrlib import errors
526
from bzrlib.osutils import format_date
527
from bzrlib.transport import get_transport
528
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
530
from bzrlib.plugins.dbus import activity
531
bus = dbus.SessionBus()
532
# get the object so we can subscribe to callbacks from it.
533
broadcast_service = bus.get_object(
534
activity.Broadcast.DBUS_NAME,
535
activity.Broadcast.DBUS_PATH)
537
def catch_branch(revision_id, urls):
538
# TODO: show all the urls, or perhaps choose the 'best'.
541
if isinstance(revision_id, unicode):
542
revision_id = revision_id.encode('utf8')
543
transport = get_transport(url)
544
a_dir = BzrDir.open_from_transport(transport)
545
branch = a_dir.open_branch()
546
revno = branch.revision_id_to_revno(revision_id)
547
revision = branch.repository.get_revision(revision_id)
548
summary = 'New revision %d in %s' % (revno, url)
549
body = 'Committer: %s\n' % revision.committer
550
body += 'Date: %s\n' % format_date(revision.timestamp,
553
body += revision.message
554
body = cgi.escape(body)
555
nw = pynotify.Notification(summary, body)
556
def start_viz(notification=None, action=None, data=None):
557
"""Start the viz program."""
558
pp = start_viz_window(branch, revision_id)
560
def start_branch(notification=None, action=None, data=None):
561
"""Start a Branch dialog"""
562
from bzrlib.plugins.gtk.branch import BranchDialog
563
bd = BranchDialog(remote_path=url)
565
nw.add_action("inspect", "Inspect", start_viz, None)
566
nw.add_action("branch", "Branch", start_branch, None)
572
broadcast_service.connect_to_signal("Revision", catch_branch,
573
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
574
pynotify.init("bzr commit-notify")
577
register_command(cmd_commit_notify)
580
555
class cmd_gselftest(GTKCommand):
581
556
"""Version of selftest that displays a notification at the end"""
673
648
register_command(cmd_test_gtk)
676
class cmd_ghandle_patch(GTKCommand):
677
"""Display a patch or merge directive, possibly merging.
679
This is a helper, meant to be launched from other programs like browsers
680
or email clients. Since these programs often do not allow parameters to
681
be provided, a "handle-patch" script is included.
684
takes_args = ['path']
688
from bzrlib.plugins.gtk.diff import (DiffWindow,
689
MergeDirectiveWindow)
690
lines = open(path, 'rb').readlines()
691
lines = [l.replace('\r\n', '\n') for l in lines]
693
directive = merge_directive.MergeDirective.from_lines(lines)
694
except errors.NotAMergeDirective:
695
window = DiffWindow()
696
window.set_diff_text(path, lines)
698
window = MergeDirectiveWindow(directive, path)
699
window.set_diff_text(path, directive.patch.splitlines(True))
701
gtk = self.open_display()
702
window.connect("destroy", gtk.main_quit)
704
from dialog import error_dialog
705
error_dialog('Error', str(e))
710
register_command(cmd_ghandle_patch)
714
653
gettext.install('olive-gtk')
655
# Let's create a specialized alias to protect '_' from being erased by other
656
# uses of '_' as an anonymous variable (think pdb for one).
657
_i18n = gettext.gettext
717
659
class NoDisplayError(BzrCommandError):
718
660
"""gtk could not find a proper display"""