/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: David Planella
  • Date: 2011-03-06 08:24:07 UTC
  • mfrom: (718 trunk)
  • mto: This revision was merged to the branch mainline in revision 719.
  • Revision ID: david.planella@ubuntu.com-20110306082407-y9zwkjje5oue9egw
Added preliminary internationalization support. Merged from trunk.

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",
460
481
        window = TagsWindow(br)
461
482
        window.show()
462
483
        gtk.main()
463
 
 
464
 
 
465
 
class cmd_gselftest(GTKCommand):
466
 
    """Version of selftest that displays a notification at the end"""
467
 
 
468
 
    takes_args = builtins.cmd_selftest.takes_args
469
 
    takes_options = builtins.cmd_selftest.takes_options
470
 
    _see_also = ['selftest']
471
 
 
472
 
    def run(self, *args, **kwargs):
473
 
        import cgi
474
 
        import sys
475
 
        default_encoding = sys.getdefaultencoding()
476
 
        # prevent gtk from blowing up later
477
 
        gtk = import_pygtk()
478
 
        # prevent gtk from messing with default encoding
479
 
        import pynotify
480
 
        if sys.getdefaultencoding() != default_encoding:
481
 
            reload(sys)
482
 
            sys.setdefaultencoding(default_encoding)
483
 
        result = builtins.cmd_selftest().run(*args, **kwargs)
484
 
        if result == 0:
485
 
            summary = 'Success'
486
 
            body = 'Selftest succeeded in "%s"' % os.getcwd()
487
 
        if result == 1:
488
 
            summary = 'Failure'
489
 
            body = 'Selftest failed in "%s"' % os.getcwd()
490
 
        pynotify.init("bzr gselftest")
491
 
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
492
 
        note.set_timeout(pynotify.EXPIRES_NEVER)
493
 
        note.show()