hggtk/vis: half-integration into history dialog
authorSteve Borho <steve@borho.org>
Fri, 11 Jan 2008 23:30:39 -0600
changeset 633 c1f4652dccc5
parent 632 9ef3e5ad8ab3
child 634 b99e4c3de5e7
hggtk/vis: half-integration into history dialog The tree model is being filled correctly via the revlog generator The graphing algorithm almost works, on_iter_next() needs more work to match up the edges properly Need to add colors later One or more fields need escaping
hggtk/history.py
hggtk/vis/__init__.py
hggtk/vis/treemodel.py
hggtk/vis/treeview.py
--- a/hggtk/history.py	Fri Jan 11 22:39:39 2008 -0600
+++ b/hggtk/history.py	Fri Jan 11 23:30:39 2008 -0600
@@ -24,6 +24,8 @@
 from gdialog import *
 from hgcmd import CmdDialog
 
+from vis.treeview import TreeView
+
 
 class GLog(GDialog):
     """GTK+ based dialog for displaying repository logs
@@ -153,6 +155,9 @@
         if self.refreshing:
             return False
 
+        if self.grapher:
+            return True
+
         # Retrieve repo revision info
         self.repo.invalidate()
         repo_parents = [x.rev() for x in self.repo.workingctx().parents()]
@@ -406,89 +411,97 @@
         
     def get_body(self):
         self._menu = self.tree_context_menu()
-        
-        self.model = gtk.ListStore(str, str, long, str, str, str, str, long, object)
-        self.model.set_default_sort_func(self._sort_by_rev)
+        self.grapher = True
+        if self.grapher:
+            scroller = TreeView(self.repo)
+            self.tree = scroller.treeview
+            self.model = scroller.model
+        else:
+            self.model = gtk.ListStore(str, str, long, str, str, str, str, 
+                    long, object)
+            self.model.set_default_sort_func(self._sort_by_rev)
 
-        self.tree = gtk.TreeView(self.model)
+            self.tree = gtk.TreeView(self.model)
+            self.tree.set_reorderable(False)
+            self.tree.set_enable_search(True)
+            self.tree.set_search_equal_func(self._search_in_tree,None)
+            self.tree.get_selection().set_mode(gtk.SELECTION_SINGLE)
+            self.tree.get_selection().connect('changed',
+                    self._tree_selection_changed)
+            self.tree.set_rubber_banding(False)
+            self.tree.modify_font(pango.FontDescription(self.fontlist))
+            self.tree.set_rules_hint(True) 
+            
+            parent_cell = gtk.CellRendererPixbuf()
+            head_cell = gtk.CellRendererPixbuf()
+            tags_cell = gtk.CellRendererText()
+            changeset_cell = gtk.CellRendererText()
+            user_cell = gtk.CellRendererText()
+            summary_cell = gtk.CellRendererText()
+            date_cell = gtk.CellRendererText()
+            
+            col = 1
+            
+            col_status = gtk.TreeViewColumn('status')
+            col_status.pack_start(parent_cell, False)
+            col_status.pack_start(head_cell, False)
+            col_status.set_cell_data_func(parent_cell, self.make_parent)
+            col_status.set_cell_data_func(head_cell, self.make_head)
+            
+            col += 1
+            col_rev = gtk.TreeViewColumn('rev', changeset_cell)
+            col_rev.add_attribute(changeset_cell, 'text', col)
+            col_rev.set_cell_data_func(changeset_cell, self._text_color)
+            col_rev.set_sort_column_id(col)
+            col_rev.set_resizable(False)
+            
+            col += 1
+            col_tag = gtk.TreeViewColumn('tag', tags_cell)
+            col_tag.add_attribute(tags_cell, 'text', col)
+            col_tag.set_cell_data_func(tags_cell, self._text_color)
+            col_tag.set_sort_column_id(col)
+            col_tag.set_resizable(True)
+            
+            col += 1
+            user_cell.set_property('ellipsize', pango.ELLIPSIZE_END)
+            user_cell.set_property('width_chars', 20)
+            col_user = gtk.TreeViewColumn('user', user_cell)
+            col_user.add_attribute(user_cell, 'text', col)
+            col_user.set_cell_data_func(user_cell, self._text_color)
+            col_user.set_sort_column_id(col)
+            col_user.set_resizable(True)
+            
+            col += 1
+            summary_cell.set_property('ellipsize', pango.ELLIPSIZE_END)
+            summary_cell.set_property('width_chars', 65)
+            col_sum = gtk.TreeViewColumn('summary', summary_cell)
+            col_sum.add_attribute(summary_cell, 'text', col)
+            col_sum.set_cell_data_func(summary_cell, self._text_color)
+            col_sum.set_sort_column_id(col)
+            col_sum.set_resizable(True)
+
+            col += 1
+            col_date = gtk.TreeViewColumn('date', date_cell)
+            col_date.add_attribute(date_cell, 'text', col)
+            col_date.set_cell_data_func(date_cell, self._text_color)
+            col_date.set_sort_column_id(col)
+            col_date.set_resizable(True)
+
+            self.tree.append_column(col_status)
+            self.tree.append_column(col_rev)
+            self.tree.append_column(col_tag)
+            self.tree.append_column(col_user)
+            self.tree.append_column(col_sum)
+            self.tree.append_column(col_date)
+            self.tree.set_headers_clickable(True)
+            
+            scroller = gtk.ScrolledWindow()
+            scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+            scroller.add(self.tree)
+
         self.tree.connect('button-release-event', self._tree_button_release)
         self.tree.connect('popup-menu', self._tree_popup_menu)
         self.tree.connect('row-activated', self._tree_row_act)
-        self.tree.set_reorderable(False)
-        self.tree.set_enable_search(True)
-        self.tree.set_search_equal_func(self._search_in_tree,None)
-        self.tree.get_selection().set_mode(gtk.SELECTION_SINGLE)
-        self.tree.get_selection().connect('changed', self._tree_selection_changed)
-        self.tree.set_rubber_banding(False)
-        self.tree.modify_font(pango.FontDescription(self.fontlist))
-        self.tree.set_rules_hint(True) 
-        
-        parent_cell = gtk.CellRendererPixbuf()
-        head_cell = gtk.CellRendererPixbuf()
-        tags_cell = gtk.CellRendererText()
-        changeset_cell = gtk.CellRendererText()
-        user_cell = gtk.CellRendererText()
-        summary_cell = gtk.CellRendererText()
-        date_cell = gtk.CellRendererText()
-        
-        col = 1
-        
-        col_status = gtk.TreeViewColumn('status')
-        col_status.pack_start(parent_cell, False)
-        col_status.pack_start(head_cell, False)
-        col_status.set_cell_data_func(parent_cell, self.make_parent)
-        col_status.set_cell_data_func(head_cell, self.make_head)
-        
-        col += 1
-        col_rev = gtk.TreeViewColumn('rev', changeset_cell)
-        col_rev.add_attribute(changeset_cell, 'text', col)
-        col_rev.set_cell_data_func(changeset_cell, self._text_color)
-        col_rev.set_sort_column_id(col)
-        col_rev.set_resizable(False)
-        
-        col += 1
-        col_tag = gtk.TreeViewColumn('tag', tags_cell)
-        col_tag.add_attribute(tags_cell, 'text', col)
-        col_tag.set_cell_data_func(tags_cell, self._text_color)
-        col_tag.set_sort_column_id(col)
-        col_tag.set_resizable(True)
-        
-        col += 1
-        user_cell.set_property('ellipsize', pango.ELLIPSIZE_END)
-        user_cell.set_property('width_chars', 20)
-        col_user = gtk.TreeViewColumn('user', user_cell)
-        col_user.add_attribute(user_cell, 'text', col)
-        col_user.set_cell_data_func(user_cell, self._text_color)
-        col_user.set_sort_column_id(col)
-        col_user.set_resizable(True)
-        
-        col += 1
-        summary_cell.set_property('ellipsize', pango.ELLIPSIZE_END)
-        summary_cell.set_property('width_chars', 65)
-        col_sum = gtk.TreeViewColumn('summary', summary_cell)
-        col_sum.add_attribute(summary_cell, 'text', col)
-        col_sum.set_cell_data_func(summary_cell, self._text_color)
-        col_sum.set_sort_column_id(col)
-        col_sum.set_resizable(True)
-
-        col += 1
-        col_date = gtk.TreeViewColumn('date', date_cell)
-        col_date.add_attribute(date_cell, 'text', col)
-        col_date.set_cell_data_func(date_cell, self._text_color)
-        col_date.set_sort_column_id(col)
-        col_date.set_resizable(True)
-
-        self.tree.append_column(col_status)
-        self.tree.append_column(col_rev)
-        self.tree.append_column(col_tag)
-        self.tree.append_column(col_user)
-        self.tree.append_column(col_sum)
-        self.tree.append_column(col_date)
-        self.tree.set_headers_clickable(True)
-        
-        scroller = gtk.ScrolledWindow()
-        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
-        scroller.add(self.tree)
         
         tree_frame = gtk.Frame()
         tree_frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hggtk/vis/__init__.py	Fri Jan 11 23:30:39 2008 -0600
@@ -0,0 +1,1 @@
+# placeholder
--- a/hggtk/vis/treemodel.py	Fri Jan 11 22:39:39 2008 -0600
+++ b/hggtk/vis/treemodel.py	Fri Jan 11 23:30:39 2008 -0600
@@ -130,27 +130,26 @@
             revision = self.revisions[revid]
 
         if column == REVISION: return revision
-        if column == MESSAGE: return revision[2]
+        if column == MESSAGE: return revision[2].split('\n')[0]
         if column == COMMITER: return re.sub('<.*@.*>', '',
                                              revision[0]).strip(' ')
-        if column == TIMESTAMP: # TODO: not sure if this is correct
-            return strftime("%Y-%m-%d %H:%M", localtime(revision[1]))
+        if column == TIMESTAMP:
+            return strftime("%Y-%m-%d %H:%M", localtime(revision[1][0]))
 
     def on_iter_next(self, rowref):
-        if rowref < len(self.line_graph_data) - 1:
-            return rowref+1
         # Dynamically generate graph rows on demand
-        while rowref >= len(self.line_graph_data):
-            # TODO: not sure about this either
+        while rowref >= len(self.line_graph_data)-1:
             try:
                 (rev, node, node_index, edges,
-                    n_columns, parents, children) = self.grapher()
+                    n_columns, parents, children) = self.grapher.next()
             except StopIteration:
                 break
             # TODO: add color later on
-            lines = [(r, 0) for (r, n) in edges]
+            lines = [(s, e, 0) for (s, e) in edges]
             self.line_graph_data.append( (rev, (node_index, 0),
                 lines, parents, children) )
+        if rowref < len(self.line_graph_data) - 1:
+            return rowref+1
         return None
 
     def on_iter_children(self, parent):
--- a/hggtk/vis/treeview.py	Fri Jan 11 22:39:39 2008 -0600
+++ b/hggtk/vis/treeview.py	Fri Jan 11 23:30:39 2008 -0600
@@ -10,8 +10,8 @@
 import gtk
 import gobject
 import pango
-from hggtk.vis import treemodel
-from hggtk.vis import graphcell
+import treemodel
+import graphcell
 
 class TreeView(gtk.ScrolledWindow):
 
@@ -47,13 +47,6 @@
                                  'Show date column',
                                  False,
                                  gobject.PARAM_READWRITE),
-
-        'compact': (gobject.TYPE_BOOLEAN,
-                    'Compact view',
-                    'Break ancestry lines to save space',
-                    True,
-                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE)
-
     }
 
     __gsignals__ = {
@@ -65,7 +58,7 @@
                               ())
     }
 
-    def __init__(self, repo, start, maxnum, compact=True):
+    def __init__(self, repo):
         """Create a new TreeView.
 
         :param repo:  Repository object to show.
