/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-06-28 17:13:46 UTC
  • mto: This revision was merged to the branch mainline in revision 517.
  • Revision ID: jelmer@samba.org-20080628171346-ob42iggcc663s4xz
Show full license details in about dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
gcommit           GTK+ commit dialog.
23
23
gconflicts        GTK+ conflicts. 
24
24
gdiff             Show differences in working tree in a GTK+ Window. 
25
 
ghandle-patch     Display and optionally merge a merge directive or patch.
26
25
ginit             Initialise a new branch.
27
26
gmissing          GTK+ missing revisions dialog. 
28
27
gpreferences      GTK+ preferences dialog. 
37
36
 
38
37
import bzrlib
39
38
 
40
 
version_info = (0, 94, 0, 'dev', 0)
 
39
version_info = (0, 95, 0, 'dev', 1)
41
40
 
42
41
if version_info[3] == 'final':
43
42
    version_string = '%d.%d.%d' % version_info[:3]
45
44
    version_string = '%d.%d.%d%s%d' % version_info
46
45
__version__ = version_string
47
46
 
48
 
required_bzrlib = (1, 0)
 
47
required_bzrlib = (1, 3)
49
48
 
50
49
def check_bzrlib_version(desired):
51
50
    """Check that bzrlib is compatible.
109
108
    return os.path.dirname(__file__)
110
109
 
111
110
 
 
111
def icon_path(*args):
 
112
    basedirs = [os.path.join(data_path()),
 
113
             "/usr/share/bzr-gtk", 
 
114
             "/usr/local/share/bzr-gtk"]
 
115
    for basedir in basedirs:
 
116
        path = os.path.join(basedir, 'icons', *args)
 
117
        if os.path.exists(path):
 
118
            return path
 
119
    return None
 
120
 
 
121
 
 
122
def open_display():
 
123
    pygtk = import_pygtk()
 
124
    try:
 
125
        import gtk
 
126
    except RuntimeError, e:
 
127
        if str(e) == "could not open display":
 
128
            raise NoDisplayError
 
129
    set_ui_factory()
 
130
    return gtk
 
131
 
 
132
 
112
133
class GTKCommand(Command):
113
134
    """Abstract class providing GTK specific run commands."""
114
135
 
115
 
    def open_display(self):
116
 
        pygtk = import_pygtk()
117
 
        try:
118
 
            import gtk
119
 
        except RuntimeError, e:
120
 
            if str(e) == "could not open display":
121
 
                raise NoDisplayError
122
 
        set_ui_factory()
123
 
        return gtk
124
 
 
125
136
    def run(self):
126
 
        self.open_display()
 
137
        open_display()
127
138
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
128
139
        dialog.run()
129
140
 
157
168
 
158
169
    def run(self, location="."):
159
170
        (br, path) = branch.Branch.open_containing(location)
160
 
        self.open_display()
 
171
        open_display()
161
172
        from push import PushDialog
162
173
        dialog = PushDialog(br.repository, br.last_revision(), br)
163
174
        dialog.run()
182
193
            if revision is not None:
183
194
                if len(revision) == 1:
184
195
                    tree1 = wt
185
 
                    revision_id = revision[0].in_history(branch).rev_id
 
196
                    revision_id = revision[0].as_revision_id(tree1.branch)
186
197
                    tree2 = branch.repository.revision_tree(revision_id)
187
198
                elif len(revision) == 2:
188
 
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
199
                    revision_id_0 = revision[0].as_revision_id(branch)
189
200
                    tree2 = branch.repository.revision_tree(revision_id_0)
190
 
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
201
                    revision_id_1 = revision[1].as_revision_id(branch)
191
202
                    tree1 = branch.repository.revision_tree(revision_id_1)
192
203
            else:
193
204
                tree1 = wt
215
226
            wt.unlock()
216
227
 
217
228
 
218
 
def start_viz_window(branch, revision, limit=None):
 
229
def start_viz_window(branch, revisions, limit=None):
219
230
    """Start viz on branch with revision revision.
220
231
    
221
232
    :return: The viz window object.
