def __init__(self): super(Window, self).__init__() box = QtGui.QBoxLayout(QtGui.QBoxLayout.LeftToRight, self) self.resize(500, 200) self.setLayout(box) self.canvas_0 = SceneCanvas(bgcolor='w') self.vb_0 = ViewBox(parent=self.canvas_0.scene, bgcolor='r') self.vb_0.camera.rect = -1, -1, 2, 2 self.canvas_0.events.initialize.connect(self.on_init) self.canvas_0.events.resize.connect( partial(on_resize, self.canvas_0, self.vb_0)) box.addWidget(self.canvas_0.native) # pass the context from the first canvas to the second self.canvas_1 = SceneCanvas(bgcolor='w', shared=self.canvas_0.context) self.vb_1 = ViewBox(parent=self.canvas_1.scene, bgcolor='b') self.vb_1.camera.rect = -1, -1, 2, 2 self.canvas_1.events.resize.connect( partial(on_resize, self.canvas_1, self.vb_1)) box.addWidget(self.canvas_1.native) self.tick_count = 0 self.timer = Timer(interval=1., connect=self.on_timer, start=True) self.setWindowTitle('Shared contexts') self.show()
def test_panzoom_link(): vbs = [ViewBox(camera='panzoom') for _ in range(4)] cams = [vb.camera for vb in vbs] for cam in cams: cam.rect = (0, 0, 100, 100) cams[0].link(cams[1]) cams[0].link(cams[2], axis='x') cams[0].link(cams[3], axis='y') cams[1].rect = (-20, -20, 130, 130) assert cams[0].rect.pos == (-20, -20) and cams[0].rect.size == (130, 130) assert cams[2].rect.pos == (-20, 0) and cams[2].rect.size == (130, 100) assert cams[3].rect.pos == (0, -20) and cams[3].rect.size == (100, 130)
def test_turntable_camera_link(): vbs = [ViewBox(camera='turntable') for _ in range(3)] cams = [vb.camera for vb in vbs] for cam in cams: cam.elevation = 45.0 cam.azimuth = 120.0 cam.scale_factor = 4.0 cams[0].link(cams[1]) cams[0].link(cams[2], props=['azimuth', 'elevation']) cams[1].elevation = 30.0 cams[1].azimuth = 90.0 cams[1].scale_factor = 2.0 assert cams[0].elevation == 30.0 assert cams[0].azimuth == 90.0 assert cams[0].scale_factor == 2.0 assert cams[2].elevation == 30.0 assert cams[2].azimuth == 90.0 assert cams[2].scale_factor == 4.0