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