/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: 2010-12-17 22:48:28 UTC
  • Revision ID: jelmer@samba.org-20101217224828-qswc8wgf2dd0h0jv
remove some unused imports.

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
 
207
190
                revids.append(br.last_revision())
208
191
            else:
209
192
                revids.append(revision[0].as_revision_id(br))
210
 
        from gi.repository import Gtk
 
193
        import gtk
211
194
        pp = start_viz_window(br, revids, limit)
212
 
        pp.connect("destroy", lambda w: Gtk.main_quit())
 
195
        pp.connect("destroy", lambda w: gtk.main_quit())
213
196
        pp.show()
214
 
        Gtk.main()
 
197
        gtk.main()
215
198
 
216
199
 
217
200
class cmd_gannotate(GTKCommand):
234
217
    aliases = ["gblame", "gpraise"]
235
218
    
236
219
    def run(self, filename, all=False, plain=False, line='1', revision=None):
237
 
        Gtk = open_display()
 
220
        gtk = open_display()
238
221
 
239
222
        try:
240
223
            line = int(line)
265
248
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
266
249
 
267
250
        window = GAnnotateWindow(all, plain, branch=br)
268
 
        window.connect("destroy", lambda w: Gtk.main_quit())
 
251
        window.connect("destroy", lambda w: gtk.main_quit())
269
252
        config = GAnnotateConfig(window)
270
253
        window.show()
271
254
        br.lock_read()
274
257
        try:
275
258
            window.annotate(tree, br, file_id)
276
259
            window.jump_to_line(line)
277
 
            Gtk.main()
 
260
            gtk.main()
278
261
        finally:
279
262
            br.unlock()
280
263
            if wt is not None:
329
312
    takes_options = ['revision']
330
313
 
331
314
    def run(self, path='.', revision=None):
332
 
        Gtk = open_display()
 
315
        gtk = open_display()
333
316
        from bzrlib.plugins.gtk.status import StatusWindow
334
317
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
335
318
 
344
327
            revision_id = None
345
328
 
346
329
        status = StatusWindow(wt, wt_path, revision_id)
347
 
        status.connect("destroy", Gtk.main_quit)
 
330
        status.connect("destroy", gtk.main_quit)
348
331
        status.show()
349
 
        Gtk.main()
 
332
        gtk.main()
350
333
 
351
334
 
352
335
class cmd_gsend(GTKCommand):
355
338
    """
356
339
    def run(self):
357
340
        (br, path) = branch.Branch.open_containing(".")
358
 
        Gtk = open_display()
 
341
        gtk = open_display()
359
342
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
360
343
        from StringIO import StringIO
361
344
        dialog = SendMergeDirectiveDialog(br)
362
 
        if dialog.run() == Gtk.ResponseType.OK:
 
345
        if dialog.run() == gtk.RESPONSE_OK:
363
346
            outf = StringIO()
364
347
            outf.writelines(dialog.get_merge_directive().to_lines())
365
348
            mail_client = br.get_config().get_mail_client()
422
405
    """
423
406
    takes_args = ["other_branch?"]
424
407
    def run(self, other_branch=None):
 
408
        pygtk = import_pygtk()
425
409
        try:
426
 
            from gi.repository import Gtk
 
410
            import gtk
427
411
        except RuntimeError, e:
428
412
            if str(e) == "could not open display":
429
413
                raise NoDisplayError
473
457
    def run(self):
474
458
        br = branch.Branch.open_containing('.')[0]
475
459
        
476
 
        Gtk = open_display()
 
460
        gtk = open_display()
477
461
        from tags import TagsWindow
478
462
        window = TagsWindow(br)
479
463
        window.show()
480
 
        Gtk.main()
 
464
        gtk.main()
 
465
 
 
466
 
 
467
class cmd_gselftest(GTKCommand):
 
468
    """Version of selftest that displays a notification at the end"""
 
469
 
 
470
    takes_args = builtins.cmd_selftest.takes_args
 
471
    takes_options = builtins.cmd_selftest.takes_options
 
472
    _see_also = ['selftest']
 
473
 
 
474
    def run(self, *args, **kwargs):
 
475
        import cgi
 
476
        import sys
 
477
        default_encoding = sys.getdefaultencoding()
 
478
        # prevent gtk from blowing up later
 
479
        gtk = import_pygtk()
 
480
        # prevent gtk from messing with default encoding
 
481
        import pynotify
 
482
        if sys.getdefaultencoding() != default_encoding:
 
483
            reload(sys)
 
484
            sys.setdefaultencoding(default_encoding)
 
485
        result = builtins.cmd_selftest().run(*args, **kwargs)
 
486
        if result == 0:
 
487
            summary = 'Success'
 
488
            body = 'Selftest succeeded in "%s"' % os.getcwd()
 
489
        if result == 1:
 
490
            summary = 'Failure'
 
491
            body = 'Selftest failed in "%s"' % os.getcwd()
 
492
        pynotify.init("bzr gselftest")
 
493
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
 
494
        note.set_timeout(pynotify.EXPIRES_NEVER)
 
495
        note.show()