/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-05-20 19:24:12 UTC
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: jelmer@samba.org-20060520192412-d71ad24912cb3fad
Move commands to top-level __init__

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 GCloneDialog
 
41
 
 
42
        window = GCloneDialog()
 
43
        if window.run() == gtk.RESPONSE_OK:
 
44
            print window.url
 
45
            print 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
        bzrdir = BzrDir.open_containing(".")[0]
 
60
        repos = bzrdir.open_repository()
 
61
        branch = bzrdir.open_branch()
 
62
        tree2 = repos.revision_tree(branch.last_revision())
 
63
        tree1 = WorkingTree.open_containing(".")[0]
 
64
 
 
65
        from viz.diffwin import DiffWindow
 
66
        try:
 
67
            import gtk
 
68
        except RuntimeError, e:
 
69
            if str(e) == "could not open display":
 
70
                raise NoDisplayError
 
71
        window = DiffWindow()
 
72
        window.connect("destroy", lambda w: gtk.main_quit())
 
73
        window.set_diff("Working Tree", tree1, tree2)
 
74
        window.show()
 
75
 
 
76
        gtk.main()
 
77
 
 
78
register_command(cmd_gdiff)
 
79
 
 
80
class cmd_visualise(Command):
 
81
    """Graphically visualise this branch.
 
82
 
 
83
    Opens a graphical window to allow you to see the history of the branch
 
84
    and relationships between revisions in a visual manner,
 
85
 
 
86
    The default starting point is latest revision on the branch, you can
 
87
    specify a starting point with -r revision.
 
88
    """
 
89
    takes_options = [
 
90
        "revision",
 
91
        Option('limit', "maximum number of revisions to display",
 
92
               int, 'count')]
 
93
    takes_args = [ "location?" ]
 
94
    aliases = [ "visualize", "vis", "viz" ]
 
95
 
 
96
    def run(self, location=".", revision=None, limit=None):
 
97
        (branch, path) = Branch.open_containing(location)
 
98
        branch.lock_read()
 
99
        branch.repository.lock_read()
 
100
        try:
 
101
            if revision is None:
 
102
                revid = branch.last_revision()
 
103
                if revid is None:
 
104
                    return
 
105
            else:
 
106
                (revno, revid) = revision[0].in_history(branch)
 
107
 
 
108
            from viz.bzrkapp import BzrkApp
 
109
                
 
110
            app = BzrkApp()
 
111
            app.show(branch, revid, limit)
 
112
        finally:
 
113
            branch.repository.unlock()
 
114
            branch.unlock()
 
115
        app.main()
 
116
 
 
117
 
 
118
register_command(cmd_visualise)
 
119
 
 
120
class cmd_gannotate(Command):
 
121
    """GTK+ annotate.
 
122
    
 
123
    Browse changes to FILENAME line by line in a GTK+ window.
 
124
    """
 
125
 
 
126
    takes_args = ["filename"]
 
127
    takes_options = [
 
128
        Option("all", help="show annotations on all lines"),
 
129
        Option("plain", help="don't highlight annotation lines"),
 
130
        Option("line", type=int, argname="lineno",
 
131
               help="jump to specified line number")
 
132
    ]
 
133
    aliases = ["gblame", "gpraise"]
 
134
    
 
135
    def run(self, filename, all=False, plain=False, line=1):
 
136
        import pygtk
 
137
        pygtk.require("2.0")
 
138
 
 
139
        try:
 
140
            import gtk
 
141
        except RuntimeError, e:
 
142
            if str(e) == "could not open display":
 
143
                raise NoDisplayError
 
144
 
 
145
        from annotate.gannotate import GAnnotateWindow
 
146
        from annotate.config import GAnnotateConfig
 
147
 
 
148
        (wt, path) = WorkingTree.open_containing(filename)
 
149
        branch = wt.branch
 
150
 
 
151
        file_id = wt.path2id(path)
 
152
 
 
153
        if file_id is None:
 
154
            raise NotVersionedError(filename)
 
155
 
 
156
        window = GAnnotateWindow(all, plain)
 
157
        window.connect("destroy", lambda w: gtk.main_quit())
 
158
        window.set_title(path + " - gannotate")
 
159
        config = GAnnotateConfig(window)
 
160
        window.show()
 
161
        branch.lock_read()
 
162
        try:
 
163
            window.annotate(branch, file_id)
 
164
        finally:
 
165
            branch.unlock()
 
166
        window.jump_to_line(line)
 
167
        
 
168
        gtk.main()
 
169
 
 
170
register_command(cmd_gannotate)
 
171
 
 
172
class cmd_gcommit(Command):
 
173
    """GTK+ commit dialog
 
174
 
 
175
    Graphical user interface for committing revisions"""
 
176
    
 
177
    takes_args = []
 
178
    takes_options = []
 
179
 
 
180
    def run(self, filename=None):
 
181
        import pygtk
 
182
        pygtk.require("2.0")
 
183
 
 
184
        try:
 
185
            import gtk
 
186
        except RuntimeError, e:
 
187
            if str(e) == "could not open display":
 
188
                raise NoDisplayError
 
189
 
 
190
        from commit import GCommitDialog
 
191
        from bzrlib.commit import Commit
 
192
        from bzrlib.errors import (BzrCommandError, PointlessCommit, ConflictsInTree, 
 
193
           StrictCommitFailed)
 
194
 
 
195
        (wt, path) = WorkingTree.open_containing(filename)
 
196
        branch = wt.branch
 
197
 
 
198
        file_id = wt.path2id(path)
 
199
 
 
200
        if file_id is None:
 
201
            raise NotVersionedError(filename)
 
202
 
 
203
        dialog = GCommitDialog(wt)
 
204
        dialog.set_title(path + " - Commit")
 
205
        if dialog.run() != gtk.RESPONSE_CANCEL:
 
206
            Commit().commit(working_tree=wt,message=dialog.message,
 
207
                specific_files=dialog.specific_files)
 
208
 
 
209
register_command(cmd_gcommit)
 
210
 
 
211
class NoDisplayError(BzrCommandError):
 
212
    """gtk could not find a proper display"""
 
213
 
 
214
    def __str__(self):
 
215
        return "No DISPLAY. gannotate is disabled."