12
14
# along with this program; if not, write to the Free Software
13
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
"""GTK+ frontends to Bazaar commands """
17
"""Graphical support for Bazaar using GTK.
20
commit-notify Start the graphical notifier of commits.
21
gannotate GTK+ annotate.
22
gbranch GTK+ branching.
23
gcheckout GTK+ checkout.
24
gcommit GTK+ commit dialog
26
gdiff Show differences in working tree in a GTK+ Window.
27
ginit Initialise a new branch.
28
gmissing GTK+ missing revisions dialog.
29
gpreferences GTK+ preferences dialog.
31
gstatus GTK+ status dialog
32
gtags Manage branch tags.
33
visualise Graphically visualise this branch.
19
__version__ = '0.16.0'
38
__version__ = '0.18.0'
20
39
version_info = tuple(int(n) for n in __version__.split('.'))
38
58
# get the message out any way we can
39
59
from warnings import warn as warning
40
60
if bzrlib_version < desired:
61
from bzrlib.errors import BzrError
41
62
warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
63
' %s.' % (bzrlib.__version__, __version__))
43
# Not using BzrNewError, because it may not exist.
44
raise Exception, ('Version mismatch', version_info)
64
raise BzrError('Version mismatch: %r' % version_info)
46
66
warning('bzr-gtk is not up to date with installed bzr version %s.'
47
67
' \nThere should be a newer version available, e.g. %i.%i.'
48
68
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
if bzrlib_version != desired_plus:
50
raise Exception, 'Version mismatch'
53
71
check_bzrlib_version(version_info[:2])
87
105
bzrlib.ui.ui_factory = GtkUIFactory()
90
class cmd_gbranch(Command):
108
class GTKCommand(Command):
109
"""Abstract class providing GTK specific run commands."""
111
def open_display(self):
112
pygtk = import_pygtk()
115
except RuntimeError, e:
116
if str(e) == "could not open display":
123
dialog = self.get_gtk_dialog(os.path.abspath('.'))
127
class cmd_gbranch(GTKCommand):
91
128
"""GTK+ branching.
96
pygtk = import_pygtk()
99
except RuntimeError, e:
100
if str(e) == "could not open display":
132
def get_gtk_dialog(self, path):
103
133
from bzrlib.plugins.gtk.branch import BranchDialog
106
dialog = BranchDialog(os.path.abspath('.'))
109
class cmd_gcheckout(Command):
134
return BranchDialog(path)
137
class cmd_gcheckout(GTKCommand):
110
138
""" GTK+ checkout.
115
pygtk = import_pygtk()
118
except RuntimeError, e:
119
if str(e) == "could not open display":
142
def get_gtk_dialog(self, path):
122
143
from bzrlib.plugins.gtk.checkout import CheckoutDialog
125
dialog = CheckoutDialog(os.path.abspath('.'))
129
class cmd_gpush(Command):
144
return CheckoutDialog(path)
148
class cmd_gpush(GTKCommand):
135
154
def run(self, location="."):
136
155
(br, path) = branch.Branch.open_containing(location)
138
pygtk = import_pygtk()
141
except RuntimeError, e:
142
if str(e) == "could not open display":
145
157
from push import PushDialog
148
158
dialog = PushDialog(br)
152
class cmd_gdiff(Command):
163
class cmd_gdiff(GTKCommand):
153
164
"""Show differences in working tree in a GTK+ Window.
155
166
Otherwise, all changes for the tree are listed.
214
def start_viz_window(branch, revision, limit=None):
215
"""Start viz on branch with revision revision.
217
:return: The viz window object.
219
from viz.branchwin import BranchWindow
222
pp.set_branch(branch, revision, limit)
223
# cleanup locks when the window is closed
224
pp.connect("destroy", lambda w: branch.unlock())
203
228
class cmd_visualise(Command):
204
229
"""Graphically visualise this branch.
230
254
(revno, revid) = revision[0].in_history(br)
232
from viz.branchwin import BranchWindow
236
pp.set_branch(br, revid, limit)
257
pp = start_viz_window(br, revid, limit)
237
258
pp.connect("destroy", lambda w: gtk.main_quit())
241
br.repository.unlock()
245
class cmd_gannotate(Command):
265
class cmd_gannotate(GTKCommand):
246
266
"""GTK+ annotate.
248
268
Browse changes to FILENAME line by line in a GTK+ window.
251
271
takes_args = ["filename", "line?"]
252
272
takes_options = [
253
Option("all", help="show annotations on all lines"),
254
Option("plain", help="don't highlight annotation lines"),
273
Option("all", help="Show annotations on all lines."),
274
Option("plain", help="Don't highlight annotation lines."),
255
275
Option("line", type=int, argname="lineno",
256
help="jump to specified line number"),
276
help="Jump to specified line number."),
259
279
aliases = ["gblame", "gpraise"]
261
281
def run(self, filename, all=False, plain=False, line='1', revision=None):
262
pygtk = import_pygtk()
266
except RuntimeError, e:
267
if str(e) == "could not open display":
282
gtk = self.open_display()
345
351
(wt, path) = workingtree.WorkingTree.open_containing(filename)
347
except NotBranchError, e:
349
353
except NoWorkingTree, e:
352
(br, path) = branch.Branch.open_containing(path)
353
except NotBranchError, e:
355
(br, path) = branch.Branch.open_containing(path)
356
357
commit = CommitDialog(wt, path, not br)
360
class cmd_gstatus(Command):
362
class cmd_gstatus(GTKCommand):
361
363
"""GTK+ status dialog
363
365
Graphical user interface for showing status
388
class cmd_gconflicts(Command):
383
class cmd_gconflicts(GTKCommand):
393
388
(wt, path) = workingtree.WorkingTree.open_containing('.')
395
pygtk = import_pygtk()
398
except RuntimeError, e:
399
if str(e) == "could not open display":
402
390
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
405
391
dialog = ConflictsDialog(wt)
409
class cmd_gpreferences(Command):
396
class cmd_gpreferences(GTKCommand):
410
397
""" GTK+ preferences dialog.
414
pygtk = import_pygtk()
417
except RuntimeError, e:
418
if str(e) == "could not open display":
421
402
from bzrlib.plugins.gtk.preferences import PreferencesWindow
424
403
dialog = PreferencesWindow()
479
479
for cmd in commands:
480
480
register_command(cmd)
483
class cmd_commit_notify(GTKCommand):
484
"""Run the bzr commit notifier.
486
This is a background program which will pop up a notification on the users
487
screen when a commit occurs.
491
from notify import NotifyPopupMenu
492
gtk = self.open_display()
493
menu = NotifyPopupMenu()
494
icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
495
icon.connect('popup-menu', menu.display)
501
from bzrlib.bzrdir import BzrDir
502
from bzrlib import errors
503
from bzrlib.osutils import format_date
504
from bzrlib.transport import get_transport
505
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
507
from bzrlib.plugins.dbus import activity
508
bus = dbus.SessionBus()
509
# get the object so we can subscribe to callbacks from it.
510
broadcast_service = bus.get_object(
511
activity.Broadcast.DBUS_NAME,
512
activity.Broadcast.DBUS_PATH)
514
def catch_branch(revision_id, urls):
515
# TODO: show all the urls, or perhaps choose the 'best'.
518
if isinstance(revision_id, unicode):
519
revision_id = revision_id.encode('utf8')
520
transport = get_transport(url)
521
a_dir = BzrDir.open_from_transport(transport)
522
branch = a_dir.open_branch()
523
revno = branch.revision_id_to_revno(revision_id)
524
revision = branch.repository.get_revision(revision_id)
525
summary = 'New revision %d in %s' % (revno, url)
526
body = 'Committer: %s\n' % revision.committer
527
body += 'Date: %s\n' % format_date(revision.timestamp,
530
body += revision.message
531
body = cgi.escape(body)
532
nw = pynotify.Notification(summary, body)
533
def start_viz(notification=None, action=None, data=None):
534
"""Start the viz program."""
535
pp = start_viz_window(branch, revision_id)
537
def start_branch(notification=None, action=None, data=None):
538
"""Start a Branch dialog"""
539
from bzrlib.plugins.gtk.branch import BranchDialog
540
bd = BranchDialog(remote_path=url)
542
nw.add_action("inspect", "Inspect", start_viz, None)
543
nw.add_action("branch", "Branch", start_branch, None)
549
broadcast_service.connect_to_signal("Revision", catch_branch,
550
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
551
pynotify.init("bzr commit-notify")
554
register_command(cmd_commit_notify)
483
558
gettext.install('olive-gtk')
485
561
class NoDisplayError(BzrCommandError):
486
562
"""gtk could not find a proper display"""
488
564
def __str__(self):
489
565
return "No DISPLAY. Unable to run GTK+ application."
491
568
def test_suite():
492
569
from unittest import TestSuite