Rev 519: merge new progress bars in bzr viz. in file:///data/jelmer/bzr-gtk/trunk/

Jelmer Vernooij jelmer at samba.org
Sun Jun 29 23:39:10 BST 2008


At file:///data/jelmer/bzr-gtk/trunk/

------------------------------------------------------------
revno: 519
revision-id: jelmer at samba.org-20080629223909-puqp6u30f74zskhd
parent: jelmer at samba.org-20080629223421-1tjpwvl02csd0m0h
parent: jelmer at samba.org-20080629181229-1l2m4cf7vvbyh8qg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2008-06-30 00:39:09 +0200
message:
  merge new progress bars in bzr viz.
added:
  tests/test_linegraph.py        test_linegraph.py-20080629155407-bytip7n4r8dhg591-1
modified:
  NEWS                           news-20070325173539-3va57o99cz3o57xe-1
  branchview/linegraph.py        graph.py-20051016214152-ebf565808c860cf7
  branchview/treeview.py         treeview.py-20071020204704-vk1erblrjhbcgw94-1
  tests/__init__.py              __init__.py-20070201155018-mi2dl3spgj7fqdum-1
  ui.py                          ui.py-20060716163355-owuqwa9uhnlfsojs-1
    ------------------------------------------------------------
    revno: 511.5.6
    revision-id: jelmer at samba.org-20080629181229-1l2m4cf7vvbyh8qg
    parent: jelmer at samba.org-20080629162424-48a6rrjmmpejfcyr
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sun 2008-06-29 20:12:29 +0200
    message:
      Simplify progress bar code, use embedded progress bar inside viz window.
    modified:
      branchview/linegraph.py        graph.py-20051016214152-ebf565808c860cf7
      branchview/treeview.py         treeview.py-20071020204704-vk1erblrjhbcgw94-1
      ui.py                          ui.py-20060716163355-owuqwa9uhnlfsojs-1
    ------------------------------------------------------------
    revno: 511.5.5
    revision-id: jelmer at samba.org-20080629162424-48a6rrjmmpejfcyr
    parent: jelmer at samba.org-20080629162015-amhe7xj4cdmup4id
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sun 2008-06-29 18:24:24 +0200
    message:
      Stop emitting no longer used revisions-loaded message.
    modified:
      branchview/treeview.py         treeview.py-20071020204704-vk1erblrjhbcgw94-1
    ------------------------------------------------------------
    revno: 511.5.4
    revision-id: jelmer at samba.org-20080629162015-amhe7xj4cdmup4id
    parent: jelmer at samba.org-20080629161112-3j4zp0r0e7cv6cds
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sun 2008-06-29 18:20:15 +0200
    message:
      Rename GtkProgressBarStack to GtkWindowProgressBarStack
    modified:
      ui.py                          ui.py-20060716163355-owuqwa9uhnlfsojs-1
    ------------------------------------------------------------
    revno: 511.5.3
    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
    ------------------------------------------------------------
    revno: 511.5.2
    revision-id: jelmer at samba.org-20080629155440-iuzfrlfifnplp9jq
    parent: jelmer at samba.org-20080629154730-xfsotoxwkiytf0ph
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sun 2008-06-29 17:54:40 +0200
    message:
      Add simple test for linegraph.
    added:
      tests/test_linegraph.py        test_linegraph.py-20080629155407-bytip7n4r8dhg591-1
    modified:
      branchview/linegraph.py        graph.py-20051016214152-ebf565808c860cf7
      tests/__init__.py              __init__.py-20070201155018-mi2dl3spgj7fqdum-1
    ------------------------------------------------------------
    revno: 511.5.1
    revision-id: jelmer at samba.org-20080629154730-xfsotoxwkiytf0ph
    parent: jelmer at samba.org-20080628154539-l5lkvs5qwuf2zx1m
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sun 2008-06-29 17:47:30 +0200
    message:
      Pass graph object rather than full repository to linegraph.
    modified:
      branchview/linegraph.py        graph.py-20051016214152-ebf565808c860cf7
      branchview/treeview.py         treeview.py-20071020204704-vk1erblrjhbcgw94-1
=== modified file 'NEWS'
--- a/NEWS	2008-06-29 22:34:21 +0000
+++ b/NEWS	2008-06-29 22:39:09 +0000
@@ -4,6 +4,8 @@
 
   * Added Refresh menu option with F5 keyboard shortcut (Russ Brown)
 
