def do_import(self): """ Import an ontology into the currently active Project. """ self.debug('Open dialog') dialog = QtWidgets.QFileDialog(self.session) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen) dialog.setDirectory(expandPath('~')) dialog.setFileMode(QtWidgets.QFileDialog.ExistingFiles) dialog.setViewMode(QtWidgets.QFileDialog.Detail) if dialog.exec_(): selected = [x for x in dialog.selectedFiles() if fexists(x)] if selected: try: with BusyProgressDialog(parent=self.session) as progress: for path in selected: progress.setWindowTitle('Importing {0}...'.format( os.path.basename(path))) worker = DescriptionsLoader( path, self.session.project, self.session) worker.run() except Exception as e: msgbox = QtWidgets.QMessageBox(self.session) msgbox.setDetailedText(format_exception(e)) msgbox.setIconPixmap( QtGui.QIcon( ':/icons/48/ic_error_outline_black').pixmap(48)) msgbox.setStandardButtons(QtWidgets.QMessageBox.Close) msgbox.setText( 'Eddy could not import all the selected files!') msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('Import failed!') msgbox.exec_()
def doImportDescriptions(self): """ Start the CSV import process. """ # SELECT CSV FILE VIA FILE DIALOG dialog = QtWidgets.QFileDialog(self.session) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen) dialog.setDirectory(expandPath('~')) dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) dialog.setViewMode(QtWidgets.QFileDialog.Detail) dialog.setNameFilters([File.Csv.value]) if not dialog.exec_(): return selected = expandPath(first(dialog.selectedFiles())) self.debug('Importing descriptions from file: {}'.format(selected)) reader = csv.reader(selected, dialect='excel', quoting=csv.QUOTE_ALL, quotechar='"') # PARSE CSV AND GENERATE COMMANDS commands = [] for row in reader: try: predicate, description = row[:2] # GET NODE CORRESPONDING TO PREDICATE for node in self.project.predicates(name=predicate): undo = self.project.meta(node.type(), node.text()) redo = undo.copy() redo[K_DESCRIPTION] = description undo[K_DESCRIPTION_STATUS] = undo.get( K_DESCRIPTION_STATUS, '') redo[K_DESCRIPTION_STATUS] = undo.get( K_DESCRIPTION_STATUS, '') # TODO: ADD STATUS COLUMN TO CSV # TODO: there is no conflict handler at the moment, # We need to provide here an interface for the user to # merge the current and imported description if redo != undo: commands.append( CommandNodeSetMeta(self.project, node.type(), node.text(), undo, redo)) except Exception as e: self.session.addNotification( textwrap.dedent(""" <b><font color="#7E0B17">ERROR</font></b>: Could not complete description import, please see the log for details. """)) return # APPLY CHANGES with BusyProgressDialog("Applying changes..."): self.session.undostack.beginMacro('edit {0} description'.format( self.node.name)) for command in commands: self.session.undostack.push(command) self.session.undostack.endMacro()
def doCreateSessionFromScratch(self, projName, ontIri, ontPrefix): """ Create a session for a new brand project. """ for session in self.sessions: # Look among the active sessions and see if we already have # a session loaded for the given project: if so, focus it. if not session.project.path and session.project.name == projName and session.project.ontologyIRI == ontIri: session.show() break else: # If we do not have a session for the given project we'll create one. with BusyProgressDialog('Creating new project with name: {0}'.format(projName)): try: session = Session(self, path=None, projName=projName, ontIri=ontIri, ontPrefix=ontPrefix) except ProjectStopLoadingError: pass except Exception as e: LOGGER.warning('Failed to create session for new project : %s', e) msgbox = QtWidgets.QMessageBox() msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48)) msgbox.setText('Failed to create session for new project') msgbox.setTextFormat(QtCore.Qt.RichText) msgbox.setDetailedText(format_exception(e)) msgbox.setStandardButtons(QtWidgets.QMessageBox.Close) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('Project Error!') msgbox.exec_() else: ############################################# # CLOSE THE WELCOME SCREEN IF NECESSARY ################################# try: self.welcome.close() except (AttributeError, RuntimeError): pass ############################################# # STARTUP THE SESSION ################################# connect(session.sgnQuit, self.doQuit) connect(session.sgnClosed, self.onSessionClosed) self.sessions.append(session) self.sgnSessionCreated.emit(session) session.show()
def doCreateSession(self, path): """ Create a session using the given project path. :type path: str """ for session in self.sessions: # Look among the active sessions and see if we already have # a session loaded for the given project: if so, focus it. if session.project.path == path: session.show() break else: # If we do not have a session for the given project we'll create one. with BusyProgressDialog('Loading project: {0}'.format( os.path.basename(path))): try: session = Session(self, path) except ProjectStopLoadingError: pass except (ProjectNotFoundError, ProjectNotValidError, ProjectVersionError) as e: LOGGER.warning( 'Failed to create session for project %s: %s', path, e) msgbox = QtWidgets.QMessageBox() msgbox.setIconPixmap( QtGui.QIcon( ':/icons/48/ic_error_outline_black').pixmap(48)) msgbox.setText( 'Failed to create session for project: <b>{0}</b>!'. format(os.path.basename(path))) msgbox.setTextFormat(QtCore.Qt.RichText) msgbox.setDetailedText(format_exception(e)) msgbox.setStandardButtons(QtWidgets.QMessageBox.Close) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('Project Error!') msgbox.exec_() except Exception as e: raise e else: ############################################# # UPDATE RECENT PROJECTS ################################# settings = QtCore.QSettings(ORGANIZATION, APPNAME) projects = settings.value('project/recent', None, str) or [] try: projects.remove(path) except ValueError: pass finally: projects.insert(0, path) projects = projects[:8] settings.setValue('project/recent', projects) settings.sync() ############################################# # CLOSE THE WELCOME SCREEN IF NECESSARY ################################# try: self.welcome.close() except (AttributeError, RuntimeError): pass ############################################# # STARTUP THE SESSION ################################# connect(session.sgnQuit, self.doQuit) connect(session.sgnClosed, self.onSessionClosed) self.sessions.append(session) session.show()