/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 commands.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-06 14:53:44 UTC
  • Revision ID: jelmer@samba.org-20110406145344-m6s0i7q7ssjwhmwq
Support use without gtk.Spinner, which is only available in pygtk >= 2.22.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from bzrlib import (
18
18
    branch,
19
 
    builtins,
 
19
    errors,
20
20
    workingtree,
21
21
    )
22
22
from bzrlib.commands import (
33
33
 
34
34
from bzrlib.plugins.gtk import (
35
35
    _i18n,
36
 
    open_display,
37
36
    import_pygtk,
38
37
    set_ui_factory,
39
38
    )
40
39
 
 
40
 
 
41
class NoDisplayError(errors.BzrCommandError):
 
42
    """gtk could not find a proper display"""
 
43
 
 
44
    def __str__(self):
 
45
        return "No DISPLAY. Unable to run GTK+ application."
 
46
 
 
47
 
 
48
def open_display():
 
49
    pygtk = import_pygtk()
 
50
    try:
 
51
        import gtk
 
52
    except RuntimeError, e:
 
53
        if str(e) == "could not open display":
 
54
            raise NoDisplayError
 
55
    set_ui_factory()
 
56
    return gtk
 
57
 
 
58
 
 
59
 
41
60
class GTKCommand(Command):
42
61
    """Abstract class providing GTK specific run commands."""
43
62
 
162
181
 
163
182
 
164
183
class cmd_visualise(Command):
165
 
    """Graphically visualise this branch.
166
 
 
167
 
    Opens a graphical window to allow you to see the history of the branch
168
 
    and relationships between revisions in a visual manner,
169
 
 
170
 
    The default starting point is latest revision on the branch, you can
171
 
    specify a starting point with -r revision.
 
184
    """Graphically visualise one or several branches.
 
185
 
 
186
    Opens a graphical window to allow you to see branches history and
 
187
    relationships between revisions in a visual manner,
 
188
 
 
189
    If no revision is specified, the branch last revision is taken as a
 
190
    starting point. When a revision is specified, the presented graph starts
 
191
    with it (as a side effect, when a shared repository is used, any revision
 
192
    can be used even if it's not part of the branch history).
172
193
    """
173
194
    takes_options = [
174
195
        "revision",
375
396
        dialog.run()
376
397
 
377
398
 
378
 
class cmd_ginfo(Command):
379
 
    """ GTK+ info dialog
380
 
    
381
 
    """
382
 
    def run(self):
383
 
        from bzrlib import workingtree
384
 
        from bzrlib.plugins.gtk.olive.info import InfoDialog
385
 
        wt = workingtree.WorkingTree.open_containing('.')[0]
386
 
        info = InfoDialog(wt.branch)
387
 
        info.display()
388
 
        info.window.run()
389
 
 
390
 
 
391
399
class cmd_gmerge(Command):
392
400
    """ GTK+ merge dialog
393
401
    
473
481
        window = TagsWindow(br)
474
482
        window.show()
475
483
        gtk.main()
476
 
 
477
 
 
478
 
class cmd_gselftest(GTKCommand):
479
 
    """Version of selftest that displays a notification at the end"""
480
 
 
481
 
    takes_args = builtins.cmd_selftest.takes_args
482
 
    takes_options = builtins.cmd_selftest.takes_options
483
 
    _see_also = ['selftest']
484
 
 
485
 
    def run(self, *args, **kwargs):
486
 
        import cgi
487
 
        import sys
488
 
        default_encoding = sys.getdefaultencoding()
489
 
        # prevent gtk from blowing up later
490
 
        gtk = import_pygtk()
491
 
        # prevent gtk from messing with default encoding
492
 
        import pynotify
493
 
        if sys.getdefaultencoding() != default_encoding:
494
 
            reload(sys)
495
 
            sys.setdefaultencoding(default_encoding)
496
 
        result = builtins.cmd_selftest().run(*args, **kwargs)
497
 
        if result == 0:
498
 
            summary = 'Success'
499
 
            body = 'Selftest succeeded in "%s"' % os.getcwd()
500
 
        if result == 1:
501
 
            summary = 'Failure'
502
 
            body = 'Selftest failed in "%s"' % os.getcwd()
503
 
        pynotify.init("bzr gselftest")
504
 
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
505
 
        note.set_timeout(pynotify.EXPIRES_NEVER)
506
 
        note.show()