/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 18:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629181229-1l2m4cf7vvbyh8qg
Simplify progress bar code, use embedded progress bar inside viz window.

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]
120
119
    return None
121
120
 
122
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
 
123
133
class GTKCommand(Command):
124
134
    """Abstract class providing GTK specific run commands."""
125
135
 
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
 
 
136
136
    def run(self):
137
 
        self.open_display()
 
137
        open_display()
138
138
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
139
139
        dialog.run()
140
140
 
168
168
 
169
169
    def run(self, location="."):
170
170
        (br, path) = branch.Branch.open_containing(location)
171
 
        self.open_display()
 
171
        open_display()
172
172
        from push import PushDialog
173
173
        dialog = PushDialog(br.repository, br.last_revision(), br)
174
174
        dialog.run()
193
193
            if revision is not None:
194
194
                if len(revision) == 1:
195
195
                    tree1 = wt
196
 
                    revision_id = revision[0].in_history(branch).rev_id
 
196
                    revision_id = revision[0].as_revision_id(tree1.branch)
197
197
                    tree2 = branch.repository.revision_tree(revision_id)
198
198
                elif len(revision) == 2:
199
 
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
199
                    revision_id_0 = revision[0].as_revision_id(branch)
200
200
                    tree2 = branch.repository.revision_tree(revision_id_0)
201
 
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
201
                    revision_id_1 = revision[1].as_revision_id(branch)
202
202
                    tree1 = branch.repository.revision_tree(revision_id_1)
203
203
            else:
204
204
                tree1 = wt
261
261
            if revision is None:
262
262
                revids.append(br.last_revision())
263
263
            else:
264
 
                (revno, revid) = revision[0].in_history(br)
265
 
                revids.append(revid)
 
264
                revids.append(revision[0].as_revision_id(br))
266
265
        import gtk
267
266
        pp = start_viz_window(br, revids, limit)
268
267
        pp.connect("destroy", lambda w: gtk.main_quit())
287
286
    aliases = ["gblame", "gpraise"]
288
287
    
289
288
    def run(self, filename, all=False, plain=False, line='1', revision=None):
290
 
        gtk = self.open_display()
 
289
        gtk = open_display()
291
290
 
292
291
        try:
293
292
            line = int(line)
312
311
        if revision is not None:
313
312
            if len(revision) != 1:
314
313
                raise BzrCommandError("Only 1 revion may be specified.")
315
 
            revision_id = revision[0].in_history(br).rev_id
 
314
            revision_id = revision[0].as_revision_id(br)
316
315
            tree = br.repository.revision_tree(revision_id)
317
316
        else:
318
317
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
319
318
 
320
 
        window = GAnnotateWindow(all, plain)
 
319
        window = GAnnotateWindow(all, plain, branch=br)
321
320
        window.connect("destroy", lambda w: gtk.main_quit())
322
321
        config = GAnnotateConfig(window)
323
322
        window.show()
346
345
 
347
346
    def run(self, filename=None):
348
347
        import os
349
 
        self.open_display()
 
348
        open_display()
350
349
        from commit import CommitDialog
351
350
        from bzrlib.errors import (BzrCommandError,
352
351
                                   NotBranchError,
359
358
            br = wt.branch
360
359
        except NoWorkingTree, e:
361
360
            from dialog import error_dialog
362
 
            error_dialog(_('Directory does not have a working tree'),
363
 
                         _('Operation aborted.'))
 
361
            error_dialog(_i18n('Directory does not have a working tree'),
 
362
                         _i18n('Operation aborted.'))
364
363
            return 1 # should this be retval=3?
365
364
 
366
365
        # It is a good habit to keep things locked for the duration, but it
383
382
    
384
383
    aliases = [ "gst" ]
385
384
    takes_args = ['PATH?']
386
 
    takes_options = []
 
385
    takes_options = ['revision']
387
386
 
388
 
    def run(self, path='.'):
 
387
    def run(self, path='.', revision=None):
389
388
        import os
390
 
        gtk = self.open_display()
 
389
        gtk = open_display()
391
390
        from status import StatusDialog
392
391
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
393
 
        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)