@@ -80,20 +73,24 @@
 
         self.construct_treeview()
 
-        self.iter   = None
+        self.iter = None
         self.repo = repo
+        self.model = self.create_model()
+        self.treeview.set_model(self.model)
+        gobject.idle_add(self.populate)
 
-        self.start = start
-        self.maxnum = maxnum
-        self.compact = compact
-
-        gobject.idle_add(self.populate)
+    def create_model(self):
+        opts = { 'rev' : [] }
+        limit = self.repo.ui.config('tortoisehg', 'graphlimit', None)
+        (start_rev, stop_rev) = (self.repo.changelog.count() - 1, 0)
+        if limit:
+            stop_rev = max(stop_rev, start_rev - limit + 1)
+        grapher = treemodel.revision_grapher(self.repo, start_rev, stop_rev)
+        return treemodel.TreeModel(self.repo, grapher)
 
     def do_get_property(self, property):
         if property.name == 'date-column-visible':
             return self.date_column.get_visible()
-        elif property.name == 'compact':
-            return self.compact
         elif property.name == 'repo':
             return self.repo
         elif property.name == 'revision':
@@ -108,8 +105,6 @@
     def do_set_property(self, property, value):
         if property.name == 'date-column-visible':
             self.date_column.set_visible(value)
-        elif property.name == 'compact':
-            self.compact = value
         elif property.name == 'repo':
             self.repo = value
         elif property.name == 'revision':
