-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
160 lines (121 loc) · 5.58 KB
/
GUI.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
# Importing modules from the Python Standard Library.
import sys
import math
# Importing third-party modules.
import numpy as np
# Importing Matplot's Python Library.
import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
# Importing PyQt5.
from PyQt5 import QtCore, QtWidgets, QtGui
class MainWindow(QtWidgets.QMainWindow):
""""The MainWindow class inherits from the QMainWindow. It acts as a container for the MainWindow class
(QWidget) while also setting the window title and creating the statusbar."""
def __init__(self):
super().__init__()
# Setting the window title, icon, and assigning the MainWindow class as the central widget.
self.setWindowTitle("Quanta")
self.setWindowIcon(QtGui.QIcon("Icon.png"))
# Creating instances of the tabs within the QMainWindow class.
self.ViewTab = ViewTab()
self.ConsoleTab = ConsoleTab()
self.ParametersTab = ParametersTab()
# Creating the QTabWidget and adding the instances of the tabs to it.
Tabs = QtWidgets.QTabWidget()
Tabs.addTab(self.ViewTab, "View")
Tabs.addTab(self.ConsoleTab, "Console")
Tabs.addTab(self.ParametersTab, "Parameters")
self.setCentralWidget(Tabs)
# Creating the Statusbar.
StatusBar = self.statusBar()
StatusBar.showMessage('Ready')
# Creating the toolbar.
self.Toolbar = self.addToolBar("Toolbar")
self.Toolbar.setMovable(False)
# Creating the progressbar.
self.ProgressBar = QtWidgets.QProgressBar(self)
# Creating buttons.
self.UpdateView = QtWidgets.QAction("Update View", self)
# Adding widgets and buttons(actions) to the toolbar.
self.Toolbar.addAction(self.UpdateView)
self.Toolbar.addWidget(self.ProgressBar)
# Buttons are connected to their respective handlers.
self.UpdateView.triggered.connect(MainWindow.UpdateView_handler)
# Displaying the Graphical User Interface.
self.show()
def UpdateView_handler():
# Console output.
print("Event: UpdateView_handler")
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
figure = Figure(figsize=(width, height), dpi=dpi)
self.axes = figure.gca(projection='3d')
super(MplCanvas, self).__init__(figure)
class ViewTab(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.length_x = 1
self.length_y = 1
self.quantum_number_x = 3
self.quantum_number_y = 2
"""Generating x-coordinates."""
x = np.linspace(0, self.length_x, 100)
"""Generating y-coordinates."""
y = np.linspace(0, self.length_y, 100)
"""Generating all possible xy-coordinates."""
X,Y = np.meshgrid(x,y)
"""Generating z-coordinates from xy-coordinates."""
Z = np.sqrt((2)/(self.length_x*self.length_y))*np.sin((math.pi*self.quantum_number_x*X)/(self.length_x))*np.sin((math.pi*self.quantum_number_y*Y)/(self.length_y))
plt = MplCanvas(self, width=5, height=4, dpi=100)
contour = plt.axes.plot_surface(X,Y,Z,cmap='hot')
plt.figure.colorbar(contour, shrink = 1)
plt.axes.view_init(elev = 20, azim = -135)
plt.axes.set_xlabel(r'$x$')
plt.axes.set_ylabel(r'$y$')
plt.axes.set_zlabel(r'$\psi(x, y)$')
Layout = QtWidgets.QVBoxLayout()
Layout.addWidget(plt)
self.setLayout(Layout)
class ConsoleTab(QtWidgets.QWidget):
def __init__(self):
super().__init__()
# Creating the Console(QTextBrowser class) within the ConsoleTab(QTabWidget class).
self.Textbox = QtWidgets.QTextBrowser(self)
self.Textbox.setReadOnly(True)
self.Textbox.setOpenExternalLinks(True)
# Adding the Console(QTextBrowser class) to the layout ConsoleTab(QTabWidget class)..
Layout = QtWidgets.QVBoxLayout()
Layout.addWidget(self.Textbox)
self.setLayout(Layout)
# Printing starting text.
self.Textbox.insertPlainText("===========================")
self.Textbox.insertPlainText("\n")
self.Textbox.insertHtml("<b> Quanta Version: 0.0.1 </b>")
self.Textbox.insertPlainText("\n")
self.Textbox.insertHtml("<b> Created by Prithvi R. </b>")
self.Textbox.insertPlainText("\n")
self.Textbox.insertPlainText("======================")
class ParametersTab(QtWidgets.QWidget):
def __init__(self):
super().__init__()
GridLayout = QtWidgets.QGridLayout()
self.setLayout(GridLayout)
Group = QtWidgets.QGroupBox("Quantum System")
self.QuantumSystem = QtWidgets.QComboBox(self)
self.QuantumSystem.resize(200, 25)
self.QuantumSystem.addItem("Particle in a Box (2D)")
GridLayout.addWidget(Group)
self.QuantumFunction = QtWidgets.QComboBox(self)
self.QuantumFunction.resize(200, 25)
self.QuantumFunction.addItem("Wavefunction")
self.QuantumFunction.addItem("Probability Density Function")
GridLayout.addWidget(Group)
GroupLayout = QtWidgets.QVBoxLayout()
GroupLayout.addWidget(self.QuantumSystem)
GroupLayout.addWidget(self.QuantumFunction)
Group.setLayout(GroupLayout)
if __name__ == "__main__":
application = QtWidgets.QApplication(sys.argv)
GUI = MainWindow()
application.exec_()