Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix crash when print from qgis processing algorithm while the python …
…console is displayed
  • Loading branch information
troopa81 authored and nyalldawson committed Jan 29, 2019
1 parent e9ae431 commit 5f38b34
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python/console/console_output.py
Expand Up @@ -19,7 +19,7 @@
Some portions of code were taken from https://code.google.com/p/pydee/
"""

from qgis.PyQt.QtCore import Qt, QCoreApplication
from qgis.PyQt.QtCore import Qt, QCoreApplication, QThread, QMetaObject, Q_RETURN_ARG, Q_ARG, QObject, pyqtSlot
from qgis.PyQt.QtGui import QColor, QFont, QKeySequence, QFontDatabase
from qgis.PyQt.QtWidgets import QGridLayout, QSpacerItem, QSizePolicy, QShortcut, QMenu, QApplication
from qgis.PyQt.Qsci import QsciScintilla, QsciLexerPython
Expand All @@ -28,20 +28,28 @@
import sys


class writeOut(object):
class writeOut(QObject):

ERROR_COLOR = "#e31a1c"

def __init__(self, shellOut, out=None, style=None):
"""
This class allows writing to stdout and stderr
"""
super().__init__()
self.sO = shellOut
self.out = None
self.style = style
self.fire_keyboard_interrupt = False

@pyqtSlot(str)
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)))
Expand Down

0 comments on commit 5f38b34

Please sign in to comment.