222
233
    """
223
234
    from viz import BranchWindow
224
 
    return BranchWindow(branch, revision, limit)
 
235
    return BranchWindow(branch, revisions, limit)
225
236
 
226
237
 
227
238
class cmd_visualise(Command):
237
248
        "revision",
238
249
        Option('limit', "Maximum number of revisions to display.",
239
250
               int, 'count')]
240
 
    takes_args = [ "location?" ]
 
251
    takes_args = [ "locations*" ]
241
252
    aliases = [ "visualize", "vis", "viz" ]
242
253
 
243
 
    def run(self, location=".", revision=None, limit=None):
 
254
    def run(self, locations_list, revision=None, limit=None):
244
255
        set_ui_factory()
245
 
        (br, path) = branch.Branch.open_containing(location)
246
 
        if revision is None:
247
 
            revid = br.last_revision()
248
 
            if revid is None:
249
 
                return
250
 
        else:
251
 
            (revno, revid) = revision[0].in_history(br)
252
 
 
 
256
        if locations_list is None:
 
257
            locations_list = ["."]
 
258
        revids = []
 
259
        for location in locations_list:
 
260
            (br, path) = branch.Branch.open_containing(location)
 
261
            if revision is None:
 
262
                revids.append(br.last_revision())
 
263
            else:
 
264
                revids.append(revision[0].as_revision_id(br))
253
265
        import gtk
254
 
        pp = start_viz_window(br, revid, limit)
 
266
        pp = start_viz_window(br, revids, limit)
255
267
        pp.connect("destroy", lambda w: gtk.main_quit())
256
268
        pp.show()
257
269
        gtk.main()
274
286
    aliases = ["gblame", "gpraise"]
275
287
    
276
288
    def run(self, filename, all=False, plain=False, line='1', revision=None):
277
 
        gtk = self.open_display()
 
289
        gtk = open_display()
278
290
 
279
291
        try:
280
292
            line = int(line)
299
311
        if revision is not None:
300
312
            if len(revision) != 1:
301
313
                raise BzrCommandError("Only 1 revion may be specified.")
302
 
            revision_id = revision[0].in_history(br).rev_id
 
314
            revision_id = revision[0].as_revision_id(br)
303
315
            tree = br.repository.revision_tree(revision_id)
304
316
        else:
305
317
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
306
318
 
307
 
        window = GAnnotateWindow(all, plain)
 
319
        window = GAnnotateWindow(all, plain, branch=br)
308
320
        window.connect("destroy", lambda w: gtk.main_quit())
309
 
        window.set_title(path + " - gannotate")
310
321
        config = GAnnotateConfig(window)
311
322
        window.show()
312
323
        br.lock_read()
334
345
 
335
346
    def run(self, filename=None):
336
347
        import os
337
 
        self.open_display()
 
348
        open_display()
338
349
        from commit import CommitDialog
339
350
        from bzrlib.errors import (BzrCommandError,
340
351
                                   NotBranchError,
347
358
            br = wt.branch
348
359
        except NoWorkingTree, e:
349
360
            from dialog import error_dialog
350
 
            error_dialog(_('Directory does not have a working tree'),
351
 
                         _('Operation aborted.'))
 
361
            error_dialog(_i18n('Directory does not have a working tree'),
 
362
                         _i18n('Operation aborted.'))
352
363
            return 1 # should this be retval=3?
353
364
 
354
365
        # It is a good habit to keep things locked for the duration, but it
371
382
    
372
383
    aliases = [ "gst" ]
373
384
    takes_args = ['PATH?']
374
 
    takes_options = []
 
385
    takes_options = ['revision']
375
386
 
376
 
    def run(self, path='.'):
 
387
    def run(self, path='.', revision=None):
377
388
        import os
378
 
        gtk = self.open_display()
 
389
        gtk = open_display()
379
390
        from status import StatusDialog
380
391
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
381
 
        status = StatusDialog(wt, wt_path)
 
392
        
 
393
        if revision is not None:
 
394
            try:
 
395
                revision_id = revision[0].as_revision_id(wt.branch)
 
396
            except:
 
397
                from bzrlib.errors import BzrError
 
398
                raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
 
399
        else:
 
400
            revision_id = None
 
401
 
 
402
        status = StatusDialog(wt, wt_path, revision_id)
382
403
        status.connect("destroy", gtk.main_quit)
383
404
        status.run()
384
405
 
389
410
    """
390
411
    def run(self):
391
412
        (br, path) = branch.Branch.open_containing(".")
392
 
        gtk = self.open_display()
 
413
        gtk = open_display()
393
414
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
394
415
        from StringIO import StringIO
395
416
        dialog = SendMergeDirectiveDialog(br)
