def __init__(self, *args, **kwargs): # customise the style kwargs.setdefault('style', wx.TE_READONLY) # initialise super class super(InstrumentDisplay, self).__init__(*args, **kwargs) # set the background colour (also for text controls) # self.SetBackgroundColour(wx.WHITE) # text controls self._label_text = wx.TextCtrl(self, style=wx.BORDER_NONE) self._label_text.SetFont( wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self._label_text.SetBackgroundColour(self.GetBackgroundColour()) self._label_text.ChangeValue("---") self._value_text = wx.TextCtrl(self, style=wx.BORDER_NONE | wx.TE_CENTRE) self._value_text.SetFont( wx.Font(30, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self._value_text.SetBackgroundColour(self.GetBackgroundColour()) self._value_text.ChangeValue("-.-") self._value_text.SetMinSize((60, 40)) self._unit_text = wx.TextCtrl(self, style=wx.BORDER_NONE | wx.TE_RIGHT) self._unit_text.SetFont( wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)) self._unit_text.SetBackgroundColour(self.GetBackgroundColour()) self._unit_text.ChangeValue("--") # value text needs a nested sizer to centre vertically self._value_sizer = wx.BoxSizer(wx.HORIZONTAL) self._value_sizer.Add( self._value_text, wx.SizerFlags(1).Align(wx.ALIGN_CENTRE_VERTICAL).Border(wx.ALL, 0)) # top level sizers self._top_sizer = wx.BoxSizer(wx.VERTICAL) self._top_sizer.Add( self._label_text, wx.SizerFlags(0).Align(wx.ALIGN_TOP | wx.ALIGN_LEFT).Border( wx.ALL, 2)) self._top_sizer.Add(self._value_sizer, wx.SizerFlags(1).Expand().Border(wx.ALL, 1)) self._top_sizer.Add( self._unit_text, wx.SizerFlags(0).Align(wx.ALIGN_RIGHT).Border(wx.ALL, 2)) # layout sizers self._top_sizer.SetSizeHints(self) self.SetSizer(self._top_sizer) self.SetAutoLayout(True)
def StartRow(self, label=None): if self.row: self.EndRow() if label: self.row = wx.BoxSizer(wx.HORIZONTAL) text = wx.StaticText(self.panel, label=label) font = wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.BOLD) text.SetFont(font) self.row.Add(text, 0, wx.LEFT, 10) self.vbox.Add(self.row, 0, wx.TOP, 10) self.row = wx.BoxSizer(wx.HORIZONTAL)
def call(self): '''show the dialog as a child process''' mp_util.child_close_fds() from MAVProxy.modules.lib import wx_processguard from MAVProxy.modules.lib.wx_loader import wx from wx.lib.agw.genericmessagedialog import GenericMessageDialog app = wx.App(False) # note! font size change is not working. I don't know why yet font = wx.Font(self.font_size, wx.MODERN, wx.NORMAL, wx.NORMAL) dlg = GenericMessageDialog(None, self.message, self.title, wx.ICON_INFORMATION|wx.OK) dlg.SetFont(font) dlg.ShowModal() app.MainLoop()
def on_timer(self, event): state = self.state if state.close_event.wait(0.001): self.timer.Stop() self.Destroy() return while state.child_pipe_recv.poll(): try: obj = state.child_pipe_recv.recv() except EOFError: self.timer.Stop() self.Destroy() return if isinstance(obj, Value): # request to set a status field if obj.name not in self.values: # create a new status field statictextbox = wx.StaticText(self.panel, -1, obj.text) font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL) statictextbox.SetFont(font) # possibly add more status rows for i in range(len(self.status), obj.row + 1): self.status.append(wx.BoxSizer(wx.HORIZONTAL)) self.vbox.Insert(len(self.status) - 1, self.status[i], 0, flag=wx.ALIGN_LEFT | wx.TOP) self.vbox.Layout() self.status[obj.row].Add(statictextbox, border=5) self.status[obj.row].AddSpacer(20) self.values[obj.name] = statictextbox statictextbox = self.values[obj.name] statictextbox.SetForegroundColour(obj.fg) statictextbox.SetBackgroundColour(obj.bg) statictextbox.SetLabel(obj.text) self.panel.Layout() elif isinstance(obj, Text): '''request to add text to the console''' self.pending.append(obj) for p in self.pending: # we're scrolled at the bottom oldstyle = self.control.GetDefaultStyle() style = wx.TextAttr() style.SetTextColour(p.fg) style.SetBackgroundColour(p.bg) self.control.SetDefaultStyle(style) self.control.AppendText(p.text) self.control.SetDefaultStyle(oldstyle) self.pending = [] elif isinstance(obj, mp_menu.MPMenuTop): if obj is not None: self.SetMenuBar(None) self.menu = obj self.SetMenuBar(self.menu.wx_menu()) self.Bind(wx.EVT_MENU, self.on_menu) self.Refresh() self.Update() elif isinstance(obj, mp_menu.MPButton): if obj is not None: newbtn = wx.Button(self.panel, label=obj.label) newbtn.Bind(wx.EVT_BUTTON, self.on_button) self.buttongridsizer.Add(newbtn, 0, wx.EXPAND) self.buttons.append(obj) elif isinstance(obj, win_layout.WinLayout): win_layout.set_wx_window_layout(self, obj)
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)