def __init__(self):  #the __init__ method inside a class is its constructor

        self.Text = "AU London"  #text that appears in the GUI titlebar
        self.Icon = Icon.FromHandle(
            icon.GetHicon()
        )  #takes a bitmap image and converts to a file that can be used as a Icon for the titlebar
        self.BackColor = Color.FromArgb(255, 255, 255)

        self.WindowState = FormWindowState.Normal  # set maximised minimised or normal size GUI
        self.CenterToScreen()  # centres GUI to the middle of your screen
        self.BringToFront()  #brings the GUI to the front of all opens windows.
        self.Topmost = True  # true to display the GUI infront of any other active forms

        screenSize = Screen.GetWorkingArea(
            self
        )  #get the size of the computers main screen, as the form will scale differently to different sized screens
        self.Width = screenSize.Width / 4  #set the size of the form based on the size of the users screen. this helps to ensure consistant look across different res screens.
        self.Height = screenSize.Height / 4
        uiWidth = self.DisplayRectangle.Width  #get the size of the form to use to scale form elements
        uiHeight = self.DisplayRectangle.Height

        #self.FormBorderStyle = FormBorderStyle.FixedDialog      # fixed dialog stops the user from adjusting the form size. Recomended disabling this when testing to see if elements are in the wrong place.

        self.userOutput = userOutputDefaultStr  #create a container to store the output from the form
        self.runNextOutput = False  #set these default values

        #############-------------\-------------#############
        spacing = 10  #spacing size for GUI elements to form a consistent border

        # creates the text box for a info message
        userMessage = Label()  #label displays texts
        font = Font("Helvetica ", 10)
        userMessage.Text = message
        userMessage.Font = font
        userMessage.Location = Point(
            spacing, spacing
        )  #all location require a point object from system.Drawing to set the location.
        userMessage.Size = Size(
            uiWidth - (spacing * 2), (uiHeight / 4)
        )  #size the control with the width of the GUI to ensure it scales with different screen
        self.Controls.Add(userMessage)  #this adds control element to the GUI

        #############-------------\-------------#############
        #logo file
        logo = PictureBox()
        logo.Image = logoFile
        ratio = float(logo.Height) / float(
            logo.Width
        )  #needs to be a float as int will round to the nearest whole number
        logo.Size = Size(
            uiWidth / 4, (uiHeight / 4) * ratio
        )  #scale the image by the ratio between the images height & width
        logo.Location = Point(spacing, (uiHeight - logo.Height) - spacing)
        logo.SizeMode = PictureBoxSizeMode.Zoom  # zooms the image to fit the extent
        logo.Anchor = (
            AnchorStyles.Bottom | AnchorStyles.Left
        )  #anchor styles lock elements to a given corner of the GUI if you allow users change size
        self.Controls.Add(logo)
        #logo.BorderStyle = BorderStyle.Fixed3D    #gives a border to the panel to test its location

        #############-------------\-------------#############

        #combox drop down
        cBox = ComboBox()  #dropdown control form
        cBox.Location = Point(spacing, uiHeight / 3)
        cBox.Width = uiWidth - (spacing * 2)
        cBox.Items.AddRange(
            listInput
        )  # Adds an array of items to the list of items for a ComboBox.
        cBox.DropDownStyle = ComboBoxStyle.DropDownList  #setting to dropdown list prevents users from being able to add aditional text values
        cBox.SelectedIndexChanged += self.dropDownOutput  #.Click+= registers the press of the button to register the event handler and determine what action takes place when button clicked
        self.Controls.Add(cBox)

        #############-------------\-------------#############

        #Create ok button
        btnOk = Button()  #create a button control
        btnOk.Text = "Next"
        btnOk.Location = Point(uiWidth - ((btnOk.Width * 2) + spacing),
                               uiHeight - (btnOk.Height + spacing))
        btnOk.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right)
        btnOk.Click += self.okButtonPressed  #Register the event on the button bress to trigger the def okButtonPressed
        self.Controls.Add(btnOk)

        #Create Cancel Button
        btnCancel = Button()
        #btnCancel.Parent = self
        btnCancel.Text = "Cancel"
        btnCancel.Location = Point(uiWidth - (btnOk.Width + spacing),
                                   uiHeight - (btnOk.Height + spacing))
        btnCancel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right)
        btnCancel.Click += self.CnlButtonPressed
        self.Controls.Add(btnCancel)
示例#2
0
if isinstance(IN[1], list):
    inputtypes = IN[1]
else:
    inputtypes = [IN[1]]

