/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2008-07-31 01:55:07 UTC
  • mto: (580.2.1 gtk.gloom)
  • mto: This revision was merged to the branch mainline in revision 581.
  • Revision ID: jelmer@samba.org-20080731015507-tarukc7r26ud7twu
Avoid making assumptions about a branch being a loom until we've checked.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
"""Graphical support for Bazaar using GTK.
16
16
 
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. 
23
22
gconflicts        GTK+ conflicts. 
24
23
gdiff             Show differences in working tree in a GTK+ Window. 
25
24
ginit             Initialise a new branch.
 
25
gloom             GTK+ loom browse dialog
 
26
gmerge            GTK+ merge dialog
26
27
gmissing          GTK+ missing revisions dialog. 
27
28
gpreferences      GTK+ preferences dialog. 
28
29
gpush             GTK+ push.
104
105
    bzrlib.ui.ui_factory = GtkUIFactory()
105
106
 
106
107
 
107
 
def data_path():
108
 
    return os.path.dirname(__file__)
109
 
 
110
 
 
111
 
def icon_path(*args):
112
 
    basedirs = [os.path.join(data_path()),
 
108
def data_basedirs():
 
109
    return [os.path.dirname(__file__),
113
110
             "/usr/share/bzr-gtk", 
114
111
             "/usr/local/share/bzr-gtk"]
115
 
    for basedir in basedirs:
116
 
        path = os.path.join(basedir, 'icons', *args)
 
112
 
 
113
 
 
114
def data_path(*args):
 
115
    for basedir in data_basedirs():
 
116
        path = os.path.join(basedir, *args)
117
117
        if os.path.exists(path):
118
118
            return path
119
119
    return None
120
120
 
121
121
 
 
122
def icon_path(*args):
 
123
    return data_path(os.path.join('icons', *args))
 
124
 
 
125
 
122
126
def open_display():
123
127
    pygtk = import_pygtk()
124
128
    try:
169
173
    def run(self, location="."):
170
174
        (br, path) = branch.Branch.open_containing(location)
171
175
        open_display()
172
 
        from push import PushDialog
 
176
        from bzrlib.plugins.gtk.push import PushDialog
173
177
        dialog = PushDialog(br.repository, br.last_revision(), br)
174
178
        dialog.run()
175
179
 
176
180
 
 
181
class cmd_gloom(GTKCommand):
 
182
    """ GTK+ loom.
 
183
    
 
184
    """
 
185
    takes_args = [ "location?" ]
 
186
 
 
187
    def run(self, location="."):
 
188
        try:
 
189
            (tree, path) = workingtree.WorkingTree.open_containing(location)
 
190
            br = tree.branch
 
191
        except NoWorkingTree, e:
 
192
            (br, path) = branch.Branch.open_containing(location)
 
193
            tree = None
 
194
        open_display()
 
195
        from bzrlib.plugins.gtk.loom import LoomDialog
 
196
        dialog = LoomDialog(br, tree)
 
197
        dialog.run()
 
198
 
177
199
 
178
200
class cmd_gdiff(GTKCommand):
179
201
    """Show differences in working tree in a GTK+ Window.
231
253
    
232
254
    :return: The viz window object.
233
255
    """
234
 
    from viz import BranchWindow
 
256
    from bzrlib.plugins.gtk.viz import BranchWindow
235
257
    return BranchWindow(branch, revisions, limit)
236
258
 
237
259
 
449
471
        dialog.run()
450
472
 
451
473
 
 
474
class cmd_gmerge(Command):
 
475
    """ GTK+ merge dialog
 
476
    
 
477
    """
 
478
    takes_args = ["merge_from_path?"]
 
479
    def run(self, merge_from_path=None):
 
480
        from bzrlib import workingtree
 
481
        from bzrlib.plugins.gtk.dialog import error_dialog
 
482
        from bzrlib.plugins.gtk.merge import MergeDialog
 
483
        
 
484
        (wt, path) = workingtree.WorkingTree.open_containing('.')
 
485
        old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
 
486
        delta = wt.changes_from(old_tree)
 
487
        if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
 
488
            error_dialog(_i18n('There are local changes in the branch'),
 
489
                         _i18n('Please commit or revert the changes before merging.'))
 
490
        else:
 
491
            parent_branch_path = wt.branch.get_parent()
 
492
            merge = MergeDialog(wt, path, parent_branch_path)
 
493
            response = merge.run()
 
494
            merge.destroy()
 
495
 
 
496
 
452
497
class cmd_gmissing(Command):
453
498
    """ GTK+ missing revisions dialog.
