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])
85
101
def set_ui_factory():
86
pygtk = import_pygtk()
87
103
from ui import GtkUIFactory
89
105
bzrlib.ui.ui_factory = GtkUIFactory()
92
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):
93
128
"""GTK+ branching.
98
pygtk = import_pygtk()
101
except RuntimeError, e:
102
if str(e) == "could not open display":
132
def get_gtk_dialog(self, path):
105
133
from bzrlib.plugins.gtk.branch import BranchDialog
108
dialog = BranchDialog(os.path.abspath('.'))
111
register_command(cmd_gbranch)
113
class cmd_gcheckout(Command):
134
return BranchDialog(path)
137
class cmd_gcheckout(GTKCommand):
114
138
""" GTK+ checkout.
119
pygtk = import_pygtk()
122
except RuntimeError, e:
123
if str(e) == "could not open display":
142
def get_gtk_dialog(self, path):
126
143
from bzrlib.plugins.gtk.checkout import CheckoutDialog
129
dialog = CheckoutDialog(os.path.abspath('.'))
132
register_command(cmd_gcheckout)
134
class cmd_gpush(Command):
144
return CheckoutDialog(path)
148
class cmd_gpush(GTKCommand):
260
271
takes_args = ["filename", "line?"]
261
272
takes_options = [
262
Option("all", help="show annotations on all lines"),
263
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."),
264
275
Option("line", type=int, argname="lineno",
265
help="jump to specified line number"),
276
help="Jump to specified line number."),
268
279
aliases = ["gblame", "gpraise"]
270
281
def run(self, filename, all=False, plain=False, line='1', revision=None):
271
pygtk = import_pygtk()
275
except RuntimeError, e:
276
if str(e) == "could not open display":
282
gtk = self.open_display()
335
340
def run(self, filename=None):
337
pygtk = import_pygtk()
341
except RuntimeError, e:
342
if str(e) == "could not open display":
346
343
from commit import CommitDialog
347
from bzrlib.commit import Commit
348
344
from bzrlib.errors import (BzrCommandError,
358
351
(wt, path) = workingtree.WorkingTree.open_containing(filename)
360
except NotBranchError, e:
362
353
except NoWorkingTree, e:
365
(br, path) = branch.Branch.open_containing(path)
366
except NotBranchError, e:
355
(br, path) = branch.Branch.open_containing(path)
370
357
commit = CommitDialog(wt, path, not br)
373
register_command(cmd_gcommit)
375
class cmd_gstatus(Command):
362
class cmd_gstatus(GTKCommand):
376
363
"""GTK+ status dialog
378
365
Graphical user interface for showing status
385
372
def run(self, path='.'):
387
pygtk = import_pygtk()
391
except RuntimeError, e:
392
if str(e) == "could not open display":
374
gtk = self.open_display()
396
375
from status import StatusDialog
397
376
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
398
377
status = StatusDialog(wt, wt_path)
399
378
status.connect("destroy", gtk.main_quit)
402
register_command(cmd_gstatus)
404
class cmd_gconflicts(Command):
383
class cmd_gconflicts(GTKCommand):
409
388
(wt, path) = workingtree.WorkingTree.open_containing('.')
411
pygtk = import_pygtk()
414
except RuntimeError, e:
415
if str(e) == "could not open display":
418
390
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
421
391
dialog = ConflictsDialog(wt)
424
register_command(cmd_gconflicts)
426
class cmd_gpreferences(Command):
396
class cmd_gpreferences(GTKCommand):
427
397
""" GTK+ preferences dialog.
431
pygtk = import_pygtk()
434
except RuntimeError, e:
435
if str(e) == "could not open display":
438
402
from bzrlib.plugins.gtk.preferences import PreferencesWindow
441
403
dialog = PreferencesWindow()
444
register_command(cmd_gpreferences)
408
class cmd_gmissing(Command):
409
""" GTK+ missing revisions dialog.
412
takes_args = ["other_branch?"]
413
def run(self, other_branch=None):
414
pygtk = import_pygtk()
417
except RuntimeError, e:
418
if str(e) == "could not open display":
421
from bzrlib.plugins.gtk.missing import MissingWindow
422
from bzrlib.branch import Branch
424
local_branch = Branch.open_containing(".")[0]
425
if other_branch is None:
426
other_branch = local_branch.get_parent()
428
if other_branch is None:
429
raise errors.BzrCommandError("No peer location known or specified.")
430
remote_branch = Branch.open_containing(other_branch)[0]
432
local_branch.lock_read()
434
remote_branch.lock_read()
436
dialog = MissingWindow(local_branch, remote_branch)
439
remote_branch.unlock()
441
local_branch.unlock()
444
class cmd_ginit(GTKCommand):
447
from initialize import InitDialog
448
dialog = InitDialog(os.path.abspath(os.path.curdir))
452
class cmd_gtags(GTKCommand):
454
br = branch.Branch.open_containing('.')[0]
456
gtk = self.open_display()
457
from tags import TagsWindow
458
window = TagsWindow(br)
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)
447
558
gettext.install('olive-gtk')
449
561
class NoDisplayError(BzrCommandError):
450
562
"""gtk could not find a proper display"""
452
564
def __str__(self):
453
565
return "No DISPLAY. Unable to run GTK+ application."
455
568
def test_suite():
456
569
from unittest import TestSuite