+  * Show progress bars in bzr viz window (Chad Miller, Jelmer Vernooij)
+
  BUG FIXES
 
   * Replace _() calls by _i18n() calls. (Vincent Ladeuil, #187283)
@@ -33,6 +35,7 @@
     bzrlib.plugins.gtk. This addresses the occasional collisions with '_' used
     as an anonymous variable. (Vincent Ladeuil)
 
+  * Add test for linegraph code. (Jelmer Vernooij)
 
 0.94.0    2008-05-04
 

=== modified file 'branchview/linegraph.py'
--- a/branchview/linegraph.py	2008-05-04 18:16:01 +0000
+++ b/branchview/linegraph.py	2008-06-29 18:12:29 +0000
@@ -11,9 +11,10 @@
 
 from bzrlib.revision import NULL_REVISION
 from bzrlib.tsort import merge_sort
+from bzrlib import ui
 
-def linegraph(repository, start_revs, maxnum, broken_line_length = None,
-              graph_data = True, mainline_only = False):
+def linegraph(graph, start_revs, maxnum=None, broken_line_length=None,
+              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,26 +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.
     """
-    
-    graph = repository.get_graph()
+    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_cnt=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_cnt=len(ghosts))
+        for i, ghost in enumerate(ghosts):
+            if i % 25 == 0:
+                progress_bar.update(None, current_cnt=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:
@@ -93,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_cnt=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(None, current_cnt=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()
@@ -150,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_cnt=len(branch_ids))
+            for i, branch_id in enumerate(branch_ids):
+                if i % 25 == 0:
+                    progress_bar.update(None, current_cnt=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_cnt=len(lines))
+            for i, (child_index, parent_index, line_col_indexes) in enumerate(lines):
+                if i % 25 == 0:
+                    progress_bar.update(None, current_cnt=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-28 15:45:39 +0000
+++ b/branchview/treeview.py	2008-06-29 18:12:29 +0000
@@ -13,13 +13,16 @@
 import pango
 import re
 import treemodel
+from bzrlib import ui
 
 from bzrlib.plugins.gtk import _i18n
+from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
 from linegraph import linegraph, same_branch
 from graphcell import CellRendererGraph
 from treemodel import TreeModel
 from bzrlib.revision import NULL_REVISION
 
+
 class TreeView(gtk.VBox):
 
     __gproperties__ = {
@@ -82,9 +85,6 @@
     }
 
     __gsignals__ = {
-        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
-                             gobject.TYPE_NONE,
-                             ()),
         'revision-selected': (gobject.SIGNAL_RUN_FIRST,
                               gobject.TYPE_NONE,
                               ()),
@@ -108,9 +108,9 @@
         """
         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())
+        loading_msg_widget = ProgressPanel()
+        ui.ui_factory.set_nested_progress_bar_widget(loading_msg_widget.get_progress_bar)
+        self.pack_start(loading_msg_widget, expand=False, fill=True)
 
         self.scrolled_window = gtk.ScrolledWindow()
         self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
@@ -120,7 +120,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 +222,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 +275,44 @@
                        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,
-                                                        (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
+        self.progress_bar = ui.ui_factory.nested_progress_bar()
+        self.progress_bar.update(msg="Loading ancestry graph", total_cnt=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,
+                                                            self.progress_bar)
+
+            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)
+
+            return False
+        finally:
+            self.progress_bar.finished()
 
     def construct_treeview(self):
         self.treeview = gtk.TreeView()
@@ -394,25 +397,6 @@
         
         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."""
         (path, focus) = treeview.get_cursor()

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-10-30 21:15:13 +0000
+++ b/tests/__init__.py	2008-06-29 15:54:40 +0000
@@ -27,6 +27,7 @@
     testmod_names = [
         'test_commit',
         'test_diff',
+        'test_linegraph',
         'test_preferences',
         'test_history',
         ]

=== added file 'tests/test_linegraph.py'
--- a/tests/test_linegraph.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_linegraph.py	2008-06-29 15:54:40 +0000
@@ -0,0 +1,45 @@
+# Copyright (C) 2008 Jelmer Vernooij <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Test the linegraph functionality."""
+
+import os
+
+import gtk
+
+from bzrlib import (
+	graph,
+    tests,
+    )
+from bzrlib.util import bencode
+
+from bzrlib.plugins.gtk.branchview.linegraph import linegraph
+
+
+class TestLinegraph(tests.TestCase):
+	def get_graph(self, dict):
+		return graph.Graph(graph.DictParentsProvider(dict))
+
+	def test_simple(self):
+		lg = linegraph(self.get_graph({"A": ("B", "C"), "B": ()}), ["A"])
+		self.assertEquals(lg,  
+            ([
+               ['A', (0, 0), [(0, 0, 0)], ['B'], [], (2,)],
+               ['B', (0, 0), [], (), ['A'], (1,)]
+             ],
+             {'A': 0, 'B': 1},
+             1))
+

=== modified file 'ui.py'
--- a/ui.py	2008-06-20 03:36:30 +0000
+++ b/ui.py	2008-06-29 18:12:29 +0000
@@ -22,7 +22,7 @@
 import gtk
 import sys
 
-import bzrlib.progress
+from bzrlib import progress
 from bzrlib.ui import UIFactory
 
 
@@ -40,54 +40,94 @@
                          gtk.RESPONSE_NO)
 
 
