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

        Notifies the ToggleButton about an event.
        """
        if not self.eventarea or not self.sensitive:
            return # Not completely realized or sensitive.
        
        elif event.signal == SIG_MOUSEDOWN:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "ToggleButton.MOUSEDOWN"
                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)
        
        elif event.signal == SIG_MOUSEUP:
            if self.eventarea.collidepoint (event.data.pos):
                if base.debug: print "ToggleButton.MOUSEUP"
                self.run_signal_handlers (SIG_MOUSEUP)
                if event.data.button == 1:
                    if self.__click:
                        # The usual order for a ToggleButton: get a
                        # click and toggle state upon it.
                        if base.debug: print "ToggleButton.CLICKED"
                        self.run_signal_handlers (SIG_CLICKED)
                        self.set_active (not self.active)
                        if base.debug: print "ToggleButton.TOGGLED"
                        self.run_signal_handlers (SIG_TOGGLED)
                        if not self.active:
                            self.state = STATE_ENTERED
            elif (event.data.button == 1) and self.__click and not self.active:
                # Only a half click was made, reset the state of the
                # ToggleButton.
                self.state = STATE_NORMAL

        elif event.signal == SIG_MOUSEMOVE:
            # If the state was set in any way although the button's
            # not active, reset the state.
            if (not self.active) and (self.state == STATE_ACTIVE):
                self.state = STATE_NORMAL
            Button.notify (self, event)
        else:
            # Any other event will be escalated to the parent(s).
            Button.notify (self, event)