Exemple #1
0
def qgis_excepthook(type, value, tb):
    # detect if running in the main thread
    in_main_thread = QThread.currentThread() == QgsApplication.instance(
    ).thread()

    # only use messagebar if running in main thread - otherwise it will crash!
    showException(type, value, tb, None, messagebar=in_main_thread)
Exemple #2
0
    def __init__(self, files, needPrj):
        QThread.__init__(self, QThread.currentThread())
        self.inFiles = files
        self.needPrj = needPrj

        self.mutex = QMutex()
        self.stopMe = 0
    def write(self, m):

        # This manage the case when console is called from another thread
        if QThread.currentThread() != QCoreApplication.instance().thread():
            QMetaObject.invokeMethod(self, "write", Qt.QueuedConnection,
                                     Q_ARG(str, m))
            return

        if self.style == "_traceback":
            # Show errors in red
            stderrColor = QColor(
                self.sO.settings.value("pythonConsole/stderrFontColor",
                                       QColor(self.ERROR_COLOR)))
            self.sO.SendScintilla(QsciScintilla.SCI_STYLESETFORE, 0o01,
                                  stderrColor)
            self.sO.SendScintilla(QsciScintilla.SCI_STYLESETITALIC, 0o01, True)
            self.sO.SendScintilla(QsciScintilla.SCI_STYLESETBOLD, 0o01, True)
            pos = self.sO.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
            self.sO.SendScintilla(QsciScintilla.SCI_STARTSTYLING, pos, 31)
            self.sO.append(m)
            self.sO.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 0o01)
        else:
            self.sO.append(m)

        if self.out:
            self.out.write(m)

        self.move_cursor_to_end()

        if self.style != "_traceback":
            self.sO.repaint()

        if self.fire_keyboard_interrupt:
            self.fire_keyboard_interrupt = False
            raise KeyboardInterrupt
Exemple #4
0
    def __init__(self, files, needPrj):
        QThread.__init__(self, QThread.currentThread())
        self.inFiles = files
        self.needPrj = needPrj

        self.mutex = QMutex()
        self.stopMe = 0
Exemple #5
0
    def write(self, m):

        # This manage the case when console is called from another thread
        if QThread.currentThread() != QCoreApplication.instance().thread():
            QMetaObject.invokeMethod(self, "write", Qt.QueuedConnection, Q_ARG(str, m))
            return

        if self.style == "_traceback":
            # Show errors in red
            stderrColor = QColor(self.sO.settings.value("pythonConsole/stderrFontColor", QColor(self.ERROR_COLOR)))
            self.sO.SendScintilla(QsciScintilla.SCI_STYLESETFORE, 0o01, stderrColor)
            self.sO.SendScintilla(QsciScintilla.SCI_STYLESETITALIC, 0o01, True)
            self.sO.SendScintilla(QsciScintilla.SCI_STYLESETBOLD, 0o01, True)
            pos = self.sO.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
            self.sO.SendScintilla(QsciScintilla.SCI_STARTSTYLING, pos, 31)
            self.sO.append(m)
            self.sO.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 0o01)
        else:
            self.sO.append(m)

        if self.out:
            self.out.write(m)

        self.move_cursor_to_end()

        if self.style != "_traceback":
            self.sO.repaint()

        if self.fire_keyboard_interrupt:
            self.fire_keyboard_interrupt = False
            raise KeyboardInterrupt
Exemple #6
0
def qgis_excepthook(type, value, tb):
    # detect if running in the main thread
    in_main_thread = True
    if QThread.currentThread() != QgsApplication.instance().thread():
        in_main_thread = False

    # only use messagebar if running in main thread - otherwise it will crash!
    showException(type, value, tb, None, messagebar=in_main_thread)
def showException(etype, value, tb, msg, *args, **kwargs):
    if QThread.currentThread() == qApp.thread():
        # we can show the exception directly
        show_debug_widget((etype,value,tb))
    else:
        # we need to pass the exception details to main thread - we can't do GUI stuff here
        deferred_dw_handler.debug_widget_data = (etype,value,tb)
        QMetaObject.invokeMethod(deferred_dw_handler, "start_deferred", Qt.QueuedConnection)
Exemple #8
0
    def __init__(self, iface, outputDir, projectFile, saveToZip):
        QThread.__init__(self, QThread.currentThread())
        self.mutex = QMutex()
        self.stopMe = 0

        self.iface = iface
        self.outputDir = outputDir
        self.layersDir = outputDir + "/layers"
        self.projectFile = projectFile
        self.saveToZip = saveToZip
Exemple #9
0
    def get_valid_mime_uri(layer_name, uri, wkb_type):
        """
        Gross method to force a valid layer path, only used for very old QGIS versions
        """
        if QgsWkbTypes.geometryType(wkb_type) == QgsWkbTypes.NullGeometry:
            layer_type = QgsMapLayer.RasterLayer
        else:
            layer_type = QgsMapLayer.VectorLayer

        if QThread.currentThread() == QCoreApplication.instance().thread():
            from .datasourceselectdialog import DataSourceSelectDialog  # pylint: disable=import-outside-toplevel

            dlg = DataSourceSelectDialog(layer_name=layer_name,
                                         original_uri=uri,
                                         layer_type=layer_type)
            if dlg.exec_():
                return dlg.uri

        # use default dummy path - QGIS 3.4 will crash on invalid layer sources otherwise
        uri = QgsMimeDataUtils.Uri()
        if QgsWkbTypes.geometryType(wkb_type) == QgsWkbTypes.PointGeometry:
            file = 'dummy_points.shp'
        elif QgsWkbTypes.geometryType(wkb_type) == QgsWkbTypes.LineGeometry:
            file = 'dummy_lines.shp'
        elif QgsWkbTypes.geometryType(wkb_type) == QgsWkbTypes.PolygonGeometry:
            file = 'dummy_polygon.shp'
        elif QgsWkbTypes.geometryType(wkb_type) == QgsWkbTypes.NullGeometry:
            file = 'dummy_raster.tif'
        else:
            # ???
            file = 'dummy_points.shp'

        path = os.path.dirname(os.path.abspath(__file__))
        uri.uri = os.path.realpath(os.path.join(path, '..', '..',
                                                file)).replace('\\', '/')
        uri.providerKey = 'ogr'
        return uri
Exemple #10
0
def qgis_excepthook(type, value, tb):
    # detect if running in the main thread
    in_main_thread = QCoreApplication.instance() is None or QThread.currentThread() == QCoreApplication.instance().thread()

    # only use messagebar if running in main thread - otherwise it will crash!
    showException(type, value, tb, None, messagebar=in_main_thread)