Ejemplo n.º 1
0
def base_except_hook(exc_type, exc_value, exc_traceback):
    """
    Used to handle all uncaught exceptions.
    :type exc_type: class
    :type exc_value: Exception
    :type exc_traceback: Traceback
    """
    if issubclass(exc_type, KeyboardInterrupt):
        app.quit()
    else:
        global msgbox
        if not msgbox:
            LOGGER.critical(format_exception(exc_value))
            msgbox = QtWidgets.QMessageBox()
            msgbox.setIconPixmap(QtGui.QPixmap(':/images/eddy-sad'))
            msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
            msgbox.setWindowTitle('Fatal error!')
            msgbox.setText('This is embarrassing ...\n\n' \
            'A critical error has just occurred. {0} will continue to work, ' \
            'however a reboot is highly recommended.'.format(APPNAME))
            msgbox.setInformativeText('If the problem persists you can '
            '<a href="{0}">submit a bug report</a>.'.format(BUG_TRACKER))
            msgbox.setDetailedText(format_exception(exc_value))
            msgbox.setStandardButtons(QtWidgets.QMessageBox.Close | QtWidgets.QMessageBox.Ok)
            buttonOk = msgbox.button(QtWidgets.QMessageBox.Ok)
            buttonOk.setText('Close')
            buttonQuit = msgbox.button(QtWidgets.QMessageBox.Close)
            buttonQuit.setText('Quit {0}'.format(APPNAME))
            connect(buttonOk.clicked, msgbox.close)
            connect(buttonQuit.clicked, app.quit)
            # noinspection PyArgumentList
            QtWidgets.QApplication.beep()
            msgbox.exec_()
            msgbox = None
Ejemplo n.º 2
0
 def accept(self):
     """
     Trigger the install of the selected plugin.
     """
     try:
         spec = self.session.pmanager.install(self.pluginField.value())
     except Exception as e:
         msgbox = QtWidgets.QMessageBox(self)
         msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48))
         msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
         msgbox.setText('{0} could not install plugin archive <b>{1}</b>: {2}'.format(APPNAME, self.pluginField.value(), e))
         msgbox.setDetailedText(format_exception(e))
         msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
         msgbox.setWindowTitle('Plugin install failed!')
         msgbox.exec_()
     else:
         plugin_name = spec.get('plugin', 'name')
         plugin_version = spec.get('plugin', 'version')
         plugin_author = spec.get('plugin', 'author', fallback='<unknown>')
         message = dedent("""Successfully installed plugin <b>{0} v{1}</b> by <b>{2}</b>.
         Please reboot {3} for the plugin to work.""".format(plugin_name, plugin_version, plugin_author, APPNAME))
         msgbox = QtWidgets.QMessageBox(self)
         msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_done_black').pixmap(48))
         msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
         msgbox.setText(message)
         msgbox.setTextFormat(QtCore.Qt.RichText)
         msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
         msgbox.setWindowTitle('Plugin installed!')
         msgbox.exec_()
         super().accept()
Ejemplo n.º 3
0
 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_()
