2014-05-18 21:57:16 +00:00
|
|
|
#import PySide
|
|
|
|
import pyqtgraph as pg
|
2015-07-17 18:49:01 +00:00
|
|
|
import pytest
|
2014-05-18 21:57:16 +00:00
|
|
|
|
|
|
|
app = pg.mkQApp()
|
|
|
|
|
|
|
|
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-18 13:38:34 +00:00
|
|
|
|
2015-07-17 18:49:01 +00:00
|
|
|
# TODO fix this test!
|
2015-07-18 13:38:34 +00:00
|
|
|
# @pytest.mark.skipif(True or pg.Qt.USE_PYSIDE,
|
|
|
|
# reason=('unclear why test is failing. skipping until '
|
|
|
|
# 'someone has time to fix it'))
|
|
|
|
@pytest.mark.skipif(pg.Qt.USE_PYSIDE, reason="pyside does not have qTest")
|
2014-05-18 21:57:16 +00:00
|
|
|
def test_ViewBox():
|
2015-07-18 13:38:34 +00:00
|
|
|
qtest = pg.Qt.QtTest.QTest
|
2014-05-18 21:57:16 +00:00
|
|
|
global app, win, vb
|
|
|
|
QRectF = pg.QtCore.QRectF
|
|
|
|
|
|
|
|
win = pg.GraphicsWindow()
|
|
|
|
win.ci.layout.setContentsMargins(0,0,0,0)
|
|
|
|
win.resize(200, 200)
|
|
|
|
win.show()
|
|
|
|
vb = win.addViewBox()
|
|
|
|
|
2014-08-07 13:11:34 +00:00
|
|
|
# set range before viewbox is shown
|
2014-05-18 21:57:16 +00:00
|
|
|
vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0)
|
|
|
|
|
|
|
|
# required to make mapFromView work properly.
|
|
|
|
qtest.qWaitForWindowShown(win)
|
|
|
|
|
|
|
|
g = pg.GridItem()
|
|
|
|
vb.addItem(g)
|
|
|
|
|
|
|
|
app.processEvents()
|
|
|
|
|
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
|
|
|
view1 = QRectF(0, 0, 10, 10)
|
|
|
|
size1 = QRectF(0, h, w, -h)
|
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# test resize
|
|
|
|
win.resize(400, 400)
|
|
|
|
app.processEvents()
|
|
|
|
w = vb.geometry().width()
|
|
|
|
h = vb.geometry().height()
|
|
|
|
size1 = QRectF(0, h, w, -h)
|
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# now lock aspect
|
|
|
|
vb.setAspectLocked()
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
assertMapping(vb, view1, size1)
|
|
|
|
|
|
|
|
# test tall resize
|
2015-07-20 14:26:12 +00:00
|
|
|
# win.resize(400, 800)
|
|
|
|
# app.processEvents()
|
|
|
|
# w = vb.geometry().width()
|
|
|
|
# h = vb.geometry().height()
|
|
|
|
# view1 = QRectF(0, -5, 10, 20)
|
|
|
|
# size1 = QRectF(0, h, w, -h)
|
|
|
|
# assertMapping(vb, view1, size1)
|
2014-05-18 21:57:16 +00:00
|
|
|
|
|
|
|
# test limits + resize (aspect ratio constraint has priority over limits
|
2015-07-20 14:26:12 +00:00
|
|
|
# win.resize(400, 400)
|
|
|
|
# app.processEvents()
|
|
|
|
# vb.setLimits(xMin=0, xMax=10, yMin=0, yMax=10)
|
|
|
|
# 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)
|
|
|
|
# assertMapping(vb, view1, size1)
|
2014-05-18 21:57:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import user,sys
|
|
|
|
test_ViewBox()
|