Exemple #1
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
    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
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 #4
0
 def _deactivate_copyrights(self):
     self.iface.layerTreeView().clicked.disconnect(
         self._write_copyright_entries)
     self.iface.layerTreeView().currentLayerChanged.disconnect(
         self._write_copyright_entries)
     self.proj.layersAdded.disconnect(self._write_copyright_entries)
     self.proj.layersRemoved.disconnect(self._write_copyright_entries)
     QgsProject.instance().writeEntry("CopyrightLabel", "/Label",
                                      self._default_copyright)
     QgsProject.instance().writeEntry("CopyrightLabel", "/Enabled", False)
     QMetaObject.invokeMethod(self.iface.mainWindow(),
                              "projectReadDecorationItems")
     self.iface.mapCanvas().refresh()
Exemple #5
0
    def _write_copyright_entries(self, param):
        adding_layers = []
        if isinstance(param, QgsMapLayer):
            adding_layers.append(param)
        elif isinstance(param, list):
            if isinstance(param[0], QgsMapLayer):
                adding_layers += param

        parsed_copyrights = self._parse_copyrights(adding_layers=adding_layers)
        copyrights_to_text = []
        for c in parsed_copyrights:
            if c in self._default_copyright:
                continue
            copyrights_to_text.append(c)

        copyrights_text = ' '.join(copyrights_to_text)

        #trim copyright to raw
        copyrights_to_trim = parsed_copyrights + self._previous_copyrights
        trimed_copyrights_text = self._trim_copyrights_to_default(
            copyrights_to_trim)
        if not trimed_copyrights_text == "":
            print(trimed_copyrights_text)
            self._default_copyright = trimed_copyrights_text
            self._default_copyright_is_visible = True

        #if user defined copyright exists and visible
        if self._default_copyright and self._default_copyright_is_visible:
            copyrights_text += " " + self._default_copyright

        # when no active MapTiler layer
        if parsed_copyrights == []:
            QgsProject.instance().writeEntry("CopyrightLabel", "/Label",
                                             self._default_copyright)
            QgsProject.instance().writeEntry(
                "CopyrightLabel", "/Enabled",
                self._default_copyright_is_visible)
        else:
            QgsProject.instance().writeEntry("CopyrightLabel", "/Label",
                                             copyrights_text)
            QgsProject.instance().writeEntry("CopyrightLabel", "/Enabled",
                                             True)

        QgsProject.instance().writeEntry("CopyrightLabel", "/MarginH", 1)
        QgsProject.instance().writeEntry("CopyrightLabel", "/MarginV", 1)
        QMetaObject.invokeMethod(self.iface.mainWindow(),
                                 "projectReadDecorationItems")
        self.iface.mapCanvas().refresh()

        self._previous_copyrights = copyrights_to_text
Exemple #6
0
    def _write_copyright_entries(self):
        copyrights_text = self._parse_copyrights()
        # when no active MapTiler layer
        if copyrights_text == '':
            copyrights_text = self._default_copyright
            QgsProject.instance().writeEntry("CopyrightLabel", "/Label",
                                             copyrights_text)
            QgsProject.instance().writeEntry("CopyrightLabel", "/Enabled",
                                             False)

        else:
            QgsProject.instance().writeEntry("CopyrightLabel", "/Label",
                                             copyrights_text)
            QgsProject.instance().writeEntry("CopyrightLabel", "/Enabled",
                                             True)
        QgsProject.instance().writeEntry("CopyrightLabel", "/MarginH", 1)
        QgsProject.instance().writeEntry("CopyrightLabel", "/MarginV", 1)
        QMetaObject.invokeMethod(self.iface.mainWindow(),
                                 "projectReadDecorationItems")
        self.iface.mapCanvas().refresh()
    def render(self):
        """ do the rendering. This function is called in the worker thread """

        debug("[WORKER THREAD] Calling request() asynchronously", 3)
        QMetaObject.invokeMethod(self.controller, "request")

        # setup a timer that checks whether the rendering has not been stopped
        # in the meanwhile
        timer = QTimer()
        timer.setInterval(50)
        timer.timeout.connect(self.onTimeout)
        timer.start()

        debug("[WORKER THREAD] Waiting for the async request to complete", 3)
        self.loop = QEventLoop()
        self.controller.finished.connect(self.loop.exit)
        self.loop.exec_()

        debug("[WORKER THREAD] Async request finished", 3)

        painter = self.context.painter()
        painter.drawImage(0, 0, self.controller.img)
        return True
    def render(self):
        """ do the rendering. This function is called in the worker thread """

        debug("[WORKER THREAD] Calling request() asynchronously", 3)
        QMetaObject.invokeMethod(self.controller, "request")

        # setup a timer that checks whether the rendering has not been stopped
        # in the meanwhile
        timer = QTimer()
        timer.setInterval(50)
        timer.timeout.connect(self.onTimeout)
        timer.start()

        debug("[WORKER THREAD] Waiting for the async request to complete", 3)
        self.loop = QEventLoop()
        self.controller.finished.connect(self.loop.exit)
        self.loop.exec_()

        debug("[WORKER THREAD] Async request finished", 3)

        painter = self.context.painter()
        painter.drawImage(0, 0, self.controller.img)
        return True