394
403
        status.connect("destroy", gtk.main_quit)
395
404
        status.run()
396
405
 
401
410
    """
402
411
    def run(self):
403
412
        (br, path) = branch.Branch.open_containing(".")
404
 
        gtk = self.open_display()
 
413
        gtk = open_display()
405
414
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
406
415
        from StringIO import StringIO
407
416
        dialog = SendMergeDirectiveDialog(br)
423
432
    """
424
433
    def run(self):
425
434
        (wt, path) = workingtree.WorkingTree.open_containing('.')
426
 
        self.open_display()
 
435
        open_display()
427
436
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
428
437
        dialog = ConflictsDialog(wt)
429
438
        dialog.run()
434
443
 
435
444
    """
436
445
    def run(self):
437
 
        self.open_display()
 
446
        open_display()
438
447
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
439
448
        dialog = PreferencesWindow()
440
449
        dialog.run()
478
487
 
479
488
class cmd_ginit(GTKCommand):
480
489
    def run(self):
481
 
        self.open_display()
 
490
        open_display()
482
491
        from initialize import InitDialog
483
492
        dialog = InitDialog(os.path.abspath(os.path.curdir))
484
493
        dialog.run()
488
497
    def run(self):
489
498
        br = branch.Branch.open_containing('.')[0]
490
499
        
491
 
        gtk = self.open_display()
 
500
        gtk = open_display()
492
501
        from tags import TagsWindow
493
502
        window = TagsWindow(br)
494
503
        window.show()
525
534
 
526
535
    def run(self):
527
536
        from notify import NotifyPopupMenu
528
 
        gtk = self.open_display()
 
537
        gtk = open_display()
529
538
        menu = NotifyPopupMenu()
530
539
        icon = gtk.status_icon_new_from_file(icon_path("bzr-icon-64.png"))
531
540
        icon.connect('popup-menu', menu.display)
683
692
register_command(cmd_test_gtk)
684
693
 
685
694
 
686
 
class cmd_ghandle_patch(GTKCommand):
687
 
    """Display a patch or merge directive, possibly merging.
688
 
 
689
 
    This is a helper, meant to be launched from other programs like browsers
690
 
    or email clients.  Since these programs often do not allow parameters to
691
 
    be provided, a "handle-patch" script is included.
692
 
    """
693
 
 
694
 
    takes_args = ['path']
695
 
 
696
 
    def run(self, path):
697
 
        try:
698
 
            from bzrlib.plugins.gtk.diff import (DiffWindow,
699
 
                                                 MergeDirectiveWindow)
700
 
            lines = open(path, 'rb').readlines()
701
 
            lines = [l.replace('\r\n', '\n') for l in lines]
702
 
            try:
703
 
                directive = merge_directive.MergeDirective.from_lines(lines)
704
 
            except errors.NotAMergeDirective:
705
 
                window = DiffWindow()
706
 
                window.set_diff_text(path, lines)
707
 
            else:
708
 
                window = MergeDirectiveWindow(directive, path)
709
 
                window.set_diff_text(path, directive.patch.splitlines(True))
710
 
            window.show()
711
 
            gtk = self.open_display()
712
 
            window.connect("destroy", gtk.main_quit)
713
 
        except Exception, e:
714
 
            from dialog import error_dialog
715
 
            error_dialog('Error', str(e))
716
 
            raise
717
 
        gtk.main()
718
 
 
719
 
 
720
 
register_command(cmd_ghandle_patch)
721
 
 
722
695
 
723
696
import gettext
724
697
gettext.install('olive-gtk')
725
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
726
702
 
727
703
class NoDisplayError(BzrCommandError):
728
704
    """gtk could not find a proper display"""