Skip to content

Commit

Permalink
Merge pull request #40 from neutrons/fix_error_message_crash
Browse files Browse the repository at this point in the history
Fix crash with error dialog
  • Loading branch information
AndreiSavici committed Mar 28, 2023
2 parents 3acc2a4 + c028aa8 commit 47139cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/shiver/views/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
QHBoxLayout,
QErrorMessage,
)
from qtpy.QtCore import Signal

from .loading_buttons import LoadingButtons
from .histogram_parameters import HistogramParameter
Expand All @@ -13,6 +14,8 @@
class Histogram(QWidget):
"""Histogram widget"""

error_message_signal = Signal(str)

def __init__(self, parent=None):
super().__init__(parent)

Expand All @@ -28,9 +31,17 @@ def __init__(self, parent=None):
layout.addWidget(self.histogram_workspaces)
self.setLayout(layout)

self.error_message_signal.connect(self._show_error_message)

def show_error_message(self, msg):
"""Will show a error dialog with the given message"""
error = QErrorMessage()
"""Will show a error dialog with the given message
This will emit a signal so that other threads can call this but have the GUI thread execute"""
self.error_message_signal.emit(msg)

def _show_error_message(self, msg):
"""Will show a error dialog with the given message from qt signal"""
error = QErrorMessage(self)
error.showMessage(msg)
error.exec_()

Expand Down
21 changes: 21 additions & 0 deletions tests/views/test_histogram.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""UI test for the histogram tab"""
import os
from qtpy.QtCore import QTimer
from qtpy.QtWidgets import QErrorMessage, QTextEdit
from mantid.simpleapi import ( # pylint: disable=no-name-in-module
LoadMD,
MakeSlice,
CreateSampleWorkspace,
)
from shiver import Shiver
from shiver.views.histogram import Histogram


def test_histogram(qtbot):
Expand Down Expand Up @@ -57,3 +60,21 @@ def test_histogram(qtbot):
histogram_list = shiver.main_window.histogram.histogram_workspaces.histogram_workspaces
assert histogram_list.count() == 1
assert histogram_list.item(0).text() == "line"


def test_msg_dialog(qtbot):
"""Test the error message dialog in the histogram widget"""
histo = Histogram()
qtbot.addWidget(histo)
histo.show()

def test_dialog():
dialog = histo.findChild(QErrorMessage)
text_edit = dialog.findChild(QTextEdit)
dialog.close()
text = text_edit.toPlainText()
assert text == "This is only a test!"

QTimer.singleShot(100, test_dialog)

histo.show_error_message("This is only a test!")

1 comment on commit 47139cc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for shiver-dev has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/conda-legacy-deploy/-/pipelines/358306"

Please sign in to comment.