/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: Mark Lee
  • Date: 2009-07-10 20:07:43 UTC
  • mto: This revision was merged to the branch mainline in revision 661.
  • Revision ID: bzr@lazymalevolence.com-20090710200743-2s9x0xa8jgs9wf8s
Remove credits.pickle (generated file).

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
    merge_directive,
20
21
    workingtree,
21
22
    )
22
23
from bzrlib.commands import (
25
26
    )
26
27
from bzrlib.errors import (
27
28
    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,
35
37
    set_ui_factory,
36
38
    )
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
39
 
58
40
class GTKCommand(Command):
59
41
    """Abstract class providing GTK specific run commands."""
148
130
                tree2 = tree1.basis_tree()
149
131
 
150
132
            from diff import DiffWindow
151
 
            from gi.repository import Gtk
 
133
            import gtk
152
134
            window = DiffWindow()
153
 
            window.connect("destroy", Gtk.main_quit)
 
135
            window.connect("destroy", gtk.main_quit)
154
136
            window.set_diff("Working Tree", tree1, tree2)
155
137
            if filename is not None:
156
138
                tree_filename = wt.relpath(filename)
164
146
                                          filename)
165
147
            window.show()
166
148
 
167
 
            Gtk.main()
 
149
            gtk.main()
168
150
        finally:
169
151
            wt.unlock()
170
152
 
179
161
 
180
162
 
181
163
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).
 
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.
191
171
    """
192
172
    takes_options = [
193
173
        "revision",
207
187
                revids.append(br.last_revision())
208
188
            else:
209
189
                revids.append(revision[0].as_revision_id(br))
210
 
        from gi.repository import Gtk
 
190
        import gtk
211
191
        pp = start_viz_window(br, revids, limit)
212
 
        pp.connect("destroy", lambda w: Gtk.main_quit())
 
192
        pp.connect("destroy", lambda w: gtk.main_quit())
213
193
        pp.show()
214
 
        Gtk.main()
 
194
        gtk.main()
215
195
 
216
196
 
217
197
class cmd_gannotate(GTKCommand):
218
198
    """GTK+ annotate.
219
199
    
220
200
    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.
224
201
    """
225
202
 
226
203
    takes_args = ["filename", "line?"]
234
211
    aliases = ["gblame", "gpraise"]
235
212
    
236
213
    def run(self, filename, all=False, plain=False, line='1', revision=None):
237
 
        Gtk = open_display()
 
214
        gtk = open_display()
238
215
 
239
216
        try:
240
217
            line = int(line)
265
242
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
266
243
 
267
244
        window = GAnnotateWindow(all, plain, branch=br)
268
 
        window.connect("destroy", lambda w: Gtk.main_quit())
 
245
        window.connect("destroy", lambda w: gtk.main_quit())
269
246
        config = GAnnotateConfig(window)
270
247
        window.show()
271
248
        br.lock_read()
274
251
        try:
275
252
            window.annotate(tree, br, file_id)
276
253
            window.jump_to_line(line)
277
 
            Gtk.main()
 
254
            gtk.main()
278
255
        finally:
279
256
            br.unlock()
280
257
            if wt is not None:
292
269
    takes_options = []
293
270
 
294
271
    def run(self, filename=None):
 
272
        import os
295
273
        open_display()
296
274
        from commit import CommitDialog
 
275
        from bzrlib.errors import (BzrCommandError,
 
276
                                   NotBranchError,
 
277
                                   NoWorkingTree)
297
278
 
298
279
        wt = None
299
280
        br = None
329
310
    takes_options = ['revision']
330
311
 
331
312
    def run(self, path='.', revision=None):
332
 
        Gtk = open_display()
 
313
        import os
 
314
        gtk = open_display()
333
315
        from bzrlib.plugins.gtk.status import StatusWindow
334
316
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
335
317
 
344
326
            revision_id = None
345
327
 
346
328
        status = StatusWindow(wt, wt_path, revision_id)
347
 
        status.connect("destroy", Gtk.main_quit)
 
329
        status.connect("destroy", gtk.main_quit)
348
330
        status.show()
349
 
        Gtk.main()
 
331
        gtk.main()
350
332
 
351
333
 
352
334
class cmd_gsend(GTKCommand):
355
337
    """
356
338
    def run(self):
357
339
        (br, path) = branch.Branch.open_containing(".")
358
 
        Gtk = open_display()
 
340
        gtk = open_display()
359
341
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
360
342
        from StringIO import StringIO
361
343
        dialog = SendMergeDirectiveDialog(br)
362
 
        if dialog.run() == Gtk.ResponseType.OK:
 
344
        if dialog.run() == gtk.RESPONSE_OK:
363
345
            outf = StringIO()
364
346
            outf.writelines(dialog.get_merge_directive().to_lines())
365
347
            mail_client = br.get_config().get_mail_client()
394
376
        dialog.run()
395
377
 
396
378
 
 
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
 
397
392
class cmd_gmerge(Command):
398
393
    """ GTK+ merge dialog
399
394
    
422
417
    """
423
418
    takes_args = ["other_branch?"]
424
419
    def run(self, other_branch=None):
 
420
        pygtk = import_pygtk()
425
421
        try:
426
 
            from gi.repository import Gtk
 
422
            import gtk
427
423
        except RuntimeError, e:
428
424
            if str(e) == "could not open display":
429
425
                raise NoDisplayError
436
432
            other_branch = local_branch.get_parent()
437
433
            
438
434
            if other_branch is None:
439
 
                raise BzrCommandError("No peer location known or specified.")
 
435
                raise errors.BzrCommandError("No peer location known or specified.")
440
436
        remote_branch = Branch.open_containing(other_branch)[0]
441
437
        set_ui_factory()
442
438
        local_branch.lock_read()
452
448
 
453
449
 
454
450
class cmd_ginit(GTKCommand):
455
 
    """ GTK+ init dialog
456
 
 
457
 
    Graphical user interface for initializing new branches.
458
 
 
459
 
    """
460
451
    def run(self):
461
452
        open_display()
462
453
        from initialize import InitDialog
465
456
 
466
457
 
467
458
class cmd_gtags(GTKCommand):
468
 
    """ GTK+ tags dialog 
469
 
 
470
 
    Graphical user interface to view, create, or remove tags.
471
 
 
472
 
    """
473
459
    def run(self):
474
460
        br = branch.Branch.open_containing('.')[0]
475
461
        
476
 
        Gtk = open_display()
 
462
        gtk = open_display()
477
463
        from tags import TagsWindow
478
464
        window = TagsWindow(br)
479
465
        window.show()
480
 
        Gtk.main()
 
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()