示例#1
0
    def mouse_pressed(self, event):
        for button in self.buttons:
            # check if the button has been clicked on
            if button.contains(event.x, event.y):
                if button.bType == 0:
                    action = Action.MoveAction(
                        self.canvas, button.x, button.y, 100, 125,
                        button.color, button.textString)  # create new action
                elif button.bType == 1:
                    action = Action.BodyAction(self.canvas, button.x, button.y,
                                               100, 125, button.color,
                                               button.textString)
                elif button.bType == 2:
                    action = Action.HeadAction(self.canvas, button.x, button.y,
                                               100, 125, button.color,
                                               button.textString)
                elif button.bType == 3:
                    action = Action.VoiceAction(self.canvas, button.x,
                                                button.y, 100, 125,
                                                button.color,
                                                button.textString, self.server)

                elif button.bType == 4:
                    action = Action.ListenAction(self.canvas, button.x,
                                                 button.y, 100, 125,
                                                 button.color,
                                                 button.textString,
                                                 self.server)

                action.clicked = True  # set that the action has been clicked
                self.actions.append(action)  # add action to list

        for action in self.actions:
            # check if the action has been clicked on
            click_location = action.click_location(event.x, event.y)
            if click_location == 3:
                action.clicked = True  # set that the action is clicked

                for box in self.boxes:
                    # check if an action within the box has been clicked
                    if box.contains(event.x, event.y):
                        box.action = None  # set the box is no longer filled
            elif click_location == 1 and not action.clicked:  # if the up button is clicked
                action.change_setting(1, self.canvas)
            elif click_location == 2 and not action.clicked:  # if the down button is clicked
                action.change_setting(0, self.canvas)

        # if the play button was pressed
        if self.startButton.contains(event.x, event.y):
            self.run_program()