/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-09-02 15:42:18 UTC
  • mto: This revision was merged to the branch mainline in revision 274.
  • Revision ID: matkor@laptop-hp-20070902154218-nba0woaqjsn20f9n
Ignoring eric3 project files.

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+ conflicts. 
 
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.16.0'
 
36
__version__ = '0.91.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:
41
 
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
 
59
        from bzrlib.errors import BzrError
 
60
        warning('Installed Bazaar 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
67
 
52
68
 
53
69
check_bzrlib_version(version_info[:2])
60
76
lazy_import(globals(), """
61
77
from bzrlib import (
62
78
    branch,
 
79
    builtins,
63
80
    errors,
64
81
    workingtree,
65
82
    )
87
104
    bzrlib.ui.ui_factory = GtkUIFactory()
88
105
 
89
106
 
 
107
def data_path():
 
108
    return os.path.dirname(__file__)
 
109
 
 
110
 
90
111
class GTKCommand(Command):
91
112
    """Abstract class providing GTK specific run commands."""
92
113
 
137
158
        (br, path) = branch.Branch.open_containing(location)
138
159
        self.open_display()
139
160
        from push import PushDialog
140
 
        dialog = PushDialog(br)
 
161
        dialog = PushDialog(br.repository, br.last_revision(), br)
141
162
        dialog.run()
142
163
 
143
164
 
181
202
                try:
182
203
                    window.set_file(tree_filename)
183
204
                except NoSuchFile:
184
 
                    if (tree1.inventory.path2id(tree_filename) is None and 
185
 
                        tree2.inventory.path2id(tree_filename) is None):
 
205
                    if (tree1.path2id(tree_filename) is None and 
 
206
                        tree2.path2id(tree_filename) is None):
186
207
                        raise NotVersionedError(filename)
187
208
                    raise BzrCommandError('No changes found for file "%s"' % 
188
209
                                          filename)
193
214
            wt.unlock()
194
215
 
195
216
 
 
217
def start_viz_window(branch, revision, limit=None):
 
218
    """Start viz on branch with revision revision.
 
219
    
 
220
    :return: The viz window object.
 
221
    """
 
222
    from viz.branchwin import BranchWindow
 
223
    branch.lock_read()
 
224
    pp = BranchWindow()
 
225
    pp.set_branch(branch, revision, limit)
 
226
    # cleanup locks when the window is closed
 
227
    pp.connect("destroy", lambda w: branch.unlock())
 
228
    return pp
 
229
 
 
230
 
196
231
class cmd_visualise(Command):
197
232
    """Graphically visualise this branch.
198
233
 
204
239
    """
205
240
    takes_options = [
206
241
        "revision",
207
 
        Option('limit', "maximum number of revisions to display",
 
242
        Option('limit', "Maximum number of revisions to display.",
208
243
               int, 'count')]
209
244
    takes_args = [ "location?" ]
210
245
    aliases = [ "visualize", "vis", "viz" ]
213
248
        set_ui_factory()
214
249
        (br, path) = branch.Branch.open_containing(location)
215
250
        br.lock_read()
216
 
        br.repository.lock_read()
217
251
        try:
218
252
            if revision is None:
219
253
                revid = br.last_revision()
222
256
            else:
223
257
                (revno, revid) = revision[0].in_history(br)
224
258
 
225
 
            from viz.branchwin import BranchWindow
226
259
            import gtk
227
 
                
228
 
            pp = BranchWindow()
229
 
            pp.set_branch(br, revid, limit)
 
260
            pp = start_viz_window(br, revid, limit)
230
261
            pp.connect("destroy", lambda w: gtk.main_quit())
231
262
            pp.show()
232
263
            gtk.main()
233
264
        finally:
234
 
            br.repository.unlock()
235
265
            br.unlock()
236
266
 
237
267
 
243
273
 
244
274
    takes_args = ["filename", "line?"]
245
275
    takes_options = [
246
 
        Option("all", help="show annotations on all lines"),
247
 
        Option("plain", help="don't highlight annotation lines"),
 
276
        Option("all", help="Show annotations on all lines."),
 
277
        Option("plain", help="Don't highlight annotation lines."),
248
278
        Option("line", type=int, argname="lineno",
249
 
               help="jump to specified line number"),
 
279
               help="Jump to specified line number."),
250
280
        "revision",
251
281
    ]
252
282
    aliases = ["gblame", "gpraise"]
323
353
        try:
324
354
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
325
355
            br = wt.branch
326
 
        except NotBranchError, e:
327
 
            path = e.path
328
356
        except NoWorkingTree, e:
329
357
            path = e.base
330
 
            try:
331
 
                (br, path) = branch.Branch.open_containing(path)
332
 
            except NotBranchError, e:
333
 
                path = e.path
 
358
            (br, path) = branch.Branch.open_containing(path)
334
359
 
335
360
        commit = CommitDialog(wt, path, not br)
336
361
        commit.run()
359
384
 
360
385
 
361
386
class cmd_gconflicts(GTKCommand):
362
 
    """ GTK+ push.
 
387
    """ GTK+ conflicts.
363
388
    
 
389
    Select files from the list of conflicts and run an external utility to
 
390
    resolve them.
364
391
    """
365
392
    def run(self):
366
393
        (wt, path) = workingtree.WorkingTree.open_containing('.')
427
454
        dialog.run()
428
455
 
429
456
 
 
457
class cmd_gtags(GTKCommand):
 
458
    def run(self):
 
459
        br = branch.Branch.open_containing('.')[0]
 
460
        
 
461
        gtk = self.open_display()
 
462
        from tags import TagsWindow
 
463
        window = TagsWindow(br)
 
464
        window.show()
 
465
        gtk.main()
 
466
 
 
467
 
430
468
commands = [
431
469
    cmd_gmissing, 
432
470
    cmd_gpreferences, 
439
477
    cmd_gpush, 
440
478
    cmd_gcheckout, 
441
479
    cmd_gbranch,
442
 
    cmd_ginit
 
480
    cmd_ginit,
 
481
    cmd_gtags
443
482
    ]
444
483
 
445
484
for cmd in commands:
454
493
    """
455
494
 
456
495
    def run(self):
 
496
        from notify import NotifyPopupMenu
457
497
        gtk = self.open_display()
 
498
        menu = NotifyPopupMenu()
 
499
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
500
        icon.connect('popup-menu', menu.display)
 
501
 
458
502
        import cgi
459
503
        import dbus
460
504
        import dbus.service
471
515
        broadcast_service = bus.get_object(
472
516
            activity.Broadcast.DBUS_NAME,
473
517
            activity.Broadcast.DBUS_PATH)
 
518
 
474
519
        def catch_branch(revision_id, urls):
475
520
            # TODO: show all the urls, or perhaps choose the 'best'.
476
521
            url = urls[0]
490
535
                body += revision.message
491
536
                body = cgi.escape(body)
492
537
                nw = pynotify.Notification(summary, body)
 
538
                def start_viz(notification=None, action=None, data=None):
 
539
                    """Start the viz program."""
 
540
                    pp = start_viz_window(branch, revision_id)
 
541
                    pp.show()
 
542
                def start_branch(notification=None, action=None, data=None):
 
543
                    """Start a Branch dialog"""
 
544
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
545
                    bd = BranchDialog(remote_path=url)
 
546
                    bd.run()
 
547
                nw.add_action("inspect", "Inspect", start_viz, None)
 
548
                nw.add_action("branch", "Branch", start_branch, None)
493
549
                nw.set_timeout(5000)
494
550
                nw.show()
495
551
            except Exception, e:
503
559
register_command(cmd_commit_notify)
504
560
 
505
561
 
 
562
class cmd_gselftest(GTKCommand):
 
563
    """Version of selftest that displays a notification at the end"""
 
564
 
 
565
    takes_args = builtins.cmd_selftest.takes_args
 
566
    takes_options = builtins.cmd_selftest.takes_options
 
567
    _see_also = ['selftest']
 
568
 
 
569
    def run(self, *args, **kwargs):
 
570
        import cgi
 
571
        import sys
 
572
        default_encoding = sys.getdefaultencoding()
 
573
        # prevent gtk from blowing up later
 
574
        gtk = import_pygtk()
 
575
        # prevent gtk from messing with default encoding
 
576
        import pynotify
 
577
        if sys.getdefaultencoding() != default_encoding:
 
578
            reload(sys)
 
579
            sys.setdefaultencoding(default_encoding)
 
580
        result = builtins.cmd_selftest().run(*args, **kwargs)
 
581
        if result == 0:
 
582
            summary = 'Success'
 
583
            body = 'Selftest succeeded in "%s"' % os.getcwd()
 
584
        if result == 1:
 
585
            summary = 'Failure'
 
586
            body = 'Selftest failed in "%s"' % os.getcwd()
 
587
        pynotify.init("bzr gselftest")
 
588
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
 
589
        note.set_timeout(pynotify.EXPIRES_NEVER)
 
590
        note.show()
 
591
 
 
592
 
 
593
register_command(cmd_gselftest)
 
594
 
 
595
 
506
596
import gettext
507
597
gettext.install('olive-gtk')
508
598