/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: Jelmer Vernooij
  • Date: 2007-07-15 18:12:57 UTC
  • Revision ID: jelmer@samba.org-20070715181257-g264qus2zyi3v39z
Add RevisionSelectionBox widget, use in TagDialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#
1
3
# This program is free software; you can redistribute it and/or modify
2
4
# it under the terms of the GNU General Public License as published by
3
5
# the Free Software Foundation; either version 2 of the License, or
12
14
# along with this program; if not, write to the Free Software
13
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
16
 
15
 
"""GTK+ frontends to Bazaar commands """
 
17
"""Graphical support for Bazaar using GTK.
 
18
 
 
19
This plugin includes:
 
20
commit-notify     Start the graphical notifier of commits.
 
21
gannotate         GTK+ annotate. 
 
22
gbranch           GTK+ branching. 
 
23
gcheckout         GTK+ checkout. 
 
24
gcommit           GTK+ commit dialog 
 
25
gconflicts        GTK+ push. 
 
26
gdiff             Show differences in working tree in a GTK+ Window. 
 
27
ginit             Initialise a new branch.
 
28
gmissing          GTK+ missing revisions dialog. 
 
29
gpreferences      GTK+ preferences dialog. 
 
30
gpush             GTK+ push. 
 
31
gstatus           GTK+ status dialog 
 
32
gtags             Manage branch tags.
 
33
visualise         Graphically visualise this branch. 
 
34
"""
16
35
 
17
36
import bzrlib
18
37
 
19
 
__version__ = '0.17.0'
 
38
__version__ = '0.18.0'
20
39
version_info = tuple(int(n) for n in __version__.split('.'))
21
40
 
22
41
 
30
49
    """
31
50
    desired_plus = (desired[0], desired[1]+1)
32
51
    bzrlib_version = bzrlib.version_info[:2]
33
 
    if bzrlib_version == desired:
 
52
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
 
53
                                     bzrlib.version_info[3] == 'dev'):
34
54
        return
35
55
    try:
36
56
        from bzrlib.trace import warning
38
58
        # get the message out any way we can
39
59
        from warnings import warn as warning
40
60
    if bzrlib_version < desired:
 
61
        from bzrlib.errors import BzrError
41
62
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
63
                ' %s.' % (bzrlib.__version__, __version__))
43
64
        raise BzrError('Version mismatch: %r' % version_info)
45
66
        warning('bzr-gtk is not up to date with installed bzr version %s.'
46
67
                ' \nThere should be a newer version available, e.g. %i.%i.' 
47
68
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
48
 
        if bzrlib_version != desired_plus:
49
 
            raise Exception, 'Version mismatch'
50
69
 
51
70
 
52
71
check_bzrlib_version(version_info[:2])
192
211
            wt.unlock()
193
212
 
194
213
 
 
214
def start_viz_window(branch, revision, limit=None):
 
215
    """Start viz on branch with revision revision.
 
216
    
 
217
    :return: The viz window object.
 
218
    """
 
219
    from viz.branchwin import BranchWindow
 
220
    branch.lock_read()
 
221
    pp = BranchWindow()
 
222
    pp.set_branch(branch, revision, limit)
 
223
    # cleanup locks when the window is closed
 
224
    pp.connect("destroy", lambda w: branch.unlock())
 
225
    return pp
 
226
 
 
227
 
195
228
class cmd_visualise(Command):
196
229
    """Graphically visualise this branch.
197
230
 
203
236
    """
204
237
    takes_options = [
205
238
        "revision",
206
 
        Option('limit', "maximum number of revisions to display",
 
239
        Option('limit', "Maximum number of revisions to display.",
207
240
               int, 'count')]
208
241
    takes_args = [ "location?" ]
209
242
    aliases = [ "visualize", "vis", "viz" ]
212
245
        set_ui_factory()
213
246
        (br, path) = branch.Branch.open_containing(location)
214
247
        br.lock_read()
215
 
        br.repository.lock_read()
216
248
        try:
217
249
            if revision is None:
218
250
                revid = br.last_revision()
221
253
            else:
222
254
                (revno, revid) = revision[0].in_history(br)
223
255
 
224
 
            from viz.branchwin import BranchWindow
225
256
            import gtk
226
 
                
227
 
            pp = BranchWindow()
228
 
            pp.set_branch(br, revid, limit)
 
257
            pp = start_viz_window(br, revid, limit)
229
258
            pp.connect("destroy", lambda w: gtk.main_quit())
230
259
            pp.show()
231
260
            gtk.main()
232
261
        finally:
233
 
            br.repository.unlock()
234
262
            br.unlock()
235
263
 
236
264
 
242
270
 
243
271
    takes_args = ["filename", "line?"]
244
272
    takes_options = [
245
 
        Option("all", help="show annotations on all lines"),
246
 
        Option("plain", help="don't highlight annotation lines"),
 
273
        Option("all", help="Show annotations on all lines."),
 
274
        Option("plain", help="Don't highlight annotation lines."),
247
275
        Option("line", type=int, argname="lineno",
248
 
               help="jump to specified line number"),
 
276
               help="Jump to specified line number."),
249
277
        "revision",
250
278
    ]
251
279
    aliases = ["gblame", "gpraise"]
460
488
    """
461
489
 
462
490
    def run(self):
 
491
        from notify import NotifyPopupMenu
463
492
        gtk = self.open_display()
 
493
        menu = NotifyPopupMenu()
 
494
        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
 
495
        icon.connect('popup-menu', menu.display)
 
496
 
464
497
        import cgi
465
498
        import dbus
466
499
        import dbus.service
477
510
        broadcast_service = bus.get_object(
478
511
            activity.Broadcast.DBUS_NAME,
479
512
            activity.Broadcast.DBUS_PATH)
 
513
 
480
514
        def catch_branch(revision_id, urls):
481
515
            # TODO: show all the urls, or perhaps choose the 'best'.
482
516
            url = urls[0]
496
530
                body += revision.message
497
531
                body = cgi.escape(body)
498
532
                nw = pynotify.Notification(summary, body)
 
533
                def start_viz(notification=None, action=None, data=None):
 
534
                    """Start the viz program."""
 
535
                    pp = start_viz_window(branch, revision_id)
 
536
                    pp.show()
 
537
                def start_branch(notification=None, action=None, data=None):
 
538
                    """Start a Branch dialog"""
 
539
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
540
                    bd = BranchDialog(remote_path=url)
 
541
                    bd.run()
 
542
                nw.add_action("inspect", "Inspect", start_viz, None)
 
543
                nw.add_action("branch", "Branch", start_branch, None)
499
544
                nw.set_timeout(5000)
500
545
                nw.show()
501
546
            except Exception, e: