85
100
def set_ui_factory():
86
pygtk = import_pygtk()
87
102
from ui import GtkUIFactory
89
104
bzrlib.ui.ui_factory = GtkUIFactory()
92
class cmd_gbranch(Command):
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):
93
131
"""GTK+ branching.
98
pygtk = import_pygtk()
101
except RuntimeError, e:
102
if str(e) == "could not open display":
135
def get_gtk_dialog(self, path):
105
136
from bzrlib.plugins.gtk.branch import BranchDialog
108
dialog = BranchDialog(os.path.abspath('.'))
111
register_command(cmd_gbranch)
113
class cmd_gcheckout(Command):
137
return BranchDialog(path)
140
class cmd_gcheckout(GTKCommand):
114
141
""" GTK+ checkout.
119
pygtk = import_pygtk()
122
except RuntimeError, e:
123
if str(e) == "could not open display":
145
def get_gtk_dialog(self, path):
126
146
from bzrlib.plugins.gtk.checkout import CheckoutDialog
129
dialog = CheckoutDialog(os.path.abspath('.'))
132
register_command(cmd_gcheckout)
134
class cmd_gpush(Command):
147
return CheckoutDialog(path)
151
class cmd_gpush(GTKCommand):
385
375
def run(self, path='.'):
387
pygtk = import_pygtk()
391
except RuntimeError, e:
392
if str(e) == "could not open display":
377
gtk = self.open_display()
396
378
from status import StatusDialog
397
379
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
398
380
status = StatusDialog(wt, wt_path)
399
381
status.connect("destroy", gtk.main_quit)
402
register_command(cmd_gstatus)
404
class cmd_gconflicts(Command):
386
class cmd_gconflicts(GTKCommand):
389
Select files from the list of conflicts and run an external utility to
409
393
(wt, path) = workingtree.WorkingTree.open_containing('.')
411
pygtk = import_pygtk()
414
except RuntimeError, e:
415
if str(e) == "could not open display":
418
395
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
421
396
dialog = ConflictsDialog(wt)
424
register_command(cmd_gconflicts)
401
class cmd_gpreferences(GTKCommand):
402
""" GTK+ preferences dialog.
407
from bzrlib.plugins.gtk.preferences import PreferencesWindow
408
dialog = PreferencesWindow()
413
class cmd_gmissing(Command):
414
""" GTK+ missing revisions dialog.
417
takes_args = ["other_branch?"]
418
def run(self, other_branch=None):
419
pygtk = import_pygtk()
422
except RuntimeError, e:
423
if str(e) == "could not open display":
426
from bzrlib.plugins.gtk.missing import MissingWindow
427
from bzrlib.branch import Branch
429
local_branch = Branch.open_containing(".")[0]
430
if other_branch is None:
431
other_branch = local_branch.get_parent()
433
if other_branch is None:
434
raise errors.BzrCommandError("No peer location known or specified.")
435
remote_branch = Branch.open_containing(other_branch)[0]
437
local_branch.lock_read()
439
remote_branch.lock_read()
441
dialog = MissingWindow(local_branch, remote_branch)
444
remote_branch.unlock()
446
local_branch.unlock()
449
class cmd_ginit(GTKCommand):
452
from initialize import InitDialog
453
dialog = InitDialog(os.path.abspath(os.path.curdir))
457
class cmd_gtags(GTKCommand):
459
br = branch.Branch.open_containing('.')[0]
461
gtk = self.open_display()
462
from tags import TagsWindow
463
window = TagsWindow(br)
485
register_command(cmd)
488
class cmd_commit_notify(GTKCommand):
489
"""Run the bzr commit notifier.
491
This is a background program which will pop up a notification on the users
492
screen when a commit occurs.
496
from notify import NotifyPopupMenu
497
gtk = self.open_display()
498
menu = NotifyPopupMenu()
499
icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
500
icon.connect('popup-menu', menu.display)
506
from bzrlib.bzrdir import BzrDir
507
from bzrlib import errors
508
from bzrlib.osutils import format_date
509
from bzrlib.transport import get_transport
510
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
512
from bzrlib.plugins.dbus import activity
513
bus = dbus.SessionBus()
514
# get the object so we can subscribe to callbacks from it.
515
broadcast_service = bus.get_object(
516
activity.Broadcast.DBUS_NAME,
517
activity.Broadcast.DBUS_PATH)
519
def catch_branch(revision_id, urls):
520
# TODO: show all the urls, or perhaps choose the 'best'.
523
if isinstance(revision_id, unicode):
524
revision_id = revision_id.encode('utf8')
525
transport = get_transport(url)
526
a_dir = BzrDir.open_from_transport(transport)
527
branch = a_dir.open_branch()
528
revno = branch.revision_id_to_revno(revision_id)
529
revision = branch.repository.get_revision(revision_id)
530
summary = 'New revision %d in %s' % (revno, url)
531
body = 'Committer: %s\n' % revision.committer
532
body += 'Date: %s\n' % format_date(revision.timestamp,
535
body += revision.message
536
body = cgi.escape(body)
537
nw = pynotify.Notification(summary, body)
538
def start_viz(notification=None, action=None, data=None):
539
"""Start the viz program."""
540
pp = start_viz_window(branch, revision_id)
542
def start_branch(notification=None, action=None, data=None):
543
"""Start a Branch dialog"""
544
from bzrlib.plugins.gtk.branch import BranchDialog
545
bd = BranchDialog(remote_path=url)
547
nw.add_action("inspect", "Inspect", start_viz, None)
548
nw.add_action("branch", "Branch", start_branch, None)
554
broadcast_service.connect_to_signal("Revision", catch_branch,
555
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
556
pynotify.init("bzr commit-notify")
559
register_command(cmd_commit_notify)
562
class cmd_gselftest(GTKCommand):
563
"""Version of selftest that displays a notification at the end"""
565
takes_args = builtins.cmd_selftest.takes_args
566
takes_options = builtins.cmd_selftest.takes_options
567
_see_also = ['selftest']
569
def run(self, *args, **kwargs):
572
default_encoding = sys.getdefaultencoding()
573
# prevent gtk from blowing up later
575
# prevent gtk from messing with default encoding
577
if sys.getdefaultencoding() != default_encoding:
579
sys.setdefaultencoding(default_encoding)
580
result = builtins.cmd_selftest().run(*args, **kwargs)
583
body = 'Selftest succeeded in "%s"' % os.getcwd()
586
body = 'Selftest failed in "%s"' % os.getcwd()
587
pynotify.init("bzr gselftest")
588
note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
589
note.set_timeout(pynotify.EXPIRES_NEVER)
593
register_command(cmd_gselftest)
427
597
gettext.install('olive-gtk')
429
600
class NoDisplayError(BzrCommandError):
430
601
"""gtk could not find a proper display"""
432
603
def __str__(self):
433
604
return "No DISPLAY. Unable to run GTK+ application."
435
607
def test_suite():
436
608
from unittest import TestSuite