Skip to content

Commit

Permalink
[gui.qt/win32] don't use currently defunct GLPatchWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
renefritze authored and renemilk committed Jan 12, 2017
1 parent 7bbf0f3 commit 7af8ee0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/pymor/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ def _get_fenics_version():
return version


def _windows_platform():
return sys.platform == 'win32' or sys.platform == 'cygwin'


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'
if _windows_platform():
matplotlib.use('Qt4Agg')
return matplotlib.__version__


Expand Down
35 changes: 22 additions & 13 deletions src/pymor/gui/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import signal
import time

import sys

from pymor.core.config import config
from pymor.core.defaults import defaults
from pymor.core.interfaces import BasicInterface
Expand Down Expand Up @@ -177,23 +179,24 @@ def step_backward(self):
_launch_qt_app_pids = set()



def _doit():
try:
app = QApplication([])
except RuntimeError:
app = QCoreApplication.instance()
main_window = main_window_factory()
main_window.show()
app.exec_()

def _launch_qt_app(main_window_factory, block):
"""Wrapper to display plot in a separate process."""

def doit():
try:
app = QApplication([])
except RuntimeError:
app = QCoreApplication.instance()
main_window = main_window_factory()
main_window.show()
app.exec_()

import sys
if block and not getattr(sys, '_called_from_test', False):
doit()
_doit()
else:
p = multiprocessing.Process(target=doit)
p = multiprocessing.Process(target=_doit)
p.start()
_launch_qt_app_pids.add(p.pid)

Expand All @@ -202,14 +205,20 @@ def stop_gui_processes():
for p in multiprocessing.active_children():
if p.pid in _launch_qt_app_pids:
try:
os.kill(p.pid, signal.SIGKILL)
# kill is needed on linux, term on win32
sig = getattr(signal, 'SIGKILL', signal.SIGTERM)
os.kill(p.pid, sig)
except OSError:
pass


def _default_backend():
return 'gl' if 'win' not in sys.platform else 'matplotlib'


@defaults('backend', sid_ignore=('backend',))
def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None, legend=None,
separate_colorbars=False, rescale_colorbars=False, backend='gl', block=False, columns=2):
separate_colorbars=False, rescale_colorbars=False, backend=_default_backend(), block=False, columns=2):
"""Visualize scalar data associated to a two-dimensional |Grid| as a patch plot.
The grid's |ReferenceElement| must be the triangle or square. The data can either
Expand Down
15 changes: 11 additions & 4 deletions src/pymordemos/thermalblock_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import numpy as np
import OpenGL


OpenGL.ERROR_ON_COPY = True

from pymor.core.exceptions import PySideMissing
Expand All @@ -51,8 +52,10 @@
from pymor.analyticalproblems.thermalblock import thermal_block_problem
from pymor.discretizers.cg import discretize_stationary_cg
from pymor.gui.gl import ColorBarWidget, GLPatchWidget
from pymor.gui.matplotlib import MatplotlibPatchWidget
from pymor.reductors.coercive import reduce_coercive_simple
from pymor import gui
from pymor.core import config


PARAM_STEPS = 10
Expand Down Expand Up @@ -89,10 +92,14 @@ def __init__(self, parent, sim):
super().__init__(parent)
self.sim = sim
box = QtGui.QHBoxLayout()
self.solution = GLPatchWidget(self, self.sim.grid, vmin=0., vmax=0.8)
self.bar = ColorBarWidget(self, vmin=0., vmax=0.8)
box.addWidget(self.solution, 2)
box.addWidget(self.bar, 2)
if config._windows_platform():
self.solution = MatplotlibPatchWidget(self, self.sim.grid, vmin=0., vmax=0.8)
box.addWidget(self.solution, 2)
else:
self.solution = GLPatchWidget(self, self.sim.grid, vmin=0., vmax=0.8)
self.bar = ColorBarWidget(self, vmin=0., vmax=0.8)
box.addWidget(self.solution, 2)
box.addWidget(self.bar, 2)
self.param_panel = ParamRuler(self, sim)
box.addWidget(self.param_panel)
self.setLayout(box)
Expand Down

0 comments on commit 7af8ee0

Please sign in to comment.