411
432
    """
412
433
    def run(self):
413
434
        (wt, path) = workingtree.WorkingTree.open_containing('.')
414
 
        self.open_display()
 
435
        open_display()
415
436
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
416
437
        dialog = ConflictsDialog(wt)
417
438
        dialog.run()
422
443
 
423
444
    """
424
445
    def run(self):
425
 
        self.open_display()
 
446
        open_display()
426
447
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
427
448
        dialog = PreferencesWindow()
428
449
        dialog.run()
466
487
 
467
488
class cmd_ginit(GTKCommand):
468
489
    def run(self):
469
 
        self.open_display()
 
490
        open_display()
470
491
        from initialize import InitDialog
471
492
        dialog = InitDialog(os.path.abspath(os.path.curdir))
472
493
        dialog.run()
476
497
    def run(self):
477
498
        br = branch.Branch.open_containing('.')[0]
478
499
        
479
 
        gtk = self.open_display()
 
500
        gtk = open_display()
480
501
        from tags import TagsWindow
481
502
        window = TagsWindow(br)
482
503
        window.show()
513
534
 
514
535
    def run(self):
515
536
        from notify import NotifyPopupMenu
516
 
        gtk = self.open_display()
 
537
        gtk = open_display()
517
538
        menu = NotifyPopupMenu()
518
 
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
539
        icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
519
540
        icon.connect('popup-menu', menu.display)
520
541
 
521
542
        import cgi
528
549
        from bzrlib.transport import get_transport
529
550
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
530
551
            import dbus.glib
531
 
        from bzrlib.plugins.dbus import activity
 
552
        BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
532
553
        bus = dbus.SessionBus()
533
 
        # get the object so we can subscribe to callbacks from it.
534
 
        broadcast_service = bus.get_object(
535
 
            activity.Broadcast.DBUS_NAME,
536
 
            activity.Broadcast.DBUS_PATH)
537
554
 
538
555
        def catch_branch(revision_id, urls):
539
556
            # TODO: show all the urls, or perhaps choose the 'best'.
570
587
            except Exception, e:
571
588
                print e
572
589
                raise
573
 
        broadcast_service.connect_to_signal("Revision", catch_branch,
574
 
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
590
        bus.add_signal_receiver(catch_branch,
 
591
                                dbus_interface=BROADCAST_INTERFACE,
 
592
                                signal_name="Revision")
575
593
        pynotify.init("bzr commit-notify")
576
594
        gtk.main()
577
595
 
674
692
register_command(cmd_test_gtk)
675
693
 
676
694
 
677
 
class cmd_ghandle_patch(GTKCommand):
678
 
    """Display a patch or merge directive, possibly merging.
679
 
 
680
 
    This is a helper, meant to be launched from other programs like browsers
681
 
    or email clients.  Since these programs often do not allow parameters to
682
 
    be provided, a "handle-patch" script is included.
683
 
    """
684
 
 
685
 
    takes_args = ['path']
686
 
 
687
 
    def run(self, path):
688
 
        try:
689
 
            from bzrlib.plugins.gtk.diff import (DiffWindow,
690
 
                                                 MergeDirectiveWindow)
691
 
            lines = open(path, 'rb').readlines()
692
 
            lines = [l.replace('\r\n', '\n') for l in lines]
693
 
            try:
694
 
                directive = merge_directive.MergeDirective.from_lines(lines)
695
 
            except errors.NotAMergeDirective:
696
 
                window = DiffWindow()
697
 
                window.set_diff_text(path, lines)
698
 
            else:
699
 
                window = MergeDirectiveWindow(directive, path)
700
 
                window.set_diff_text(path, directive.patch.splitlines(True))
701
 
            window.show()
702
 
            gtk = self.open_display()
703
 
            window.connect("destroy", gtk.main_quit)
704
 
        except Exception, e:
705
 
            from dialog import error_dialog
706
 
            error_dialog('Error', str(e))
707
 
            raise
708
 
        gtk.main()
709
 
 
710
 
 
711
 
register_command(cmd_ghandle_patch)
712
 
 
713
695
 
714
696
import gettext
715
697
gettext.install('olive-gtk')
716
698
 
 
699
# Let's create a specialized alias to protect '_' from being erased by other
 
700
# uses of '_' as an anonymous variable (think pdb for one).
 
701
_i18n = gettext.gettext
717
702
 
718
703
class NoDisplayError(BzrCommandError):
719
704
    """gtk could not find a proper display"""