Allow selection of two different object types in selectors
svn: r17973
This commit is contained in:
parent
871508b7f3
commit
763bea26ec
@ -193,6 +193,8 @@ class BaseSelector(ManagedWindow.ManagedWindow):
|
|||||||
id_list = self.get_selected_ids()
|
id_list = self.get_selected_ids()
|
||||||
if id_list and id_list[0]:
|
if id_list and id_list[0]:
|
||||||
result = self.get_from_handle_func()(id_list[0])
|
result = self.get_from_handle_func()(id_list[0])
|
||||||
|
if result is None and self.get_from_handle_func2:
|
||||||
|
result = self.get_from_handle_func2()(id_list[0])
|
||||||
self.close()
|
self.close()
|
||||||
elif val != gtk.RESPONSE_DELETE_EVENT:
|
elif val != gtk.RESPONSE_DELETE_EVENT:
|
||||||
self.close()
|
self.close()
|
||||||
@ -225,6 +227,9 @@ class BaseSelector(ManagedWindow.ManagedWindow):
|
|||||||
def get_from_handle_func(self):
|
def get_from_handle_func(self):
|
||||||
assert False, "Must be defined in the subclass"
|
assert False, "Must be defined in the subclass"
|
||||||
|
|
||||||
|
def get_from_handle_func2(self):
|
||||||
|
return None
|
||||||
|
|
||||||
def get_handle_column(self):
|
def get_handle_column(self):
|
||||||
# return 3
|
# return 3
|
||||||
assert False, "Must be defined in the subclass"
|
assert False, "Must be defined in the subclass"
|
||||||
|
@ -65,5 +65,8 @@ class SelectCitation(BaseSelector):
|
|||||||
def get_from_handle_func(self):
|
def get_from_handle_func(self):
|
||||||
return self.db.get_citation_from_handle
|
return self.db.get_citation_from_handle
|
||||||
|
|
||||||
|
def get_from_handle_func2(self):
|
||||||
|
return self.db.get_source_from_handle
|
||||||
|
|
||||||
def get_handle_column(self):
|
def get_handle_column(self):
|
||||||
return 11
|
return 11
|
||||||
|
@ -65,6 +65,10 @@ COLUMN_CONFIDENCE = 4
|
|||||||
COLUMN_SOURCE = 5
|
COLUMN_SOURCE = 5
|
||||||
COLUMN_CHANGE = 9
|
COLUMN_CHANGE = 9
|
||||||
|
|
||||||
|
COLUMN2_HANDLE = 0
|
||||||
|
COLUMN2_ID = 1
|
||||||
|
COLUMN2_TITLE = 2
|
||||||
|
|
||||||
INVALID_DATE_FORMAT = config.get('preferences.invalid-date-format')
|
INVALID_DATE_FORMAT = config.get('preferences.invalid-date-format')
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -262,11 +266,12 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel):
|
|||||||
self.gen_cursor = None
|
self.gen_cursor = None
|
||||||
self.map = None
|
self.map = None
|
||||||
self.fmap = None
|
self.fmap = None
|
||||||
|
self.map2 = None
|
||||||
|
self.fmap2 = None
|
||||||
self.smap = None
|
self.smap = None
|
||||||
# Can't call FlatBaseModel.destroy(self), because it fails when a treemodel
|
# Can't call FlatBaseModel.destroy(self), because it fails when a treemodel
|
||||||
# is passed, so can't just do:
|
# is passed, so can't just do:
|
||||||
# CitationBaseModel.destroy(self)
|
# CitationBaseModel.destroy(self)
|
||||||
self.hmap = None
|
|
||||||
self.number_items = None
|
self.number_items = None
|
||||||
TreeBaseModel.destroy(self)
|
TreeBaseModel.destroy(self)
|
||||||
|
|
||||||
@ -275,10 +280,22 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel):
|
|||||||
CitationBaseModel
|
CitationBaseModel
|
||||||
"""
|
"""
|
||||||
self.number_items = self.db.get_number_of_citations
|
self.number_items = self.db.get_number_of_citations
|
||||||
# FIXME: What should the number in the next line be?
|
self.map2 = db.get_raw_source_data
|
||||||
# FIXME: Only the first element of hmap ever seems to be populated.
|
self.fmap2 = [
|
||||||
# Why is this, and is it correct?
|
self.column2_src_title,
|
||||||
self.hmap = [self.column_header] + [None] * len(self.smap)
|
self.column2_src_id,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
self.column2_handle,
|
||||||
|
None
|
||||||
|
]
|
||||||
|
|
||||||
def get_tree_levels(self):
|
def get_tree_levels(self):
|
||||||
"""
|
"""
|
||||||
@ -294,24 +311,25 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel):
|
|||||||
data The object data.
|
data The object data.
|
||||||
"""
|
"""
|
||||||
source_handle = data[COLUMN_SOURCE]
|
source_handle = data[COLUMN_SOURCE]
|
||||||
if source_handle:
|
|
||||||
source = self.db.get_source_from_handle(source_handle)
|
source = self.db.get_source_from_handle(source_handle)
|
||||||
if source:
|
if source is not None:
|
||||||
source_name = source.get_title()
|
source_name = source.get_title()
|
||||||
sort_key = self.sort_func(data)
|
sort_key = self.sort_func(data)
|
||||||
# add as node: parent, child, sortkey, handle; parent and child are
|
# add as node: parent, child, sortkey, handle; parent and child are
|
||||||
# nodes in the treebasemodel, and will be used as iters
|
# nodes in the treebasemodel, and will be used as iters
|
||||||
self.add_node(source_name, handle, sort_key, handle)
|
if self.get_node(source_handle) is None:
|
||||||
|
self.add_node(None, source_handle, source_name, source_handle,
|
||||||
|
secondary=True)
|
||||||
|
self.add_node(source_handle, handle, sort_key, handle)
|
||||||
else:
|
else:
|
||||||
log.warn("Citation %s still has a pointer (handle %s) to a deleted source" %
|
log.warn("Citation %s does not have a source" %
|
||||||
(data[COLUMN_ID], source_handle))
|
unicode(data[COLUMN_PAGE]), exc_info=True)
|
||||||
else:
|
|
||||||
log.warn("Citation %s does not have a source" % unicode(data[COLUMN_PAGE]),
|
|
||||||
exc_info=True)
|
|
||||||
|
|
||||||
def column_header(self, node):
|
def column2_handle(self, data):
|
||||||
"""
|
return unicode(data[COLUMN2_HANDLE])
|
||||||
Return a column heading. This is called for nodes with no associated
|
|
||||||
Gramps handle.
|
def column2_src_title(self, data):
|
||||||
"""
|
return unicode(data[COLUMN2_TITLE])
|
||||||
return node.name
|
|
||||||
|
def column2_src_id(self, data):
|
||||||
|
return unicode(data[COLUMN2_ID])
|
||||||
|
@ -78,10 +78,10 @@ class Node(object):
|
|||||||
children A list of (sortkey, nodeid) tuples for the children of the node.
|
children A list of (sortkey, nodeid) tuples for the children of the node.
|
||||||
This list is always kept sorted.
|
This list is always kept sorted.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('name', 'sortkey', 'ref', 'handle', 'parent', 'prev',
|
__slots__ = ('name', 'sortkey', 'ref', 'handle', 'secondary', 'parent',
|
||||||
'next', 'children')#, '__weakref__')
|
'prev', 'next', 'children')#, '__weakref__')
|
||||||
|
|
||||||
def __init__(self, ref, parent, sortkey, handle):
|
def __init__(self, ref, parent, sortkey, handle, secondary):
|
||||||
self.name = sortkey
|
self.name = sortkey
|
||||||
if sortkey:
|
if sortkey:
|
||||||
self.sortkey = map(conv_unicode_tosrtkey_ongtk, sortkey)
|
self.sortkey = map(conv_unicode_tosrtkey_ongtk, sortkey)
|
||||||
@ -89,17 +89,19 @@ class Node(object):
|
|||||||
self.sortkey = None
|
self.sortkey = None
|
||||||
self.ref = ref
|
self.ref = ref
|
||||||
self.handle = handle
|
self.handle = handle
|
||||||
|
self.secondary = secondary
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.prev = None
|
self.prev = None
|
||||||
self.next = None
|
self.next = None
|
||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
def set_handle(self, handle):
|
def set_handle(self, handle, secondary=False):
|
||||||
"""
|
"""
|
||||||
Assign the handle of a Gramps object to this node.
|
Assign the handle of a Gramps object to this node.
|
||||||
"""
|
"""
|
||||||
if not self.handle:
|
if not self.handle:
|
||||||
self.handle = handle
|
self.handle = handle
|
||||||
|
self.secondary = secondary
|
||||||
else:
|
else:
|
||||||
print ('WARNING: Attempt to add handle twice to the node (%s)' %
|
print ('WARNING: Attempt to add handle twice to the node (%s)' %
|
||||||
handle)
|
handle)
|
||||||
@ -353,10 +355,12 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
self.gen_cursor = None
|
self.gen_cursor = None
|
||||||
self.number_items = None # function
|
self.number_items = None # function
|
||||||
self.map = None
|
self.map = None
|
||||||
|
self.map2 = None
|
||||||
|
|
||||||
self.smap = None
|
self.smap = None
|
||||||
self.fmap = None
|
self.fmap = None
|
||||||
self.hmap = None
|
self.smap2 = None
|
||||||
|
self.fmap2 = None
|
||||||
|
|
||||||
def displayed(self):
|
def displayed(self):
|
||||||
"""
|
"""
|
||||||
@ -404,7 +408,7 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
self.handle2node.clear()
|
self.handle2node.clear()
|
||||||
self.nodemap.clear()
|
self.nodemap.clear()
|
||||||
#start with creating the new iters
|
#start with creating the new iters
|
||||||
topnode = Node(None, None, None, None)
|
topnode = Node(None, None, None, None, False)
|
||||||
self.nodemap.add_node(topnode)
|
self.nodemap.add_node(topnode)
|
||||||
self.tree[None] = topnode
|
self.tree[None] = topnode
|
||||||
|
|
||||||
@ -537,7 +541,8 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
status_col.end()
|
status_col.end()
|
||||||
status.end()
|
status.end()
|
||||||
|
|
||||||
def add_node(self, parent, child, sortkey, handle, add_parent=True):
|
def add_node(self, parent, child, sortkey, handle, add_parent=True,
|
||||||
|
secondary=False):
|
||||||
"""
|
"""
|
||||||
Add a node to the map.
|
Add a node to the map.
|
||||||
|
|
||||||
@ -560,10 +565,12 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
if child in self.tree:
|
if child in self.tree:
|
||||||
#a node is added that is already present,
|
#a node is added that is already present,
|
||||||
child_node = self.tree[child]
|
child_node = self.tree[child]
|
||||||
self._add_dup_node(child_node, parent, child, sortkey, handle)
|
self._add_dup_node(child_node, parent, child, sortkey, handle,
|
||||||
|
secondary)
|
||||||
else:
|
else:
|
||||||
parent_node = self.tree[parent]
|
parent_node = self.tree[parent]
|
||||||
child_node = Node(child, id(parent_node), sortkey, handle)
|
child_node = Node(child, id(parent_node), sortkey, handle,
|
||||||
|
secondary)
|
||||||
parent_node.add_child(child_node, self.nodemap)
|
parent_node.add_child(child_node, self.nodemap)
|
||||||
self.tree[child] = child_node
|
self.tree[child] = child_node
|
||||||
self.nodemap.add_node(child_node)
|
self.nodemap.add_node(child_node)
|
||||||
@ -580,7 +587,7 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
if handle:
|
if handle:
|
||||||
self.handle2node[handle] = child_node
|
self.handle2node[handle] = child_node
|
||||||
|
|
||||||
def _add_dup_node(self, node, parent, child, sortkey, handle):
|
def _add_dup_node(self, node, parent, child, sortkey, handle, secondary):
|
||||||
"""
|
"""
|
||||||
How to handle adding a node a second time
|
How to handle adding a node a second time
|
||||||
Default: if group nodes can have handles, it is allowed to add it
|
Default: if group nodes can have handles, it is allowed to add it
|
||||||
@ -592,7 +599,7 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
% (str(parent), str(child)))
|
% (str(parent), str(child)))
|
||||||
return
|
return
|
||||||
if handle:
|
if handle:
|
||||||
node.set_handle(handle)
|
node.set_handle(handle, secondary)
|
||||||
if not self._in_build:
|
if not self._in_build:
|
||||||
self.__total += 1
|
self.__total += 1
|
||||||
self.__displayed += 1
|
self.__displayed += 1
|
||||||
@ -774,30 +781,34 @@ class TreeBaseModel(gtk.GenericTreeModel):
|
|||||||
if col == self.color_column():
|
if col == self.color_column():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Look for header fuction for column and call it
|
# Return the node name for the first column
|
||||||
if self.hmap[col] is not None:
|
if col == 0:
|
||||||
return self.hmap[col](node)
|
return self.column_header(node)
|
||||||
|
|
||||||
# If no header fuction return an empty string
|
|
||||||
return u''
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# return values for 'data' row, calling a function
|
# return values for 'data' row, calling a function
|
||||||
# according to column_defs table
|
# according to column_defs table
|
||||||
return self._get_value(node.handle, col)
|
return self._get_value(node.handle, col, node.secondary)
|
||||||
|
|
||||||
def _get_value(self, handle, col):
|
def _get_value(self, handle, col, secondary=False):
|
||||||
"""
|
"""
|
||||||
Returns the contents of a given column of a gramps object
|
Returns the contents of a given column of a gramps object
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
if handle in self.lru_data:
|
if handle in self.lru_data:
|
||||||
data = self.lru_data[handle]
|
data = self.lru_data[handle]
|
||||||
else:
|
else:
|
||||||
|
if not secondary:
|
||||||
data = self.map(handle)
|
data = self.map(handle)
|
||||||
|
else:
|
||||||
|
data = self.map2(handle)
|
||||||
if not self._in_build:
|
if not self._in_build:
|
||||||
self.lru_data[handle] = data
|
self.lru_data[handle] = data
|
||||||
|
|
||||||
|
try:
|
||||||
|
if not secondary:
|
||||||
return (self.fmap[col](data))
|
return (self.fmap[col](data))
|
||||||
|
else:
|
||||||
|
return (self.fmap2[col](data))
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user