/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,
20
 
    merge_directive,
 
19
    errors,
21
20
    workingtree,
22
21
    )
23
22
from bzrlib.commands import (
26
25
    )
27
26
from bzrlib.errors import (
28
27
    BzrCommandError,
 
28
    NoWorkingTree,
29
29
    NotVersionedError,
30
30
    NoSuchFile,
31
31
    )
32
32
from bzrlib.option import Option
33
33
 
34
34
from bzrlib.plugins.gtk import (
35
 
    open_display,
36
 
    import_pygtk,
37
35
    set_ui_factory,
38
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
 
39
57
 
40
58
class GTKCommand(Command):
41
59
    """Abstract class providing GTK specific run commands."""
130
148
                tree2 = tree1.basis_tree()
131
149
 
132
150
            from diff import DiffWindow
133
 
            import gtk
 
151
            from gi.repository import Gtk
134
152
            window = DiffWindow()
135
 
            window.connect("destroy", gtk.main_quit)
 
153
            window.connect("destroy", Gtk.main_quit)
136
154
            window.set_diff("Working Tree", tree1, tree2)
137
155
            if filename is not None:
138
156
                tree_filename = wt.relpath(filename)
146
164
                                          filename)
147
165
            window.show()
148
166
 
149
 
            gtk.main()
 
167
            Gtk.main()
150
168
        finally:
151
169
            wt.unlock()
152
170
 
161
179
 
162
180
 
163
181
class cmd_visualise(Command):
164
 
    """Graphically visualise this branch.
165
 
 
166
 
    Opens a graphical window to allow you to see the history of the branch
167
 
    and relationships between revisions in a visual manner,
168
 
 
169
 
    The default starting point is latest revision on the branch, you can
170
 
    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).
171
191
    """
