def c_openAutoPreset(self, dropDownItem, file):
        if file.get_key() is None:
            print("No file selected")
            return
        # file should be blank because it will delete everything in it when it is opened
        self.robot.autoScheduler.actionList.clear()
        with open(file.get_key(), "r") as presetFile:
            try:
                preset = json.load(presetFile)
            except:
                print("File is empty")
                return
            for action in preset:
                coord = None
                if action["coord"] != []:
                    if action["key"] != "bezier":
                        # creates a field coordinate
                        coord = coordinates.FieldCoordinate(
                            action["coord"][0], action["coord"][1],
                            action["coord"][2], action["coord"][3])
                    else:
                        # loops through and makes a list of coordinates
                        coord = []
                        for point in action["coord"]:
                            coord.append(
                                coordinates.FieldCoordinate(
                                    point[0], point[1], point[2], point[3]))

                self.c_addGenericAction(self.genericActionList, action["key"],
                                        coord)

        self.updateSchedulerFlag = True
        self.updatePresetFileDropdown()
def createRotateInPlaceAction(pathFollower, coord):
    newCoord = coordinates.FieldCoordinate("Rotated", pathFollower.robotX,
                                           pathFollower.robotY, coord.angle)

    return Action("Rotate to " + newCoord.name,
                  lambda: driveToPoint(pathFollower, newCoord, 0.5, True),
                  "rotate", newCoord)
 def mouse_down_listener(self, widget, x, y):
     x, y = svgToFieldCoordinates(x, y, self.fieldWidth, self.fieldHeight,
                                  self.fieldPixelsPerFoot)
     self.selectedCoord = coordinates.FieldCoordinate(
         "Selected", x, y, self.selectedCoord.angle)
     for point in self.targetPoints:
         if math.hypot(x - point.x, y - point.y) < 1:
             self.selectedCoord = point
     self.updateCursorPosition()
def createRotateTowardsPointAction(robot, coord):

    # calculates the angle to rotate to be
    # facing at the point coord
    xDiff = coord.x - robot.pathFollower.robotX
    yDiff = coord.y - robot.pathFollower.robotY
    angle = math.atan2(yDiff, xDiff) - math.pi / 2

    newCoord = coordinates.FieldCoordinate("Rotated",
                                           robot.pathFollower.robotX,
                                           robot.pathFollower.robotY, angle)

    return Action("Rotate towards " + newCoord.name,
                  lambda: rotateTowardsPoint(robot, newCoord), "face",
                  newCoord)
    def initFieldMap(self, robot):
        fieldBox = self.sectionBox()

        robotBox = gui.HBox()
        fieldBox.append(robotBox)

        setPositionBtn = gui.Button("Set Robot to Cursor")
        setPositionBtn.set_on_click_listener(self.c_setRobotPosition)
        robotBox.append(setPositionBtn)

        setRotationBtn = gui.Button("Point Robot at Cursor")
        setRotationBtn.set_on_click_listener(self.c_pointAtCursor)
        robotBox.append(setRotationBtn)

        def setCursorAngle(button, angle):
            self.selectedCoord.angle = angle
            self.updateCursorPosition()

        leftBtn = gui.Button('<')
        leftBtn.set_on_click_listener(setCursorAngle, math.radians(90))
        robotBox.append(leftBtn)
        rightBtn = gui.Button('>')
        rightBtn.set_on_click_listener(setCursorAngle, math.radians(-90))
        robotBox.append(rightBtn)
        upBtn = gui.Button('^')
        upBtn.set_on_click_listener(setCursorAngle, 0)
        robotBox.append(upBtn)
        downBtn = gui.Button('v')
        downBtn.set_on_click_listener(setCursorAngle, math.radians(180))
        robotBox.append(downBtn)

        self.fieldSvg = gui.Svg()
        self.makeField('/res:field.png', True)
        fieldBox.append(self.fieldSvg)

        self.robotPathLines = []

        self.selectedCoord = coordinates.FieldCoordinate(
            "Center", 0, 0, math.radians(-90))
        self.updateCursorPosition()

        return fieldBox