/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: Vincent Ladeuil
  • Date: 2008-06-10 15:25:47 UTC
  • mto: This revision was merged to the branch mainline in revision 504.
  • Revision ID: v.ladeuil+lp@free.fr-20080610152547-dwmil1p8pd0mfpnl
Fix third failing test (thanks to jam).

* tests/test_commit.py:
(TestPendingRevisions.test_pending_revisions_multi_merge): Fix
provided by jam: bzr we now filter the pending merges so that only
the 'heads()' are included. We just ensure that the pending merges
contain the unique tips for the ancestries.

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.
18
19
gannotate         GTK+ annotate. 
19
20
gbranch           GTK+ branching. 
20
21
gcheckout         GTK+ checkout. 
21
22
gcommit           GTK+ commit dialog.
22
23
gconflicts        GTK+ conflicts. 
23
24
gdiff             Show differences in working tree in a GTK+ Window. 
 
25
ghandle-patch     Display and optionally merge a merge directive or patch.
24
26
ginit             Initialise a new branch.
25
 
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_basedirs():
108
 
    return [os.path.dirname(__file__),
 
108
def data_path():
 
109
    return os.path.dirname(__file__)
 
110
 
 
111
 
 
112
def icon_path(*args):
 
113
    basedirs = [os.path.join(data_path()),
109
114
             "/usr/share/bzr-gtk", 
110
115
             "/usr/local/share/bzr-gtk"]
111
 
 
112
 
 
113
 
def data_path(*args):
114
 
    for basedir in data_basedirs():
115
 
        path = os.path.join(basedir, *args)
 
116
    for basedir in basedirs:
 
117
        path = os.path.join(basedir, 'icons', *args)
116
118
        if os.path.exists(path):
117
119
            return path
118
120
    return None
119
121
 
120
122
 
121
 
def icon_path(*args):
122
 
    return data_path(os.path.join('icons', *args))
123
 
 
124
 
 
125
 
def open_display():
126
 
    pygtk = import_pygtk()
127
 
    try:
128
 
        import gtk
129
 
    except RuntimeError, e:
130
 
        if str(e) == "could not open display":
131
 
            raise NoDisplayError
132
 
    set_ui_factory()
133
 
    return gtk
134
 
 
135
 
 
136
123
class GTKCommand(Command):
137
124
    """Abstract class providing GTK specific run commands."""
138
125
 
 
126
    def open_display(self):
 
127
        pygtk = import_pygtk()
 
128
        try:
 
129
            import gtk
 
130
        except RuntimeError, e:
 
131
            if str(e) == "could not open display":
 
132
                raise NoDisplayError
 
133
        set_ui_factory()
 
134
        return gtk
 
135
 
139
136
    def run(self):
140
 
        open_display()
 
137
        self.open_display()
141
138
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
142
139
        dialog.run()
143
140
 
171
168
 
172
169
    def run(self, location="."):
173
170
        (br, path) = branch.Branch.open_containing(location)
174
 
        open_display()
 
171
        self.open_display()
175
172
        from push import PushDialog
176
173
        dialog = PushDialog(br.repository, br.last_revision(), br)
177
174
        dialog.run()
289
286
    aliases = ["gblame", "gpraise"]
290
287
    
291
288
    def run(self, filename, all=False, plain=False, line='1', revision=None):
292
 
        gtk = open_display()
 
289
        gtk = self.open_display()
293
290
 
294
291
        try:
295
292
            line = int(line)
348
345
 
349
346
    def run(self, filename=None):
350
347
        import os
351
 
        open_display()
 
348
        self.open_display()
352
349
        from commit import CommitDialog
353
350
        from bzrlib.errors import (BzrCommandError,
354
351
                                   NotBranchError,
389
386
 
390
387
    def run(self, path='.', revision=None):
391
388
        import os
392
 
        gtk = open_display()
 
389
        gtk = self.open_display()
393
390
        from status import StatusDialog
394
391
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
395
392
        
413
410
    """
414
411
    def run(self):
415
412
        (br, path) = branch.Branch.open_containing(".")
416
 
        gtk = open_display()
 
413
        gtk = self.open_display()
417
414
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
418
415
        from StringIO import StringIO
419
416
        dialog = SendMergeDirectiveDialog(br)
435
432
    """
436
433
    def run(self):
437
434
        (wt, path) = workingtree.WorkingTree.open_containing('.')
438
 
        open_display()
 
435
        self.open_display()
439
436
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
440
437
        dialog = ConflictsDialog(wt)
441
438
        dialog.run()
446
443
 
447
444
    """
448
445
    def run(self):
449
 
        open_display()
 
446
        self.open_display()
450
447
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
451
448
        dialog = PreferencesWindow()
452
449
        dialog.run()
453
450
 
454
451
 
455
 
class cmd_gmerge(Command):
456
 
    """ GTK+ merge dialog
457
 
    
458
 
    """
459
 
    takes_args = ["merge_from_path?"]
460
 
    def run(self, merge_from_path=None):
461
 
        from bzrlib import workingtree
462
 
        from bzrlib.plugins.gtk.dialog import error_dialog
463
 
        from bzrlib.plugins.gtk.merge import MergeDialog
464
 
        
465
 
        (wt, path) = workingtree.WorkingTree.open_containing('.')
466
 
        old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
467
 
        delta = wt.changes_from(old_tree)
468
 
        if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
469
 
            error_dialog(_i18n('There are local changes in the branch'),
470
 
                         _i18n('Please commit or revert the changes before merging.'))
471
 
        else:
472
 
            parent_branch_path = wt.branch.get_parent()
473
 
            merge = MergeDialog(wt, path, parent_branch_path)
474
 
            response = merge.run()
475
 
            merge.destroy()
476
 
 
477
 
 
478
452
class cmd_gmissing(Command):
479
453
    """ GTK+ missing revisions dialog.
480
454
 
513
487
 
514
488
class cmd_ginit(GTKCommand):
515
489
    def run(self):
516
 
        open_display()
 
490
        self.open_display()
517
491
        from initialize import InitDialog
518
492
        dialog = InitDialog(os.path.abspath(os.path.curdir))
519
493
        dialog.run()
523
497
    def run(self):
524
498
        br = branch.Branch.open_containing('.')[0]
525
499
        
526
 
        gtk = open_display()
 
500
        gtk = self.open_display()
527
501
        from tags import TagsWindow
528
502
        window = TagsWindow(br)
529
503
        window.show()
538
512
    cmd_gconflicts, 
539
513
    cmd_gdiff,
540
514
    cmd_ginit,
541
 
    cmd_gmerge,
542
515
    cmd_gmissing, 
543
516
    cmd_gpreferences, 
544
517
    cmd_gpush, 
552
525
    register_command(cmd)
553
526
 
554
527
 
 
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 = self.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
 
555
599
class cmd_gselftest(GTKCommand):
556
600
    """Version of selftest that displays a notification at the end"""
557
601
 
648
692
register_command(cmd_test_gtk)
649
693
 
650
694
 
 
695
class cmd_ghandle_patch(GTKCommand):
 
696
    """Display a patch or merge directive, possibly merging.
 
697
 
 
698
    This is a helper, meant to be launched from other programs like browsers
 
699
    or email clients.  Since these programs often do not allow parameters to
 
700
    be provided, a "handle-patch" script is included.
 
701
    """
 
702
 
 
703
    takes_args = ['path']
 
704
 
 
705
    def run(self, path):
 
706
        try:
 
707
            from bzrlib.plugins.gtk.diff import (DiffController,
 
708
                                                 MergeDirectiveController)
 
709
            if path == '-':
 
710
                lines = sys.stdin.readlines()
 
711
            else:
 
712
                lines = open(path, 'rb').readlines()
 
713
            lines = [l.replace('\r\n', '\n') for l in lines]
 
714
            try:
 
715
                directive = merge_directive.MergeDirective.from_lines(lines)
 
716
            except errors.NotAMergeDirective:
 
717
                controller = DiffController(path, lines)
 
718
            else:
 
719
                controller = MergeDirectiveController(path, directive)
 
720
            window = controller.window
 
721
            window.show()
 
722
            gtk = self.open_display()
 
723
            window.connect("destroy", gtk.main_quit)
 
724
        except Exception, e:
 
725
            from dialog import error_dialog
 
726
            error_dialog('Error', str(e))
 
727
            raise
 
728
        gtk.main()
 
729
 
 
730
 
 
731
register_command(cmd_ghandle_patch)
 
732
 
651
733
 
652
734
import gettext
653
735
gettext.install('olive-gtk')