def __init__(self, parent, API): wx.Panel.__init__(self, parent) self.API = API self.active = False self.tab = None label = wx.StaticText(self, label = localize("When code recieved") + ":") self.choice = wx.ComboBox(self, style = wx.CB_DROPDOWN | wx.CB_READONLY, choices = ['open', 'save', 'upload'], name = "action") self.choice.SetValue("open") #TODO: remember self.start = wx.Button(self, label = localize("Start Seal-Blockly editor")) controls = wx.BoxSizer(wx.HORIZONTAL) controls.Add(label, 0, wx.EXPAND | wx.ALL) controls.Add(self.choice, 0, wx.EXPAND | wx.ALL) controls.Add(self.start, 0, wx.EXPAND | wx.LEFT | wx.RIGHT) self.outputArea = wx.TextCtrl(self, style = wx.TE_MULTILINE) self.outputArea.SetBackgroundColour("black") self.outputArea.SetForegroundColour("white") self.outputArea.SetEditable(False) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(controls, 0, wx.EXPAND | wx.wx.TOP | wx.LEFT | wx.RIGHT, 10) sizer.Add(self.outputArea, 1, wx.EXPAND | wx.ALL, 5) self.Bind(wx.EVT_BUTTON, self.toggleListen, self.start) self.SetBackgroundColour("white") self.SetSizerAndFit(sizer) self.SetAutoLayout(1) self.Hide()
def toggleListen(self, event = None): self.active = not self.active if self.active: self.start.SetLabel(localize("Stop Seal-Blockly editor")) self.run() else: self.start.SetLabel(localize("Start Seal-Blockly editor"))
def __init__(self, parent, API): self.API = API super(NewMote, self).__init__(parent=parent, title=localize("Add new mote")) self.main = wx.BoxSizer(wx.VERTICAL) self.controls = wx.GridBagSizer(10, 10) self.newMote = wx.Button(self, label=localize("Add mote")) self.close = wx.Button(self, label=localize("Close")) self.controls.Add(self.close, (2, 0), flag=wx.EXPAND | wx.ALL) self.controls.Add(self.newMote, (2, 1), flag=wx.EXPAND | wx.ALL) nameText = wx.StaticText(self, label=localize("Mote name") + ":") self.controls.Add(nameText, (0, 0), flag=wx.EXPAND | wx.ALL) self.name = wx.TextCtrl(self) self.controls.Add(self.name, (0, 1), flag=wx.EXPAND | wx.ALL) portText = wx.StaticText(self, label=localize("Mote port") + ":") self.controls.Add(portText, (1, 0), flag=wx.EXPAND | wx.ALL) self.port = wx.TextCtrl(self) self.controls.Add(self.port, (1, 1), flag=wx.EXPAND | wx.ALL) self.portError = wx.StaticText(self, label="") self.controls.Add(self.portError, (1, 2), flag=wx.EXPAND | wx.ALL) self.main.Add(self.controls, 0, wx.EXPAND | wx.ALL, 3) self.Bind(wx.EVT_BUTTON, self.addNewMote, self.newMote) self.Bind(wx.EVT_BUTTON, self.doClose, self.close) self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show()
def onCloseCheck(self, event = None): if self.getPageObject() == None: # Nothing to check return True if self.getPageObject().saveState == False: # Initiate DialogBox dialog = wx.MessageDialog(self, localize('Save changes to') + ' "' + self.getPageObject().fileName + '" ' + localize('before close it?'), localize('Unsaved file') + ' "' + self.getPageObject().fileName + '"', wx.YES_NO | wx.CANCEL | wx.ICON_EXCLAMATION) retVal = dialog.ShowModal() if retVal == wx.ID_YES: # Create save dialog self.doPopupSave(None) # Recursion to make sure it's really saved. return self.onCloseCheck() elif retVal == wx.ID_CANCEL: # Stop action if there is any if event: event.Veto() return False # It's ok to close return True
def doPopupSave(self, event): if self.getPageObject() == None: return if self.getPageObject().hasAFile == True: self.getPageObject().save() else: save = wx.FileDialog( self, localize("Save") + " \"" + str(self.GetPageText(self.GetSelection())) + '"', wildcard='Seal ' + localize('files') + ' (*.sl)|*.sl|' + localize('All files') + '|*', style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, defaultFile=self.getPageObject().fileName) if save.ShowModal() == wx.ID_OK: if not save.GetPath().endswith(".sl") and self.getPageObject( ).projectType == SEAL_PROJECT: self.getPageObject().updateInfo(path=save.GetPath() + '.sl') else: self.getPageObject().updateInfo(path=save.GetPath()) self.getPageObject().save() self.getPageObject().hasAFile = True save.Destroy() return self.getPageObject().hasAFile == True
def __init__(self, parent, API): super(ListenModule, self).__init__(parent) self.API = API self.haveMote = False self.listening = False self.args = {'serialPort': '/dev/ttyUSB0', 'baudrate': 38400} Motelist.addUpdateCallback(self.updateMotelist) self.SetBackgroundColour("white") self.main = wx.BoxSizer(wx.VERTICAL) self.listenControls = wx.BoxSizer(wx.HORIZONTAL) self.ports = wx.ComboBox(self, choices=[], size=(300, -1)) self.clear = wx.Button(self, label=localize("Start listening")) self.refresh = wx.Button(self, label=localize("Refresh")) self.clearOutput = wx.Button(self, label=localize("Clear")) self.saveOutput = wx.Button(self, label=localize("Save to file")) self.baudrate = wx.ComboBox(self, choices=[ '2400', '4800', '9600', '19200', '38400', '57600', '115200' ]) self.baudrate.SetSelection(4) self.ports.SetEditable(False) # Init outputArea for output self.outputArea = OutputArea(self, self.API, 1) self.updateStatus = self.outputArea.printLine self.clearOutputArea = self.outputArea.clear self.listenControls.Add(self.ports) self.listenControls.Add(self.baudrate) self.listenControls.Add(self.refresh) self.listenControls.Add(self.clear) self.listenControls.Add(self.clearOutput) self.listenControls.Add(self.saveOutput) self.main.Add(self.listenControls, 0, wx.EXPAND | wx.wx.TOP | wx.LEFT | wx.RIGHT, 10) self.main.Add(self.outputArea, 1, wx.EXPAND | wx.ALL, 5) self.Bind(wx.EVT_BUTTON, self.doClear, self.clear) self.Bind(wx.EVT_BUTTON, self.updateMotelist, self.refresh) self.Bind(wx.EVT_BUTTON, self.clearOutputArea, self.clearOutput) self.Bind(wx.EVT_BUTTON, self.saveOutputArea, self.saveOutput) self.Bind(wx.EVT_COMBOBOX, self.changeTarget, self.ports) self.Bind(wx.EVT_COMBOBOX, self.changeBaudrate, self.baudrate) self.Bind(wx.EVT_TEXT, self.changeTarget, self.ports) #self.updateMotelist() self.SetSizer(self.main) self.main.Fit(self) self.Show()
def __init__(self, parent, API): super(UploadModule, self).__init__(parent=parent) self.API = API self.editorManager = self.API.tabManager.GetCurrentPage() self.filename = self.editorManager.fileName Motelist.addUpdateCallback(self.updateMotelist) self.tmpDir = self.API.path + '/temp/' self.haveMote = False self.platform = "telosb" self.moteOrder = list() # this is path from /osw/tools/IDE self.pathToMansos = self.API.path + "/../.." self.motes = [] self.main = wx.BoxSizer(wx.VERTICAL) self.controls = wx.GridBagSizer(10, 10) #self.source = wx.ComboBox(self, choices = ["USB", "Shell"]) #self.source.SetValue("USB") self.upload = wx.Button(self, label=localize("Upload")) self.platforms = wx.ComboBox(self, choices=self.API.getPlatforms()) self.refresh = wx.Button(self, label=localize("Refresh")) self.compile = wx.Button(self, label=localize("Compile")) self.newMote = wx.Button(self, label=localize("Add mote")) self.platforms.SetValue(self.API.getActivePlatform()) if self.API.platformOnly != None: self.platforms.Enable(False) self.controls.Add(self.compile, (0, 0), flag=wx.EXPAND | wx.ALL) self.controls.Add(self.platforms, (0, 1), flag=wx.EXPAND | wx.ALL) self.controls.Add(self.upload, (0, 2), span=(2, 2), flag=wx.EXPAND | wx.ALL) #self.controls.Add(self.source, (1, 1), flag = wx.EXPAND | wx.ALL) self.controls.Add(self.newMote, (1, 1), flag=wx.EXPAND | wx.ALL) self.controls.Add(self.refresh, (1, 0), flag=wx.EXPAND | wx.ALL) self.list = wx.CheckListBox(self, wx.ID_ANY, style=wx.MULTIPLE) self.main.Add(self.controls, 0, wx.EXPAND | wx.ALL, 3) self.main.Add(self.list, 0, wx.EXPAND | wx.ALL, 3) self.Bind(wx.EVT_BUTTON, self.API.doCompile, self.compile) self.Bind(wx.EVT_BUTTON, self.API.doUpload, self.upload) self.Bind(wx.EVT_BUTTON, self.updateMotelist, self.refresh) #self.Bind(wx.EVT_COMBOBOX, self.populateMotelist, self.source) self.Bind(wx.EVT_BUTTON, self.openNewMoteDialog, self.newMote) self.Bind(wx.EVT_COMBOBOX, self.API.changePlatform, self.platforms) self.Bind(wx.EVT_CHECKLISTBOX, self.modifyTargets, self.list) self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show() self.updateMotelist()
def __init__(self, parent, API): super(ListenModule, self).__init__(parent) self.API = API self.haveMote = False self.listening = False self.args = { 'serialPort': '/dev/ttyUSB0', 'baudrate': 38400 } Motelist.addUpdateCallback(self.updateMotelist) self.SetBackgroundColour("white") self.main = wx.BoxSizer(wx.VERTICAL) self.listenControls = wx.BoxSizer(wx.HORIZONTAL) self.ports = wx.ComboBox(self, choices = [], size = (300, -1)) self.clear = wx.Button(self, label = localize("Start listening")) self.refresh = wx.Button(self, label = localize("Refresh")) self.clearOutput = wx.Button(self, label = localize("Clear")) self.saveOutput = wx.Button(self, label = localize("Save to file")) self.baudrate = wx.ComboBox(self, choices = ['2400', '4800', '9600', '19200', '38400', '57600', '115200']) self.baudrate.SetSelection(4); self.ports.SetEditable(False) # Init outputArea for output self.outputArea = OutputArea(self, self.API, 1) self.updateStatus = self.outputArea.printLine self.clearOutputArea = self.outputArea.clear self.listenControls.Add(self.ports) self.listenControls.Add(self.baudrate) self.listenControls.Add(self.refresh) self.listenControls.Add(self.clear) self.listenControls.Add(self.clearOutput) self.listenControls.Add(self.saveOutput) self.main.Add(self.listenControls, 0, wx.EXPAND | wx.wx.TOP | wx.LEFT | wx.RIGHT, 10); self.main.Add(self.outputArea, 1, wx.EXPAND | wx.ALL, 5); self.Bind(wx.EVT_BUTTON, self.doClear, self.clear) self.Bind(wx.EVT_BUTTON, self.updateMotelist, self.refresh) self.Bind(wx.EVT_BUTTON, self.clearOutputArea, self.clearOutput) self.Bind(wx.EVT_BUTTON, self.saveOutputArea, self.saveOutput) self.Bind(wx.EVT_COMBOBOX, self.changeTarget, self.ports) self.Bind(wx.EVT_COMBOBOX, self.changeBaudrate, self.baudrate) self.Bind(wx.EVT_TEXT, self.changeTarget, self.ports) #self.updateMotelist() self.SetSizer(self.main) self.main.Fit(self) self.Show()
def __init__(self, parent, API): super(UploadModule, self).__init__(parent = parent) self.API = API self.editorManager = self.API.tabManager.GetCurrentPage() self.filename = self.editorManager.fileName Motelist.addUpdateCallback(self.updateMotelist) self.tmpDir = self.API.path + '/temp/' self.haveMote = False self.platform = "telosb" self.moteOrder = list() # this is path from /mansos/tools/IDE self.pathToMansos = self.API.path + "/../.." self.motes = [] self.main = wx.BoxSizer(wx.VERTICAL) self.controls = wx.GridBagSizer(10, 10) #self.source = wx.ComboBox(self, choices = ["USB", "Shell"]) #self.source.SetValue("USB") self.upload = wx.Button(self, label = localize("Upload")) self.platforms = wx.ComboBox(self, choices = self.API.getPlatforms()) self.refresh = wx.Button(self, label = localize("Refresh")) self.compile = wx.Button(self, label = localize("Compile")) self.newMote = wx.Button(self, label = localize("Add mote")) self.platforms.SetValue(self.API.getActivePlatform()) if self.API.platformOnly != None: self.platforms.Enable(False) self.controls.Add(self.compile, (0, 0), flag = wx.EXPAND | wx.ALL) self.controls.Add(self.platforms, (0, 1), flag = wx.EXPAND | wx.ALL) self.controls.Add(self.upload, (0, 2), span = (2, 2), flag = wx.EXPAND | wx.ALL) #self.controls.Add(self.source, (1, 1), flag = wx.EXPAND | wx.ALL) self.controls.Add(self.newMote, (1, 1), flag = wx.EXPAND | wx.ALL) self.controls.Add(self.refresh, (1, 0), flag = wx.EXPAND | wx.ALL) self.list = wx.CheckListBox(self, wx.ID_ANY, style = wx.MULTIPLE) self.main.Add(self.controls, 0, wx.EXPAND | wx.ALL, 3); self.main.Add(self.list, 0, wx.EXPAND | wx.ALL, 3); self.Bind(wx.EVT_BUTTON, self.API.doCompile, self.compile) self.Bind(wx.EVT_BUTTON, self.API.doUpload, self.upload) self.Bind(wx.EVT_BUTTON, self.updateMotelist, self.refresh) #self.Bind(wx.EVT_COMBOBOX, self.populateMotelist, self.source) self.Bind(wx.EVT_BUTTON, self.openNewMoteDialog, self.newMote) self.Bind(wx.EVT_COMBOBOX, self.API.changePlatform, self.platforms) self.Bind(wx.EVT_CHECKLISTBOX, self.modifyTargets, self.list) self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show() self.updateMotelist()
def saveOutputArea(self, event): save = wx.FileDialog(self, localize("Save node output") + " \"", wildcard=localize('All files') + '|*', style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, defaultFile=self.args["serialPort"]) if save.ShowModal() == wx.ID_OK: with open(save.GetPath(), "w") as out: out.write(self.outputArea.outputArea.GetValue()) save.Destroy()
def saveOutputArea(self, event): save = wx.FileDialog(self, localize("Save node output") + " \"", wildcard = localize('All files') + '|*', style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, defaultFile = self.args["serialPort"]) if save.ShowModal() == wx.ID_OK: with open(save.GetPath(),"w") as out: out.write(self.outputArea.outputArea.GetValue()) save.Destroy()
def doPopupSaveAs(self, event): save = wx.FileDialog(self, localize("Save as") + " \"" + str(self.GetPageText(self.GetSelection())) + '"', wildcard = 'Seal ' + localize('files') + ' (*.sl)|*.sl|' + localize('All files') + '|*', style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, defaultFile = self.getPageObject().fileName) if save.ShowModal() == wx.ID_OK: if not save.GetPath().endswith(".sl") and self.getPageObject().projectType == SEAL_PROJECT: self.getPageObject().updateInfo(path = save.GetPath() + '.sl') else: self.getPageObject().updateInfo(path = save.GetPath()) self.getPageObject().save() self.getPageObject().hasAFile = True save.Destroy()
def generateSecondTier(self, value, choices=None): if self.name is None: if choices is None: choices = list() # Generate and place both 2nd tier objects objText = wx.StaticText(self, label=localize("Edit object") + ":") self.data.Add(objText, pos=(1, 0)) self.name = wx.ComboBox(self, choices=choices, size=(150, 25), style=wx.CB_DROPDOWN, name="object") self.data.Add(self.name, pos=(1, 1)) # Only for title change self.Bind(wx.EVT_COMBOBOX, self.onObjChange, self.name) self.Bind(wx.EVT_TEXT, self.onObjChange, self.name) # Update choices if needed, must do before value update if choices != self.name.GetItems(): self.name.Clear() self.name.AppendItems(choices) # Update value if needed, must do after choices update if value is not None: if value.lower() != self.name.GetValue().lower(): self.name.SetValue(value) else: self.name.SetValue('') # Return if 3rd tier needs to be generated return self.name.GetValue() != ''
def generateFirstTier(self, value): if self.type is None: # Generate and place both 1st tier objects actuatorText = wx.StaticText(self, label=localize("Edit actuator") + ":") self.data.Add(actuatorText, pos=(0, 0)) self.type = wx.ComboBox(self, choices=self.API.getKeywords(), style=wx.CB_DROPDOWN, name="actuator", size=(150, 25)) self.data.Add(self.type, pos=(0, 1)) self.Bind(wx.EVT_COMBOBOX, self.onActuatorChange, self.type) self.Bind(wx.EVT_TEXT, self.onActuatorChange, self.type) # Update value if needed if value is not None: if value.lower() != self.type.GetValue().lower(): self.type.SetValue(str(value)) else: self.type.SetValue('') # Return if 2nd tier needs to be generated return True #self.type.GetValue() != ''
def generateSecondTier(self, value, choices = None): if self.name is None: if choices is None: choices = list() # Generate and place both 2nd tier objects objText = wx.StaticText(self, label = localize("Edit object") + ":") self.data.Add(objText, pos = (1, 0)) self.name = wx.ComboBox(self, choices = choices, size = (150, 25), style = wx.CB_DROPDOWN, name = "object") self.data.Add(self.name, pos = (1, 1)) # Only for title change self.Bind(wx.EVT_COMBOBOX, self.onObjChange, self.name) self.Bind(wx.EVT_TEXT, self.onObjChange, self.name) # Update choices if needed, must do before value update if choices != self.name.GetItems(): self.name.Clear() self.name.AppendItems(choices) # Update value if needed, must do after choices update if value is not None: if value.lower() != self.name.GetValue().lower(): self.name.SetValue(value) else: self.name.SetValue('') # Return if 3rd tier needs to be generated return self.name.GetValue() != ''
def addNewMote(self, event): if not Motelist.portExists(self.port.GetValue()): self.portError.SetLabel(localize("No device found on this port") + "!") self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show() else: if Motelist.addMote(self.port.GetValue(), self.name.GetValue(), "User defined"): self.API.updateUserMotes() self.Close() else: self.portError.SetLabel(localize("There already is device on that port in list") + "!") self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show()
def updateMotelist(self, event = None): oldVal = self.ports.GetValue() self.haveMote = False self.ports.Clear() for mote in Motelist.getMotelist(False): if not self.haveMote: self.args['serialPort'] = mote.getPort() self.haveMote = True self.ports.Append(mote.getNiceName()) self.ports.SetStringSelection(oldVal) if self.ports.GetValue() == "": if self.haveMote: self.ports.SetValue(localize("Use default device")) else: self.ports.SetValue(localize("No devices found"))
def __init__(self, parent, API): wx.Panel.__init__(self, parent) self.API = API; self.API.editors.append(self) self.initUI() self.lastSaved = '' ### Editor visible variables # @ creation we assume document is not saved. self.saveState = False # Filename or untitled document self.fileName = localize('Untitled') + str(self.GetParent().nextPageNr) + '.sl' # Filename and full path(relative or absolute) self.filePath = localize('Untitled') + str(self.GetParent().nextPageNr) + '.sl' # This marks if document already have a file attached to it self.hasAFile = False # Define project type self.projectType = SEAL_PROJECT self.detectSEAL()
def updateMotelist(self, event=None): oldVal = self.ports.GetValue() self.haveMote = False self.ports.Clear() for mote in Motelist.getMotelist(False): if not self.haveMote: self.args['serialPort'] = mote.getPort() self.haveMote = True self.ports.Append(mote.getNiceName()) self.ports.SetStringSelection(oldVal) if self.ports.GetValue() == "": if self.haveMote: self.ports.SetValue(localize("Use default device")) else: self.ports.SetValue(localize("No devices found"))
def loadUserMotes(self): # Read motelist from config file if os.path.exists(".motelist") and os.path.isfile(".motelist"): f = open(".motelist", 'r') lines = f.readlines() for x in lines: if x != '': if x.find("->") != -1: name, port = x.strip().split("->") Motelist.addMote(port, name, localize("User defined"))
def initCondition(self): self.clearStatement() self.main = wx.BoxSizer(wx.VERTICAL) self.condCreatorSizer = wx.BoxSizer(wx.HORIZONTAL) self.main.Add(self.condCreatorSizer, 1, wx.EXPAND | wx.ALL, 5) self.condCreador = None self.updateCondCreator(None) nextEditable = wx.Button(self, label = localize("Find next parameter")) self.Bind(wx.EVT_BUTTON, self.launchNextEditFinder, nextEditable) self.main.Add(nextEditable, 0, wx.EXPAND | wx.ALL, 5) self.textBox = None self.finishInit()
def initCondition(self): self.clearStatement() self.main = wx.BoxSizer(wx.VERTICAL) self.condCreatorSizer = wx.BoxSizer(wx.HORIZONTAL) self.main.Add(self.condCreatorSizer, 1, wx.EXPAND | wx.ALL, 5) self.condCreador = None self.updateCondCreator(None) nextEditable = wx.Button(self, label=localize("Find next parameter")) self.Bind(wx.EVT_BUTTON, self.launchNextEditFinder, nextEditable) self.main.Add(nextEditable, 0, wx.EXPAND | wx.ALL, 5) self.textBox = None self.finishInit()
def changePlatform(self, event): if event is not None: platform = event.GetEventObject().GetValue() else: platform = "telosb" if platform in self.platforms: self.activePlatform = self.platforms.index(platform) else: self.activePlatform = self.platforms.index("telosb") self.printInfo(localize("Changed platform to") + " " + self.getActivePlatform() + "\n")
def doClear(self, event=None): self.API.stopThread("Serial port listener") # String is returned when callback triggers, so by that we always know # that we do not listen now if type(event) is str: if self.listening: self.listening = False self.clear.SetLabel(localize('Start listening')) self.updateStatus("\nListening stopped.\n", False) return if self.ports.GetValue() == "No devices found": return self.listening = not self.listening if self.listening: self.clear.SetLabel(localize('Stop listening')) self.updateStatus("\nListening started.\n", False) else: self.clear.SetLabel(localize('Start listening')) self.updateStatus("\nListening stopped.\n", False) # Redraw button if size have changed self.clear.SetSize(self.clear.GetEffectiveMinSize()) if self.API.getActivePlatform() not in ['xm1000', 'z1']: # make sure reset pin is low for the platforms that need it self.args['reset'] = True else: self.args['reset'] = False if self.listening: thread = MyThread(listenSerialPort, self.args, \ self.doClear, False, True, \ "Serial port listener", self.updateStatus) self.API.startThread(thread) else: self.API.stopThread("Serial port listener")
def doClear(self, event = None): self.API.stopThread("Serial port listener") # String is returned when callback triggers, so by that we always know # that we do not listen now if type(event) is str: if self.listening: self.listening = False self.clear.SetLabel(localize('Start listening')) self.updateStatus("\nListening stopped.\n", False) return if self.ports.GetValue() == "No devices found": return; self.listening = not self.listening if self.listening: self.clear.SetLabel(localize('Stop listening')) self.updateStatus("\nListening started.\n", False) else: self.clear.SetLabel(localize('Start listening')) self.updateStatus("\nListening stopped.\n", False) # Redraw button if size have changed self.clear.SetSize(self.clear.GetEffectiveMinSize()) if self.API.getActivePlatform() not in ['xm1000', 'z1'] : # make sure reset pin is low for the platforms that need it self.args['reset'] = True else: self.args['reset'] = False if self.listening: thread = MyThread(listenSerialPort, self.args, \ self.doClear, False, True, \ "Serial port listener", self.updateStatus) self.API.startThread(thread) else: self.API.stopThread("Serial port listener")
def __init__(self, parent, API): wx.Panel.__init__(self, parent) self.API = API self.API.editors.append(self) self.initUI() self.lastSaved = '' ### Editor visible variables # @ creation we assume document is not saved. self.saveState = False # Filename or untitled document self.fileName = localize('Untitled') + str( self.GetParent().nextPageNr) + '.sl' # Filename and full path(relative or absolute) self.filePath = localize('Untitled') + str( self.GetParent().nextPageNr) + '.sl' # This marks if document already have a file attached to it self.hasAFile = False # Define project type self.projectType = SEAL_PROJECT self.detectSEAL()
def updateCondCreator(self, event): if self.condCreador is None: condCreatorText = wx.StaticText(self, label = localize("Choose function") + ":") self.condCreador = wx.ComboBox(self, choices = [""] + self.API.sealSyntax.getFunctionBodys(), style = wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SIMPLE, name = "CondCreator") self.Bind(wx.EVT_COMBOBOX, self.ekeCondition, self.condCreador) self.main.Add(condCreatorText) self.main.Add(self.condCreador, 0, wx.EXPAND | wx.ALL, 5) else: # In future I plan to adjust proposed function depending on selection pass
def addNewMote(self, event): if not Motelist.portExists(self.port.GetValue()): self.portError.SetLabel( localize("No device found on this port") + "!") self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show() else: if Motelist.addMote(self.port.GetValue(), self.name.GetValue(), "User defined"): self.API.updateUserMotes() self.Close() else: self.portError.SetLabel( localize("There already is device on that port in list") + "!") self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show()
def changePlatform(self, event): if event is not None: platform = event.GetEventObject().GetValue() else: platform = "telosb" if platform in self.platforms: self.activePlatform = self.platforms.index(platform) else: self.activePlatform = self.platforms.index("telosb") self.printInfo( localize("Changed platform to") + " " + self.getActivePlatform() + "\n")
def addPage(self, newFile = ''): if newFile == '': self.AddPage(EditorManager(self, self.API), localize("Untitled") + ' ' + str(self.nextPageNr) + '.sl') else: self.AddPage(EditorManager(self, self.API), newFile) self.nextPageNr += 1 self.SetSelection(self.GetPageCount() - 1) # Add any file associated with it self.getPageObject().update(newFile) self.Layout() self.API.frame.deactivateNoEditorMode() self.onPageChanged(None)
def __init__(self, parent, API): aui.AuiNotebook.__init__(self, parent, style = aui.AUI_NB_CLOSE_ON_ACTIVE_TAB | aui.AUI_NB_SMART_TABS) self.API = API self.API.tabManager = self # Need to set because next statement uses it self.nextPageNr = 1 self.AddPage(EditorManager(self, self.API), localize("Untitled")) self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.onPageChanged) self.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.doPopupClose) #self.Bind(aui.EVT_AUINOTEBOOK_BUTTON, self.onCloseCheck) self.Bind(aui.EVT_AUINOTEBOOK_TAB_RIGHT_DOWN, self.showPopupMenu)
def __init__(self, parent, API): self.API = API super(NewMote, self).__init__(parent = parent, title = localize("Add new mote")) self.main = wx.BoxSizer(wx.VERTICAL) self.controls = wx.GridBagSizer(10, 10) self.newMote = wx.Button(self, label = localize("Add mote")) self.close = wx.Button(self, label = localize("Close")) self.controls.Add(self.close, (2, 0), flag = wx.EXPAND | wx.ALL) self.controls.Add(self.newMote, (2, 1), flag = wx.EXPAND | wx.ALL) nameText = wx.StaticText(self, label = localize("Mote name") + ":") self.controls.Add(nameText, (0, 0), flag = wx.EXPAND | wx.ALL) self.name = wx.TextCtrl(self) self.controls.Add(self.name, (0, 1), flag = wx.EXPAND | wx.ALL) portText = wx.StaticText(self, label = localize("Mote port") + ":") self.controls.Add(portText, (1, 0), flag = wx.EXPAND | wx.ALL) self.port = wx.TextCtrl(self) self.controls.Add(self.port, (1, 1), flag = wx.EXPAND | wx.ALL) self.portError = wx.StaticText(self, label = "") self.controls.Add(self.portError, (1, 2), flag = wx.EXPAND | wx.ALL) self.main.Add(self.controls, 0, wx.EXPAND | wx.ALL, 3); self.Bind(wx.EVT_BUTTON, self.addNewMote, self.newMote) self.Bind(wx.EVT_BUTTON, self.doClose, self.close) self.SetSizerAndFit(self.main) self.SetAutoLayout(1) self.Show()
def updateCondCreator(self, event): if self.condCreador is None: condCreatorText = wx.StaticText(self, label=localize("Choose function") + ":") self.condCreador = wx.ComboBox( self, choices=[""] + self.API.sealSyntax.getFunctionBodys(), style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SIMPLE, name="CondCreator") self.Bind(wx.EVT_COMBOBOX, self.ekeCondition, self.condCreador) self.main.Add(condCreatorText) self.main.Add(self.condCreador, 0, wx.EXPAND | wx.ALL, 5) else: # In future I plan to adjust proposed function depending on selection pass
def updateMotelist(self, event = None): old = self.list.GetCheckedStrings() pos = 0 self.list.Clear() for mote in Motelist.getMotelist(False): self.list.Enable(True) self.list.Insert(mote.getNiceName(), pos) if mote.getNiceName() in old: self.list.Check(pos) pos += 1 if self.list.GetCount() == 0: self.list.Enable(False) self.list.Insert(localize("No devices found!"), 0)
def generateFirstLine(self, text, value): # Generate text and combobox if self.textBox is None: self.text = wx.StaticText(self, label = localize(text) + ":") self.textBox = wx.TextCtrl(self, name = "first", size = (100, 100), style = wx.TE_PROCESS_TAB | wx.TE_PROCESS_ENTER | wx.TE_MULTILINE | wx.TE_AUTO_SCROLL) self.textBox.Bind(wx.EVT_CHAR, self.processKeyUp) self.textBox.Bind(wx.EVT_TEXT, self.onTextChange) # Add them to layout self.condCreatorSizer.Add(self.text) self.condCreatorSizer.Add(self.textBox, 10, wx.EXPAND | wx.ALL, 5) # Update entry with new value if text is not None: self.text.SetLabel(text) if value is not None: self.textBox.SetValue(value) self.activeField = self.textBox
def generateFirstLine(self, text, value): # Generate text and combobox if self.textBox is None: self.text = wx.StaticText(self, label=localize(text) + ":") self.textBox = wx.TextCtrl(self, name="first", size=(100, 100), style=wx.TE_PROCESS_TAB | wx.TE_PROCESS_ENTER | wx.TE_MULTILINE | wx.TE_AUTO_SCROLL) self.textBox.Bind(wx.EVT_CHAR, self.processKeyUp) self.textBox.Bind(wx.EVT_TEXT, self.onTextChange) # Add them to layout self.condCreatorSizer.Add(self.text) self.condCreatorSizer.Add(self.textBox, 10, wx.EXPAND | wx.ALL, 5) # Update entry with new value if text is not None: self.text.SetLabel(text) if value is not None: self.textBox.SetValue(value) self.activeField = self.textBox
def generateFirstTier(self, value): if self.type is None: # Generate and place both 1st tier objects actuatorText = wx.StaticText(self, label = localize("Edit actuator") + ":") self.data.Add(actuatorText, pos = (0, 0)) self.type = wx.ComboBox(self, choices = self.API.getKeywords(), style = wx.CB_DROPDOWN, name = "actuator", size = (150, 25)) self.data.Add(self.type, pos = (0, 1)) self.Bind(wx.EVT_COMBOBOX, self.onActuatorChange, self.type) self.Bind(wx.EVT_TEXT, self.onActuatorChange, self.type) # Update value if needed if value is not None: if value.lower() != self.type.GetValue().lower(): self.type.SetValue(str(value)) else: self.type.SetValue('') # Return if 2nd tier needs to be generated return True #self.type.GetValue() != ''
def showPopupMenu(self, event): # Make clicked tab active, so all actions target this tab. self.SetSelection(event.GetSelection(), True) self._rmenu = wx.Menu() self.openConfig = self._rmenu.Append(wx.ID_ANY, '&' + localize("Open config file") + '', localize("Open config file")) self.openMakefile = self._rmenu.Append(wx.ID_ANY, '&' + localize("Open makefile") + '', localize("Open makefile")) self.doClean = self._rmenu.Append(wx.ID_ANY, '&' + localize("Clean target") + '', localize("Clean target")) self.popupReload = self._rmenu.Append(wx.ID_REPLACE, '&' + localize("Reload") + '\tCtrl+R', localize("Reload")) self.popupSave = self._rmenu.Append(wx.ID_SAVE, '&' + localize('Save') + '\tCtrl+S', localize("Save")) self.popupSaveAs = self._rmenu.Append(wx.ID_SAVEAS, '&' + localize("Save as") + '\tCtrl+A', localize("Save as")) self.popupClose = self._rmenu.Append(wx.ID_CLOSE, '&' + localize('Close') + '\tCtrl+W', localize("Close")) self.Bind(wx.EVT_MENU, self.doPopupConfig, self.openConfig) self.Bind(wx.EVT_MENU, self.doPopupMakefile, self.openMakefile) self.Bind(wx.EVT_MENU, self.doPopupReload, self.popupReload) self.Bind(wx.EVT_MENU, self.doPopupSave, self.popupSave) self.Bind(wx.EVT_MENU, self.doPopupSaveAs, self.popupSaveAs) self.Bind(wx.EVT_MENU, self.doPopupClose, self.popupClose) self.Bind(wx.EVT_MENU, self.API.compiler.clean, self.doClean) #Disable control if needed if self.getPageObject().saveState == True: self.popupSave.Enable(False) if self.getPageObject().fileName[-3:] != ".sl" and \ self.getPageObject().fileName[-2:] != ".c": self.openConfig.Enable(False) self.openMakefile.Enable(False) # Popup the menu. If an item is selected then its handler # will be called before PopupMenu returns. self.PopupMenu(self._rmenu) self._rmenu.Destroy()
def generateThirdTier(self, keywords, realParams, changed): # Create new objects if changed: # Destroy old objects for x in self.combo: self.data.Remove(x[0]) self.data.Remove(x[1]) x[0].Destroy() x[1].Destroy() for x in self.check: self.data.Remove(x[0]) self.data.Remove(x[1]) x[0].Destroy() x[1].Destroy() # Clear checkboxes and comboboxes, contains wrappers for deleted # objects, hope python cleans them up after this :) self.check = list() self.combo = list() # Cycle all posible parameters and draw according boxes for parameter in keywords: # This is advanced parameter, don't display it if parameter[2] == True: continue text = wx.StaticText(self, label=localize(parameter[0]) + ":") # Get real parameter associated with current name value = self.API.getParamByName(realParams, parameter[0])[1] try: if len(parameter[1]) == 0: parameter[1].append("") except Exception: parameter[1] = [""] # Create combobox or checkbox if type(parameter[1][0]) is not bool: box = wx.ComboBox(self, choices=[""] + parameter[1], style=wx.CB_DROPDOWN, size=(150, 25), name=str(parameter[0])) self.Bind(wx.EVT_TEXT, self.onParamChange, box) if value != None: box.SetValue(str(value)) self.combo.append((text, box)) else: box = wx.CheckBox(self, name=str(parameter[0])) self.Bind(wx.EVT_CHECKBOX, self.onParamChange, box) if value != None: box.SetValue(True) else: box.SetValue(False) self.check.append((text, box)) # Always starting @ 2nd row, enumeration starts from zero row = 2 # Combo's first for x in self.combo: self.data.Add(x[0], pos=(row, 0)) self.data.Add(x[1], pos=(row, 1)) row += 1 # Check's after, this way it looks nice for x in self.check: self.data.Add(x[0], pos=(row, 0)) self.data.Add(x[1], pos=(row, 1)) row += 1 # Edit old objects else: for x in self.check: # Check that everything is ok before accessing values if x[1] is not None: # Update if correct box found if x[1].GetName().lower() in realParams: x[1].SetValue(True) else: x[1].SetValue(False) for x in self.combo: # Check that everything is ok before accessing values if x[1] is not None: # Update if correct box found if x[1].GetName().lower() in realParams: x[1].SetValue(str(realParams[x[1].GetName().lower()])) else: x[1].SetValue("")
def generateThirdTier(self, keywords, realParams, changed): # Create new objects if changed: # Destroy old objects for x in self.combo: self.data.Remove(x[0]) self.data.Remove(x[1]) x[0].Destroy() x[1].Destroy() for x in self.check: self.data.Remove(x[0]) self.data.Remove(x[1]) x[0].Destroy() x[1].Destroy() # Clear checkboxes and comboboxes, contains wrappers for deleted # objects, hope python cleans them up after this :) self.check = list() self.combo = list() # Cycle all posible parameters and draw according boxes for parameter in keywords: # This is advanced parameter, don't display it if parameter[2] == True: continue text = wx.StaticText(self, label = localize(parameter[0]) + ":") # Get real parameter associated with current name value = self.API.getParamByName(realParams, parameter[0])[1] try: if len(parameter[1]) == 0: parameter[1].append("") except Exception: parameter[1] = [""] # Create combobox or checkbox if type(parameter[1][0]) is not bool: box = wx.ComboBox(self, choices = [""] + parameter[1], style = wx.CB_DROPDOWN, size = (150, 25), name = str(parameter[0])) self.Bind(wx.EVT_TEXT, self.onParamChange, box) if value != None: box.SetValue(str(value)) self.combo.append((text, box)) else: box = wx.CheckBox(self, name = str(parameter[0])) self.Bind(wx.EVT_CHECKBOX, self.onParamChange, box) if value != None: box.SetValue(True) else: box.SetValue(False) self.check.append((text, box)) # Always starting @ 2nd row, enumeration starts from zero row = 2 # Combo's first for x in self.combo: self.data.Add(x[0], pos = (row, 0)) self.data.Add(x[1], pos = (row, 1)) row += 1 # Check's after, this way it looks nice for x in self.check: self.data.Add(x[0], pos = (row, 0)) self.data.Add(x[1], pos = (row, 1)) row += 1 # Edit old objects else: for x in self.check: # Check that everything is ok before accessing values if x[1] is not None: # Update if correct box found if x[1].GetName().lower() in realParams: x[1].SetValue(True) else: x[1].SetValue(False) for x in self.combo: # Check that everything is ok before accessing values if x[1] is not None: # Update if correct box found if x[1].GetName().lower() in realParams: x[1].SetValue(str(realParams[x[1].GetName().lower()])) else: x[1].SetValue("")
def __init__(self, argv): self.loaded = False self.config = wx.Config("MansOS-IDE", style=wx.CONFIG_USE_LOCAL_FILE) self.path = os.getcwd() # All functions here will be called upon exit self.onExit = [Settings.saveConfig] Settings() # All defined platforms self.platforms = self.getPlatformsFromMakefile() self.platformOnly = None self.excludedPlatforms = list() self.activePlatform = self.platforms.index("telosb") # Flag indicates that next thread's output shouldn't trigger # force switching to info area tab. self.supressTabSwitching = False self.targets = [None] self.targetType = "USB" self.activeThreads = {} self.onExit.append(self.killAllThreads) if LOG_TO_FILE: path = os.getcwd() os.chdir(self.path) self.logFile = open(LOG_FILE_NAME, "a") os.chdir(path) self.onExit.append(self.logFile.close) # this is path from /mansos/tools/IDE self.pathToMansos = os.path.join(self.path, "../..") # Try to get system default font #font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) #self.fontName = font.GetFaceName() #if self.fontName != "": # print "Using system default font: {}".format(self.fontName) #else: self.fontName = "Courier New" # print "Can't find system default font, defaulting to {}".\ # format(self.fontName) self.listenModules = list() self.editors = list() icon = os.path.normpath('../../doc/mansos-32x32.ico') ### Module initializations # Visual objects here can be used in forms only after they have been re-parented # using their Reparent() function, else they won't be visible! self.emptyFrame = wx.Frame(None) # Defines seal syntax self.sealSyntax = SealSyntax(self) # Init translation module Translater(self) # Init output_tools #self.outputTools = OutputTools(self.emptyFrame, self) # Init outputArea for info, 1st tab self.infoArea = OutputArea(self.emptyFrame, self, 0) self.printInfo = self.infoArea.printLine self.clearInfoArea = self.infoArea.clear # Init blockly handler if os.path.exists( os.path.join(self.path, Settings.get("blockly_location"))): self.blockly = Blockly(self.emptyFrame, self) self.foundBlockly = True else: print "Warning: No SEAL-Blockly found!" self.foundBlockly = False # Init seal parser self.sealParser = seal_parser.SealParser("msp430", self.printInfo, False, True) # Init tab manager self.tabManager = TabManager(self.emptyFrame, self) # Init listenModule self.listenModules.append(ListenModule(self.emptyFrame, self)) self.editPanel = ScrolledPanel(self.emptyFrame) self.editWindow = EditStatement(self.editPanel, self) self.frame = Frame(None, "MansOS IDE", (0, 0), (0, 0), self) #self.outputTools.addTools() self.compiler = DoCompile(self) self.uploader = DoUpload(self) ### Shortcuts # This allows modules to be disabled and dummy functions attached, so other # modules can keep saving the day... Each module updates his functions at # startup and restores them at termination. All function calls between modules # should go through here, but this ain't perfect world :( self.getKeywords = self.sealSyntax.getKeywords #self.printInfo = self.dummyPrint self.printOutput = self.dummyPrint # Check if icon can be found if os.path.exists(icon): self.frame.SetIcon(wx.Icon(icon, wx.BITMAP_TYPE_ICO, 32, 32)) else: self.logMsg(LOG_WARNING, "Icon not found in '{}'!".format(icon)) # Check that everything is OK assert len(self.emptyFrame.GetChildren()) == 0, \ "There are parentless objects after API initialization.\n{}".format(\ self.emptyFrame.GetChildren()) self.syncModuleCheckboxes() # Initialize upload targets self.uploadTargets = ([], localize('the default device')) # Load last used tabs self.tabManager.loadRememberedTabs() for x in argv: self.tabManager.addPage(x) self.frame.auiManager.Update() self.loaded = True self.frame.checkToggleState() Motelist.startPeriodicUpdate() self.onExit.append(Motelist.stopPeriodicUpdate) self.loadUserMotes()
def __init__(self, argv): self.loaded = False self.config = wx.Config("OSW-IDE", style = wx.CONFIG_USE_LOCAL_FILE) self.path = os.getcwd() # All functions here will be called upon exit self.onExit = [Settings.saveConfig] Settings() # All defined platforms self.platforms = self.getPlatformsFromMakefile() self.platformOnly = None self.excludedPlatforms = list() self.activePlatform = self.platforms.index("telosb") # Flag indicates that next thread's output shouldn't trigger # force switching to info area tab. self.supressTabSwitching = False self.targets = [None] self.targetType = "USB" self.activeThreads = {} self.onExit.append(self.killAllThreads) if LOG_TO_FILE: path = os.getcwd() os.chdir(self.path) self.logFile = open(LOG_FILE_NAME, "a") os.chdir(path) self.onExit.append(self.logFile.close) # this is path from /osw/tools/IDE self.pathToMansos = os.path.join(self.path, "../..") # Try to get system default font #font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) #self.fontName = font.GetFaceName() #if self.fontName != "": # print "Using system default font: {}".format(self.fontName) #else: self.fontName = "Courier New" # print "Can't find system default font, defaulting to {}".\ # format(self.fontName) self.listenModules = list() self.editors = list() icon = os.path.normpath('../../doc/osw-32x32.ico') ### Module initializations # Visual objects here can be used in forms only after they have been re-parented # using their Reparent() function, else they won't be visible! self.emptyFrame = wx.Frame(None) # Defines seal syntax self.sealSyntax = SealSyntax(self) # Init translation module Translater(self) # Init output_tools #self.outputTools = OutputTools(self.emptyFrame, self) # Init outputArea for info, 1st tab self.infoArea = OutputArea(self.emptyFrame, self, 0) self.printInfo = self.infoArea.printLine self.clearInfoArea = self.infoArea.clear # Init blockly handler if os.path.exists(os.path.join(self.path, Settings.get("blockly_location"))): self.blockly = Blockly(self.emptyFrame, self) self.foundBlockly = True else: print "Warning: No SEAL-Blockly found!" self.foundBlockly = False # Init seal parser self.sealParser = seal_parser.SealParser("msp430", self.printInfo, False, True) # Init tab manager self.tabManager = TabManager(self.emptyFrame, self) # Init listenModule self.listenModules.append(ListenModule(self.emptyFrame, self)) self.editPanel = ScrolledPanel(self.emptyFrame) self.editWindow = EditStatement(self.editPanel, self) self.frame = Frame(None, "OSW IDE", (0, 0), (0, 0), self) #self.outputTools.addTools() self.compiler = DoCompile(self) self.uploader = DoUpload(self) ### Shortcuts # This allows modules to be disabled and dummy functions attached, so other # modules can keep saving the day... Each module updates his functions at # startup and restores them at termination. All function calls between modules # should go through here, but this ain't perfect world :( self.getKeywords = self.sealSyntax.getKeywords #self.printInfo = self.dummyPrint self.printOutput = self.dummyPrint # Check if icon can be found if os.path.exists(icon): self.frame.SetIcon(wx.Icon(icon, wx.BITMAP_TYPE_ICO, 32, 32)) else: self.logMsg(LOG_WARNING, "Icon not found in '{}'!".format(icon)) # Check that everything is OK assert len(self.emptyFrame.GetChildren()) == 0, \ "There are parentless objects after API initialization.\n{}".format(\ self.emptyFrame.GetChildren()) self.syncModuleCheckboxes() # Initialize upload targets self.uploadTargets = ([], localize('the default device')) # Load last used tabs self.tabManager.loadRememberedTabs() for x in argv: self.tabManager.addPage(x) self.frame.auiManager.Update() self.loaded = True self.frame.checkToggleState() Motelist.startPeriodicUpdate() self.onExit.append(Motelist.stopPeriodicUpdate) self.loadUserMotes()