Ejemplo n.º 1
0
    def InitUI(self):
        color = wx.Colour()
        color.SetFromString(DARK_BACKGROUND)
        self.SetBackgroundColour(scale_color(color, .9))

        cols = 2 if len(self.mavlink_messages) > 1 else 1
        compass_sizer = wx.GridSizer(0, cols, 2, 2)

        self.compass_panels = []
        for m in self.mavlink_messages:
            p = self.CompassPanel(self, m)
            compass_sizer.Add(p)
            self.compass_panels.append(p)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        sizer.Add(compass_sizer)
        sizer.Add(self.Footer(), flag=wx.EXPAND)
        sizer.Fit(self)
        def InitUI(self):
            color = wx.Colour()
            color.SetFromString(LIGHT_BACKGROUND)
            self.SetBackgroundColour(scale_color(color, 0.95))

            font = self.GetFont()
            font.SetWeight(wx.FONTWEIGHT_BOLD)
            font.SetPointSize(24)
            self.SetFont(font)

            self.SetMinSize((400, -1))

            self.compass_text = wx.StaticText(self)

            self.fitness_value_text = wx.StaticText(self)
            font.SetWeight(wx.FONTWEIGHT_NORMAL)
            self.fitness_value_text.SetFont(font)

            self.parameters_sizer = self.CalibrationParameters()

            fitness_sizer = wx.BoxSizer(wx.HORIZONTAL)
            text = wx.StaticText(self, label='Fitness')
            text.SetFont(self.fitness_value_text.GetFont())
            fitness_sizer.Add(text, proportion=1, flag=wx.EXPAND)
            fitness_sizer.Add(self.fitness_value_text)

            sizer = wx.BoxSizer(wx.VERTICAL)
            self.SetSizer(sizer)
            sizer.AddSpacer(16)
            sizer.Add(self.compass_text, border=16, flag=wx.LEFT | wx.RIGHT)
            sizer.AddSpacer(16)
            sizer.Add(self.StatusPanel(), flag=wx.EXPAND)
            sizer.AddSpacer(16)
            sizer.Add(fitness_sizer,
                      border=16,
                      flag=wx.LEFT | wx.RIGHT | wx.EXPAND)
            sizer.AddSpacer(16)
            sizer.Add(self.parameters_sizer,
                      border=16,
                      flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND)

            sizer.Hide(self.parameters_sizer)
Ejemplo n.º 3
0
def scale_color(color, scale):
    r, g, b = color
    r, g, b = round(scale * r), round(scale * g), round(scale * b)
    r, g, b = min(255, r), min(255, g), min(255, b)
    return wx.Colour(r, g, b)
