/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-29 19:34:29 UTC
  • mto: This revision was merged to the branch mainline in revision 520.
  • Revision ID: jelmer@samba.org-20080629193429-ir2ilmbko6qkubg5
Add Branch/Index option if bzr-search is available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
import bzrlib
38
38
 
39
 
version_info = (0, 94, 0, 'dev', 0)
 
39
version_info = (0, 95, 0, 'dev', 1)
40
40
 
41
41
if version_info[3] == 'final':
42
42
    version_string = '%d.%d.%d' % version_info[:3]
44
44
    version_string = '%d.%d.%d%s%d' % version_info
45
45
__version__ = version_string
46
46
 
47
 
required_bzrlib = (1, 0)
 
47
required_bzrlib = (1, 3)
48
48
 
49
49
def check_bzrlib_version(desired):
50
50
    """Check that bzrlib is compatible.
77
77
    branch,
78
78
    builtins,
79
79
    errors,
 
80
    merge_directive,
80
81
    workingtree,
81
82
    )
82
83
""")
107
108
    return os.path.dirname(__file__)
108
109
 
109
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
 
110
133
class GTKCommand(Command):
111
134
    """Abstract class providing GTK specific run commands."""
112
135
 
113
 
    def open_display(self):
114
 
        pygtk = import_pygtk()
115
 
        try:
116
 
            import gtk
117
 
        except RuntimeError, e:
118
 
            if str(e) == "could not open display":
119
 
                raise NoDisplayError
120
 
        set_ui_factory()
121
 
        return gtk
122
 
 
123
136
    def run(self):
124
 
        self.open_display()
 
137
        open_display()
125
138
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
126
139
        dialog.run()
127
140
 
155
168
 
156
169
    def run(self, location="."):
157
170
        (br, path) = branch.Branch.open_containing(location)
158
 
        self.open_display()
 
171
        open_display()
159
172
        from push import PushDialog
160
173
        dialog = PushDialog(br.repository, br.last_revision(), br)
161
174
        dialog.run()
180
193
            if revision is not None:
181
194
                if len(revision) == 1:
182
195
                    tree1 = wt
183
 
                    revision_id = revision[0].in_history(branch).rev_id
 
196
                    revision_id = revision[0].as_revision_id(tree1.branch)
184
197
                    tree2 = branch.repository.revision_tree(revision_id)
185
198
                elif len(revision) == 2:
186
 
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
199
                    revision_id_0 = revision[0].as_revision_id(branch)
187
200
                    tree2 = branch.repository.revision_tree(revision_id_0)
188
 
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
201
                    revision_id_1 = revision[1].as_revision_id(branch)
189
202
                    tree1 = branch.repository.revision_tree(revision_id_1)
190
203
            else:
191
204
                tree1 = wt
213
226
            wt.unlock()
214
227
 
215
228
 
216
 
def start_viz_window(branch, revision, limit=None):
 
229
def start_viz_window(branch, revisions, limit=None):
217
230
    """Start viz on branch with revision revision.
218
231
    
219
232
    :return: The viz window object.
220
233
    """
221
234
    from viz import BranchWindow
222
 
    return BranchWindow(branch, revision, limit)
 
235
    return BranchWindow(branch, revisions, limit)
223
236
 
224
237
 
225
238
class cmd_visualise(Command):
235
248
        "revision",
236
249
        Option('limit', "Maximum number of revisions to display.",
237
250
               int, 'count')]
238
 
    takes_args = [ "location?" ]
 
251
    takes_args = [ "locations*" ]
239
252
    aliases = [ "visualize", "vis", "viz" ]
240
253
 
241
 
    def run(self, location=".", revision=None, limit=None):
 
254
    def run(self, locations_list, revision=None, limit=None):
242
255
        set_ui_factory()
243
 
        (br, path) = branch.Branch.open_containing(location)
244
 
        if revision is None:
245
 
            revid = br.last_revision()
246
 
            if revid is None:
247
 
                return
248
 
        else:
249
 
            (revno, revid) = revision[0].in_history(br)
250
 
 
 
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))
251
265
        import gtk
252
 
        pp = start_viz_window(br, revid, limit)
 
266
        pp = start_viz_window(br, revids, limit)
253
267
        pp.connect("destroy", lambda w: gtk.main_quit())
254
268
        pp.show()
255
269
        gtk.main()
272
286
    aliases = ["gblame", "gpraise"]
273
287
    
274
288
    def run(self, filename, all=False, plain=False, line='1', revision=None):
275
 
        gtk = self.open_display()
 
289
        gtk = open_display()
276
290
 
277
291
        try:
278
292
            line = int(line)
297
311
        if revision is not None:
298
312
            if len(revision) != 1:
299
313
                raise BzrCommandError("Only 1 revion may be specified.")
300
 
            revision_id = revision[0].in_history(br).rev_id
 
314
            revision_id = revision[0].as_revision_id(br)
