Esempio n. 1
0
    def notify (self, event):
        """B.notify (...) -> None

        Notifies the Button about an event.
        """
        if not self.eventarea or not self.sensitive:
            # The button does not seem to be completely realized for now or
            # is not sensitive.
            return

        elif event.signal == SIG_MOUSEDOWN:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "Button.MOUSEDOWN"
                self.focus = True
                # The button only acts upon left clicks.
                if event.data.button == 1:
                    self.state = STATE_ACTIVE
                    self.__click = True
                self.run_signal_handlers (SIG_MOUSEDOWN)

        elif event.signal == SIG_MOUSEUP:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "Button.MOUSEUP"
                self.run_signal_handlers (SIG_MOUSEUP)
                if event.data.button == 1:
                    if self.state == STATE_ACTIVE:
                        self.state = STATE_ENTERED
                    else:
                        self.state = STATE_NORMAL
                    # Check for a previous left click.
                    if self.__click:
                        self.__click = False
                        if base.debug: print "Button.CLICKED"
                        self.run_signal_handlers (SIG_CLICKED)
            elif (event.data.button == 1) and (self.state == STATE_ACTIVE):
                # Reset the 'clicked' state for the button, if the mouse
                # button 1 is released at another location.
                self.__click = False
                self.state = STATE_NORMAL

        elif event.signal == SIG_MOUSEMOVE:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "Button.MOUSEMOVE (inner)"
                if self.state == STATE_NORMAL:
                    self.state = STATE_ENTERED
                self.run_signal_handlers (SIG_MOUSEMOVE)
            elif self.state == STATE_ENTERED:
                if base.debug: print "Button.MOUSEMOVE (outer)"
                self.state = STATE_NORMAL

        elif (event.signal == SIG_KEYDOWN) and self.focus:
            if event.data.key in (pygame.locals.K_SPACE,
                                  pygame.locals.K_KP_ENTER,
                                  pygame.locals.K_RETURN):
                # Activate the focused button, if the user presses
                # space, return or enter.
                self.activate ()
        
        Bin.notify (self, event)
Esempio n. 2
0
    def notify (self, event):
        """W.notify (event) -> None

        Notifies the window about an event.
        """
        if not self.sensitive or not self.eventarea:
            return

        if event.signal == SIG_MOUSEDOWN:
            if self.rect.collidepoint (event.data.pos):
                if base.debug: print "Window.MOUSEDOWN"
                self.focus = True
                self.run_signal_handlers (SIG_MOUSEDOWN)
                if self._caption_rect.collidepoint (event.data.pos):
                    if event.data.button == 1:
                        # Initiate window movement.
                        self.state = STATE_ACTIVE
                        self.__pressed = True
                        self.__old_pos = event.data.pos
                    elif event.data.button == 2:
                        # Minimize/maximize window.
                        self.__minimized = not self.__minimized
                        self.dirty = True
        
        elif event.signal == SIG_MOUSEUP:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "Window.MOUSEUP"
                self.run_signal_handlers (SIG_MOUSEUP)
                if event.data.button == 1:
                    if self.__pressed:
                        self.__pressed = False
                        self.state = STATE_NORMAL

        elif event.signal == SIG_MOUSEMOVE:
            if self.__pressed:
                # The window is moved.
                self._move_to_position (event.data.pos)
                self.__old_pos = event.data.pos
            else:
                if self.eventarea.collidepoint (event.data.pos):
                    if base.debug: print "Window.MOUSEMOVE (inner)"
                    self.run_signal_handlers (SIG_MOUSEMOVE)

        Bin.notify (self, event)
