-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.pyw
1346 lines (1282 loc) · 53.7 KB
/
Main.pyw
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
import os
import sys
import PyQt5.QtGui
from PyQt5 import QtCore
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import getpass
import time
# import core
from lib.StyleReader import StyleReader
from lib.fileTreeView import CreateFileTree
from lib.readConfig import readConfig
import lib.WindowMenu as WindowMenuThis
import lib.core.ui.ChoicePanel as ChoicePanel
import lib.core.function.TabPanel
import lib.core.function.Starter as Starter
import lib.core.function.Setting as Setting
import lib.core.function.TabBar as TabBar
# more lib
from lib.core.ui.newPanelWindow import PanelWindow
# from function
import lib.core.function.About as About
# import base functions
from lib.base import *
# from start import START
print('in Main application')
# end
# theme
WindowLineList = []
OptionWidgetList = []
Window_self = None
SELF = None
class PFrame(QFrame):
# 重写mousePressEvent事件
def mousePressEvent(self, evt) -> None:
global Window_self
# color line
Windowline = self.findChild(QWidget, "WindowLine_"+self.objectName())
self.setStyleSheet('#'+self.objectName() +
'{border:1px solid #4888FF;border-radius:0px;}')
Windowline.setStyleSheet(
'background-image:url(./img/main_2/titlePanel.png);background-repeat:repeat-x;background-position:0px,center;')
for OtherWindowLine in WindowLineList:
if OtherWindowLine != Windowline:
try:
OtherWindowLine.parent().parent().setStyleSheet('#'+OtherWindowLine.parent().parent().objectName() +
'{border-radius:0px;}')
OtherWindowLine.setStyleSheet('background:rgba(0,0,0,0);')
except:
pass
# option widget一整个选项条
OptionWidget = self.findChild(QWidget, "option_"+self.objectName())
OptionWidget.setStyleSheet("#"+"option_"+self.objectName()+'{}')
for option_widget in OptionWidgetList:
if option_widget != OptionWidget:
try:
option_widget.setStyleSheet(
"#"+"option_"+self.objectName()+'{background-color:rgba(0,0,0,0);}')
except:
pass
# 在子窗口类里的pos需要改一下,这个是什么?
# print(evt.globalPos().x(),Window_self.geometry().x())
PointPos = QPoint(evt.globalPos().x() - Window_self.geometry().x(),
evt.globalPos().y() - Window_self.geometry().y())
# print(PointPos)
ChoicePanel.CheckRemoveThePanel(PointPos)
# print(evt.x(),evt.y(),dir(self))
class NewEditor(QMainWindow):
def __init__(self, app, start):
# start
QtWidgets.qApp.processEvents()
print_('[!] : start MCS')
global Window_self
super().__init__()
Window_self = self
globals()['SELF'] = self
self.theme = '#555'
self.start = start
#
self.start.prompt.setText(f'进入主程序准备阶段 . . . {str(self.start.pv)}%')
QtWidgets.qApp.processEvents()
#
self.EditorList = []
self.app = app
self.Editorindex = 0
self.Theme = {'bg': '#ededed', 'QFrame': '#f9f9f9'}
self.index = 0
self.panelWindowCount = 0
self.SettingWindowCount = 0
self.OPEN_VTK_WIDGET = []
self.VTK_render = []
self.IsReloading = False
self.VTK_irender = []
self.WebList = []
self.TREE_VIEW = []
self.openTerminal = True
self.makeTerminal()
self.QLABEL_NBT_ASCII_Name_LIST = []
self.HEX_VIEW = []
self.ASCII_VIEW = []
self.QLABEL_NBT_name_LIST = []
self.AllChildWindow = {}
self.ChildWindowCount = 1
self.setting = {}
self.thread_count = 0
self.LogIndex = 0
self.outputIndex = 0
self.childPanelCount = 0
self.Projectfolders = 0
self.Projectfiles = 0
self.newUntitledFileCount = 0
self.py_list = ['3.8', '3.9', '3.10', '3.11', 'auto']
self.version_list = ['0.1', '0.2', '0.3', 'auto']
#
with open('./config/config.json', 'r', encoding='utf-8') as ReadConfig:
self.Config = eval(ReadConfig.read())
with open(self.Config['path']+'/'+self.Config['name']+'/.mcstudio/'+self.Config['name']+'.mcsProject', 'r', encoding='utf-8') as ProjectConfig:
self.ProjectConfig = eval(ProjectConfig.read())
self.initUI()
self.UseTheme()
self.updateOutPut()
self.make_extend_menuBar()
print_('[!] : end start MCS')
print_(f'use time:{process_time()}s')
self.activateWindow()
self.setFocus()
def make_extend_menuBar(self):
h_line1 = QFrame()
h_line1.setFrameShape(QFrame.VLine)
h_line1.setFrameShadow(QFrame.Sunken)
################################
self.TopMenuBar = QWidget(self)
self.TopMenuBar.setMinimumWidth(260)
self.TopMenuBar.setObjectName('TopMenuBar')
self.TopMenuBar.setStyleSheet(
'''
#TopMenuBar{background-color:rgba(0,0,0,0);}
#TopMenuBar QLabel {
background-color:rgba(0,0,0,0);
}
#TopMenuBar QPushbutton {
background-color:rgba(0,0,0,0);
}
#TopMenuBar QCombox {
background-color:rgba(0,0,0,0);
}
#run {
background-color:rgba(0,0,0,0);
}
''')
self.TopMenuBar.setMaximumHeight(26)
this_layout = QHBoxLayout(self.TopMenuBar)
this_layout.setContentsMargins(0, 0, 0, 0)
self.TopMenuBar.move(460, 1)
#
this_layout.addWidget(h_line1)
#
self.Game_Version = QComboBox(self)
self.Game_Version.setMinimumWidth(80)
self.Game_Version.setView(QListView())
this_layout.addWidget(self.Game_Version)
################################
for version in self.version_list:
self.Game_Version.addItem(QIcon("./img/Minecraft.png"), version)
# minecraft version
h_line2 = QFrame()
h_line2.setFrameShape(QFrame.VLine)
h_line2.setFrameShadow(QFrame.Sunken)
this_layout.addWidget(h_line2)
# run
run = QPushButton()
run.setIcon(QIcon('./img/icons/play.svg'))
run.setText('run')
run.setObjectName('run')
this_layout.addWidget(run)
#
h_line3 = QFrame()
h_line3.setFrameShape(QFrame.VLine)
h_line3.setFrameShadow(QFrame.Sunken)
this_layout.addWidget(h_line3)
# python version
self.py_Version = QComboBox()
self.py_Version.setView(QListView())
self.py_Version.setMinimumWidth(80)
this_layout.addWidget(self.py_Version)
for py in self.py_list:
self.py_Version.addItem(QIcon("./img/file/icons/python.svg"), py)
# minecraft version
h_line4 = QFrame()
h_line4.setFrameShape(QFrame.VLine)
h_line4.setFrameShadow(QFrame.Sunken)
this_layout.addWidget(h_line4)
# folder
folder = QPushButton(self)
folder.setText(self.Config['name'])
folder.setIcon(QIcon('./img/file/icons/folder-queue-open.svg'))
folder.setObjectName('folder')
folder.setStyleSheet('''
#folder{background-color:rgba(0, 127, 212,0.15);border:1px solid #007FD4;}
#folder:hover {
background-color:rgba(150,150,150,0.4);
} ''')
folder.move(355, 2)
folder.clicked.connect(self.openProject)
folder.setMaximumHeight(23)
def updateOutPut(self):
with open('./log.txt', 'r', encoding='utf-8') as output:
self.OutPut_Widget.setText(output.read())
def openProject(self):
os.system('start "" "'+self.Config['path']+'/'+self.Config['name']+'"')
def UseTheme(self):
self.setStyleSheet('''
QSplitter::handle {
background-color: rgba(0, 0, 0, 0.0);
margin: 0px !important;
padding: 0px !important;
border: 0px !important;
}
QSplitter::handle:pressed {
border: 0px !important;
}
#ChoiceButton_this {
border-radius: 5px !important;
text-align: left;
margin-left: 5px;
margin-right: 5px;
padding-left: 3px;
border: 1px solid #567dbc;
margin-top: 2px;
margin-bottom: 2px;
}
#smallTitle {
border: 0px;
border-bottom: 1px solid #aaa;
color:gray;
text-align: left;
background-color: rgba(0, 0, 0, 0.0);
border-radius: 0px !important;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 5px;
margin-top: 5px;
padding-left: 5px;
font-size: 11.5px;
}
* {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
QTabWidget::pane{
border-right:0px;
border-bottom:0px;
}
QTabWidget {
border-right:0px;
border-bottom:0px;
}
''')
def CreatChildWindow(self, parent: QWidget, mode, spliterList: list, Old_widget_splitter_to: str, layoutThis=None): # 在这里创建了子面板
if Old_widget_splitter_to == '1':
# to <1> widget
pass
elif Old_widget_splitter_to == '2':
# to <2> wdiget
pass
else:
pass
# 负责分隔并且给每个块都附加上基础样式和控件,并且设置好内嵌父控件
if layoutThis == None:
MainWidgetlayout = QHBoxLayout()
MainWidgetlayout.setContentsMargins(0, 0, 0, 0)
parent.setLayout(MainWidgetlayout)
if mode == Qt.Vertical:
NewSpliter = QSplitter(Qt.Vertical)
elif mode == Qt.Horizontal:
NewSpliter = QSplitter(Qt.Horizontal)
NewSpliter.setObjectName("SPLITTERS")
NewSpliter.setStyleSheet('''
background-color: rgba(0, 0, 0, 0.0);
margin: 0px !important;
padding: 0px !important;
''')
NewSpliter.setHandleWidth(3)
# QFRAME分隔
QWidget_1 = PFrame()
QWidget_1.setObjectName(
'PURE_WIDGET_SPLITTER_'+str(self.ChildWindowCount))
QWidget_1.setStyleSheet(
'#PURE_WIDGET_SPLITTER_'+str(self.ChildWindowCount) + '{margin:0px;border-radius:0px;}')
self.ChildWindowCount = self.ChildWindowCount + 1
QWidget_2 = PFrame()
QWidget_2.setObjectName(
'PURE_WIDGET_SPLITTER_'+str(self.ChildWindowCount))
QWidget_2.setStyleSheet(
'#PURE_WIDGET_SPLITTER_'+str(self.ChildWindowCount) + '{margin:0px;border-radius:0px;}')
# 命名
# 设置边框
# end
self.ChildWindowCount = self.ChildWindowCount + 1
NewSpliter.addWidget(QWidget_1)
QWidget_1.setMinimumSize(0, 0)
QWidget_2.setMinimumSize(0, 0)
NewSpliter.addWidget(QWidget_2)
NewSpliter.setSizes(spliterList)
if layoutThis == None:
MainWidgetlayout.addWidget(NewSpliter)
else:
layoutThis.addWidget(NewSpliter)
WidgetList = [QWidget_1, QWidget_2]
# 重写mousePressEvent事件
return WidgetList
pass
def makeTabWidget(self, StartTabList: list):
self.Toptabs = QTabWidget()
# tabs.setTabPosition(QTabWidget.West)
self.Toptabs.setMovable(True)
self.Toptabs.setTabsClosable(True)
for TabName in StartTabList:
globals()['QTabWidget_'+TabName] = QWidget()
globals()['QTabWidget_'+TabName].setObjectName('thisTabWidget')
# lib.core.function.TabPanel.AppendTabWidget(self,globals()['QTabWidget_'+TabName],TabName)#初始化tab栏
self.Toptabs.addTab(globals()['QTabWidget_'+TabName], TabName)
QtWidgets.qApp.processEvents()
def openFolder(self):
os.system('start '+self.setting['path']+'/'+self.setting['name'])
def GetDir(self, Lastpath, tabCount):
for file_name in os.listdir(Lastpath):
if os.path.isdir(Lastpath+'//'+file_name) == True:
# print(file_name)
# is folder
# print(Lastpath+'\\'+file_name)
self.pathList.append(tabCount*' '+file_name)
self.Projectfolders = self.Projectfolders + 1
self.GetDir(Lastpath+'\\'+file_name, tabCount=tabCount+1)
else:
self.pathList.append(tabCount*' '+file_name)
self.Projectfiles += 1
def center(self): # 居中_方法
ScreenWidth = QGuiApplication.primaryScreen().geometry().width()
ScreenHeight = QGuiApplication.primaryScreen().geometry().height()
self.move(ScreenWidth/2 - self.W/2, ScreenHeight/2 - self.H/2)
def initUI(self):
# self.setFixedSize(self.W,self.H)#禁止改变大小
self.THIS_MAIN_WIDGET = QWidget()
self.setCentralWidget(self.THIS_MAIN_WIDGET)
self.User = getpass.getuser()
# self.setGeometry(300, 300, 250, 150)
# #(x, y, w, h)
self.VboxLayOut_This = QVBoxLayout()
self.VboxLayOut_This.setContentsMargins(0, 0, 0, 0)
self.VboxLayOut_This.setSpacing(0)
self.TopDIV = QWidget()
self.TopDIV.setObjectName('TopDIV')
self.TopDIV.setMinimumHeight(30)
self.TopDIV.setMaximumHeight(30)
# self.VboxLayOut_This.addWidget(self.TopDIV)
# VBoxLayout
'''self.Tool_head_DIV = QWidget(self.widget)
self.Tool_head_DIV.move(30,0)
self.Tool_head_DIV.resize(390,29)
self.Tool_head_DIV.setObjectName('Tool_head_DIV')'''
self.MakeToolDIV()
# this
# 设置标题栏的tip-path
self.makeTabWidget(TabBar.editors)
# make tabs widget
# self.MainWidget = QWidget()
# self.MainWidget.setObjectName('MainWidget')
self.boxlayout_1 = QVBoxLayout()
self.boxlayout_1.setContentsMargins(0, 0, 0, 0)
self.boxlayout_1.setSpacing(0)
self.Toptabs.setContentsMargins(0, 0, 0, 0)
self.Toptabs.setObjectName('Toptabs')
self.boxlayout_1.addWidget(self.Toptabs)
self.Toptabs.tabBarClicked.connect(self.reloadEditor)
# self.Toptabs.setMaximumHeight(45)
# self.boxlayout_1.addWidget(self.MainWidget)
self.THIS_MAIN_WIDGET.setLayout(self.boxlayout_1)
self.THIS_MAIN_WIDGET.setObjectName('THIS_MAIN_WIDGET')
# init后续初始化
# 初始化-1
self.MakeChildWindow()
#
self.setWindowIcon(QIcon('./img/appicon/icon32.png'))
self.UseToolBar()
# Status
self.StatusText = 'MCS already started'
self.status = self.statusBar()
self.status.setContentsMargins(0, 0, 0, 0)
# 状态栏本身显示的信息 第二个参数是信息停留的时间,单位是毫秒,默认是0(0表示在下一个操作来临前一直显示)
self.status.showMessage(self.StatusText, 0)
self.APP_MEMORY = 4*1024 # 4GB内存
self.Memory = MemoryWidget()
#
self.UseMemory = UseMemory(self.APP_MEMORY)
#
self.HELP_button = QPushButton()
self.HELP_button.setIcon(QIcon('./img/icons/help-circle.svg'))
self.HELP_button.setFixedSize(16, 16)
#
self.INFO = QPushButton()
self.INFO.setIcon(QIcon('./img/icons/message-square.svg'))
self.INFO.setFixedSize(16, 16)
#
self.status.addPermanentWidget(self.UseMemory, stretch=0)
self.status.addPermanentWidget(self.Memory, stretch=0)
self.status.addPermanentWidget(self.INFO, stretch=0)
self.status.addPermanentWidget(self.HELP_button, stretch=0)
#
def reloadEditor(self, a0):
Name = SELF.Toptabs.tabText(a0)
if Name == 'Editor':
if self.IsReloading == False:
print('reloading')
self.WebList[0].reload()
self.IsReloading = True
def event(self, QEvent):
if QEvent.type() == QEvent.StatusTip:
if QEvent.tip() == "":
QEvent = QStatusTipEvent(self.StatusText) # 此处为要始终显示的内容
return super().event(QEvent)
def UseToolBar(self):
leftBar = QToolBar('leftBar')
self.addToolBar(Qt.LeftToolBarArea, leftBar)
leftBar.setOrientation(Qt.Vertical)
# add actions
search = QAction(QIcon("./img/icons/search.svg"), "search", self)
leftBar.addAction(search)
#
lib = QAction(QIcon("./img/icons/grid.svg"), "lib", self)
leftBar.addAction(lib)
#
drive = QAction(QIcon("./img/icons/hard-drive.svg"), "drive", self)
leftBar.addAction(drive)
#
git = QAction(QIcon("./img/icons/git-merge.svg"), "git", self)
leftBar.addAction(git)
#
layout = QAction(QIcon("./img/icons/layout.svg"), "layout", self)
leftBar.addAction(layout)
#
info = QAction(QIcon("./img/icons/info.svg"), "info", self)
leftBar.addAction(info)
#
terminal = QAction(QIcon("./img/icons/terminal.svg"), "terminal", self)
leftBar.addAction(terminal)
#
self.max = QAction(QIcon("./img/icons/maximize-2.svg"), "max", self)
leftBar.addAction(self.max)
leftBar.actionTriggered[QAction].connect(self.leftbtnpressed)
# leftBar.setMinimumWidth(35)
def leftbtnpressed(self, a):
if a.text() == 'max':
if self.isFullScreen() == False:
self.setWindowState(Qt.WindowFullScreen)
self.max.setIcon(QIcon("./img/icons/minimize-2.svg"))
else:
self.setWindowState(Qt.WindowNoState)
self.max.setIcon(QIcon("./img/icons/maximize-2.svg"))
elif a.text() == 'terminal':
self.UseTerminal()
elif a.text() == 'info':
self.Tool_about_APP()
def UseTerminal(self):
if self.openTerminal == False:
# 显示
self.openTerminal = True
self.Terminal.show()
else:
# 不显示
self.Terminal.hide()
self.openTerminal = False
def makeTerminal(self):
self.OutPut_Widget = QTextBrowser()
self.OutPut_Widget.insertHtml('<a>ready to start [output]</a>')
self.Terminal = QDockWidget("output", self)
self.Terminal.setWidget(self.OutPut_Widget)
self.addDockWidget(Qt.BottomDockWidgetArea, self.Terminal)
#
self.start.prompt.setText(f'刷新 output 面板 . . . {str(self.start.pv)}%')
QtWidgets.qApp.processEvents()
def recursiveDict(self, dict, parentWidget):
SplitterSize = [0, 0]
This_Dict = {}
for key in dict:
if key != "PROJECT_LIST":
if dict[key]['float'] == 'left' or dict[key]['float'] == 'right':
mode = Qt.Horizontal
else:
mode = Qt.Vertical
This_Dict[dict[key]['float']] = dict[key]['size']
for i in This_Dict:
if i == 'left' or i == 'top':
SplitterSize[0] = This_Dict[i]
else:
SplitterSize[1] = This_Dict[i]
WidgetList = self.CreatChildWindow(
parentWidget, mode, SplitterSize, "1") # 创建分隔控件
# CreatChildWindow(self,parent,mode,spliterList:list,Old_widget_splitter_to:str):
tempCount = 0
for key_s in dict: # 修饰样式以及子控件实现
if key_s != "PROJECT_LIST":
if dict[key_s]['Children'] != None: # 如果他有children
self.recursiveDict(
dict[key_s]['Children'], WidgetList[tempCount]) # 递归给子布局
# 为父控件重置样式
WidgetList[tempCount].setContentsMargins(0, 0, 0, 0)
WidgetList[tempCount].setStyleSheet(
"#"+WidgetList[tempCount].objectName()+'{border:0px;}')
else:
self.SetChildWindow_STYLE(
WidgetList[tempCount], dict[key_s]) # 设置样式的吧
tempCount += 1 # tempCount自加1
def SetChildWindow_STYLE(self, widget, dict: dict):
# set the child window's style
# 颜色条
ChildLayout = QVBoxLayout()
ChildLayout.setContentsMargins(0, 0, 0, 0)
ChildLayout.setSpacing(0)
# layout end
# top-option-widget
OptionWidget = QWidget()
OptionWidget.setStyleSheet('')
OptionWidget.setMinimumHeight(20)
OptionWidget.setMaximumHeight(20)
OptionWidget.setObjectName('option_'+widget.objectName())
OptionWidgetList.append(OptionWidget)
# make the option buttons
# close button->
OptionLayout = QHBoxLayout() # layout this widget
# end of layout
CloseButton = QPushButton() # 关闭此面板
CloseButton.setObjectName('Close_Button') # 完成
CloseButton.setMaximumHeight(20)
CloseButton.setMaximumWidth(20)
CloseButton.setToolTip("Close the Panel")
CloseButton.clicked.connect(self.closePanel)
CloseButton.setStyleSheet('''
*{background-image: url(./img/big_close__.png);
background-color: transparent;
background-repeat: no-repeat;
background-position: center center;}
*:hover {
background-color: rgb(255, 112, 112);
border: 1px solid #ccc;
}''')
# setting
# splitter
splitterButton = QPushButton() # 分割此面板
splitterButton.setObjectName(dict['Window'])
splitterButton.setMaximumHeight(20)
splitterButton.setMaximumWidth(20)
splitterButton.setStyleSheet('''
*{background-image: url(./img/main/split.png);
background-repeat: no-repeat;
background-position: center center;}
''')
splitterButton.setToolTip('Split the Panel - Horizontal')
splitterButton.clicked.connect(self.splitPanel)
# split-v
splitterButton_v = QPushButton() # 分割此面板
splitterButton_v.setObjectName(dict['Window'])
splitterButton_v.setMaximumHeight(20)
splitterButton_v.setMaximumWidth(20)
splitterButton_v.setStyleSheet('''
*{background-image: url(./img/main/split_v.png);
background-repeat: no-repeat;
background-position: center center;}
''')
splitterButton_v.setToolTip('Split the Panel - Vertical')
splitterButton_v.clicked.connect(self.splitPanel_V)
# out window
outButton = QPushButton() # 弹出此面板
outButton.setObjectName(dict['Window'])
outButton.setMaximumHeight(20)
outButton.setMaximumWidth(20)
outButton.setStyleSheet('''
*{background-image: url(./img/main/out3_2.png);
background-repeat: no-repeat;
background-position: center center;}
''')
outButton.setToolTip('Pop up window')
outButton.clicked.connect(self.PopUpWindow)
# Line->
Line = QWidget() # 子窗口的分割线
Line.setObjectName("WindowLine_"+widget.objectName())
Line.setMaximumHeight(7)
# Window name->
WindowName = QPushButton() # 主类名
WindowName.clicked.connect(self.OutTheChoicePanel)
WindowName.setToolTip(dict['Window'])
WindowName.setObjectName('WindowName')
WindowName.setText(dict['Window'])
WindowName.setStyleSheet('''
#WindowName {
background-color: rgba(0, 0, 0, 0.0);
padding-left:2px;
padding-right:15px;
border: 1px solid rgba(0, 0, 0, 0.0);
background-image: url(./img/bottom_to.png);
background-position:right center;
background-repeat:no-repeat;
color:gray;
}
#WindowName:hover{
background-color: #567dbc;
}''')
WindowLineList.append(Line)
# 给名称设置样式-icon
IconPath = WindowMenuThis.WindowMenu[dict['Window']]['icon']
WindowName.setIcon(QIcon(IconPath))
# WindowName.setMaximumWidth(7*len(dict['Window']))
# set layout
OptionLayout.addWidget(WindowName)
OptionLayout.addWidget(Line)
OptionLayout.setStretch(1, 2)
OptionLayout.addWidget(outButton)
OptionLayout.addWidget(splitterButton)
OptionLayout.addWidget(splitterButton_v)
OptionLayout.addWidget(CloseButton)
OptionLayout.setSpacing(0)
CloseButton.setContentsMargins(0, 0, 0, 0)
OptionWidget.setContentsMargins(0, 0, 0, 0)
OptionLayout.setContentsMargins(2, 0, 0, 0)
OptionWidget.setLayout(OptionLayout)
# Main-widget
Child_main_widget = QWidget()
Child_main_widget.setObjectName(
'Child_main_widget_'+str(self.childPanelCount))
# 立刻加一咯
self.childPanelCount = self.childPanelCount + 1
# add widget to layout
ChildLayout.addWidget(OptionWidget)
ChildLayout.addWidget(Child_main_widget)
widget.setLayout(ChildLayout)
# 初始化面板->this:1
# def PanelStarter(Sender:QPushButton,self,Name) -> None:#导入模块部分
Starter.PanelStarter(WindowName, self, dict['Window'])
pass
def OutTheChoicePanel(self):
# print(self.geometry())
ChoicePanel.OutTheChoicePanel(self.sender(), self, self.geometry())
def MakeChildWindow(self):
# make childewindow
for item in TabBar.editors:
globals()['QTabWidget_'+item].setContentsMargins(2, 2, 2, 2)
# self.MainWidget.setContentsMargins(2,2,2,2)
try:
self.recursiveDict(WindowMenuThis.StarterInfo[item], globals()[
'QTabWidget_'+item]) # 产生窗口
print('[info] : successful started<'+item +
f'> {str(time.localtime().tm_hour)}:{str(time.localtime().tm_min)}:{str(time.localtime().tm_sec)} \n')
QtWidgets.qApp.processEvents()
except Exception as e:
print(WindowMenuThis)
print('[Error] : Starter<'+item +
f'> failed {str(time.localtime().tm_hour)}:{str(time.localtime().tm_min)}:{str(time.localtime().tm_sec)}\n', e)
print(traceback.format_exc())
QtWidgets.qApp.processEvents()
def closeEvent(self, event):
for VtkWidget in self.OPEN_VTK_WIDGET:
VtkWidget.Finalize()
with open('./config/config.json', 'r', encoding='utf-8') as ReadConfig:
getThisConfig = eval(ReadConfig.read())
getThisConfig['w'] = self.width()
getThisConfig['h'] = self.height()
getThisConfig['x'] = self.x()
getThisConfig['y'] = self.y()
with open('./config/config.json', 'w', encoding='utf-8') as NewConfig:
NewConfig.write(str(getThisConfig))
pass
# window.menu function this
# 一些其他的函数
# some other function
def Strange_recursive_delete(self, sender, recursive):
if recursive > 0:
if sender.parent().parent().__class__ == PFrame:
print('this is the Pframe', sender.parent().parent())
if sender.parent().count() == 1:
print('delete')
if sender.parent().parent().parent().count() == 1:
self.Strange_recursive_delete(
sender.parent().parent(), recursive-1)
else:
recursive = 0
sender.parent().parent().deleteLater()
# 如果在子空间内的2个面板被全部删除,则删除这个子空间的父部件
def closePanel(self):
sender = self.sender()
# print(sender.parent().parent().parent())
out = 1
ThisIndex = sender.parent().parent().parent().indexOf(sender.parent().parent())
if ThisIndex == 1:
out = 0
sender.parent().parent().deleteLater()
# print(sender.parent().parent().parent().count())
sender.parent().parent().parent().setSizes([100])
# print(sender.parent().parent().parent().parent())
recursive = int(self.ChildWindowCount/2) + \
1 # 最小递归次数,可以被count = 0时提前返回
self.Strange_recursive_delete(sender.parent().parent(), recursive)
sender.parent().parent().parent().setSizes([100])
# 改写一个接受参数的
def closePanel_sender(self, sender):
# print(sender.parent().parent().parent())
out = 1
ThisIndex = sender.parent().parent().parent().indexOf(sender.parent().parent())
if ThisIndex == 1:
out = 0
sender.parent().parent().deleteLater()
# print(sender.parent().parent().parent().count())
sender.parent().parent().parent().setSizes([100])
# print(sender.parent().parent().parent().parent())
recursive = int(self.ChildWindowCount/2) + \
1 # 最小递归次数,可以被count = 0时提前返回
self.Strange_recursive_delete(sender.parent().parent(), recursive)
sender.parent().parent().parent().setSizes([100])
def splitPanel(self):
senderThis = self.sender()
LastName = senderThis.parent().children()[1].text()
try:
for wline in WindowLineList:
if wline.objectName() == "WindowLine_"+senderThis.parent().parent().objectName():
WindowLineList.remove(wline)
break
for oline in OptionWidgetList:
if oline.objectName() == "option_"+senderThis.parent().parent().objectName():
OptionWidgetList.remove(oline)
break
except:
pass
thisSplitterWidget = senderThis.parent().parent()
ThisLayout = thisSplitterWidget.layout()
# thisSplitterWidget.setLayout(None)
item_list = list(range(ThisLayout.count()))
item_list.reverse() # 倒序删除,避免影响布局顺序
for i in item_list:
item = ThisLayout.itemAt(i)
ThisLayout.removeItem(item)
if item.widget():
item.widget().deleteLater()
getWidget = self.CreatChildWindow(thisSplitterWidget, Qt.Horizontal, [
10, 10], "1", layoutThis=ThisLayout) # 创建分隔控件
thisSplitterWidget.setStyleSheet(
'#'+thisSplitterWidget.objectName()+"{border:0px;}")
self.SetChildWindow_STYLE(
getWidget[0], {'Window': LastName}) # 0
self.SetChildWindow_STYLE(getWidget[1], {'Window': 'White'}) # 1
# 复制一个splitPanel_V
def splitPanel_V(self):
senderThis = self.sender()
LastName = senderThis.parent().children()[1].text()
# print(ColorLineList)
try:
for wline in WindowLineList:
if wline.objectName() == "WindowLine_"+senderThis.parent().parent().objectName():
WindowLineList.remove(wline)
break
for oline in OptionWidgetList:
if oline.objectName() == "option_"+senderThis.parent().parent().objectName():
OptionWidgetList.remove(oline)
break
except:
pass
# 'option_'+widget.objectName()
thisSplitterWidget = senderThis.parent().parent()
ThisLayout = thisSplitterWidget.layout()
# thisSplitterWidget.setLayout(None)
item_list = list(range(ThisLayout.count()))
item_list.reverse() # 倒序删除,避免影响布局顺序
for i in item_list:
item = ThisLayout.itemAt(i)
ThisLayout.removeItem(item)
if item.widget():
item.widget().deleteLater()
getWidget = self.CreatChildWindow(thisSplitterWidget, Qt.Vertical, [
10, 10], "1", layoutThis=ThisLayout) # 创建分隔控件
thisSplitterWidget.setStyleSheet(
'#'+thisSplitterWidget.objectName()+"{border:0px;}")
self.SetChildWindow_STYLE(
getWidget[0], {'Window': LastName}) # 0
self.SetChildWindow_STYLE(getWidget[1], {'Window': 'White'}) # 1
# PopUpWindow可能会有点复杂
def PopUpWindow(self):
sender = self.sender()
LastName = sender.parent().children()[1].text()
Frame_X = sender.pos().x()
Frame_Y = sender.pos().y()
Width_ = sender.parent().parent().width()
Height_ = sender.parent().parent().height()
ThisSenderName = sender.objectName()
Pos_X = sender.mapToGlobal(sender.pos()).x() # 控件相对于屏幕的位置
Pos_Y = sender.mapToGlobal(sender.pos()).y()
print(Pos_X, Pos_Y, Width_, Height_)
globals()['PanelWindow_This_' +
str(self.panelWindowCount)] = QMainWindow(self)
thisWindow = globals()['PanelWindow_This_'+str(self.panelWindowCount)]
thisWindow.resize(Width_, Height_ - 30)
thisWindow.show()
screen = QDesktopWidget().screenGeometry()
print(Frame_X, Width_)
size = thisWindow.geometry()
thisWindow.move(Pos_X - Frame_X - (Width_) +
sender.width() + 62, Pos_Y - Frame_Y)
# globals()['PanelWindow_This_'+str(self.panelWindowCount)].label_2.setText(ThisSenderName)
# globals()['PanelWindow_This_'+str(self.panelWindowCount)].setMaximumSize(Width_,Height_)
print(thisWindow.geometry())
#
thisWindow.Config = self.Config
#
thisWindow.THIS_MAIN_WIDGET = QWidget()
# WindowLineList.append(Line)
# 给名称设置样式-icon
IconPath = WindowMenuThis.WindowMenu[LastName]['icon']
# Starter.PanelStarter(thisWindow.WindowName,thisWindow,sender.objectName())#def PanelStarter(Sender:QPushButton,self,Name) -> None:#导入模块部分
Name = LastName
thisLayout = QVBoxLayout()
thisLayout.setContentsMargins(0, 0, 0, 0)
thisLayout.setSpacing(0)
# thisWindow.widget_2.setStyleSheet('*{border-bottom-left-radius:7px;border-bottom-right-radius:7px;}')
thisWindow.setCentralWidget(thisWindow.THIS_MAIN_WIDGET)
thisWindow.THIS_MAIN_WIDGET.setLayout(thisLayout)
thisWindow.THIS_MAIN_WIDGET.setObjectName('THIS_MAIN_WIDGET_')
thisWindow.setWindowTitle(Name)
# give value
thisWindow.EditorList = self.EditorList
thisWindow.Editorindex = self.Editorindex
thisWindow.index = self.index
thisWindow.panelWindowCount = self.panelWindowCount
thisWindow.SettingWindowCount = self.SettingWindowCount
thisWindow.LogIndex = self.LogIndex
thisWindow.outputIndex = self.outputIndex
thisWindow.childPanelCount = self.childPanelCount
thisWindow.Config = self.Config
thisWindow.ProjectConfig = self.ProjectConfig
thisWindow.AllChildWindow = self.AllChildWindow
thisWindow.ChildWindowCount = self.ChildWindowCount
thisWindow.setting = self.setting
thisWindow.Projectfolders = self.Projectfolders
thisWindow.Projectfiles = self.Projectfiles
# give value
# 进入主初始化模块
exec(f"lib.core.module.{Name}.init(thisLayout,'{Name}',thisWindow)")
self.closePanel_sender(sender) # 删除面板
self.panelWindowCount += 1
def Tool_about_APP(self):
# about the application
print('open about window')
# window.menu function this -> Tool_control_clicked
sender = self.sender()
globals()['NewAboutWindow_'+str(self.SettingWindowCount)
] = PanelWindow() # 直接复用好了
thisAbout = globals()['NewAboutWindow_'+str(self.SettingWindowCount)]
thisAbout.resize(400, 500)
screen = QDesktopWidget().screenGeometry()
size = thisAbout.geometry()
newLeft = int((screen.width() - size.width()) / 2)
newTop = int((screen.height() - size.height()) / 2)
thisAbout.move(newLeft, newTop)
thisAbout.WindowName.setText('About')
thisAbout.WindowName.setStyleSheet('margin-left:7px;')
MainLayout = QVBoxLayout()
thisAbout.widget_2.setLayout(MainLayout)
# thisAbout.widget_2.setStyleSheet('background-color:#f9f9f9;')
# thisAbout.widget.setStyleSheet('background-color:#fff;')
MainLayout.addWidget(About.MakeAbout())
thisAbout.show()
self.SettingWindowCount += 1 # 自加
def Tool_control_clicked(self):
print('open settings window')
# window.menu function this -> Tool_control_clicked
sender = self.sender()
globals()['NewSettingWindow_'+str(self.SettingWindowCount)
] = Setting.SettingWindow(self, self.User) # 直接复用好了
ThisSetting = globals()['NewSettingWindow_' +
str(self.SettingWindowCount)]
screen = QDesktopWidget().screenGeometry()
size = ThisSetting.geometry()
newLeft = int((screen.width() - size.width()) / 2)
newTop = int((screen.height() - size.height()) / 2)
ThisSetting.setWindowTitle('Setting - '+self.User)
ThisSetting.WindowName.setText('Setting - '+self.User)
ThisSetting.resize(760, 660)
ThisSetting.move(newLeft, newTop)
ThisSetting.show()
self.SettingWindowCount += 1 # 自加
def getAllWidget(self, lastWidget):
for widget in lastWidget.children():
rewrite_print(widget)
try:
widget.setStyleSheet('')
except:
pass
if len(widget.children()) != 0:
self.getAllWidget(widget)
def MakeToolDIV(self): # 菜单栏部分
menubar = self.menuBar()
# bar
###
FILE = ['新建项目', '打开项目', '新建文件', '打开文件',
'最近打开的项目', '保存', '保存副本', '打包为zip', '关闭']
FILE_FUNC = [print, print, print, print,
print, print, print, print, qApp.quit]
FILE_KEY = ['Ctrl+N', 'Ctrl+O', '', '', '',
'Ctrl+S', 'Ctrl+Shift+S', 'Ctrl+P', 'Ctrl+Q']
fileMenu = menubar.addMenu("文件(F)")
for i in range(len(FILE)):
Act = QAction(QIcon('exit.png'), FILE[i], self)
Act.setShortcut(FILE_KEY[i])
Act.triggered.connect(FILE_FUNC[i])
fileMenu.addAction(Act)
####
editMenu = menubar.addMenu("编辑(E)")
EDIT = ['撤销', '恢复', '剪切', '复制', '粘贴', '查找', '替换', '添加方块', '删除方块']
EDIT_FUNC = [print, print, print, print,
print, print, print, print, print]
EDIT_KEY = ['Ctrl+Z', 'Ctrl+Y', 'Ctrl+X', 'Ctrl+C',
'Ctrl+V', 'Ctrl+Alt+F', 'Ctrl+H', 'Ctrl+A', 'Ctrl+D']
for i in range(len(EDIT)):
Act = QAction(QIcon('exit.png'), EDIT[i], self)
Act.setShortcut(EDIT_KEY[i])
Act.triggered.connect(EDIT_FUNC[i])
editMenu.addAction(Act)
###
select = menubar.addMenu("选择(S)")
SELECT = ['全选', '反向选', '勾选', '自由选取']
SELECT_FUNC = [print, print, print, print]
SELECT_KEY = ['Ctrl+Shift+S', 'Ctrl+Alt+S',
'Ctrl+Shift+T', 'Ctrl+Shift+F']
for i in range(len(SELECT)):
Act = QAction(QIcon('exit.png'), SELECT[i], self)
Act.setShortcut(SELECT_KEY[i])
Act.triggered.connect(SELECT_FUNC[i])
select.addAction(Act)
###
run = menubar.addMenu("运行(R)")
RUN = ['运行脚本', '运行调试', '运行解析指令', '调试指令', '运行指令模拟器']
RUN_FUNC = [print, print, print, print, print]
RUN_KEY = ['Ctrl+R', 'Ctrl+Alt+R',
'Ctrl+Shift+C', 'Ctrl+Alt+C', 'Ctrl+M']
for i in range(len(RUN)):
Act = QAction(QIcon('exit.png'), RUN[i], self)
Act.setShortcut(RUN_KEY[i])
Act.triggered.connect(RUN_FUNC[i])
run.addAction(Act)
###
window = menubar.addMenu("窗口(W)")
WINDOW = ['方块(背包)', '实体(entites)', '掉落物(items)',
'指令聊天栏(/)', '渲染(renderer)']
WINDOW_FUNC = [print, print, print, print, print]
for i in range(len(RUN)):
Act = QAction(QIcon('exit.png'), WINDOW[i], self)
Act.triggered.connect(WINDOW_FUNC[i])