def __del__(self): #We assume that there is only one Gui object. if Widget.widgetExists(self.mTop): #self.mTop.shutDown() self.mTop.setFocusHandler(None) self.mTop=None
def handleModalFocusGained(self): # Distribute an event to all widgets in the "widget with mouse" queue. while len(self.mWidgetWithMouseQueue) > 0: widget=self.mWidgetWithMouseQueue[0] if Widget.widgetExists(widget) == True: self.distributeMouseEvent(widget,MouseEvent.EXITED,self.mLastMousePressButton,self.mLastMousePressX,self.mLastMousePressY,true,true) self.mWidgetWithMouseQueue.pop(0) self.mFocusHandler.setLastWidgetWithModalMouseInputFocus(self.mFocusHandler.getModalMouseInputFocused())
def handleModalFocusReleased(self): #Check all widgets below the mouse to see if they are #present in the "widget with mouse" queue. If a widget #is not then it should be added and an entered event should #be sent to it. widget=self.getEventSource(self.mLastMouseX,self.mLastMouseX) parent=widget while parent != None: parent=widget.getParent() #Check if the widget is present in the "widget with mouse" queue. widgetIsPresentInQueue = false for i in self.mWidgetWithMouseQueue: if i == widget: widgetIsPresentInQueue = true break #Widget is not present, send an entered event and add #it to the "widget with mouse" queue. if widgetIsPresentInQueue == False and Widget.widgetExists(widget) == True: self.distributeMouseEvent(widget,MouseEvent.ENTERED,self.mLastMousePressButtons,self.mLastMouseX,self.mLastMouseY,False,True) self.mWidgetWithMouseQueue.insert(0,widget) swap = widget widget = parent parent = swap.getParent()
def distributeKeyEvent(self,keyEvent): parent=keyEvent.getSource() widget=keyEvent.getSource() if self.mFocusHandler.getModalFocused() != None and widget.isModalFocused() == False: return None if self.mFocusHandler.getModalMouseInputFocused() != None and widget.isModalMouseInputFocused() == False: return None while parent != None: #If the widget has been removed due to input #cancel the distribution. if Widget.widgetExists(widget) == False: break parent=widget.getParent() type=keyEvent.getType() if widget.isEnabled() == True: keyListeners=widget.getKeyListeners() for i in keyListeners: if type == KeyEvent.PRESSED: i().keyPressed(keyEvent) elif type == KeyEvent.RELEASED: i().keyReleased(keyEvent) else: raise GCN_EXCEPTION("Unknown key event type.") swap=widget widget=parent parent=swap.getParent() #If a non modal focused widget has been reached #and we have modal focus cancel the distribution. if self.mFocusHandler.getModalFocused() != None and widget.isModalFocused() == False: break
def distributeMouseEvent(self,source,type,button,x,y,force=False,toSourceOnly=False): parent=source widget=source if self.mFocusHandler.getModalFocused() != None and widget.isModalFocused() == False and force == False: return None if self.mFocusHandler.getModalMouseInputFocused() != None and widget.isModalMouseInputFocused() == False and force == False: return None mouseEvent=MouseEvent(source,self.mShiftPressed,self.mControlPressed,self.mAltPressed,self.mMetaPressed,type,button,x,y,self.mClickCount) while parent != None: #If the widget has been removed due to input #cancel the distribution. if Widget.widgetExists(widget) == False: return None parent=widget.getParent() if widget.isEnabled() == True or force == True: widgetX, widgetY=widget.getAbsolutePosition() mouseEvent.mX=x-widgetX mouseEvent.mY=y-widgetY mouseListeners=widget.getMouseListeners() type=mouseEvent.getType() #Send the event to all mouse listeners of the widget. for i in mouseListeners: if type == MouseEvent.ENTERED: i().mouseEntered(mouseEvent) elif type == MouseEvent.DRAGGED: i().mouseDragged(mouseEvent) elif type == MouseEvent.EXITED: i().mouseExited(mouseEvent) elif type == MouseEvent.MOVED: i().mouseMoved(mouseEvent) elif type == MouseEvent.PRESSED: i().mousePressed(mouseEvent) elif type == MouseEvent.RELEASED: i().mouseReleased(mouseEvent) elif type == MouseEvent.WHEEL_MOVED_UP: i().mouseWheelMovedUp(mouseEvent) elif type == MouseEvent.WHEEL_MOVED_DOWN: i().mouseWheelMovedDown(mouseEvent) elif type == MouseEvent.CLICKED: i().mouseClicked(mouseEvent) else: raise GCN_EXCEPTION("Unknown mouse event type.") if toSourceOnly == True: break swap=widget widget=parent parent=swap.getParent() #If a non modal focused widget has been reached #and we have modal focus cancel the distribution. if self.mFocusHandler.getModalFocused() != None and widget.isModalFocused() == False: break #If a non modal mouse input focused widget has been reached #and we have modal mouse input focus cancel the distribution. if self.mFocusHandler.getModalMouseInputFocused() != None and widget.isModalMouseInputFocused() == False: break
def handleMouseMoved(self,mouseInput): if len(self.mWidgetWithMouseQueue) > 0 and ( mouseInput.getX() < 0 or mouseInput.getY() < 0 or self.mTop.getDimension().isPointInRect(mouseInput.getX(),mouseInput.getY()) ) == False: #distribute an event to all widgets in the "widget with mouse" queue. while len(self.mWidgetWithMouseQueue) > 0: widget=self.mWidgetWithMouseQueue[0] if Widget.widgetExists(widget): self.distributeMouseEvent(widget,MouseEvent.EXITED,mouseInput.getButton(),mouseInput.getX(),mouseInput.getY(),true,true) self.mWidgetWithMouseQueue.pop(0) return None #Check if there is a need to send mouse exited events by #traversing the "widget with mouse" queue. widgetWithMouseQueueCheckDone=len(self.mWidgetWithMouseQueue) == 0 while widgetWithMouseQueueCheckDone == False: iterations=0 for i in self.mWidgetWithMouseQueue: widget=i #If a widget in the "widget with mouse queue" doesn't #exist anymore it should be removed from the queue if Widget.widgetExists(widget) == False: self.mWidgetWithMouseQueue.remove(widget) break else: x, y=widget.getAbsolutePosition() if x > mouseInput.getX() or y > mouseInput.getX() or x+widget.getWidth() <= mouseInput.getX() or y+widget.getHeight() <= mouseInput.getY() or widget.isVisible() == False: self.distributeMouseEvent(widget,MouseEvent.EXITED,mouseInput.getButton(),mouseInput.getX(),mouseInput.getY(),true,true) self.mClickCount=1 self.mLastMousePressTimeStamp=0 self.mWidgetWithMouseQueue.remove(i) break iterations+=1 widgetWithMouseQueueCheckDone = iterations == len(self.mWidgetWithMouseQueue) #Check all widgets below the mouse to see if they are #present in the "widget with mouse" queue. If a widget #is not then it should be added and an entered event should #be sent to it. parent=self.getMouseEventSource(mouseInput.getX(),mouseInput.getY()) widget=parent #If a widget has modal mouse input focus then it will #always be returned from getMouseEventSource, but we only wan't to send #mouse entered events if the mouse has actually entered the widget with #modal mouse input focus, hence we need to check if that's the case. If #it's not we should simply ignore to send any mouse entered events. if self.mFocusHandler.getModalMouseInputFocused() == widget and Widget.widgetExists(widget) == True: x, y=widget.getAbsolutePosition() if x > mouseInput.getX() or y > mouseInput.getY() or x+widget.getWidth() <= mouseInput.getX() or y+widget.getHeight() <= mouseInput.getY(): parent=None while parent != None: parent=widget.getParent() # Check if the widget is present in the "widget with mouse" queue. widgetIsPresentInQueue=False for i in self.mWidgetWithMouseQueue: if i==widget: widgetIsPresentInQueue=True break # Widget is not present, send an entered event and add #it to the "widget with mouse" queue. if widgetIsPresentInQueue == False and Widget.widgetExists(widget) == True: self.distributeMouseEvent(widget,MouseEvent.ENTERED,mouseInput.getButton(),mouseInput.getX(),mouseInput.getY(),True,True) self.mWidgetWithMouseQueue.insert(0,widget) swap = widget widget = parent parent = swap.getParent() if self.mFocusHandler.getDraggedWidget() != None: #self.distributeMouseEvent(widget,MouseEvent.DRAGGED,mouseInput.getButton(),mouseInput.getX(),mouseInput.getY(),True,True) self.distributeMouseEvent(self.mFocusHandler.getDraggedWidget(),MouseEvent.DRAGGED,mouseInput.getButton(),mouseInput.getX(),mouseInput.getY(),True,True) else: self.distributeMouseEvent(widget,MouseEvent.MOVED,mouseInput.getButton(),mouseInput.getX(),mouseInput.getY(),True,True)