/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 __init__.py

  • Committer: Mateusz Korniak
  • Date: 2007-07-21 13:16:33 UTC
  • mto: This revision was merged to the branch mainline in revision 248.
  • Revision ID: matkor@laptop-hp-20070721131633-t40kxs20j1q2fvvc
Context menu "Remove and delete added"
Acts like "Remove" but also deletes file locally.

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
 
"""GTK+ frontends to Bazaar commands """
 
15
"""Graphical support for Bazaar using GTK.
 
16
 
 
17
This plugin includes:
 
18
commit-notify     Start the graphical notifier of commits.
 
19
gannotate         GTK+ annotate. 
 
20
gbranch           GTK+ branching. 
 
21
gcheckout         GTK+ checkout. 
 
22
gcommit           GTK+ commit dialog 
 
23
gconflicts        GTK+ push. 
 
24
gdiff             Show differences in working tree in a GTK+ Window. 
 
25
ginit             Initialise a new branch.
 
26
gmissing          GTK+ missing revisions dialog. 
 
27
gpreferences      GTK+ preferences dialog. 
 
28
gpush             GTK+ push. 
 
29
gstatus           GTK+ status dialog 
 
30
gtags             Manage branch tags.
 
31
visualise         Graphically visualise this branch. 
 
32
"""
16
33
 
17
34
import bzrlib
18
35
 
19
 
__version__ = '0.15.0'
 
36
__version__ = '0.19.0'
20
37
version_info = tuple(int(n) for n in __version__.split('.'))
21
38
 
22
39
 
30
47
    """
31
48
    desired_plus = (desired[0], desired[1]+1)
32
49
    bzrlib_version = bzrlib.version_info[:2]
33
 
    if bzrlib_version == desired:
 
50
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
 
51
                                     bzrlib.version_info[3] == 'dev'):
34
52
        return
35
53
    try:
36
54
        from bzrlib.trace import warning
38
56
        # get the message out any way we can
39
57
        from warnings import warn as warning
40
58
    if bzrlib_version < desired:
 
59
        from bzrlib.errors import BzrError
41
60
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
61
                ' %s.' % (bzrlib.__version__, __version__))
43
 
        # Not using BzrNewError, because it may not exist.
44
 
        raise Exception, ('Version mismatch', version_info)
 
62
        raise BzrError('Version mismatch: %r' % version_info)
45
63
    else:
46
64
        warning('bzr-gtk is not up to date with installed bzr version %s.'
47
65
                ' \nThere should be a newer version available, e.g. %i.%i.' 
48
66
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
 
        if bzrlib_version != desired_plus:
50
 
            raise Exception, 'Version mismatch'
51
 
 
52
 
 
53
 
check_bzrlib_version(version_info[:2])
54
 
 
55
 
from bzrlib import errors
 
67
 
 
68
 
 
69
## check_bzrlib_version(version_info[:2]) REMOVE
 
70
 
 
71
from bzrlib.trace import warning
 
72
if __name__ != 'bzrlib.plugins.gtk':
 
73
    warning("Not running as bzrlib.plugins.gtk, things may break.")
 
74
 
 
75
from bzrlib.lazy_import import lazy_import
 
76
lazy_import(globals(), """
 
77
from bzrlib import (
 
78
    branch,
 
79
    errors,
 
80
    workingtree,
 
81
    )
 
82
""")
 
83
 
56
84
from bzrlib.commands import Command, register_command, display_command
57
85
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
58
 
from bzrlib.commands import Command, register_command
59
86
from bzrlib.option import Option
60
 
from bzrlib.branch import Branch
61
 
from bzrlib.workingtree import WorkingTree
62
 
from bzrlib.bzrdir import BzrDir
63
87
 
64
88
import os.path
65
89
 
73
97
 
74
98
 
75
99
def set_ui_factory():
76
 
    pygtk = import_pygtk()
77
 
    from olive.ui import GtkUIFactory
 
100
    import_pygtk()
 
101
    from ui import GtkUIFactory
78
102
    import bzrlib.ui
79
103
    bzrlib.ui.ui_factory = GtkUIFactory()
80
104
 
81
105
 
82
 
class cmd_gbranch(Command):
 
106
class GTKCommand(Command):
 
107
    """Abstract class providing GTK specific run commands."""
 
108
 
 
109
    def open_display(self):
 
110
        pygtk = import_pygtk()
 
111
        try:
 
112
            import gtk
 
113
        except RuntimeError, e:
 
114
            if str(e) == "could not open display":
 
115
                raise NoDisplayError
 
116
        set_ui_factory()
 
117
        return gtk
 
118
 
 
119
    def run(self):
 
120
        self.open_display()
 
121
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
 
122
        dialog.run()
 
123
 
 
124
 
 
125
class cmd_gbranch(GTKCommand):
83
126
    """GTK+ branching.
84
127
    
85
128
    """
86
129
 
87
 
    def run(self):
88
 
        pygtk = import_pygtk()
89
 
        try:
90
 
            import gtk
91
 
        except RuntimeError, e:
92
 
            if str(e) == "could not open display":
93
 
                raise NoDisplayError
94
 
 
95
 
        from bzrlib.plugins.gtk.olive.branch import BranchDialog
96
 
 
97
 
        set_ui_factory()
98
 
        dialog = BranchDialog(os.path.abspath('.'))
99
 
        dialog.window.connect("destroy", lambda w: gtk.main_quit())
100
 
        dialog.display()
101
 
        
102
 
        gtk.main()
103
 
 
104
 
register_command(cmd_gbranch)
105
 
 
106
 
class cmd_gdiff(Command):
 
130
    def get_gtk_dialog(self, path):
 
131
        from bzrlib.plugins.gtk.branch import BranchDialog
 
132
        return BranchDialog(path)
 
133
 
 
134
 
 
135
class cmd_gcheckout(GTKCommand):
 
136
    """ GTK+ checkout.
 
137
    
 
138
    """
 
139
    
 
140
    def get_gtk_dialog(self, path):
 
141
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
 
142
        return CheckoutDialog(path)
 
143
 
 
144
 
 
145
 
 
146
class cmd_gpush(GTKCommand):
 
147
    """ GTK+ push.
 
148
    
 
149
    """
 
150
    takes_args = [ "location?" ]
 
151
 
 
152
    def run(self, location="."):
 
153
        (br, path) = branch.Branch.open_containing(location)
 
154
        self.open_display()
 
155
        from push import PushDialog
 
156
        dialog = PushDialog(br.repository, br.last_revision(), br)
 
157
        dialog.run()
 
158
 
 
159
 
 
160
 
 
161
class cmd_gdiff(GTKCommand):
107
162
    """Show differences in working tree in a GTK+ Window.
108
163
    
109
164
    Otherwise, all changes for the tree are listed.
114
169
    @display_command
115
170
    def run(self, revision=None, filename=None):
116
171
        set_ui_factory()
117
 
        wt = WorkingTree.open_containing(".")[0]
118
 
        branch = wt.branch
119
 
        if revision is not None:
120
 
            if len(revision) == 1:
 
172
        wt = workingtree.WorkingTree.open_containing(".")[0]
 
173
        wt.lock_read()
 
174
        try:
 
175
            branch = wt.branch
 
176
            if revision is not None:
 
177
                if len(revision) == 1:
 
178
                    tree1 = wt
 
179
                    revision_id = revision[0].in_history(branch).rev_id
 
180
                    tree2 = branch.repository.revision_tree(revision_id)
 
181
                elif len(revision) == 2:
 
182
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
183
                    tree2 = branch.repository.revision_tree(revision_id_0)
 
184
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
185
                    tree1 = branch.repository.revision_tree(revision_id_1)
 
186
            else:
121
187
                tree1 = wt
122
 
                revision_id = revision[0].in_history(branch).rev_id
123
 
                tree2 = branch.repository.revision_tree(revision_id)
124
 
            elif len(revision) == 2:
125
 
                revision_id_0 = revision[0].in_history(branch).rev_id
126
 
                tree2 = branch.repository.revision_tree(revision_id_0)
127
 
                revision_id_1 = revision[1].in_history(branch).rev_id
128
 
                tree1 = branch.repository.revision_tree(revision_id_1)
129
 
        else:
130
 
            tree1 = wt
131
 
            tree2 = tree1.basis_tree()
132
 
 
133
 
        from viz.diffwin import DiffWindow
134
 
        import gtk
135
 
        window = DiffWindow()
136
 
        window.connect("destroy", lambda w: gtk.main_quit())
137
 
        window.set_diff("Working Tree", tree1, tree2)
138
 
        if filename is not None:
