-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathApp.py
222 lines (163 loc) · 6.3 KB
/
MathApp.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
import sys
from pathlib import Path
from PyQt5.QtWidgets import (
QApplication,
QLabel,
QMainWindow,
QPushButton,
QVBoxLayout,
QHBoxLayout,
QWidget,
QGridLayout,
QMenuBar,
QMenu,
QAction,
)
from PyQt5.QtGui import (
QPixmap,
QIcon,
)
from PyQt5 import QtCore
from Circle import *
from Sphere import *
from Ellipse import *
from Ellipsoid import *
from Square import *
from Cube import *
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=5, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
self.axes.set_aspect('equal', adjustable='box')
super(MplCanvas, self).__init__(fig)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self._createActions()
self._createMenuBar()
self.window1 = WindowCircle()
self.window2 = WindowSphere()
self.window3 = WindowEllipse()
self.window4 = WindowEllipsoid()
self.window5 = WindowSquare()
self.window6 = WindowCube()
self.setWindowTitle('PyQt Math App')
self.setMinimumWidth(500)
self.setMinimumHeight(500)
self.setMaximumWidth(500)
self.setMaximumHeight(500)
buttonClose = QPushButton('Close')
buttonClose.clicked.connect(app.closeAllWindows)
l = QHBoxLayout()
l.addStretch(1)
l.addWidget(buttonClose)
l2 = QVBoxLayout()
l3 = QGridLayout()
l2.addLayout(l3)
self.label = QLabel(self)
self.pixmap = QPixmap('Shapes.png')
self.setWindowIcon(QIcon('Shape_ico.png'))
self.label.setPixmap(self.pixmap)
self.label.setAlignment(QtCore.Qt.AlignCenter)
l3.addWidget(self.label,0,0,1,2)
button1 = QPushButton("Circle")
# button1.setStyleSheet('background-color: rgb(128, 0, 32);\ncolor: rgb(255, 255, 255);')
button1.clicked.connect(
lambda checked: self.toggle_window(self.window1)
)
l3.addWidget(button1,1,0)
button2 = QPushButton("Sphere")
# button2.setStyleSheet('background-color: rgb(128, 0, 32);\ncolor: rgb(255, 255, 255);')
button2.clicked.connect(
lambda checked: self.toggle_window(self.window2)
)
l3.addWidget(button2,1,1)
button3 = QPushButton("Ellipse")
# button3.setStyleSheet('background-color: rgb(128, 0, 32);\ncolor: rgb(255, 255, 255);')
button3.clicked.connect(
lambda checked: self.toggle_window(self.window3)
)
l3.addWidget(button3,2,0)
button4 = QPushButton("Ellipsoid")
# button4.setStyleSheet('background-color: rgb(128, 0, 32);\ncolor: rgb(255, 255, 255);')
button4.clicked.connect(
lambda checked: self.toggle_window(self.window4)
)
l3.addWidget(button4,2,1)
button5 = QPushButton("Square")
# button5.setStyleSheet('background-color: rgb(128, 0, 32);\ncolor: rgb(255, 255, 255);')
button5.clicked.connect(
lambda checked: self.toggle_window(self.window5)
)
l3.addWidget(button5,3,0)
button6 = QPushButton("Cube")
# button6.setStyleSheet('background-color: rgb(128, 0, 32);\ncolor: rgb(255, 255, 255);')
button6.clicked.connect(
lambda checked: self.toggle_window(self.window6)
)
l3.addWidget(button6,3,1)
l2.addLayout(l)
w = QWidget()
w.setLayout(l2)
self.setCentralWidget(w)
def toggle_window(self, window):
if window.isVisible():
window.hide()
else:
window.show()
def _createActions(self):
# Creating action using the first constructor
self.closeAction = QAction(self)
self.closeAction.setText("&Close")
self.closeAction.triggered.connect(app.closeAllWindows)
self.closeAction.setShortcut("Ctrl+W")
self.circleAction = QAction(self)
self.circleAction.setText("&Circle")
self.circleAction.triggered.connect(lambda checked: self.toggle_window(self.window1))
self.circleAction.setShortcut("Ctrl+1")
self.sphereAction = QAction(self)
self.sphereAction.setText("&Sphere")
self.sphereAction.triggered.connect(lambda checked: self.toggle_window(self.window2))
self.sphereAction.setShortcut("Ctrl+2")
self.ellipseAction = QAction(self)
self.ellipseAction.setText("&Ellipse")
self.ellipseAction.triggered.connect(lambda checked: self.toggle_window(self.window3))
self.ellipseAction.setShortcut("Ctrl+3")
self.ellipsoidAction = QAction(self)
self.ellipsoidAction.setText("&Ellipsoid")
self.ellipsoidAction.triggered.connect(lambda checked: self.toggle_window(self.window4))
self.ellipsoidAction.setShortcut("Ctrl+4")
self.squareAction = QAction(self)
self.squareAction.setText("&Square")
self.squareAction.triggered.connect(lambda checked: self.toggle_window(self.window5))
self.squareAction.setShortcut("Ctrl+5")
self.cubeAction = QAction(self)
self.cubeAction.setText("&Cube")
self.cubeAction.triggered.connect(lambda checked: self.toggle_window(self.window6))
self.cubeAction.setShortcut("Ctrl+6")
def _createMenuBar(self):
menuBar = QMenuBar(self)
self.setMenuBar(menuBar)
# Creating menus using a QMenu object
fileMenu = QMenu("&File", self)
menuBar.addMenu(fileMenu)
fileMenu.addAction(self.closeAction)
# Creating menus using a title
geometryMenu = menuBar.addMenu("&Geometry")
menuBar.addMenu(geometryMenu)
geometryMenu.addAction(self.circleAction)
geometryMenu.addAction(self.sphereAction)
geometryMenu.addAction(self.ellipseAction)
geometryMenu.addAction(self.ellipsoidAction)
geometryMenu.addAction(self.squareAction)
geometryMenu.addAction(self.cubeAction)
helpMenu = menuBar.addMenu("&Help")
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.setStyleSheet(Path('style.qss').read_text())
app.exec()