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

  • Committer: Jelmer Vernooij
  • Date: 2006-05-19 16:56:46 UTC
  • mfrom: (0.1.25 gannotate)
  • Revision ID: jelmer@samba.org-20060519165646-0d867938fdbc9097
Merge in Dan Loda's gannotate plugin and put it in annotate/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
__version__ = "0.7pre"
 
18
__author__ = "Dan Loda <danloda@gmail.com>"
 
19
 
 
20
from bzrlib.workingtree import WorkingTree
 
21
from bzrlib.commands import Command, register_command
 
22
from bzrlib.errors import NotVersionedError, BzrCommandError
 
23
from bzrlib.option import Option
 
24
 
 
25
 
 
26
class cmd_gannotate(Command):
 
27
    """GTK+ annotate.
 
28
    
 
29
    Browse changes to FILENAME line by line in a GTK+ window.
 
30
    """
 
31
 
 
32
    takes_args = ["filename"]
 
33
    takes_options = [
 
34
        Option("all", help="show annotations on all lines"),
 
35
        Option("plain", help="don't highlight annotation lines"),
 
36
        Option("line", type=int, argname="lineno",
 
37
               help="jump to specified line number")
 
38
    ]
 
39
    aliases = ["gblame", "gpraise"]
 
40
    
 
41
    def run(self, filename, all=False, plain=False, line=1):
 
42
        import pygtk
 
43
        pygtk.require("2.0")
 
44
 
 
45
        try:
 
46
            import gtk
 
47
        except RuntimeError, e:
 
48
            if str(e) == "could not open display":
 
49
                raise NoDisplayError
 
50
 
 
51
        from gannotate import GAnnotateWindow
 
52
        from config import GAnnotateConfig
 
53
 
 
54
        (wt, path) = WorkingTree.open_containing(filename)
 
55
        branch = wt.branch
 
56
 
 
57
        file_id = wt.path2id(path)
 
58
 
 
59
        if file_id is None:
 
60
            raise NotVersionedError(filename)
 
61
 
 
62
        window = GAnnotateWindow(all, plain)
 
63
        window.connect("destroy", lambda w: gtk.main_quit())
 
64
        window.set_title(path + " - gannotate")
 
65
        config = GAnnotateConfig(window)
 
66
        window.show()
 
67
        branch.lock_read()
 
68
        try:
 
69
            window.annotate(branch, file_id)
 
70
        finally:
 
71
            branch.unlock()
 
72
        window.jump_to_line(line)
 
73
        
 
74
        gtk.main()
 
75
 
 
76
 
 
77
register_command(cmd_gannotate)
 
78
 
 
79
 
 
80
class NoDisplayError(BzrCommandError):
 
81
    """gtk could not find a proper display"""
 
82
 
 
83
    def __str__(self):
 
84
        return "No DISPLAY. gannotate is disabled."
 
85