/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 16:24:24 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629162424-48a6rrjmmpejfcyr
Stop emitting no longer used revisions-loaded message.

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