454
499
 
512
557
    cmd_gconflicts, 
513
558
    cmd_gdiff,
514
559
    cmd_ginit,
 
560
    cmd_gmerge,
515
561
    cmd_gmissing, 
516
562
    cmd_gpreferences, 
517
563
    cmd_gpush, 
521
567
    cmd_visualise
522
568
    ]
523
569
 
 
570
try:
 
571
    from bzrlib.plugins import loom
 
572
except ImportError:
 
573
    pass # Loom plugin doesn't appear to be present
 
574
else:
 
575
    commands.append(cmd_gloom)
 
576
 
524
577
for cmd in commands:
525
578
    register_command(cmd)
526
579
 
527
580
 
528
 
class cmd_commit_notify(GTKCommand):
529
 
    """Run the bzr commit notifier.
530
 
 
531
 
    This is a background program which will pop up a notification on the users
532
 
    screen when a commit occurs.
533
 
    """
534
 
 
535
 
    def run(self):
536
 
        from notify import NotifyPopupMenu
537
 
        gtk = open_display()
538
 
        menu = NotifyPopupMenu()
539
 
        icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
540
 
        icon.connect('popup-menu', menu.display)
541
 
 
542
 
        import cgi
543
 
        import dbus
544
 
        import dbus.service
545
 
        import pynotify
546
 
        from bzrlib.bzrdir import BzrDir
547
 
        from bzrlib import errors
548
 
        from bzrlib.osutils import format_date
549
 
        from bzrlib.transport import get_transport
550
 
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
551
 
            import dbus.glib
552
 
        BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
553
 
        bus = dbus.SessionBus()
554
 
 
555
 
        def catch_branch(revision_id, urls):
556
 
            # TODO: show all the urls, or perhaps choose the 'best'.
557
 
            url = urls[0]
558
 
            try:
559
 
                if isinstance(revision_id, unicode):
560
 
                    revision_id = revision_id.encode('utf8')
561
 
                transport = get_transport(url)
562
 
                a_dir = BzrDir.open_from_transport(transport)
563
 
                branch = a_dir.open_branch()
564
 
                revno = branch.revision_id_to_revno(revision_id)
565
 
                revision = branch.repository.get_revision(revision_id)
566
 
                summary = 'New revision %d in %s' % (revno, url)
567
 
                body  = 'Committer: %s\n' % revision.committer
568
 
                body += 'Date: %s\n' % format_date(revision.timestamp,
569
 
                    revision.timezone)
570
 
                body += '\n'
571
 
                body += revision.message
572
 
                body = cgi.escape(body)
573
 
                nw = pynotify.Notification(summary, body)
574
 
                def start_viz(notification=None, action=None, data=None):
575
 
                    """Start the viz program."""
576
 
                    pp = start_viz_window(branch, revision_id)
577
 
                    pp.show()
578
 
                def start_branch(notification=None, action=None, data=None):
579
 
                    """Start a Branch dialog"""
580
 
                    from bzrlib.plugins.gtk.branch import BranchDialog
581
 
                    bd = BranchDialog(remote_path=url)
582
 
                    bd.run()
583
 
                nw.add_action("inspect", "Inspect", start_viz, None)
584
 
                nw.add_action("branch", "Branch", start_branch, None)
585
 
                nw.set_timeout(5000)
586
 
                nw.show()
587
 
            except Exception, e:
588
 
                print e
589
 
                raise
590
 
        bus.add_signal_receiver(catch_branch,
591
 
                                dbus_interface=BROADCAST_INTERFACE,
592
 
                                signal_name="Revision")
593
 
        pynotify.init("bzr commit-notify")
594
 
        gtk.main()
595
 
 
596
 
register_command(cmd_commit_notify)
597
 
 
598
 
 
599
581
class cmd_gselftest(GTKCommand):
600
582
    """Version of selftest that displays a notification at the end"""
601
583