-
Notifications
You must be signed in to change notification settings - Fork 82
/
uPyCraft.py
2991 lines (2558 loc) · 122 KB
/
uPyCraft.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import Qsci
from PyQt4.Qsci import QsciScintilla, QsciScintillaBase, QsciLexerPython
import binascii
import PyQt4
import queue
import base64
import sys
import math
import json
import os
import Esp
import shutil
import webbrowser
import qrc_resources
import time
import platform
import threading
import urllib
import subprocess
from subprocess import check_output
import codecs
import socket
import ctypes
import pyflakes
from urllib import request
from pyflakes.api import main as pyflakesMain
from graphicsInterface import saveUntitled, createBoardNewDirName, findReplaceText, \
SerialWidget, LanLocWidget, Preferences, treeRightClickRename
from readWriteUart import readWriteUart
from ctrl import ctrlAction
from updateNewFirmware import updateNewFirmware, updateNewFirmwareBar
from mainComponents import myTerminal,myTreeView,myTabWidget
from check import checkVersionExampleFire, attentionUpdata, ProgressIDEorExampleBar
from threadDownloadFirmware import threadDownloadFirmware, threadUserFirmware
from microbit_api import MICROPYTHON_APIS
from SourceCodePro import SourceCodePro
mainShow=True
nowIDEVersion ="1.1"
isCheckFirmware =False
rootDirectoryPath =os.path.expanduser("~")
rootDirectoryPath =rootDirectoryPath.replace("\\","/")
currentTempPath ="%s/AppData/Local/uPyCraft/temp/"%rootDirectoryPath
currentExamplesPath="%s/AppData/Local/uPyCraft/examples"%rootDirectoryPath
print(rootDirectoryPath)
print(currentTempPath)
print(currentExamplesPath)
if not os.path.exists("%s/AppData/Local/uPyCraft"%rootDirectoryPath):
os.makedirs("%s/AppData/Local/uPyCraft"%rootDirectoryPath)
if not os.path.exists("%s/AppData/Local/uPyCraft/download"%rootDirectoryPath):
os.makedirs("%s/AppData/Local/uPyCraft/download"%rootDirectoryPath)
if not os.path.exists("%s/AppData/Local/uPyCraft/temp"%rootDirectoryPath):
os.makedirs("%s/AppData/Local/uPyCraft/temp"%rootDirectoryPath)
EXPANDED_IMPORT = ("from microbit import pin15, pin2, pin0, pin1,\
pin3, pin6, pin4, i2c, pin5, pin7, pin8, Image,\
pin9, pin14, pin16, reset, pin19, temperature,\
sleep, pin20, button_a, button_b, running_time,\
accelerometer, display, uart, spi, panic, pin13,\
pin12, pin11, pin10, compass")
MICROBIT_QSCI_APIS=["import","from","class","global","else","while","break",\
"False","True","with"]
updateFirmwareList=[]
class fileItem:
def __init__(self):
self.size=0
self.list=[]
class MainWidget(QMainWindow):
def __init__(self,parent=None):
super(MainWidget,self).__init__(parent)
#self.setWindowFlags(Qt.WindowCloseButtonHint)#HelpButtonHint?
#basic set
self.setWindowTitle("uPyCraft V%s"%nowIDEVersion)
self.setWindowIcon(QIcon(':/logo.png'))
self.resize(1000,800)
self.setFont()
self.setIconSize(QSize(36,36))
self.fileitem=fileItem()
self.fileName=''
self.rootDir="."
self.currentCom=""
self.myDefaultProgram=""
self.checkDefaultProgram=""
self.cutCopyPasteMsg=""
self.currentBoard="esp32"
self.workspacePath=""
self.canNotIdentifyBoard=False
#self.setStyleSheet("background-color: rgb(254, 138, 58);")
self.clipboard=QApplication.clipboard()
self.readwriteQueue=queue.Queue()
self.uitoctrlQueue=queue.Queue()
self.inDownloadFile=False #判断是否正在下载,避免多次快速F5,导致异常
#tree
self.tree=None
self.createTree()
#lexer
self.lexer=None
self.createLexer()
self.autoAPI=Qsci.QsciAPIs(self.lexer)
#terminal
self.terminal=None
self.createTerminal()
#tabWidget
self.editorLine=0
self.editorIndex=0
self.editorRightMenu=None
self.tabWidget=None
self.createTabWidget()
#rightSplitter
self.rightSplitter=None
self.createRightSplitter()
#mainWindow
self.mainWindow=None
self.createMainWindow()
self.setCentralWidget(self.mainWindow)
#serial
self.myserial=SerialWidget()
self.serialComList=[]
#basic config contains:check config.json,fill workspacePath
if not self.createBasicConfig():
global mainShow
mainShow=False
return
#actions
self.createActions()
#menus
self.createMenus()
#toolBars
self.createToolBars()
#create graphics interface
self.createGraphicsInterface()
#create Preferences
self.preferencesDialog=Preferences()
#thread
self.readuart=readWriteUart(self.readwriteQueue,self)
self.connect(self.readuart,SIGNAL("uiRecvFromUart"),self.uiRecvFromUart)
self.ctrl=ctrlAction(self.readuart,self.readwriteQueue,self.uitoctrlQueue,self)
self.connect(self.ctrl,SIGNAL("uiRecvFromCtrl"),self.uiRecvFromCtrl)
self.connect(self.ctrl,SIGNAL("reflushTree"),self.reflushTree)
self.connect(self.ctrl,SIGNAL("checkFiremware"),self.checkFiremware)
self.connect(self.ctrl,SIGNAL("loadFileSig"),self.loadFileSig)
self.connect(self.ctrl,SIGNAL("deleteBoardFileSig"),self.deleteBoardFileSig)
self.connect(self.ctrl,SIGNAL("renameDirDeleteDirTab"),self.renameDirDeleteDirTab)
#self.connect(self.ctrl,SIGNAL("intoFuncSig"),self.intoFuncSig)
#timer for serial check
self.timerClose=False
global timer
timer=threading.Timer(1,self.fun_timer)
self.connect(self,SIGNAL("timerCloseTerminal"),self.timerCloseTerminal)
self.connect(self,SIGNAL("timerAddComMenu"),self.timerAddComMenu)
self.connect(self,SIGNAL("timerSetComMenu"),self.timerSetComMenu)
self.connect(self,SIGNAL("timerClearComMenu"),self.timerClearComMenu)
timer.start()
#check version(IDE,examples)
self.check=checkVersionExampleFire(self)
self.connect(self.check,SIGNAL("updateThing"),self.updateThing)
self.connect(self.check,SIGNAL("updatePer"),self.updataPer)
self.connect(self.check,SIGNAL("reflushExamples"),self.reflushExamples)
self.connect(self.check,SIGNAL("changeUpdateFirmwareList"),self.changeUpdateFirmwareList)
self.connect(self.check,SIGNAL("changeIsCheckFirmware"),self.setIsCheckFirmware)
self.check.start()
self.setStyleSheet("""
QMessageBox { background-color: rgb(236,236,236);color:black; }
QPushButton{background-color:rgb(253,97,72);color:white;}
""")
def setFont(self):
fonts=None
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):#for windows
FONTDIRS=os.path.join(os.environ['WINDIR'],'Fonts')
fonts=os.listdir(FONTDIRS)
flags=False
elif sys.platform.startswith('darwin'):#for mac
FONTDIRS=rootDirectoryPath+"/Library/Fonts"
fonts=os.listdir(FONTDIRS)
flags=False
if fonts==None:
return
for filename in fonts:
if(filename.upper().find('SOURCECODEPRO.TTF')==0):
flags=True
break
if flags is False:
checkfont=QMessageBox.question(self,"SourceCodePro Font",
"Please install SourceCodePro font",
QMessageBox.Ok|QMessageBox.Cancel,
QMessageBox.Ok)
if checkfont==QMessageBox.Ok:
ttf=binascii.unhexlify(SourceCodePro)
try:
fp=open(rootDirectoryPath+'/Desktop/'+'SourceCodePro.ttf','wb')
fp.write(ttf)
fp.close()
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
os.system('SourceCodePro.ttf')
elif sys.platform.startswith('darwin'):
subprocess.call(['open',rootDirectoryPath+'/Desktop/'+'SourceCodePro.ttf'])
#os.remove("SourceCodePro.ttf")
except:
print("install ttf false.")
font=QFont(self.tr("Source Code Pro"),10)
QApplication.setFont(font)
def createTree(self):
self.tree=myTreeView(self)
self.connect(self.tree,SIGNAL("doubleClicked(QModelIndex)"),self.slotTreeDoubleClickOpenFile)
self.rootDevice=QStandardItem(QIcon(":/treeMenuClosed.png"),"device")
self.rootSD=QStandardItem(QIcon(":/treeMenuClosed.png"),"sd")
self.rootLib=QStandardItem(QIcon(":/treeMenuClosed.png"),"uPy_lib")
self.workSpace=QStandardItem(QIcon(":/treeMenuClosed.png"),"workSpace")
model=QStandardItemModel(self.tree)
#stringlist = [' board']
#model.setHorizontalHeaderLabels(stringlist)
model.appendRow(self.rootDevice)
model.appendRow(self.rootSD)
model.appendRow(self.rootLib)
model.appendRow(self.workSpace)
self.tree.setModel(model)
self.tree.createRightMenu()
def createLexer(self):
self.lexer = QsciLexerPython()
self.lexer.setDefaultPaper(QColor(38,45,52))
self.lexer.setDefaultColor(QColor(255,255,255))
self.lexer.setFont(QFont(self.tr("Consolas"),13,1))
self.lexer.setColor( Qt.darkGreen, QsciLexerPython.Comment)
self.lexer.setColor( QColor(255,128,0), QsciLexerPython.TripleDoubleQuotedString )
self.lexer.setColor( QColor(165,42,42), QsciLexerPython.ClassName )
self.lexer.setColor( QColor(0,138,140), QsciLexerPython.FunctionMethodName )
self.lexer.setColor( Qt.green, QsciLexerPython.Keyword )
self.lexer.setColor( QColor(255,0,255), QsciLexerPython.Number )
self.lexer.setColor( Qt.darkBlue, QsciLexerPython.Decorator )
self.lexer.setColor( QColor(165,152,36), QsciLexerPython.DoubleQuotedString )
self.lexer.setColor( QColor(165,152,36), QsciLexerPython.SingleQuotedString )
#self.lexer.setIndentationWarning(QsciLexerPython.Spaces)
def createTerminal(self):
self.terminal=myTerminal(self.readwriteQueue,self)
self.cursor=self.terminal.textCursor()
self.cursorLeftOrRight=0
self.moveposition=0
self.connect(self.terminal,SIGNAL("cursorPositionChanged()"),self.slotTerminalCursorChanged)
self.connect(self.terminal,SIGNAL("setCursor"),self.slotTerminalSetCursor)
def createTabWidget(self):
self.tabWidget=myTabWidget(self.editorRightMenu,self.fileitem,self)
self.tabWidget.setTabsClosable(True)
self.tabWidget.setFont(QFont(self.tr("Source Code Pro"),10,100))
self.tabWidget.setStyleSheet(""" QWidget{background-color: qlineargradient(x1: 0, x2: 1,stop: 0 #262D34, stop: 1 #222529);
border-width:0px;border-color:#666666;border-style:none;color:white;}
QScrollBar:vertical{background-color:rgb(94,98,102);
border:0px;
width: 15px;
margin:0px 0px 0px 0px;
}
QScrollBar::add-page:vertical{background-color:rgb(61,62,64);
width: 15px;
margin:0px 0px 0px 0px;
}
QScrollBar::sub-page:vertical{background-color:rgb(61,62,64);
width: 15px;
margin:0px 0px 0px 0px;
}
""")
#self.connect(self.tabWidget, SIGNAL("tabCloseRequested(int)"),self.closeTab)
#self.connect(self.tabWidget, SIGNAL("currentChanged(int)"),self.currentTabChange)
def createRightSplitter(self):
self.rightSplitter=QSplitter(Qt.Vertical)
self.rightSplitter.setOpaqueResize(False)
self.rightSplitter.setStyleSheet("QSplitter{background-color:qlineargradient(x1: 0, x2: 1,stop: 0 #646464, stop: 1 #171717);}"
"QTabBar::tab{ border-top-left-radius:3px; border-top-right-radius:5px; \
min-width:120px; \
min-height:25px; \
border:0px solid rgb(255,0,0); \
border-bottom:none; \
margin-top: 3; \
color: rgb(255,255,255);\
}"
"QTabWidget::pane{border-width:0px;border-color:rgb(161,161,161); border-style: inset;background-color: rgb(64, 64, 64);}"
"QTabBar::tab::selected{background-color:rgb(38,45,52);border-bottom:2px solid rgb(254,152,77);}"
"QTabBar::tab::!selected{background-color:rgb(64,64,64);}"
"QTabBar::close-button{subcontrol-position:right;image: url(:/tabClose.png) }"
"QTabBar::close-button:hover{subcontrol-position:right;image: url(:/tabCloseHover.png) }"
)
self.rightSplitter.setHandleWidth(1)
self.rightSplitter.addWidget(self.tabWidget)
self.rightSplitter.addWidget(self.terminal)
self.rightSplitterList=[600,200]
self.rightSplitter.setSizes(self.rightSplitterList)
def createMainWindow(self):
self.mainWindow=QSplitter(Qt.Horizontal,self)
self.mainWindow.setStyleSheet("background-color: rgb(236, 236, 236);")
self.mainWindow.setStyleSheet("QSplitter::handle { background-color: rgb(236, 236, 236);}")
self.mainWindow.setHandleWidth(1)
self.mainWindow.addWidget(self.tree)
self.mainWindow.addWidget(self.rightSplitter)
self.mainWindow.setStretchFactor(0,1)
self.mainWindow.setStretchFactor(1,7)
self.mainWindow.setFrameShape(QFrame.NoFrame)
def createActions(self):
#File
#self.fileOpenAction=QAction(QIcon(":/fileOpen.png"),self.tr("Open"),self)
self.fileOpenAction=QAction(self.tr("Open"),self)
self.fileOpenAction.setShortcut("Ctrl+O")
self.fileOpenAction.setStatusTip(self.tr("open a new file"))
self.connect(self.fileOpenAction,SIGNAL("triggered()"),self.slotOpenFile)
self.fileOpenToolsAction=QAction(QIcon(":/fileOpen.png"),self.tr("Open"),self)
#self.fileOpenToolsAction.setShortcut("Ctrl+O")
self.fileOpenToolsAction.setStatusTip(self.tr("open a new file"))
self.connect(self.fileOpenToolsAction,SIGNAL("triggered()"),self.slotOpenFile)
#self.fileNewAction=QAction(QIcon(":/newFile.png"),self.tr("New"),self)
self.fileNewAction=QAction(self.tr("New"),self)
self.fileNewAction.setShortcut("Ctrl+N")
self.fileNewAction.setStatusTip(self.tr("create a new file"))
self.connect(self.fileNewAction,SIGNAL("triggered()"),self.slotNewFile)
self.fileNewToolsAction=QAction(QIcon(":/newFile.png"),self.tr("New"),self)
#self.fileNewToolsAction.setShortcut("Ctrl+N")
self.fileNewToolsAction.setStatusTip(self.tr("create a new file"))
self.connect(self.fileNewToolsAction,SIGNAL("triggered()"),self.slotNewFile)
#self.fileSaveAction=QAction(QIcon(":/save.png"),self.tr("Save"),self)
self.fileSaveAction=QAction(self.tr("Save"),self)
self.fileSaveAction.setShortcut("Ctrl+S")
self.fileSaveAction.setStatusTip(self.tr("save the file"))
self.connect(self.fileSaveAction,SIGNAL("triggered()"),self.slotSaveFile)
self.fileSaveToolsAction=QAction(QIcon(":/save.png"),self.tr("Save"),self)
#self.fileSaveToolsAction.setShortcut("Ctrl+S") #must delete,else ctrl+s not work
self.fileSaveToolsAction.setStatusTip(self.tr("save the file"))
self.connect(self.fileSaveToolsAction,SIGNAL("triggered()"),self.slotSaveFile)
#self.fileSaveAsAction=QAction(QIcon(":/saveas.png"),self.tr("Save as"),self)
self.fileSaveAsAction=QAction(self.tr("Save as"),self)
self.fileSaveAsAction.setStatusTip(self.tr("save as a file"))
self.connect(self.fileSaveAsAction,SIGNAL("triggered()"),self.slotSaveFileAs)
#self.refreshBoardFileAction=QAction(QIcon(":/flush.png"),self.tr("Reflush Directory "),self)
self.refreshBoardFileAction=QAction(self.tr("Reflush Directory "),self)
self.refreshBoardFileAction.setStatusTip(self.tr("refresh board file"))
self.connect(self.refreshBoardFileAction,SIGNAL("triggered()"),self.slotTreeModel)
#self.exampleTools=QAction(QIcon(":/examples.png"),self.tr("Examples"),self)
self.exampleTools=QAction(self.tr("Examples"),self)
self.exampleMenu=QMenu(self.tr("example"))
self.connect(self.exampleMenu,SIGNAL("triggered(QAction*)"),self.showExamples)
self.exampleMenu.setStyleSheet("""QMenu {background-color: rgb(254,254,254);}
QMenu::item::selected { background-color: rgb(255,239,227); color: #000;}""")
if self.currentBoard=="esp32":
self.boardEsp32()
elif self.currentBoard=="esp8266":
self.boardEsp8266()
elif self.currentBoard=="pyboard":
self.boardPyboard()
elif self.currentBoard=="microbit":
self.boardMicrobit()
elif self.currentBoard=="TPYBoardV202":
self.boardTPYBoardV202()
elif self.currentBoard=="TPYBoardV102":
self.boardTPYBoardV102()
else:
self.boardOther()
self.createUpyLibMenu()
self.createWorkSpaceMenu()
#self.exitAction=QAction(QIcon(":/exit.png"),self.tr("Exit"),self)
self.exitAction=QAction(self.tr("Exit"),self)
self.exitAction.setShortcut("Ctrl+Q")
self.setStatusTip(self.tr("Out"))
self.connect(self.exitAction,SIGNAL("triggered()"),self.close)
#Edit
#self.cutAction=QAction(QIcon(":/cut.png"),self.tr("Cut"),self)
self.cutAction=QAction(self.tr("Cut"),self)
self.cutAction.setShortcut("Ctrl+X")
self.connect(self.cutAction,SIGNAL("triggered()"),self.slotCut)
#self.copyAction=QAction(QIcon(":/copy.png"),self.tr("Copy"),self)
self.copyAction=QAction(self.tr("Copy"),self)
self.copyAction.setShortcut("Ctrl+C")
self.connect(self.copyAction,SIGNAL("triggered()"),self.slotCopy)
#self.pasteAction=QAction(QIcon(":/paste.png"),self.tr("Paste"),self)
self.pasteAction=QAction(self.tr("Paste"),self)
self.pasteAction.setShortcut("Ctrl+V")
self.connect(self.pasteAction,SIGNAL("triggered()"),self.slotPaste)
#self.undoAction=QAction(QIcon(":/undo.png"),self.tr("Undo"),self)
self.undoAction=QAction(self.tr("Undo"),self)
self.undoAction.setShortcut("Ctrl+Z")
self.connect(self.undoAction,SIGNAL("triggered()"),self.slotUndo)
self.undoToolsAction=QAction(QIcon(":/undo.png"),self.tr("Undo"),self)
#self.undoToolsAction.setShortcut("Ctrl+Z")
self.connect(self.undoToolsAction,SIGNAL("triggered()"),self.slotUndo)
#self.redoAction=QAction(QIcon(":/redo.png"),self.tr("Redo"),self)
self.redoAction=QAction(self.tr("Redo"),self)
self.redoAction.setShortcut("Ctrl+Y")
self.connect(self.redoAction,SIGNAL("triggered()"),self.slotRedo)
self.redoToolsAction=QAction(QIcon(":/redo.png"),self.tr("Redo"),self)
#self.redoToolsAction.setShortcut("Ctrl+Y")
self.connect(self.redoToolsAction,SIGNAL("triggered()"),self.slotRedo)
#self.syntaxCheckAction=QAction(QIcon(":/syntaxCheck.png"),self.tr("syntaxCheck"),self)
self.syntaxCheckAction=QAction(self.tr("syntaxCheck"),self)
self.syntaxCheckAction.setStatusTip("the program syntax check")
self.connect(self.syntaxCheckAction,SIGNAL("triggered()"),self.slotSyntaxCheck)
self.syntaxCheckToolsAction=QAction(QIcon(":/syntaxCheck.png"),self.tr("syntaxCheck"),self)
self.syntaxCheckToolsAction.setStatusTip("the program syntax check")
self.connect(self.syntaxCheckToolsAction,SIGNAL("triggered()"),self.slotSyntaxCheck)
#self.clearTerminalAction=QAction(QIcon(":/clear.png"),self.tr("Clear"),self)
self.clearTerminalAction=QAction(self.tr("Clear"),self)
self.clearTerminalAction.setStatusTip(self.tr("clear Terminal"))
self.connect(self.clearTerminalAction,SIGNAL("triggered()"),self.slotClearTerminal)
self.clearTerminalToolsAction=QAction(QIcon(":/clear.png"),self.tr("Clear"),self)
self.clearTerminalToolsAction.setStatusTip(self.tr("clear Terminal"))
self.connect(self.clearTerminalToolsAction,SIGNAL("triggered()"),self.slotClearTerminal)
#self.findAction=QAction(QIcon(":/find.png"),self.tr("find replace"),self)
self.findAction=QAction(self.tr("find replace"),self)
self.findAction.setShortcut("Ctrl+F")
self.connect(self.findAction,SIGNAL("triggered()"),self.slotFindReplaceText)
#tools
#self.comMenuTools=QAction(QIcon(":/serial.png"),self.tr("Serial"),self)
self.comMenuTools=QAction(self.tr("Serial"),self)
self.comMenu=QMenu(self.tr("com"))
self.comActionGroup=QActionGroup(self)
mylist=self.myserial.Port_List()
for i in mylist:
self.serialComList.append(i)
i=QAction(i,self)
i.setCheckable(True)
self.comMenu.addAction(self.comActionGroup.addAction(i))
self.comActionGroup.setExclusive(True)
self.connect(self.comMenu,SIGNAL("triggered(QAction*)"),self.slotChooseCom)
self.comMenuTools.setMenu(self.comMenu)
self.comMenu.setStyleSheet("""QMenu {background-color: rgb(254,254,254);}
QMenu::item::selected { background-color: rgb(255,239,227); color: #000;}""")
#self.serialConnect=QAction(QIcon(":/connect.png"),self.tr("Connect"),self)
self.serialConnect=QAction(self.tr("Connect"),self)
self.connect(self.serialConnect,SIGNAL("triggered()"),self.slotConnectSerial)
self.serialConnectToolsAction=QAction(QIcon(":/serialConnect.png"),self.tr("Connect"),self)
self.connect(self.serialConnectToolsAction,SIGNAL("triggered()"),self.slotConnectSerial)
#self.serialClose=QAction(QIcon(":/serialClose.png"),self.tr("disconnect"),self)
self.serialClose=QAction(self.tr("disconnect"),self)
self.connect(self.serialClose,SIGNAL("triggered()"),self.slotCloseSerial)
self.serialCloseToolsAction=QAction(QIcon(":/serialClose.png"),self.tr("disconnect"),self)
self.connect(self.serialCloseToolsAction,SIGNAL("triggered()"),self.slotCloseSerial)
self.esp8266=QAction(self.tr("esp8266"),self)
self.connect(self.esp8266,SIGNAL("triggered()"),self.boardEsp8266)
self.esp8266.setCheckable(True)
self.esp32=QAction(self.tr("esp32"),self)
self.connect(self.esp32,SIGNAL("triggered()"),self.boardEsp32)
self.esp32.setCheckable(True)
self.pyboard=QAction(self.tr("pyboard"),self)
self.connect(self.pyboard,SIGNAL("triggered()"),self.boardPyboard)
self.pyboard.setCheckable(True)
self.microbit=QAction(self.tr("microbit"),self)
self.connect(self.microbit,SIGNAL("triggered()"),self.boardMicrobit)
self.microbit.setCheckable(True)
self.TPYBoardV202=QAction(self.tr("TPYBoardV202"),self)
self.connect(self.TPYBoardV202,SIGNAL("triggered()"),self.boardTPYBoardV202)
self.TPYBoardV202.setCheckable(True)
self.TPYBoardV102=QAction(self.tr("TPYBoardV102"),self)
self.connect(self.TPYBoardV102,SIGNAL("triggered()"),self.boardTPYBoardV102)
self.TPYBoardV102.setCheckable(True)
self.otherBoard=QAction(self.tr("other"),self)
self.connect(self.otherBoard,SIGNAL("triggered()"),self.boardOther)
self.otherBoard.setCheckable(True)
self.boardActionGroup=QActionGroup(self)
self.boardActionGroup.addAction(self.esp8266)
self.boardActionGroup.addAction(self.TPYBoardV202)
self.boardActionGroup.addAction(self.esp32)
self.boardActionGroup.addAction(self.pyboard)
self.boardActionGroup.addAction(self.TPYBoardV102)
self.boardActionGroup.addAction(self.microbit)
self.boardActionGroup.addAction(self.otherBoard)
self.boardActionGroup.setExclusive(True)
self.boardMenu = QMenu(self.tr("board"))
self.boardMenu.addAction(self.esp8266)
self.boardMenu.addAction(self.TPYBoardV202)
self.boardMenu.addAction(self.esp32)
self.boardMenu.addAction(self.pyboard)
self.boardMenu.addAction(self.TPYBoardV102)
self.boardMenu.addAction(self.microbit)
self.boardMenu.addAction(self.otherBoard)
#self.boardMenuTools=QAction(QIcon(":/board.png"),self.tr("board"),self)
self.boardMenuTools=QAction(self.tr("board"),self)
self.boardMenuTools.setMenu(self.boardMenu)
self.boardMenu.setStyleSheet("""QMenu {background-color: rgb(254,254,254);}
QMenu::item::selected { background-color: rgb(255,239,227); color: #000;}""")
#self.downloadAction=QAction(QIcon(":/download.png"),self.tr("Download"),self)
self.downloadAction=QAction(self.tr("Download"),self)
self.downloadAction.setStatusTip(self.tr("download file to the board"))
self.connect(self.downloadAction,SIGNAL("triggered()"),self.slotDownloadFile)
#self.downloadAndRunAction=QAction(QIcon(":/downloadAndRun.png"),self.tr("DownloadAndRun"),self)
self.downloadAndRunAction=QAction(self.tr("DownloadAndRun"),self)
self.downloadAndRunAction.setShortcut("F5")
self.downloadAndRunAction.setStatusTip(self.tr("download file and run"))
self.connect(self.downloadAndRunAction,SIGNAL("triggered()"),self.slotDownloadFileAndRun)
self.downloadAndRunToolsAction=QAction(QIcon(":/downloadAndRun.png"),self.tr("DownloadAndRun"),self)
#self.downloadAndRunToolsAction.setShortcut("F5")
self.downloadAndRunToolsAction.setStatusTip(self.tr("download file and run"))
self.connect(self.downloadAndRunToolsAction,SIGNAL("triggered()"),self.slotDownloadFileAndRun)
self.isDownloadFileAndRun=False
#self.stopProgramAction=QAction(QIcon(":/stop.png"),self.tr("Stop"),self)
self.stopProgramAction=QAction(self.tr("Stop"),self)
self.stopProgramAction.setStatusTip(self.tr("stop the program"))
self.connect(self.stopProgramAction,SIGNAL("triggered()"),self.slotStopProgram)
self.stopProgramToolsAction=QAction(QIcon(":/stop.png"),self.tr("Stop"),self)
self.stopProgramToolsAction.setStatusTip(self.tr("stop the program"))
self.connect(self.stopProgramToolsAction,SIGNAL("triggered()"),self.slotStopProgram)
#self.preferenceAction=QAction(QIcon(":/edit.png"),self.tr("Preferences"),self)
self.preferenceAction=QAction(self.tr("Preferences"),self)
self.connect(self.preferenceAction,SIGNAL("triggered()"),self.slotPreferences)
#self.initconfig=QAction(QIcon(":/init.png"),self.tr("InitConfig"),self)
self.initconfig=QAction(self.tr("InitConfig"),self)
self.connect(self.initconfig,SIGNAL("triggered()"),self.slotInitConfig)
#self.burnfirmware=QAction(QIcon(":/burnFirmware.png"),self.tr("BurnFirmware"),self)
self.burnfirmware=QAction(self.tr("BurnFirmware"),self)
self.connect(self.burnfirmware,SIGNAL("triggered()"),self.slotBurnFirmware)
#help
#self.aboutAction=QAction(QIcon(":/about.png"),self.tr("Tutorial online"),self)
self.aboutAction=QAction(self.tr("Tutorial online"),self)
self.connect(self.aboutAction,SIGNAL("triggered()"),self.slotAbout)
def createMenus(self):
#Files
self.fileMenu=self.menuBar().addMenu(self.tr("File"))
self.fileMenu.addAction(self.fileNewAction)
self.fileMenu.addAction(self.fileOpenAction)
self.fileMenu.addAction(self.exampleTools)
self.fileMenu.addAction(self.fileSaveAction)
self.fileMenu.addAction(self.fileSaveAsAction)
self.fileMenu.addAction(self.refreshBoardFileAction)
self.fileMenu.addAction(self.exitAction)
self.fileMenu.setStyleSheet("background-color: rgb(254,254,254);")
#edit
editMenu=self.menuBar().addMenu(self.tr("Edit"))
editMenu.addAction(self.copyAction)
editMenu.addAction(self.cutAction)
editMenu.addAction(self.pasteAction)
editMenu.addAction(self.redoAction)
editMenu.addAction(self.undoAction)
editMenu.addAction(self.syntaxCheckAction)
editMenu.addAction(self.findAction)
editMenu.setStyleSheet("background-color: rgb(254,254,254);")
#Tools
toolMenu=self.menuBar().addMenu(self.tr("Tools"))
toolMenu.addAction(self.comMenuTools)
toolMenu.addAction(self.boardMenuTools)
toolMenu.addAction(self.downloadAction)
toolMenu.addAction(self.downloadAndRunAction)
toolMenu.addAction(self.stopProgramAction)
toolMenu.addAction(self.burnfirmware)
toolMenu.addAction(self.initconfig)
toolMenu.addAction(self.preferenceAction)
toolMenu.setStyleSheet("background-color: rgb(254,254,254);")
self.connect(toolMenu,SIGNAL("hovered(QAction*)"),self.slotToolMenuHover)
#Help
aboutMenu=self.menuBar().addMenu(self.tr("Help"))
aboutMenu.addAction(self.aboutAction)
aboutMenu.setStyleSheet("background-color: rgb(254,254,254);")
self.menuBar().setStyleSheet("""QMenuBar {background-color: rgb(254, 254, 254);}
QMenuBar::item {background: rgb(254, 254, 254);}
QMenu::item::selected { background-color: rgb(255,239,227); color: #000; }
QMenuBar::item::selected {background-color: #FFEFE3;}""")
#create toolBars
def createToolBars(self):
fileToolBar=self.addToolBar("File")
fileToolBar.addAction(self.fileNewToolsAction)
fileToolBar.addAction(self.fileOpenToolsAction)
fileToolBar.addAction(self.fileSaveToolsAction)
fileToolBar.addAction(self.downloadAndRunToolsAction)
fileToolBar.addAction(self.stopProgramToolsAction)
fileToolBar.addAction(self.serialConnectToolsAction)
fileToolBar.addAction(self.serialCloseToolsAction)
fileToolBar.addAction(self.undoToolsAction)
fileToolBar.addAction(self.redoToolsAction)
fileToolBar.addAction(self.syntaxCheckToolsAction)
fileToolBar.addAction(self.clearTerminalToolsAction)
self.serialCloseToolsAction.setVisible(False)
if sys.platform=="darwin":
self.setUnifiedTitleAndToolBarOnMac(True)
else:
self.setUnifiedTitleAndToolBarOnMac(False)
# #FFBE2B #FF4E50
fileToolBar.setStyleSheet("""QToolBar {background-color: qlineargradient( y1: 0, y2: 1,stop: 0 #FF4E50, stop: 1 #FFBE2B);spacing:8px;}""")
self.addToolBar(Qt.RightToolBarArea,fileToolBar)
#create examples menu for File->Examples
def createExampleMenu(self):
#two follow lines mean:on PC conmon dir and board dir(contians:esp8266,esp32,pyboard,microbit)
self.PCcommonList=[]
self.PCboardList=[]
if self.currentBoard=="esp32":
self.getPCcommonExamples("%s/AppData/Local/uPyCraft/examples/Common"%rootDirectoryPath)
self.getPCboardExamples("%s/AppData/Local/uPyCraft/examples/Boards/ESP32"%rootDirectoryPath)
for filename in self.PCboardList:
if filename in self.PCcommonList:
self.PCcommonList.remove(filename)
self.getPCexamples("%s/AppData/Local/uPyCraft/examples/Boards/ESP32"%rootDirectoryPath,self.exampleMenu)
menuTitle=[]
for i in self.exampleMenu.findChildren(QMenu):
if i.title() not in menuTitle:
menuTitle.append(i.title())
for adir in self.PCcommonList:
adirList = adir.split("/")
if adirList[1] in menuTitle:
for i in self.exampleMenu.findChildren(QMenu):
if i.title()==adirList[1]:
self.addPCcommonExamples(adir[1:],i,adir[1:])
break
else:
newMenu = self.exampleMenu.addMenu(adirList[1])
self.addPCcommonExamples(adir[1:],newMenu,adir[1:])
menuTitle.append(adirList[1])
elif self.currentBoard=="esp8266":
self.getPCcommonExamples("%s/AppData/Local/uPyCraft/examples/Common"%rootDirectoryPath)
self.getPCboardExamples("%s/AppData/Local/uPyCraft/examples/Boards/ESP8266"%rootDirectoryPath)
for filename in self.PCboardList:
if filename in self.PCcommonList:
self.PCcommonList.remove(filename)
self.getPCexamples("%s/AppData/Local/uPyCraft/examples/Boards/ESP8266"%rootDirectoryPath,self.exampleMenu)
menuTitle=[]
for i in self.exampleMenu.findChildren(QMenu):
menuTitle.append(i.title())
for adir in self.PCcommonList:
adirList = adir.split("/")
if adirList[1] in menuTitle:
for i in self.exampleMenu.findChildren(QMenu):
if i.title()==adirList[1]:
self.addPCcommonExamples(adir[1:],i,adir[1:])
break
else:
newMenu = self.exampleMenu.addMenu(adirList[1])
self.addPCcommonExamples(adir[1:],newMenu,adir[1:])
menuTitle.append(adirList[1])
elif self.currentBoard=="TPYBoardV202":
self.getPCboardExamples("%s/AppData/Local/uPyCraft/examples/Boards/TPYBoardV202"%rootDirectoryPath)
for filename in self.PCboardList:
if filename in self.PCcommonList:
self.PCcommonList.remove(filename)
self.getPCexamples("%s/AppData/Local/uPyCraft/examples/Boards/TPYBoardV202"%rootDirectoryPath,self.exampleMenu)
menuTitle=[]
for i in self.exampleMenu.findChildren(QMenu):
menuTitle.append(i.title())
for adir in self.PCcommonList:
adirList = adir.split("/")
if adirList[1] in menuTitle:
for i in self.exampleMenu.findChildren(QMenu):
if i.title()==adirList[1]:
self.addPCcommonExamples(adir[1:],i,adir[1:])
break
else:
newMenu = self.exampleMenu.addMenu(adirList[1])
self.addPCcommonExamples(adir[1:],newMenu,adir[1:])
menuTitle.append(adirList[1])
elif self.currentBoard=="pyboard":
self.getPCboardExamples("%s/AppData/Local/uPyCraft/examples/Boards/pyboard"%rootDirectoryPath)
for filename in self.PCboardList:
if filename in self.PCcommonList:
self.PCcommonList.remove(filename)
self.getPCexamples("%s/AppData/Local/uPyCraft/examples/Boards/pyboard"%rootDirectoryPath,self.exampleMenu)
menuTitle=[]
for i in self.exampleMenu.findChildren(QMenu):
menuTitle.append(i.title())
for adir in self.PCcommonList:
adirList = adir.split("/")
if adirList[1] in menuTitle:
for i in self.exampleMenu.findChildren(QMenu):
if i.title()==adirList[1]:
self.addPCcommonExamples(adir[1:],i,adir[1:])
break
else:
newMenu = self.exampleMenu.addMenu(adirList[1])
self.addPCcommonExamples(adir[1:],newMenu,adir[1:])
menuTitle.append(adirList[1])
elif self.currentBoard=="TPYBoardV102":
self.getPCboardExamples("%s/AppData/Local/uPyCraft/examples/Boards/TPYBoardV102"%rootDirectoryPath)
for filename in self.PCboardList:
if filename in self.PCcommonList:
self.PCcommonList.remove(filename)
self.getPCexamples("%s/AppData/Local/uPyCraft/examples/Boards/TPYBoardV102"%rootDirectoryPath,self.exampleMenu)
menuTitle=[]
for i in self.exampleMenu.findChildren(QMenu):
menuTitle.append(i.title())
for adir in self.PCcommonList:
adirList = adir.split("/")
if adirList[1] in menuTitle:
for i in self.exampleMenu.findChildren(QMenu):
if i.title()==adirList[1]:
self.addPCcommonExamples(adir[1:],i,adir[1:])
break
else:
newMenu = self.exampleMenu.addMenu(adirList[1])
self.addPCcommonExamples(adir[1:],newMenu,adir[1:])
menuTitle.append(adirList[1])
elif self.currentBoard=="microbit":
self.getPCboardExamples("%s/AppData/Local/uPyCraft/examples/Boards/microbit"%rootDirectoryPath)
for filename in self.PCboardList:
if filename in self.PCcommonList:
self.PCcommonList.remove(filename)
self.getPCexamples("%s/AppData/Local/uPyCraft/examples/Boards/microbit"%rootDirectoryPath,self.exampleMenu)
menuTitle=[]
for i in self.exampleMenu.findChildren(QMenu):
menuTitle.append(i.title())
for adir in self.PCcommonList:
adirList = adir.split("/")
if adirList[1] in menuTitle:
for i in self.exampleMenu.findChildren(QMenu):
if i.title()==adirList[1]:
self.addPCcommonExamples(adir[1:],i,adir[1:])
break
else:
newMenu = self.exampleMenu.addMenu(adirList[1])
self.addPCcommonExamples(adir[1:],newMenu,adir[1:])
menuTitle.append(adirList[1])
else:
pass
self.exampleTools.setMenu(self.exampleMenu)
def createUpyLibMenu(self):
if not os.path.exists("%s/AppData/Local/uPyCraft/examples/uPy_lib"%rootDirectoryPath):
return
uPyLibPath="%s/AppData/Local/uPyCraft/examples/uPy_lib"%rootDirectoryPath
row=self.rootLib.rowCount() #clear board treemodel
self.rootLib.removeRows(0,row) #use for refresh treemodel,these two lines
self.getPCLibFile(self.rootLib,uPyLibPath)
def createWorkSpaceMenu(self):
if not os.path.exists(self.workspacePath):
row=self.workSpace.rowCount()
self.workSpace.removeRows(0,row)
return
path=self.workspacePath
row=self.workSpace.rowCount()
self.workSpace.removeRows(0,row)
self.getPCLibFile(self.workSpace,path)
def createWorkSpacePath(self):
if not os.path.exists(self.workspacePath):
print("workspacePath is none")
print(self.workspacePath)
self.workspacePath = QFileDialog.getExistingDirectory(self,"set your work space path","./")
if self.workspacePath=="":
return False
self.workspacePath=self.workspacePath.replace("\\","/")
self.workspacePath+="/workSpace"
if not os.path.exists(self.workspacePath):
os.mkdir(self.workspacePath)
os.mkdir(self.workspacePath+"/user_lib")
else:
pass
if os.path.exists("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath):
configfile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'r')
mymsg=configfile.read()
configfile.close()
jsonDict=eval(mymsg)
jsonDict['workSpace']=str(self.workspacePath)
jsonMsg=str(jsonDict)
configfile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'w')
configfile.write(jsonMsg)
configfile.close()
if not os.path.exists(self.workspacePath+"/user_lib"):
os.mkdir(self.workspacePath+"/user_lib")
return True
#create graphics interface
def createGraphicsInterface(self):
self.saveUntitled=saveUntitled()
self.connect(self.saveUntitled.okButton,SIGNAL("clicked()"),self.saveUntitledOK)
self.newBoardDirName=createBoardNewDirName()
self.connect(self.newBoardDirName.okButton,SIGNAL("clicked()"),self.getBoardDirName)
self.getTreeRightMenuRename=treeRightClickRename()
self.connect(self.getTreeRightMenuRename.okButton,SIGNAL("clicked()"),self.getTreeRenameOk)
def createBasicConfig(self):
path=os.getcwd()
path=path.replace("\\","/")
if not os.path.exists("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath):
configFile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'w')
configFile.write("{'serial':'None',\
'updateURL':'https://git.oschina.net/dfrobot/upycraft/raw/master/uPyCraft.json',\
'checkFirmware':'check update',\
'address':'China Mainland',\
'workSpace':'%s'}"%(path+"/workSpace"))
configFile.close()
configFile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'rU')
configMsg=configFile.read()
configFile.close()
try:
jsonDict=eval(configMsg)
except:
QMessageBox.information(self,self.tr("attention"),self.tr("Please put the uPy_Craft and workSpace into non-Chinese dir."),QMessageBox.Ok)
os.remove("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath)
return False
self.workspacePath=path+"/workSpace"
else:
configFile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'rU')
configMsg=configFile.read()
configFile.close()
try:
jsonDict=eval(configMsg)
except:
QMessageBox.information(self,self.tr("attention"),self.tr("Please put the uPy_Craft and workSpace into non-Chinese dir."),QMessageBox.Ok)
os.remove("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath)
return False
if jsonDict.get("workSpace") != None:
self.workspacePath=jsonDict['workSpace']
else:
self.workspacePath=path+"/workSpace"
if jsonDict.get('serial')==None or \
jsonDict.get('updateURL')==None or \
jsonDict.get('checkFirmware')==None or \
jsonDict.get('address')==None or \
jsonDict.get('workSpace')==None:
configFile=open("%s/AppData/Local/uPyCraft/config.json"%rootDirectoryPath,'w')
configFile.write("{'serial':'None','updateURL':'https://git.oschina.net/dfrobot/upycraft/raw/master/uPyCraft.json',\
'checkFirmware':'check update','address':'China Mainland','workSpace':'%s'}"%self.workspacePath)
configFile.close()
return True
###any slot function
#File
def slotOpenFile(self):
filename=QFileDialog.getOpenFileName(self)
filename=filename.replace("\\","/")
if str(filename).find(".py")<0 and \
str(filename).find(".txt")<0 and \
str(filename).find(".json")<0 and \
str(filename).find(".ini")<0:
self.terminal.append("current version only open py txt json ini file")
return
self.pcOpenFile(filename)
def slotTreeDoubleClickOpenFile(self,index):
if self.fileName.find(".py")<0 and \
self.fileName.find(".txt")<0 and \
self.fileName.find(".json")<0 and \
self.fileName.find(".ini")<0:
self.terminal.append("current version only open py txt json ini file.")
return
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
elif sys.platform=="darwin" and self.fileName.find(rootDirectoryPath)>=0:
self.pcOpenFile(self.fileName)
return
else:
if self.editClassFileitem(self.fileName):
self.uitoctrlQueue.put("loadfile:::%s"%self.fileName)
pass
else:
print("double false")
def slotNewFile(self):
self.tabWidget.createNewTab("untitled","",self.lexer)
def slotSaveFile(self):
if self.tabWidget.currentWidget() is None:
print("slotSaveFile none file")
return
self.saveStr=self.tabWidget.currentWidget().text()
if self.tabWidget.tabText(self.tabWidget.currentIndex())=="untitled":
if self.saveUntitled.isHidden():
self.saveUntitled.show()
elif self.tabWidget.tabToolTip(self.tabWidget.currentTab).find(currentExamplesPath)>=0:
self.slotSaveFileAs()
else:
tabname = self.tabWidget.tabText(self.tabWidget.currentIndex())
filepath = self.tabWidget.tabToolTip(self.tabWidget.currentIndex())
print(tabname)
print(filepath)
if tabname[0] != "*":#tabname have *,means it's changed,can be save