Example #1
0
    def didFinishLaunching(self):
        log.info("Finding plugins")

        if getattr(sys, 'frozen', False):
            # frozen - load from app dir
            pluginsDir = getUserPluginsDirectory()
            plugins.findNewPluginsInDir(pluginsDir)
        else:
            # not frozen - load from src/plugins
            # from editorapp.py, ../../plugins
            devPluginsDir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "plugins")
            plugins.findNewPluginsInDir(devPluginsDir)

        for pluginRef in plugins.getAllPlugins():
            if pluginRef.enabled:
                if not pluginRef.load():
                    showErrorDialog("%s while loading plugin \"%s\"" % (pluginRef.loadError[0].__name__, pluginRef.displayName), pluginRef.loadError, False)

        log.info("Opening worlds from command line.")

        if len(self.commandLineWorlds):
            for filename in self.commandLineWorlds:
                self.loadFile(filename, self.args.view)
        else:
            self.showWorldList()

        if len(self.sessions) and self.args.eval:
            session = self.sessions[-1]
            eval_globals = {"session": session,
                            "self": self}
            exec(self.args.eval, eval_globals)
Example #2
0
    def setData(self, index, value, role=Qt.DisplayRole):
        if role != Qt.CheckStateRole:
            return
        if index.column() != 1:
            return

        row = index.row()
        if row >= len(self.pluginRefs):
            return False

        value = value == Qt.Checked

        pluginRef = self.pluginRefs[row]
        pluginRef.enabled = value

        if value:
            if not pluginRef.load():
                showErrorDialog("%s while loading plugin \"%s\"" % (pluginRef.loadError[0].__name__, pluginRef.displayName), pluginRef.loadError, False)

        else:
            if not pluginRef.unload():
                showErrorDialog("%s while unloading plugin \"%s\"" % (pluginRef.unloadError[0].__name__, pluginRef.displayName), pluginRef.unloadError, False)

        self.dataChanged.emit(index, index)
        return True
Example #3
0
    def didFinishLaunching(self):
        log.info("Finding plugins")

        if getattr(sys, 'frozen', False):
            # frozen - load from app dir
            pluginsDir = getUserPluginsDirectory()
            plugins.findNewPluginsInDir(pluginsDir)
        else:
            # not frozen - load from src/plugins
            # from editorapp.py, ../../plugins
            devPluginsDir = os.path.join(
                os.path.dirname(os.path.dirname(__file__)), "plugins")
            plugins.findNewPluginsInDir(devPluginsDir)

        for pluginRef in plugins.getAllPlugins():
            if pluginRef.enabled:
                if not pluginRef.load():
                    showErrorDialog(
                        "%s while loading plugin \"%s\"" %
                        (pluginRef.loadError[0].__name__,
                         pluginRef.displayName), pluginRef.loadError, False)

        log.info("Opening worlds from command line.")

        if len(self.commandLineWorlds):
            for filename in self.commandLineWorlds:
                self.loadFile(filename)
        else:
            self.showWorldList()

        if len(self.sessions) and self.args.eval:
            session = self.sessions[-1]
            eval_globals = {"session": session, "self": self}
            exec(self.args.eval, eval_globals)
Example #4
0
 def pluginAdded(self, cls):
     try:
         instance = cls(self.editorSession)
         self.plugins.append(instance)
     except Exception as e:
         msg = "Error while instantiating plugin class %s" % (cls, )
         log.exception(msg)
         showErrorDialog(msg, fatal=False)
Example #5
0
 def pluginAdded(self, cls):
     try:
         instance = cls(self.editorSession)
         self.plugins.append(instance)
     except Exception as e:
         msg = "Error while instantiating plugin class %s" % (cls,)
         log.exception(msg)
         showErrorDialog(msg, fatal=False)
Example #6
0
 def tryReloadPlugins(self):
     if not DevModeSetting.value():
         return
     
     for pluginRef in plugins.getAllPlugins():
         if pluginRef.checkTimestamps():
             log.info("Plugin %s changed. Reloading plugin module...", pluginRef.displayName)
             if not pluginRef.unload():
                 showErrorDialog("%s while unloading plugin \"%s\"" % (pluginRef.unloadError[0].__name__, pluginRef.displayName), pluginRef.unloadError, False)
                 if not pluginRef.load():
                     showErrorDialog("%s while loading plugin \"%s\"" % (pluginRef.loadError[0].__name__, pluginRef.displayName), pluginRef.loadError, False)