Esempio n. 3
0
    def notify (self, event):
        """S.notify (...) -> None

        Notifies the ScrolledWindow about an event.
        """
        if not self.sensitive:
            return
        
        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client ()
            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint (event.data.pos):
                    self.focus = True
                    self.run_signal_handlers (SIG_MOUSEDOWN, event.data)

                    # Mouse wheel.
                    for c in self.controls:
                        c.notify (event)
                    if not event.handled:
                        if self._vscroll_visible:
                            if event.data.button == 4:
                                self.vscrollbar.decrease ()
                            elif event.data.button == 5:
                                self.vscrollbar.increase ()
                        elif self._hscroll_visible:
                            if event.data.button == 4:
                                self.hscrollbar.decrease ()
                            elif event.data.button == 5:
                                self.hscrollbar.increase ()
                    event.handled = True
        
        elif (event.signal == SIG_KEYDOWN) and self.focus:
            if self._hscroll_visible:
                # Horizontal scrollbar key movement
                if event.data.key == K_RIGHT:
                    self.hscrollbar.increase ()
                    event.handled = True
                elif event.data.key == K_LEFT:
                    self.hscrollbar.decrease ()
                    event.handled = True
                elif event.data.key == K_END:
                    self.hscrollbar.value = self.hscrollbar.maximum
                    event.handled = True
                elif event.data.key == K_HOME:
                    self.hscrollbar.value = self.hscrollbar.minimum
                    event.handled = True
            if self._vscroll_visible:
                # Vertical scrollbar key movement
                if event.data.key == K_DOWN:
                    self.vscrollbar.increase ()
                    event.handled = True
                elif event.data.key == K_UP:
                    self.vscrollbar.decrease ()
                    event.handled = True
                elif event.data.key == K_PAGEUP:
                    val = self.vscrollbar.value - 10 * self.vscrollbar.step
                    if val > self.vscrollbar.minimum:
                        self.vscrollbar.value = val
                    else:
                        self.vscrollbar.value = self.vscrollbar.minimum
                    event.handled = True
                elif event.data.key == K_PAGEDOWN:
                    val = self.vscrollbar.value + 10 * self.vscrollbar.step
                    if val < self.vscrollbar.maximum:
                        self.vscrollbar.value = val
                    else:
                        self.vscrollbar.value = self.vscrollbar.maximum
                    event.handled = True
                elif event.data.key == K_END:
                    self.vscrollbar.value = self.vscrollbar.maximum
                    event.handled = True
                elif event.data.key == K_HOME:
                    self.vscrollbar.value = self.vscrollbar.minimum
                    event.handled = True

        Bin.notify (self, event)
Esempio n. 4
0
    def notify (self, event):
        """B.notify (...) -> None

        Notifies the ButtonBase about an event.
        """
        if not self.sensitive:
            return

        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client ()

            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint (event.data.pos):
                    self.focus = True
                    # The button only acts upon left clicks.
                    if event.data.button == 1:
                        self.__click = True
                        self.state = STATE_ACTIVE
                    self.run_signal_handlers (SIG_MOUSEDOWN, event.data)
                    event.handled = True

            elif event.signal == SIG_MOUSEUP:
                if eventarea.collidepoint (event.data.pos):
                    self.run_signal_handlers (SIG_MOUSEUP, event.data)
                    if event.data.button == 1:
                        if self.state == STATE_ACTIVE:
                            self.state = STATE_ENTERED
                        else:
                            self.state = STATE_NORMAL
                        
                        # Check for a previous left click.
                        if self.__click:
                            self.__click = False
                            self.run_signal_handlers (SIG_CLICKED)
                    event.handled = True
                            
                elif event.data.button == 1:
                    # Reset the 'clicked' state for the button, if the mouse
                    # button 1 is released at another location.
                    self.__click = False
                    self.state = STATE_NORMAL

            elif event.signal == SIG_MOUSEMOVE:
                if eventarea.collidepoint (event.data.pos):
                    if not self.__click:
                        self.state = STATE_ENTERED
                    else:
                        self.state = STATE_ACTIVE
                    
                    self.run_signal_handlers (SIG_MOUSEMOVE, event.data)
                    self.entered = True
                    event.handled = True
                else:
                    self.entered = False

        elif (event.signal == SIG_KEYDOWN) and self.focus:
            if event.data.key in (K_SPACE, K_KP_ENTER, K_RETURN):
                # Activate the focused button, if the user presses
                # space, return or enter.
                self.activate ()
                event.handled = True
        
        Bin.notify (self, event)
