diff --git a/gramps/gui/views/listview.py b/gramps/gui/views/listview.py index 4d4bc044e..9f7227798 100644 --- a/gramps/gui/views/listview.py +++ b/gramps/gui/views/listview.py @@ -63,7 +63,7 @@ from gramps.gen.errors import WindowActiveError from ..filters import SearchBar from ..widgets.menuitem import add_menuitem from gramps.gen.constfunc import UNITYPE -from gramps.gen.const import CUSTOM_FILTERS, USE_TIPS +from gramps.gen.const import CUSTOM_FILTERS from gramps.gen.utils.debug import profile from gramps.gen.utils.string import data_recover_msg from gramps.gen.utils.file import get_unicode_path_from_file_chooser @@ -178,7 +178,8 @@ class ListView(NavigationView): self.list.drag_dest_set_target_list(tglist) scrollwindow = Gtk.ScrolledWindow() - scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + scrollwindow.set_policy(Gtk.PolicyType.AUTOMATIC, + Gtk.PolicyType.AUTOMATIC) scrollwindow.set_shadow_type(Gtk.ShadowType.ETCHED_IN) scrollwindow.add(self.list) @@ -326,9 +327,6 @@ class ListView(NavigationView): self.__display_column_sort() self.goto_active(None) - if USE_TIPS and self.model.tooltip_column() is not None: - self.list.set_tooltip_column(self.model.tooltip_column()) - self.dirty = False cput4 = time.clock() self.uistate.show_filter_results(self.dbstate, @@ -404,27 +402,21 @@ class ListView(NavigationView): if not handle or handle in self.selected_handles(): return - if self.model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY: - # Flat - path = self.model.node_map.get_path_from_handle(handle) - else: - # Tree - path = None - node = self.model.get_node(handle) - if node: - iter = self.model.get_iter(node) - has_parent, parent_iter = self.model.do_iter_parent(iter) - if has_parent: - parent_path = self.model.do_get_path(parent_iter) - if parent_path: - parent_path_list = parent_path.get_indices() - for i in range(len(parent_path_list)): - expand_path = Gtk.TreePath( - tuple([x for x in parent_path_list[:i+1]])) - self.list.expand_row(expand_path, False) - path = self.model.do_get_path(iter) + iter_ = self.model.get_iter_from_handle(handle) + if iter_: + if not (self.model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY): + # Expand tree + parent_iter = self.model.iter_parent(iter_) + if parent_iter: + parent_path = self.model.get_path(parent_iter) + parent_path_list = parent_path.get_indices() + for i in range(len(parent_path_list)): + expand_path = Gtk.TreePath( + tuple([x for x in parent_path_list[:i+1]])) + self.list.expand_row(expand_path, False) - if path is not None: + # Select active object + path = self.model.get_path(iter_) self.selection.unselect_all() self.selection.select_path(path) self.list.scroll_to_cell(path, None, 1, 0.5, 0) @@ -568,15 +560,11 @@ class ListView(NavigationView): if not prompt: self.uistate.set_busy_cursor(False) - def blist(self, store, path, iter, sel_list): + def blist(self, store, path, iter_, sel_list): '''GtkTreeSelectionForeachFunc construct a list sel_list with all selected handles ''' - if store.do_get_flags() & Gtk.TreeModelFlags.LIST_ONLY: - handle = store.node_map.get_handle(path.get_indices()[0]) - else: - handle = store.get_handle(store.get_node_from_iter(iter)) - + handle = store.get_handle_from_iter(iter_) if handle is not None: sel_list.append(handle) @@ -810,10 +798,9 @@ class ListView(NavigationView): # Tree store, paths = self.selection.get_selected_rows() if paths: - firstsel = paths[0] - firstnode = self.model.get_node_from_iter( - self.model.do_get_iter(firstsel)[1]) - if len(paths)==1 and firstnode.handle is None: + firstsel = self.model.get_iter(paths[0]) + handle = self.model.get_handle_from_iter(firstsel) + if len(paths)==1 and handle is None: return self.expand_collapse_tree_branch() else: self.edit(obj) @@ -894,19 +881,17 @@ class ListView(NavigationView): if event.keyval in (Gdk.KEY_Return, Gdk.KEY_KP_Enter): store, paths = self.selection.get_selected_rows() if paths: - firstsel = paths[0] - firstnode = self.model.get_node_from_iter( - self.model.do_get_iter(firstsel)[1]) - if len(paths) == 1 and firstnode.handle is None: + iter_ = self.model.get_iter(paths[0]) + handle = self.model.get_handle_from_iter(iter_) + if len(paths) == 1 and handle is None: return self.expand_collapse_tree_branch() else: if event.keyval in (Gdk.KEY_Return, Gdk.KEY_KP_Enter): store, paths = self.selection.get_selected_rows() if paths: - firstsel = paths[0] - firstnode = self.model.get_node_from_iter( - self.model.do_get_iter(firstsel)[1]) - if len(paths) == 1 and firstnode.handle is None: + iter_ = self.model.get_iter(paths[0]) + handle = self.model.get_handle_from_iter(iter_) + if len(paths) == 1 and handle is None: return self.expand_collapse_tree() else: self.edit(obj) @@ -921,9 +906,9 @@ class ListView(NavigationView): store, paths = self.selection.get_selected_rows() if paths: firstsel = paths[0] - firstnode = self.model.get_node_from_iter( - self.model.do_get_iter(firstsel)[1]) - if firstnode.handle: + iter_ = self.model.get_iter(firstsel) + handle = self.model.get_handle_from_iter(iter_) + if handle: return False if self.list.row_expanded(firstsel): self.list.collapse_row(firstsel) @@ -940,9 +925,9 @@ class ListView(NavigationView): store, paths = self.selection.get_selected_rows() if paths: firstsel = paths[0] - firstnode = self.model.get_node_from_iter( - self.model.do_get_iter(firstsel)[1]) - if firstnode.handle: + iter_ = self.model.get_iter(firstsel) + handle = self.model.get_handle_from_iter(iter_) + if handle: return False if self.list.row_expanded(firstsel): self.list.collapse_row(firstsel) @@ -1062,36 +1047,29 @@ class ListView(NavigationView): ofile.end_row() else: # Tree model - hasmodel, iter = self.model.do_get_iter((0,)) - if hasmodel: - node = self.model.get_node_from_iter(iter) - self.write_node(node, len(levels), [], ofile, data_cols) + iter_ = self.model.get_iter((0,)) + if iter_: + self.write_node(iter_, len(levels), [], ofile, data_cols) ofile.end_page() ofile.close() - def write_node(self, node, depth, level, ofile, data_cols): - if node is None: - return - while node is not None: - iternode = self.model.get_iter(node) - new_level = level + [self.model.do_get_value(iternode, 0)] - if self.model.get_handle(node): + def write_node(self, iter_, depth, level, ofile, data_cols): + + while iter_: + new_level = level + [self.model.get_value(iter_, 0)] + if self.model.get_handle_from_iter(iter_): ofile.start_row() padded_level = new_level + [''] * (depth - len(new_level)) list(map(ofile.write_cell, padded_level)) for index in data_cols: - ofile.write_cell(self.model.do_get_value(iternode, index)) + ofile.write_cell(self.model.get_value(iter_, index)) ofile.end_row() - has_child, first_child = self.model.do_iter_children(iternode) - if has_child: - self.write_node(self.model.get_node_from_iter(first_child), - depth, new_level, ofile, data_cols) - has_next = self.model.do_iter_next(iternode) - node = self.model.get_node_from_iter(iternode) - if not has_next: - node = None + first_child = self.model.iter_children(iter_) + self.write_node(first_child, depth, new_level, ofile, data_cols) + + iter_ = self.model.iter_next(iter_) #################################################################### # Template functions diff --git a/gramps/gui/views/treemodels/citationtreemodel.py b/gramps/gui/views/treemodels/citationtreemodel.py index 97a381e90..0e504fdc0 100644 --- a/gramps/gui/views/treemodels/citationtreemodel.py +++ b/gramps/gui/views/treemodels/citationtreemodel.py @@ -174,7 +174,7 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel): data The object data. """ sort_key = self.sort_func2(data) - if self.get_node(data[5]): + if self._get_node(data[5]): self.add_node(data[5], handle, sort_key, handle, secondary=True) def do_get_n_columns(self): diff --git a/gramps/gui/views/treemodels/flatbasemodel.py b/gramps/gui/views/treemodels/flatbasemodel.py index 433910017..b859843ff 100644 --- a/gramps/gui/views/treemodels/flatbasemodel.py +++ b/gramps/gui/views/treemodels/flatbasemodel.py @@ -526,7 +526,7 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): col = search[1][0] text = search[1][1] inv = search[1][2] - func = lambda x: self.get_value_from_handle(x, col) or UEMPTY + func = lambda x: self._get_value(x, col) or UEMPTY if search[2]: self.search = ExactSearchFilter(func, text, inv) else: @@ -705,17 +705,12 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): node = self.do_get_iter(path)[1] self.row_changed(path, node) - def handle2path(self, handle): - """ - Obtain from a handle, a path. - Part of common api with flat/treebasemodel - """ - return self.on_get_path_from_handle(handle) - def get_iter_from_handle(self, handle): """ Get the iter for a gramps handle. """ + if self.node_map.get_path_from_handle(handle) is None: + return None return self.node_map.new_iter(handle) def get_handle_from_iter(self, iter): @@ -775,7 +770,7 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): except IndexError: return False, Gtk.TreeIter() - def get_value_from_handle(self, handle, col): + def _get_value(self, handle, col): """ Given handle and column, return unicode value in the column We need this to search in the column in the GUI @@ -796,7 +791,7 @@ class FlatBaseModel(GObject.Object, Gtk.TreeModel): """ #print 'do_get_val', iter, iter.user_data, col handle = self.node_map._index2hndl[iter.user_data][1] - val = self.get_value_from_handle(handle, col) + val = self._get_value(handle, col) #print 'val is', val, type(val) #GTK 3 should convert unicode objects automatically, but this diff --git a/gramps/gui/views/treemodels/placemodel.py b/gramps/gui/views/treemodels/placemodel.py index 43d537c52..ce503d146 100644 --- a/gramps/gui/views/treemodels/placemodel.py +++ b/gramps/gui/views/treemodels/placemodel.py @@ -359,7 +359,7 @@ class PlaceTreeModel(PlaceBaseModel, TreeBaseModel): if node.name: return '%s' % cgi.escape(node.name) else: - level = len(self.do_get_path(self.get_iter(node)).get_indices()) + level = len(self.do_get_path(self._get_iter(node)).get_indices()) heading = '%s' % cgi.escape(COUNTRYLEVELS['default'][level]) # This causes a problem with Gtk3 unless we cast to str. return str(heading) diff --git a/gramps/gui/views/treemodels/treebasemodel.py b/gramps/gui/views/treemodels/treebasemodel.py index 9e71acf15..daa943e83 100644 --- a/gramps/gui/views/treemodels/treebasemodel.py +++ b/gramps/gui/views/treemodels/treebasemodel.py @@ -644,7 +644,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): if not self._in_build: # emit row_inserted signal - iternode = self.get_iter(child_node) + iternode = self._get_iter(child_node) path = self.do_get_path(iternode) self.row_inserted(path, iternode) if handle: @@ -681,7 +681,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): self.__displayed -= 1 self.__total -= 1 elif node.parent: # don't remove the hidden root node - iternode = self.get_iter(node) + iternode = self._get_iter(node) path = self.do_get_path(iternode) self.nodemap.node(node.parent).remove_child(node, self.nodemap) del self.tree[node.ref] @@ -719,7 +719,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): if node.parent is None: path = iter = None else: - iternode = self.get_iter(node) + iternode = self._get_iter(node) path = self.do_get_path(iternode) # activate when https://bugzilla.gnome.org/show_bug.cgi?id=684558 # is resolved @@ -749,7 +749,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): """ if sys.version_info[0] >= 3: assert isinstance(handle, str) - if self.get_node(handle) is not None: + if self._get_node(handle) is not None: return # row already exists cput = time.clock() if not self.search or \ @@ -773,7 +773,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): if sys.version_info[0] >= 3: assert isinstance(handle, str) cput = time.clock() - node = self.get_node(handle) + node = self._get_node(handle) if node is None: return # row not currently displayed @@ -786,7 +786,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): if not parent.children: if parent.handle: # emit row_has_child_toggled signal - iternode = self.get_iter(parent) + iternode = self._get_iter(parent) path = self.do_get_path(iternode) self.row_has_child_toggled(path, iternode) else: @@ -804,7 +804,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): """ if sys.version_info[0] >= 3: assert isinstance(handle, str) - if self.get_node(handle) is None: + if self._get_node(handle) is None: return # row not currently displayed self.delete_row_by_handle(handle) @@ -813,7 +813,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): # If the node hasn't moved, all we need is to call row_changed. #self.row_changed(path, node) - def new_iter(self, nodeid): + def _new_iter(self, nodeid): """ Return a new iter containing the nodeid in the nodemap """ @@ -824,7 +824,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): iter.user_data = nodeid return iter - def get_iter(self, node): + def _get_iter(self, node): """ Return an iter from the node. iters are always created afresh @@ -835,37 +835,20 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): :param path: node as it appears in the treeview :type path: Node """ - iter = self.new_iter(id(node)) + iter = self._new_iter(id(node)) return iter - def get_handle(self, node): - """ - Get the gramps handle for a node. Return None if the node does - not correspond to a gramps object. - """ - handle = node.handle - if handle and not isinstance(handle, UNITYPE): - handle = handle.decode('utf-8') - return handle - - def get_node(self, handle): + def _get_node(self, handle): """ Get the node for a handle. """ return self.handle2node.get(handle) - def handle2path(self, handle): - """ - Obtain from a handle, a path. - Part of common api with flat/treebasemodel - """ - return self.do_get_path(self.get_iter(self.get_node(handle))) - def get_iter_from_handle(self, handle): """ Get the iter for a gramps handle. """ - return self.get_iter(self._get_node(handle)) + return self._get_iter(self._get_node(handle)) def get_handle_from_iter(self, iter): """ @@ -964,7 +947,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): for index in pathlist: _index = (-index - 1) if self.__reverse else index node = self.nodemap.node(node.children[_index][1]) - return True, self.get_iter(node) + return True, self._get_iter(node) def get_node_from_iter(self, iter): if iter and iter.user_data: @@ -1024,7 +1007,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): nodeid = nodeparent.children[-1 if self.__reverse else 0][1] else: return False, None - return True, self.new_iter(nodeid) + return True, self._new_iter(nodeid) def do_iter_has_child(self, iter): """ @@ -1054,7 +1037,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): if node.children: if len(node.children) > index: _index = (-index - 1) if self.__reverse else index - return True, self.new_iter(node.children[_index][1]) + return True, self._new_iter(node.children[_index][1]) else: return False, None else: @@ -1066,6 +1049,6 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): """ node = self.get_node_from_iter(iterchild) if node.parent: - return True, self.new_iter(node.parent) + return True, self._new_iter(node.parent) else: return False, None diff --git a/gramps/plugins/view/persontreeview.py b/gramps/plugins/view/persontreeview.py index e00696598..a1dfbcbfb 100644 --- a/gramps/plugins/view/persontreeview.py +++ b/gramps/plugins/view/persontreeview.py @@ -170,9 +170,8 @@ class PersonTreeView(BasePersonView): pathids = path.get_indices() if len(pathids) == 1: path = Gtk.TreePath((pathids[0], 0)) - nodeiter = model.do_get_iter(path)[1] - node = model.get_node_from_iter(nodeiter) - handle = model.get_handle(node) + iter_ = model.get_iter(path) + handle = model.get_handle_from_iter(iter_) basepers = self.dbstate.db.get_person_from_handle(handle) if basepers: preset_name(basepers, name) diff --git a/gramps/plugins/view/placetreeview.py b/gramps/plugins/view/placetreeview.py index 923d83046..3f43aacad 100644 --- a/gramps/plugins/view/placetreeview.py +++ b/gramps/plugins/view/placetreeview.py @@ -201,34 +201,27 @@ class PlaceTreeView(PlaceBaseView): level1 = level2 = level3 = "" if len(pathlist) == 1: path = pathlist[0] - suc, node = model.do_get_iter(path) - if suc: - noden = model.get_node_from_iter(node) + iter_ = model.get_iter(path) + if iter_: if len(path) == 1: - level[0] = noden.name + level[0] = model.get_node_from_iter(iter_).name elif len(path) == 2: - level[1] = noden.name - suc, parent = model.do_iter_parent(node) - parentn = model.get_node_from_iter(parent) - level[0] = parentn.name + level[1] = model.get_node_from_iter(iter_).name + parent = model.iter_parent(iter_) + level[0] = model.get_node_from_iter(parent).name elif len(path) == 3: - level[2] = noden.name - suc, parent = model.do_iter_parent(node) - parentn = model.get_node_from_iter(parent) - level[1] = parentn.name - suc, parent = model.do_iter_parent(parent) - parentn = model.get_node_from_iter(parent) - level[0] = parentn.name + level[2] = model.get_node_from_iter(iter_).name + parent = model.iter_parent(iter_) + level[1] = model.get_node_from_iter(parent).name + parent = model.iter_parent(parent) + level[0] = model.get_node_from_iter(parent).name else: - suc, parent = model.do_iter_parent(node) - parentn = model.get_node_from_iter(parent) - level[2] = parentn.name - suc, parent = model.do_iter_parent(parent) - parentn = model.get_node_from_iter(parent) - level[1] = parentn.name - suc, parent = model.do_iter_parent(parent) - parentn = model.get_node_from_iter(parent) - level[0] = parentn.name + parent = model.iter_parent(iter_) + level[2] = model.get_node_from_iter(parent).name + parent = model.iter_parent(parent) + level[1] = model.get_node_from_iter(parent).name + parent = model.iter_parent(parent) + level[0] = model.get_node_from_iter(parent).name for ind in [0, 1, 2]: if level[ind] and level[ind] == COUNTRYLEVELS['default'][ind+1]: