From 3d23affc8a37298531ebde32df154b798eed6e17 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Fri, 10 May 2013 15:59:03 +0000 Subject: [PATCH] 6665: New errors when using pygobject 3.8: Cannot get n_columns on flatbasemodel svn: r22244 --- .../gui/views/treemodels/citationlistmodel.py | 2 +- .../gui/views/treemodels/citationtreemodel.py | 2 +- gramps/gui/views/treemodels/eventmodel.py | 2 +- gramps/gui/views/treemodels/familymodel.py | 2 +- gramps/gui/views/treemodels/flatbasemodel.py | 30 ++++++++++++++----- gramps/gui/views/treemodels/mediamodel.py | 2 +- gramps/gui/views/treemodels/notemodel.py | 2 +- gramps/gui/views/treemodels/peoplemodel.py | 2 +- gramps/gui/views/treemodels/placemodel.py | 2 +- gramps/gui/views/treemodels/repomodel.py | 2 +- gramps/gui/views/treemodels/sourcemodel.py | 2 +- gramps/gui/views/treemodels/treebasemodel.py | 8 +++-- 12 files changed, 38 insertions(+), 20 deletions(-) diff --git a/gramps/gui/views/treemodels/citationlistmodel.py b/gramps/gui/views/treemodels/citationlistmodel.py index f02359308..95b55d484 100644 --- a/gramps/gui/views/treemodels/citationlistmodel.py +++ b/gramps/gui/views/treemodels/citationlistmodel.py @@ -105,5 +105,5 @@ class CitationListModel(CitationBaseModel, FlatBaseModel): self.smap = None FlatBaseModel.destroy(self) - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps/gui/views/treemodels/citationtreemodel.py b/gramps/gui/views/treemodels/citationtreemodel.py index 807b70a83..d33de2b54 100644 --- a/gramps/gui/views/treemodels/citationtreemodel.py +++ b/gramps/gui/views/treemodels/citationtreemodel.py @@ -177,7 +177,7 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel): if self._get_node(data[5]): self.add_node(data[5], handle, sort_key, handle, secondary=True) - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_header(self, node): diff --git a/gramps/gui/views/treemodels/eventmodel.py b/gramps/gui/views/treemodels/eventmodel.py index 2dd057b4a..a97fa0b75 100644 --- a/gramps/gui/views/treemodels/eventmodel.py +++ b/gramps/gui/views/treemodels/eventmodel.py @@ -110,7 +110,7 @@ class EventModel(FlatBaseModel): self.smap = None FlatBaseModel.destroy(self) - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_description(self,data): diff --git a/gramps/gui/views/treemodels/familymodel.py b/gramps/gui/views/treemodels/familymodel.py index dcfa42d59..cd20bacc7 100644 --- a/gramps/gui/views/treemodels/familymodel.py +++ b/gramps/gui/views/treemodels/familymodel.py @@ -104,7 +104,7 @@ class FamilyModel(FlatBaseModel): """ return 8 - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_father(self, data): diff --git a/gramps/gui/views/treemodels/flatbasemodel.py b/gramps/gui/views/treemodels/flatbasemodel.py index 8551426d8..b692674ba 100644 --- a/gramps/gui/views/treemodels/flatbasemodel.py +++ b/gramps/gui/views/treemodels/flatbasemodel.py @@ -277,6 +277,8 @@ class FlatNodeMap(object): iter = Gtk.TreeIter() iter.stamp = self.stamp ##GTK3: user data may only be an integer, we store the index + ##PROBLEM: pygobject 3.8 seems to store 0 as None, we need to correct + ## when using user_data for that! iter.user_data = self._hndl2index[handle] return iter @@ -327,8 +329,8 @@ class FlatNodeMap(object): """ index = iter.user_data if index is None: - #Nothing on this level - return False + #problem in pygobject 3.8, passing 0 stores None + index = 0 if self._reverse : index -= 1 @@ -452,7 +454,7 @@ class FlatNodeMap(object): # FlatBaseModel # #------------------------------------------------------------------------- -class FlatBaseModel(GObject.Object, Gtk.TreeModel): +class FlatBaseModel(GObject.GObject, Gtk.TreeModel): """ The base class for all flat treeview models. It keeps a FlatNodeMap, and obtains data from database as needed @@ -464,7 +466,7 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): search=None, skip=set(), sort_map=None): cput = time.clock() - GObject.GObject.__init__(self) + super(FlatBaseModel, self).__init__() #inheriting classes must set self.map to obtain the data self.prev_handle = None self.prev_data = None @@ -713,7 +715,11 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): """ Get the gramps handle for an iter. """ - index = self.node_map.real_index(iter.user_data) + ud = iter.user_data + if ud is None: + #problem in pygobject 3.8, passing 0 stores None + ud = 0 + index = self.node_map.real_index(ud) return self.node_map.get_handle(index) # The following implement the public interface of Gtk.TreeModel @@ -727,9 +733,13 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): return Gtk.TreeModelFlags.LIST_ONLY #| Gtk.TreeModelFlags.ITERS_PERSIST def do_get_n_columns(self): + """Internal method. Don't inherit""" + return self.on_get_n_columns() + + def on_get_n_columns(self): """ Return the number of columns. Must be implemented in the child objects - See Gtk.TreeModel + See Gtk.TreeModel. Inherit as needed """ #print 'do_get_n_col' raise NotImplementedError @@ -785,8 +795,12 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): See Gtk.TreeModel. col is the model column that is needed, not the visible column! """ - #print 'do_get_val', iter, iter.user_data, col - handle = self.node_map._index2hndl[iter.user_data][1] + #print ('do_get_val', iter, iter.user_data, col) + ud = iter.user_data + if ud is None: + #problem in pygobject 3.8, passing 0 stores None + ud = 0 + handle = self.node_map._index2hndl[ud][1] val = self._get_value(handle, col) #print 'val is', val, type(val) diff --git a/gramps/gui/views/treemodels/mediamodel.py b/gramps/gui/views/treemodels/mediamodel.py index dd203b300..1d4e43314 100644 --- a/gramps/gui/views/treemodels/mediamodel.py +++ b/gramps/gui/views/treemodels/mediamodel.py @@ -103,7 +103,7 @@ class MediaModel(FlatBaseModel): """ return 8 - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_description(self, data): diff --git a/gramps/gui/views/treemodels/notemodel.py b/gramps/gui/views/treemodels/notemodel.py index 0188beb29..ec46b23b5 100644 --- a/gramps/gui/views/treemodels/notemodel.py +++ b/gramps/gui/views/treemodels/notemodel.py @@ -97,7 +97,7 @@ class NoteModel(FlatBaseModel): """ return 6 - def do_get_n_columns(self): + def on_get_n_columns(self): """Return the column number of the Note tab.""" return len(self.fmap) + 1 diff --git a/gramps/gui/views/treemodels/peoplemodel.py b/gramps/gui/views/treemodels/peoplemodel.py index d14bf0c5e..d0c08e478 100644 --- a/gramps/gui/views/treemodels/peoplemodel.py +++ b/gramps/gui/views/treemodels/peoplemodel.py @@ -185,7 +185,7 @@ class PeopleBaseModel(object): self.lru_bdate.clear() self.lru_ddate.clear() - def do_get_n_columns(self): + def on_get_n_columns(self): """ Return the number of columns in the model """ return len(self.fmap)+1 diff --git a/gramps/gui/views/treemodels/placemodel.py b/gramps/gui/views/treemodels/placemodel.py index aa4a2b363..4bd23e166 100644 --- a/gramps/gui/views/treemodels/placemodel.py +++ b/gramps/gui/views/treemodels/placemodel.py @@ -125,7 +125,7 @@ class PlaceBaseModel(object): self.fmap = None self.smap = None - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_place_name(self, data): diff --git a/gramps/gui/views/treemodels/repomodel.py b/gramps/gui/views/treemodels/repomodel.py index 142cac4ea..69c212c59 100644 --- a/gramps/gui/views/treemodels/repomodel.py +++ b/gramps/gui/views/treemodels/repomodel.py @@ -105,7 +105,7 @@ class RepositoryModel(FlatBaseModel): self.smap = None FlatBaseModel.destroy(self) - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_id(self,data): diff --git a/gramps/gui/views/treemodels/sourcemodel.py b/gramps/gui/views/treemodels/sourcemodel.py index 42f5fcc8a..da1dbf62e 100644 --- a/gramps/gui/views/treemodels/sourcemodel.py +++ b/gramps/gui/views/treemodels/sourcemodel.py @@ -87,7 +87,7 @@ class SourceModel(FlatBaseModel): self.smap = None FlatBaseModel.destroy(self) - def do_get_n_columns(self): + def on_get_n_columns(self): return len(self.fmap)+1 def column_title(self,data): diff --git a/gramps/gui/views/treemodels/treebasemodel.py b/gramps/gui/views/treemodels/treebasemodel.py index caf946f78..39745c335 100644 --- a/gramps/gui/views/treemodels/treebasemodel.py +++ b/gramps/gui/views/treemodels/treebasemodel.py @@ -235,7 +235,7 @@ class NodeMap(object): # TreeBaseModel # #------------------------------------------------------------------------- -class TreeBaseModel(GObject.Object, Gtk.TreeModel): +class TreeBaseModel(GObject.GObject, Gtk.TreeModel): """ The base class for all hierarchical treeview models. The model defines the mapping between a unique node and a path. Paths are defined by a tuple. @@ -288,7 +288,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): group_can_have_handle = False, has_secondary=False): cput = time.clock() - GObject.GObject.__init__(self) + super(TreeBaseModel, self).__init__() #We create a stamp to recognize invalid iterators. From the docs: #Set the stamp to be equal to your model's stamp, to mark the #iterator as valid. When your model's structure changes, you should @@ -867,6 +867,10 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): return 0 #Gtk.TreeModelFlags.ITERS_PERSIST def do_get_n_columns(self): + """Internal method. Don't inherit""" + return self.on_get_n_columns() + + def on_get_n_columns(self): """ Return the number of columns. Must be implemented in the child objects See Gtk.TreeModel