Ejemplo n.º 4
0
 def doDeleteProject(self, path):
     """
     Delete the given project.
     :type path: str
     """
     msgbox = QtWidgets.QMessageBox(self)
     msgbox.setFont(Font('Roboto', 11))
     msgbox.setIconPixmap(
         QtGui.QIcon(':/icons/48/ic_question_outline_black').pixmap(48))
     msgbox.setInformativeText(
         '<b>NOTE: This action is not reversible!</b>')
     msgbox.setStandardButtons(QtWidgets.QMessageBox.No
                               | QtWidgets.QMessageBox.Yes)
     msgbox.setTextFormat(QtCore.Qt.RichText)
     msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
     msgbox.setWindowTitle('Remove project: {0}?'.format(
         os.path.basename(path)))
     msgbox.setText(
         'Are you sure you want to remove project: <b>{0}</b>'.format(
             os.path.basename(path)))
     msgbox.exec_()
     if msgbox.result() == QtWidgets.QMessageBox.Yes:
         try:
             # REMOVE THE PROJECT FROM DISK
             rmdir(path)
         except Exception as e:
             msgbox = QtWidgets.QMessageBox(self)
             msgbox.setDetailedText(format_exception(e))
             msgbox.setIconPixmap(
                 QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(
                     48))
             msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
             msgbox.setTextFormat(QtCore.Qt.RichText)
             msgbox.setText(
                 'Eddy could not remove the specified project: <b>{0}</b>!'.
                 format(os.path.basename(path)))
             msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
             msgbox.setWindowTitle('ERROR!')
             msgbox.exec_()
         else:
             # UPDATE THE RECENT PROJECT LIST
             recentList = []
             settings = QtCore.QSettings(ORGANIZATION, APPNAME)
             for path in map(expandPath, settings.value('project/recent')):
                 if isdir(path):
                     recentList.append(path)
             settings.setValue('project/recent', recentList)
             settings.sync()
             # CLEAR CURRENT LAYOUT
             for i in reversed(range(self.innerLayoutL.count())):
                 item = self.innerLayoutL.itemAt(i)
                 self.innerLayoutL.removeItem(item)
             # DISPOSE NEW PROJECT BLOCK
             for path in recentList:
                 project = ProjectBlock(path, self.innerWidgetL)
                 connect(project.sgnDeleteProject, self.doDeleteProject)
                 connect(project.sgnOpenProject, self.doOpenProject)
                 self.innerLayoutL.addWidget(project, 0, QtCore.Qt.AlignTop)
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
 def doDeleteProject(self, path):
     """
     Delete the given project.
     :type path: str
     """
     msgbox = QtWidgets.QMessageBox(self)
     msgbox.setFont(Font('Roboto', 11))
     msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_question_outline_black').pixmap(48))
     msgbox.setInformativeText('<b>NOTE: This action is not reversible!</b>')
     msgbox.setStandardButtons(QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes)
     msgbox.setTextFormat(QtCore.Qt.RichText)
     msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
     msgbox.setWindowTitle('Remove project: {0}?'.format(os.path.basename(path)))
     msgbox.setText('Are you sure you want to remove project: <b>{0}</b>'.format(os.path.basename(path)))
     msgbox.exec_()
     if msgbox.result() == QtWidgets.QMessageBox.Yes:
         try:
             # REMOVE THE PROJECT FROM DISK
             rmdir(path)
         except Exception as e:
             msgbox = QtWidgets.QMessageBox(self)
             msgbox.setDetailedText(format_exception(e))
             msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48))
             msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
             msgbox.setTextFormat(QtCore.Qt.RichText)
             msgbox.setText('Eddy could not remove the specified project: <b>{0}</b>!'.format(os.path.basename(path)))
             msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
             msgbox.setWindowTitle('ERROR!')
             msgbox.exec_()
         else:
             # UPDATE THE RECENT PROJECT LIST
             recentList = []
             settings = QtCore.QSettings(ORGANIZATION, APPNAME)
             for path in map(expandPath, settings.value('project/recent')):
                 if isdir(path):
                     recentList.append(path)
             settings.setValue('project/recent', recentList)
             settings.sync()
             # CLEAR CURRENT LAYOUT
             for i in reversed(range(self.innerLayoutL.count())):
                 item = self.innerLayoutL.itemAt(i)
                 self.innerLayoutL.removeItem(item)
             # DISPOSE NEW PROJECT BLOCK
             for path in recentList:
                 project = ProjectBlock(path, self.innerWidgetL)
                 connect(project.sgnDeleteProject, self.doDeleteProject)
                 connect(project.sgnOpenProject, self.doOpenRecentProject)
                 self.innerLayoutL.addWidget(project, 0, QtCore.Qt.AlignTop)
