3 from python_qt_binding
import QtWidgets, QtCore
4 from python_qt_binding.QtWidgets
import QWidget, QPushButton, QColorDialog
5 from python_qt_binding.QtCore
import Slot
6 from python_qt_binding.QtGui
import QColor
18 self.editor.observers.append(self)
22 self.
layout = QtWidgets.QGridLayout()
24 self.widget.setLayout(self.
layout)
27 self.mesh_label.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Fixed)
33 self.diameter_spinbox.editingFinished.connect(
lambda: self.
diameter_changed())
37 self.length_spinbox.editingFinished.connect(
lambda: self.
length_changed())
41 self.width_spinbox.editingFinished.connect(
lambda: self.
width_changed())
45 self.height_spinbox.editingFinished.connect(
lambda: self.
height_changed())
48 self.color_label.setAutoFillBackground(
True)
72 def update(self, editor, level, elements):
76 if self.editor.active_frame
is not self.
old_frame:
82 if self.editor.active_frame
is not None:
92 self.mesh_label.hide()
93 self.mesh_button.hide()
94 self.diameter_label.hide()
95 self.diameter_spinbox.hide()
96 self.length_label.hide()
97 self.length_spinbox.hide()
98 self.width_label.hide()
99 self.width_spinbox.hide()
100 self.height_label.hide()
101 self.height_spinbox.hide()
103 if frame
is None or frame.style ==
"none":
104 self.widget.setEnabled(
False)
107 if frame.style ==
"mesh":
108 self.mesh_label.show()
109 self.mesh_button.show()
110 elif frame.style ==
"sphere":
111 self.diameter_label.show()
112 self.diameter_spinbox.show()
114 self.length_label.show()
115 self.length_spinbox.show()
116 self.width_label.show()
117 self.width_spinbox.show()
118 if frame.style ==
"cube":
119 self.height_label.show()
120 self.height_spinbox.show()
122 self.widget.setEnabled(
True)
125 if frame
is None or frame.style ==
"none":
128 if frame.style ==
"mesh":
129 self.mesh_label.setText(frame.path)
130 elif frame.style ==
"sphere":
131 self.diameter_spinbox.setValue(frame.diameter)
133 self.length_spinbox.setValue(frame.length)
134 self.width_spinbox.setValue(frame.width)
135 if frame.style ==
"cube":
136 self.height_spinbox.setValue(frame.height)
140 values =
"{}, {}, {}, {}".format(200, 200, 200, 255)
142 values =
"{}, {}, {}, {}".format(frame.color[0]*255, frame.color[1]*255, frame.color[2]*255, frame.color[3]*255)
143 self.color_label.setStyleSheet(
"QLabel { background-color: rgba("+values+
"); }")
147 if self.editor.active_frame.diameter != self.diameter_spinbox.value():
148 self.editor.command(
Command_SetGeometry(self.
editor, self.editor.active_frame,
"diameter", self.diameter_spinbox.value()))
152 if self.editor.active_frame.length != self.length_spinbox.value():
157 if self.editor.active_frame.width != self.width_spinbox.value():
162 if self.editor.active_frame.height != self.height_spinbox.value():
167 path = QtWidgets.QFileDialog.getOpenFileName(
None,
'Open Mesh',
'/home',
'Mesh Files (*.stl)')[0]
169 rospackage = rospkg.get_package_name(path)
170 if rospackage
is None:
171 QtWidgets.QMessageBox.warning(self.
widget,
"Saving absolute path to mesh",
172 "Cannot find rospackage with selected mesh in it!\nSaving absolute path to mesh instead!")
177 rel_path = os.path.relpath(path , rospkg.RosPack().get_path(rospackage))
178 print(
"Saving: package: {} + relative path: {}".format(rospackage, rel_path))
182 QtWidgets.QMessageBox.warning(self.
widget,
"Saving absolute path to mesh",
183 "The found rospackage with selected mesh in it is not sourced in your ROS workspace!\n"+
184 "Cannot resolve the packagepath\nSaving absolute path to mesh instead!")
191 frame = self.editor.active_frame
192 color = QtWidgets.QColorDialog.getColor(
193 QColor(frame.color[0]*255,
199 options=QtWidgets.QColorDialog.ShowAlphaChannel)