for i, j in zip(inputnames, inputtypes):
    label = Label()
    label.Location = Point(xlabel, y + 4 * resfactY)
    label.Height = 20 * resfactY
    label.Width = 80 * resfactX
    label.Text = str(i)
    form.Controls.Add(label)
    if isinstance(j, list):
        cb = ComboBox()
        cb.Location = Point(xinput, y)
        cb.Width = 150 * resfactX
        globals()['dict%d' % (cbindex)] = {}
        try:
            for k in j:
                globals()['dict%d' % (cbindex)][k.Name] = k
                cb.Items.Add(k.Name)
        except:
            for k in j:
                try:
                    globals()['dict%d' % (cbindex)][str(k)] = k
                except:
                    globals()['dict%d' %
                              (cbindex)][k.encode('utf-8').decode('utf-8')] = k
                cb.Items.Add(k)
        form.Controls.Add(cb)
        form.output.append(cb)
示例#3
0
    def __init__(self):
        self.received_messages = {}
        self.msg_ids = {}

        self.config = None
        self.num_messages = DEFAULT_NUM_MESSAGES
        if path.exists(CONFIG_FILENAME):
            print('Reading config...')
            self.config = open(CONFIG_FILENAME, 'r').readlines()
            for x in range(len(self.config)):
                self.config[x] = self.config[x].strip('\n')
            self.num_messages = int(self.config[0].split(',')[0])

        # we subscribe to every possible MAVLink message here
        # super inefficient, but much easier to just collect 'em all!
        for attr_name in dir(MAVLink.MAVLINK_MSG_ID):
            if attr_name.upper() == attr_name:
                attr = getattr(MAVLink.MAVLINK_MSG_ID, attr_name)
                self.msg_ids[attr.value__] = attr
                MAV.SubscribeToPacketType(
                    attr, Func[MAVLink.MAVLinkMessage,
                               bool](self.get_message_data))
        MAV.OnPacketReceived += self.packet_handler

        self.Text = 'MAVLink MinMonitor'
        self.Location = Point(0, 0)
        self.TopMost = True
        self.BackColor = CustomColor.MPDarkGray
        self.ForeColor = CustomColor.White
        self.Shown += self.on_load
        self.FormClosing += self.on_exit

        self.margin = 5
        start_x, start_y = 12, 10

        self.msg_widgets = []
        for x in range(self.num_messages):
            cbo_msg_id = ComboBox()
            cbo_msg_id.Width = 175
            cbo_msg_id.DropDownStyle = ComboBoxStyle.DropDown
            cbo_msg_id.FlatStyle = FlatStyle.Flat
            cbo_msg_id.BackColor = CustomColor.MPLightGray
            cbo_msg_id.ForeColor = CustomColor.White
            cbo_msg_id.DataSource = self.received_messages.keys()
            cbo_msg_id.MouseDown += self.update_message_ids
            cbo_msg_id.SelectionChangeCommitted += self.update_datasource
            cbo_msg_id.Text = ''

            cbo_msg_dataframes = ComboBox()
            cbo_msg_dataframes.Width = 120
            cbo_msg_dataframes.DropDownStyle = ComboBoxStyle.DropDown
            cbo_msg_dataframes.FlatStyle = FlatStyle.Flat
            cbo_msg_dataframes.BackColor = CustomColor.MPLightGray
            cbo_msg_dataframes.ForeColor = CustomColor.White
            cbo_msg_dataframes.Text = ''

            lbl_data = Label()
            lbl_data.Text = 'NO DATA'
            lbl_data.BackColor = CustomColor.MPMediumGray
            lbl_data.Width = 120
            lbl_data.Height = cbo_msg_id.Height - 5

            txt_min = TextBox()
            txt_min.Width = 75
            txt_min.BorderStyle = BorderStyle.FixedSingle
            txt_min.BackColor = CustomColor.MPLightGray
            txt_min.ForeColor = CustomColor.White
            txt_min.MaxLength = 10
            txt_min.TextAlign = HorizontalAlignment.Center
            txt_min.KeyPress += self.limit_to_decimal_digits

            txt_max = TextBox()
            txt_max.Width = 75
            txt_max.BorderStyle = BorderStyle.FixedSingle
            txt_max.BackColor = CustomColor.MPLightGray
            txt_max.ForeColor = CustomColor.White
            txt_max.MaxLength = 10
            txt_max.TextAlign = HorizontalAlignment.Center
            txt_max.KeyPress += self.limit_to_decimal_digits

            txt_factor = TextBox()
            txt_factor.Width = 75
            txt_factor.BorderStyle = BorderStyle.FixedSingle
            txt_factor.BackColor = CustomColor.MPLightGray
            txt_factor.ForeColor = CustomColor.White
            txt_factor.MaxLength = 10
            txt_factor.TextAlign = HorizontalAlignment.Center
            txt_factor.KeyPress += self.limit_to_decimal_digits

            self.msg_widgets.append(
                OrderedDict([('cbo_msg_id', cbo_msg_id),
                             ('cbo_msg_dataframes', cbo_msg_dataframes),
                             ('lbl_data', lbl_data), ('txt_min', txt_min),
                             ('txt_max', txt_max),
                             ('txt_factor', txt_factor)]))

        self.lbl_min = Label()
        self.lbl_min.Text = 'Min'
        self.lbl_min.BackColor = CustomColor.MPDarkGray
        self.lbl_min.Width = self.msg_widgets[0]['txt_min'].Width
        self.lbl_min.Height = self.msg_widgets[0]['txt_min'].Height - 5

        self.lbl_max = Label()
        self.lbl_max.Text = 'Max'
        self.lbl_max.BackColor = CustomColor.MPDarkGray
        self.lbl_max.Width = self.msg_widgets[0]['txt_max'].Width
        self.lbl_max.Height = self.msg_widgets[0]['txt_max'].Height - 5

        self.lbl_factor = Label()
        self.lbl_factor.Text = 'Factor'
        self.lbl_factor.BackColor = CustomColor.MPDarkGray
        self.lbl_factor.Width = self.msg_widgets[0]['txt_factor'].Width
        self.lbl_factor.Height = self.msg_widgets[0]['txt_factor'].Height - 5

        self.lbl_num_messages = Label()
        self.lbl_num_messages.Text = 'Number of messages to monitor (restart to take effect)'
        self.lbl_num_messages.BackColor = CustomColor.MPDarkGray
        self.lbl_num_messages.AutoSize = True

        self.spn_num_messages = NumericUpDown()
        self.spn_num_messages.Width = 40
        self.spn_num_messages.BorderStyle = BorderStyle.FixedSingle
        self.spn_num_messages.BackColor = CustomColor.MPLightGray
        self.spn_num_messages.ForeColor = CustomColor.White
        self.spn_num_messages.Value = self.num_messages

        self.chk_hide_factors = CheckBox()
        self.chk_hide_factors.FlatAppearance.BorderSize = 1
        self.chk_hide_factors.FlatAppearance.BorderColor = CustomColor.MPLightGray
        self.chk_hide_factors.Text = 'Hide threshold/scaling preferences'
        self.chk_hide_factors.AutoSize = True

        self.chk_sticky = CheckBox()
        self.chk_sticky.FlatAppearance.BorderSize = 1
        self.chk_sticky.FlatAppearance.BorderColor = CustomColor.MPLightGray
        self.chk_sticky.Text = 'Always on top'
        self.chk_sticky.AutoSize = True

        self.lbl_status = Label()
        self.lbl_status.Text = 'No messages received'
        self.lbl_status.BackColor = CustomColor.MPMediumGray
        self.lbl_status.Height = self.msg_widgets[0]['txt_min'].Height - 5

        # pseudo-responsive form layout
        x, y = start_x, start_y
        max_x = 0
        x = start_x + (self.msg_widgets[0]['cbo_msg_id'].Width +
                       self.msg_widgets[0]['cbo_msg_dataframes'].Width +
                       self.msg_widgets[0]['lbl_data'].Width) + self.margin * 4
        x, y, x_extent = \
            self.add_control_horizontal(self.lbl_min, x, y, self.margin)
        x, y, x_extent = \
            self.add_control_horizontal(self.lbl_max, x, y, self.margin)
        x, y, x_extent = \
            self.add_control_vertical(self.lbl_factor, x, y, self.margin)
        for widget in self.msg_widgets:
            x = start_x
            for control in widget.items():
                x, y, x_extent = self.add_control_horizontal(
                    control[1], x, y, self.margin)
            max_x = max([x_extent, max_x])
            y += widget.items()[0][1].Height + self.margin
        self.Width = max_x + self.margin * 4
        self.WideWidth = self.Width
        self.NarrowWidth = self.msg_widgets[0]['lbl_data'].Location.X + \
                           self.msg_widgets[0]['lbl_data'].Width + self.margin * 5
        y += 20
        x, y, x_extent = self.add_control_horizontal(self.spn_num_messages,
                                                     start_x, y, self.margin)
        x, y, x_extent = self.add_control_vertical(self.lbl_num_messages, x,
                                                   y + 3, self.margin)
        x, y, x_extent = self.add_control_vertical(self.chk_hide_factors,
                                                   start_x + 3, y + 5,
                                                   self.margin)
        x, y, x_extent = self.add_control_vertical(self.chk_sticky, x, y,
                                                   self.margin)
        self.lbl_status.Width = self.Width - self.margin * 7
        x, y, x_extent = self.add_control_vertical(self.lbl_status, start_x,
                                                   y + 3, self.margin)
        self.Height = y + self.lbl_status.Height + self.margin * 5