Skip to content

Commit

Permalink
[gui] use Py.Qt shim
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrave committed Apr 27, 2017
1 parent 1268798 commit 5a5a168
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion dependencies.py
Expand Up @@ -4,7 +4,7 @@
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

tests_require = ['pytest', 'pytest-cov']
install_requires = ['cython>=0.20.1', 'numpy>=1.8.1', 'scipy>=0.13.3', 'Sphinx>=1.4.0', 'docopt']
install_requires = ['cython>=0.20.1', 'numpy>=1.8.1', 'scipy>=0.13.3', 'Sphinx>=1.4.0', 'docopt', 'Qt.py']
setup_requires = ['pytest-runner', 'cython>=0.20.1', 'numpy>=1.8.1']
install_suggests = {'ipython>=3.0': 'an enhanced interactive python shell',
'ipyparallel': 'required for pymor.parallel.ipython',
Expand Down
18 changes: 8 additions & 10 deletions src/pymor/core/config.py
Expand Up @@ -15,13 +15,6 @@ def _get_fenics_version():
return version


def _get_matplotlib_version():
import matplotlib
# matplotlib's default is to use PyQt for Qt4 bindings. However, we use PySide ..
matplotlib.rcParams['backend.qt4'] = 'PySide'
return matplotlib.__version__


def _get_ipython_version():
try:
import ipyparallel
Expand All @@ -31,21 +24,26 @@ def _get_ipython_version():
return getattr(IPython.parallel, '__version__', True)


def _get_qt_version():
import Qt
return Qt.__binding__ + ' ' + Qt.__binding_version__


_PACKAGES = {
'CYTHON': lambda: import_module('cython').__version__,
'DEALII': lambda: import_module('pydealii'),
'DOCOPT': lambda: import_module('docopt').__version__,
'FENICS': _get_fenics_version,
'GL': lambda: import_module('OpenGL.GL') and import_module('OpenGL').__version__,
'IPYTHON': _get_ipython_version,
'MATPLOTLIB': _get_matplotlib_version,
'MATPLOTLIB': lambda: import_module('matplotlib').__version__,
'MPI': lambda: import_module('mpi4py.MPI') and import_module('mpi4py').__version__,
'NUMPY': lambda: import_module('numpy').__version__,
'PYAMG': lambda: import_module('pyamg.version').full_version,
'PYSIDE': lambda: import_module('PySide.QtGui') and import_module('PySide.QtCore').__version__,
'PYTEST': lambda: import_module('pytest').__version__,
'PYVTK': lambda: bool(import_module('evtk')),
'QTOPENGL': lambda: bool(import_module('PySide.QtOpenGL')),
'QT': _get_qt_version,
'QTOPENGL': lambda: bool(import_module('Qt.QtOpenGL')),
'SCIPY': lambda: import_module('scipy').__version__,
'SCIPY_LSMR': lambda: hasattr(import_module('scipy.sparse.linalg'), 'lsmr'),
'SPHINX': lambda: import_module('sphinx').__version__,
Expand Down
6 changes: 3 additions & 3 deletions src/pymor/core/exceptions.py
Expand Up @@ -49,8 +49,8 @@ def __init__(self, op):
self.op = op


class PySideMissing(ImportError):
"""Raise me where having importable PySide is non-optional"""
class QtMissing(ImportError):
"""Raise me where having importable Qt bindings is non-optional"""
def __init__(self, msg=None):
msg = msg or 'cannot visualize: import of PySide failed'
msg = msg or 'cannot visualize: import of Qt bindings failed'
super().__init__(msg)
7 changes: 4 additions & 3 deletions src/pymor/gui/gl.py
Expand Up @@ -16,10 +16,11 @@
from pymor.core.config import config


if config.HAVE_PYSIDE and config.HAVE_QTOPENGL and config.HAVE_GL:
if config.HAVE_QT and config.HAVE_QTOPENGL and config.HAVE_GL:
import OpenGL.GL as gl
from PySide.QtGui import QSizePolicy, QPainter, QFontMetrics
from PySide.QtOpenGL import QGLWidget
from Qt.QtWidgets import QSizePolicy
from Qt.QtGui import QPainter, QFontMetrics
from Qt.QtOpenGL import QGLWidget
from ctypes import c_void_p

from pymor.grids.constructions import flatten_grid
Expand Down
4 changes: 2 additions & 2 deletions src/pymor/gui/matplotlib.py
Expand Up @@ -14,8 +14,8 @@
from pymor.core.config import config


if config.HAVE_PYSIDE and config.HAVE_MATPLOTLIB:
from PySide.QtGui import QSizePolicy
if config.HAVE_QT and config.HAVE_MATPLOTLIB:
from Qt.QtWidgets import QSizePolicy

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

Expand Down
22 changes: 11 additions & 11 deletions src/pymor/gui/qt.py
Expand Up @@ -3,8 +3,8 @@
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

""" This module provides a few methods and classes for visualizing data
associated to grids. We use the `PySide <http://www.pyside.org>`_ bindings
for the `Qt <http://www.qt-project.org>`_ widget toolkit for the GUI.
associated to grids. We use the the `Qt <http://www.qt-project.org>`_ widget
toolkit for the GUI.
"""

import math as m
Expand All @@ -20,7 +20,7 @@
from pymor.core.defaults import defaults
from pymor.core.interfaces import BasicInterface
from pymor.core.logger import getLogger
from pymor.core.exceptions import PySideMissing
from pymor.core.exceptions import QtMissing
from pymor.grids.oned import OnedGrid
from pymor.grids.referenceelements import triangle, square
from pymor.gui.gl import GLPatchWidget, ColorBarWidget
Expand All @@ -29,10 +29,10 @@
from pymor.vectorarrays.interfaces import VectorArrayInterface
from pymor.vectorarrays.numpy import NumpyVectorArray, NumpyVectorSpace

if config.HAVE_PYSIDE:
from PySide.QtGui import (QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QSlider, QApplication, QLCDNumber,
if config.HAVE_QT:
from Qt.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QSlider, QApplication, QLCDNumber,
QAction, QStyle, QToolBar, QLabel, QFileDialog, QMessageBox)
from PySide.QtCore import Qt, QCoreApplication, QTimer
from Qt.QtCore import Qt, QCoreApplication, QTimer

class PlotMainWindow(QWidget):
"""Base class for plot main windows."""
Expand Down Expand Up @@ -245,8 +245,8 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
The number of columns in the visualizer GUI in case multiple plots are displayed
at the same time.
"""
if not config.HAVE_PYSIDE:
raise PySideMissing()
if not config.HAVE_QT:
raise QtMissing()

assert backend in {'gl', 'matplotlib'}

Expand All @@ -257,7 +257,7 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
backend = 'matplotlib'
elif not config.HAVE_QTOPENGL:
logger = getLogger('pymor.gui.qt.visualize_patch')
logger.warn('import of PySide.QtOpenGL failed, falling back to matplotlib; rendering will be slow')
logger.warn('import of Qt.QtOpenGL failed, falling back to matplotlib; rendering will be slow')
backend = 'matplotlib'
if backend == 'matplotlib' and not config.HAVE_MATPLOTLIB:
raise ImportError('cannot visualize: import of matplotlib failed')
Expand Down Expand Up @@ -412,8 +412,8 @@ def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_
block
If `True`, block execution until the plot window is closed.
"""
if not config.HAVE_PYSIDE:
raise PySideMissing()
if not config.HAVE_QT:
raise QtMissing()
if not config.HAVE_MATPLOTLIB:
raise ImportError('cannot visualize: import of matplotlib failed')

Expand Down
6 changes: 3 additions & 3 deletions src/pymordemos/thermalblock_gui.py
Expand Up @@ -41,11 +41,11 @@

OpenGL.ERROR_ON_COPY = True

from pymor.core.exceptions import PySideMissing
from pymor.core.exceptions import QtMissing
try:
from PySide import QtGui
from Qt import QtGui
except ImportError as e:
raise PySideMissing()
raise QtMissing()
from pymor.algorithms.basisextension import gram_schmidt_basis_extension
from pymor.algorithms.greedy import greedy
from pymor.analyticalproblems.thermalblock import thermal_block_problem
Expand Down
6 changes: 3 additions & 3 deletions src/pymortests/demos.py
Expand Up @@ -11,7 +11,7 @@
import shutil

from pymortests.base import runmodule, check_results
from pymor.core.exceptions import PySideMissing
from pymor.core.exceptions import QtMissing
from pymor.gui.qt import stop_gui_processes


Expand Down Expand Up @@ -125,8 +125,8 @@ def nop(*args, **kwargs):
result = None
try:
result = demo()
except PySideMissing:
pytest.xfail("PySide missing")
except QtMissing:
pytest.xfail("Qt missing")
finally:
stop_gui_processes()
from pymor.parallel.default import _cleanup
Expand Down
6 changes: 3 additions & 3 deletions src/pymortests/grid.py
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import pytest

from pymor.core.exceptions import PySideMissing
from pymor.core.exceptions import QtMissing
from pymor.gui.qt import stop_gui_processes
from pymortests.fixtures.grid import grid, grids_with_visualize
from pymortests.pickling import assert_picklable_without_dumps_function
Expand Down Expand Up @@ -446,7 +446,7 @@ def nop(*args, **kwargs):
g = grids_with_visualize
U = np.ones(g.size(g.dim))
g.visualize(U, g.dim)
except PySideMissing:
pytest.xfail("PySide missing")
except QtMissing:
pytest.xfail("Qt missing")
finally:
stop_gui_processes()
6 changes: 3 additions & 3 deletions src/pymortests/gui.py
Expand Up @@ -12,7 +12,7 @@
from pymor.discretizers.cg import discretize_stationary_cg
from pymor.domaindiscretizers.default import discretize_domain_default
from pymor.grids.rect import RectGrid
from pymor.core.exceptions import PySideMissing
from pymor.core.exceptions import QtMissing

from pymortests.base import runmodule
from pymor.domaindescriptions.basic import RectDomain, LineDomain
Expand All @@ -37,8 +37,8 @@ def test_visualize_patch(backend_gridtype):
U = discretization.solve()
try:
visualize_patch(data['grid'], U=U, backend=backend)
except PySideMissing as ie:
pytest.xfail("PySide missing")
except QtMissing as ie:
pytest.xfail("Qt missing")
finally:
stop_gui_processes()

Expand Down

0 comments on commit 5a5a168

Please sign in to comment.