-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
116 lines (91 loc) · 3.59 KB
/
main.py
File metadata and controls
116 lines (91 loc) · 3.59 KB
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
# DOC> name: 地图编辑器2.0
# DOC> time: 2022.12.14
# DOC> desc: 重构之前的地图编辑器
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from Euclid.Euclid import *
from Euclid.EuclidGraphicsView import *
from Euclid.EuclidWindow import *
from Euclid.EuclidWidgets import *
from utils import *
from qtutils import *
from EditorBrushWindow import *
from EditorTileWindow import *
from EditorMapWindow import *
from EditorProjectCreator import *
from EditorData import *
class MapEditorMainWindow(QMainWindow):
def __init__(self) -> None:
super().__init__(None)
self.setObjectName(EUCLID_MAINWINDOW)
self.build()
self.project = None
def build(self):
self.brushWindow = EditorBrushWindow(self)
self.tileWindow = EditorTileWindow(self, labelSize=(50, 64))
self.roomEditor = EditorMapWindow(self)
self.createProjectWindow = ProjectCreatorWindow(self)
self.createProjectWindow.hide()
self.build_menu()
self.setup()
def build_menu(self):
'''构建菜单'''
self.menubar = self.menuBar()
menu_file = self.menubar.addMenu("文件")
action = menu_file.addAction("创建工程")
action.triggered.connect(self.create_project)
def create_project(self):
'''创建一个新的工程'''
if self.project != None and not self.project.hasSaved:
btn = qtutils.question_withcancel(None,"创建工程文件","当前工程未保存,是否保存?")
if btn == QMessageBox.Ok:
pass
elif btn == QMessageBox.Cancel:
return
def _(valid:bool, tilesize:tuple):
'''回调函数'''
if valid:
self.project = ProjectData(tilesize)
self.roomEditor.initproject(self.project)
self.tileWindow.load_project(self.project)
self.createProjectWindow.startup(_)
def setup(self):
'''设置基本参数'''
font = QFont("zpix")
self.setFont(font)
self.setWindowTitle("地图编辑器2.0")
style = f"{read('./Qss/euclid.qss')}\n{read('./Qss/editor.qss')}"
self.setStyleSheet(style)
EuclidWindow.load_layout(self, "./layout.txt")
def keyPressEvent(self, event: QKeyEvent) -> None:
self.roomEditor.receiveKeyEvent(event)
def keyReleaseEvent(self, a0) -> None:
self.roomEditor.receiveKeyReleaseEvent(a0)
def closeEvent(self, evt: QCloseEvent) -> None:
'''退出主窗体的时候记录所有窗体的布局信息'''
if self.project != None and not self.project.hasSaved:
btn = qtutils.question_withcancel(None,"关闭窗体","是否保存当前的工程文件?")
if btn == QMessageBox.Cancel:
evt.ignore()
return
elif btn == QMessageBox.Ok:
print("保存当前的工程文件")
EuclidWindow.save_layout(self, "./layout.txt")
def resizeEvent(self, a0: QResizeEvent) -> None:
self.menubar.resize(self.width(), self.menubar.height())
return super().resizeEvent(a0)
def initProject(self):
'''自动初始化一个新的工程文件'''
self.project = ProjectData()
self.roomEditor.initproject(self.project)
self.tileWindow.load_project(self.project)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
font = QFont("zpix", 9)
font.setStyleStrategy(QFont.NoAntialias)
app.setFont(font)
window = MapEditorMainWindow()
window.show()
sys.exit(app.exec_())