Rev 514: Merge Chad's progress bar in viz patch. in file:///data/jelmer/bzr-gtk/trunk/
Jelmer Vernooij
jelmer at samba.org
Sun Jun 29 17:11:14 BST 2008
At file:///data/jelmer/bzr-gtk/trunk/
------------------------------------------------------------
revno: 514
revision-id: jelmer at samba.org-20080629161112-3j4zp0r0e7cv6cds
parent: jelmer at samba.org-20080629155440-iuzfrlfifnplp9jq
parent: chad at mysql.com-20080501140949-zg3vgni13mi8qojr
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sun 2008-06-29 18:11:12 +0200
message:
Merge Chad's progress bar in viz patch.
modified:
branchview/linegraph.py graph.py-20051016214152-ebf565808c860cf7
branchview/treeview.py treeview.py-20071020204704-vk1erblrjhbcgw94-1
ui.py ui.py-20060716163355-owuqwa9uhnlfsojs-1
------------------------------------------------------------
revno: 475.2.2
revision-id: chad at mysql.com-20080501140949-zg3vgni13mi8qojr
parent: chad at mysql.com-20080501120626-8k0ay6jee6tfz1sz
committer: Chad MILLER <chad at mysql.com>
branch nick: gtk
timestamp: Thu 2008-05-01 10:09:49 -0400
message:
Big diff, few changes. :(
Wrap sub-progress bars in try/finally to ensure they're cleaned up.
Make the root progress bar optional.
modified:
branchview/linegraph.py graph.py-20051016214152-ebf565808c860cf7
branchview/treeview.py treeview.py-20071020204704-vk1erblrjhbcgw94-1
------------------------------------------------------------
revno: 475.2.1
revision-id: chad at mysql.com-20080501120626-8k0ay6jee6tfz1sz
parent: jelmer at samba.org-20080425213841-4569rcvea3yx09q5
committer: Chad MILLER <chad at mysql.com>
branch nick: gtk
timestamp: Thu 2008-05-01 08:06:26 -0400
message:
Make "vizualize" use the GUI progress bar defined in the parent 'ui' module.
Update the progress bar so that one need not specify both the total steps and
the current step with every update.
Remove extraneous signaling and put related progress-bar element close to its
use.
TODO: Given a nested-progress-bar object, one should be able to use it as a
factory of sub-bars.
modified:
branchview/linegraph.py graph.py-20051016214152-ebf565808c860cf7
branchview/treeview.py treeview.py-20071020204704-vk1erblrjhbcgw94-1
ui.py ui.py-20060716163355-owuqwa9uhnlfsojs-1
=== modified file 'branchview/linegraph.py'
--- a/branchview/linegraph.py 2008-06-29 15:54:40 +0000
+++ b/branchview/linegraph.py 2008-06-29 16:11:12 +0000
@@ -11,9 +11,10 @@
from bzrlib.revision import NULL_REVISION
from bzrlib.tsort import merge_sort
+from bzrlib import ui
def linegraph(graph, start_revs, maxnum=None, broken_line_length=None,
- graph_data=True, mainline_only=False):
+ graph_data=True, mainline_only=False, root_progress=None):
"""Produce a directed graph of a bzr repository.
Returns a tuple of (line_graph, revid_index, columns_len) where
@@ -42,25 +43,47 @@
It's up to you how to actually draw the nodes and lines (straight,
curved, kinked, etc.) and to pick the actual colours for each index.
"""
-
+ assert isinstance(start_revs, list)
+ def update_root_progress(step_number):
+ """IFF our container received a root progress bar, then update it."""
+ if root_progress is not None:
+ root_progress.update(current=step_number)
+
graph_parents = {}
ghosts = set()
graph_children = {}
- for (revid, parent_revids) in graph.iter_ancestry(start_revs):
- if parent_revids is None:
- ghosts.add(revid)
- continue
- if parent_revids == (NULL_REVISION,):
- graph_parents[revid] = ()
- else:
- graph_parents[revid] = parent_revids
- for parent in parent_revids:
- graph_children.setdefault(parent, []).append(revid)
- graph_children.setdefault(revid, [])
- for ghost in ghosts:
- for ghost_child in graph_children[ghost]:
- graph_parents[ghost_child] = [p for p in graph_parents[ghost_child]
- if p not in ghosts]
+ update_root_progress(1)
+ progress_bar = ui.ui_factory.nested_progress_bar()
+ try:
+ progress_bar.update(msg="Arranging tree fragments")
+ for i, (revid, parent_revids) in enumerate(graph.iter_ancestry(start_revs)):
+ if i % 25 == 0:
+ progress_bar.tick()
+ if parent_revids is None:
+ ghosts.add(revid)
+ continue
+ if parent_revids == (NULL_REVISION,):
+ graph_parents[revid] = ()
+ else:
+ graph_parents[revid] = parent_revids
+ for parent in parent_revids:
+ graph_children.setdefault(parent, []).append(revid)
+ graph_children.setdefault(revid, [])
+ finally:
+ progress_bar.finished()
+
+ update_root_progress(2)
+ progress_bar = ui.ui_factory.nested_progress_bar()
+ try:
+ progress_bar.update(msg="Removing ghosts", total=len(ghosts))
+ for i, ghost in enumerate(ghosts):
+ if i % 25 == 0:
+ progress_bar.update(current=i)
+ for ghost_child in graph_children[ghost]:
+ graph_parents[ghost_child] = [p for p in graph_parents[ghost_child]
+ if p not in ghosts]
+ finally:
+ progress_bar.finished()
graph_parents["top:"] = start_revs
if len(graph_parents)>0:
@@ -92,36 +115,45 @@
linegraph = []
- for (rev_index, (sequence_number,
- revid,
- merge_depth,
- revno_sequence,
- end_of_merge)) in enumerate(merge_sorted_revisions):
- if maxnum and rev_index >= maxnum:
- break
- revid_index[revid] = rev_index
-
- parents = graph_parents[revid]
- linegraph.append([revid,
- None,
- [],
- parents,
- None,
- revno_sequence])
-
- if graph_data:
- revno_index[revno_sequence] = rev_index
-
- branch_id = revno_sequence[0:-1]
-
- branch_line = None
- if branch_id not in branch_lines:
- branch_line = []
- branch_lines[branch_id] = branch_line
- else:
- branch_line = branch_lines[branch_id]
-
- branch_line.append(rev_index)
+ update_root_progress(3)
+ progress_bar = ui.ui_factory.nested_progress_bar()
+ try:
+ progress_bar.update(msg="Finding nodes", total=len(merge_sorted_revisions))
+ for (rev_index, (sequence_number,
+ revid,
+ merge_depth,
+ revno_sequence,
+ end_of_merge)) in enumerate(merge_sorted_revisions):
+
+ if rev_index % 25 == 0:
+ progress_bar.update(current=rev_index)
+ if maxnum and rev_index >= maxnum:
+ break
+ revid_index[revid] = rev_index
+
+ parents = graph_parents[revid]
+ linegraph.append([revid,
+ None,
+ [],
+ parents,
+ None,
+ revno_sequence])
+
+ if graph_data:
+ revno_index[revno_sequence] = rev_index
+
+ branch_id = revno_sequence[0:-1]
+
+ branch_line = None
+ if branch_id not in branch_lines:
+ branch_line = []
+ branch_lines[branch_id] = branch_line
+ else:
+ branch_line = branch_lines[branch_id]
+
+ branch_line.append(rev_index)
+ finally:
+ progress_bar.finished()
if graph_data:
branch_ids = branch_lines.keys()
@@ -149,178 +181,194 @@
columns = [list(empty_column)]
- for branch_id in branch_ids:
- branch_line = branch_lines[branch_id]
-
- # Find the col_index for the direct parent branch. This will be the
- # starting point when looking for a free column.
- parent_col_index = 0
- parent_index = None
- if len(branch_id) > 1:
- parent_revno = branch_id[0:-1]
- if parent_revno in revno_index:
- parent_index = revno_index[parent_revno]
- parent_node = linegraph[parent_index][1]
- if parent_node:
- parent_col_index = parent_node[0]
-
-
- col_search_order = _branch_line_col_search_order(columns,
- parent_col_index)
- color = reduce(lambda x, y: x+y, branch_id, 0)
- cur_cont_line = []
-
- line_range = []
- last_rev_index = None
- for rev_index in branch_line:
- if last_rev_index:
- if broken_line_length and \
- rev_index - last_rev_index > broken_line_length:
- line_range.append(last_rev_index+1)
- line_range.append(rev_index-1)
- else:
- line_range.extend(range(last_rev_index+1, rev_index))
-
- line_range.append(rev_index)
- last_rev_index = rev_index
-
- if parent_index:
- if broken_line_length and \
- parent_index - last_rev_index > broken_line_length:
- line_range.append(last_rev_index+1)
- else:
- line_range.extend(range(last_rev_index+1, parent_index))
-
- col_index = _find_free_column(columns,
- empty_column,
- col_search_order,
- line_range)
- node = (col_index, color)
- for rev_index in branch_line:
- linegraph[rev_index][1] = node
- columns[col_index][rev_index] = True
-
- for rev_index in branch_line:
- (sequence_number,
- revid,
- merge_depth,
- revno_sequence,
- end_of_merge) = merge_sorted_revisions[rev_index]
-
- linegraph[rev_index][4] = graph_children[revid]
- col_index = linegraph[rev_index][1][0]
-
- for parent_revid in graph_parents[revid]:
- if parent_revid in revid_index:
-
- parent_index = revid_index[parent_revid]
+ update_root_progress(4)
+ progress_bar = ui.ui_factory.nested_progress_bar()
+ try:
+ progress_bar.update(msg="Organizing edges", total=len(branch_ids))
+ for i, branch_id in enumerate(branch_ids):
+ if i % 25 == 0:
+ progress_bar.update(current=i)
+ branch_line = branch_lines[branch_id]
+
+ # Find the col_index for the direct parent branch. This will be the
+ # starting point when looking for a free column.
+ parent_col_index = 0
+ parent_index = None
+ if len(branch_id) > 1:
+ parent_revno = branch_id[0:-1]
+ if parent_revno in revno_index:
+ parent_index = revno_index[parent_revno]
parent_node = linegraph[parent_index][1]
if parent_node:
parent_col_index = parent_node[0]
+
+
+ col_search_order = _branch_line_col_search_order(columns,
+ parent_col_index)
+ color = reduce(lambda x, y: x+y, branch_id, 0)
+ cur_cont_line = []
+
+ line_range = []
+ last_rev_index = None
+ for rev_index in branch_line:
+ if last_rev_index:
+ if broken_line_length and \
+ rev_index - last_rev_index > broken_line_length:
+ line_range.append(last_rev_index+1)
+ line_range.append(rev_index-1)
else:
- parent_col_index = None
- col_search_order = \
- _line_col_search_order(columns,
- parent_col_index,
- col_index)
-
- # If this line is really long, break it.
- if len(branch_id) > 0 and \
- broken_line_length and \
- parent_index - rev_index > broken_line_length:
- child_line_col_index = \
- _find_free_column(columns,
- empty_column,
- col_search_order,
- (rev_index + 1,))
- _mark_column_as_used(columns,
- child_line_col_index,
- (rev_index + 1,))
-
- # Recall _line_col_search_order to reset it back to
- # the beging.
+ line_range.extend(range(last_rev_index+1, rev_index))
+
+ line_range.append(rev_index)
+ last_rev_index = rev_index
+
+ if parent_index:
+ if broken_line_length and \
+ parent_index - last_rev_index > broken_line_length:
+ line_range.append(last_rev_index+1)
+ else:
+ line_range.extend(range(last_rev_index+1, parent_index))
+
+ col_index = _find_free_column(columns,
+ empty_column,
+ col_search_order,
+ line_range)
+ node = (col_index, color)
+ for rev_index in branch_line:
+ linegraph[rev_index][1] = node
+ columns[col_index][rev_index] = True
+
+ for rev_index in branch_line:
+ (sequence_number,
+ revid,
+ merge_depth,
+ revno_sequence,
+ end_of_merge) = merge_sorted_revisions[rev_index]
+
+ linegraph[rev_index][4] = graph_children[revid]
+ col_index = linegraph[rev_index][1][0]
+
+ for parent_revid in graph_parents[revid]:
+ if parent_revid in revid_index:
+
+ parent_index = revid_index[parent_revid]
+ parent_node = linegraph[parent_index][1]
+ if parent_node:
+ parent_col_index = parent_node[0]
+ else:
+ parent_col_index = None
col_search_order = \
_line_col_search_order(columns,
parent_col_index,
col_index)
- parent_col_line_index = \
- _find_free_column(columns,
- empty_column,
- col_search_order,
- (parent_index - 1,))
- _mark_column_as_used(columns,
- parent_col_line_index,
- (parent_index - 1,))
- lines.append((rev_index,
- parent_index,
- (child_line_col_index,
- parent_col_line_index)))
- else :
- line_col_index = col_index
- if parent_index - rev_index >1:
- line_range = range(rev_index + 1, parent_index)
- line_col_index = \
- _find_free_column(columns,
- empty_column,
- col_search_order,
- line_range)
- _mark_column_as_used(columns,
- line_col_index,
- line_range)
- lines.append((rev_index,
- parent_index,
- (line_col_index,)))
+
+ # If this line is really long, break it.
+ if len(branch_id) > 0 and \
+ broken_line_length and \
+ parent_index - rev_index > broken_line_length:
+ child_line_col_index = \
+ _find_free_column(columns,
+ empty_column,
+ col_search_order,
+ (rev_index + 1,))
+ _mark_column_as_used(columns,
+ child_line_col_index,
+ (rev_index + 1,))
+
+ # Recall _line_col_search_order to reset it back to
+ # the beging.
+ col_search_order = \
+ _line_col_search_order(columns,
+ parent_col_index,
+ col_index)
+ parent_col_line_index = \
+ _find_free_column(columns,
+ empty_column,
+ col_search_order,
+ (parent_index - 1,))
+ _mark_column_as_used(columns,
+ parent_col_line_index,
+ (parent_index - 1,))
+ lines.append((rev_index,
+ parent_index,
+ (child_line_col_index,
+ parent_col_line_index)))
+ else :
+ line_col_index = col_index
+ if parent_index - rev_index >1:
+ line_range = range(rev_index + 1, parent_index)
+ line_col_index = \
+ _find_free_column(columns,
+ empty_column,
+ col_search_order,
+ line_range)
+ _mark_column_as_used(columns,
+ line_col_index,
+ line_range)
+ lines.append((rev_index,
+ parent_index,
+ (line_col_index,)))
+ finally:
+ progress_bar.finished()
- for (child_index, parent_index, line_col_indexes) in lines:
- (child_col_index, child_color) = linegraph[child_index][1]
- (parent_col_index, parent_color) = linegraph[parent_index][1]
-
- if len(line_col_indexes) == 1:
- if parent_index - child_index == 1:
- linegraph[child_index][2].append(
- (child_col_index,
- parent_col_index,
- parent_color))
+ update_root_progress(5)
+ progress_bar = ui.ui_factory.nested_progress_bar()
+ try:
+ progress_bar.update(msg="Pretifying graph", total=len(lines))
+ for i, (child_index, parent_index, line_col_indexes) in enumerate(lines):
+ if i % 25 == 0:
+ progress_bar.update(current=i)
+ (child_col_index, child_color) = linegraph[child_index][1]
+ (parent_col_index, parent_color) = linegraph[parent_index][1]
+
+ if len(line_col_indexes) == 1:
+ if parent_index - child_index == 1:
+ linegraph[child_index][2].append(
+ (child_col_index,
+ parent_col_index,
+ parent_color))
+ else:
+ # line from the child's column to the lines column
+ linegraph[child_index][2].append(
+ (child_col_index,
+ line_col_indexes[0],
+ parent_color))
+ # lines down the line's column
+ for line_part_index in range(child_index+1, parent_index-1):
+ linegraph[line_part_index][2].append(
+ (line_col_indexes[0],
+ line_col_indexes[0],
+ parent_color))
+ # line from the line's column to the parent's column
+ linegraph[parent_index-1][2].append(
+ (line_col_indexes[0],
+ parent_col_index,
+ parent_color))
else:
+ # Broken line
# line from the child's column to the lines column
linegraph[child_index][2].append(
(child_col_index,
line_col_indexes[0],
parent_color))
- # lines down the line's column
- for line_part_index in range(child_index+1, parent_index-1):
- linegraph[line_part_index][2].append(
- (line_col_indexes[0],
- line_col_indexes[0],
- parent_color))
+ # Broken line end
+ linegraph[child_index+1][2].append(
+ (line_col_indexes[0],
+ None,
+ parent_color))
+
+ # Broken line end
+ linegraph[parent_index-2][2].append(
+ (None,
+ line_col_indexes[1],
+ parent_color))
# line from the line's column to the parent's column
linegraph[parent_index-1][2].append(
- (line_col_indexes[0],
+ (line_col_indexes[1],
parent_col_index,
parent_color))
- else:
- # Broken line
- # line from the child's column to the lines column
- linegraph[child_index][2].append(
- (child_col_index,
- line_col_indexes[0],
- parent_color))
- # Broken line end
- linegraph[child_index+1][2].append(
- (line_col_indexes[0],
- None,
- parent_color))
-
- # Broken line end
- linegraph[parent_index-2][2].append(
- (None,
- line_col_indexes[1],
- parent_color))
- # line from the line's column to the parent's column
- linegraph[parent_index-1][2].append(
- (line_col_indexes[1],
- parent_col_index,
- parent_color))
+ finally:
+ progress_bar.finished()
return (linegraph, revid_index, len(columns))
else:
return (linegraph, revid_index, 0)
=== modified file 'branchview/treeview.py'
--- a/branchview/treeview.py 2008-06-29 15:47:30 +0000
+++ b/branchview/treeview.py 2008-06-29 16:11:12 +0000
@@ -13,6 +13,7 @@
import pango
import re
import treemodel
+from bzrlib import ui
from bzrlib.plugins.gtk import _i18n
from linegraph import linegraph, same_branch
@@ -82,9 +83,6 @@
}
__gsignals__ = {
- 'revisions-loaded': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ()),
'revision-selected': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
()),
@@ -108,10 +106,6 @@
"""
gtk.VBox.__init__(self, spacing=0)
- self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
- self.connect('revisions-loaded',
- lambda x: self.loading_msg_box.hide())
-
self.scrolled_window = gtk.ScrolledWindow()
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
@@ -120,7 +114,6 @@
self.pack_start(self.scrolled_window, expand=True, fill=True)
self.scrolled_window.add(self.construct_treeview())
-
self.iter = None
self.branch = branch
@@ -223,7 +216,6 @@
self.emit('tag-added', tag, revid)
def refresh(self):
- self.loading_msg_box.show()
gobject.idle_add(self.populate, self.get_revision())
def update(self):
@@ -277,39 +269,46 @@
should be broken.
"""
- if self.compact:
- broken_line_length = 32
- else:
- broken_line_length = None
-
- show_graph = self.graph_column.get_visible()
-
- self.branch.lock_read()
- (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
- (self.start,) , # Sequence of start revisions
- self.maxnum,
- broken_line_length,
- show_graph,
- self.mainline_only)
-
- self.model = TreeModel(self.branch, linegraphdata)
- self.graph_cell.columns_len = columns_len
- width = self.graph_cell.get_size(self.treeview)[2]
- if width > 500:
- width = 500
- self.graph_column.set_fixed_width(width)
- self.graph_column.set_max_width(width)
- self.index = index
- self.treeview.set_model(self.model)
-
- if not revision or revision == NULL_REVISION:
- self.treeview.set_cursor(0)
- else:
- self.set_revision(revision)
-
- self.emit('revisions-loaded')
-
- return False
+ loading_progress = ui.ui_factory.nested_progress_bar()
+ loading_progress.update(msg="Loading ancestry graph", total=5)
+
+ try:
+ if self.compact:
+ broken_line_length = 32
+ else:
+ broken_line_length = None
+
+ show_graph = self.graph_column.get_visible()
+
+ self.branch.lock_read()
+ (linegraphdata, index, columns_len) = linegraph(self.branch.repository.get_graph(),
+ self.start,
+ self.maxnum,
+ broken_line_length,
+ show_graph,
+ self.mainline_only,
+ loading_progress)
+
+ self.model = TreeModel(self.branch, linegraphdata)
+ self.graph_cell.columns_len = columns_len
+ width = self.graph_cell.get_size(self.treeview)[2]
+ if width > 500:
+ width = 500
+ self.graph_column.set_fixed_width(width)
+ self.graph_column.set_max_width(width)
+ self.index = index
+ self.treeview.set_model(self.model)
+
+ if not revision or revision == NULL_REVISION:
+ self.treeview.set_cursor(0)
+ else:
+ self.set_revision(revision)
+
+ self.emit('revisions-loaded')
+
+ return False
+ finally:
+ loading_progress.finished()
def construct_treeview(self):
self.treeview = gtk.TreeView()
@@ -393,25 +392,6 @@
self.treeview.append_column(self.date_column)
return self.treeview
-
- def construct_loading_msg(self):
- image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
- gtk.ICON_SIZE_BUTTON)
- image_loading.show()
-
- label_loading = gtk.Label(
- _i18n("Please wait, loading ancestral graph..."))
- label_loading.set_alignment(0.0, 0.5)
- label_loading.show()
-
- self.loading_msg_box = gtk.HBox()
- self.loading_msg_box.set_spacing(5)
- self.loading_msg_box.set_border_width(5)
- self.loading_msg_box.pack_start(image_loading, False, False)
- self.loading_msg_box.pack_start(label_loading, True, True)
- self.loading_msg_box.show()
-
- return self.loading_msg_box
def _on_selection_changed(self, treeview):
"""callback for when the treeview changes."""
=== modified file 'ui.py'
--- a/ui.py 2008-06-20 03:36:30 +0000
+++ b/ui.py 2008-06-29 16:11:12 +0000
@@ -45,6 +45,8 @@
super(GtkProgressBar, self).__init__()
self.set_fraction(0.0)
self._stack = stack
+ self.current = None
+ self.total = None
def finished(self):
self._stack.remove(self)
@@ -56,10 +58,14 @@
self.pulse()
def update(self, msg=None, current=None, total=None):
+ if current:
+ self.current = current
+ if total:
+ self.total = total
if msg is not None:
self.set_text(msg)
- if None not in (current, total) and total > 0:
- self.set_fraction(1.0 * current / total)
+ if None not in (self.current, self.total):
+ self.set_fraction(1.0 * self.current / self.total)
while gtk.events_pending():
gtk.main_iteration()
More information about the bazaar-commits
mailing list