/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: Martin Pool
  • Date: 2010-05-27 03:07:30 UTC
  • mfrom: (688.1.5 201956-help)
  • Revision ID: mbp@canonical.com-20100527030730-os0opv1xroetccm9
Make find/goto more discoverable

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from bzrlib import (
18
18
    branch,
19
 
    errors,
 
19
    builtins,
20
20
    workingtree,
21
21
    )
22
22
from bzrlib.commands import (
32
32
from bzrlib.option import Option
33
33
 
34
34
from bzrlib.plugins.gtk import (
 
35
    _i18n,
 
36
    open_display,
35
37
    import_pygtk,
36
38
    set_ui_factory,
37
39
    )
38
 
from bzrlib.plugins.gtk.i18n import _i18n
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
40
 
60
41
class GTKCommand(Command):
61
42
    """Abstract class providing GTK specific run commands."""
181
162
 
182
163
 
183
164
class cmd_visualise(Command):
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).
 
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.
193
172
    """
194
173
    takes_options = [
195
174
        "revision",
396
375
        dialog.run()
397
376
 
398
377
 
 
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
 
399
391
class cmd_gmerge(Command):
400
392
    """ GTK+ merge dialog
401
393
    
481
473
        window = TagsWindow(br)
482
474
        window.show()
483
475
        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()