def get_export_records(self, node=None, folder_ids=None, ref_keys=None): ''' determine what records to export. backend for html and bibtex export - if node is not None, we export the reference or folder it refers to. - elif folder_ids is not None, we collect all references in those folders - elif ref_keys is not None, we export just those references - else, we export the current selection. ''' if node is not None: if hub.is_ref(node): records = [self.get_ref_dict(node)] else: folder_id = node[1] branches, records = self.get_nodes_below([folder_id]) elif folder_ids is not None: branches, records = self.get_nodes_below(folder_ids) elif ref_keys is not None: records = self.get_refs_by_key(ref_keys) # print('records', len(records)) else: # get current selection records = hub.get_selected_refs_full() return sorted( records, key=lambda r: r['bibtexkey']) # sorting could be made configurable
def oo_cite(self, node=None, status=True): ''' insert a single reference into openoffice ''' if node is None: node = hub.tree.focus_element() assert hub.is_ref(node) raw_data = self.get_ref_dict(node) adapted = {} junk = "branches abstract selected pmid reftype_id purpose ref_id" for key, value in raw_data.items(): if key in junk: continue new_key = self.key_mapping.get(key, key.title()) adapted[new_key] = str(value) # pprint.pprint(adapted) try: self.insert_ref(adapted) except ConnectionError: hub.show_errors("No active Writer document found") if status: hub.set_status_bar('cited %s' % adapted['Identifier'])
def mail_current(self, node=None): ''' mail currently highlighted reference ''' if node is None: # invocation from menu will trigger this case node = hub.tree.focus_element() assert hub.is_ref(node) self._mail_references([node[1]])
def edit_item(self): ''' open edid dialog for reference or branch ''' w, focus_element = self.get_focus() if hub.is_ref(focus_element): hub.ref_edit() else: hub.branch_edit()
def toggle_view(self): """ Collapse currently focussed position; works only if the underlying tree allows it. """ focus_element = self.focus_element() if hub.is_ref(focus_element): hub.ref_view() else: self._tree.toggle_collapsed(focus_element) self.refresh()
def delete_other_instances(self, node): ''' here, we figure out what references exactly should be deleted from the node that was passed. A-hah. We need to be careful here - we cannot do this recursively with folders, because we might have multiple instances within the folder, and then all would get killed. Or, we would have to use some recursive query first to figure out exactly what would be preserved. ''' if hub.is_ref(node): ref_id, branch_id = node[1:] self._delete_other_instances([ref_id], [branch_id]) return # so it's a folder ... branch_id = node[1] subfolder_ids, ref_ids = self.get_nodes_below([branch_id], ids_only=True) self._delete_other_instances(ref_ids, subfolder_ids + [branch_id])
def make_question(self): template = self.ref_question if hub.is_ref( self.node) else self.branch_question return template % self.node_info