2014-05-18 17:57:16 -04:00
|
|
|
#import PySide
|
|
|
|
import pyqtgraph as pg
|
2015-07-31 14:51:34 -04:00
|
|
|
import pytest
|
2014-05-18 17:57:16 -04:00
|
|
|
|
2015-07-31 14:39:07 -04:00
|
|
|
app = pg.mkQApp()
|
2015-07-31 14:39:32 -04:00
|
|
|
qtest = pg.Qt.QtTest.QTest
|
2015-07-31 14:42:31 -04:00
|
|
|
QRectF = pg.QtCore.QRectF
|
2014-05-18 17:57:16 -04:00
|
|
|
|
2015-07-31 14:39:32 -04: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 10:15:02 -04:00
|
|
|
|
2015-07-31 14:42:31 -04:00
|
|
|
def init_viewbox():
|
|
|
|
"""Helper function to init the ViewBox
|
|
|
|
"""
|
|
|
|
global win, vb
|
2015-07-31 14:39:32 -04:00
|
|
|
|
2020-11-21 00:02:32 -08:00
|
|
|
win = pg.GraphicsLayoutWidget()
|
2015-07-31 14:39:32 -04: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 11:27:17 +08:00
|
|
|
qtest.qWaitForWindowExposed(win)
|
2015-07-31 14:39:32 -04:00
|
|
|
|
|
|
|
g = pg.GridItem()
|
|
|
|
vb.addItem(g)
|
2014-05-18 17:57:16 -04:00
|
|
|
app.processEvents()
|
2015-07-31 14:39:32 -04:00
|
|
|
|
2015-07-31 14:42:31 -04:00
|
|
|
def test_ViewBox():
|
|
|
|
init_viewbox()
|
|
|
|
|
2014-05-18 17:57:16 -04:00
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
2015-07-31 10:44:28 -04:00
|
|
|
view1 = QRectF(0, 0, 10, 10)
|
2014-05-18 17:57:16 -04:00
|
|
|
size1 = QRectF(0, h, w, -h)
|
2015-07-31 14:39:32 -04:00
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# test resize
|
|
|
|
win.resize(400, 400)
|
|
|
|
app.processEvents()
|
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
2015-07-31 10:44:28 -04:00
|
|
|
size1 = QRectF(0, h, w, -h)
|
2015-07-31 14:39:32 -04:00
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# now lock aspect
|
2015-07-31 14:39:07 -04:00
|
|
|
vb.setAspectLocked()
|
2015-07-31 14:39:32 -04:00
|
|
|
|
2014-05-18 17:57:16 -04: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 14:39:32 -04:00
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
2014-05-18 17:57:16 -04:00
|
|
|
# test tall resize
|
2019-07-01 19:00:18 -07:00
|
|
|
win.resize(200, 400)
|
2015-07-31 10:44:28 -04: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 14:39:32 -04:00
|
|
|
assertMapping(vb, view1, size1)
|
2015-07-31 10:44:28 -04:00
|
|
|
|
2019-09-27 13:37:40 -07:00
|
|
|
win.close()
|
|
|
|
|
2015-07-31 10:44:28 -04:00
|
|
|
|
2019-11-06 10:59:51 +01: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 00:02:32 -08:00
|
|
|
|
2015-07-31 14:48:26 -04:00
|
|
|
skipreason = "Skipping this test until someone has time to fix it."
|
|
|
|
@pytest.mark.skipif(True, reason=skipreason)
|
2015-07-31 14:39:32 -04:00
|
|
|
def test_limits_and_resize():
|
2015-07-31 14:42:31 -04:00
|
|
|
init_viewbox()
|
|
|
|
|
2015-07-31 14:39:32 -04:00
|
|
|
# now lock aspect
|
2015-07-31 13:31:54 -04:00
|
|
|
vb.setAspectLocked()
|
2015-07-31 14:39:32 -04: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 13:31:54 -04:00
|
|
|
win.resize(800, 400)
|
|
|
|
app.processEvents()
|
2015-07-31 14:39:32 -04: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)
|