/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-13 23:09:47 UTC
  • Revision ID: jelmer@samba.org-20070713230947-0bngzxibg52vhmjo
Move olive about dialog into olive.

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)
192
213
            wt.unlock()
193
214
 
194
215
 
 
216
def start_viz_window(branch, revision, limit=None):
 
217
    """Start viz on branch with revision revision.
 
218
    
 
219
    :return: The viz window object.
 
220
    """
 
221
    from viz.branchwin import BranchWindow
 
222
    branch.lock_read()
 
223
    pp = BranchWindow()
 
224
    pp.set_branch(branch, revision, limit)
 
225
    # cleanup locks when the window is closed
 
226
    pp.connect("destroy", lambda w: branch.unlock())
 
227
    return pp
 
228
 
 
229
 
195
230
class cmd_visualise(Command):
196
231
    """Graphically visualise this branch.
197
232
 
203
238
    """
204
239
    takes_options = [
205
240
        "revision",
206
 
        Option('limit', "maximum number of revisions to display",
 
241
        Option('limit', "Maximum number of revisions to display.",
207
242
               int, 'count')]
208
243
    takes_args = [ "location?" ]
209
244
    aliases = [ "visualize", "vis", "viz" ]
212
247
        set_ui_factory()
213
248
        (br, path) = branch.Branch.open_containing(location)
214
249
        br.lock_read()
215
 
        br.repository.lock_read()
216
250
        try:
217
251
            if revision is None:
218
252
                revid = br.last_revision()
221
255
            else:
222
256
                (revno, revid) = revision[0].in_history(br)
223
257
 
224
 
            from viz.branchwin import BranchWindow
225
258
            import gtk
226
 
                
227
 
            pp = BranchWindow()
228
 
            pp.set_branch(br, revid, limit)
 
259
            pp = start_viz_window(br, revid, limit)
229
260
            pp.connect("destroy", lambda w: gtk.main_quit())
230
261
            pp.show()
231
262
            gtk.main()
232
263
        finally:
233
 
            br.repository.unlock()
234
264
            br.unlock()
235
265
 
236
266
 
242
272
 
243
273
    takes_args = ["filename", "line?"]
244
274
    takes_options = [
245
 
        Option("all", help="show annotations on all lines"),
246
 
        Option("plain", help="don't highlight annotation lines"),
 
275
        Option("all", help="Show annotations on all lines."),
 
276
        Option("plain", help="Don't highlight annotation lines."),
247
277
        Option("line", type=int, argname="lineno",
248
 
               help="jump to specified line number"),
 
278
               help="Jump to specified line number."),
249
279
        "revision",
250
280
    ]
251
281
    aliases = ["gblame", "gpraise"]
460
490
    """
461
491
 
462
492
    def run(self):
 
493
        from notify import NotifyPopupMenu
463
494
        gtk = self.open_display()
 
495
        menu = NotifyPopupMenu()
 
496
        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
 
497
        icon.connect('popup-menu', menu.display)
 
498
 
464
499
        import cgi
465
500
        import dbus
466
501
        import dbus.service
477
512
        broadcast_service = bus.get_object(
478
513
            activity.Broadcast.DBUS_NAME,
479
514
            activity.Broadcast.DBUS_PATH)
 
515
 
480
516
        def catch_branch(revision_id, urls):
481
517
            # TODO: show all the urls, or perhaps choose the 'best'.
482
518
            url = urls[0]
496
532
                body += revision.message
497
533
                body = cgi.escape(body)
498
534
                nw = pynotify.Notification(summary, body)
 
535
                def start_viz(notification=None, action=None, data=None):
 
536
                    """Start the viz program."""
 
537
                    pp = start_viz_window(branch, revision_id)
 
538
                    pp.show()
 
539
                def start_branch(notification=None, action=None, data=None):
 
540
                    """Start a Branch dialog"""
 
541
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
542
                    bd = BranchDialog(remote_path=url)
 
543
                    bd.run()
 
544
                nw.add_action("inspect", "Inspect", start_viz, None)
 
545
                nw.add_action("branch", "Branch", start_branch, None)
499
546
                nw.set_timeout(5000)
500
547
                nw.show()
501
548
            except Exception, e: