bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
1
by Scott James Remnant
Commit the first version of bzrk. |
1 |
#!/usr/bin/python
|
2 |
# -*- coding: UTF-8 -*-
|
|
3 |
"""Branch window.
|
|
4 |
||
5 |
This module contains the code to manage the branch information window,
|
|
6 |
which contains both the revision graph and details panes.
|
|
7 |
"""
|
|
8 |
||
9 |
__copyright__ = "Copyright © 2005 Canonical Ltd." |
|
10 |
__author__ = "Scott James Remnant <scott@ubuntu.com>" |
|
11 |
||
12 |
||
13 |
import os |
|
14 |
||
15 |
import gtk |
|
16 |
import gobject |
|
17 |
import pango |
|
18 |
||
19 |
from bzrlib.osutils import format_date |
|
20 |
||
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
21 |
from graph import distances, graph, same_branch |
1
by Scott James Remnant
Commit the first version of bzrk. |
22 |
from graphcell import CellRendererGraph |
23 |
||
24 |
||
25 |
class BranchWindow(gtk.Window): |
|
26 |
"""Branch window. |
|
27 |
||
28 |
This object represents and manages a single window containing information
|
|
29 |
for a particular branch.
|
|
30 |
"""
|
|
31 |
||
32 |
def __init__(self): |
|
33 |
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) |
|
34 |
self.set_border_width(0) |
|
35 |
self.set_title("bzrk") |
|
36 |
||
37 |
# Use three-quarters of the screen by default
|
|
38 |
screen = self.get_screen() |
|
4
by Scott James Remnant
Use the size of the first monitor rather than the entire screen |
39 |
monitor = screen.get_monitor_geometry(0) |
40 |
width = int(monitor.width * 0.75) |
|
41 |
height = int(monitor.height * 0.75) |
|
1
by Scott James Remnant
Commit the first version of bzrk. |
42 |
self.set_default_size(width, height) |
43 |
||
44 |
# FIXME AndyFitz!
|
|
45 |
icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON) |
|
46 |
self.set_icon(icon) |
|
47 |
||
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
48 |
self.accel_group = gtk.AccelGroup() |
49 |
self.add_accel_group(self.accel_group) |
|
50 |
||
1
by Scott James Remnant
Commit the first version of bzrk. |
51 |
self.construct() |
52 |
||
53 |
def construct(self): |
|
54 |
"""Construct the window contents.""" |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
55 |
paned = gtk.VPaned() |
56 |
paned.pack1(self.construct_top(), resize=True, shrink=False) |
|
57 |
paned.pack2(self.construct_bottom(), resize=True, shrink=True) |
|
58 |
self.add(paned) |
|
59 |
paned.show() |
|
60 |
||
61 |
def construct_top(self): |
|
62 |
"""Construct the top-half of the window.""" |
|
63 |
vbox = gtk.VBox(spacing=6) |
|
64 |
vbox.set_border_width(12) |
|
65 |
vbox.show() |
|
66 |
||
1
by Scott James Remnant
Commit the first version of bzrk. |
67 |
scrollwin = gtk.ScrolledWindow() |
68 |
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) |
|
69 |
scrollwin.set_shadow_type(gtk.SHADOW_IN) |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
70 |
vbox.pack_start(scrollwin, expand=True, fill=True) |
1
by Scott James Remnant
Commit the first version of bzrk. |
71 |
scrollwin.show() |
72 |
||
73 |
self.treeview = gtk.TreeView() |
|
74 |
self.treeview.set_rules_hint(True) |
|
75 |
self.treeview.set_search_column(4) |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
76 |
self.treeview.connect("cursor-changed", self._treeview_cursor_cb) |
1
by Scott James Remnant
Commit the first version of bzrk. |
77 |
scrollwin.add(self.treeview) |
78 |
self.treeview.show() |
|
79 |
||
80 |
cell = CellRendererGraph() |
|
81 |
column = gtk.TreeViewColumn() |
|
82 |
column.set_resizable(False) |
|
83 |
column.pack_start(cell, expand=False) |
|
84 |
column.add_attribute(cell, "node", 1) |
|
85 |
column.add_attribute(cell, "in-lines", 2) |
|
86 |
column.add_attribute(cell, "out-lines", 3) |
|
87 |
self.treeview.append_column(column) |
|
88 |
||
89 |
cell = gtk.CellRendererText() |
|
90 |
cell.set_property("width-chars", 40) |
|
91 |
cell.set_property("ellipsize", pango.ELLIPSIZE_END) |
|
92 |
column = gtk.TreeViewColumn("Message") |
|
93 |
column.set_resizable(True) |
|
94 |
column.pack_start(cell, expand=True) |
|
95 |
column.add_attribute(cell, "text", 4) |
|
96 |
self.treeview.append_column(column) |
|
97 |
||
98 |
cell = gtk.CellRendererText() |
|
99 |
cell.set_property("width-chars", 40) |
|
100 |
cell.set_property("ellipsize", pango.ELLIPSIZE_END) |
|
101 |
column = gtk.TreeViewColumn("Committer") |
|
102 |
column.set_resizable(True) |
|
103 |
column.pack_start(cell, expand=True) |
|
104 |
column.add_attribute(cell, "text", 5) |
|
105 |
self.treeview.append_column(column) |
|
106 |
||
107 |
cell = gtk.CellRendererText() |
|
108 |
cell.set_property("ellipsize", pango.ELLIPSIZE_END) |
|
109 |
column = gtk.TreeViewColumn("Date") |
|
110 |
column.set_resizable(True) |
|
111 |
column.pack_start(cell, expand=True) |
|
112 |
column.add_attribute(cell, "text", 6) |
|
113 |
self.treeview.append_column(column) |
|
114 |
||
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
115 |
hbox = gtk.HBox(False, spacing=6) |
116 |
vbox.pack_start(hbox, expand=False, fill=False) |
|
117 |
hbox.show() |
|
118 |
||
119 |
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK) |
|
120 |
self.back_button.add_accelerator("clicked", self.accel_group, ord('['), |
|
121 |
0, 0) |
|
122 |
self.back_button.connect("clicked", self._back_clicked_cb) |
|
123 |
hbox.pack_start(self.back_button, expand=False, fill=True) |
|
124 |
self.back_button.show() |
|
125 |
||
126 |
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD) |
|
127 |
self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'), |
|
128 |
0, 0) |
|
129 |
self.fwd_button.connect("clicked", self._fwd_clicked_cb) |
|
130 |
hbox.pack_start(self.fwd_button, expand=False, fill=True) |
|
131 |
self.fwd_button.show() |
|
132 |
||
133 |
return vbox |
|
134 |
||
135 |
def construct_bottom(self): |
|
136 |
"""Construct the bottom half of the window.""" |
|
137 |
label = gtk.Label("test") |
|
138 |
label.show() |
|
139 |
||
140 |
return label |
|
141 |
||
1
by Scott James Remnant
Commit the first version of bzrk. |
142 |
def set_branch(self, branch, start): |
143 |
"""Set the branch and start position for this window. |
|
144 |
||
145 |
Creates a new TreeModel and populates it with information about
|
|
146 |
the new branch before updating the window title and model of the
|
|
147 |
treeview itself.
|
|
148 |
"""
|
|
149 |
# [ revision, node, last_lines, lines, message, committer, timestamp ]
|
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
150 |
self.model = gtk.ListStore(gobject.TYPE_PYOBJECT, |
151 |
gobject.TYPE_PYOBJECT, |
|
152 |
gobject.TYPE_PYOBJECT, |
|
153 |
gobject.TYPE_PYOBJECT, |
|
154 |
str, str, str) |
|
155 |
self.index = {} |
|
156 |
index = 0 |
|
1
by Scott James Remnant
Commit the first version of bzrk. |
157 |
|
158 |
last_lines = [] |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
159 |
(revids, self.revisions, colours, self.children) \ |
160 |
= distances(branch, start) |
|
161 |
for revision, node, lines in graph(revids, self.revisions, colours): |
|
1
by Scott James Remnant
Commit the first version of bzrk. |
162 |
message = revision.message.split("\n")[0] |
163 |
if revision.committer is not None: |
|
164 |
timestamp = format_date(revision.timestamp, revision.timezone) |
|
165 |
else: |
|
166 |
timestamp = None |
|
167 |
||
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
168 |
self.model.append([ revision, node, last_lines, lines, |
169 |
message, revision.committer, timestamp ]) |
|
170 |
self.index[revision] = index |
|
171 |
index += 1 |
|
172 |
||
1
by Scott James Remnant
Commit the first version of bzrk. |
173 |
last_lines = lines |
174 |
||
175 |
self.set_title(os.path.basename(branch.base) + " - bzrk") |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
176 |
self.treeview.set_model(self.model) |
177 |
||
178 |
def _treeview_cursor_cb(self, *args): |
|
179 |
"""Callback for when the treeview cursor changes.""" |
|
180 |
(path, col) = self.treeview.get_cursor() |
|
181 |
revision = self.model[path][0] |
|
182 |
||
5
by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually |
183 |
self.back_button.set_sensitive(len(revision.parent_ids) > 0) |
184 |
self.fwd_button.set_sensitive(len(self.children[revision]) > 0) |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
185 |
|
186 |
def _back_clicked_cb(self, *args): |
|
187 |
"""Callback for when the back button is clicked.""" |
|
188 |
(path, col) = self.treeview.get_cursor() |
|
189 |
revision = self.model[path][0] |
|
190 |
if not len(revision.parent_ids): |
|
191 |
return
|
|
192 |
||
193 |
for parent_id in revision.parent_ids: |
|
194 |
parent = self.revisions[parent_id] |
|
195 |
if same_branch(revision, parent): |
|
196 |
self.treeview.set_cursor(self.index[parent]) |
|
197 |
break
|
|
198 |
else: |
|
199 |
next = self.revisions[revision.parent_ids[0]] |
|
200 |
self.treeview.set_cursor(self.index[next]) |
|
201 |
||
5
by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually |
202 |
def _fwd_clicked_cb(self, *args): |
203 |
"""Callback for when the forward button is clicked.""" |
|
204 |
(path, col) = self.treeview.get_cursor() |
|
205 |
revision = self.model[path][0] |
|
206 |
if not len(self.children[revision]): |
|
207 |
return
|
|
208 |
||
209 |
for child in self.children[revision]: |
|
210 |
if same_branch(child, revision): |
|
211 |
self.treeview.set_cursor(self.index[child]) |
|
212 |
break
|
|
213 |
else: |
|
214 |
prev = list(self.children[revision])[0] |
|
215 |
self.treeview.set_cursor(self.index[prev]) |