/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: Szilveszter Farkas (Phanatic)
  • Date: 2008-03-03 17:24:22 UTC
  • mto: This revision was merged to the branch mainline in revision 435.
  • Revision ID: szilveszter.farkas@gmail.com-20080303172422-y1u0gg7kyirrxuun
Installing an olive package is pretty useless. (Fixed: #136432)

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