1+ import PyQt5 .QtWidgets as QtWidgets
2+ from matplotlib .figure import Figure
3+ from matplotlib .backends .backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
4+
5+ class MatrixButtons (QtWidgets .QWidget ):
6+ """Widget for PyQt5 with the Matrix input and the buttons
7+
8+ ...
9+
10+ Attributes
11+ ----------
12+ layout: QtWidgets.QGridLayout
13+ """
14+ def __init__ (self ):
15+ super ().__init__ ()
16+ self .layout = QtWidgets .QGridLayout (self ) # Set the layout
17+
18+ # First row
19+ self .matrix00 = QtWidgets .QLineEdit ()
20+ self .matrix10 = QtWidgets .QLineEdit ()
21+ self .matrix20 = QtWidgets .QLineEdit ()
22+ self .addToLayout (self .matrix00 ,[0 ,0 ],[1 ,1 ])
23+ self .addToLayout (self .matrix10 ,[1 ,0 ],[1 ,1 ])
24+ self .addToLayout (self .matrix20 ,[2 ,0 ],[1 ,1 ])
25+
26+ # Second row
27+ self .matrix01 = QtWidgets .QLineEdit ()
28+ self .matrix11 = QtWidgets .QLineEdit ()
29+ self .matrix21 = QtWidgets .QLineEdit ()
30+ self .addToLayout (self .matrix01 ,[0 ,1 ],[1 ,1 ])
31+ self .addToLayout (self .matrix11 ,[1 ,1 ],[1 ,1 ])
32+ self .addToLayout (self .matrix21 ,[2 ,1 ],[1 ,1 ])
33+
34+ # Third row
35+ self .matrix02 = QtWidgets .QLineEdit ()
36+ self .matrix12 = QtWidgets .QLineEdit ()
37+ self .matrix22 = QtWidgets .QLineEdit ()
38+ self .addToLayout (self .matrix02 ,[0 ,2 ],[1 ,1 ])
39+ self .addToLayout (self .matrix12 ,[1 ,2 ],[1 ,1 ])
40+ self .addToLayout (self .matrix22 ,[2 ,2 ],[1 ,1 ])
41+
42+ # Button for plot the grid transformed by the matrix
43+ plotButton = QtWidgets .QPushButton ('Plot' )
44+ self .addToLayout (plotButton ,[1 ,3 ],[1 ,1 ])
45+
46+
47+ def addToLayout (self , widget , position :list , size :list ):
48+ self .layout .addWidget (widget ,position [1 ],position [0 ],size [1 ],size [0 ])
49+
50+ def setMatrix (self ,matrix ):
51+ """Add widget to layout
52+ """
53+ # First row
54+ self .matrix00 .setText (str (matrix [0 ,0 ]))
55+ self .matrix10 .setText (str (matrix [0 ,1 ]))
56+ self .matrix20 .setText (str (matrix [0 ,2 ]))
57+
58+ # Second row
59+ self .matrix01 .setText (str (matrix [1 ,0 ]))
60+ self .matrix11 .setText (str (matrix [1 ,1 ]))
61+ self .matrix21 .setText (str (matrix [1 ,2 ]))
62+
63+ # Third row
64+ self .matrix02 .setText (str (matrix [2 ,0 ]))
65+ self .matrix12 .setText (str (matrix [2 ,1 ]))
66+ self .matrix22 .setText (str (matrix [2 ,2 ]))
0 commit comments