def create_main_panel(self): import platform if platform.system() == 'Darwin': from MAVProxy.modules.lib.MacOS import backend_wxagg FigCanvas = backend_wxagg.FigureCanvasWxAgg else: from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas self.panel = wx.Panel(self) self.init_plot() self.canvas = FigCanvas(self.panel, -1, self.fig) self.close_button = wx.Button(self.panel, -1, "Close") self.Bind(wx.EVT_BUTTON, self.on_close_button, self.close_button) self.pause_button = wx.Button(self.panel, -1, "Pause") self.Bind(wx.EVT_BUTTON, self.on_pause_button, self.pause_button) self.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button, self.pause_button) self.hbox1 = wx.BoxSizer(wx.HORIZONTAL) self.hbox1.Add(self.close_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) self.hbox1.AddSpacer(1) self.hbox1.Add(self.pause_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) self.vbox = wx.BoxSizer(wx.VERTICAL) self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW) self.vbox.Add(self.hbox1, 0, flag=wx.ALIGN_LEFT | wx.TOP) self.panel.SetSizer(self.vbox) self.vbox.Fit(self)
def __init__(self, title, graphdef, callback): wx.Dialog.__init__(self, None, -1, title, size=(900, 400)) self.callback = callback self.graphdef = graphdef self.panel = wx.Panel(self, -1) vbox = wx.BoxSizer(wx.VERTICAL) # name entry hbox_name = wx.BoxSizer(wx.HORIZONTAL) st_name = wx.StaticText(self.panel, -1, 'Name: ') self.tc_name = wx.TextCtrl(self.panel, -1, size=(400, -1)) self.tc_name.Value = self.graphdef.name hbox_name.Add(st_name, 0, wx.LEFT, 10) hbox_name.Add(self.tc_name, 0, wx.LEFT, 35) vbox.Add(hbox_name, 0, wx.TOP, 10) # expression entry st = wx.StaticText(self.panel, -1, 'Expressions: ') vbox.Add(st, 0, wx.LEFT, 10) hbox_expressions = wx.BoxSizer(wx.HORIZONTAL) self.tc_expressions = wx.TextCtrl(self.panel, -1, style=wx.TE_MULTILINE | wx.HSCROLL, size=(800, 80)) elist = [] for e in self.graphdef.expressions: e = ' '.join(e.split()) elist.append(e) self.tc_expressions.Value = '\n'.join(elist) vbox.Add(self.tc_expressions, 0, wx.LEFT, 15) # description entry st = wx.StaticText(self.panel, -1, 'Description: ') vbox.Add(st, 0, wx.LEFT, 10) self.tc_description = wx.TextCtrl(self.panel, -1, style=wx.TE_MULTILINE) vbox.Add(self.tc_description, 1, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, 15) self.tc_description.Value = self.graphdef.description # buttons button_save = wx.Button(self.panel, 1, 'Save') button_cancel = wx.Button(self.panel, 2, 'Cancel') button_test = wx.Button(self.panel, 3, 'Test') hbox_buttons = wx.BoxSizer(wx.HORIZONTAL) hbox_buttons.Add(button_save, 0, wx.LEFT, 10) hbox_buttons.Add(button_cancel, 0, wx.LEFT, 10) hbox_buttons.Add(button_test, 0, wx.LEFT, 10) vbox.Add(hbox_buttons, 0, wx.TOP, 10) self.Bind(wx.EVT_BUTTON, self.OnSave, id=1) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=2) self.Bind(wx.EVT_BUTTON, self.OnTest, id=3) self.panel.SetSizer(vbox) self.Centre()
def AddButton(self, label, callback=None): c = wx.Button(self.panel, label=label) self.AddControl(c, label, False) if callback is not None: self.callbacks[c.GetId()] = callback c.Bind(wx.EVT_BUTTON, self.OnButton) self.row.Add(c, 0, wx.LEFT, 20)
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 __init__(self, tab_names, title='Title', size=wx.DefaultSize): wx.Dialog.__init__(self, None, -1, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.tab_names = tab_names self.notebook = wx.Notebook(self, -1, size=size) self.panels = {} self.sizers = {} for t in tab_names: self.panels[t] = wx.Panel(self.notebook) self.notebook.AddPage(self.panels[t], t) self.sizers[t] = wx.BoxSizer(wx.VERTICAL) self.panels[t].SetSizer(self.sizers[t]) self.dialog_sizer = wx.BoxSizer(wx.VERTICAL) self.dialog_sizer.Add(self.notebook, 1, wx.EXPAND | wx.ALL, 5) self.controls = {} self.browse_option_map = {} self.control_map = {} self.setting_map = {} button_box = wx.BoxSizer(wx.HORIZONTAL) self.button_apply = wx.Button(self, -1, "Apply") self.button_cancel = wx.Button(self, -1, "Cancel") self.button_save = wx.Button(self, -1, "Save") self.button_load = wx.Button(self, -1, "Load") button_box.Add(self.button_cancel, 0, wx.ALL) button_box.Add(self.button_apply, 0, wx.ALL) button_box.Add(self.button_save, 0, wx.ALL) button_box.Add(self.button_load, 0, wx.ALL) self.dialog_sizer.Add(button_box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) wx.EVT_BUTTON(self, self.button_cancel.GetId(), self.on_cancel) wx.EVT_BUTTON(self, self.button_apply.GetId(), self.on_apply) wx.EVT_BUTTON(self, self.button_save.GetId(), self.on_save) wx.EVT_BUTTON(self, self.button_load.GetId(), self.on_load) self.Centre()
def createWidgets(self): #create the panels for the tabs PanelAssembly = wx.Panel(self.nb) boxAssembly = wx.BoxSizer(wx.VERTICAL) PanelAssembly.SetAutoLayout(True) PanelAssembly.SetSizer(boxAssembly) PanelAssembly.Layout() PanelEngine = wx.Panel(self.nb) boxEngine = wx.BoxSizer(wx.VERTICAL) PanelEngine.SetAutoLayout(True) PanelEngine.SetSizer(boxEngine) PanelEngine.Layout() PanelTakeoff = wx.Panel(self.nb) boxTakeoff = wx.BoxSizer(wx.VERTICAL) PanelTakeoff.SetAutoLayout(True) PanelTakeoff.SetSizer(boxTakeoff) PanelTakeoff.Layout() PanelCruise = wx.Panel(self.nb) boxCruise = wx.BoxSizer(wx.VERTICAL) PanelCruise.SetAutoLayout(True) PanelCruise.SetSizer(boxCruise) PanelCruise.Layout() PanelDrop = wx.Panel(self.nb) boxDrop = wx.BoxSizer(wx.VERTICAL) PanelDrop.SetAutoLayout(True) PanelDrop.SetSizer(boxDrop) PanelDrop.Layout() PanelLanding = wx.Panel(self.nb) boxLanding = wx.BoxSizer(wx.VERTICAL) PanelLanding.SetAutoLayout(True) PanelLanding.SetSizer(boxLanding) PanelLanding.Layout() PanelShutdown = wx.Panel(self.nb) boxShutdown = wx.BoxSizer(wx.VERTICAL) PanelShutdown.SetAutoLayout(True) PanelShutdown.SetSizer(boxShutdown) PanelShutdown.Layout() #add the data to the individual tabs '''before assembly checklist''' for key in self.beforeAssemblyList: if self.beforeAssemblyList[key] == 0: disCheckBox = wx.CheckBox(PanelAssembly, wx.ID_ANY, key) disCheckBox.Enable(False) boxAssembly.Add(disCheckBox) if self.beforeAssemblyList[key] == 2: boxAssembly.Add(wx.CheckBox(PanelAssembly, wx.ID_ANY, key)) self.AssemblyButton = wx.Button(PanelAssembly, wx.ID_ANY, "Close final hatches") boxAssembly.Add(self.AssemblyButton) '''before Engine Start checklist''' for key in self.beforeEngineList: if self.beforeEngineList[key] == 0: disCheckBox = wx.CheckBox(PanelEngine, wx.ID_ANY, key) disCheckBox.Enable(False) boxEngine.Add(disCheckBox) if self.beforeEngineList[key] == 2: boxEngine.Add(wx.CheckBox(PanelEngine, wx.ID_ANY, key)) self.EngineButton = wx.Button(PanelEngine, wx.ID_ANY, "Ready for Engine start") boxEngine.Add(self.EngineButton) '''before takeoff checklist''' for key in self.beforeTakeoffList: if self.beforeTakeoffList[key] == 0: disCheckBox = wx.CheckBox(PanelTakeoff, wx.ID_ANY, key) disCheckBox.Enable(False) boxTakeoff.Add(disCheckBox) if self.beforeTakeoffList[key] == 2: boxTakeoff.Add(wx.CheckBox(PanelTakeoff, wx.ID_ANY, key)) self.TakeoffButton = wx.Button(PanelTakeoff, wx.ID_ANY, "Ready for Takeoff") boxTakeoff.Add(self.TakeoffButton) '''before cruise/AUTO checklist''' for key in self.beforeCruiseList: if self.beforeCruiseList[key] == 0: disCheckBox = wx.CheckBox(PanelCruise, wx.ID_ANY, key) disCheckBox.Enable(False) boxCruise.Add(disCheckBox) if self.beforeCruiseList[key] == 2: boxCruise.Add(wx.CheckBox(PanelCruise, wx.ID_ANY, key)) self.CruiseButton = wx.Button(PanelCruise, wx.ID_ANY, "Ready for Cruise/AUTO") boxCruise.Add(self.CruiseButton) '''before bottle drop checklist''' for key in self.bottleDropList: if self.bottleDropList[key] == 0: disCheckBox = wx.CheckBox(PanelDrop, wx.ID_ANY, key) disCheckBox.Enable(False) boxDrop.Add(disCheckBox) if self.bottleDropList[key] == 2: boxDrop.Add(wx.CheckBox(PanelDrop, wx.ID_ANY, key)) self.DropButton = wx.Button(PanelDrop, wx.ID_ANY, "Ready for Bottle Drop") boxDrop.Add(self.DropButton) '''before landing checklist''' for key in self.beforeLandingList: if self.beforeLandingList[key] == 0: disCheckBox = wx.CheckBox(PanelLanding, wx.ID_ANY, key) disCheckBox.Enable(False) boxLanding.Add(disCheckBox) if self.beforeLandingList[key] == 2: boxLanding.Add(wx.CheckBox(PanelLanding, wx.ID_ANY, key)) self.LandingButton = wx.Button(PanelLanding, wx.ID_ANY, "Ready for Landing") boxLanding.Add(self.LandingButton) '''before shutdown checklist''' for key in self.beforeShutdownList: if self.beforeShutdownList[key] == 0: disCheckBox = wx.CheckBox(PanelShutdown, wx.ID_ANY, key) disCheckBox.Enable(False) boxShutdown.Add(disCheckBox) if self.beforeShutdownList[key] == 2: boxShutdown.Add(wx.CheckBox(PanelShutdown, wx.ID_ANY, key)) self.ShutdownButton = wx.Button(PanelShutdown, wx.ID_ANY, "Ready for Shutdown") boxShutdown.Add(self.ShutdownButton) #and add in the tabs self.nb.AddPage(PanelAssembly, "1. During Assembly") self.nb.AddPage(PanelEngine, "2. Before Engine Start") self.nb.AddPage(PanelTakeoff, "3. Before Takeoff") self.nb.AddPage(PanelCruise, "4. Before Cruise/AUTO") self.nb.AddPage(PanelDrop, "5. Before Bottle Drop") self.nb.AddPage(PanelLanding, "6. Before Landing") self.nb.AddPage(PanelShutdown, "7. Before Shutdown")
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, 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))