/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: Szilveszter Farkas
  • Date: 2009-05-26 13:58:24 UTC
  • mto: (635.2.6 trunk)
  • mto: This revision was merged to the branch mainline in revision 639.
  • Revision ID: szilveszter.farkas@gmail.com-20090526135824-fwvt03uqtl2p6vk7
Updated the README entry about GtkSourceView.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# along with this program; if not, write to the Free Software
13
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
14
 
15
 
import os
16
 
 
17
15
from bzrlib import (
18
16
    branch,
19
 
    errors,
 
17
    builtins,
 
18
    merge_directive,
20
19
    workingtree,
21
20
    )
22
21
from bzrlib.commands import (
25
24
    )
26
25
from bzrlib.errors import (
27
26
    BzrCommandError,
28
 
    NoWorkingTree,
29
27
    NotVersionedError,
30
28
    NoSuchFile,
31
29
    )
32
30
from bzrlib.option import Option
33
31
 
34
32
from bzrlib.plugins.gtk import (
 
33
    open_display,
 
34
    import_pygtk,
35
35
    set_ui_factory,
36
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
 
 
57
37
 
58
38
class GTKCommand(Command):
59
39
    """Abstract class providing GTK specific run commands."""
148
128
                tree2 = tree1.basis_tree()
149
129
 
150
130
            from diff import DiffWindow
151
 
            from gi.repository import Gtk
 
131
            import gtk
152
132
            window = DiffWindow()
153
 
            window.connect("destroy", Gtk.main_quit)
 
133
            window.connect("destroy", gtk.main_quit)
154
134
            window.set_diff("Working Tree", tree1, tree2)
155
135
            if filename is not None:
156
136
                tree_filename = wt.relpath(filename)
164
144
                                          filename)
165
145
            window.show()
166
146
 
167
 
            Gtk.main()
 
147
            gtk.main()
168
148
        finally:
169
149
            wt.unlock()
170
150
 
179
159
 
180
160
 
181
161
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).
 
162
    """Graphically visualise this branch.
 
163
 
 
164
    Opens a graphical window to allow you to see the history of the branch
 
165
    and relationships between revisions in a visual manner,
 
166
 
 
167
    The default starting point is latest revision on the branch, you can
 
168
    specify a starting point with -r revision.
191
169
    """
192
170
    takes_options = [
193
171
        "revision",
207
185
                revids.append(br.last_revision())
208
186
            else:
209
187
                revids.append(revision[0].as_revision_id(br))
210
 
        from gi.repository import Gtk
 
188
        import gtk
211
189
        pp = start_viz_window(br, revids, limit)
212
 
        pp.connect("destroy", lambda w: Gtk.main_quit())
 
190
        pp.connect("destroy", lambda w: gtk.main_quit())
213
191
        pp.show()
214
 
        Gtk.main()
 
192
        gtk.main()
215
193
 
216
194
 
217
195
class cmd_gannotate(GTKCommand):
218
196
    """GTK+ annotate.
219
197
    
220
198
    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
199
    """
225
200
 
226
201
    takes_args = ["filename", "line?"]
234
209
    aliases = ["gblame", "gpraise"]
235
210
    
236
211
    def run(self, filename, all=False, plain=False, line='1', revision=None):
237
 
        Gtk = open_display()
 
212
        gtk = open_display()
238
213
 
239
214
        try:
240
215
            line = int(line)
265
240
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
266
241
 
267
242
        window = GAnnotateWindow(all, plain, branch=br)
268
 
        window.connect("destroy", lambda w: Gtk.main_quit())
 
243
        window.connect("destroy", lambda w: gtk.main_quit())
269
244
        config = GAnnotateConfig(window)
270
245
        window.show()
271
246
        br.lock_read()
274
249
        try:
275
250
            window.annotate(tree, br, file_id)
276
251
            window.jump_to_line(line)
277
 
            Gtk.main()
 
252
            gtk.main()
278
253
        finally:
279
254
            br.unlock()
280
255
            if wt is not None:
292
267
    takes_options = []
293
268
 
294
269
    def run(self, filename=None):
 
270
        import os
295
271
        open_display()
296
272
        from commit import CommitDialog
 
273
        from bzrlib.errors import (BzrCommandError,
 
274
                                   NotBranchError,
 
275
                                   NoWorkingTree)
297
276
 
298
277
        wt = None
299
278
        br = None
329
308
    takes_options = ['revision']
330
309
 
331
310
    def run(self, path='.', revision=None):
332
 
        Gtk = open_display()
 
311
        import os
 
312
        gtk = open_display()
333
313
        from bzrlib.plugins.gtk.status import StatusWindow
334
314
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
335
315
 
344
324
            revision_id = None
345
325
 
346
326
        status = StatusWindow(wt, wt_path, revision_id)
347
 
        status.connect("destroy", Gtk.main_quit)
 
327
        status.connect("destroy", gtk.main_quit)
348
328
        status.show()
349
 
        Gtk.main()
 
329
        gtk.main()
350
330
 
351
331
 
352
332
class cmd_gsend(GTKCommand):
355
335
    """
356
336
    def run(self):
357
337
        (br, path) = branch.Branch.open_containing(".")
358
 
        Gtk = open_display()
 
338
        gtk = open_display()
359
339
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
360
340
        from StringIO import StringIO
361
341
        dialog = SendMergeDirectiveDialog(br)
362
 
        if dialog.run() == Gtk.ResponseType.OK:
 
342
        if dialog.run() == gtk.RESPONSE_OK:
363
343
            outf = StringIO()
364
344
            outf.writelines(dialog.get_merge_directive().to_lines())
365
345
            mail_client = br.get_config().get_mail_client()
394
374
        dialog.run()
395
375
 
396
376
 
 
377
class cmd_ginfo(Command):
 
378
    """ GTK+ info dialog
 
379
    
 
380
    """
 
381
    def run(self):
 
382
        from bzrlib import workingtree
 
383
        from bzrlib.plugins.gtk.olive.info import InfoDialog
 
384
        wt = workingtree.WorkingTree.open_containing('.')[0]
 
385
        info = InfoDialog(wt.branch)
 
386
        info.display()
 
387
        info.window.run()
 
388
 
 
389
 
397
390
class cmd_gmerge(Command):
398
391
    """ GTK+ merge dialog
399
392
    
422
415
    """
423
416
    takes_args = ["other_branch?"]
424
417
    def run(self, other_branch=None):
 
418
        pygtk = import_pygtk()
425
419
        try:
426
 
            from gi.repository import Gtk
 
420
            import gtk
427
421
        except RuntimeError, e:
428
422
            if str(e) == "could not open display":
429
423
                raise NoDisplayError
436
430
            other_branch = local_branch.get_parent()
437
431
            
438
432
            if other_branch is None:
439
 
                raise BzrCommandError("No peer location known or specified.")
 
433
                raise errors.BzrCommandError("No peer location known or specified.")
440
434
        remote_branch = Branch.open_containing(other_branch)[0]
441
435
        set_ui_factory()
442
436
        local_branch.lock_read()
452
446
 
453
447
 
454
448
class cmd_ginit(GTKCommand):
455
 
    """ GTK+ init dialog
456
 
 
457
 
    Graphical user interface for initializing new branches.
458
 
 
459
 
    """
460
449
    def run(self):
461
450
        open_display()
462
451
        from initialize import InitDialog
465
454
 
466
455
 
467
456
class cmd_gtags(GTKCommand):
468
 
    """ GTK+ tags dialog 
469
 
 
470
 
    Graphical user interface to view, create, or remove tags.
471
 
 
472
 
    """
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()