139
 
            tree_filename = wt.relpath(filename)
140
 
            try:
141
 
                window.set_file(tree_filename)
142
 
            except NoSuchFile:
143
 
                if (tree1.inventory.path2id(tree_filename) is None and 
144
 
                    tree2.inventory.path2id(tree_filename) is None):
145
 
                    raise NotVersionedError(filename)
146
 
                raise BzrCommandError('No changes found for file "%s"' % 
147
 
                                      filename)
148
 
        window.show()
149
 
 
150
 
        gtk.main()
151
 
 
152
 
register_command(cmd_gdiff)
 
188
                tree2 = tree1.basis_tree()
 
189
 
 
190
            from diff import DiffWindow
 
191
            import gtk
 
192
            window = DiffWindow()
 
193
            window.connect("destroy", gtk.main_quit)
 
194
            window.set_diff("Working Tree", tree1, tree2)
 
195
            if filename is not None:
 
196
                tree_filename = wt.relpath(filename)
 
197
                try:
 
198
                    window.set_file(tree_filename)
 
199
                except NoSuchFile:
 
200
                    if (tree1.path2id(tree_filename) is None and 
 
201
                        tree2.path2id(tree_filename) is None):
 
202
                        raise NotVersionedError(filename)
 
203
                    raise BzrCommandError('No changes found for file "%s"' % 
 
204
                                          filename)
 
205
            window.show()
 
206
 
 
207
            gtk.main()
 
208
        finally:
 
209
            wt.unlock()
 
210
 
 
211
 
 
212
def start_viz_window(branch, revision, limit=None):
 
213
    """Start viz on branch with revision revision.
 
214
    
 
215
    :return: The viz window object.
 
216
    """
 
217
    from viz.branchwin import BranchWindow
 
218
    branch.lock_read()
 
219
    pp = BranchWindow()
 
220
    pp.set_branch(branch, revision, limit)
 
221
    # cleanup locks when the window is closed
 
222
    pp.connect("destroy", lambda w: branch.unlock())
 
223
    return pp
 
224
 
153
225
 
154
226
class cmd_visualise(Command):
155
227
    """Graphically visualise this branch.
162
234
    """
