Skip to content

Commit b577a24

Browse files
committed
Basic interface created
Everything is ready for start with the functionality
1 parent ea4fcd9 commit b577a24

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed

MatrixButtons.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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]))

Plotting.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ def __init__(self):
4040
self.canvas = FigureCanvas(self.fig) # Get the plot image
4141
self.axes = self.fig.add_subplot(111,projection='3d') # Create matpotlib axes
4242

43-
layout = QtWidgets.QVBoxLayout(self)
44-
layout.addWidget(self.canvas)
43+
self.setWindowTitle('Linear transformations')
44+
45+
self.layout = QtWidgets.QGridLayout(self) # Set the layout
46+
47+
self.addToLayout(self.canvas, [0,0],[10,10]) # add the plot to the layout
4548

4649
def scatter(self,xyzgrid:list,colors:list):
4750
"""Scatter the data
@@ -59,4 +62,9 @@ def scatter(self,xyzgrid:list,colors:list):
5962
colors
6063
"""
6164
self.axes.clear()
62-
self.axes.scatter(xyzgrid[0],xyzgrid[1],xyzgrid[2],c = colors,alpha=0.7)
65+
self.axes.scatter(xyzgrid[0],xyzgrid[1],xyzgrid[2],c = colors,alpha=0.7)
66+
67+
def addToLayout(self, widget, position:list = [0,0], size:list = [1,1]):
68+
"""Add widget to layout
69+
"""
70+
self.layout.addWidget(widget,position[1],position[0],size[1],size[0])

main.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from Plotting import PlotWidget #The plot object
1414

15+
from MatrixButtons import MatrixButtons
16+
1517
def transformPoint(x,y,z):
1618
"""Return the vector transformed
1719
@@ -85,12 +87,17 @@ def adjust_plot(axes):
8587

8688
colors = list(map(colorizer, originalGrid[0], originalGrid[1], originalGrid[2])) # Asign the colors to the points
8789

88-
app = QtWidgets.QApplication([])
89-
plot = PlotWidget()
90+
app = QtWidgets.QApplication([]) # Create the app
91+
plot = PlotWidget() # Get the widget where the plot is
92+
93+
plot.scatter(xyzgrid,colors) # Scatter
94+
95+
adjust_plot(plot.axes) # Set the limits of the axes
9096

91-
plot.scatter(xyzgrid,colors)
97+
interface = MatrixButtons() # Get the interface
98+
plot.addToLayout(interface,[11,4],[10,2]) # add the interface to the plot layout
9299

93-
adjust_plot(plot.axes)
100+
interface.setMatrix(transformationMatrix)
94101

95-
plot.show()
102+
plot.show()
96103
app.exec()

0 commit comments

Comments
 (0)