/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: 2010-08-21 09:32:13 UTC
  • mto: This revision was merged to the branch mainline in revision 719.
  • Revision ID: david.planella@ubuntu.com-20100821093213-njpqd5sploa8n71m
Adapted desktop entries for translation

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,
 
37
    import_pygtk,
35
38
    set_ui_factory,
36
39
    )
37
 
from bzrlib.plugins.gtk.i18n import _i18n
38
 
 
39
 
 
40
 
class NoDisplayError(errors.BzrCommandError):
41
 
    """gtk could not find a proper display"""
42
 
 
43
 
    def __str__(self):
44
 
        return "No DISPLAY. Unable to run GTK+ application."
45
 
 
46
 
 
47
 
def open_display():
48
 
    try:
49
 
        from gi.repository import Gtk
50
 
    except RuntimeError, e:
51
 
        if str(e) == "could not open display":
52
 
            raise NoDisplayError
53
 
    set_ui_factory()
54
 
    return Gtk
55
 
 
56
 
 
57
40
 
58
41
class GTKCommand(Command):
59
42
    """Abstract class providing GTK specific run commands."""
148
131
                tree2 = tree1.basis_tree()
149
132
 
150
133
            from diff import DiffWindow
151
 
            from gi.repository import Gtk
 
134
            import gtk
152
135
            window = DiffWindow()
153
 
            window.connect("destroy", Gtk.main_quit)
 
136
            window.connect("destroy", gtk.main_quit)
154
137
            window.set_diff("Working Tree", tree1, tree2)
155
138
            if filename is not None:
156
139
                tree_filename = wt.relpath(filename)
164
147
                                          filename)
165
148
            window.show()
166
149
 
167
 
            Gtk.main()
 
150
            gtk.main()
168
151
        finally:
169
152
            wt.unlock()
170
153
 
179
162
 
180
163
 
181
164
class cmd_visualise(Command):
182
 
    """Graphically visualise one or several branches.
183
 
 
184
 
    Opens a graphical window to allow you to see branches history and
185
 
    relationships between revisions in a visual manner,
186
 
 
187
 
    If no revision is specified, the branch last revision is taken as a
188
 
    starting point. When a revision is specified, the presented graph starts
189
 
    with it (as a side effect, when a shared repository is used, any revision
190
 
    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.
191
172
    """
192
173
    takes_options = [
193
174
        "revision",
207
188
                revids.append(br.last_revision())
208
189
            else:
209
190
                revids.append(revision[0].as_revision_id(br))
210
 
        from gi.repository import Gtk
 
191
        import gtk
211
192
        pp = start_viz_window(br, revids, limit)
212
 
        pp.connect("destroy", lambda w: Gtk.main_quit())
 
193
        pp.connect("destroy", lambda w: gtk.main_quit())
213
194
        pp.show()
214
 
        Gtk.main()
 
195
        gtk.main()
215
196
 
216
197
 
217
198
class cmd_gannotate(GTKCommand):
234
215
    aliases = ["gblame", "gpraise"]
235
216
    
236
217
    def run(self, filename, all=False, plain=False, line='1', revision=None):
237
 
        Gtk = open_display()
 
218
        gtk = open_display()
238
219
 
239
220
        try:
240
221
            line = int(line)
265
246
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
266
247
 
267
248
        window = GAnnotateWindow(all, plain, branch=br)
268
 
        window.connect("destroy", lambda w: Gtk.main_quit())
 
249
        window.connect("destroy", lambda w: gtk.main_quit())
269
250
        config = GAnnotateConfig(window)
270
251
        window.show()
271
252
        br.lock_read()
274
255
        try:
275
256
            window.annotate(tree, br, file_id)
276
257
            window.jump_to_line(line)
277
 
            Gtk.main()
 
258
            gtk.main()
278
259
        finally:
279
260
            br.unlock()
280
261
            if wt is not None:
329
310
    takes_options = ['revision']
330
311
 
331
312
    def run(self, path='.', revision=None):
332
 
        Gtk = open_display()
 
313
        gtk = open_display()
333
314
        from bzrlib.plugins.gtk.status import StatusWindow
334
315
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
335
316
 
344
325
            revision_id = None
345
326
 
346
327
        status = StatusWindow(wt, wt_path, revision_id)
347
 
        status.connect("destroy", Gtk.main_quit)
 
328
        status.connect("destroy", gtk.main_quit)
348
329
        status.show()
349
 
        Gtk.main()
 
330
        gtk.main()
350
331
 
351
332
 
352
333
class cmd_gsend(GTKCommand):
355
336
    """
356
337
    def run(self):
357
338
        (br, path) = branch.Branch.open_containing(".")
358
 
        Gtk = open_display()
 
339
        gtk = open_display()
359
340
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
360
341
        from StringIO import StringIO
361
342
        dialog = SendMergeDirectiveDialog(br)
362
 
        if dialog.run() == Gtk.ResponseType.OK:
 
343
        if dialog.run() == gtk.RESPONSE_OK:
363
344
            outf = StringIO()
364
345
            outf.writelines(dialog.get_merge_directive().to_lines())
365
346
            mail_client = br.get_config().get_mail_client()
422
403
    """
423
404
    takes_args = ["other_branch?"]
424
405
    def run(self, other_branch=None):
 
406
        pygtk = import_pygtk()
425
407
        try:
426
 
            from gi.repository import Gtk
 
408
            import gtk
427
409
        except RuntimeError, e:
428
410
            if str(e) == "could not open display":
429
411
                raise NoDisplayError
473
455
    def run(self):
474
456
        br = branch.Branch.open_containing('.')[0]
475
457
        
476
 
        Gtk = open_display()
 
458
        gtk = open_display()
477
459
        from tags import TagsWindow
478
460
        window = TagsWindow(br)
479
461
        window.show()
480
 
        Gtk.main()
 
462
        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()