/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: 2012-07-09 15:23:26 UTC
  • mto: This revision was merged to the branch mainline in revision 794.
  • Revision ID: jelmer@samba.org-20120709152326-dzxb8zoz0btull7n
Remove bzr-notify.

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 (
32
32
from bzrlib.option import Option
33
33
 
34
34
from bzrlib.plugins.gtk import (
35
 
    _i18n,
36
 
    open_display,
37
 
    import_pygtk,
38
35
    set_ui_factory,
39
36
    )
 
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
 
40
57
 
41
58
class GTKCommand(Command):
42
59
    """Abstract class providing GTK specific run commands."""
131
148
                tree2 = tree1.basis_tree()
132
149
 
133
150
            from diff import DiffWindow
134
 
            import gtk
 
151
            from gi.repository import Gtk
135
152
            window = DiffWindow()
136
 
            window.connect("destroy", gtk.main_quit)
 
153
            window.connect("destroy", Gtk.main_quit)
137
154
            window.set_diff("Working Tree", tree1, tree2)
138
155
            if filename is not None:
139
156
                tree_filename = wt.relpath(filename)
147
164
                                          filename)
148
165
            window.show()
149
166
 
150
 
            gtk.main()
 
167
            Gtk.main()
151
168
        finally:
152
169
            wt.unlock()
153
170
 
162
179
 
163
180
 
164
181
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.
 
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).
172
191
    """
173
192
    takes_options = [
174
193
        "revision",
188
207
                revids.append(br.last_revision())
189
208
            else:
190
209
                revids.append(revision[0].as_revision_id(br))
191
 
        import gtk
 
210
        from gi.repository import Gtk
192
211
        pp = start_viz_window(br, revids, limit)
193
 
        pp.connect("destroy", lambda w: gtk.main_quit())
 
212
        pp.connect("destroy", lambda w: Gtk.main_quit())
194
213
        pp.show()
195
 
        gtk.main()
 
214
        Gtk.main()
196
215
 
197
216
 
198
217
class cmd_gannotate(GTKCommand):
199
218
    """GTK+ annotate.
200
219
    
201
220
    Browse changes to FILENAME line by line in a GTK+ window.
 
221
 
 
222
    Within the annotate window, you can use Ctrl-F to search for text, and 
 
223
    Ctrl-G to jump to a line by number.
202
224
    """
203
225
 
204
226
    takes_args = ["filename", "line?"]
212
234
    aliases = ["gblame", "gpraise"]
213
235
    
214
236
    def run(self, filename, all=False, plain=False, line='1', revision=None):
215
 
        gtk = open_display()
 
237
        Gtk = open_display()
216
238
 
217
239
        try:
218
240
            line = int(line)
243
265
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
244
266
 
245
267
        window = GAnnotateWindow(all, plain, branch=br)
246
 
        window.connect("destroy", lambda w: gtk.main_quit())
 
268
        window.connect("destroy", lambda w: Gtk.main_quit())
247
269
        config = GAnnotateConfig(window)
248
270
        window.show()
249
271
        br.lock_read()
252
274
        try:
253
275
            window.annotate(tree, br, file_id)
254
276
            window.jump_to_line(line)
255
 
            gtk.main()
 
277
            Gtk.main()
256
278
        finally:
257
279
            br.unlock()
258
280
            if wt is not None:
307
329
    takes_options = ['revision']
308
330
 
309
331
    def run(self, path='.', revision=None):
310
 
        gtk = open_display()
 
332
        Gtk = open_display()
311
333
        from bzrlib.plugins.gtk.status import StatusWindow
312
334
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
313
335
 
322
344
            revision_id = None
323
345
 
324
346
        status = StatusWindow(wt, wt_path, revision_id)
325
 
        status.connect("destroy", gtk.main_quit)
 
347
        status.connect("destroy", Gtk.main_quit)
326
348
        status.show()
327
 
        gtk.main()
 
349
        Gtk.main()
328
350
 
329
351
 
330
352
class cmd_gsend(GTKCommand):
333
355
    """
334
356
    def run(self):
335
357
        (br, path) = branch.Branch.open_containing(".")
336
 
        gtk = open_display()
 
358
        Gtk = open_display()
337
359
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
338
360
        from StringIO import StringIO
339
361
        dialog = SendMergeDirectiveDialog(br)
340
 
        if dialog.run() == gtk.RESPONSE_OK:
 
362
        if dialog.run() == Gtk.ResponseType.OK:
341
363
            outf = StringIO()
342
364
            outf.writelines(dialog.get_merge_directive().to_lines())
343
365
            mail_client = br.get_config().get_mail_client()
372
394
        dialog.run()
373
395
 
374
396
 
375
 
class cmd_ginfo(Command):
376
 
    """ GTK+ info dialog
377
 
    
378
 
    """
379
 
    def run(self):
380
 
        from bzrlib import workingtree
381
 
        from bzrlib.plugins.gtk.olive.info import InfoDialog
382
 
        wt = workingtree.WorkingTree.open_containing('.')[0]
383
 
        info = InfoDialog(wt.branch)
384
 
        info.display()
385
 
        info.window.run()
386
 
 
387
 
 
388
397
class cmd_gmerge(Command):
389
398
    """ GTK+ merge dialog
390
399
    
413
422
    """
414
423
    takes_args = ["other_branch?"]
415
424
    def run(self, other_branch=None):
416
 
        pygtk = import_pygtk()
417
425
        try:
418
 
            import gtk
 
426
            from gi.repository import Gtk
419
427
        except RuntimeError, e:
420
428
            if str(e) == "could not open display":
421
429
                raise NoDisplayError
444
452
 
445
453
 
446
454
class cmd_ginit(GTKCommand):
 
455
    """ GTK+ init dialog
 
456
 
 
457
    Graphical user interface for initializing new branches.
 
458
 
 
459
    """
447
460
    def run(self):
448
461
        open_display()
449
462
        from initialize import InitDialog
452
465
 
453
466
 
454
467
class cmd_gtags(GTKCommand):
 
468
    """ GTK+ tags dialog 
 
469
 
 
470
    Graphical user interface to view, create, or remove tags.
 
471
 
 
472
    """
455
473
    def run(self):
456
474
        br = branch.Branch.open_containing('.')[0]
457
475
        
458
 
        gtk = open_display()
 
476
        Gtk = open_display()
459
477
        from tags import TagsWindow
460
478
        window = TagsWindow(br)
461
479
        window.show()
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()
 
480
        Gtk.main()