Example #7
0
def showPluginLoadError(pluginRef, unloading=False):
    doing = "loading"
    loadError = pluginRef.loadError
    if unloading:
        doing = "unloading"
        loadError = pluginRef.unloadError

    if loadError[0] == ImportError:
        if 'pymclevel' in loadError[1].message:
            QMessageBox.warning(None, ("MCEdit 1.0 Filters not supported"),
                                ("The file `{filename}` is an MCEdit 1.0 filter, which cannot be used in this version of MCEdit.\n\nRemove it from your plugins folder to avoid this error.").format(
                                    filename=os.path.basename(pluginRef.filename)
                                ))
            return

    showErrorDialog("%s while %s plugin \"%s\"" % (loadError[0].__name__, doing, pluginRef.displayName),
                    loadError, fatal=False, report=False)
Example #8
0
def excepthook(exc_type, exc_value, exc_tb):
    # When an error is caught during a Qt signal call, PySide calls PyErr_Print to
    # display the error traceback. PyErr_Print calls sys.excepthook to actually print the
    # exception, so we override it to send the error to the logging module and exit with an error,
    # since PySide foolishly tries to continue after catching the error.
    log.error("Unhandled Exception: \n\t%s", exc_value, exc_info=(exc_type, exc_value, exc_tb))
    # text = "An error has occured.\n\nUnhandled exception: %s" % exc_value
    # if getattr(sys, 'frozen', False):
    #     if editorApp:
    #         if editorApp.mainWindow:
    #             editorApp.mainWindow.hide()
    #     msg = QtGui.QMessageBox(editorApp.mainWindow or None if editorApp else None)
    #     msg.setIcon(QtGui.QMessageBox.Critical)
    #     msg.setText(text)
    #     msg.exec_()
    # sys.exit(-1)

    from mcedit2.dialogs.error_dialog import showErrorDialog
    showErrorDialog("Unhandled Exception", (exc_type, exc_value, exc_tb), fatal=True)
Example #9
0
    def tryReloadPlugins(self):
        if not DevModeSetting.value():
            return

        for pluginRef in plugins.getAllPlugins():
            if pluginRef.checkTimestamps():
                log.info("Plugin %s changed. Reloading plugin module...",
                         pluginRef.displayName)
                if not pluginRef.unload():
                    showErrorDialog(
                        "%s while unloading plugin \"%s\"" %
                        (pluginRef.unloadError[0].__name__,
                         pluginRef.displayName), pluginRef.unloadError, False)
                    if not pluginRef.load():
                        showErrorDialog(
                            "%s while loading plugin \"%s\"" %
                            (pluginRef.loadError[0].__name__,
                             pluginRef.displayName), pluginRef.loadError,
                            False)
Example #10
0
def showPluginLoadError(pluginRef, unloading=False):
    doing = "loading"
    loadError = pluginRef.loadError
    if unloading:
        doing = "unloading"
        loadError = pluginRef.unloadError

    if loadError[0] == ImportError:
        if 'pymclevel' in loadError[1].message:
            QMessageBox.warning(None, ("MCEdit 1.0 Filters not supported"), (
                "The file `{filename}` is an MCEdit 1.0 filter, which cannot be used in this version of MCEdit.\n\nRemove it from your plugins folder to avoid this error."
            ).format(filename=os.path.basename(pluginRef.filename)))
            return

    showErrorDialog("%s while %s plugin \"%s\"" %
                    (loadError[0].__name__, doing, pluginRef.displayName),
                    loadError,
                    fatal=False,
                    report=False)
Example #11
0
def excepthook(exc_type, exc_value, exc_tb):
    # When an error is caught during a Qt signal call, PySide calls PyErr_Print to
    # display the error traceback. PyErr_Print calls sys.excepthook to actually print the
    # exception, so we override it to send the error to the logging module and exit with an error,
    # since PySide foolishly tries to continue after catching the error.
    log.error("Unhandled Exception: \n\t%s",
              exc_value,
              exc_info=(exc_type, exc_value, exc_tb))
    # text = "An error has occured.\n\nUnhandled exception: %s" % exc_value
    # if getattr(sys, 'frozen', False):
    #     if editorApp:
    #         if editorApp.mainWindow:
    #             editorApp.mainWindow.hide()
    #     msg = QtGui.QMessageBox(editorApp.mainWindow or None if editorApp else None)
    #     msg.setIcon(QtGui.QMessageBox.Critical)
    #     msg.setText(text)
    #     msg.exec_()
    # sys.exit(-1)

    from mcedit2.dialogs.error_dialog import showErrorDialog
    showErrorDialog("Unhandled Exception", (exc_type, exc_value, exc_tb),
                    fatal=True)