Added some ViewBox unit tests, fixed minor API bug
This commit is contained in:
parent
88c55c9f98
commit
ab411012f8
@ -33,6 +33,10 @@ else:
|
||||
|
||||
if USE_PYSIDE:
|
||||
from PySide import QtGui, QtCore, QtOpenGL, QtSvg
|
||||
try:
|
||||
from PySide import QtTest
|
||||
except ImportError:
|
||||
pass
|
||||
import PySide
|
||||
try:
|
||||
from PySide import shiboken
|
||||
@ -106,6 +110,10 @@ else:
|
||||
from PyQt4 import QtOpenGL
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
from PyQt4 import QtTest
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
import sip
|
||||
|
@ -671,7 +671,10 @@ class ViewBox(GraphicsWidget):
|
||||
Added in version 0.9.9
|
||||
"""
|
||||
update = False
|
||||
|
||||
allowed = ['xMin', 'xMax', 'yMin', 'yMax', 'minXRange', 'maxXRange', 'minYRange', 'maxYRange']
|
||||
for kwd in kwds:
|
||||
if kwd not in allowed:
|
||||
raise ValueError("Invalid keyword argument '%s'." % kwd)
|
||||
#for kwd in ['xLimits', 'yLimits', 'minRange', 'maxRange']:
|
||||
#if kwd in kwds and self.state['limits'][kwd] != kwds[kwd]:
|
||||
#self.state['limits'][kwd] = kwds[kwd]
|
||||
@ -1511,7 +1514,8 @@ class ViewBox(GraphicsWidget):
|
||||
if dx != 0:
|
||||
changed[0] = True
|
||||
viewRange[0] = [self.state['targetRange'][0][0] - dx, self.state['targetRange'][0][1] + dx]
|
||||
|
||||
|
||||
|
||||
# ----------- Make corrections for view limits -----------
|
||||
|
||||
limits = (self.state['limits']['xLimits'], self.state['limits']['yLimits'])
|
||||
@ -1562,7 +1566,7 @@ class ViewBox(GraphicsWidget):
|
||||
changed[axis] = True
|
||||
|
||||
#print "after applying edge limits:", viewRange[axis]
|
||||
|
||||
|
||||
changed = [(viewRange[i][0] != self.state['viewRange'][i][0]) or (viewRange[i][1] != self.state['viewRange'][i][1]) for i in (0,1)]
|
||||
self.state['viewRange'] = viewRange
|
||||
|
||||
|
85
pyqtgraph/graphicsItems/ViewBox/tests/test_ViewBox.py
Normal file
85
pyqtgraph/graphicsItems/ViewBox/tests/test_ViewBox.py
Normal file
@ -0,0 +1,85 @@
|
||||
#import PySide
|
||||
import pyqtgraph as pg
|
||||
|
||||
app = pg.mkQApp()
|
||||
qtest = pg.Qt.QtTest.QTest
|
||||
|
||||
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()
|
||||
|
||||
def test_ViewBox():
|
||||
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()
|
||||
|
||||
vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0)
|
||||
|
||||
# required to make mapFromView work properly.
|
||||
qtest.qWaitForWindowShown(win)
|
||||
vb.update()
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
# 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)
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import user,sys
|
||||
test_ViewBox()
|
||||
|
Loading…
Reference in New Issue
Block a user