示例#1
0
class MovementFrame(LabelFrame):
    """Has controls for aiming the laser tracker."""
    def __init__(self, master, text="Movement", **options):
        LabelFrame.__init__(self, master, text=text, **options)
        self.tracker = master.tracker

        self.coordinate_frame = NamedEntryFrame(self, ("Radius", "Theta",
                                                       "Phi"),
                                                parsers={"Radius": float,
                                                         "Theta": float,
                                                         "Phi": float})
        self.coordinate_frame.grid(row=0, column=0, rowspan=3)

        self.search_button = Button(self, text="Search",
                                    command=bg_caller(self.search))
        self.search_button.grid(row=0, column=1)
        self.move_button = Button(self, text="Move",
                                  command=bg_caller(self.move_tracker))
        self.move_button.grid(row=1, column=1)
        self.move_absolute_button = Button(self, text="Move (absolute)",
                                           command=bg_caller(self.move_absolute))
        self.move_absolute_button.grid(row=2, column=1)
                    
    def move_tracker(self):
        try:
            coords = self.coordinate_frame.get_all()
        except ValueError as e:
            logger.error("Parsing error: {}".format(e.message))
            return

        r, theta, phi = coords["Radius"], coords["Theta"], coords["Phi"]
        self.tracker.move(r, theta, phi)
        logger.info("Moved tracker by {}".format((r, theta, phi)))

    def move_absolute(self):
        try:
            coords = self.coordinate_frame.get_all()
        except ValueError as e:
            logger.error("Parsing error: {}".format(e.message))
            return

        r, theta, phi = coords["Radius"], coords["Theta"], coords["Phi"]
        self.tracker.move_absolute(r, theta, phi)
        logger.info("Moved tracker to {}".format((r, theta, phi)))

    def search(self):
        try:
            r = self.coordinate_frame.get("Radius")
        except ValueError:
            logger.error("Couldn't parse radius field.")
            return

        self.tracker.search(r)
        logger.info("Searched with radius {}".format(r))