/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: 2006-06-07 09:27:13 UTC
  • mfrom: (55.1.4 bzr-gtk)
  • Revision ID: jelmer@samba.org-20060607092713-b0ae12ee9de2ace8
[merge] Home

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""GTK+ frontends to Bazaar commands """
18
 
import viz
19
 
import annotate
20
 
import commit
21
 
import gdiff
 
18
from bzrlib.commands import Command, register_command, display_command
 
19
from bzrlib.errors import NotVersionedError, BzrCommandError
 
20
from bzrlib.commands import Command, register_command
 
21
from bzrlib.option import Option
 
22
from bzrlib.branch import Branch
 
23
from bzrlib.workingtree import WorkingTree
 
24
from bzrlib.bzrdir import BzrDir
 
25
 
 
26
class cmd_gbranch(Command):
 
27
    """GTK+ branching.
 
28
    
 
29
    """
 
30
 
 
31
    def run(self):
 
32
        import pygtk
 
33
        pygtk.require("2.0")
 
34
        try:
 
35
            import gtk
 
36
        except RuntimeError, e:
 
37
            if str(e) == "could not open display":
 
38
                raise NoDisplayError
 
39
 
 
40
        from clone import CloneDialog
 
41
 
 
42
        window = CloneDialog()
 
43
        if window.run() == gtk.RESPONSE_OK:
 
44
            bzrdir = BzrDir.open(window.url)
 
45
            bzrdir.sprout(window.dest_path)
 
46
 
 
47
register_command(cmd_gbranch)
 
48
 
 
49
class cmd_gdiff(Command):
 
50
    """Show differences in working tree in a GTK+ Window.
 
51
    
 
52
    Otherwise, all changes for the tree are listed.
 
53
    """
 
54
    takes_args = []
 
55
    takes_options = []
 
56
 
 
57
    @display_command
 
58
    def run(self, revision=None, file_list=None):
 
59
        tree1 = WorkingTree.open_containing(".")[0]
 
60
        branch = tree1.branch
 
61
        tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
 
62
 
 
63
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
64
        import gtk
 
65
        window = DiffWindow()
 
66
        window.connect("destroy", lambda w: gtk.main_quit())
 
67
        window.set_diff("Working Tree", tree1, tree2)
 
68
        window.show()
 
69
 
 
70
        gtk.main()
 
71
 
 
72
register_command(cmd_gdiff)
 
73
 
 
74
class cmd_visualise(Command):
 
75
    """Graphically visualise this branch.
 
76
 
 
77
    Opens a graphical window to allow you to see the history of the branch
 
78
    and relationships between revisions in a visual manner,
 
79
 
 
80
    The default starting point is latest revision on the branch, you can
 
81
    specify a starting point with -r revision.
 
82
    """
 
83
    takes_options = [
 
84
        "revision",
 
85
        Option('limit', "maximum number of revisions to display",
 
86
               int, 'count')]
 
87
    takes_args = [ "location?" ]
 
88
    aliases = [ "visualize", "vis", "viz" ]
 
89
 
 
90
    def run(self, location=".", revision=None, limit=None):
 
91
        (branch, path) = Branch.open_containing(location)
 
92
        branch.lock_read()
 
93
        branch.repository.lock_read()
 
94
        try:
 
95
            if revision is None:
 
96
                revid = branch.last_revision()
 
97
                if revid is None:
 
98
                    return
 
99
            else:
 
100
                (revno, revid) = revision[0].in_history(branch)
 
101
 
 
102
            from viz.bzrkapp import BzrkApp
 
103
                
 
104
            app = BzrkApp()
 
105
            app.show(branch, revid, limit)
 
106
        finally:
 
107
            branch.repository.unlock()
 
108
            branch.unlock()
 
109
        app.main()
 
110
 
 
111
 
 
112
register_command(cmd_visualise)
 
113
 
 
114
class cmd_gannotate(Command):
 
115
    """GTK+ annotate.
 
116
    
 
117
    Browse changes to FILENAME line by line in a GTK+ window.
 
118
    """
 
119
 
 
120
    takes_args = ["filename"]
 
121
    takes_options = [
 
122
        Option("all", help="show annotations on all lines"),
 
123
        Option("plain", help="don't highlight annotation lines"),
 
124
        Option("line", type=int, argname="lineno",
 
125
               help="jump to specified line number")
 
126
    ]
 
127
    aliases = ["gblame", "gpraise"]
 
128
    
 
129
    def run(self, filename, all=False, plain=False, line=1):
 
130
        import pygtk
 
131
        pygtk.require("2.0")
 
132
 
 
133
        try:
 
134
            import gtk
 
135
        except RuntimeError, e:
 
136
            if str(e) == "could not open display":
 
137
                raise NoDisplayError
 
138
 
 
139
        from annotate.gannotate import GAnnotateWindow
 
140
        from annotate.config import GAnnotateConfig
 
141
 
 
142
        (wt, path) = WorkingTree.open_containing(filename)
 
143
        branch = wt.branch
 
144
 
 
145
        file_id = wt.path2id(path)
 
146
 
 
147
        if file_id is None:
 
148
            raise NotVersionedError(filename)
 
149
 
 
150
        window = GAnnotateWindow(all, plain)
 
151
        window.connect("destroy", lambda w: gtk.main_quit())
 
152
        window.set_title(path + " - gannotate")
 
153
        config = GAnnotateConfig(window)
 
154
        window.show()
 
155
        branch.lock_read()
 
156
        try:
 
157
            window.annotate(branch, file_id)
 
158
        finally:
 
159
            branch.unlock()
 
160
        window.jump_to_line(line)
 
161
        
 
162
        gtk.main()
 
163
 
 
164
register_command(cmd_gannotate)
 
165
 
 
166
class cmd_gcommit(Command):
 
167
    """GTK+ commit dialog
 
168
 
 
169
    Graphical user interface for committing revisions"""
 
170
    
 
171
    takes_args = []
 
172
    takes_options = []
 
173
 
 
174
    def run(self, filename=None):
 
175
        import pygtk
 
176
        pygtk.require("2.0")
 
177
 
 
178
        try:
 
179
            import gtk
 
180
        except RuntimeError, e:
 
181
            if str(e) == "could not open display":
 
182
                raise NoDisplayError
 
183
 
 
184
        from commit import GCommitDialog
 
185
        from bzrlib.commit import Commit
 
186
        from bzrlib.errors import (BzrCommandError, PointlessCommit, ConflictsInTree, 
 
187
           StrictCommitFailed)
 
188
 
 
189
        (wt, path) = WorkingTree.open_containing(filename)
 
190
        branch = wt.branch
 
191
 
 
192
        file_id = wt.path2id(path)
 
193
 
 
194
        if file_id is None:
 
195
            raise NotVersionedError(filename)
 
196
 
 
197
        dialog = GCommitDialog(wt)
 
198
        dialog.set_title(path + " - Commit")
 
199
        if dialog.run() != gtk.RESPONSE_CANCEL:
 
200
            Commit().commit(working_tree=wt,message=dialog.message,
 
201
                specific_files=dialog.specific_files)
 
202
 
 
203
register_command(cmd_gcommit)
 
204
 
 
205
class NoDisplayError(BzrCommandError):
 
206
    """gtk could not find a proper display"""
 
207
 
 
208
    def __str__(self):
 
209
        return "No DISPLAY. gannotate is disabled."