Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom message handler for pyside2 #285

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions qt_gui/src/qt_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,21 @@ def main(self, argv=None, standalone=None, plugin_argument_provider=None,
from qt_gui.perspective_manager import PerspectiveManager
from qt_gui.plugin_manager import PluginManager

# TODO PySide2 segfaults when invoking this custom message handler atm
if QT_BINDING != 'pyside':
def message_handler(type_, context, msg):
colored_output = 'TERM' in os.environ and 'ANSI_COLORS_DISABLED' not in os.environ
cyan_color = '\033[36m' if colored_output else ''
red_color = '\033[31m' if colored_output else ''
reset_color = '\033[0m' if colored_output else ''
if type_ == QtDebugMsg and self._options.verbose:
print(msg, file=sys.stderr)
elif type_ == QtWarningMsg:
print(cyan_color + msg + reset_color, file=sys.stderr)
elif type_ == QtCriticalMsg:
print(red_color + msg + reset_color, file=sys.stderr)
elif type_ == QtFatalMsg:
print(red_color + msg + reset_color, file=sys.stderr)
sys.exit(1)
qInstallMessageHandler(message_handler)
def message_handler(type_, context, msg):
colored_output = 'TERM' in os.environ and 'ANSI_COLORS_DISABLED' not in os.environ
cyan_color = '\033[36m' if colored_output else ''
red_color = '\033[31m' if colored_output else ''
reset_color = '\033[0m' if colored_output else ''
if type_ == QtDebugMsg and self._options.verbose:
print(msg, file=sys.stderr)
elif type_ == QtWarningMsg:
print(cyan_color + msg + reset_color, file=sys.stderr)
elif type_ == QtCriticalMsg:
print(red_color + msg + reset_color, file=sys.stderr)
elif type_ == QtFatalMsg:
print(red_color + msg + reset_color, file=sys.stderr)
sys.exit(1)
qInstallMessageHandler(message_handler)

app = self.create_application(argv)

Expand Down