Skip to content

Commit

Permalink
restructuring gui files
Browse files Browse the repository at this point in the history
  • Loading branch information
akchobby committed Mar 8, 2022
1 parent da79e97 commit 32c0057
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 62 deletions.
3 changes: 2 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires =[
"setuptools>=42",
"wheel",
"numpy",
"matplotlib"
"matplotlib",
"pyQt5"
]
build-backend="setuptools.build_meta"
34 changes: 34 additions & 0 deletions python/src/transforms_package/gui/mainWindow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from PyQt5 import QtWidgets,QtCore
from gui.toplayout import TopLayout

class Widget(QtWidgets.QDialog):
def __init__(self):
super().__init__()


mainLayout = QtWidgets.QGridLayout()

# bottom layout
self.bottomLayout = QtWidgets.QGroupBox()
self.createBottomLayout()

# top layout
self.topLayout = TopLayout(self.txt)
self.topLayout.create()


mainLayout.addWidget(self.topLayout, 0, 0)
mainLayout.addWidget(self.topLayout.canvas, 1,0)
mainLayout.addWidget(self.bottomLayout, 2,0)

self.setLayout(mainLayout)
self.setWindowTitle('Rotation Viewer')

def createBottomLayout(self):
bLayout = QtWidgets.QVBoxLayout()

self.txt = QtWidgets.QTextBrowser(self.bottomLayout)
self.txt.setGeometry(QtCore.QRect())
self.txt.setObjectName("Params")
bLayout.addWidget(self.txt, 0)
self.bottomLayout.setLayout(bLayout)
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5 import QtWidgets, QtGui
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
import numpy as np
from quaternion import *

class Widget(QtWidgets.QDialog):
def __init__(self, data):

class TopLayout(QtWidgets.QGroupBox):

def __init__(self, textBox):

super().__init__()
fig = Figure()
self.fig = fig
self.canvas = FigureCanvas(self.fig)
self.axes = self.fig.add_subplot(111, projection='3d', azim=170, elev=20)

mainLayout = QtWidgets.QGridLayout()
self.txt = textBox

layout = QtWidgets.QVBoxLayout()
labels = self._createLabels()
layout.addWidget(labels[0],0)
layout.addLayout(self._createRotationLayout(),1)
layout.addWidget(labels[1],2)
layout.addLayout(self._createQuaternionLayout(),3)
layout.addWidget(labels[2],4)
layout.addLayout(self._createEulerLayout(),5)
self.setLayout(layout)

# top layout
self.topLayout = QtWidgets.QGroupBox()
self.createTopLayout()
for box in self.quat_spinboxes:
box.valueChanged.connect(self.quat_update)

Expand All @@ -32,37 +36,35 @@ def __init__(self, data):

for box in self.euler_spinboxes:
box.valueChanged.connect(self.euler_update)

# Mid layout declaring here for ease of access
fig = Figure()
self.fig = fig
self.canvas = FigureCanvas(self.fig)
self.axes = self.fig.add_subplot(111, projection='3d', azim=170, elev=20)



# bottom layout
self.bottomLayout = QtWidgets.QGroupBox()
self.createBottomLayout()



mainLayout.addWidget(self.topLayout,0, 0)
mainLayout.addWidget(self.canvas,1,0)
mainLayout.addWidget(self.bottomLayout, 2,0)

self.setLayout(mainLayout)
self.setWindowTitle('Rotation Viewer')

def createTopLayout(self):
layout = QtWidgets.QVBoxLayout()
def _createRotationLayout(self):
# Rotation
rotation_layout = QtWidgets.QGridLayout()
self.rotation_spinboxes = [[ QtWidgets.QDoubleSpinBox(self.topLayout) for i in range(0,3)] for i in range(0,3)]
self.rotation_spinboxes = [[ QtWidgets.QDoubleSpinBox(self) for i in range(0,3)] for i in range(0,3)]

