def edit(self, obj): """ Edit a Citation """ for handle in self.selected_handles(): citation = self.dbstate.db.get_citation_from_handle(handle) try: EditCitation(self.dbstate, self.uistate, [], citation) except Errors.WindowActiveError: pass
def edit_citation(self, handle): """ Edit the selected citation. """ try: citation = self.dbstate.db.get_citation_from_handle(handle) source_handle = citation.get_reference_handle() source = self.dbstate.db.get_source_from_handle(source_handle) EditCitation(self.dbstate, self.uistate, [], citation, source) except Errors.WindowActiveError: pass
def share_button_clicked(self, obj): SelectCitation = SelectorFactory('Citation') sel = SelectCitation(self.dbstate, self.uistate, self.track) object = sel.run() LOG.debug("selected object: %s" % object) # the object returned should either be a Source or a Citation if object: if isinstance(object, Source): try: from gui.editors import EditCitation EditCitation(self.dbstate, self.uistate, self.track, gen.lib.Citation(), object, callback=self.add_callback, callertitle=self.callertitle) except Errors.WindowActiveError: from QuestionDialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text()) elif isinstance(object, Citation): try: from gui.editors import EditCitation EditCitation(self.dbstate, self.uistate, self.track, object, callback=self.add_callback, callertitle=self.callertitle) except Errors.WindowActiveError: from QuestionDialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text()) else: raise ValueError("selection must be either source or citation")
def add_button_clicked(self, obj): """ Create a new Citation instance and call the EditCitation editor with the new citation. Called when the Add button is clicked. If the window already exists (Errors.WindowActiveError), we ignore it. This prevents the dialog from coming up twice on the same object. """ try: from gui.editors import EditCitation EditCitation(self.dbstate, self.uistate, self.track, gen.lib.Citation(), gen.lib.Source(), self.add_callback, self.callertitle) except Errors.WindowActiveError: pass
def _handle_drag(self, row, handle): """ A CITATION_LINK has been dragged """ if handle: object = self.dbstate.db.get_citation_from_handle(handle) if isinstance(object, Citation): try: from gui.editors import EditCitation EditCitation(self.dbstate, self.uistate, self.track, object, callback=self.add_callback, callertitle=self.callertitle) except Errors.WindowActiveError: from QuestionDialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text()) else: raise ValueError("selection must be either source or citation")
def edit_button_clicked(self, obj): """ Get the selected Citation instance and call the EditCitation editor with the citation. Called when the Edit button is clicked. If the window already exists (Errors.WindowActiveError), we ignore it. This prevents the dialog from coming up twice on the same object. """ handle = self.get_selected() if handle: citation = self.dbstate.db.get_citation_from_handle(handle) try: from gui.editors import EditCitation EditCitation(self.dbstate, self.uistate, self.track, citation, callertitle=self.callertitle) except Errors.WindowActiveError: pass
def edit(self, obj): """ Edit either a Source or a Citation, depending on user selection """ for handle in self.selected_handles(): # The handle will either be a Source handle or a Citation handle source = self.dbstate.db.get_source_from_handle(handle) citation = self.dbstate.db.get_citation_from_handle(handle) if (not source and not citation) or (source and citation): raise ValueError("selection must be either source or citation") if citation: try: EditCitation(self.dbstate, self.uistate, [], citation) except Errors.WindowActiveError: pass else: # FIXME need try block here try: EditSource(self.dbstate, self.uistate, [], source) except Errors.WindowActiveError: from QuestionDialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text2())
def add(self, obj): """ add: Add a new citation and a new source (this can also be done by source view add a source, then citation view add a new citation to an existing source) Create a new Source instance and Citation instance and call the EditSource editor with the new source. Called when the Add button is clicked. If the window already exists (Errors.WindowActiveError), we ignore it. This prevents the dialog from coming up twice on the same object. However, since the window is identified by the Source object, and we have just created a new one, it seems to be impossible for the window to already exist, so this is just an extra safety measure. """ try: EditCitation(self.dbstate, self.uistate, [], gen.lib.Citation(), gen.lib.Source()) except Errors.WindowActiveError: pass
def handle_extra_type(self, objtype, handle): """ A SOURCE_LINK object has been dragged """ if handle: object = self.dbstate.db.get_source_from_handle(handle) if isinstance(object, Source): try: from gui.editors import EditCitation EditCitation(self.dbstate, self.uistate, self.track, gen.lib.Citation(), object, callback=self.add_callback, callertitle=self.callertitle) except Errors.WindowActiveError: from QuestionDialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text()) else: raise ValueError("selection must be either source or citation")
def share(self, obj): """ share: Add a new citation to an existing source (when a source is selected) """ for handle in self.selected_handles(): # The handle will either be a Source handle or a Citation handle source = self.dbstate.db.get_source_from_handle(handle) citation = self.dbstate.db.get_citation_from_handle(handle) if (not source and not citation) or (source and citation): raise ValueError("selection must be either source or citation") if source: try: EditCitation(self.dbstate, self.uistate, [], gen.lib.Citation(), source) except Errors.WindowActiveError: from QuestionDialog import WarningDialog WarningDialog(_("Cannot share this reference"), self.__blocked_text()) else: msg = _("Cannot add citation.") msg2 = _("In order to add a citation to an existing source, " " you must select a source.") ErrorDialog(msg, msg2)
def edit_object(dbstate, uistate, reftype, ref): """ Invokes the appropriate editor for an object type and given handle. """ from gui.editors import (EditEvent, EditPerson, EditFamily, EditSource, EditPlace, EditMedia, EditRepository, EditCitation) if reftype == 'Person': try: person = dbstate.db.get_person_from_handle(ref) EditPerson(dbstate, uistate, [], person) except Errors.WindowActiveError: pass elif reftype == 'Family': try: family = dbstate.db.get_family_from_handle(ref) EditFamily(dbstate, uistate, [], family) except Errors.WindowActiveError: pass elif reftype == 'Source': try: source = dbstate.db.get_source_from_handle(ref) EditSource(dbstate, uistate, [], source) except Errors.WindowActiveError: pass elif reftype == 'Citation': try: citation = dbstate.db.get_citation_from_handle(ref) EditCitation(dbstate, uistate, [], citation) except Errors.WindowActiveError: """ Return the text used when citation cannot be edited """ blocked_text = _("Cannot open new citation editor at this time. " "Either the citation is already being edited, " "or the associated source is already being " "edited, and opening a citation editor " "(which also allows the source " "to be edited), would create ambiguity " "by opening two editors on the same source. " "\n\n" "To edit the citation, close the source " "editor and open an editor for the citation " "alone") from QuestionDialog import WarningDialog WarningDialog(_("Cannot open new citation editor"), blocked_text) elif reftype == 'Place': try: place = dbstate.db.get_place_from_handle(ref) EditPlace(dbstate, uistate, [], place) except Errors.WindowActiveError: pass elif reftype == 'Media': try: obj = dbstate.db.get_media_from_handle(ref) EditMedia(dbstate, uistate, [], obj) except Errors.WindowActiveError: pass elif reftype == 'Event': try: event = dbstate.db.get_event_from_handle(ref) EditEvent(dbstate, uistate, [], event) except Errors.WindowActiveError: pass elif reftype == 'Repository': try: repo = dbstate.db.get_repository_from_handle(ref) EditRepository(dbstate, uistate, [], repo) except Errors.WindowActiveError: pass
def on_table_doubleclick(self, obj): """ Handle events on tables. obj is a treeview """ from gui.editors import (EditPerson, EditEvent, EditFamily, EditCitation, EditSource, EditPlace, EditRepository, EditNote, EditMedia) selection = obj.get_selection() store, paths = selection.get_selected_rows() tpath = paths[0] if len(paths) > 0 else None node = store.get_iter(tpath) if tpath else None if not node: return index = store.get_value(node, 0) # index if self._callback_leftdouble: self._callback_leftdouble(store.get_value(node, 1)) return True elif self.__link[index]: objclass, handle = self.__link[index] if objclass == 'Person': person = self.access.dbase.get_person_from_handle(handle) if person: try: EditPerson(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], person) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Event': event = self.access.dbase.get_event_from_handle(handle) if event: try: EditEvent(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], event) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Family': ref = self.access.dbase.get_family_from_handle(handle) if ref: try: EditFamily(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Citation': ref = self.access.dbase.get_citation_from_handle(handle) if ref: try: EditCitation(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Source': ref = self.access.dbase.get_source_from_handle(handle) if ref: try: EditSource(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Place': ref = self.access.dbase.get_place_from_handle(handle) if ref: try: EditPlace(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Repository': ref = self.access.dbase.get_repository_from_handle(handle) if ref: try: EditRepository(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'Note': ref = self.access.dbase.get_note_from_handle(handle) if ref: try: EditNote(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass in ['Media', 'MediaObject']: ref = self.access.dbase.get_object_from_handle(handle) if ref: try: EditMedia(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, [], ref) return True # handled event except Errors.WindowActiveError: pass elif objclass == 'PersonList': from QuickReports import run_quick_report_by_name run_quick_report_by_name(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, 'filterbyname', 'list of people', handles=handle) elif objclass == 'Filter': from QuickReports import run_quick_report_by_name run_quick_report_by_name(self.simpledoc.doc.dbstate, self.simpledoc.doc.uistate, 'filterbyname', handle[0]) return False # didn't handle event