class MyDlg(wx.Frame): def __init__(self,parent,conf_file='conf.txt',id = -1,title = '',pos = wx.Point(0,0),size = wx.Size(495,550),style = wx.DEFAULT_DIALOG_STYLE,name = 'dialogBox'): #pre=wx.PreDialog() self.OnPreCreate() try: self.conf = ConfigHandler(conf_file) except IOError: wx.MessageBox("Could not find the config file, %s" %conf_file) self.__del__() sys.exit(1) board = self.conf.getBoard() #pre.Create(parent,id,title + ' ' + board,pos,size,wx.CAPTION|wx.RESIZE_BORDER|wx.SYSTEM_MENU|wx.CLOSE_BOX|wx.DIALOG_NO_PARENT|wx.DEFAULT_DIALOG_STYLE|wx.MINIMIZE_BOX,name) wx.Frame.__init__(self, parent, id,title + ' ' + board,pos,size,wx.CAPTION|wx.RESIZE_BORDER|wx.SYSTEM_MENU|wx.CLOSE_BOX|wx.MINIMIZE_BOX,name) self.statusBar = self.CreateStatusBar() #self.PostCreate(pre) self.initBefore() self.VwXinit() self.initAfter() def __del__(self): self.Ddel() return def VwXinit(self): self.main_pannel = wx.Panel(self,-1,wx.Point(-5,0),wx.Size(609,493)) self.DigiOpPin = wx.StaticBox(self.main_pannel,-1,"",wx.Point(10,100),wx.Size(468,71)) self.DigiOpPin.SetLabel('Digital output pins') digi_pins = self.conf.getDigiPinNames() self.cmbDigiOpPins = wx.ComboBox(self.main_pannel,-1,"",wx.Point(125,125),wx.Size(80,21),digi_pins,wx.CB_READONLY) self.cmbDigiOpPins.SetLabel("Select Pin") self.stDigitalOut = wx.StaticText(self.main_pannel,-1,"",wx.Point(25,125),wx.Size(99,13),wx.ST_NO_AUTORESIZE) self.stDigitalOut.SetLabel("Select a Digital Pin") self.btDigiOutSet = wx.Button(self.main_pannel,-1,"",wx.Point(380,120),wx.Size(85,30)) self.btDigiOutSet.SetLabel("Set") self.Bind(wx.EVT_BUTTON,self.OnDigiSet,self.btDigiOutSet) self.stDigiOpSelState = wx.StaticText(self.main_pannel,-1,"",wx.Point(220,125),wx.Size(69,13),wx.ST_NO_AUTORESIZE) self.stDigiOpSelState.SetLabel("Select State") self.cmbHighLow = wx.ComboBox(self.main_pannel,-1,"",wx.Point(290,125),wx.Size(65,21),[r'High',r'Low'],wx.CB_READONLY) self.cmbHighLow.SetLabel("State") self.sbDigigInpPins = wx.StaticBox(self.main_pannel,-1,"",wx.Point(10,190),wx.Size(463,76)) self.sbDigigInpPins.SetLabel('Digital Input Pins') self.stDigiOutPin = wx.StaticText(self.main_pannel,-1,"",wx.Point(25,225),wx.Size(94,13),wx.ST_NO_AUTORESIZE) self.stDigiOutPin.SetLabel("Select a Digital Pin") self.cmbSerPort = wx.ComboBox(self.main_pannel,-1,"",wx.Point(120,35),wx.Size(145,21),[],wx.CB_READONLY) self.cmbSerPort.SetLabel("Select Pin") self.btOpenPrt = wx.Button(self.main_pannel,-1,"",wx.Point(285,30),wx.Size(85,30)) self.btOpenPrt.SetLabel("Open") self.Bind(wx.EVT_BUTTON,self.OnOpenPrt,self.btOpenPrt) self.ledPinState = wx.gizmos.LEDNumberCtrl(self.main_pannel,-1,wx.Point(350,220),wx.Size(70,40)) self.sbAnalogOut = wx.StaticBox(self.main_pannel,-1,"",wx.Point(10,290),wx.Size(463,86)) self.sbAnalogOut.SetLabel('Analog Out') self.stAnIn = wx.StaticText(self.main_pannel,-1,"",wx.Point(20,420),wx.Size(104,13),wx.ST_NO_AUTORESIZE) self.stAnIn.SetLabel("Select an Analog pin") self.cmbAnalogOut = wx.ComboBox(self.main_pannel,-1,"",wx.Point(125,325),wx.Size(80,21),self.conf.getAnaOutPinNames(),wx.CB_READONLY) self.cmbAnalogOut.SetLabel("Select pin") self.txAnalogOut = wx.TextCtrl(self.main_pannel,-1,"",wx.Point(300,320),wx.Size(60,21)) self.stAnoutVal = wx.StaticText(self.main_pannel,-1,"",wx.Point(225,325),wx.Size(69,13),wx.ST_NO_AUTORESIZE) self.stAnoutVal.SetLabel("Enter a value") self.btAnalogOut = wx.Button(self.main_pannel,-1,"",wx.Point(370,315),wx.Size(85,30)) self.btAnalogOut.SetLabel("Set") self.Bind(wx.EVT_BUTTON,self.OnAnaSet,self.btAnalogOut) self.sbAnalogIn = wx.StaticBox(self.main_pannel,-1,"",wx.Point(10,390),wx.Size(463,81)) self.sbAnalogIn.SetLabel('Analog In') self.stSelAnOut = wx.StaticText(self.main_pannel,-1,"",wx.Point(20,325),wx.Size(104,13),wx.ST_NO_AUTORESIZE) self.stSelAnOut.SetLabel("Select an Analog pin") self.cmbAnalogIn = wx.ComboBox(self.main_pannel,-1,"",wx.Point(125,420),wx.Size(80,21),self.conf.getAnaInPinNames(),wx.CB_READONLY) self.cmbAnalogIn.SetLabel("Select pin") self.btAnalogRead = wx.Button(self.main_pannel,-1,"",wx.Point(225,415),wx.Size(85,30)) self.btAnalogRead.SetLabel("Read") self.Bind(wx.EVT_BUTTON,self.OnAnaRead,self.btAnalogRead) self.ledAnalogRead = wx.gizmos.LEDNumberCtrl(self.main_pannel,-1,wx.Point(350,415),wx.Size(75,40)) self.SerPort = wx.StaticBox(self.main_pannel,-1,"",wx.Point(10,10),wx.Size(468,71)) self.SerPort.SetLabel('Serial port selection') self.stSelPort = wx.StaticText(self.main_pannel,-1,"",wx.Point(20,35),wx.Size(100,13),wx.ST_NO_AUTORESIZE) self.stSelPort.SetLabel("Select a serial port") self.cmbDigiRead = wx.ComboBox(self.main_pannel,-1,"",wx.Point(125,225),wx.Size(80,21),digi_pins,wx.CB_READONLY) self.cmbDigiRead.SetLabel("Select Pin") self.btClosePrt = wx.Button(self.main_pannel,-1,"",wx.Point(385,30),wx.Size(85,30)) self.btClosePrt.SetLabel("Close") self.Bind(wx.EVT_BUTTON,self.OnClosePrt,self.btClosePrt) self.btDigiRead = wx.Button(self.main_pannel,-1,"",wx.Point(225,220),wx.Size(85,30)) self.btDigiRead.SetLabel("Read") self.Bind(wx.EVT_BUTTON,self.OnDigiRead,self.btDigiRead) self.Refresh() return def VwXDelComp(self): return #[win]add your code here def OnOpenPrt(self,event): #init function #[51e]Code event VwX...Don't modify[51e]# #add your code here ser_prt = self.cmbSerPort.GetValue().encode('ASCII') if (ser_prt == ""): return # lets try and create a TransLayer object try: self.ArdCtrl = TransLayer(ser_prt, self.conf.getVref(), self.conf.getRes()) self.btOpenPrt.Enable(False) self.btClosePrt.Enable(True) self.btDigiOutSet.Enable(True) self.btDigiRead.Enable(True) self.btAnalogOut.Enable(True) self.btAnalogRead.Enable(True) except IOError, error: err = str(error) wx.MessageBox(err+"\n Application exiting...") sys.exit(1) return #end function
class QuickCtlConfig ( wx.Frame ): def __init__( self, parent, cfgFile="Arduino_Duemilanove.cfg" ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 373,507 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) # This named tuple acts like the group holder for GUI controls # that we need to control self.ctls = namedtuple("ctls", 'availableLstCtl selectedLstCtl') self.ctlDic = {} self.serPort = "" self.cfgFile = cfgFile # Try to open the config file and load the values try: self.cfg = ConfigHandler(self.cfgFile) except: wx.MessageBox(cfgFile + " was not found ") wx.Exit() self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) frameSizer = wx.BoxSizer( wx.VERTICAL ) self.mainPanel = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) mainSizer = wx.BoxSizer( wx.VERTICAL ) #mainSizer.Add( gpioBox, 1, wx.EXPAND, 5 ) sizer = self.addPerBox('GPIOs', 'gpio') mainSizer.Add( sizer, 1, wx.EXPAND, 5 ) sizer = self.addPerBox('DACs', 'dac') mainSizer.Add( sizer, 1, wx.EXPAND, 5 ) sizer = self.addPerBox('ADCs', 'adc') mainSizer.Add( sizer, 1, wx.EXPAND, 5 ) # Let's popuate the list box with the pins that are available # first read the pickle file associated with the config file # and populate appropriately try: pick = os.path.splitext(self.cfgFile)[0]+'.pickle' pick = file(pick) self.selectedCtlDic = pickle.load(pick) except: self.selectedCtlDic = {'gpio':[], 'dac':[], 'adc':[]} self.selectedCtlDic['gpio'].sort(self.cfg.__cmp__) self.selectedCtlDic['adc'].sort(self.cfg.__cmp__) self.selectedCtlDic['dac'].sort(self.cfg.__cmp__) gpios = self.cfg.getDigiPinNames() gpios = self.__reomove_dups__(gpios, self.selectedCtlDic['gpio']) self.ctlDic['gpio'].availableLstCtl.InsertItems(gpios, 0) self.ctlDic['gpio'].selectedLstCtl.InsertItems(self.selectedCtlDic['gpio'], 0) dacs = self.cfg.getAnaOutPinNames() dacs = self.__reomove_dups__(dacs, self.selectedCtlDic['dac']) self.ctlDic['dac'].availableLstCtl.InsertItems(dacs, 0) self.ctlDic['dac'].selectedLstCtl.InsertItems(self.selectedCtlDic['dac'], 0) adcs = self.cfg.getAnaInPinNames() adcs = self.__reomove_dups__(adcs, self.selectedCtlDic['adc']) self.ctlDic['adc'].availableLstCtl.InsertItems(adcs, 0) self.ctlDic['adc'].selectedLstCtl.InsertItems(self.selectedCtlDic['adc'], 0) self.availbleCtlDic = {'gpio':gpios, 'dac':dacs, 'adc':adcs} self.prts = GetSerPorts() self.ports = self.prts.get_ports(); sdbSizer = wx.StdDialogButtonSizer() self.sdbSizerOK = wx.Button( self.mainPanel, wx.ID_OK ) self.sdbSizerOK.Bind( wx.EVT_BUTTON, self.onOk ) sdbSizer.AddButton( self.sdbSizerOK ) self.sdbSizerCancel = wx.Button( self.mainPanel, wx.ID_CANCEL ) self.sdbSizerCancel.Bind( wx.EVT_BUTTON, self.onCancel ) sdbSizer.AddButton( self.sdbSizerCancel ) sdbSizer.Realize(); self.stPortName = wx.StaticText(self.mainPanel, -1, " Select the serial port name") self.cmbSerPort = wx.ComboBox(self.mainPanel,-1,"",wx.Point(120,35),wx.Size(15,21), self.ports,wx.CB_READONLY) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.stPortName, 1, wx.EXPAND, 10) sizer.Add(self.cmbSerPort, 1, wx.EXPAND, 1) mainSizer.Add((0, 20)) mainSizer.Add(sizer, .9, wx.EXPAND, 5 ) mainSizer.Add((0, 10)) mainSizer.Add( sdbSizer, .8, wx.EXPAND, 5 ) mainSizer.Add((0, 20)) self.mainPanel.SetSizer( mainSizer ) self.mainPanel.Layout() mainSizer.Fit( self.mainPanel ) frameSizer.Add( self.mainPanel, 1, wx.EXPAND |wx.ALL, 5 ) self.SetSizer( frameSizer ) # Now that all the GUI controls are laid out, let us now populate the lists self.Layout() self.Centre( wx.BOTH ) def __reomove_dups__(self, origList, copyList): """ Removes entries from origList that are present in origList """ if len(origList) == 0:return for cp in copyList: if cp in origList: origList.remove(cp) return origList def onL2r(self, event): button = event.GetEventObject() btnId = event.GetId() btnById = self.FindWindowById(btnId) name = btnById.GetName().replace('l2r', '') selection = self.ctlDic[name].availableLstCtl.GetStringSelection() if selection == '': return self.ctlDic[name].selectedLstCtl.Append(selection) self.selectedCtlDic[name].append(selection) n = self.ctlDic[name].availableLstCtl.FindString(selection) self.ctlDic[name].availableLstCtl.Delete(n) #print self.selectedCtlDic[name] def onR2l(self, event): button = event.GetEventObject() btnId = event.GetId() btnById = self.FindWindowById(btnId) name = btnById.GetName().replace('r2l', '') selection = self.ctlDic[name].selectedLstCtl.GetStringSelection() if selection == '': return self.ctlDic[name].availableLstCtl.Append(selection) self.selectedCtlDic[name].remove(selection) n = self.ctlDic[name].selectedLstCtl.FindString(selection) self.ctlDic[name].selectedLstCtl.Delete(n) #print self.selectedCtlDic[name] def onOk(self, event): # Let us store the user selections cfgFile = os.path.splitext(self.cfgFile)[0] # serialize pick = file(cfgFile + '.pickle', 'w') self.selectedCtlDic['gpio'].sort(self.cfg.__cmp__) self.selectedCtlDic['adc'].sort(self.cfg.__cmp__) self.selectedCtlDic['dac'].sort(self.cfg.__cmp__) pickle.dump(self.selectedCtlDic, pick) serPort = self.cmbSerPort.GetValue().encode('ASCII') try: quickCtlFrame = QuickCtl(serPort, self.cfg, self.selectedCtlDic['gpio'], self.selectedCtlDic['adc'], self.selectedCtlDic['dac']) self.Show(False) except: wx.MessageBox("Oops, there was a problem", style=wx.ICON_EXCLAMATION) wx.Exit() quickCtlFrame.Show(True) def onCancel(self, event): self.Close() def addPerBox(self, title='GPIOs', name='gpio'): # We will use a dictionary to hold all the info required to # control the list item boxSizer = wx.StaticBoxSizer( wx.StaticBox( self.mainPanel, wx.ID_ANY, title), wx.VERTICAL ) vSizer = wx.BoxSizer( wx.HORIZONTAL ) leftVSizer = wx.BoxSizer( wx.VERTICAL ) self.stAvailablePorts = wx.StaticText( self.mainPanel, wx.ID_ANY, u"Available port(s)", wx.DefaultPosition, wx.DefaultSize, 0 ) self.stAvailablePorts.Wrap( -1 ) leftVSizer.Add( self.stAvailablePorts, 0, wx.ALL, 5 ) self.lstAvailablePorts = wx.ListBox( self.mainPanel, wx.ID_ANY, wx.DefaultPosition, (100, 75), style = wx.LB_SORT) leftVSizer.Add( self.lstAvailablePorts, 0, wx.ALL, 5 ) vSizer.Add( leftVSizer, 1, wx.EXPAND, 5 ) midVSizer = wx.BoxSizer( wx.VERTICAL ) midVSizer.Add((0, 30)) self.btnLeftToRight = wx.Button( self.mainPanel, wx.ID_ANY, u">>", wx.DefaultPosition, wx.DefaultSize, 0, name = name+'l2r' ) self.btnLeftToRight.Bind( wx.EVT_BUTTON, self.onL2r ) midVSizer.Add( self.btnLeftToRight, 0, wx.ALIGN_CENTER|wx.ALL, 5 ) self.btnRightToLeft = wx.Button( self.mainPanel, wx.ID_ANY, u"<<", wx.DefaultPosition, wx.DefaultSize, 0, name = name+'r2l' ) self.btnRightToLeft.Bind( wx.EVT_BUTTON, self.onR2l ) midVSizer.Add( self.btnRightToLeft, 0, wx.ALIGN_CENTER|wx.ALL, 5 ) vSizer.Add( midVSizer, 1, wx.EXPAND, 10 ) rightVSizer = wx.BoxSizer( wx.VERTICAL ) self.stSelectedPorts = wx.StaticText( self.mainPanel, wx.ID_ANY, u"Selected port(s)", wx.DefaultPosition, wx.DefaultSize, 0 ) self.stSelectedPorts.Wrap( -1 ) rightVSizer.Add( self.stSelectedPorts, 0, wx.ALL, 5 ) self.lstSelectedPorts = wx.ListBox( self.mainPanel, wx.ID_ANY, wx.DefaultPosition, (100, 75), style = wx.LB_SORT) rightVSizer.Add( self.lstSelectedPorts, 0, wx.ALL, 5 ) temp = self.ctls(self.lstAvailablePorts, self.lstSelectedPorts) vSizer.Add( rightVSizer, 1, wx.EXPAND, 5 ) boxSizer.Add( vSizer, 1, wx.ALIGN_CENTER|wx.EXPAND, 5 ) self.ctlDic[name] = temp return boxSizer def __del__( self ): wx.Exit() return
class ControllerFrame(wx.Frame): def __init__(self, parent, conf_file='conf.txt', id=-1, title='', pos=wx.Point(0, 0), size=wx.Size(530, 520), style=wx.DEFAULT_DIALOG_STYLE, name='dialogBox'): #pre=wx.PreDialog() self.OnPreCreate() try: self.conf = ConfigHandler(conf_file) except IOError: wx.MessageBox("Could not find the config file, %s" % conf_file) self.__del__() sys.exit(1) board = self.conf.getBoard() wx.Frame.__init__( self, parent, id, title + ' ' + board, pos, size, wx.CAPTION | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.MINIMIZE_BOX, name) self.statusBar = self.CreateStatusBar() font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) font.SetPointSize(10) self.initBefore() self.VwXinit() self.initAfter() def __del__(self): self.Ddel() wx.Exit() return def VwXinit(self): self.main_pannel = wx.Panel(self, -1, wx.Point(-5, 0), wx.Size(609, 493)) self.DigiOpPin = wx.StaticBox(self.main_pannel, -1, "", wx.Point(10, 100), wx.Size(500, 70)) self.DigiOpPin.SetLabel('Digital output pins') digi_pins = self.conf.getDigiPinNames() self.cmbDigiOpPins = wx.ComboBox(self.main_pannel, -1, "", wx.Point(160, 125), wx.Size(80, 25), digi_pins, wx.CB_READONLY) self.cmbDigiOpPins.SetLabel("Select Pin") self.stDigitalOut = wx.StaticText(self.main_pannel, -1, "", wx.Point(25, 125), wx.Size(125, 20), wx.ST_NO_AUTORESIZE) self.stDigitalOut.SetLabel("Select a Digital Pin") self.btDigiOutSet = wx.Button(self.main_pannel, -1, "", wx.Point(420, 120), wx.Size(85, 30)) self.btDigiOutSet.SetLabel("Set") self.Bind(wx.EVT_BUTTON, self.OnDigiSet, self.btDigiOutSet) self.stDigiOpSelState = wx.StaticText(self.main_pannel, -1, "", wx.Point(250, 125), wx.Size(80, 20), wx.ST_NO_AUTORESIZE) self.stDigiOpSelState.SetLabel("Select State") self.cmbHighLow = wx.ComboBox(self.main_pannel, -1, "", wx.Point(340, 125), wx.Size(65, 25), [r'High', r'Low'], wx.CB_READONLY) self.cmbHighLow.SetLabel("State") self.sbDigigInpPins = wx.StaticBox(self.main_pannel, -1, "", wx.Point(10, 190), wx.Size(500, 76)) self.sbDigigInpPins.SetLabel('Digital Input Pins') self.stDigiOutPin = wx.StaticText(self.main_pannel, -1, "", wx.Point(25, 215), wx.Size(125, 20), wx.ST_NO_AUTORESIZE) self.stDigiOutPin.SetLabel("Select a Digital Pin") self.cmbSerPort = wx.ComboBox(self.main_pannel, -1, "", wx.Point(160, 35), wx.Size(120, 25), [], wx.CB_READONLY) self.cmbSerPort.SetLabel("Select Pin") self.btOpenPrt = wx.Button(self.main_pannel, -1, "", wx.Point(285, 30), wx.Size(85, 30)) self.btOpenPrt.SetLabel("Open") self.Bind(wx.EVT_BUTTON, self.OnOpenPrt, self.btOpenPrt) self.ledPinState = wx.gizmos.LEDNumberCtrl(self.main_pannel, -1, wx.Point(350, 215), wx.Size(70, 40)) self.sbAnalogOut = wx.StaticBox(self.main_pannel, -1, "", wx.Point(10, 285), wx.Size(500, 70)) self.sbAnalogOut.SetLabel('Analog Out') self.stAnIn = wx.StaticText(self.main_pannel, -1, "", wx.Point(20, 400), wx.Size(140, 20), wx.ST_NO_AUTORESIZE) self.stAnIn.SetLabel("Select an Analog pin") self.cmbAnalogOut = wx.ComboBox(self.main_pannel, -1, "", wx.Point(160, 310), wx.Size(80, 25), self.conf.getAnaOutPinNames(), wx.CB_READONLY) self.cmbAnalogOut.SetLabel("Select pin") self.txAnalogOut = wx.TextCtrl(self.main_pannel, -1, "", wx.Point(345, 310), wx.Size(60, 25)) self.stAnoutVal = wx.StaticText(self.main_pannel, -1, "", wx.Point(250, 310), wx.Size(100, 20), wx.ST_NO_AUTORESIZE) self.stAnoutVal.SetLabel("Enter a value") self.btAnalogOut = wx.Button(self.main_pannel, -1, "", wx.Point(420, 310), wx.Size(85, 30)) self.btAnalogOut.SetLabel("Set") self.Bind(wx.EVT_BUTTON, self.OnAnaSet, self.btAnalogOut) self.sbAnalogIn = wx.StaticBox(self.main_pannel, -1, "", wx.Point(10, 375), wx.Size(500, 80)) self.sbAnalogIn.SetLabel('Analog In') self.stSelAnOut = wx.StaticText(self.main_pannel, -1, "", wx.Point(20, 310), wx.Size(140, 20), wx.ST_NO_AUTORESIZE) self.stSelAnOut.SetLabel("Select an Analog pin") self.cmbAnalogIn = wx.ComboBox(self.main_pannel, -1, "", wx.Point(160, 400), wx.Size(80, 25), self.conf.getAnaInPinNames(), wx.CB_READONLY) self.cmbAnalogIn.SetLabel("Select pin") self.btAnalogRead = wx.Button(self.main_pannel, -1, "", wx.Point(250, 400), wx.Size(85, 30)) self.btAnalogRead.SetLabel("Read") self.Bind(wx.EVT_BUTTON, self.OnAnaRead, self.btAnalogRead) self.ledAnalogRead = wx.gizmos.LEDNumberCtrl(self.main_pannel, -1, wx.Point(350, 400), wx.Size(75, 40)) self.SerPort = wx.StaticBox(self.main_pannel, -1, "", wx.Point(10, 10), wx.Size(500, 71)) self.SerPort.SetLabel('Serial port selection') self.stSelPort = wx.StaticText(self.main_pannel, -1, "", wx.Point(20, 35), wx.Size(140, 20), wx.ST_NO_AUTORESIZE) self.stSelPort.SetLabel("Select a serial port") self.cmbDigiRead = wx.ComboBox(self.main_pannel, -1, "", wx.Point(160, 215), wx.Size(80, 25), digi_pins, wx.CB_READONLY) self.cmbDigiRead.SetLabel("Select Pin") self.btClosePrt = wx.Button(self.main_pannel, -1, "", wx.Point(385, 30), wx.Size(85, 30)) self.btClosePrt.SetLabel("Close") self.Bind(wx.EVT_BUTTON, self.OnClosePrt, self.btClosePrt) self.btDigiRead = wx.Button(self.main_pannel, -1, "", wx.Point(250, 215), wx.Size(85, 30)) self.btDigiRead.SetLabel("Read") self.Bind(wx.EVT_BUTTON, self.OnDigiRead, self.btDigiRead) self.Refresh() return def VwXDelComp(self): return #[win]add your code here def OnOpenPrt(self, event): #init function #[51e]Code event VwX...Don't modify[51e]# #add your code here ser_prt = self.cmbSerPort.GetValue().encode('ASCII') if (ser_prt == ""): return # lets try and create a TransLayer object try: self.ArdCtrl = TransLayer(ser_prt, self.conf.getVref(), self.conf.getRes()) print self.conf.getVref() self.btOpenPrt.Enable(False) self.btClosePrt.Enable(True) self.btDigiOutSet.Enable(True) self.btDigiRead.Enable(True) self.btAnalogOut.Enable(True) self.btAnalogRead.Enable(True) except IOError, error: err = str(error) wx.MessageBox(err + "\n Application exiting...") sys.exit(1) return #end function
class QuickCtlConfig(wx.Frame): def __init__(self, parent, cfgFile="Arduino_Duemilanove.cfg"): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, size=wx.Size(373, 507), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) # This named tuple acts like the group holder for GUI controls # that we need to control self.ctls = namedtuple("ctls", 'availableLstCtl selectedLstCtl') self.ctlDic = {} self.serPort = "" self.cfgFile = cfgFile # Try to open the config file and load the values try: self.cfg = ConfigHandler(self.cfgFile) except: wx.MessageBox(cfgFile + " was not found ") wx.Exit() self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) frameSizer = wx.BoxSizer(wx.VERTICAL) self.mainPanel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) mainSizer = wx.BoxSizer(wx.VERTICAL) #mainSizer.Add( gpioBox, 1, wx.EXPAND, 5 ) sizer = self.addPerBox('GPIOs', 'gpio') mainSizer.Add(sizer, 1, wx.EXPAND, 5) sizer = self.addPerBox('DACs', 'dac') mainSizer.Add(sizer, 1, wx.EXPAND, 5) sizer = self.addPerBox('ADCs', 'adc') mainSizer.Add(sizer, 1, wx.EXPAND, 5) # Let's popuate the list box with the pins that are available # first read the pickle file associated with the config file # and populate appropriately try: pick = os.path.splitext(self.cfgFile)[0] + '.pickle' pick = file(pick) self.selectedCtlDic = pickle.load(pick) except: self.selectedCtlDic = {'gpio': [], 'dac': [], 'adc': []} self.selectedCtlDic['gpio'].sort(self.cfg.__cmp__) self.selectedCtlDic['adc'].sort(self.cfg.__cmp__) self.selectedCtlDic['dac'].sort(self.cfg.__cmp__) gpios = self.cfg.getDigiPinNames() gpios = self.__reomove_dups__(gpios, self.selectedCtlDic['gpio']) self.ctlDic['gpio'].availableLstCtl.InsertItems(gpios, 0) self.ctlDic['gpio'].selectedLstCtl.InsertItems( self.selectedCtlDic['gpio'], 0) dacs = self.cfg.getAnaOutPinNames() dacs = self.__reomove_dups__(dacs, self.selectedCtlDic['dac']) self.ctlDic['dac'].availableLstCtl.InsertItems(dacs, 0) self.ctlDic['dac'].selectedLstCtl.InsertItems( self.selectedCtlDic['dac'], 0) adcs = self.cfg.getAnaInPinNames() adcs = self.__reomove_dups__(adcs, self.selectedCtlDic['adc']) self.ctlDic['adc'].availableLstCtl.InsertItems(adcs, 0) self.ctlDic['adc'].selectedLstCtl.InsertItems( self.selectedCtlDic['adc'], 0) self.availbleCtlDic = {'gpio': gpios, 'dac': dacs, 'adc': adcs} self.prts = GetSerPorts() self.ports = self.prts.get_ports() sdbSizer = wx.StdDialogButtonSizer() self.sdbSizerOK = wx.Button(self.mainPanel, wx.ID_OK) self.sdbSizerOK.Bind(wx.EVT_BUTTON, self.onOk) sdbSizer.AddButton(self.sdbSizerOK) self.sdbSizerCancel = wx.Button(self.mainPanel, wx.ID_CANCEL) self.sdbSizerCancel.Bind(wx.EVT_BUTTON, self.onCancel) sdbSizer.AddButton(self.sdbSizerCancel) sdbSizer.Realize() self.stPortName = wx.StaticText(self.mainPanel, -1, " Select the serial port name") self.cmbSerPort = wx.ComboBox(self.mainPanel, -1, "", wx.Point(120, 35), wx.Size(15, 21), self.ports, wx.CB_READONLY) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.stPortName, 1, wx.EXPAND, 10) sizer.Add(self.cmbSerPort, 1, wx.EXPAND, 1) mainSizer.Add((0, 20)) mainSizer.Add(sizer, .9, wx.EXPAND, 5) mainSizer.Add((0, 10)) mainSizer.Add(sdbSizer, .8, wx.EXPAND, 5) mainSizer.Add((0, 20)) self.mainPanel.SetSizer(mainSizer) self.mainPanel.Layout() mainSizer.Fit(self.mainPanel) frameSizer.Add(self.mainPanel, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(frameSizer) # Now that all the GUI controls are laid out, let us now populate the lists self.Layout() self.Centre(wx.BOTH) def __reomove_dups__(self, origList, copyList): """ Removes entries from origList that are present in origList """ if len(origList) == 0: return for cp in copyList: if cp in origList: origList.remove(cp) return origList def onL2r(self, event): button = event.GetEventObject() btnId = event.GetId() btnById = self.FindWindowById(btnId) name = btnById.GetName().replace('l2r', '') selection = self.ctlDic[name].availableLstCtl.GetStringSelection() if selection == '': return self.ctlDic[name].selectedLstCtl.Append(selection) self.selectedCtlDic[name].append(selection) n = self.ctlDic[name].availableLstCtl.FindString(selection) self.ctlDic[name].availableLstCtl.Delete(n) #print self.selectedCtlDic[name] def onR2l(self, event): button = event.GetEventObject() btnId = event.GetId() btnById = self.FindWindowById(btnId) name = btnById.GetName().replace('r2l', '') selection = self.ctlDic[name].selectedLstCtl.GetStringSelection() if selection == '': return self.ctlDic[name].availableLstCtl.Append(selection) self.selectedCtlDic[name].remove(selection) n = self.ctlDic[name].selectedLstCtl.FindString(selection) self.ctlDic[name].selectedLstCtl.Delete(n) #print self.selectedCtlDic[name] def onOk(self, event): # Let us store the user selections cfgFile = os.path.splitext(self.cfgFile)[0] # serialize pick = file(cfgFile + '.pickle', 'w') self.selectedCtlDic['gpio'].sort(self.cfg.__cmp__) self.selectedCtlDic['adc'].sort(self.cfg.__cmp__) self.selectedCtlDic['dac'].sort(self.cfg.__cmp__) pickle.dump(self.selectedCtlDic, pick) serPort = self.cmbSerPort.GetValue().encode('ASCII') try: quickCtlFrame = QuickCtl(serPort, self.cfg, self.selectedCtlDic['gpio'], self.selectedCtlDic['adc'], self.selectedCtlDic['dac']) self.Show(False) except: wx.MessageBox("Oops, there was a problem", style=wx.ICON_EXCLAMATION) wx.Exit() quickCtlFrame.Show(True) def onCancel(self, event): self.Close() def addPerBox(self, title='GPIOs', name='gpio'): # We will use a dictionary to hold all the info required to # control the list item boxSizer = wx.StaticBoxSizer( wx.StaticBox(self.mainPanel, wx.ID_ANY, title), wx.VERTICAL) vSizer = wx.BoxSizer(wx.HORIZONTAL) leftVSizer = wx.BoxSizer(wx.VERTICAL) self.stAvailablePorts = wx.StaticText(self.mainPanel, wx.ID_ANY, u"Available port(s)", wx.DefaultPosition, wx.DefaultSize, 0) self.stAvailablePorts.Wrap(-1) leftVSizer.Add(self.stAvailablePorts, 0, wx.ALL, 5) self.lstAvailablePorts = wx.ListBox(self.mainPanel, wx.ID_ANY, wx.DefaultPosition, (100, 75), style=wx.LB_SORT) leftVSizer.Add(self.lstAvailablePorts, 0, wx.ALL, 5) vSizer.Add(leftVSizer, 1, wx.EXPAND, 5) midVSizer = wx.BoxSizer(wx.VERTICAL) midVSizer.Add((0, 30)) self.btnLeftToRight = wx.Button(self.mainPanel, wx.ID_ANY, u">>", wx.DefaultPosition, wx.DefaultSize, 0, name=name + 'l2r') self.btnLeftToRight.Bind(wx.EVT_BUTTON, self.onL2r) midVSizer.Add(self.btnLeftToRight, 0, wx.ALIGN_CENTER | wx.ALL, 5) self.btnRightToLeft = wx.Button(self.mainPanel, wx.ID_ANY, u"<<", wx.DefaultPosition, wx.DefaultSize, 0, name=name + 'r2l') self.btnRightToLeft.Bind(wx.EVT_BUTTON, self.onR2l) midVSizer.Add(self.btnRightToLeft, 0, wx.ALIGN_CENTER | wx.ALL, 5) vSizer.Add(midVSizer, 1, wx.EXPAND, 10) rightVSizer = wx.BoxSizer(wx.VERTICAL) self.stSelectedPorts = wx.StaticText(self.mainPanel, wx.ID_ANY, u"Selected port(s)", wx.DefaultPosition, wx.DefaultSize, 0) self.stSelectedPorts.Wrap(-1) rightVSizer.Add(self.stSelectedPorts, 0, wx.ALL, 5) self.lstSelectedPorts = wx.ListBox(self.mainPanel, wx.ID_ANY, wx.DefaultPosition, (100, 75), style=wx.LB_SORT) rightVSizer.Add(self.lstSelectedPorts, 0, wx.ALL, 5) temp = self.ctls(self.lstAvailablePorts, self.lstSelectedPorts) vSizer.Add(rightVSizer, 1, wx.EXPAND, 5) boxSizer.Add(vSizer, 1, wx.ALIGN_CENTER | wx.EXPAND, 5) self.ctlDic[name] = temp return boxSizer def __del__(self): wx.Exit() return