diff --git a/__pycache__/ctrl.cpython-34.pyc b/__pycache__/ctrl.cpython-34.pyc index a3dd4d8..751882d 100644 Binary files a/__pycache__/ctrl.cpython-34.pyc and b/__pycache__/ctrl.cpython-34.pyc differ diff --git a/__pycache__/mainComponents.cpython-34.pyc b/__pycache__/mainComponents.cpython-34.pyc index 724be4d..5edb793 100644 Binary files a/__pycache__/mainComponents.cpython-34.pyc and b/__pycache__/mainComponents.cpython-34.pyc differ diff --git a/__pycache__/threadDownloadFirmware.cpython-34.pyc b/__pycache__/threadDownloadFirmware.cpython-34.pyc index 988023f..1fd6d2e 100644 Binary files a/__pycache__/threadDownloadFirmware.cpython-34.pyc and b/__pycache__/threadDownloadFirmware.cpython-34.pyc differ diff --git a/__pycache__/updateNewFirmware.cpython-34.pyc b/__pycache__/updateNewFirmware.cpython-34.pyc index e594cd5..587e1cd 100644 Binary files a/__pycache__/updateNewFirmware.cpython-34.pyc and b/__pycache__/updateNewFirmware.cpython-34.pyc differ diff --git a/ctrl.py b/ctrl.py index cbfdf74..7d3ff00 100644 --- a/ctrl.py +++ b/ctrl.py @@ -196,9 +196,15 @@ def getcwd(self): def dragChangeDir(self,dragfile,dropfile): #if str(dragfile).find(":")<0:#device Internal move - if str(dragfile).find(rootDirectoryPath)<0: + if sys.platform=="linux" and str(dragfile).find(rootDirectoryPath)<0: dropfile=dropfile + "/" + dragfile.split("/")[-1] self.rename(dragfile,dropfile) + elif sys.platform=="win32" and str(dragfile).find(":")<0: + dropfile=dropfile + "/" + dragfile.split("/")[-1] + self.rename(dragfile,dropfile) + #if str(dragfile).find(rootDirectoryPath)<0: + # dropfile=dropfile + "/" + dragfile.split("/")[-1] + # self.rename(dragfile,dropfile) else:#device external drag and download dropfile=dropfile + "/" + dragfile.split("/")[-1] self.dropDownFileName=dropfile @@ -824,7 +830,8 @@ def goProgram(self,filename): pass else: #if str(filename).find(":")>=0: - if str(filename).find(rootDirectoryPath)>=0: + if (sys.platform=="linux" and str(filename).find(rootDirectoryPath)>=0) or (sys.platform=="win32" and str(filename).find(":")>=0): + #if str(filename).find(rootDirectoryPath)>=0: filelist=str(filename).split('/') for afile in filelist: if afile.find(".py")>=0: @@ -846,6 +853,7 @@ def goProgram(self,filename): self.ctrltouartQueue.put("exec_:::exec(open(\'%s\').read(),globals())\r\n"%str(filename)) def loadFile(self,filename): + print("ctrl loadfile") self.loadFileBool=True self.loadFileMsg="" if self.currentBoard=="microbit": @@ -925,14 +933,17 @@ def loadFile(self,filename): self.loadFileBool=False def downloadFile(self,filename): - print("downloadFile=%s\n"%filename) filename = filename.replace("\\","/") - + print("downloadFile===============================%s\n"%filename) if str(filename).find(".py")>=0: if self.dragDropModel==True: afile=self.dropDownFileName #elif str(filename).find(":")<0: - elif str(filename).find(rootDirectoryPath)<0: + #elif str(filename).find(rootDirectoryPath)<0: + # afile=str(filename) + elif sys.platform=="linux" and str(filename).find(rootDirectoryPath)<0: + afile=str(filename) + elif sys.platform=="win32" and str(filename).find(":")<0: afile=str(filename) else: if str(filename).find("/")>=0: @@ -954,8 +965,12 @@ def downloadFile(self,filename): return afile=self.dropDownFileName #elif filename.find(":")<0: - elif filename.find(rootDirectoryPath)<0: + elif sys.platform=="linux" and filename.find(rootDirectoryPath)<0: + fileHandle=open(currentTempPath+filename,'rbU') + elif sys.platform=="win32" and filename.find(":")<0: fileHandle=open(currentTempPath+filename,'rbU') + #elif filename.find(rootDirectoryPath)<0: + # fileHandle=open(currentTempPath+filename,'rbU') else: myfile=open(currentTempPath+"/"+str(filename.split("/")[-1]),"w",encoding='UTF-8') filemsg="" @@ -1102,6 +1117,7 @@ def downloadFile(self,filename): else: self.ctrltouartQueue.put("ctrltouart:::\x03") time.sleep(0.01) + self.emit(SIGNAL("uiRecvFromCtrl"),returnData) self.emit(SIGNAL("uiRecvFromCtrl"),"download false6") return else: diff --git a/dist/uPyCraft_V0.30.exe b/dist/uPyCraft_V0.30.exe new file mode 100644 index 0000000..ca31830 Binary files /dev/null and b/dist/uPyCraft_V0.30.exe differ diff --git a/mainComponents.py b/mainComponents.py index 2ad7be6..fd5036f 100644 --- a/mainComponents.py +++ b/mainComponents.py @@ -525,17 +525,17 @@ def slotRightClickMenu(self,point): elif (self.ui.fileName=="." or self.ui.fileName=="/flash") and not self.ui.myserial.ser.isOpen(): pass elif self.ui.fileName=="/sd" or \ - (self.ui.fileName.find(rootDirectoryPath)>=0 and self.ui.fileName.split("/")[-1]=="uPy_lib"): + (((sys.platform=="linux" and self.ui.fileName.find(rootDirectoryPath)>=0) or (sys.platform=="win32" and self.ui.fileName.find(":")>=0)) and self.ui.fileName.split("/")[-1]=="uPy_lib"): pass #elif self.ui.fileName.find(":")>=0 and self.ui.fileName.find("uPy_lib")>0: - elif self.ui.fileName.find(rootDirectoryPath)>=0 and self.ui.fileName.find("uPy_lib")>0: + elif ((sys.platform=="linux" and self.ui.fileName.find(rootDirectoryPath)>=0) or (sys.platform=="win32" and self.ui.fileName.find(":")>=0)) and self.ui.fileName.find("uPy_lib")>0: self.rightClickMenu.addAction(self.openFile) self.rightClickMenu.addAction(self.closeFile) #elif self.ui.fileName.find(":")>=0 and self.ui.fileName.split("/")[-1]=="workSpace": - elif self.ui.fileName.find(rootDirectoryPath)>=0 and self.ui.fileName.split("/")[-1]=="workSpace": + elif ((sys.platform=="linux" and self.ui.fileName.find(rootDirectoryPath)>=0) or (sys.platform=="win32" and self.ui.fileName.find(":")>=0)) and self.ui.fileName.split("/")[-1]=="workSpace": self.rightClickMenu.addAction(self.openFile) #elif self.ui.fileName.find(":")>=0 and self.ui.fileName.find("workSpace")>0: - elif self.ui.fileName.find(rootDirectoryPath)>=0 and self.ui.fileName.find("workSpace")>0: + elif ((sys.platform=="linux" and self.ui.fileName.find(rootDirectoryPath)>=0) or (sys.platform=="win32" and self.ui.fileName.find(":")>=0)) and self.ui.fileName.find("workSpace")>0: self.rightClickMenu.addAction(self.openFile) self.rightClickMenu.addAction(self.closeFile) self.rightClickMenu.addAction(self.deleteFile) @@ -582,7 +582,7 @@ def getQmodelIndexParent(self,index): def chooseFile(self,index): self.ui.fileName="" self.getQmodelIndexParent(index) - + print("--4--%s"%self.ui.fileName) dirList=self.ui.fileName.split("/") if dirList[1]=="device": @@ -596,6 +596,7 @@ def chooseFile(self,index): if self.ui.createWorkSpacePath(): self.ui.fileName=self.ui.workspacePath[0:-10]+self.ui.fileName self.ui.fileName=self.ui.fileName.replace("\\","/") + self.ui.fileName=self.ui.fileName.replace("//","/") else: self.ui.fileName="" else: @@ -861,7 +862,9 @@ def createNewTab(self,filename,msg,lexer): if self.ui.currentBoard=="microbit": msg="from microbit import *\r#write your program:\r" #elif str(filename).find(":")>0: - elif str(filename).find(rootDirectoryPath)>=0: + #elif str(filename).find(rootDirectoryPath)>=0: + elif (sys.platform=="linux" and str(filename).find(rootDirectoryPath)>=0) or (sys.platform=="win32" and str(filename).find(":")>0): + #elif sys.platform=="win32" or sys.platform=="linux": self.tabBar().setTabTextColor(self.count()-1, QColor(Qt.red)) self.setTabIcon(self.count()-1, QIcon(':/pc.png')) else: diff --git a/threadDownloadFirmware.py b/threadDownloadFirmware.py index 00dc63a..4247fde 100644 --- a/threadDownloadFirmware.py +++ b/threadDownloadFirmware.py @@ -17,7 +17,7 @@ class threadUserFirmware(QThread): - def __init__(self, board, savepath, com, iserase, size, parent): + def __init__(self, board, savepath, com, iserase, size, addr, parent): super(threadUserFirmware,self).__init__(parent) self.board=board @@ -28,6 +28,13 @@ def __init__(self, board, savepath, com, iserase, size, parent): self.erasePer=0 self.erasestart=False self.erasetimer=None + self.burnaddr=0 + if addr=="0x0": + self.burnaddr=0 + else: + self.burnaddr=0x1000 + + print("burnaddr=====%d"%self.burnaddr) def run(self): esptool=Esp.ESPTool() @@ -55,21 +62,8 @@ def run(self): if self.iserase=="yes": self.emit(SIGNAL("firmwareAnyErase"),100) try: - writeFlashAddr=0 if self.board=="esp32" or self.board=="esp8266": - if self.board=="esp32": - file = codecs.open(self.savepath,'rb') - readline=2000 - while 1: - msg=file.readline() - if str(msg).find("v1.9.2-445-g84035f0f")>=0: - writeFlashAddr = 0x1000 - break - readline=readline-1 - if readline==0: - break - file.close() - Esp.Burn(esptool,str(self.board),self.savepath,self.com,False,writeFlashAddr) + Esp.Burn(esptool,str(self.board),self.savepath,self.com,False,self.burnaddr) else:#microbit print("In threaddownloadfirmware:savepath=%s"%self.savepath) self.emit(SIGNAL("firmwareAnyUpdate"),-2) @@ -119,7 +113,7 @@ def eraseTimer(self): self.erasetimer.start() class threadDownloadFirmware(QThread): - def __init__(self, url, board, savepath, com, iserase, size, parent): + def __init__(self, url, board, savepath, com, iserase, size, addr, parent): super(threadDownloadFirmware,self).__init__(parent) self.url=url self.board=board @@ -133,11 +127,17 @@ def __init__(self, url, board, savepath, com, iserase, size, parent): self.erasestart=False self.erasetimer=None + + self.burnaddr=0 + if addr=="0x0": + self.burnaddr=0 + else: + self.burnaddr=0x1000 + print("burnaddr2=====%d"%self.burnaddr) def run(self): - self.reDownload() if self.downloadOk==True: @@ -166,21 +166,8 @@ def run(self): if self.iserase=="yes": self.emit(SIGNAL("firmwareAnyErase"),100) try: - writeFlashAddr=0 if self.board=="esp32" or self.board=="esp8266": - if self.board=="esp32": - file = codecs.open(self.savepath,'rb') - readline=2000 - while 1: - msg=file.readline() - if str(msg).find("v1.9.2-445-g84035f0f")>=0: - writeFlashAddr=0x1000 - break - readline=readline-1 - if readline==0: - break - file.close() - Esp.Burn(esptool,str(self.board),self.savepath,self.com,False,writeFlashAddr) + Esp.Burn(esptool,str(self.board),self.savepath,self.com,False,self.burnaddr) else:#microbit print("In threaddownloadfirmware:savepath=%s"%self.savepath) self.emit(SIGNAL("firmwareAnyUpdate"),-2) diff --git a/uPyCraft.py b/uPyCraft.py index 564d55b..e0365d7 100644 --- a/uPyCraft.py +++ b/uPyCraft.py @@ -753,13 +753,22 @@ def slotTreeDoubleClickOpenFile(self,index): return #if self.fileName.find(":")>=0: - if self.fileName.find(rootDirectoryPath)>=0: + if sys.platform=="linux" and self.fileName.find(rootDirectoryPath)>=0: self.pcOpenFile(self.fileName) return + elif sys.platform=="win32" and self.fileName.find(":")>=0: + self.pcOpenFile(self.fileName) + return + #if self.fileName.find(rootDirectoryPath)>=0 or (self.fileName.find(":")>=0 and sys.platform=="win32"): + # self.pcOpenFile(self.fileName) + # return else: if self.editClassFileitem(self.fileName): self.uitoctrlQueue.put("loadfile:::%s"%self.fileName) - pass + pass + else: + print("double false") + print("double clicked") def slotNewFile(self): self.tabWidget.createNewTab("untitled","",self.lexer) @@ -782,8 +791,12 @@ def slotSaveFile(self): if tabname[0] != "*":#tabname have *,means it's changed,can be save return #elif filepath.find(":")<0: - elif filepath.find(rootDirectoryPath)<0: + elif sys.platform=="linux" and filepath.find(rootDirectoryPath)<0: + savefile=codecs.open(currentTempPath+str(filepath),'wb') + elif sys.platform=="win32" and filepath.find(":")<0: savefile=codecs.open(currentTempPath+str(filepath),'wb') + #elif filepath.find(rootDirectoryPath)<0: + # savefile=codecs.open(currentTempPath+str(filepath),'wb') else: savefile=open(filepath,'wb') ''' @@ -1472,11 +1485,15 @@ def slotDownloadFile(self): return False #if str(self.fileName).find(":")>=0: - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: + afile=self.fileName + elif sys.platform=="win32" and str(self.fileName).find(":")>=0: afile=self.fileName + #if str(self.fileName).find(rootDirectoryPath)>=0 or (self.fileName.find(":")>=0 and sys.platform=="win32"): + # afile=self.fileName else: afile=self.fileName - myfile=open(str(rootDirectoryPath+afile[1:]),'w',encoding='utf-8') + myfile=open(str(currentTempPath+afile[1:]),'w',encoding='utf-8') filemsg=self.tabWidget.currentWidget().text() if type(filemsg) is bytes: filemsg=filemsg.decode('utf-8') @@ -1495,6 +1512,7 @@ def slotDownloadFileAndRun(self): def slotStopProgram(self): if self.myserial.ser.isOpen(): self.readwriteQueue.put("uitouart:::\x03") + self.inDownloadFile=False else: self.terminal.append("serial not open") @@ -1667,8 +1685,12 @@ def editClassFileitem(self,filename): print("%s already exist"%filename) return False #if str(filename).find(":")<0: - if str(filename).find(rootDirectoryPath)<0: + if sys.platform=="linux" and str(filename).find(rootDirectoryPath)<0: + return True + elif sys.platform=="win32" and str(filename).find(":")<0: return True + #if str(filename).find(rootDirectoryPath)<0: + # return True return True def asciiTOutf8(self,path): @@ -1941,9 +1963,15 @@ def treeRightMenuRunFile(self): self.goProgram(self.fileName) def treeRightMenuOpenFile(self): - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: + self.pcOpenFile(self.fileName) + return + elif sys.platform=="win32" and str(self.fileName).find(":")>=0: self.pcOpenFile(self.fileName) return + #if str(self.fileName).find(rootDirectoryPath)>=0: + # self.pcOpenFile(self.fileName) + # return if str(self.fileName).find(".py")>0 or str(self.fileName).find(".txt")>0 or str(self.fileName).find(".json")>0 or str(self.fileName).find(".ini")>0: pass @@ -1971,10 +1999,17 @@ def treeRightMenuDeleteFile(self): if self.fileName=='': return #if str(self.fileName).find(":")>0: - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: + self.deletePCFile(self.fileName) + return + elif sys.platform=="win32" and str(self.fileName).find(":")>0: self.deletePCFile(self.fileName) return + #if str(self.fileName).find(rootDirectoryPath)>=0: + # self.deletePCFile(self.fileName) + # return + deleteText="confirm delete %s?"%str(self.fileName) button=QMessageBox.question(self,"DeleteFile", @@ -1993,22 +2028,40 @@ def treeRightMenuDefaultProgram(self): return #if str(self.fileName).find(":")>0: - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: + self.terminal.append("This file not in board") + return + elif sys.platform=="win32" and str(self.fileName).find(":")>=0: self.terminal.append("This file not in board") return elif str(self.fileName).find(".py")<0: self.terminal.append("only set py file") return + + + #if str(self.fileName).find(rootDirectoryPath)>=0: + # self.terminal.append("This file not in board") + # return + #elif str(self.fileName).find(".py")<0: + # self.terminal.append("only set py file") + # return + self.myDefaultProgram=self.fileName self.uitoctrlQueue.put("setdefaultprogram:::%s"%self.myDefaultProgram) def treeRightMenuRename(self): #if str(self.fileName).find(":")>0: - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: self.terminal.append("not in board,no rename") return + elif sys.platform=="win32" and str(self.fileName).find(":")>0: + self.terminal.append("not in board,no rename") + return + #if str(self.fileName).find(rootDirectoryPath)>=0: + # self.terminal.append("not in board,no rename") + # return if not self.myserial.ser.isOpen(): return @@ -2020,9 +2073,15 @@ def treeRightMenuRename(self): def treeRightMenuNewDir(self): #if str(self.fileName).find(":")>0: - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: + self.terminal.append("not board file,no new dir") + return + elif sys.platform=="win32" and str(self.fileName).find(":")>0: self.terminal.append("not board file,no new dir") return + #if str(self.fileName).find(rootDirectoryPath)>=0: + # self.terminal.append("not board file,no new dir") + # return if not self.myserial.ser.isOpen(): return if self.currentBoard=="microbit": @@ -2102,7 +2161,8 @@ def updateFirmwareOk(self): self.updateFirmwareBar.show() self.firmwareAny=threadDownloadFirmware(url,self.updateBin.boardComboBox.currentText(),self.firmwareSavePath,self.updateFirmwareCom,\ - self.updateBin.eraseComboBox.currentText(),self.updateSize,self) + self.updateBin.eraseComboBox.currentText(),self.updateSize,\ + self.updateBin.burnAddrComboBox.currentText(),self) self.connect(self.firmwareAny,SIGNAL("firmwareAnyDown"),self.firmwareAnyDown) self.connect(self.firmwareAny,SIGNAL("firmwareAnyErase"),self.firmwareAnyErase) self.connect(self.firmwareAny,SIGNAL("firmwareAnyUpdate"),self.firmwareAnyUpdate) @@ -2147,9 +2207,9 @@ def updateFirmwareOk(self): else: self.updateFirmwareBar=updateNewFirmwareBar("Burn Firmware",False,False) self.updateFirmwareBar.show() - self.firmwareAny=threadUserFirmware(self.updateBin.boardComboBox.currentText(),userFirmwareName,self.updateFirmwareCom,\ - self.updateBin.eraseComboBox.currentText(),userFirmwareSize,self) + self.updateBin.eraseComboBox.currentText(),userFirmwareSize,\ + self.updateBin.burnAddrComboBox.currentText(),self) self.connect(self.firmwareAny,SIGNAL("firmwareAnyDown"),self.firmwareAnyDown) self.connect(self.firmwareAny,SIGNAL("firmwareAnyErase"),self.firmwareAnyErase) self.connect(self.firmwareAny,SIGNAL("firmwareAnyUpdate"),self.firmwareAnyUpdate) @@ -2369,8 +2429,12 @@ def reflushTree(self,data): if self.isDownloadFileAndRun: self.isDownloadFileAndRun=False #if str(self.fileName).find(":")>=0: - if str(self.fileName).find(rootDirectoryPath)>=0: + if sys.platform=="linux" and str(self.fileName).find(rootDirectoryPath)>=0: + goProgramFile = str(self.fileName).split("/")[-1] + elif sys.platform=="win32" and str(self.fileName).find(":")>=0: goProgramFile = str(self.fileName).split("/")[-1] + #if str(self.fileName).find(rootDirectoryPath)>=0: + # goProgramFile = str(self.fileName).split("/")[-1] else: goProgramFile=self.fileName diff --git a/updateNewFirmware.py b/updateNewFirmware.py index 7f93fd5..923bbec 100644 --- a/updateNewFirmware.py +++ b/updateNewFirmware.py @@ -103,6 +103,11 @@ def __init__(self,windowname,isAuto=False,parent=None): self.boardComboBox.addItems(["esp8266","esp32","microbit"]) self.boardComboBox.setCurrentIndex(2) + self.burnAddrLabel=QLabel(self.tr("burn_addr")) + self.burnAddrComboBox=QComboBox() + self.burnAddrComboBox.addItems(["0x0","0x1000"]) + self.burnAddrComboBox.setCurrentIndex(0) + self.eraseflashLabel=QLabel(self.tr("erase_flash")) self.eraseComboBox=QComboBox() self.eraseComboBox.addItems(["yes","no"]) @@ -136,27 +141,33 @@ def __init__(self,windowname,isAuto=False,parent=None): layout.addWidget(self.boardLabel,0,0) layout.addWidget(self.boardComboBox,0,2) - layout.addWidget(self.eraseflashLabel,1,0) - layout.addWidget(self.eraseComboBox,1,2) + layout.addWidget(self.burnAddrLabel,1,0) + layout.addWidget(self.burnAddrComboBox,1,2) - layout.addWidget(self.comLabel,2,0) - layout.addWidget(self.comChoose,2,2) + layout.addWidget(self.eraseflashLabel,2,0) + layout.addWidget(self.eraseComboBox,2,2) - layout.addWidget(self.myGroupBox,3,0,2,3) + layout.addWidget(self.comLabel,3,0) + layout.addWidget(self.comChoose,3,2) - layout.addWidget(self.okButton,6,0) - layout.addWidget(self.cancelButton,6,2) + layout.addWidget(self.myGroupBox,4,0,2,3) + + layout.addWidget(self.okButton,7,0) + layout.addWidget(self.cancelButton,7,2) else: layout.addWidget(self.boardLabel,0,0) layout.addWidget(self.boardComboBox,0,2) - layout.addWidget(self.eraseflashLabel,1,0) - layout.addWidget(self.eraseComboBox,1,2) + layout.addWidget(self.burnAddrLabel,1,0) + layout.addWidget(self.burnAddrComboBox,1,2) + + layout.addWidget(self.eraseflashLabel,2,0) + layout.addWidget(self.eraseComboBox,2,2) - layout.addWidget(self.myGroupBox,2,0,2,3) + layout.addWidget(self.myGroupBox,3,0,2,3) - layout.addWidget(self.okButton,5,0) - layout.addWidget(self.cancelButton,5,2) + layout.addWidget(self.okButton,6,0) + layout.addWidget(self.cancelButton,6,2) self.radioUPY.setChecked(True) self.firmwareName.setEnabled(False) @@ -167,6 +178,13 @@ def __init__(self,windowname,isAuto=False,parent=None): self.eraseComboBox.setEnabled(False) else: self.eraseComboBox.setEnabled(True) + + if self.boardComboBox.currentText()=="esp32": + self.burnAddrComboBox.setCurrentIndex(0) + self.burnAddrComboBox.setEnabled(True) + else: + self.burnAddrComboBox.setEnabled(False) + self.resize(450,200) self.setLayout(layout) @@ -196,6 +214,13 @@ def boardChange(self,item): else: self.eraseComboBox.setCurrentIndex(0) self.eraseComboBox.setEnabled(True) + + if self.boardComboBox.currentText()=="esp32": + self.burnAddrComboBox.setCurrentIndex(0) + self.burnAddrComboBox.setEnabled(True) + else: + self.burnAddrComboBox.setCurrentIndex(0) + self.burnAddrComboBox.setEnabled(False) def chooseOk(self): self.close()