-class GtkProgressBar(gtk.ProgressBar):
-    def __init__(self, stack):
-        super(GtkProgressBar, self).__init__()
+class GtkProgressBar(gtk.ProgressBar,progress._BaseProgressBar):
+    def __init__(self, _stack=None):
+        gtk.ProgressBar.__init__(self)
         self.set_fraction(0.0)
-        self._stack = stack
-
-    def finished(self):
-        self._stack.remove(self)
+        progress._BaseProgressBar.__init__(self, _stack=_stack)
+        self.current = None
+        self.total = None
 
     def clear(self):
-        pass
+        self.hide()
 
     def tick(self):
         self.pulse()
 
-    def update(self, msg=None, current=None, total=None):
+    def child_update(self, message, current, total):
+        pass
+
+    def update(self, msg=None, current_cnt=None, total_cnt=None):
+        if current_cnt:
+            self.current = current_cnt
+        if total_cnt:
+            self.total = total_cnt
         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.fraction = float(self.current) / self.total
+            self.set_fraction(self.fraction)
         while gtk.events_pending():
             gtk.main_iteration()
 
 
-class GtkProgressBarStack(gtk.Window):
+class ProgressBarWindow(gtk.Window):
     def __init__(self):
-        super(GtkProgressBarStack, self).__init__(type=gtk.WINDOW_TOPLEVEL)
+        super(ProgressBarWindow, self).__init__(type=gtk.WINDOW_TOPLEVEL)
         self.set_border_width(0)
         self.set_title("Progress")
         self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
-        self.vbox = gtk.VBox()
-        self.add(self.vbox)
+        self.pb = GtkProgressBar(self)
+        self.add(self.pb)
+        self.resize(250, 15)
         self.set_resizable(False)
-
-    def _adapt_size(self):
-        self.resize(250, 15 * len(self.vbox.get_children()))
-
-    def get_nested(self):
-        nested = GtkProgressBar(self)
-        self.vbox.pack_start(nested)
-        self._adapt_size()
-        self.show_all()
-        return nested
-
-    def remove(self, pb):
-        self.vbox.remove(pb)
-        if len(self.vbox.get_children()) == 0: # If there is nothing to show, don't leave a ghost window here
-             self.destroy()
+        self.show_all()
+
+    def clear(self):
+        self.pb.clear()
+        self.destroy()
+
+
+class ProgressPanel(gtk.HBox):
+    def __init__(self):
+        super(ProgressPanel, self).__init__()
+        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
+                                                 gtk.ICON_SIZE_BUTTON)
+        image_loading.show()
+        
+        self.pb = GtkProgressBar(self)
+        self.set_spacing(5)
+        self.set_border_width(5)        
+        self.pack_start(image_loading, False, False)
+        self.pack_start(self.pb, True, True)
+
+    def return_pb(self, pb):
+        self._stack.return_pb(self)
+
+    def get_progress_bar(self, to_file=None, show_pct=None, show_spinner=None, show_eta=None, 
+                         show_bar=None, show_count=None, to_messages_file=None, 
+                         _stack=None):
+        self._stack = _stack
+        self.show_all()
+        return self
+    
+    def update(self, *args, **kwargs):
+        self.pb.update(*args, **kwargs)
+
+    def finished(self):
+        self.pb.finished()
+        self.hide_all()
+
+    def clear(self):
+        self.pb.clear()
+        self.hide_all()
+
+    def child_progress(self, *args, **kwargs):
+        return self.pb.child_progress(*args, **kwargs)
+
+    def child_update(self, *args, **kwargs):
+        return self.pb.child_update(*args, **kwargs)
+
 
 
 class PasswordDialog(gtk.Dialog):
@@ -122,7 +162,7 @@
 
         """
         super(GtkUIFactory, self).__init__()
-        self._progress_bar_stack = None
+        self.set_nested_progress_bar_widget(ProgressBarWindow)
 
     def get_boolean(self, prompt):
         """GtkDialog with yes/no answers"""
@@ -150,11 +190,12 @@
         else:
             return None
 
+    def set_nested_progress_bar_widget(self, widget):
+        self._progress_bar_stack = progress.ProgressBarStack(klass=widget)
+
     def nested_progress_bar(self):
         """Return a nested progress bar.
         """
-        if self._progress_bar_stack is None:
-            self._progress_bar_stack = GtkProgressBarStack()
         return self._progress_bar_stack.get_nested()
 
     def set_progress_bar_vbox(self, vbox):




More information about the bazaar-commits mailing list