def DoGetBestSize(self): dc = wx.ClientDC(self) dc.SetFont(self.GetFont()) w, h = dc.GetTextExtent(self.GetLabel()) pw, ph = self.GetPadding() w, h = w + pw, h + ph border = self.GetBorderWidth() w, h = w + 2 * border, h + 2 * border return wx.Size(w, h)
def createPlotPanel(self): '''Creates the figure and axes for the plotting panel.''' self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.canvas.SetSize(wx.Size(300, 300)) self.axes.axis('off') self.figure.subplots_adjust(left=0, right=1, top=1, bottom=0) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.EXPAND, wx.ALL) self.SetSizerAndFit(self.sizer) self.Fit()
def __init__(self, *k, **kw): if 'style' not in kw: kw['style'] = wx.BORDER_NONE super(Button, self).__init__(*k, **kw) self.border_radius = 0 self.border_width = 0 self.border_color = None self.padding = wx.Size(0, 0) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
def __init__(self, state, parent): wx.Panel.__init__(self, parent) # , style=wx.BORDER_SIMPLE) self.state = state self.sizer = wx.BoxSizer(wx.VERTICAL) self.titleText = wx.StaticText( self, label="Unassigned Vehicles -->\n\nTools:") self.sizer.Add(self.titleText, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5) self.getParamsButton = wx.Button( self, label="Get offsets", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.getParams, self.getParamsButton) self.resetButton = wx.Button( self, label="Reset layout", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.reset, self.resetButton) self.sizer.Add(self.getParamsButton) self.sizer.Add(self.resetButton) # Do the sizer layout self.SetSizer(self.sizer)
def on_redraw_timer(self, event): '''the redraw timer ensures we show new map tiles as they are downloaded''' state = self.state while state.in_queue.qsize(): try: obj = state.in_queue.get() except Exception: time.sleep(0.05) return if isinstance(obj, MPImageData): with warnings.catch_warnings(): warnings.simplefilter('ignore') img = wx.EmptyImage(obj.width, obj.height) img.SetData(obj.data) self.img = img self.need_redraw = True if state.auto_size: client_area = state.frame.GetClientSize() total_area = state.frame.GetSize() bx = max(total_area.x - client_area.x, 0) by = max(total_area.y - client_area.y, 0) state.frame.SetSize( wx.Size(obj.width + bx, obj.height + by)) if isinstance(obj, MPImageTitle): state.frame.SetTitle(obj.title) if isinstance(obj, MPImageRecenter): self.on_recenter(obj.location) if isinstance(obj, MPImageMenu): self.set_menu(obj.menu) if isinstance(obj, MPImagePopupMenu): self.set_popup_menu(obj.menu) if isinstance(obj, MPImageBrightness): state.brightness = obj.brightness self.need_redraw = True if isinstance(obj, MPImageFullSize): self.full_size() if isinstance(obj, MPImageFitToWindow): self.fit_to_window() if isinstance(obj, win_layout.WinLayout): win_layout.set_wx_window_layout(state.frame, obj) if self.need_redraw: self.redraw()
def __init__(self, state, parent, sysid, compid, vehtype, isLeader, listFollowers, takeoffalt): wx.Panel.__init__(self, parent) self.state = state self.sysid = sysid self.compid = compid self.listFollowers = listFollowers self.isLeader = isLeader self.vehtype = vehtype self.takeoffalt = takeoffalt self.inLinkLoss = False # XYZ offsets. Filled are we get params self.offsetValues = [None, None, None] self.sizer = wx.BoxSizer(wx.VERTICAL) # Status boxes if self.isLeader: self.title = wx.StaticText(self, label="Leader {0}:{1} {2}".format( sysid, compid, get_vehicle_name(vehtype))) self.offsets = wx.StaticText(self, label="Offset: N/A") else: self.title = wx.StaticText(self, label="Veh {0}:{1} {2}".format( sysid, compid, get_vehicle_name(vehtype))) self.offsets = wx.StaticText(self, label="Offset: xxxxxx") self.armmode = wx.StaticText(self, label="armed/mode N/A ") self.thrAlt = wx.StaticText( self, label="Alt: {0}m Thr: {1}%".format(0, 0)) self.altRel = wx.StaticText(self, label="Rel Alt: {0}m".format(0)) self.battery = wx.StaticText(self, label="Battery: {0}V".format(0)) self.status = wx.StaticText(self, label="Status: N/A") self.prearm = wx.StaticText(self, label="Prearm: N/A") self.statusText = wx.TextCtrl( self, style=wx.TE_READONLY | wx.TE_MULTILINE, size=wx.Size(140, 100)) # Command buttons self.doArm = wx.Button(self, label="XXX", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.arm, self.doArm) if self.isLeader: self.armSizer = wx.BoxSizer(wx.HORIZONTAL) self.doArmAll = wx.Button(self, label="ALL", size=wx.Size(70, 50)) self.Bind(wx.EVT_BUTTON, self.armAll, self.doArmAll) self.doGuided = wx.Button( self, label="Mode GUIDED", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.guided, self.doGuided) if self.isLeader: self.guidedSizer = wx.BoxSizer(wx.HORIZONTAL) self.doGuidedAll = wx.Button( self, label="ALL", size=wx.Size(70, 50)) self.Bind(wx.EVT_BUTTON, self.guidedAll, self.doGuidedAll) if vehtype != mavutil.mavlink.MAV_TYPE_GROUND_ROVER: self.doGuidedTakeoff = wx.Button( self, label="GUIDED T/O {0}m".format(self.takeoffalt), size=wx.Size(130, 50)) self.Bind(wx.EVT_BUTTON, self.guidedTakeoff, self.doGuidedTakeoff) if self.isLeader: self.takeoffSizer = wx.BoxSizer(wx.HORIZONTAL) self.doGuidedTakeoffAll = wx.Button( self, label="ALL".format(self.takeoffalt), size=wx.Size(70, 50)) self.Bind(wx.EVT_BUTTON, self.guidedTakeoffAll, self.doGuidedTakeoffAll) self.doRTL = wx.Button(self, label="Mode RTL", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.rtl, self.doRTL) if self.isLeader: self.rtlSizer = wx.BoxSizer(wx.HORIZONTAL) self.doRTLAll = wx.Button(self, label="ALL", size=wx.Size(70, 50)) self.Bind(wx.EVT_BUTTON, self.rtlAll, self.doRTLAll) self.doKill = wx.Button(self, label="KILL", size=wx.Size(100, 50)) self.killTimer = None self.Bind(wx.EVT_BUTTON, self.kill, self.doKill) if self.isLeader: self.killSizer = wx.BoxSizer(wx.HORIZONTAL) self.doKillAll = wx.Button(self, label="ALL", size=wx.Size(70, 50)) self.killAllTimer = None self.Bind(wx.EVT_BUTTON, self.killall, self.doKillAll) if self.isLeader: self.doFollowAll = wx.Button( self, label="All Follow Leader", size=wx.Size(130, 50)) self.Bind(wx.EVT_BUTTON, self.followAll, self.doFollowAll) self.doAUTO = wx.Button( self, label="Mode AUTO", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.auto, self.doAUTO) else: self.doFollow = wx.Button( self, label="Mode Follow", size=wx.Size(100, 50)) self.Bind(wx.EVT_BUTTON, self.follow, self.doFollow) # Do the sizer layout self.doSizer() # get offset params. Needs to be after GUI elements are created time.sleep(0.05) self.state.child_pipe.send(("getoffsets", self.sysid, self.compid))