-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window.py
205 lines (177 loc) · 6.42 KB
/
Window.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
from PyQt5.QtWidgets import QMainWindow, QDesktopWidget, QApplication, QAction, QFileDialog, QMessageBox
from PyQt5.QtCore import Qt
from Settings import *
from ShowPanel import ShowPanel
from StatusPanel import StatusPanel
from ControlPanel import ControlPanel
from PyFractal.Fractal import Fractal
import sys
class Window(QMainWindow):
menubar = None
miUndo = None
show_panel = None
status_panel = None
ctrl_panel = None
def __init__(self):
super().__init__()
self.initUI()
Window.status_panel = StatusPanel(self)
Window.ctrl_panel = ControlPanel(self)
Window.show_panel = ShowPanel(self)
self.show()
def initUI(self):
self.setFixedWidth(DEFAULT_WIDTH)
self.setFixedHeight(DEFAULT_HEIGHT)
self.setMouseTracking(True)
self.center()
self.build_menu()
self.setWindowTitle(APP_TITLE)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def build_menu(self):
Window.menubar = self.menuBar()
mnFile = Window.menubar.addMenu(MN_SAVE)
miCopy = QAction(MNI_COPY, self)
miSave = QAction(MNI_SAVE, self)
miExit = QAction(MNI_EXIT, self)
mnFile.addAction(miCopy)
mnFile.addAction(miSave)
mnFile.addSeparator()
mnFile.addAction(miExit)
mnOption = Window.menubar.addMenu(MN_OPTION)
Window.miUndo = QAction(MNI_UNDO, self)
Window.miUndo.setEnabled(False)
miView1 = QAction(MNI_SET_VIEW1, self)
miView2 = QAction(MNI_SET_VIEW2, self)
miView3 = QAction(MNI_SET_VIEW3, self)
miView4 = QAction(MNI_SET_VIEW4, self)
miView5 = QAction(MNI_SET_VIEW5, self)
miView6 = QAction(MNI_SET_VIEW6, self)
miFixScaling = QAction(MNI_FIX_SCALING, self, checkable=True)
miFixScaling.setChecked(False)
miOptimizeGraph = QAction(MNI_OPT_GRAPH, self, checkable=True)
miOptimizeGraph.setChecked(False)
mnOption.addAction(Window.miUndo)
mnOption.addSeparator()
mnOption.addAction(miView1)
mnOption.addAction(miView2)
mnOption.addAction(miView3)
mnOption.addAction(miView4)
mnOption.addAction(miView5)
mnOption.addAction(miView6)
mnOption.addSeparator()
mnOption.addAction(miFixScaling)
mnOption.addAction(miOptimizeGraph)
mnAbout = Window.menubar.addMenu(MN_ABOUT)
miHelp = QAction(MNI_HELP, self)
miInfo = QAction(MNI_INFO, self)
mnAbout.addAction(miHelp)
mnAbout.addSeparator()
mnAbout.addAction(miInfo)
# Shortcuts
miCopy.setShortcut(COPY_SC)
miSave.setShortcut(SAVE_SC)
miExit.setShortcut(EXIT_SC)
Window.miUndo.setShortcut(UNDO_SC)
# Action Trigger
miCopy.triggered.connect(self.copy_image)
miSave.triggered.connect(self.save_image)
miExit.triggered.connect(QApplication.instance().quit)
Window.miUndo.triggered.connect(self.undo_view)
miView1.triggered.connect(self.set_view1)
miView2.triggered.connect(self.set_view2)
miView3.triggered.connect(self.set_view3)
miView4.triggered.connect(self.set_view4)
miView5.triggered.connect(self.set_view5)
miView6.triggered.connect(self.set_view6)
miFixScaling.triggered.connect(self.fix_scaling)
miOptimizeGraph.triggered.connect(self.optimize_graph)
miHelp.triggered.connect(self.show_help)
miInfo.triggered.connect(self.show_info)
def keyPressEvent(self, e):
if e.modifiers() & Qt.ControlModifier:
ShowPanel.set_press_ctrl(True)
if e.modifiers() & Qt.ShiftModifier:
ShowPanel.set_press_shift(True)
if e.modifiers() & Qt.AltModifier:
ShowPanel.set_press_alt(True)
e.ignore()
def keyReleaseEvent(self, e):
modifiers = QApplication.keyboardModifiers()
if modifiers & Qt.ControlModifier:
ShowPanel.set_press_ctrl(False)
if modifiers & Qt.ShiftModifier:
ShowPanel.set_press_shift(False)
if modifiers & Qt.AltModifier:
ShowPanel.set_press_alt(False)
e.ignore()
@staticmethod
def copy_image():
QApplication.clipboard().setPixmap(ShowPanel.picbox.pixmap())
def save_image(self):
path, _ = QFileDialog.getSaveFileName(self, "Save file", "",
"PNG Image file (*.png)")
if path:
pixmap = ShowPanel.picbox.pixmap()
pixmap.save(path, "PNG")
def undo_view(self):
if Fractal.is_working:
return
Window.show_panel.undo_view()
def set_view1(self):
if Fractal.is_working:
return
self.set_exp(EXP_VIEW1)
ControlPanel.txt_exp.setText(EXP_VIEW1)
def set_view2(self):
if Fractal.is_working:
return
self.set_exp(EXP_VIEW2)
ControlPanel.txt_exp.setText(EXP_VIEW2)
def set_view3(self):
if Fractal.is_working:
return
self.set_exp(EXP_VIEW3)
ControlPanel.txt_exp.setText(EXP_VIEW3)
def set_view4(self):
if Fractal.is_working:
return
self.set_exp(EXP_VIEW4)
ControlPanel.txt_exp.setText(EXP_VIEW4)
def set_view5(self):
if Fractal.is_working:
return
self.set_exp(EXP_VIEW5)
ControlPanel.txt_exp.setText(EXP_VIEW5)
def set_view6(self):
if Fractal.is_working:
return
self.set_exp(EXP_VIEW6)
ControlPanel.txt_exp.setText(EXP_VIEW6)
def fix_scaling(self, state):
ShowPanel.alwaysFixScale = state
def optimize_graph(self, state):
ShowPanel.boost = state
def show_help(self):
QMessageBox.about(self, HELP_TITLE, HELP_DIALOG)
def show_info(self):
QMessageBox.about(self, INFO_TITLE, INFO_DIALOG)
@staticmethod
def set_undo_enabled(status):
if Window.menubar is not None:
Window.miUndo.setEnabled(status)
@staticmethod
def set_exp(exp):
if Fractal.is_working:
return
Window.show_panel.set_new_view(exp)
@staticmethod
def update_pic(pic):
Window.show_panel.picbox.setPixmap(pic)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Window()
sys.exit(app.exec_())