for i, row in enumerate(self.rotation_spinboxes):
for j, box in enumerate(row):
box.setMinimum(-1.175494e+38)
box.setMaximum(1.175494e+38)
rotation_layout.addWidget(box, i, j)

return rotation_layout


def _createQuaternionLayout(self):
# Quaternion
quat_layout = QtWidgets.QGridLayout()
label_width = 15
labels = ["x:","y:","z:","w:"]
self.quat_spinboxes = [QtWidgets.QDoubleSpinBox(self.topLayout) for i in labels]
self.quat_spinboxes = [QtWidgets.QDoubleSpinBox(self) for i in labels]
q_labels = [QtWidgets.QLabel(label) for label in labels]
j = 0

Expand All @@ -82,8 +84,13 @@ def createTopLayout(self):

quat_layout.setHorizontalSpacing(18)

return quat_layout

def _createEulerLayout(self):
# euler
euler_layout = QtWidgets.QGridLayout()
labels = ["x:","y:","z:","w:"]
label_width = 15

self.deg =True
self.units = [QtWidgets.QRadioButton("deg"), QtWidgets.QRadioButton("radians")]
Expand All @@ -95,7 +102,7 @@ def createTopLayout(self):
for i,unit_box in enumerate(self.units):
euler_layout.addWidget(unit_box, 0 , i)

self.euler_spinboxes = [QtWidgets.QDoubleSpinBox(self.topLayout) for i in labels[:-1]]
self.euler_spinboxes = [QtWidgets.QDoubleSpinBox(self) for i in labels[:-1]]
euler_labels = [QtWidgets.QLabel(label) for label in labels[:-1]]
j = 0

Expand All @@ -112,8 +119,11 @@ def createTopLayout(self):
j += 1


euler_layout.setHorizontalSpacing(18)
euler_layout.setHorizontalSpacing(18)

return euler_layout

def _createLabels(self):
rotation_label = QtWidgets.QLabel("Rotation Matrix :")
quat_label = QtWidgets.QLabel("Quaternion :")
euler_label = QtWidgets.QLabel("Euler ZYX:")
Expand All @@ -124,24 +134,8 @@ def createTopLayout(self):
quat_label.setFont(bold_font)
euler_label.setFont(bold_font)

layout.addWidget(rotation_label,0)
layout.addLayout(rotation_layout,1)
layout.addWidget(quat_label,2)
layout.addLayout(quat_layout,3)
layout.addWidget(euler_label,4)
layout.addLayout(euler_layout,5)
self.topLayout.setLayout(layout)
return rotation_label,quat_label, euler_label

def createBottomLayout(self):
bLayout = QtWidgets.QVBoxLayout()

self.txt = QtWidgets.QTextBrowser(self.bottomLayout)
# self.txt.setGeometry(QtCore.QRect(10, 90, 331, 111))
self.txt.setGeometry(QtCore.QRect())
self.txt.setObjectName("Params")
bLayout.addWidget(self.txt, 0)
self.bottomLayout.setLayout(bLayout)

def quat_update(self):
try:
print("[INFO] quaternion update")
Expand Down Expand Up @@ -237,17 +231,7 @@ def euler_update(self):
def unit_update(self):
button = self.sender()
self.deg = (button.unit == "deg" and button.isChecked() )







if __name__ == "__main__":
app = QtWidgets.QApplication([])
q1 = Quaternion( [0.5, 0.5,0.5,0.5] )
print(q1.to_rotation_matrix())
t1 = [-1.6602861245985938, 0.0,1.732975221562235]

win = Widget([q1,t1])
win.show()
app.exec()
8 changes: 8 additions & 0 deletions python/src/transforms_package/run_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from gui.mainWindow import Widget
from PyQt5 import QtWidgets

if __name__ == "__main__":
app = QtWidgets.QApplication([])
win = Widget()
win.show()
app.exec()

0 comments on commit 32c0057

Please sign in to comment.