172
192
    takes_options = [
173
193
        "revision",
187
207
                revids.append(br.last_revision())
188
208
            else:
189
209
                revids.append(revision[0].as_revision_id(br))
190
 
        import gtk
 
210
        from gi.repository import Gtk
191
211
        pp = start_viz_window(br, revids, limit)
192
 
        pp.connect("destroy", lambda w: gtk.main_quit())
 
212
        pp.connect("destroy", lambda w: Gtk.main_quit())
193
213
        pp.show()
194
 
        gtk.main()
 
214
        Gtk.main()
195
215
 
196
216
 
197
217
class cmd_gannotate(GTKCommand):
198
218
    """GTK+ annotate.
199
219
    
200
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.
201
224
    """
202
225
 
203
226
    takes_args = ["filename", "line?"]
211
234
    aliases = ["gblame", "gpraise"]
212
235
    
213
236
    def run(self, filename, all=False, plain=False, line='1', revision=None):
214
 
        gtk = open_display()
 
237
        Gtk = open_display()
215
238
 
216
239
        try:
217
240
            line = int(line)
242
265
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
243
266
 
244
267
        window = GAnnotateWindow(all, plain, branch=br)
245
 
        window.connect("destroy", lambda w: gtk.main_quit())
 
268
        window.connect("destroy", lambda w: Gtk.main_quit())
246
269
        config = GAnnotateConfig(window)
247
270
        window.show()
248
271
        br.lock_read()
251
274
        try:
252
275
            window.annotate(tree, br, file_id)
253
276
            window.jump_to_line(line)
254
 
            gtk.main()
 
277
            Gtk.main()
255
278
        finally:
256
279
            br.unlock()
257
280
            if wt is not None:
269
292
    takes_options = []
270
293
 
271
294
    def run(self, filename=None):
272
 
        import os
273
295
        open_display()
274
296
        from commit import CommitDialog
275
 
        from bzrlib.errors import (BzrCommandError,
276
 
                                   NotBranchError,
277
 
                                   NoWorkingTree)
278
297
 
279
298
        wt = None
280
299
        br = None
310
329
    takes_options = ['revision']
311
330
 
312
331
    def run(self, path='.', revision=None):
313
 
        import os
314
 
        gtk = open_display()
 
332
        Gtk = open_display()
315
333
        from bzrlib.plugins.gtk.status import StatusWindow
316
334
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
317
335
 
326
344
            revision_id = None
327
345
 
328
346
        status = StatusWindow(wt, wt_path, revision_id)
329
 
        status.connect("destroy", gtk.main_quit)
 
347
        status.connect("destroy", Gtk.main_quit)
330
348
        status.show()
331
 
        gtk.main()
 
349
        Gtk.main()
332
350
 
333
351
 
334
352
class cmd_gsend(GTKCommand):
337
355
    """
338
356
    def run(self):
339
357
        (br, path) = branch.Branch.open_containing(".")
340
 
        gtk = open_display()
 
358
        Gtk = open_display()
341
359
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
342
360
        from StringIO import StringIO
343
361
        dialog = SendMergeDirectiveDialog(br)
344
 
        if dialog.run() == gtk.RESPONSE_OK:
 
362
        if dialog.run() == Gtk.ResponseType.OK:
345
363
            outf = StringIO()
346
364
            outf.writelines(dialog.get_merge_directive().to_lines())
347
365
            mail_client = br.get_config().get_mail_client()
376
394
        dialog.run()
377
395
 
378
396
 
379
 
class cmd_ginfo(Command):
380
 
    """ GTK+ info dialog
381
 
    
382
 
    """
383
 
    def run(self):
384
 
        from bzrlib import workingtree
385
 
        from bzrlib.plugins.gtk.olive.info import InfoDialog
386
 
        wt = workingtree.WorkingTree.open_containing('.')[0]
387
 
        info = InfoDialog(wt.branch)
388
 
        info.display()
389
 
        info.window.run()
390
 
 
391
 
 
392
397
class cmd_gmerge(Command):
393
398
    """ GTK+ merge dialog
394
399
    
417
422
    """
418
423
    takes_args = ["other_branch?"]
419
424
    def run(self, other_branch=None):
420
 
        pygtk = import_pygtk()
421
425
        try:
422
 
            import gtk
 
426
            from gi.repository import Gtk
423
427
        except RuntimeError, e:
424
428
            if str(e) == "could not open display":
425
429
                raise NoDisplayError
432
436
            other_branch = local_branch.get_parent()
433
437
            
434
438
            if other_branch is None:
435
 
                raise errors.BzrCommandError("No peer location known or specified.")
 
439
                raise BzrCommandError("No peer location known or specified.")
436
440
        remote_branch = Branch.open_containing(other_branch)[0]
437
441
        set_ui_factory()
438
442
        local_branch.lock_read()
448
452
 
449
453
 
450
454
class cmd_ginit(GTKCommand):
 
455
    """ GTK+ init dialog
 
456
 
 
457
    Graphical user interface for initializing new branches.
 
458
 
 
459
    """
451
460
    def run(self):
452
461
        open_display()
453
462
        from initialize import InitDialog
456
465
 
457
466
 
458
467
class cmd_gtags(GTKCommand):
 
468
    """ GTK+ tags dialog 
 
469
 
 
470
    Graphical user interface to view, create, or remove tags.
 
471
 
 
472
    """
459
473
    def run(self):
460
474
        br = branch.Branch.open_containing('.')[0]
461
475
        
462
 
        gtk = open_display()
 
476
        Gtk = open_display()
463
477
        from tags import TagsWindow
464
478
        window = TagsWindow(br)
465
479
        window.show()
466
 
        gtk.main()
467
 
 
468
 
 
469
 
class cmd_gselftest(GTKCommand):
470
 
    """Version of selftest that displays a notification at the end"""
471
 
 
472
 
    takes_args = builtins.cmd_selftest.takes_args
473
 
    takes_options = builtins.cmd_selftest.takes_options
474
 
    _see_also = ['selftest']
475
 
 
476
 
    def run(self, *args, **kwargs):
477
 
        import cgi
478
 
        import sys
479
 
        default_encoding = sys.getdefaultencoding()
480
 
        # prevent gtk from blowing up later
481
 
        gtk = import_pygtk()
482
 
        # prevent gtk from messing with default encoding
483
 
        import pynotify
484
 
        if sys.getdefaultencoding() != default_encoding:
485
 
            reload(sys)
486
 
            sys.setdefaultencoding(default_encoding)
487
 
        result = builtins.cmd_selftest().run(*args, **kwargs)
488
 
        if result == 0:
489
 
            summary = 'Success'
490
 
            body = 'Selftest succeeded in "%s"' % os.getcwd()
491
 
        if result == 1:
492
 
            summary = 'Failure'
493
 
            body = 'Selftest failed in "%s"' % os.getcwd()
494
 
        pynotify.init("bzr gselftest")
495
 
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
496
 
        note.set_timeout(pynotify.EXPIRES_NEVER)
497
 
        note.show()
 
480
        Gtk.main()