2014-05-18 21:57:16 +00:00
|
|
|
#import PySide
|
|
|
|
import pyqtgraph as pg
|
2015-07-31 18:51:34 +00:00
|
|
|
import pytest
|
2014-05-18 21:57:16 +00:00
|
|
|
|
2015-07-31 18:39:07 +00:00
|
|
|
app = pg.mkQApp()
|
2015-07-31 18:39:32 +00:00
|
|
|
qtest = pg.Qt.QtTest.QTest
|
2015-07-31 18:42:31 +00:00
|
|
|
QRectF = pg.QtCore.QRectF
|
2014-05-18 21:57:16 +00:00
|
|
|
|
2015-07-31 18:39:32 +00:00
|
|
|
def assertMapping(vb, r1, r2):
|
|
|
|
assert vb.mapFromView(r1.topLeft()) == r2.topLeft()
|
|
|
|
assert vb.mapFromView(r1.bottomLeft()) == r2.bottomLeft()
|
|
|
|
assert vb.mapFromView(r1.topRight()) == r2.topRight()
|
|
|
|
assert vb.mapFromView(r1.bottomRight()) == r2.bottomRight()
|
2015-07-31 14:15:02 +00:00
|
|
|
|
2015-07-31 18:42:31 +00:00
|
|
|
def init_viewbox():
|
|
|
|
"""Helper function to init the ViewBox
|
|
|
|
"""
|
|
|
|
global win, vb
|
2015-07-31 18:39:32 +00:00
|
|
|
|
2020-11-21 08:02:32 +00:00
|
|
|
win = pg.GraphicsLayoutWidget()
|
2015-07-31 18:39:32 +00:00
|
|
|
win.ci.layout.setContentsMargins(0,0,0,0)
|
|
|
|
win.resize(200, 200)
|
|
|
|
win.show()
|
|
|
|
vb = win.addViewBox()
|
|
|
|
|
|
|
|
# set range before viewbox is shown
|
|
|
|
vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0)
|
|
|
|
|
|
|
|
# required to make mapFromView work properly.
|
2021-02-04 03:27:17 +00:00
|
|
|
qtest.qWaitForWindowExposed(win)
|
2015-07-31 18:39:32 +00:00
|
|
|
|
|
|
|
g = pg.GridItem()
|
|
|
|
vb.addItem(g)
|
2014-05-18 21:57:16 +00:00
|
|
|
app.processEvents()
|
2015-07-31 18:39:32 +00:00
|
|
|
|
2015-07-31 18:42:31 +00:00
|
|
|
def test_ViewBox():
|
|
|
|
init_viewbox()
|
|
|
|
|
2014-05-18 21:57:16 +00:00
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
2015-07-31 14:44:28 +00:00
|
|
|
view1 = QRectF(0, 0, 10, 10)
|
2014-05-18 21:57:16 +00:00
|
|
|
size1 = QRectF(0, h, w, -h)
|
2015-07-31 18:39:32 +00:00
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# test resize
|
|
|
|
win.resize(400, 400)
|
|
|
|
app.processEvents()
|
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
2015-07-31 14:44:28 +00:00
|
|
|
size1 = QRectF(0, h, w, -h)
|
2015-07-31 18:39:32 +00:00
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# now lock aspect
|
2015-07-31 18:39:07 +00:00
|
|
|
vb.setAspectLocked()
|
2015-07-31 18:39:32 +00:00
|
|
|
|
2014-05-18 21:57:16 +00:00
|
|
|
# test wide resize
|
|
|
|
win.resize(800, 400)
|
|
|
|
app.processEvents()
|
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
|
|
|
view1 = QRectF(-5, 0, 20, 10)
|
|
|
|
size1 = QRectF(0, h, w, -h)
|
2015-07-31 18:39:32 +00:00
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
2014-05-18 21:57:16 +00:00
|
|
|
# test tall resize
|
2019-07-02 02:00:18 +00:00
|
|
|
win.resize(200, 400)
|
2015-07-31 14:44:28 +00:00
|
|
|
app.processEvents()
|
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
|
|
|
view1 = QRectF(0, -5, 10, 20)
|
|
|
|
size1 = QRectF(0, h, w, -h)
|
2015-07-31 18:39:32 +00:00
|
|
|
assertMapping(vb, view1, size1)
|
2015-07-31 14:44:28 +00:00
|
|
|
|
2019-09-27 20:37:40 +00:00
|
|
|
win.close()
|
|
|
|
|
2015-07-31 14:44:28 +00:00
|
|
|
|
2019-11-06 09:59:51 +00:00
|
|
|
def test_ViewBox_setMenuEnabled():
|
|
|
|
init_viewbox()
|
|
|
|
vb.setMenuEnabled(True)
|
|
|
|
assert vb.menu is not None
|
|
|
|
vb.setMenuEnabled(False)
|
|
|
|
assert vb.menu is None
|
|
|
|
|
|
|
|
|
2020-11-21 08:02:32 +00:00
|
|
|
|
2015-07-31 18:48:26 +00:00
|
|
|
skipreason = "Skipping this test until someone has time to fix it."
|
|
|
|
@pytest.mark.skipif(True, reason=skipreason)
|
2015-07-31 18:39:32 +00:00
|
|
|
def test_limits_and_resize():
|
2015-07-31 18:42:31 +00:00
|
|
|
init_viewbox()
|
|
|
|
|
2015-07-31 18:39:32 +00:00
|
|
|
# now lock aspect
|
2015-07-31 17:31:54 +00:00
|
|
|
vb.setAspectLocked()
|
2015-07-31 18:39:32 +00:00
|
|
|
# test limits + resize (aspect ratio constraint has priority over limits
|
|
|
|
win.resize(400, 400)
|
|
|
|
app.processEvents()
|
|
|
|
vb.setLimits(xMin=0, xMax=10, yMin=0, yMax=10)
|
2015-07-31 17:31:54 +00:00
|
|
|
win.resize(800, 400)
|
|
|
|
app.processEvents()
|
2015-07-31 18:39:32 +00:00
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
|
|
|
view1 = QRectF(-5, 0, 20, 10)
|
|
|
|
size1 = QRectF(0, h, w, -h)
|
|
|
|
assertMapping(vb, view1, size1)
|