bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
1
by Scott James Remnant
Commit the first version of bzrk. |
1 |
# -*- coding: UTF-8 -*-
|
2 |
"""Branch window.
|
|
3 |
||
4 |
This module contains the code to manage the branch information window,
|
|
5 |
which contains both the revision graph and details panes.
|
|
6 |
"""
|
|
7 |
||
8 |
__copyright__ = "Copyright © 2005 Canonical Ltd." |
|
9 |
__author__ = "Scott James Remnant <scott@ubuntu.com>" |
|
10 |
||
11 |
||
12 |
import gtk |
|
13 |
import gobject |
|
14 |
import pango |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
15 |
import treemodel |
1
by Scott James Remnant
Commit the first version of bzrk. |
16 |
|
17 |
from bzrlib.osutils import format_date |
|
18 |
||
256.2.5
by Gary van der Merwe
Oops - Renamed file without changeing import lines |
19 |
from linegraph import linegraph, same_branch |
1
by Scott James Remnant
Commit the first version of bzrk. |
20 |
from graphcell import CellRendererGraph |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
21 |
from treemodel import TreeModel |
303
by Daniel Schierbeck
Made basic signaling work. |
22 |
from treeview import TreeView |
1
by Scott James Remnant
Commit the first version of bzrk. |
23 |
|
24 |
class BranchWindow(gtk.Window): |
|
25 |
"""Branch window. |
|
26 |
||
27 |
This object represents and manages a single window containing information
|
|
28 |
for a particular branch.
|
|
29 |
"""
|
|
30 |
||
315
by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead. |
31 |
def __init__(self, branch, start, maxnum, parent=None): |
1
by Scott James Remnant
Commit the first version of bzrk. |
32 |
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL) |
33 |
self.set_border_width(0) |
|
315
by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead. |
34 |
|
35 |
self.branch = branch |
|
36 |
self.start = start |
|
37 |
self.maxnum = maxnum |
|
38 |
||
39 |
self.set_title(branch.nick + " - revision history") |
|
1
by Scott James Remnant
Commit the first version of bzrk. |
40 |
|
275.1.6
by Daniel Schierbeck
Made Ctrl-W call gtk.main_quit if the window has no parent. |
41 |
self._parent = parent |
42 |
||
43 |
self.connect('key-press-event', self._on_key_pressed) |
|
275.1.1
by Daniel Schierbeck
Close branch visualization window when 'destroy' message is received. |
44 |
|
1
by Scott James Remnant
Commit the first version of bzrk. |
45 |
# Use three-quarters of the screen by default
|
46 |
screen = self.get_screen() |
|
4
by Scott James Remnant
Use the size of the first monitor rather than the entire screen |
47 |
monitor = screen.get_monitor_geometry(0) |
48 |
width = int(monitor.width * 0.75) |
|
49 |
height = int(monitor.height * 0.75) |
|
1
by Scott James Remnant
Commit the first version of bzrk. |
50 |
self.set_default_size(width, height) |
51 |
||
52 |
# FIXME AndyFitz!
|
|
53 |
icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON) |
|
54 |
self.set_icon(icon) |
|
55 |
||
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
56 |
self.accel_group = gtk.AccelGroup() |
57 |
self.add_accel_group(self.accel_group) |
|
58 |
||
1
by Scott James Remnant
Commit the first version of bzrk. |
59 |
self.construct() |
60 |
||
61 |
def construct(self): |
|
62 |
"""Construct the window contents.""" |
|
44
by David Allouche
reorganise branch window |
63 |
vbox = gtk.VBox(spacing=0) |
64 |
self.add(vbox) |
|
65 |
||
66 |
vbox.pack_start(self.construct_navigation(), expand=False, fill=True) |
|
280.2.1
by Gary van der Merwe
Add a message to the viz window to indicate that graph is still loading. |
67 |
vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True) |
68 |
||
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
69 |
paned = gtk.VPaned() |
70 |
paned.pack1(self.construct_top(), resize=True, shrink=False) |
|
7
by Scott James Remnant
Put some information about the highlighted revision in the bottom pane, |
71 |
paned.pack2(self.construct_bottom(), resize=False, shrink=True) |
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
72 |
paned.show() |
44
by David Allouche
reorganise branch window |
73 |
vbox.pack_start(paned, expand=True, fill=True) |
74 |
vbox.set_focus_child(paned) |
|
75 |
||
76 |
vbox.show() |
|
280.2.1
by Gary van der Merwe
Add a message to the viz window to indicate that graph is still loading. |
77 |
|
78 |
def construct_loading_msg(self): |
|
79 |
image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH, |
|
80 |
gtk.ICON_SIZE_BUTTON) |
|
81 |
image_loading.show() |
|
82 |
||
83 |
label_loading = gtk.Label(_("Please wait, loading ancestral graph...")) |
|
84 |
label_loading.set_alignment(0.0, 0.5) |
|
85 |
label_loading.show() |
|
86 |
||
87 |
self.loading_msg_box = gtk.HBox() |
|
88 |
self.loading_msg_box.set_spacing(5) |
|
89 |
self.loading_msg_box.set_border_width(5) |
|
90 |
self.loading_msg_box.pack_start(image_loading, False, False) |
|
91 |
self.loading_msg_box.pack_start(label_loading, True, True) |
|
92 |
self.loading_msg_box.show() |
|
93 |
||
94 |
return self.loading_msg_box |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
95 |
|
96 |
def construct_top(self): |
|
97 |
"""Construct the top-half of the window.""" |
|
316
by Daniel Schierbeck
Removed viz.TreeView.set_branch() |
98 |
self.treeview = TreeView(self.branch, self.start, self.maxnum) |
315
by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead. |
99 |
|
310
by Daniel Schierbeck
Moved to using custom signal for handling revision selections. |
100 |
self.treeview.connect("revision-selected", |
303
by Daniel Schierbeck
Made basic signaling work. |
101 |
self._treeselection_changed_cb) |
102 |
||
307
by Daniel Schierbeck
Made load notification work again. |
103 |
self.treeview.connect('revisions-loaded', |
104 |
lambda x: self.loading_msg_box.hide()) |
|
105 |
||
1
by Scott James Remnant
Commit the first version of bzrk. |
106 |
self.treeview.show() |
107 |
||
303
by Daniel Schierbeck
Made basic signaling work. |
108 |
return self.treeview |
44
by David Allouche
reorganise branch window |
109 |
|
110 |
def construct_navigation(self): |
|
111 |
"""Construct the navigation buttons.""" |
|
112 |
frame = gtk.Frame() |
|
113 |
frame.set_shadow_type(gtk.SHADOW_OUT) |
|
114 |
frame.show() |
|
115 |
||
116 |
hbox = gtk.HBox(spacing=12) |
|
117 |
frame.add(hbox) |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
118 |
hbox.show() |
119 |
||
120 |
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK) |
|
44
by David Allouche
reorganise branch window |
121 |
self.back_button.set_relief(gtk.RELIEF_NONE) |
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
122 |
self.back_button.add_accelerator("clicked", self.accel_group, ord('['), |
123 |
0, 0) |
|
124 |
self.back_button.connect("clicked", self._back_clicked_cb) |
|
125 |
hbox.pack_start(self.back_button, expand=False, fill=True) |
|
126 |
self.back_button.show() |
|
127 |
||
128 |
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD) |
|
44
by David Allouche
reorganise branch window |
129 |
self.fwd_button.set_relief(gtk.RELIEF_NONE) |
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
130 |
self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'), |
131 |
0, 0) |
|
132 |
self.fwd_button.connect("clicked", self._fwd_clicked_cb) |
|
133 |
hbox.pack_start(self.fwd_button, expand=False, fill=True) |
|
134 |
self.fwd_button.show() |
|
135 |
||
44
by David Allouche
reorganise branch window |
136 |
return frame |
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
137 |
|
138 |
def construct_bottom(self): |
|
139 |
"""Construct the bottom half of the window.""" |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
140 |
from bzrlib.plugins.gtk.logview import LogView |
256.2.23
by Gary van der Merwe
Show Children |
141 |
self.logview = LogView(None, True, [], True) |
44
by David Allouche
reorganise branch window |
142 |
(width, height) = self.get_size() |
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
143 |
self.logview.set_size_request(width, int(height / 2.5)) |
144 |
self.logview.show() |
|
145 |
self.logview.set_show_callback(self._show_clicked_cb) |
|
146 |
self.logview.set_go_callback(self._go_clicked_cb) |
|
147 |
return self.logview |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
148 |
|
275.1.5
by Daniel Schierbeck
Made windows close correctly on Ctrl-W and made the application quit on Ctrl-Q. |
149 |
def _on_key_pressed(self, widget, event): |
150 |
""" Key press event handler. """ |
|
151 |
keyname = gtk.gdk.keyval_name(event.keyval) |
|
152 |
func = getattr(self, '_on_key_press_' + keyname, None) |
|
153 |
if func: |
|
154 |
return func(event) |
|
155 |
||
156 |
def _on_key_press_w(self, event): |
|
157 |
if event.state & gtk.gdk.CONTROL_MASK: |
|
158 |
self.destroy() |
|
275.1.6
by Daniel Schierbeck
Made Ctrl-W call gtk.main_quit if the window has no parent. |
159 |
if self._parent is None: |
160 |
gtk.main_quit() |
|
275.1.5
by Daniel Schierbeck
Made windows close correctly on Ctrl-W and made the application quit on Ctrl-Q. |
161 |
|
162 |
def _on_key_press_q(self, event): |
|
163 |
if event.state & gtk.gdk.CONTROL_MASK: |
|
164 |
gtk.main_quit() |
|
265.1.1
by Gary van der Merwe
Show bzr viz interface quickly. |
165 |
|
280.1.2
by Daniel Schierbeck
Switched to handle the 'changed' signal from the treeview's treeselection instead of the 'cursor-changed' signal from the treeview itself, allowing more flexibility (particularly the ability to handle programmatic selections) |
166 |
def _treeselection_changed_cb(self, selection, *args): |
303
by Daniel Schierbeck
Made basic signaling work. |
167 |
"""callback for when the treeview changes.""" |
168 |
revision = self.treeview.get_revision() |
|
169 |
parents = self.treeview.get_parents() |
|
170 |
children = self.treeview.get_children() |
|
171 |
||
172 |
if revision is not None: |
|
256.2.62
by Gary van der Merwe
Merge Trunk. |
173 |
self.back_button.set_sensitive(len(parents) > 0) |
174 |
self.fwd_button.set_sensitive(len(children) > 0) |
|
280.1.2
by Daniel Schierbeck
Switched to handle the 'changed' signal from the treeview's treeselection instead of the 'cursor-changed' signal from the treeview itself, allowing more flexibility (particularly the ability to handle programmatic selections) |
175 |
tags = [] |
176 |
if self.branch.supports_tags(): |
|
177 |
tagdict = self.branch.tags.get_reverse_tag_dict() |
|
178 |
if tagdict.has_key(revision.revision_id): |
|
179 |
tags = tagdict[revision.revision_id] |
|
256.2.62
by Gary van der Merwe
Merge Trunk. |
180 |
self.logview.set_revision(revision, tags, children) |
7
by Scott James Remnant
Put some information about the highlighted revision in the bottom pane, |
181 |
|
3
by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show |
182 |
def _back_clicked_cb(self, *args): |
183 |
"""Callback for when the back button is clicked.""" |
|
304
by Daniel Schierbeck
Made forward/back buttons work again. |
184 |
self.treeview.back() |
185 |
||
5
by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually |
186 |
def _fwd_clicked_cb(self, *args): |
187 |
"""Callback for when the forward button is clicked.""" |
|
304
by Daniel Schierbeck
Made forward/back buttons work again. |
188 |
self.treeview.forward() |
7
by Scott James Remnant
Put some information about the highlighted revision in the bottom pane, |
189 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
190 |
def _go_clicked_cb(self, revid): |
7
by Scott James Remnant
Put some information about the highlighted revision in the bottom pane, |
191 |
"""Callback for when the go button for a parent is clicked.""" |
305
by Daniel Schierbeck
Moved revision selection to the new view. |
192 |
self.treeview.set_revision(revid) |
7
by Scott James Remnant
Put some information about the highlighted revision in the bottom pane, |
193 |
|
147
by Jelmer Vernooij
Remove a bunch of duplicate functionality. |
194 |
def _show_clicked_cb(self, revid, parentid): |
7
by Scott James Remnant
Put some information about the highlighted revision in the bottom pane, |
195 |
"""Callback for when the show button for a parent is clicked.""" |
308
by Daniel Schierbeck
Made Show Diff work again. |
196 |
self.treeview.show_diff(self.branch, revid, parentid) |
13
by Scott James Remnant
Keep the focus on the treeview |
197 |
self.treeview.grab_focus() |
46
by Wouter van Heyst
show diff on row activation, LP# 44591 |
198 |