Ejemplo n.º 7
0
 def accept(self):
     """
     Trigger the install of the selected plugin.
     """
     try:
         spec = self.session.pmanager.install(self.pluginField.value())
     except Exception as e:
         msgbox = QtWidgets.QMessageBox(self)
         msgbox.setIconPixmap(
             QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48))
         msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
         msgbox.setText(
             '{0} could not install plugin archive <b>{1}</b>: {2}'.format(
                 APPNAME, self.pluginField.value(), e))
         msgbox.setDetailedText(format_exception(e))
         msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
         msgbox.setWindowTitle('Plugin install failed!')
         msgbox.exec_()
     else:
         plugin_name = spec.get('plugin', 'name')
         plugin_version = spec.get('plugin', 'version')
         plugin_author = spec.get('plugin', 'author', fallback='<unknown>')
         message = dedent("""\
             Successfully installed plugin <b>{0} v{1}</b> by <b>{2}</b>.<br/>
             In order to load the plugin you have to restart {3}.<br/>
             <p>Would you like to restart now?</p>
             """.format(plugin_name, plugin_version, plugin_author,
                        APPNAME))
         msgbox = QtWidgets.QMessageBox(self)
         msgbox.setIconPixmap(
             QtGui.QIcon(':/icons/48/ic_done_black').pixmap(48))
         msgbox.setStandardButtons(QtWidgets.QMessageBox.Yes
                                   | QtWidgets.QMessageBox.No)
         msgbox.setText(message)
         msgbox.setTextFormat(QtCore.Qt.RichText)
         msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
         msgbox.setWindowTitle('Plugin installed!')
         buttonYes = msgbox.button(QtWidgets.QMessageBox.Yes)
         # noinspection PyArgumentList
         buttonYes.clicked.connect(
             QtWidgets.QApplication.instance().doRestart,
             QtCore.Qt.QueuedConnection)
         msgbox.exec_()
         super().accept()
Ejemplo n.º 8
0
 def accept(self):
     """
     Trigger the install of the selected reasoner.
     """
     try:
         spec = self.session.pmanager.install(self.reasonerField.value())
     except Exception as e:
         msgbox = QtWidgets.QMessageBox(self)
         msgbox.setIconPixmap(
             QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48))
         msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
         msgbox.setText(
             '{0} could not install reasoner archive <b>{1}</b>: {2}'.
             format(APPNAME, self.reasonerField.value(), e))
         msgbox.setDetailedText(format_exception(e))
         msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
         msgbox.setWindowTitle('Reasoner install failed!')
         msgbox.exec_()
     else:
         reasoner_name = spec.get('reasoner', 'name')
         reasoner_version = spec.get('reasoner', 'version')
         reasoner_author = spec.get('reasoner',
                                    'author',
                                    fallback='<unknown>')
         message = dedent(
             """Successfully installed reasoner <b>{0} v{1}</b> by <b>{2}</b>.
         Please reboot {3} for the reasoner to work.""".format(
                 reasoner_name, reasoner_version, reasoner_author, APPNAME))
         msgbox = QtWidgets.QMessageBox(self)
         msgbox.setIconPixmap(
             QtGui.QIcon(':/icons/48/ic_done_black').pixmap(48))
         msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
         msgbox.setText(message)
         msgbox.setTextFormat(QtCore.Qt.RichText)
         msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
         msgbox.setWindowTitle('Reasoner installed!')
         msgbox.exec_()
         super().accept()
Ejemplo n.º 9
0
    def accept(self):
        """
        Create Eddy workspace (if necessary).
        """
        path = self.workspaceField.value()

        try:
            mkdir(path)
        except Exception as e:
            msgbox = QtWidgets.QMessageBox(self)
            msgbox.setDetailedText(format_exception(e))
            msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_error_outline_black').pixmap(48))
            msgbox.setStandardButtons(QtWidgets.QMessageBox.Close)
            msgbox.setText('{0} could not create the specified workspace: {1}!'.format(APPNAME, path))
            msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy'))
            msgbox.setWindowTitle('Workspace setup failed!')
            msgbox.exec_()
            super().reject()
        else:
            settings = QtCore.QSettings(ORGANIZATION, APPNAME)
            settings.setValue('workspace/home', path)
            settings.sync()
            super().accept()
Ejemplo n.º 10
0
 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()