Ejemplo n.º 1
0
class ActuatorFrame(LabelFrame):
    """Provides a bunch of controls for an ActuatorBoard."""
    def __init__(self, master, board, text="Actuators", *args, **kwargs):
        LabelFrame.__init__(self, master, text=text, *args, **kwargs)
        self.board = board
        
        # The listbox contains integers: port numbers we might
        # want to send messages out to through the Board.
        self.listbox = Listbox(self)
        self.listbox.widget.configure(selectmode=EXTENDED)
        self.listbox.grid(row=0, column=0, sticky='nsew')
        for i in range(192, 208, 2):
            self.listbox.add(i)

        self.movement_frame = MovementFrame(self)
        self.movement_frame.grid()

        self.get_status_button = Button(self, text="Get status",
                                        command=bg_caller(self.get_status))
        self.get_status_button.grid()

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)

    def get_status(self):
        for port in self.listbox.get_selected_items():
            status = self.board.get_status(port)
            logger.info("Status of actuator {}: {}".format(port, status))
Ejemplo n.º 2
0
    def __init__(self, master, text="Position", **options):
        LabelFrame.__init__(self, master, text=text, **options)
        self.tracker = master.tracker

        self.listbox = Listbox(self)
        self.listbox.widget.configure(selectmode=SINGLE)
        self.listbox.grid(row=0, column=0, rowspan=6)

        self.name_frame = LabelFrame(self, text="Name")
        self.name_field = Entry(self.name_frame)
        self.name_field.grid()
        self.name_frame.grid(row=0, column=1)

        self.save_button = Button(self, text="Save current",
                                  command=bg_caller(self.save_position))
        self.save_button.grid(row=1, column=1)
        self.go_to_button = Button(self, text="Go to",
                                   command=bg_caller(self.go_to_position))
        self.go_to_button.grid(row=2, column=1)
        self.delete_button = Button(self, text="Delete",
                                    command=self.delete_position)
        self.delete_button.grid(row=3, column=1)
        self.write_button = Button(self, text="Write to file",
                                   command=self.write_to_file)
        self.write_button.grid(row=4, column=1)
        self.load_button = Button(self, text="Load from file",
                                   command=self.load_from_file)
        self.load_button.grid(row=5, column=1)
Ejemplo n.º 3
0
    def __init__(self, master, board, text="Actuators", *args, **kwargs):
        LabelFrame.__init__(self, master, text=text, *args, **kwargs)
        self.board = board
        
        # The listbox contains integers: port numbers we might
        # want to send messages out to through the Board.
        self.listbox = Listbox(self)
        self.listbox.widget.configure(selectmode=EXTENDED)
        self.listbox.grid(row=0, column=0, sticky='nsew')
        for i in range(192, 208, 2):
            self.listbox.add(i)

        self.movement_frame = MovementFrame(self)
        self.movement_frame.grid()

        self.get_status_button = Button(self, text="Get status",
                                        command=bg_caller(self.get_status))
        self.get_status_button.grid()

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
Ejemplo n.º 4
0
class PositionFrame(LabelFrame):
    """Remembers tracker positions."""
    def __init__(self, master, text="Position", **options):
        LabelFrame.__init__(self, master, text=text, **options)
        self.tracker = master.tracker

        self.listbox = Listbox(self)
        self.listbox.widget.configure(selectmode=SINGLE)
        self.listbox.grid(row=0, column=0, rowspan=6)

        self.name_frame = LabelFrame(self, text="Name")
        self.name_field = Entry(self.name_frame)
        self.name_field.grid()
        self.name_frame.grid(row=0, column=1)

        self.save_button = Button(self, text="Save current",
                                  command=bg_caller(self.save_position))
        self.save_button.grid(row=1, column=1)
        self.go_to_button = Button(self, text="Go to",
                                   command=bg_caller(self.go_to_position))
        self.go_to_button.grid(row=2, column=1)
        self.delete_button = Button(self, text="Delete",
                                    command=self.delete_position)
        self.delete_button.grid(row=3, column=1)
        self.write_button = Button(self, text="Write to file",
                                   command=self.write_to_file)
        self.write_button.grid(row=4, column=1)
        self.load_button = Button(self, text="Load from file",
                                   command=self.load_from_file)
        self.load_button.grid(row=5, column=1)

    def save_position(self):
        """Records the tracker's current position."""
        response = self.tracker.measure()[0]
        if response.status != response.DATA_ACCURATE:
            logger.error("Data taken were not accurate.")
            return

        name = self.name_field.get()
        self.listbox.add(response.position, name)
        logger.info("Saved {} as {}".format(response.position, name))
    
    def go_to_position(self):
        """Moves the tracker to the selected position."""
        selection = self.listbox.get_selected_items()
        names = self.listbox.get_selected_names()
        if len(selection) > 0:
            r, theta, phi = selection[0]
            name = names[0]
            self.tracker.move_absolute(r, theta, phi)
            logger.info("Moved tracker to {name!r} ({posn})"
                        .format(name=name, posn=(r, theta, phi)))
        else:
            logger.error("Must select a position to go to.")
        

    def delete_position(self):
        """Deletes the selected position."""
        self.listbox.remove_selected()

    def write_to_file(self):
        filename = tkFileDialog.asksaveasfilename(initialdir=nodes_dir)
        if filename:
            nodes.io.save(self.listbox.names_to_items, filename)
            logger.info("Wrote current node list to {!r}".format(filename))
    def load_from_file(self):
        filename = tkFileDialog.askopenfilename(initialdir=nodes_dir)
        if filename:
            self.listbox.clear()
            for (key, value) in nodes.io.load(filename).items():
                self.listbox.add(item=value, name=key)
            logger.info("Loaded node list from {!r}".format(filename))