301
315
            tree = br.repository.revision_tree(revision_id)
302
316
        else:
303
317
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
304
318
 
305
 
        window = GAnnotateWindow(all, plain)
 
319
        window = GAnnotateWindow(all, plain, branch=br)
306
320
        window.connect("destroy", lambda w: gtk.main_quit())
307
 
        window.set_title(path + " - gannotate")
308
321
        config = GAnnotateConfig(window)
309
322
        window.show()
310
323
        br.lock_read()
332
345
 
333
346
    def run(self, filename=None):
334
347
        import os
335
 
        self.open_display()
 
348
        open_display()
336
349
        from commit import CommitDialog
337
350
        from bzrlib.errors import (BzrCommandError,
338
351
                                   NotBranchError,
345
358
            br = wt.branch
346
359
        except NoWorkingTree, e:
347
360
            from dialog import error_dialog
348
 
            error_dialog(_('Directory does not have a working tree'),
349
 
                         _('Operation aborted.'))
 
361
            error_dialog(_i18n('Directory does not have a working tree'),
 
362
                         _i18n('Operation aborted.'))
350
363
            return 1 # should this be retval=3?
351
364
 
352
365
        # It is a good habit to keep things locked for the duration, but it
369
382
    
370
383
    aliases = [ "gst" ]
371
384
    takes_args = ['PATH?']
372
 
    takes_options = []
 
385
    takes_options = ['revision']
373
386
 
374
 
    def run(self, path='.'):
 
387
    def run(self, path='.', revision=None):
375
388
        import os
376
 
        gtk = self.open_display()
 
389
        gtk = open_display()
377
390
        from status import StatusDialog
378
391
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
379
 
        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)
380
403
        status.connect("destroy", gtk.main_quit)
381
404
        status.run()
382
405
 
387
410
    """
388
411
    def run(self):
389
412
        (br, path) = branch.Branch.open_containing(".")
390
 
        gtk = self.open_display()
 
413
        gtk = open_display()
391
414
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
392
415
        from StringIO import StringIO
393
416
        dialog = SendMergeDirectiveDialog(br)
409
432
    """
410
433
    def run(self):
411
434
        (wt, path) = workingtree.WorkingTree.open_containing('.')
412
 
        self.open_display()
 
435
        open_display()
413
436
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
414
437
        dialog = ConflictsDialog(wt)
415
438
        dialog.run()
420
443
 
421
444
    """
422
445
    def run(self):
423
 
        self.open_display()
 
446
        open_display()
424
447
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
425
448
        dialog = PreferencesWindow()
426
449
        dialog.run()
464
487
 
465
488
class cmd_ginit(GTKCommand):
466
489
    def run(self):
467
 
        self.open_display()
 
490
        open_display()
468
491
        from initialize import InitDialog
469
492
        dialog = InitDialog(os.path.abspath(os.path.curdir))
470
493
        dialog.run()
474
497
    def run(self):
475
498
        br = branch.Branch.open_containing('.')[0]
476
499
        
477
 
        gtk = self.open_display()
 
500
        gtk = open_display()
478
501
        from tags import TagsWindow
479
502
        window = TagsWindow(br)
480
503
        window.show()
511
534
 
512
535
    def run(self):
513
536
        from notify import NotifyPopupMenu
514
 
        gtk = self.open_display()
 
537
        gtk = open_display()
515
538
        menu = NotifyPopupMenu()
516
 
        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"))
517
540
        icon.connect('popup-menu', menu.display)
518
541
 
519
542
        import cgi
526
549
        from bzrlib.transport import get_transport
527
550
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
528
551
            import dbus.glib
529
 
        from bzrlib.plugins.dbus import activity
 
552
        BROADCAST_INTERFACE = "org.bazaarvcs.plugins.dbus.Broadcast"
530
553
        bus = dbus.SessionBus()
531
 
        # get the object so we can subscribe to callbacks from it.
532
 
        broadcast_service = bus.get_object(
533
 
            activity.Broadcast.DBUS_NAME,
534
 
            activity.Broadcast.DBUS_PATH)
535
554
 
536
555
        def catch_branch(revision_id, urls):
537
556
            # TODO: show all the urls, or perhaps choose the 'best'.
568
587
            except Exception, e:
569
588
                print e
570
589
                raise
571
 
        broadcast_service.connect_to_signal("Revision", catch_branch,
572
 
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
590
        bus.add_signal_receiver(catch_branch,
 
591
                                dbus_interface=BROADCAST_INTERFACE,
 
592
                                signal_name="Revision")
573
593
        pynotify.init("bzr commit-notify")
574
594
        gtk.main()
575
595
 
672
692
register_command(cmd_test_gtk)
673
693
 
674
694
 
 
695
 
675
696
import gettext
676
697
gettext.install('olive-gtk')
677
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
678
702
 
679
703
class NoDisplayError(BzrCommandError):
680
704
    """gtk could not find a proper display"""