-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMatrixButtons.py
67 lines (55 loc) · 2.27 KB
/
MatrixButtons.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
import PyQt5.QtWidgets as QtWidgets
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from sympy import Matrix
class MatrixButtons(QtWidgets.QWidget):
"""Widget for PyQt5 with the Matrix input and the buttons
...
Attributes
----------
layout: QtWidgets.QGridLayout
"""
def __init__(self):
super().__init__()
self.layout = QtWidgets.QGridLayout(self) # Set the layout
#First row
self.matrix00 = QtWidgets.QLineEdit()
self.matrix10 = QtWidgets.QLineEdit()
self.matrix20 = QtWidgets.QLineEdit()
self.addToLayout(self.matrix00,[0,0],[1,1])
self.addToLayout(self.matrix10,[1,0],[1,1])
self.addToLayout(self.matrix20,[2,0],[1,1])
# Second row
self.matrix01 = QtWidgets.QLineEdit()
self.matrix11 = QtWidgets.QLineEdit()
self.matrix21 = QtWidgets.QLineEdit()
self.addToLayout(self.matrix01,[0,1],[1,1])
self.addToLayout(self.matrix11,[1,1],[1,1])
self.addToLayout(self.matrix21,[2,1],[1,1])
# Third row
self.matrix02 = QtWidgets.QLineEdit()
self.matrix12 = QtWidgets.QLineEdit()
self.matrix22 = QtWidgets.QLineEdit()
self.addToLayout(self.matrix02,[0,2],[1,1])
self.addToLayout(self.matrix12,[1,2],[1,1])
self.addToLayout(self.matrix22,[2,2],[1,1])
# Button for plot the grid transformed by the matrix
self.plotButton = QtWidgets.QPushButton('Plot')
self.addToLayout(self.plotButton,[1,3],[1,1])
def addToLayout(self, widget, position:list, size:list):
self.layout.addWidget(widget,position[1],position[0],size[1],size[0])
def setMatrix(self,matrix):
"""Add widget to layout
"""
# First row
self.matrix00.setText(str(matrix[0,0]))
self.matrix10.setText(str(matrix[0,1]))
self.matrix20.setText(str(matrix[0,2]))
# Second row
self.matrix01.setText(str(matrix[1,0]))
self.matrix11.setText(str(matrix[1,1]))
self.matrix21.setText(str(matrix[1,2]))
# Third row
self.matrix02.setText(str(matrix[2,0]))
self.matrix12.setText(str(matrix[2,1]))
self.matrix22.setText(str(matrix[2,2]))