Skip to content

Commit

Permalink
Merge pull request #1230 from astrofrog/remove-custom-qmessagebox
Browse files Browse the repository at this point in the history
Don't use custom QMessageBox subclass
  • Loading branch information
astrofrog committed Feb 9, 2017
2 parents 113117b + 4d89263 commit 2283205
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 97 deletions.
21 changes: 10 additions & 11 deletions glue/app/qt/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from glue.viewers.scatter.qt import ScatterWidget
from glue.utils import nonpartial
from glue.utils.qt import (pick_class, GlueTabBar,
QMessageBoxPatched as QMessageBox,
set_cursor_cm, messagebox_on_error, load_ui)

from glue.app.qt.feedback import submit_bug_report, submit_feedback
Expand Down Expand Up @@ -308,13 +307,13 @@ def close_tab(self, index):
return

if not os.environ.get('GLUE_TESTING'):
buttons = QMessageBox.Ok | QMessageBox.Cancel
dialog = QMessageBox.warning(
buttons = QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
dialog = QtWidgets.QMessageBox.warning(
self, "Confirm Close",
"Are you sure you want to close this tab? "
"This will close all data viewers in the tab.",
buttons=buttons, defaultButton=QMessageBox.Cancel)
if not dialog == QMessageBox.Ok:
buttons=buttons, defaultButton=QtWidgets.QMessageBox.Cancel)
if not dialog == QtWidgets.QMessageBox.Ok:
return

w = self.tab_widget.widget(index)
Expand Down Expand Up @@ -746,13 +745,13 @@ def _reset_session(self, show=True):
"""

if not os.environ.get('GLUE_TESTING'):
buttons = QMessageBox.Ok | QMessageBox.Cancel
dialog = QMessageBox.warning(
buttons = QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
dialog = QtWidgets.QMessageBox.warning(
self, "Confirm Close",
"Are you sure you want to reset the session? "
"This will close all datasets, subsets, and data viewers",
buttons=buttons, defaultButton=QMessageBox.Cancel)
if not dialog == QMessageBox.Ok:
buttons=buttons, defaultButton=QtWidgets.QMessageBox.Cancel)
if not dialog == QtWidgets.QMessageBox.Ok:
return

ga = GlueApplication()
Expand Down Expand Up @@ -831,7 +830,7 @@ def _setup_terminal_error_dialog(self, exception):
"\nReason:\n%s" % exception)

def show_msg():
mb = QMessageBox(QMessageBox.Critical,
mb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical,
title, msg)
mb.setDetailedText(self._terminal_exception)
mb.exec_()
Expand Down Expand Up @@ -936,7 +935,7 @@ def report_error(self, message, detail):
:param detail: A longer description
:type detail: str
"""
qmb = QMessageBox(QMessageBox.Critical, "Error", message)
qmb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "Error", message)
qmb.setDetailedText(detail)
qmb.resize(400, qmb.size().height())
qmb.exec_()
Expand Down
11 changes: 5 additions & 6 deletions glue/app/qt/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QtPluginManager(object):
def __init__(self, installed=None):

self.ui = load_ui('plugin_manager.ui', None,
directory=os.path.dirname(__file__))
directory=os.path.dirname(__file__))

self.ui.cancel.clicked.connect(self.reject)
self.ui.confirm.clicked.connect(self.finalize)
Expand All @@ -39,7 +39,7 @@ def update_list(self, installed=None):

for plugin in sorted(config.plugins):
check = QtWidgets.QTreeWidgetItem(self.ui.tree.invisibleRootItem(),
["", plugin])
["", plugin])
check.setFlags(check.flags() | Qt.ItemIsUserCheckable)
if config.plugins[plugin]:
check.setCheckState(0, Qt.Checked)
Expand All @@ -65,10 +65,9 @@ def finalize(self):
except Exception:
import traceback
detail = str(traceback.format_exc())
from glue.utils.qt import QMessageBoxPatched as QMessageBox
message = QMessageBox(QMessageBox.Critical,
"Error",
"Could not save plugin configuration")
message = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical,
"Error",
"Could not save plugin configuration")
message.setDetailedText(detail)
message.exec_()
return
Expand Down
2 changes: 1 addition & 1 deletion glue/app/qt/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_choose_save_session_ioerror(self):
with patch(mock_open) as op:
op.side_effect = IOError
fd.return_value = '/tmp/junk', '/tmp/junk'
with patch('glue.app.qt.application.QMessageBox') as mb:
with patch('qtpy.QtWidgets.QMessageBox') as mb:
self.app._choose_save_session()
assert mb.call_count == 1

Expand Down
5 changes: 3 additions & 2 deletions glue/app/qt/tests/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from mock import patch

from qtpy import QtWidgets

from glue import _plugin_helpers as ph
from glue.main import load_plugins
from glue.utils.qt import QMessageBoxPatched

from ..plugin_manager import QtPluginManager

Expand Down Expand Up @@ -68,7 +69,7 @@ def test_permission_fail(tmpdir):

config2 = ph.PluginConfig.load()

