2021-05-28 14:39:00 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
2020-10-13 16:06:34 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
|
2021-05-28 14:39:00 +00:00
|
|
|
app = pg.mkQApp()
|
2020-10-13 16:06:34 +00:00
|
|
|
|
|
|
|
def test_basics_graphics_view():
|
|
|
|
view = pg.GraphicsView()
|
|
|
|
background_role = view.backgroundRole()
|
2021-06-06 01:17:43 +00:00
|
|
|
assert background_role == QtGui.QPalette.ColorRole.Window
|
2020-10-13 16:06:34 +00:00
|
|
|
|
|
|
|
assert view.backgroundBrush().color() == QtGui.QColor(0, 0, 0, 255)
|
|
|
|
|
2021-06-06 01:17:43 +00:00
|
|
|
assert view.focusPolicy() == QtCore.Qt.FocusPolicy.StrongFocus
|
|
|
|
assert view.transformationAnchor() == QtGui.QGraphicsView.ViewportAnchor.NoAnchor
|
|
|
|
minimal_update = QtGui.QGraphicsView.ViewportUpdateMode.MinimalViewportUpdate
|
2020-10-13 16:06:34 +00:00
|
|
|
assert view.viewportUpdateMode() == minimal_update
|
2021-06-06 01:17:43 +00:00
|
|
|
assert view.frameShape() == QtGui.QFrame.Shape.NoFrame
|
2020-10-13 16:06:34 +00:00
|
|
|
assert view.hasMouseTracking() is True
|
|
|
|
|
|
|
|
# Default properties
|
|
|
|
# --------------------------------------
|
|
|
|
|
|
|
|
assert view.mouseEnabled is False
|
|
|
|
assert view.aspectLocked is False
|
|
|
|
assert view.autoPixelRange is True
|
|
|
|
assert view.scaleCenter is False
|
|
|
|
assert view.clickAccepted is False
|
|
|
|
assert view.centralWidget is not None
|
|
|
|
assert view._background == "default"
|
|
|
|
|
|
|
|
# Set background color
|
|
|
|
# --------------------------------------
|
|
|
|
view.setBackground("w")
|
|
|
|
assert view._background == "w"
|
2021-06-06 01:17:43 +00:00
|
|
|
assert view.backgroundBrush().color() == QtCore.Qt.GlobalColor.white
|
2020-10-13 16:06:34 +00:00
|
|
|
|
|
|
|
# Set anti aliasing
|
|
|
|
# --------------------------------------
|
2021-06-06 01:17:43 +00:00
|
|
|
aliasing = QtGui.QPainter.RenderHint.Antialiasing
|
2020-10-13 16:06:34 +00:00
|
|
|
# Default is set to `False`
|
2021-05-28 14:39:00 +00:00
|
|
|
assert view.renderHints() & aliasing != aliasing
|
2020-10-13 16:06:34 +00:00
|
|
|
view.setAntialiasing(True)
|
|
|
|
assert view.renderHints() & aliasing == aliasing
|
|
|
|
view.setAntialiasing(False)
|
2021-05-28 14:39:00 +00:00
|
|
|
assert view.renderHints() & aliasing != aliasing
|
2020-10-13 16:06:34 +00:00
|
|
|
|
|
|
|
# Enable mouse
|
|
|
|
# --------------------------------------
|
|
|
|
view.enableMouse(True)
|
|
|
|
assert view.mouseEnabled is True
|
|
|
|
assert view.autoPixelRange is False
|
|
|
|
view.enableMouse(False)
|
|
|
|
assert view.mouseEnabled is False
|
|
|
|
assert view.autoPixelRange is True
|
|
|
|
|
|
|
|
# Add and remove item
|
|
|
|
# --------------------------------------
|
|
|
|
central_item = QtGui.QGraphicsWidget()
|
|
|
|
view.setCentralItem(central_item)
|
|
|
|
assert view.centralWidget is central_item
|
|
|
|
# XXX: Removal of central item is not clear in code
|
|
|
|
scene = view.sceneObj
|
|
|
|
assert isinstance(scene, pg.GraphicsScene)
|
|
|
|
assert central_item in scene.items()
|
|
|
|
|
|
|
|
item = QtGui.QGraphicsWidget()
|
|
|
|
assert item not in scene.items()
|
|
|
|
view.addItem(item)
|
|
|
|
assert item in scene.items()
|
|
|
|
view.removeItem(item)
|
|
|
|
assert item not in scene.items()
|
|
|
|
|
|
|
|
# Close the graphics view
|
|
|
|
# --------------------------------------
|
|
|
|
|
|
|
|
view.close()
|
|
|
|
assert view.centralWidget is None
|
|
|
|
assert view.currentItem is None
|
|
|
|
assert view.sceneObj is None
|
|
|
|
assert view.closed is True
|