Esempio n. 5
0
    def notify (self, event):
        """W.notify (event) -> None

        Notifies the window about an event.
        """
        if not self.sensitive:
            return

        # Recursively notify all attached children.
        if self.child:
            self._notify_children (self.child, event)
        if self.__stopevents:
            return

        for control in self.controls:
            if event.handled:
                return
            self._notify_children (control, event)

        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client ()
            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint (event.data.pos):
                    if not event.handled:
                        self.focus = True
                        self.run_signal_handlers (SIG_MOUSEDOWN, event.data)

                    if self._captionrect.collidepoint (event.data.pos):
                        if event.data.button == 1:
                            # Initiate window movement.
                            self.state = STATE_ACTIVE
                            self.__pressed = True
                            self.__oldpos = event.data.pos
                    event.handled = True
                else:
                    self.state = STATE_NORMAL

            elif event.signal == SIG_MOUSEUP:
                if eventarea.collidepoint (event.data.pos):
                    self.run_signal_handlers (SIG_MOUSEUP, event.data)
                    if event.data.button == 1:
                        if self.__pressed:
                            self.__pressed = False
                    event.handled = True
            
            elif event.signal == SIG_MOUSEMOVE:
                if self.__pressed:
                    # The window is moved.
                    self._move_to_position (event.data.pos)
                    event.handled = True
                elif eventarea.collidepoint (event.data.pos):
                    self.run_signal_handlers (SIG_MOUSEMOVE, event.data)
                    event.handled = True

        elif event.signal == SIG_FOCUSED:
            # Keep the active state of the window, if it contains the child
            if self._contains (self, event.data):
                if self.state != STATE_ACTIVE:
                    self.state = STATE_ACTIVE
                self._keepactive = True
            else:
                self._keepactive = False
        
        Bin.notify (self, event)
Esempio n. 6
0
    def notify(self, event):
        """B.notify (...) -> None

        Notifies the ButtonBase about an event.
        """
        if not self.sensitive:
            return

        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client()

            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint(event.data.pos):
                    self.focus = True
                    # The button only acts upon left clicks.
                    if event.data.button == 1:
                        self.__click = True
                        self.state = STATE_ACTIVE
                    self.run_signal_handlers(SIG_MOUSEDOWN, event.data)
                    event.handled = True

            elif event.signal == SIG_MOUSEUP:
                if eventarea.collidepoint(event.data.pos):
                    self.run_signal_handlers(SIG_MOUSEUP, event.data)
                    if event.data.button == 1:
                        if self.state == STATE_ACTIVE:
                            self.state = STATE_ENTERED
                        else:
                            self.state = STATE_NORMAL

                        # Check for a previous left click.
                        if self.__click:
                            self.__click = False
                            self.run_signal_handlers(SIG_CLICKED)
                    event.handled = True

                elif event.data.button == 1:
                    # Reset the 'clicked' state for the button, if the mouse
                    # button 1 is released at another location.
                    self.__click = False
                    self.state = STATE_NORMAL

            elif event.signal == SIG_MOUSEMOVE:
                if eventarea.collidepoint(event.data.pos):
                    if not self.__click:
                        self.state = STATE_ENTERED
                    else:
                        self.state = STATE_ACTIVE

                    self.run_signal_handlers(SIG_MOUSEMOVE, event.data)
                    self.entered = True
                    event.handled = True
                else:
                    self.entered = False

        elif (event.signal == SIG_KEYDOWN) and self.focus:
            if event.data.key in (K_SPACE, K_KP_ENTER, K_RETURN):
                # Activate the focused button, if the user presses
                # space, return or enter.
                self.activate()
                event.handled = True

        Bin.notify(self, event)