@@ -147,6 +142,8 @@
         return self.get_property('parents')
         
     def refresh(self):
+        self.model = self.create_model()
+        self.treeview.set_model(self.model)
         gobject.idle_add(self.populate, self.get_revision())
 
     def update(self):
@@ -185,21 +182,13 @@
     def populate(self, revision=None):
         """Fill the treeview with contents.
         """
-        opts = { 'rev' : [] }
-        limit = self.repo.ui.config('tortoisehg', 'graphlimit')
-        (start_rev, stop_rev) = (self.repo.changelog.count() - 1, 0)
-        stop_rev = max(stop_rev, start_rev - limit + 1)
-        grapher = treemodel.revision_grapher(self.repo, start_rev, stop_rev)
-
-        self.model = treemodel.TreeModel(self.repo, grapher)
         self.graph_cell.columns_len = 4 # TODO not known up-front
         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)
+        self.index = [] # TODO
 
         if revision is None:
             self.treeview.set_cursor(0)
@@ -224,14 +213,6 @@
         self.treeview.connect("cursor-changed",
                 self._on_selection_changed)
 
-        # TODO: Parent should connect menu events
-        #self.treeview.connect("row-activated", 
-        #        self._on_revision_activated)
-        #self.treeview.connect("button-release-event", 
-        #        self._on_revision_selected)
-        #self.treeview.connect('popup-menu',
-        #        self._popup_menu)
-
         self.treeview.set_property('fixed-height-mode', True)
 
         self.add(self.treeview)
@@ -276,7 +257,7 @@
         cell.set_property("width-chars", 20)
         cell.set_property("ellipsize", pango.ELLIPSIZE_END)
         self.date_column = gtk.TreeViewColumn("Date")
-        self.date_column.set_visible(False)
+        self.date_column.set_visible(True)
         self.date_column.set_resizable(True)
         self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
         self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])