コード例 #1
0
    def _load_photo(self, filename):

        the_image = tk.PhotoImage(file=filename).subsample(
            MOTORS_IMAGE_SCALEDOWN, MOTORS_IMAGE_SCALEDOWN)
        the_label = tk.Label(self.driver.canvas,
                             image=the_image,
                             borderwidth=0)
        the_label.bind('<Button-1>', self._on_click)
        return the_image, the_label
コード例 #2
0
    def __init__(self, driver):

        Dialog.__init__(self, driver)

        # Add a quadcopter image for motor testing
        (self.image_motors,
         self.label_motors) = self._load_photo(MOTORS_IMAGE_FILE)
        (self.image_motors1,
         self.label_motors1) = self._load_photo(MOTORS1_IMAGE_FILE)
        (self.image_motors2,
         self.label_motors2) = self._load_photo(MOTORS2_IMAGE_FILE)
        (self.image_motors3,
         self.label_motors3) = self._load_photo(MOTORS3_IMAGE_FILE)
        (self.image_motors4,
         self.label_motors4) = self._load_photo(MOTORS4_IMAGE_FILE)

        # Add a warning checkbox for motor testing
        self.checkbox_var = tk.IntVar()
        self.warning_motors = tk.Checkbutton(self.driver.canvas, \
                variable=self.checkbox_var, command=self._checkbox_callback, \
                text=MOTORS_WARNING_TEXT, font=('Heletica', 14),  fg='red', bg='black', highlightthickness=0)

        # A a scale for motors
        self.scale = tk.Scale(self.driver.canvas,
                              from_=100,
                              to_=0,
                              command=self._scale_callback,
                              orient=tk.VERTICAL,
                              length=MOTOR_SCALE_LENGTH,
                              bg='black',
                              fg='white')

        # A label for the scale
        self.scale_label = tk.Label(self.driver.canvas,
                                    text='%',
                                    bg='black',
                                    fg='white')

        # Index of active motor (0 = none)
        self.active_motor = 0
コード例 #3
0
ファイル: hackflight.py プロジェクト: wangdongnwpu/Hackflight
    def __init__(self):

        msppg.Parser.__init__(self)

        # No communications or arming yet
        self.comms = None
        self.armed = False
        self.gotimu = False

        # Do basic Tk initialization
        self.root = tk.Tk()
        self.root.configure(bg=BACKGROUND_COLOR)
        self.root.resizable(False, False)
        self.root.title('Hackflight Ground Control Station')
        left = (self.root.winfo_screenwidth() - DISPLAY_WIDTH) / 2
        top = (self.root.winfo_screenheight() - DISPLAY_HEIGHT) / 2
        self.root.geometry('%dx%d+%d+%d' %
                           (DISPLAY_WIDTH, DISPLAY_HEIGHT, left, top))
        self.frame = tk.Frame(self.root)

        # Too much hassle on Windows
        if 'nt' != os.name:
            self.root.tk.call('wm', 'iconphoto', self.root._w,
                              tk.PhotoImage('icon.xbm'))

        self.root.protocol('WM_DELETE_WINDOW', self.quit)

        # Create panes for two rows of widgets
        self.pane1 = self._add_pane()
        self.pane2 = self._add_pane()

        # Add a buttons
        self.button_connect = self._add_button('Connect', self.pane1,
                                               self._connect_callback)
        self.button_imu = self._add_button('IMU', self.pane2,
                                           self._imu_callback)
        self.button_motors = self._add_button('Motors', self.pane2,
                                              self._motors_button_callback)
        self.button_receiver = self._add_button('Receiver', self.pane2,
                                                self._receiver_button_callback)
        #self.button_messages = self._add_button('Messages', self.pane2, self._messages_button_callback)
        #self.button_maps = self._add_button('Maps', self.pane2, self._maps_button_callback, disabled=False)

        # Prepare for adding ports as they are detected by our timer task
        self.portsvar = tk.StringVar(self.root)
        self.portsmenu = None
        self.connected = False
        self.ports = []

        # Finalize Tk stuff
        self.frame.pack()
        self.canvas = tk.Canvas(self.root,
                                width=DISPLAY_WIDTH,
                                height=DISPLAY_HEIGHT,
                                background='black')
        self.canvas.pack()

        # Set up a text label for reporting errors
        errmsg = 'No response from board.  Possible reasons:\n\n' + \
                 '    * You connected to the wrong port.\n\n' + \
                 '    * Firmware uses serial receiver\n' + \
                 '      (DSMX, SBUS), but receiver is\n' + \
                 '      not connected.'
        self.error_label = tk.Label(self.canvas,
                                    text=errmsg,
                                    bg='black',
                                    fg='red',
                                    font=(None, 24),
                                    justify=tk.LEFT)
        self.hide(self.error_label)

        # Add widgets for motor-testing dialog; hide them immediately
        self.motors = Motors(self)
        self.motors.stop()

        # Create receiver dialog
        self.receiver = Receiver(self)

        # Create messages dialog
        #self.messages = Messages(self)

        # Create IMU dialog
        self.imu = IMU(self)
        self._schedule_connection_task()

        # Create a maps dialog
        #self.maps = Maps(self, yoffset=-30)

        # Create a splash image
        self.splashimage = tk.PhotoImage(file=resource_path('splash.gif'))
        self._show_splash()

        # Create a message parser
        #self.parser = msppg.Parser()

        # Set up parser's request strings
        self.attitude_request = msppg.serialize_ATTITUDE_RADIANS_Request()
        self.rc_request = msppg.serialize_RC_NORMAL_Request()

        # No messages yet
        self.roll_pitch_yaw = [0] * 3
        self.rxchannels = [0] * 6

        # A hack to support display in IMU dialog
        self.active_axis = 0