with patch.object(QMessageBoxPatched, 'exec_', return_value=None) as qmb:
with patch.object(QtWidgets.QMessageBox, 'exec_', return_value=None) as qmb:
w = QtPluginManager()
w.finalize()

Expand Down
8 changes: 4 additions & 4 deletions glue/dialogs/data_wizard/qt/data_wizard_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qtpy.QtCore import Qt
from qtpy import QtWidgets
from glue.utils.qt import QMessageBoxPatched as QMessageBox, set_cursor_cm
from glue.utils.qt import set_cursor_cm

__all__ = ['data_wizard', 'GlueDataDialog']

Expand All @@ -16,14 +16,14 @@ def data_wizard():
"""
def report_error(error, factory, curfile):
import traceback
retry = QMessageBox.Retry
cancel = QMessageBox.Cancel
retry = QtWidgets.QMessageBox.Retry
cancel = QtWidgets.QMessageBox.Cancel
buttons = retry | cancel
detail = traceback.format_exc()
msg = "\n".join(["Could not load %s (wrong load method?)" % curfile,
"File load method: %s" % factory.label])
detail = "\n\n".join(["Error message: %s" % error, detail])
mb = QMessageBox(QMessageBox.Critical, "Data Load Error", msg)
mb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "Data Load Error", msg)
mb.setDetailedText(detail)
mb.setDefaultButton(cancel)
mb.setStandardButtons(buttons)
Expand Down
4 changes: 2 additions & 2 deletions glue/dialogs/data_wizard/qt/tests/test_data_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ def test_data_wizard_error_cancel():
"""Returns empty list of error generated and then canceled"""
with patch('glue.dialogs.data_wizard.qt.data_wizard_dialog.GlueDataDialog') as mock:
mock().load_data.side_effect = Exception
with patch('glue.dialogs.data_wizard.qt.data_wizard_dialog.QMessageBox') as qmb:
with patch('qtpy.QtWidgets.QMessageBox') as qmb:
qmb().exec_.return_value = 0
assert data_wizard() == []
assert data_wizard() == []
4 changes: 2 additions & 2 deletions glue/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def test_die_on_error_exception():
"""Decorator should spawn a QMessageBox and exit"""
with pytest.raises(SystemExit):
with patch('glue.utils.qt.QMessageBoxPatched') as qmb:
with patch('qtpy.QtWidgets.QMessageBox') as qmb:
@die_on_error('test_msg')
def test():
raise Exception()
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_exec_real(tmpdir):
filename = tmpdir.join('test.py').strpath
with open(filename, 'w') as f:
f.write('a = 1')
with patch('glue.utils.qt.QMessageBoxPatched') as qmb:
with patch('qtpy.QtWidgets.QMessageBox') as qmb:
with patch('sys.exit') as exit:
main('glue -x {0}'.format(os.path.abspath(filename)).split())
assert exit.called_once_with(0)
Expand Down
1 change: 0 additions & 1 deletion glue/utils/qt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import, division, print_function

from .autocomplete_widget import *
from .qmessagebox_widget import *
from .dialogs import *
from .colors import *
from .decorators import *
Expand Down
12 changes: 8 additions & 4 deletions glue/utils/qt/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def set_cursor_cm(shape):

def messagebox_on_error(msg):
"""Decorator that catches exceptions and displays an error message"""
from glue.utils.qt import QMessageBoxPatched as QMessageBox # Must be here

from qtpy import QtWidgets # Must be here
from qtpy.QtCore import Qt

def decorator(func):
@wraps(func)
Expand All @@ -54,9 +56,10 @@ def wrapper(*args, **kwargs):
except Exception as e:
m = "%s\n%s" % (msg, e.args[0])
detail = str(traceback.format_exc())
qmb = QMessageBox(QMessageBox.Critical, "Error", m)
qmb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "Error", m)
qmb.setDetailedText(detail)
qmb.resize(400, qmb.size().height())
qmb.setTextInteractionFlags(Qt.TextSelectableByMouse)
qmb.exec_()
return wrapper

Expand All @@ -65,7 +68,8 @@ def wrapper(*args, **kwargs):

def die_on_error(msg):
"""Decorator that catches errors, displays a popup message, and quits"""
from glue.utils.qt import QMessageBoxPatched as QMessageBox

from qtpy import QtWidgets # Must be here

def decorator(func):
def wrapper(*args, **kwargs):
Expand All @@ -82,7 +86,7 @@ def wrapper(*args, **kwargs):
detail = "Full message:\n\n%s\n\n%s" % (m, detail)
m = m[:500] + '...'

qmb = QMessageBox(QMessageBox.Critical, "Error", m)
qmb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical, "Error", m)
qmb.setDetailedText(detail)
qmb.show()
qmb.raise_()
Expand Down
45 changes: 0 additions & 45 deletions glue/utils/qt/qmessagebox_widget.py

This file was deleted.

19 changes: 0 additions & 19 deletions glue/utils/qt/tests/test_qmessagebox_widget.py

This file was deleted.

0 comments on commit 2283205

Please sign in to comment.