Exemplo n.º 1
0
 def __onTap(self, event):
     if self.__stateMachine.state == "UNCHECKED_DOWN":
         self.__stateMachine.changeState("CHECKED_UP")
         utils.callWeakRef(self.__checkHandler, event)
     elif self.__stateMachine.state == "CHECKED_DOWN":
         self.__stateMachine.changeState("UNCHECKED_UP")
         utils.callWeakRef(self.__uncheckHandler, event)
Exemplo n.º 2
0
 def __pressHandler(self, event):
     if not self.__isCursorCaptured(event.cursorid):
         self.__captureCursor(event.cursorid)
     
     if event.cursorid not in self.__overCursorIds:
         self.__overCursorIds.add(event.cursorid)
     
     if self.__getNumberOfCapturedCursors() <= 1:
         self.__changeState(Button.STATE_DOWN)
         utils.callWeakRef(self.__pressCallback, event)
Exemplo n.º 3
0
 def _handleUp(self, event):
     if self.getState() != "IDLE":
         pos = self.__relEventPos(event)
         if self.getState() == "RUNNING":
             self.__offset = pos - self.__dragStartPos
             utils.callWeakRef(self.__upHandler, event, self.__offset)
             if self.__friction != -1:
                 self.__isSliding = True
                 self.__inertiaHandler.onDrag(Transform(pos - self.__lastPos))
                 self.__inertiaHandler.onUp()
             else:
                 self._setEnd(event)
         else:
             self.__fail(event)
Exemplo n.º 4
0
 def _handleUp(self, event):
     numContacts = len(self._contacts)
     if numContacts == 0:
         contact = event.contact
         transform = Transform(self.__relContactPos(contact) - self.__lastPosns[0])
         utils.callWeakRef(self.__upHandler, transform)
         if self.__friction != -1:
             self.__inertiaHandler.onDrag(transform)
             self.__inertiaHandler.onUp()
         else:
             self._setEnd(event)
     elif numContacts == 1:
         self.__newPhase()
     else:
         self.__newPhase()
Exemplo n.º 5
0
 def _handleMove(self, event):
     if self.getState() != "IDLE":
         pos = self.__relEventPos(event)
         offset = pos - self.__dragStartPos
         if self.getState() == "RUNNING":
             utils.callWeakRef(self.__moveHandler, event, offset)
         else:
             if offset.getNorm() > self.__minDist:
                 if self.__angleFits(offset):
                     self._setDetected(event)
                     utils.callWeakRef(self.__moveHandler, event, offset)
                 else:
                     self.__fail(event)
         if self.__inertiaHandler:
             self.__inertiaHandler.onDrag(Transform(pos - self.__lastPos))
         self.__lastPos = pos
Exemplo n.º 6
0
    def __releaseHandler(self, event):
        numberOfCapturedCursors = self.__getNumberOfCapturedCursors()
        numberOfOverCursors = len(self.__overCursorIds)
        
        if self.__isCursorCaptured(event.cursorid):
            self.__releaseCapturedCursor(event.cursorid)

        if event.cursorid in self.__overCursorIds:
            self.__overCursorIds.remove(event.cursorid)
            
        if numberOfCapturedCursors == 1 and numberOfOverCursors == 1:
            newState = Button.STATE_UP
            if self.isCheckable():
                self.__isToggled = not self.__isToggled
                if self.__isToggled:
                    newState = Button.STATE_DOWN
                
            self.__changeState(newState)
            
            utils.callWeakRef(self.__clickCallback, event)
Exemplo n.º 7
0
    def _handleChange(self):
        numContacts = len(self._contacts)
        if numContacts == 1:
            contact = self._contacts.keys()[0]
            transform = Transform(self.__relContactPos(contact) - self.__lastPosns[0])
            if self.__friction != -1:
                self.__inertiaHandler.onDrag(transform)
            utils.callWeakRef(self.__moveHandler, transform)
            self.__lastPosns = [self.__relContactPos(contact)]
        else:
            contactPosns = [self.__relContactPos(contact)
                    for contact in self._contacts.keys()]
            if numContacts == 2:
                self.__posns = contactPosns
            else:
                self.__posns = [getCentroid(self.__clusters[i], contactPosns) for
                        i in range(2)]

            startDelta = self.__lastPosns[1]-self.__lastPosns[0]
            curDelta = self.__posns[1]-self.__posns[0]

            pivot = (self.__posns[0]+self.__posns[1])/2

            rot = avg.Point2D.angle(curDelta, startDelta)

            if self.__lastPosns[0] == self.__lastPosns[1]:
                scale = 1
            else:
                scale = ((self.__posns[0]-self.__posns[1]).getNorm() / 
                        (self.__lastPosns[0]-self.__lastPosns[1]).getNorm())

            trans = ((self.__posns[0]+self.__posns[1])/2 - 
                    (self.__lastPosns[0]+self.__lastPosns[1])/2)
            transform = Transform(trans, rot, scale, pivot)
            if self.__friction != -1:
                self.__inertiaHandler.onDrag(transform)
            utils.callWeakRef(self.__moveHandler, transform)
            self.__lastPosns = self.__posns
Exemplo n.º 8
0
 def _setPossible(self, event):
     self.__stateMachine.changeState("POSSIBLE")
     utils.callWeakRef(self.__possibleHandler, event)
Exemplo n.º 9
0
 def __onInertiaMove(self, transform):
     utils.callWeakRef(self.__moveHandler, transform)
Exemplo n.º 10
0
 def __onInertiaMove(self, transform):
     self.__offset += transform.trans 
     utils.callWeakRef(self.__moveHandler, None, self.__offset)
Exemplo n.º 11
0
 def _setEnd(self, event):
     assert(self.__stateMachine.state != "POSSIBLE")
     if self.__stateMachine.state != "IDLE":
         self.__stateMachine.changeState("IDLE")
     utils.callWeakRef(self.__endHandler, event)
Exemplo n.º 12
0
 def _setDetected(self, event):
     if self.__isContinuous:
         self.__stateMachine.changeState("RUNNING")
     else:
         self.__stateMachine.changeState("IDLE")
     utils.callWeakRef(self.__detectedHandler, event)
Exemplo n.º 13
0
 def _setFail(self, event):
     assert(self.__stateMachine.state != "RUNNING")
     if self.__stateMachine.state != "IDLE":
         self.__stateMachine.changeState("IDLE")
     utils.callWeakRef(self.__failHandler, event)
Exemplo n.º 14
0
 def __onTap(self, event):
     self.__stateMachine.changeState("UP")
     utils.callWeakRef(self.__clickHandler, event)
Exemplo n.º 15
0
 def __changeState(self, state):
     self.__state = state
     self.__updateNodesVisibility()
     utils.callWeakRef(self.__stateChangeCallback, state)