Skip to content

Commit

Permalink
Merge pull request #509 from mantidproject/507_segfault_setwaterfall_cli
Browse files Browse the repository at this point in the history
Wrap set_waterfall to force a call in the qapp thread
  • Loading branch information
martyngigg authored Jul 16, 2019
2 parents e75c7f9 + 374ce0d commit 73e8e36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions mslice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
_update_overplot_checklist, _update_legend)
from mslice.models.workspacemanager.workspace_provider import get_workspace_handle
from mslice.plotting.globalfiguremanager import GlobalFigureManager
from mslice.util.qt.qapp import call_in_qapp_thread
from mslice.workspace.histogram_workspace import HistogramWorkspace

# This is not compatible with mslice as we use a separate
Expand Down Expand Up @@ -75,6 +76,7 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
elif axis == 'y':
plot_handler.manager._ygrid = b

@call_in_qapp_thread
def set_waterfall(self, isWaterfall=True, x_offset=None, y_offset=None):
""" Change the plot to/from a waterfall """
from mslice.plotting.plot_window.cut_plot import CutPlot
Expand Down
11 changes: 5 additions & 6 deletions mslice/plotting/plot_window/plot_figure_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import six
from mslice.util.qt.QtCore import Qt
from mslice.util.qt import QtCore, QtGui, QtWidgets
from mslice.util.qt.qapp import create_qapp_if_required, QAppThreadCall
from mslice.util.qt.qapp import create_qapp_if_required, call_in_qapp_thread
from mslice.models.workspacemanager.file_io import get_save_directory
from mslice.models.workspacemanager.workspace_algorithms import save_workspaces
from mslice.plotting.plot_window.plot_window import PlotWindow
Expand Down Expand Up @@ -51,12 +51,11 @@ def __init__(self, number, current_figs):

self.window.raise_()

@call_in_qapp_thread
def show(self):
def _show():
self.window.show()
self.window.activateWindow()
self.window.raise_()
QAppThreadCall(_show)()
self.window.show()
self.window.activateWindow()
self.window.raise_()

def window_closing(self):
if self.plot_handler is not None:
Expand Down
13 changes: 13 additions & 0 deletions mslice/util/qt/qapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# This file is part of the mantid workbench.
#
from __future__ import (absolute_import, unicode_literals)
from functools import wraps
import sys

from mslice.util.qt.QtCore import Qt, QMetaObject, QObject, QThread, Slot
Expand Down Expand Up @@ -75,6 +76,18 @@ def _store_function_args(self, *args, **kwargs):
self._exc_info = None


def call_in_qapp_thread(func):
"""
Decorator to force a call onto the QApplication thread
:param func: The function to decorate
:return The wrapped function
"""
@wraps(func)
def wrapper(*args, **kwargs):
return QAppThreadCall(func)(*args, **kwargs)

return wrapper

def create_qapp_if_required():
"""
Create a qapplication for non gui plots
Expand Down

0 comments on commit 73e8e36

Please sign in to comment.