Ejemplo n.º 4
0
class ReportDialog(wx.Dialog):
    light_background = wx.Colour()
    light_background.SetFromString(LIGHT_BACKGROUND)
    light_background = scale_color(light_background, 1.2)

    class StatusIcon(wx.PyWindow):
        success_color = '#00ed00'
        failure_color = '#d81313'

        def __init__(self, *k, **kw):
            super(ReportDialog.StatusIcon, self).__init__(*k, **kw)
            self.success = True
            self.Bind(wx.EVT_PAINT, self.OnPaint)

        def Success(self, success):
            self.success = success
            self.Refresh()

        def OnPaint(self, evt):
            dc = wx.BufferedPaintDC(self)
            self.Draw(dc)

        def Draw(self, dc):
            width, height = self.GetClientSize()
            if not width or not height:
                return

            gcdc = wx.GCDC(dc)

            gcdc.SetPen(wx.NullPen)

            bg = self.GetParent().GetBackgroundColour()
            gcdc.SetBackground(wx.Brush(bg, wx.SOLID))
            gcdc.Clear()

            color = self.success_color if self.success else self.failure_color
            gcdc.SetBrush(wx.Brush(color))

            x = width / 2
            y = height / 2
            gcdc.DrawCircle(x, y, min(x, y))

    class CompassPanel(Panel):
        def __init__(self, parent, m, *k, **kw):
            super(ReportDialog.CompassPanel, self).__init__(parent, *k, **kw)

            self.InitUI()

            self.compass_text.SetLabel('Compass %d' % m.compass_id)

            if m.cal_status == mavlink.MAG_CAL_SUCCESS:
                self.status_icon.Success(True)
                self.status_text.SetLabel('SUCCESS')
            else:
                self.status_icon.Success(False)
                self.status_text.SetLabel('FAILURE')

            self.fitness_value_text.SetLabel('%.3f' % m.fitness)

            texts = (
                self.offsets_texts,
                self.diagonals_texts,
                self.offdiagonals_texts,
            )
            params = (
                (m.ofs_x, m.ofs_y, m.ofs_z),
                (m.diag_x, m.diag_y, m.diag_z),
                (m.offdiag_x, m.offdiag_y, m.offdiag_z),
            )
            for targets, values in zip(texts, params):
                for target, value in zip(targets, values):
                    target.SetLabel('%.2f' % value)

        def InitUI(self):
            color = wx.Colour()
            color.SetFromString(LIGHT_BACKGROUND)
            self.SetBackgroundColour(scale_color(color, 0.95))

            font = self.GetFont()
            font.SetWeight(wx.FONTWEIGHT_BOLD)
            font.SetPointSize(24)
            self.SetFont(font)

            self.SetMinSize((400, -1))

            self.compass_text = wx.StaticText(self)

            self.fitness_value_text = wx.StaticText(self)
            font.SetWeight(wx.FONTWEIGHT_NORMAL)
            self.fitness_value_text.SetFont(font)

            self.parameters_sizer = self.CalibrationParameters()

            fitness_sizer = wx.BoxSizer(wx.HORIZONTAL)
            text = wx.StaticText(self, label='Fitness')
            text.SetFont(self.fitness_value_text.GetFont())
            fitness_sizer.Add(text, proportion=1, flag=wx.EXPAND)
            fitness_sizer.Add(self.fitness_value_text)

            sizer = wx.BoxSizer(wx.VERTICAL)
            self.SetSizer(sizer)
            sizer.AddSpacer(16)
            sizer.Add(self.compass_text, border=16, flag=wx.LEFT | wx.RIGHT)
            sizer.AddSpacer(16)
            sizer.Add(self.StatusPanel(), flag=wx.EXPAND)
            sizer.AddSpacer(16)
            sizer.Add(fitness_sizer, border=16, flag=wx.LEFT | wx.RIGHT | wx.EXPAND)
            sizer.AddSpacer(16)
            sizer.Add(self.parameters_sizer, border=16, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND)

            sizer.Hide(self.parameters_sizer)

        def StatusPanel(self):
            panel = Panel(self)

            panel.SetBackgroundColour(ReportDialog.light_background)

            self.status_icon = ReportDialog.StatusIcon(panel, size=(44, 44))
            self.status_text = wx.StaticText(panel)

            sizer = wx.BoxSizer(wx.HORIZONTAL)
            panel.SetSizer(sizer)
            sizer.AddSpacer(16)
            sizer.Add(self.status_icon, border=5, flag=wx.TOP | wx.BOTTOM)
            sizer.AddSpacer(16)
            sizer.Add(self.status_text, flag=wx.ALIGN_CENTER)
            sizer.AddSpacer(16)

            return panel

        def CalibrationParameters(self):
            self.offsets_texts = tuple(wx.StaticText(self) for _ in range(3))
            self.diagonals_texts = tuple(wx.StaticText(self) for _ in range(3))
            self.offdiagonals_texts = tuple(wx.StaticText(self) for _ in range(3))

            table = (
                ('Offsets', self.offsets_texts),
                ('Diagonals', self.diagonals_texts),
                ('Off-diagonals', self.offdiagonals_texts),
            )

            sizer = wx.FlexGridSizer(len(table) + 1, 4, 4, 10)
            sizer.AddGrowableCol(0)

            font = self.GetFont()
            font.SetPointSize(14)
            font.MakeItalic()

            text = wx.StaticText(self, label='Parameter')
            text.SetFont(font)
            sizer.Add(text)
            for label in ('X', 'Y', 'Z'):
                text = wx.StaticText(self, label=label)
                text.SetFont(font)
                sizer.Add(text, flag=wx.ALIGN_CENTER)

            font.SetWeight(wx.FONTWEIGHT_NORMAL)

            for label, (x, y, z) in table:
                text = wx.StaticText(self)
                text.SetLabel(label)

                text.SetFont(font)
                x.SetFont(font)
                y.SetFont(font)
                z.SetFont(font)

                sizer.Add(text)
                sizer.Add(x, flag=wx.ALIGN_RIGHT)
                sizer.Add(y, flag=wx.ALIGN_RIGHT)
                sizer.Add(z, flag=wx.ALIGN_RIGHT)

            return sizer

        def ShowCompassParameters(self, show):
            sizer = self.GetSizer()
            if show:
                sizer.Show(self.parameters_sizer)
            else:
                sizer.Hide(self.parameters_sizer)

    def __init__(self, parent, mavlink_messages, *k, **kw):
        super(ReportDialog, self).__init__(parent, *k, **kw)

        self.compass_parameters_shown = False
        self.mavlink_messages = mavlink_messages

        for m in self.mavlink_messages:
            if m.cal_status != mavlink.MAG_CAL_SUCCESS:
                self.success = False
                break
        else:
            self.success = True

        self.InitUI()

    def InitUI(self):
        color = wx.Colour()
        color.SetFromString(DARK_BACKGROUND)
        self.SetBackgroundColour(scale_color(color, .9))

        cols = 2 if len(self.mavlink_messages) > 1 else 1
        compass_sizer = wx.GridSizer(0, cols, 2, 2)

        self.compass_panels = []
        for m in self.mavlink_messages:
            p = self.CompassPanel(self, m)
            compass_sizer.Add(p)
            self.compass_panels.append(p)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        sizer.Add(compass_sizer)
        sizer.Add(self.Footer(), flag=wx.EXPAND)
        sizer.Fit(self)

    def Footer(self):
        footer = Panel(self)

        footer.SetBackgroundColour(ReportDialog.light_background)

        font = footer.GetFont()
        font.SetPointSize(16)
        font.SetWeight(wx.FONTWEIGHT_BOLD)
        footer.SetFont(font)

        self.show_more_button = Button(footer)
        self.show_more_button.SetLabel('Show more')
        self.show_more_button.SetBackgroundColour(wx.TransparentColour)

        self.Bind(wx.EVT_BUTTON, self.OnShowMoreButton, self.show_more_button)

        if not self.success:
            self.try_again_button = Button(footer, wx.ID_REDO)
            self.try_again_button.SetLabel('TRY AGAIN')
            self.try_again_button.SetBackgroundColour(wx.TransparentColour)
            self.try_again_button.SetForegroundColour(PRIMARY_HIGHLIGHT)

            self.Bind(wx.EVT_BUTTON, self.OnActionButton, self.try_again_button)

        self.close_button = Button(footer, wx.ID_CLOSE)
        self.close_button.SetLabel('CLOSE')
        self.close_button.SetBackgroundColour(wx.TransparentColour)
        self.close_button.SetForegroundColour(PRIMARY_HIGHLIGHT)

        self.Bind(wx.EVT_BUTTON, self.OnActionButton, self.close_button)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        footer.SetSizer(sizer)
        sizer.AddSpacer(16)
        sizer.Add(self.show_more_button)
        sizer.AddStretchSpacer()
        if not self.success:
            sizer.Add(self.try_again_button)
            sizer.AddSpacer(32)
        sizer.Add(self.close_button)
        sizer.AddSpacer(16)

        return footer

    def OnActionButton(self, evt):
        r = evt.GetEventObject().GetId()
        if self.IsModal():
            self.EndModal(r)
        else:
            self.SetReturnCode(r)
            self.Show(False)

    def OnShowMoreButton(self, evt):
        self.compass_parameters_shown = not self.compass_parameters_shown
        for p in self.compass_panels:
            p.ShowCompassParameters(self.compass_parameters_shown)

        if self.compass_parameters_shown:
            self.show_more_button.SetLabel('Show less')
        else:
            self.show_more_button.SetLabel('Show more')

        self.GetSizer().Fit(self)
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        # customise the agw style
        kwargs.setdefault(
            'agwStyle', SM.SM_DRAW_HAND
            | SM.SM_DRAW_PARTIAL_SECTORS
            | SM.SM_DRAW_SECONDARY_TICKS
            | SM.SM_DRAW_MIDDLE_TEXT)

        # initialise super class
        super(WindMeter, self).__init__(*args, **kwargs)

        # non-public attributes
        self._wind_reference = WindReference.RELATIVE
        self._wind_speed = 0
        self._wind_speed_unit = SpeedUnit.KNOTS

        # colours
        dial_colour = wx.ColourDatabase().Find('DARK SLATE GREY')
        port_arc_colour = wx.ColourDatabase().Find('RED')
        stbd_arc_colour = wx.ColourDatabase().Find('GREEN')
        bottom_arc_colour = wx.ColourDatabase().Find('TAN')
        self.SetSpeedBackground(dial_colour)

        # set lower limit to 2.999/2 to prevent the partial sectors from filling
        # the entire dial
        self.SetAngleRange(-2.995 / 2 * math.pi, math.pi / 2)

        # create the intervals
        intervals = range(0, 361, 20)
        self.SetIntervals(intervals)

        # assign colours to sectors
        colours = [dial_colour] \
            + [stbd_arc_colour] * 2 \
            + [dial_colour] * 4 \
            + [bottom_arc_colour] * 4 \
            + [dial_colour] * 4 \
            + [port_arc_colour] * 2 \
            + [dial_colour]
        self.SetIntervalColours(colours)

        # assign the ticks, colours and font
        ticks = [
            '0', '20', '40', '60', '80', '100', '120', '140', '160', '180',
            '-160', '-140', '-120', '-100', '-80', '-60', '-40', '-20', ''
        ]
        self.SetTicks(ticks)
        self.SetTicksColour(wx.WHITE)
        self.SetNumberOfSecondaryTicks(1)
        self.SetTicksFont(
            wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))

        # set the colour for the first hand indicator
        self.SetHandColour(wx.Colour(210, 210, 210))
        self.SetHandStyle("Hand")

        # do not draw the external (container) arc
        self.DrawExternalArc(False)

        # initialise the meter to zero
        self.SetWindAngle(0.0)

        # wind speed display
        self.SetMiddleTextColour(wx.WHITE)
        self.SetMiddleTextFont(
            wx.Font(16, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_NORMAL))
        self.SetWindSpeed(0.0)