163
235
    takes_options = [
164
236
        "revision",
165
 
        Option('limit', "maximum number of revisions to display",
 
237
        Option('limit', "Maximum number of revisions to display.",
166
238
               int, 'count')]
167
239
    takes_args = [ "location?" ]
168
240
    aliases = [ "visualize", "vis", "viz" ]
169
241
 
170
242
    def run(self, location=".", revision=None, limit=None):
171
243
        set_ui_factory()
172
 
        (branch, path) = Branch.open_containing(location)
173
 
        branch.lock_read()
174
 
        branch.repository.lock_read()
 
244
        (br, path) = branch.Branch.open_containing(location)
 
245
        br.lock_read()
175
246
        try:
176
247
            if revision is None:
177
 
                revid = branch.last_revision()
 
248
                revid = br.last_revision()
178
249
                if revid is None:
179
250
                    return
180
251
            else:
181
 
                (revno, revid) = revision[0].in_history(branch)
 
252
                (revno, revid) = revision[0].in_history(br)
182
253
 
183
 
            from viz.bzrkapp import BzrkApp
184
 
                
185
 
            app = BzrkApp()
186
 
            app.show(branch, revid, limit)
 
254
            import gtk
 
255
            pp = start_viz_window(br, revid, limit)
 
256
            pp.connect("destroy", lambda w: gtk.main_quit())
 
257
            pp.show()
 
258
            gtk.main()
187
259
        finally:
188
 
            branch.repository.unlock()
189
 
            branch.unlock()
190
 
        app.main()
191
 
 
192
 
 
193
 
register_command(cmd_visualise)
194
 
 
195
 
class cmd_gannotate(Command):
 
260
            br.unlock()
 
261
 
 
262
 
 
263
class cmd_gannotate(GTKCommand):
196
264
    """GTK+ annotate.
197
265
    
198
266
    Browse changes to FILENAME line by line in a GTK+ window.
200
268
 
201
269
    takes_args = ["filename", "line?"]
202
270
    takes_options = [
203
 
        Option("all", help="show annotations on all lines"),
204
 
        Option("plain", help="don't highlight annotation lines"),
 
271
        Option("all", help="Show annotations on all lines."),
 
272
        Option("plain", help="Don't highlight annotation lines."),
205
273
        Option("line", type=int, argname="lineno",
206
 
               help="jump to specified line number"),
 
274
               help="Jump to specified line number."),
207
275
        "revision",
208
276
    ]
209
277
    aliases = ["gblame", "gpraise"]
210
278
    
211
279
    def run(self, filename, all=False, plain=False, line='1', revision=None):
212
 
        pygtk = import_pygtk()
213
 
 
214
 
        try:
215
 
            import gtk
216
 
        except RuntimeError, e:
217
 
            if str(e) == "could not open display":
218
 
                raise NoDisplayError
219
 
        set_ui_factory()
 
280
        gtk = self.open_display()
220
281
 
221
282
        try:
222
283
            line = int(line)
226
287
 
227
288
        from annotate.gannotate import GAnnotateWindow
228
289
        from annotate.config import GAnnotateConfig
 
290
        from bzrlib.bzrdir import BzrDir
229
291
 
230
 
        try:
231
 
            (tree, path) = WorkingTree.open_containing(filename)
232
 
            branch = tree.branch
233
 
        except errors.NoWorkingTree:
234
 
            (branch, path) = Branch.open_containing(filename)
235
 
            tree = branch.basis_tree()
 
292
        wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
 
293
        if wt is not None:
 
294
            tree = wt
 
295
        else:
 
296
            tree = br.basis_tree()
236
297
 
237
298
        file_id = tree.path2id(path)
238
299
 
241
302
        if revision is not None:
242
303
            if len(revision) != 1:
243
304
                raise BzrCommandError("Only 1 revion may be specified.")
244
 
            revision_id = revision[0].in_history(branch).rev_id
245
 
            tree = branch.repository.revision_tree(revision_id)
 
305
            revision_id = revision[0].in_history(br).rev_id
 
306
            tree = br.repository.revision_tree(revision_id)
246
307
        else:
247
308
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
248
309
 
251
312
        window.set_title(path + " - gannotate")
252
313
        config = GAnnotateConfig(window)
253
314
        window.show()
254
 
        branch.lock_read()
 
315
        br.lock_read()
 
316
        if wt is not None:
 
317
            wt.lock_read()
255
318
        try:
256
 
            window.annotate(tree, branch, file_id)
 
319
            window.annotate(tree, br, file_id)
 
320
            window.jump_to_line(line)
 
321
            gtk.main()
257
322
        finally:
258
 
            branch.unlock()
259
 
        window.jump_to_line(line)
260
 
        
261
 
        gtk.main()
262
 
 
263
 
register_command(cmd_gannotate)
264
 
 
265
 
class cmd_gcommit(Command):
 
323
            br.unlock()
 
324
            if wt is not None:
 
325
                wt.unlock()
 
326
 
 
327
 
 
328
 
 
329
class cmd_gcommit(GTKCommand):
266
330
    """GTK+ commit dialog
267
331
 
268
332
    Graphical user interface for committing revisions"""
269
333
    
 
334
    aliases = [ "gci" ]
270
335
    takes_args = []
271
336
    takes_options = []
272
337
 
273
338
    def run(self, filename=None):
274
339
        import os
275
 
        pygtk = import_pygtk()
276
 
 
277
 
        try:
278
 
            import gtk
279
 
        except RuntimeError, e:
280
 
            if str(e) == "could not open display":
281
 
                raise NoDisplayError
282
 
 
283
 
        set_ui_factory()
284
 
        from olive.commit import CommitDialog
285
 
        from bzrlib.commit import Commit
 
340
        self.open_display()
 
341
        from commit import CommitDialog
286
342
        from bzrlib.errors import (BzrCommandError,
287
343
                                   NotBranchError,
288
 
                                   NoWorkingTree,
289
 
                                   PointlessCommit,
290
 
                                   ConflictsInTree,
291
 
                                   StrictCommitFailed)
 
344
                                   NoWorkingTree)
292
345
 
293
346
        wt = None
294
 
        branch = None
 
347
        br = None
295
348
        try:
296
 
            (wt, path) = WorkingTree.open_containing(filename)
297
 
            branch = wt.branch
298
 
        except NotBranchError, e:
299
 
            path = e.path
 
349
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
 
350
            br = wt.branch
300
351
        except NoWorkingTree, e:
301
352
            path = e.base
302
 
            try:
303
 
                (branch, path) = Branch.open_containing(path)
304
 
            except NotBranchError, e:
305
 
                path = e.path
306
 
 
307
 
 
308
 
        commit = CommitDialog(wt, path, not branch)
 
353
            (br, path) = branch.Branch.open_containing(path)
 
354
 
 
355
        commit = CommitDialog(wt, path, not br)
309
356
        commit.run()
310
357
 
311
 
register_command(cmd_gcommit)
 
358
 
 
359
 
 
360
class cmd_gstatus(GTKCommand):
 
361
    """GTK+ status dialog
 
362
 
 
363
    Graphical user interface for showing status 
 
364
    information."""
 
365
    
 
366
    aliases = [ "gst" ]
 
367
    takes_args = ['PATH?']
 
368
    takes_options = []
 
369
 
 
370
    def run(self, path='.'):
 
371
        import os
 
372
        gtk = self.open_display()
 
373
        from status import StatusDialog
 
374
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
 
375
        status = StatusDialog(wt, wt_path)
 
376
        status.connect("destroy", gtk.main_quit)
 
377
        status.run()
 
378
 
 
379
 
 
380
 
 
381
class cmd_gconflicts(GTKCommand):
 
382
    """ GTK+ push.
 
383
    
 
384
    """
 
385
    def run(self):
 
386
        (wt, path) = workingtree.WorkingTree.open_containing('.')
 
387
        self.open_display()
 
388
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
 
389
        dialog = ConflictsDialog(wt)
 
390
        dialog.run()
 
391
 
 
392
 
 
393
 
 
394
class cmd_gpreferences(GTKCommand):
 
395
    """ GTK+ preferences dialog.
 
396
 
 
397
    """
 
398
    def run(self):
 
399
        self.open_display()
 
400
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
 
401
        dialog = PreferencesWindow()
 
402
        dialog.run()
 
403
 
 
404
 
 
405
 
 
406
class cmd_gmissing(Command):
 
407
    """ GTK+ missing revisions dialog.
 
408
 
 
409
    """
 
410
    takes_args = ["other_branch?"]
 
411
    def run(self, other_branch=None):
 
412
        pygtk = import_pygtk()
 
413
        try:
 
414
            import gtk
 
415
        except RuntimeError, e:
 
416
            if str(e) == "could not open display":
 
417
                raise NoDisplayError
 
418
 
 
419
        from bzrlib.plugins.gtk.missing import MissingWindow
 
420
        from bzrlib.branch import Branch
 
421
 
 
422
        local_branch = Branch.open_containing(".")[0]
 
423
        if other_branch is None:
 
424
            other_branch = local_branch.get_parent()
 
425
            
 
426
            if other_branch is None:
 
427
                raise errors.BzrCommandError("No peer location known or specified.")
 
428
        remote_branch = Branch.open_containing(other_branch)[0]
 
429
        set_ui_factory()
 
430
        local_branch.lock_read()
 
431
        try:
 
432
            remote_branch.lock_read()
 
433
            try:
 
434
                dialog = MissingWindow(local_branch, remote_branch)
 
435
                dialog.run()
 
436
            finally:
 
437
                remote_branch.unlock()
 
438
        finally:
 
439
            local_branch.unlock()
 
440
 
 
441
 
 
442
class cmd_ginit(GTKCommand):
 
443
    def run(self):
 
444
        self.open_display()
 
445
        from initialize import InitDialog
 
446
        dialog = InitDialog(os.path.abspath(os.path.curdir))
 
447
        dialog.run()
 
448
 
 
449
 
 
450
class cmd_gtags(GTKCommand):
 
451
    def run(self):
 
452
        br = branch.Branch.open_containing('.')[0]
 
453
        
 
454
        gtk = self.open_display()
 
455
        from tags import TagsWindow
 
456
        window = TagsWindow(br)
 
457
        window.show()
 
458
        gtk.main()
 
459
 
 
460
 
 
461
commands = [
 
462
    cmd_gmissing, 
 
463
    cmd_gpreferences, 
 
464
    cmd_gconflicts, 
 
465
    cmd_gstatus,
 
466
    cmd_gcommit, 
 
467
    cmd_gannotate, 
 
468
    cmd_visualise, 
 
469
    cmd_gdiff,
 
470
    cmd_gpush, 
 
471
    cmd_gcheckout, 
 
472
    cmd_gbranch,
 
473
    cmd_ginit,
 
474
    cmd_gtags
 
475
    ]
 
476
 
 
477
for cmd in commands:
 
478
    register_command(cmd)
 
479
 
 
480
 
 
481
class cmd_commit_notify(GTKCommand):
 
482
    """Run the bzr commit notifier.
 
483
 
 
484
    This is a background program which will pop up a notification on the users
 
485
    screen when a commit occurs.
 
486
    """
 
487
 
 
488
    def run(self):
 
489
        from notify import NotifyPopupMenu
 
490
        gtk = self.open_display()
 
491
        menu = NotifyPopupMenu()
 
492
        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
 
493
        icon.connect('popup-menu', menu.display)
 
494
 
 
495
        import cgi
 
496
        import dbus
 
497
        import dbus.service
 
498
        import pynotify
 
499
        from bzrlib.bzrdir import BzrDir
 
500
        from bzrlib import errors
 
501
        from bzrlib.osutils import format_date
 
502
        from bzrlib.transport import get_transport
 
503
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
504
            import dbus.glib
 
505
        from bzrlib.plugins.dbus import activity
 
506
        bus = dbus.SessionBus()
 
507
        # get the object so we can subscribe to callbacks from it.
 
508
        broadcast_service = bus.get_object(
 
509
            activity.Broadcast.DBUS_NAME,
 
510
            activity.Broadcast.DBUS_PATH)
 
511
 
 
512
        def catch_branch(revision_id, urls):
 
513
            # TODO: show all the urls, or perhaps choose the 'best'.
 
514
            url = urls[0]
 
515
            try:
 
516
                if isinstance(revision_id, unicode):
 
517
                    revision_id = revision_id.encode('utf8')
 
518
                transport = get_transport(url)
 
519
                a_dir = BzrDir.open_from_transport(transport)
 
520
                branch = a_dir.open_branch()
 
521
                revno = branch.revision_id_to_revno(revision_id)
 
522
                revision = branch.repository.get_revision(revision_id)
 
523
                summary = 'New revision %d in %s' % (revno, url)
 
524
                body  = 'Committer: %s\n' % revision.committer
 
525
                body += 'Date: %s\n' % format_date(revision.timestamp,
 
526
                    revision.timezone)
 
527
                body += '\n'
 
528
                body += revision.message
 
529
                body = cgi.escape(body)
 
530
                nw = pynotify.Notification(summary, body)
 
531
                def start_viz(notification=None, action=None, data=None):
 
532
                    """Start the viz program."""
 
533
                    pp = start_viz_window(branch, revision_id)
 
534
                    pp.show()
 
535
                def start_branch(notification=None, action=None, data=None):
 
536
                    """Start a Branch dialog"""
 
537
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
538
                    bd = BranchDialog(remote_path=url)
 
539
                    bd.run()
 
540
                nw.add_action("inspect", "Inspect", start_viz, None)
 
541
                nw.add_action("branch", "Branch", start_branch, None)
 
542
                nw.set_timeout(5000)
 
543
                nw.show()
 
544
            except Exception, e:
 
545
                print e
 
546
                raise
 
547
        broadcast_service.connect_to_signal("Revision", catch_branch,
 
548
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
549
        pynotify.init("bzr commit-notify")
 
550
        gtk.main()
 
551
 
 
552
register_command(cmd_commit_notify)
 
553
 
 
554
 
 
555
import gettext
 
556
gettext.install('olive-gtk')
 
557
 
312
558
 
313
559
class NoDisplayError(BzrCommandError):
314
560
    """gtk could not find a proper display"""
316
562
    def __str__(self):
317
563
        return "No DISPLAY. Unable to run GTK+ application."
318
564
 
 
565
 
319
566
def test_suite():
320
567
    from unittest import TestSuite
321
568
    import tests
322
 
    result = TestSuite()
323
 
    result.addTest(tests.test_suite())
 
569
    import sys
 
570
    default_encoding = sys.getdefaultencoding()
 
571
    try:
 
572
        result = TestSuite()
 
573
        result.addTest(tests.test_suite())
 
574
    finally:
 
575
        if sys.getdefaultencoding() != default_encoding:
 
576
            reload(sys)
 
577
            sys.setdefaultencoding(default_encoding)
324
578
    return result
325