100
85
def set_ui_factory():
86
pygtk = import_pygtk()
102
87
from ui import GtkUIFactory
104
89
bzrlib.ui.ui_factory = GtkUIFactory()
108
return os.path.dirname(__file__)
111
class GTKCommand(Command):
112
"""Abstract class providing GTK specific run commands."""
114
def open_display(self):
115
pygtk = import_pygtk()
118
except RuntimeError, e:
119
if str(e) == "could not open display":
126
dialog = self.get_gtk_dialog(os.path.abspath('.'))
130
class cmd_gbranch(GTKCommand):
92
class cmd_gbranch(Command):
131
93
"""GTK+ branching.
135
def get_gtk_dialog(self, path):
98
pygtk = import_pygtk()
101
except RuntimeError, e:
102
if str(e) == "could not open display":
136
105
from bzrlib.plugins.gtk.branch import BranchDialog
137
return BranchDialog(path)
140
class cmd_gcheckout(GTKCommand):
108
dialog = BranchDialog(os.path.abspath('.'))
111
register_command(cmd_gbranch)
113
class cmd_gcheckout(Command):
141
114
""" GTK+ checkout.
145
def get_gtk_dialog(self, path):
119
pygtk = import_pygtk()
122
except RuntimeError, e:
123
if str(e) == "could not open display":
146
126
from bzrlib.plugins.gtk.checkout import CheckoutDialog
147
return CheckoutDialog(path)
151
class cmd_gpush(GTKCommand):
129
dialog = CheckoutDialog(os.path.abspath('.'))
132
register_command(cmd_gcheckout)
134
class cmd_gpush(Command):
274
260
takes_args = ["filename", "line?"]
275
261
takes_options = [
276
Option("all", help="Show annotations on all lines."),
277
Option("plain", help="Don't highlight annotation lines."),
262
Option("all", help="show annotations on all lines"),
263
Option("plain", help="don't highlight annotation lines"),
278
264
Option("line", type=int, argname="lineno",
279
help="Jump to specified line number."),
265
help="jump to specified line number"),
282
268
aliases = ["gblame", "gpraise"]
284
270
def run(self, filename, all=False, plain=False, line='1', revision=None):
285
gtk = self.open_display()
271
pygtk = import_pygtk()
275
except RuntimeError, e:
276
if str(e) == "could not open display":
375
385
def run(self, path='.'):
377
gtk = self.open_display()
387
pygtk = import_pygtk()
391
except RuntimeError, e:
392
if str(e) == "could not open display":
378
396
from status import StatusDialog
379
397
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
380
398
status = StatusDialog(wt, wt_path)
381
399
status.connect("destroy", gtk.main_quit)
386
class cmd_gconflicts(GTKCommand):
402
register_command(cmd_gstatus)
404
class cmd_gconflicts(Command):
391
409
(wt, path) = workingtree.WorkingTree.open_containing('.')
411
pygtk = import_pygtk()
414
except RuntimeError, e:
415
if str(e) == "could not open display":
393
418
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
394
421
dialog = ConflictsDialog(wt)
399
class cmd_gpreferences(GTKCommand):
400
""" GTK+ preferences dialog.
405
from bzrlib.plugins.gtk.preferences import PreferencesWindow
406
dialog = PreferencesWindow()
411
class cmd_gmissing(Command):
412
""" GTK+ missing revisions dialog.
415
takes_args = ["other_branch?"]
416
def run(self, other_branch=None):
417
pygtk = import_pygtk()
420
except RuntimeError, e:
421
if str(e) == "could not open display":
424
from bzrlib.plugins.gtk.missing import MissingWindow
425
from bzrlib.branch import Branch
427
local_branch = Branch.open_containing(".")[0]
428
if other_branch is None:
429
other_branch = local_branch.get_parent()
431
if other_branch is None:
432
raise errors.BzrCommandError("No peer location known or specified.")
433
remote_branch = Branch.open_containing(other_branch)[0]
435
local_branch.lock_read()
437
remote_branch.lock_read()
439
dialog = MissingWindow(local_branch, remote_branch)
442
remote_branch.unlock()
444
local_branch.unlock()
447
class cmd_ginit(GTKCommand):
450
from initialize import InitDialog
451
dialog = InitDialog(os.path.abspath(os.path.curdir))
455
class cmd_gtags(GTKCommand):
457
br = branch.Branch.open_containing('.')[0]
459
gtk = self.open_display()
460
from tags import TagsWindow
461
window = TagsWindow(br)
483
register_command(cmd)
486
class cmd_commit_notify(GTKCommand):
487
"""Run the bzr commit notifier.
489
This is a background program which will pop up a notification on the users
490
screen when a commit occurs.
494
from notify import NotifyPopupMenu
495
gtk = self.open_display()
496
menu = NotifyPopupMenu()
497
icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
498
icon.connect('popup-menu', menu.display)
504
from bzrlib.bzrdir import BzrDir
505
from bzrlib import errors
506
from bzrlib.osutils import format_date
507
from bzrlib.transport import get_transport
508
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
510
from bzrlib.plugins.dbus import activity
511
bus = dbus.SessionBus()
512
# get the object so we can subscribe to callbacks from it.
513
broadcast_service = bus.get_object(
514
activity.Broadcast.DBUS_NAME,
515
activity.Broadcast.DBUS_PATH)
517
def catch_branch(revision_id, urls):
518
# TODO: show all the urls, or perhaps choose the 'best'.
521
if isinstance(revision_id, unicode):
522
revision_id = revision_id.encode('utf8')
523
transport = get_transport(url)
524
a_dir = BzrDir.open_from_transport(transport)
525
branch = a_dir.open_branch()
526
revno = branch.revision_id_to_revno(revision_id)
527
revision = branch.repository.get_revision(revision_id)
528
summary = 'New revision %d in %s' % (revno, url)
529
body = 'Committer: %s\n' % revision.committer
530
body += 'Date: %s\n' % format_date(revision.timestamp,
533
body += revision.message
534
body = cgi.escape(body)
535
nw = pynotify.Notification(summary, body)
536
def start_viz(notification=None, action=None, data=None):
537
"""Start the viz program."""
538
pp = start_viz_window(branch, revision_id)
540
def start_branch(notification=None, action=None, data=None):
541
"""Start a Branch dialog"""
542
from bzrlib.plugins.gtk.branch import BranchDialog
543
bd = BranchDialog(remote_path=url)
545
nw.add_action("inspect", "Inspect", start_viz, None)
546
nw.add_action("branch", "Branch", start_branch, None)
552
broadcast_service.connect_to_signal("Revision", catch_branch,
553
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
554
pynotify.init("bzr commit-notify")
557
register_command(cmd_commit_notify)
560
class cmd_gselftest(GTKCommand):
561
"""Version of selftest that displays a notification at the end"""
563
takes_args = builtins.cmd_selftest.takes_args
564
takes_options = builtins.cmd_selftest.takes_options
565
_see_also = ['selftest']
567
def run(self, *args, **kwargs):
569
# prevent gtk from blowing up later
572
result = builtins.cmd_selftest().run(*args, **kwargs)
575
body = 'Selftest succeeded in "%s"' % os.getcwd()
578
body = 'Selftest failed in "%s"' % os.getcwd()
579
pynotify.init("bzr gselftest")
580
note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
581
note.set_timeout(pynotify.EXPIRES_NEVER)
585
register_command(cmd_gselftest)
424
register_command(cmd_gconflicts)
589
427
gettext.install('olive-gtk')
592
429
class NoDisplayError(BzrCommandError):
593
430
"""gtk could not find a proper display"""
595
432
def __str__(self):
596
433
return "No DISPLAY. Unable to run GTK+ application."
599
435
def test_suite():
600
436
from unittest import TestSuite