Esempio n. 7
0
    def notify(self, event):
        """W.notify (event) -> None

        Notifies the window about an event.
        """
        if not self.sensitive:
            return

        # Recursively notify all attached children.
        if self.child:
            self._notify_children(self.child, event)
        if self.__stopevents:
            return

        for control in self.controls:
            if event.handled:
                return
            self._notify_children(control, event)

        if event.signal in SIGNALS_MOUSE:
            eventarea = self.rect_to_client()
            if event.signal == SIG_MOUSEDOWN:
                if eventarea.collidepoint(event.data.pos):
                    if not event.handled:
                        self.focus = True
                        self.run_signal_handlers(SIG_MOUSEDOWN, event.data)

                    if self._captionrect.collidepoint(event.data.pos):
                        if event.data.button == 1:
                            # Initiate window movement.
                            self.state = STATE_ACTIVE
                            self.__pressed = True
                            self.__oldpos = event.data.pos
                    event.handled = True
                else:
                    self.state = STATE_NORMAL

            elif event.signal == SIG_MOUSEUP:
                if eventarea.collidepoint(event.data.pos):
                    self.run_signal_handlers(SIG_MOUSEUP, event.data)
                    if event.data.button == 1:
                        if self.__pressed:
                            self.__pressed = False
                    event.handled = True

            elif event.signal == SIG_MOUSEMOVE:
                if self.__pressed:
                    # The window is moved.
                    self._move_to_position(event.data.pos)
                    event.handled = True
                elif eventarea.collidepoint(event.data.pos):
                    self.run_signal_handlers(SIG_MOUSEMOVE, event.data)
                    event.handled = True

        elif event.signal == SIG_FOCUSED:
            # Keep the active state of the window, if it contains the child
            if self._contains(self, event.data):
                if self.state != STATE_ACTIVE:
                    self.state = STATE_ACTIVE
                self._keepactive = True
            else:
                self._keepactive = False

        Bin.notify(self, event)
Esempio n. 8
0
    def notify (self, event):
        """S.notify (...) -> None

        Notifies the ScrolledWindow about an event.
        """
        if not self.eventarea or not self.sensitive:
            return

        if event.signal == SIG_MOUSEDOWN:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "ScrolledWindow.MOUSEDOWN"
                self.focus = True
                self.run_signal_handlers (SIG_MOUSEDOWN)
                # Mouse wheel.
                if self._hscroll_visible and \
                   (self.hscrollbar.eventarea.collidepoint (event.data.pos)):
                    # Do not scroll vertical, if the mouse cursor is
                    # over the horizontal scrollbar.
                    pass
                elif self._vscroll_visible:
                    if event.data.button == 4:
                        self.vscrollbar.decrease ()
                    elif event.data.button == 5:
                        self.vscrollbar.increase ()
        
        elif (event.signal == SIG_KEYDOWN) and self.focus:
            if self._hscroll_visible:
                # Horizontal scrollbar key movement
                if event.data.key == pygame.locals.K_RIGHT:
                    self.hscrollbar.increase ()

                elif event.data.key == pygame.locals.K_LEFT:
                    self.hscrollbar.decrease ()

                elif event.data.key == pygame.locals.K_END:
                    self.hscrollbar.value = self.hscrollbar.maximum

                elif event.data.key == pygame.locals.K_HOME:
                    self.hscrollbar.value = self.hscrollbar.minimum

            if self._vscroll_visible:
                # Vertical scrollbar key movement
                if event.data.key == pygame.locals.K_DOWN:
                    self.vscrollbar.increase ()

                elif event.data.key == pygame.locals.K_UP:
                    self.vscrollbar.decrease ()

                elif event.data.key == pygame.locals.K_PAGEUP:
                    val = self.vscrollbar.value - 10 * self.vscrollbar.step
                    if val > self.vscrollbar.minimum:
                        self.vscrollbar.value = val
                    else:
                        self.vscrollbar.value = self.vscrollbar.minimum

                elif event.data.key == pygame.locals.K_PAGEDOWN:
                    val = self.vscrollbar.value + 10 * self.vscrollbar.step
                    if val < self.vscrollbar.maximum:
                        self.vscrollbar.value = val
                    else:
                        self.vscrollbar.value = self.vscrollbar.maximum

                elif event.data.key == pygame.locals.K_END:
                    self.vscrollbar.value = self.vscrollbar.maximum

                elif event.data.key == pygame.locals.K_HOME:
                    self.vscrollbar.value = self.vscrollbar.minimum

        Bin.notify (self, event)