-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasy_gui.py
More file actions
72 lines (48 loc) · 2.13 KB
/
easy_gui.py
File metadata and controls
72 lines (48 loc) · 2.13 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
from PyQt5 import QtWidgets, QtGui
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
class MplWidget(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
super(MplWidget, self).__init__(fig)
# --------------------------------------
class EasyPlotGUI(QtWidgets.QMainWindow):
"""Easy GUI with Matplotlib
"""
def __init__(self, ui_python_file):
self.app = QtWidgets.QApplication([])
self.window_title="EasyPlotGUI"
self.icon_path=None
self.ui=ui_python_file.Ui_MainWindow()
super().__init__()
self.ui.setupUi(self)
def show_gui(self):
"""Shows the GUI.
"""
try:
self.ax=self.ui.MplWidget.axes
self.draw=self.ui.MplWidget.draw
self.update_graph()
except AttributeError:
pass
self.update_interactivity()
self.setWindowTitle(self.window_title)
if self.icon_path!=None:
self.setWindowIcon(QtGui.QIcon(self.icon_path))
self.show() # Show a window
self.app.exec_()
def update_interactivity(self):
"""This method adds the interactivity between the GUI elements and the code. An example of execution can be seen below. This method is supposed to be overwritten when EasyGUI is imported as a parent class for adding your own graphs.
Check interactivity functions on PySide2 doc.
"""
# example, to be overwritten
self.ui.pushButton_generate_random_signal.clicked.connect(self.update_graph)
def update_graph(self):
"""This method generates and updates the graph. An example of execution can be seen below. This method is supposed to be overwritten when EasyGUI is imported as a parent class for adding your own graphs.
"""
# example, to be overwritten
self.draw()