def onInit(self): self.__minCutoffSlider = LabledSlider(label="Minimum Cutoff", range=(0.3, 8.0), formatStr="%.1f", pos=(10, 10), parent=self) self.__minCutoffSlider.subscribe(widget.Slider.THUMB_POS_CHANGED, self.__onSliderMove) self.__cutoffSlopeSlider = LabledSlider(label="Cutoff Slope", range=(0.0, 0.05), formatStr="%.3f", pos=(10, 50), parent=self) self.__minCutoffSlider.subscribe(widget.Slider.THUMB_POS_CHANGED, self.__onSliderMove) self.__onSliderMove(avg.Point2D(0, 0)) self.subscribe(avg.Node.CURSOR_DOWN, self.__onDown) self.__contact = None self.__rawContactCircle = avg.CircleNode(r=7 * player.getPixelsPerMM(), color="FF0000", opacity=0, parent=self) self.__filteredContactCircle = avg.CircleNode(r=7 * player.getPixelsPerMM(), color="00FF00", opacity=0, parent=self) self.__filters = None
def queryDimensions(): res = player.getScreenResolution() self.assert_(res.x > 0 and res.y > 0 and res.x < 10000 and res.y < 10000) ppmm = player.getPixelsPerMM() self.assert_(ppmm > 0 and ppmm < 10000) mm = player.getPhysicalScreenDimensions() self.assert_(mm.x > 0 and mm.y > 0 and mm.x < 10000 and mm.y < 10000) player.assumePixelsPerMM(ppmm) newPPMM = player.getPixelsPerMM() self.assertAlmostEqual(newPPMM, ppmm) newMM = player.getPhysicalScreenDimensions() self.assertEqual(newMM, mm)
def queryDimensions(): res = player.getScreenResolution() self.assert_(0 < res.x < 10000 and 0 < res.y < 10000) ppmm = player.getPixelsPerMM() self.assert_(0 < ppmm < 10000) mm = player.getPhysicalScreenDimensions() self.assert_(0 < mm.x < 10000 and 0 < mm.y < 10000) player.assumePixelsPerMM(ppmm) newPPMM = player.getPixelsPerMM() self.assertAlmostEqual(newPPMM, ppmm) newMM = player.getPhysicalScreenDimensions() self.assertEqual(newMM, mm)
def __init__(self, node, direction, numContacts=1, initialEvent=None, directionTolerance=SWIPE_DIRECTION_TOLERANCE, minDist=MIN_SWIPE_DIST, maxContactDist=MAX_SWIPE_CONTACT_DIST, possibleHandler=None, failHandler=None, detectedHandler=None): self.__numContacts = numContacts self.__angleWanted = self.__angleFromDirection(direction) self.__directionTolerance = directionTolerance self.__minDist = minDist*player.getPixelsPerMM() self.__maxInterContactDist = maxContactDist*player.getPixelsPerMM() super(SwipeRecognizer, self).__init__(node, False, numContacts, initialEvent, possibleHandler=possibleHandler, failHandler=failHandler, detectedHandler=detectedHandler)
def _handleUp(self, event): if self.getState() == "POSSIBLE": if (event.contact.distancefromstart > self.__maxDist*player.getPixelsPerMM()): self._setFail(event) else: self._setDetected(event)
def _handleUp(self, event): if self.getState() == "POSSIBLE": if (event.contact.distancefromstart > TapRecognizer.MAX_TAP_DIST*player.getPixelsPerMM()): self._setFail(event) else: self._setDetected(event)
def init(self): player.showCursor(True) self.__minCutoffSlider = LabledSlider(label="Minimum Cutoff", min=0.3, max=8.0, formatStr="%.1f", onChange=self.__onSliderMove, pos=(10,10), parent=self._parentNode) self.__cutoffSlopeSlider = LabledSlider(label="Cutoff Slope", min=0.0, max=0.05, formatStr="%.3f", onChange=self.__onSliderMove, pos=(10,50), parent=self._parentNode) self.__onSliderMove() self._parentNode.subscribe(avg.Node.CURSOR_DOWN, self.__onDown) self.__contact = None self.__rawContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), color="FF0000", opacity=0, parent=self._parentNode) self.__filteredContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), color="00FF00", opacity=0, parent=self._parentNode) self.__filters = None
def __init__(self, event, parent=None, **kwargs): avg.DivNode.__init__(self, **kwargs) self.registerInstance(self, parent) event.contact.subscribe(avg.Contact.CURSOR_MOTION, self._onMotion) event.contact.subscribe(avg.Contact.CURSOR_UP, self._onUp) self.pos = self.getParent().getRelPos(event.pos) self._fingerSize = 7 * player.getPixelsPerMM() # Assume 14mm width for a finger. self._radius = self._getRadius(event)
def onInit(self): self.__minCutoffSlider = LabledSlider(label="Minimum Cutoff", range=(0.3, 8.0), formatStr="%.1f", pos=(10,10), parent=self) self.__minCutoffSlider.subscribe(widget.Slider.THUMB_POS_CHANGED, self.__onSliderMove) self.__cutoffSlopeSlider = LabledSlider(label="Cutoff Slope", range=(0.0, 0.05), formatStr="%.3f", pos=(10,50), parent=self) self.__minCutoffSlider.subscribe(widget.Slider.THUMB_POS_CHANGED, self.__onSliderMove) self.__onSliderMove(avg.Point2D(0,0)) self.subscribe(avg.Node.CURSOR_DOWN, self.__onDown) self.__contact = None self.__rawContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), color="FF0000", opacity=0, parent=self) self.__filteredContactCircle = avg.CircleNode(r=7*player.getPixelsPerMM(), color="00FF00", opacity=0, parent=self) self.__filters = None
def _handleUp(self, event): if self.__stateMachine.state == "DOWN1": self.__startTime = player.getFrameTime() self.__stateMachine.changeState("UP1") elif self.__stateMachine.state == "DOWN2": if ((event.pos - self.__startPos).getNorm() > self.__maxDist*player.getPixelsPerMM()): self._setFail(event) else: self._setDetected(event) self.__stateMachine.changeState("IDLE") elif self.__stateMachine.state == "IDLE": pass else: assert(False), self.__stateMachine.state
def _handleDown(self, event): self.__startTime = player.getFrameTime() if self.__stateMachine.state == "IDLE": self.__frameHandlerID = player.subscribe(player.ON_FRAME, self.__onFrame) self.__stateMachine.changeState("DOWN1") self.__startPos = event.pos self._setPossible(event) elif self.__stateMachine.state == "UP1": if ((event.pos - self.__startPos).getNorm() > self.__maxDist*player.getPixelsPerMM()): self.__stateMachine.changeState("IDLE") self._setFail(event) else: self.__stateMachine.changeState("DOWN2") else: assert(False), self.__stateMachine.state
def _handleMove(self, event): if self.getState() != "IDLE": pos = self.__relEventPos(event) offset = pos - self.__dragStartPos if self.getState() == "RUNNING": self.notifySubscribers(Recognizer.MOTION, [offset]); else: if offset.getNorm() > self.__minDragDist*player.getPixelsPerMM(): if self.__angleFits(offset): self._setDetected(event) self.notifySubscribers(Recognizer.MOTION, [offset]); else: self.__fail(event) if self.__inertiaHandler: self.__inertiaHandler.onDrag(Transform(pos - self.__lastPos)) self.__lastPos = pos
def _handleMove(self, event): if not self._handleCoordSysNodeUnlinked(): if self.getState() != "IDLE": pos = self._relEventPos(self.__coordSysNode(), event) offset = pos - self.__dragStartPos if self.getState() == "RUNNING": self.notifySubscribers(Recognizer.MOTION, [offset]) else: if offset.getNorm() > self.__minDragDist*player.getPixelsPerMM(): if self.__angleFits(offset): self._setDetected(event) self.notifySubscribers(Recognizer.MOTION, [offset]) else: self.__fail(event) if self.__inertiaHandler: self.__inertiaHandler.onDrag(Transform(pos - self.__lastPos)) self.__lastPos = pos
def _setActiveArea(self, upNode, activeAreaNode, fatFingerEnlarge): if fatFingerEnlarge: if activeAreaNode: raise (RuntimeError("Button: Can't specify both fatFingerEnlarge and activeAreaNode")) size = upNode.size minSize = 20 * player.getPixelsPerMM() size = avg.Point2D(max(minSize, size.x), max(minSize, size.y)) activeAreaNode = avg.RectNode(size=size, opacity=0, parent=self) # Here we need to store a 'hard' reference to the active area node # because the tap recognizer won't keep it self.__activeAreaNode = activeAreaNode else: if activeAreaNode == None: activeAreaNode = self else: self.appendChild(activeAreaNode) self._tapRecognizer = gesture.TapRecognizer( activeAreaNode, possibleHandler=self._onDown, detectedHandler=self._onTap, failHandler=self._onTapFail )
def _setActiveArea(self, upNode, activeAreaNode, fatFingerEnlarge): self.__activeAreaNode = activeAreaNode if fatFingerEnlarge: if self.__activeAreaNode != None: raise(RuntimeError( "Button: Can't specify both fatFingerEnlarge and activeAreaNode")) size = upNode.size minSize = 20*player.getPixelsPerMM() size = avg.Point2D(max(minSize, size.x), max(minSize, size.y)) self.__activeAreaNode = avg.RectNode(size=size, opacity=0, parent=self) else: if self.__activeAreaNode == None: self.__activeAreaNode = self else: self.appendChild(self.__activeAreaNode) self._tapRecognizer = gesture.TapRecognizer(self.__activeAreaNode, possibleHandler=self._onDown, detectedHandler=self._onTap, failHandler=self._onTapFail)
def on_frame(self): """ Needed to be called every frame. """ if not self.__event: return if self.__double_tap_hold_active or self.__hold_active: return now = player.getFrameTime() down_time = now - self.__event_time if down_time <= self.__device_pointer_config.hold_delay: return if self.__event_movement_dist > self.__device_pointer_config.hold_max_dist * player.getPixelsPerMM( ): return else: self.__hold_active = True StudyLog.get_instance().write_device_canvas_event( self.__device, "HOLD") self.dispatch(self.__HOLD, sender=self, event=self.__event)
def _setActiveArea(self, upNode, activeAreaNode, fatFingerEnlarge): if fatFingerEnlarge: if activeAreaNode: raise (RuntimeError( "Button: Can't specify both fatFingerEnlarge and activeAreaNode" )) size = upNode.size minSize = 20 * player.getPixelsPerMM() size = avg.Point2D(max(minSize, size.x), max(minSize, size.y)) activeAreaNode = avg.RectNode(size=size, opacity=0, parent=self) #Here we need to store a 'hard' reference to the active area node #because the tap recognizer won't keep it self.__activeAreaNode = activeAreaNode else: if activeAreaNode is None: activeAreaNode = self else: self.appendChild(activeAreaNode) self._tapRecognizer = gesture.TapRecognizer( activeAreaNode, possibleHandler=self._onDown, detectedHandler=self._onTap, failHandler=self._onTapFail)
def _handleMove(self, event): self.__lastEvent = event if self.getState() == "POSSIBLE": if (event.contact.distancefromstart > self.__maxDist*player.getPixelsPerMM()): self._setFail(event)
def _handleMove(self, event): if self.__stateMachine.state != "IDLE": if ((event.pos - self.__startPos).getNorm() > TapRecognizer.MAX_TAP_DIST*player.getPixelsPerMM()): self.__stateMachine.changeState("IDLE") self._setFail(event)
def _handleMove(self, event): if self.__stateMachine.state != "IDLE": if ((event.pos - self.__startPos).getNorm() > self.__maxDist*player.getPixelsPerMM()): self.__stateMachine.changeState("IDLE") self._setFail(event)
def _handleMove(self, event): self.__lastEvent = event if self.getState() == "POSSIBLE": if (event.contact.distancefromstart > TapRecognizer.MAX_TAP_DIST*player.getPixelsPerMM()): self._setFail(event)
def _handleMove(self, event): if self.getState() != "IDLE": if (event.contact.distancefromstart > self.__maxDist*player.getPixelsPerMM()): self._setFail(event)