00001
00002
00003 from python_qt_binding import loadUi, QtGui, QtCore
00004 from python_qt_binding.QtGui import QWidget, QPushButton
00005 from python_qt_binding.QtCore import Signal, Slot
00006
00007
00008 from frame_editor.commands import *
00009
00010 from frame_editor.interface import Interface
00011
00012
00013 class FrameEditor_StyleWidget(Interface):
00014
00015 def __init__(self, frame_editor):
00016 self.editor = frame_editor
00017 self.editor.observers.append(self)
00018
00019 self.old_frame = None
00020
00021 self.layout = QtGui.QGridLayout()
00022 self.widget = QWidget()
00023 self.widget.setLayout(self.layout)
00024
00025 self.mesh_label = QtGui.QLineEdit("File:")
00026 self.mesh_label.setSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Fixed)
00027 self.mesh_button = QtGui.QPushButton("Open")
00028 self.mesh_button.clicked.connect(self.btn_open_mesh_clicked)
00029
00030 self.diameter_label = QtGui.QLabel("Diameter:")
00031 self.diameter_spinbox = QtGui.QDoubleSpinBox()
00032 self.diameter_spinbox.editingFinished.connect(self.diameter_changed)
00033
00034 self.length_label = QtGui.QLabel("Length:")
00035 self.length_spinbox = QtGui.QDoubleSpinBox()
00036 self.length_spinbox.editingFinished.connect(self.length_changed)
00037
00038 self.width_label = QtGui.QLabel("Width:")
00039 self.width_spinbox = QtGui.QDoubleSpinBox()
00040 self.width_spinbox.editingFinished.connect(self.width_changed)
00041
00042 self.height_label = QtGui.QLabel("Height:")
00043 self.height_spinbox = QtGui.QDoubleSpinBox()
00044 self.height_spinbox.editingFinished.connect(self.height_changed)
00045
00046 self.color_label = QtGui.QLabel()
00047 self.color_label.setAutoFillBackground(True)
00048 self.update_color_label(None)
00049 self.color_button = QtGui.QPushButton("Set Color")
00050 self.color_button.clicked.connect(self.btn_color_clicked)
00051
00052 self.layout.addWidget(self.mesh_label, 0, 0)
00053 self.layout.addWidget(self.mesh_button, 0, 1)
00054 self.layout.addWidget(self.diameter_label, 1, 0)
00055 self.layout.addWidget(self.diameter_spinbox, 1, 1)
00056 self.layout.addWidget(self.length_label, 2, 0)
00057 self.layout.addWidget(self.length_spinbox, 2, 1)
00058 self.layout.addWidget(self.width_label, 3, 0)
00059 self.layout.addWidget(self.width_spinbox, 3, 1)
00060 self.layout.addWidget(self.height_label, 4, 0)
00061 self.layout.addWidget(self.height_spinbox, 4, 1)
00062 self.layout.addWidget(self.color_label, 5, 0)
00063 self.layout.addWidget(self.color_button, 5, 1)
00064
00065 self.update_widget(None)
00066
00067
00068 def get_widget(self):
00069 return self.widget
00070
00071 def update(self, editor, level, elements):
00072
00073 if level & 2:
00074
00075 if self.editor.active_frame is not self.old_frame:
00076 self.update_widget(self.editor.active_frame)
00077 self.update_values(self.editor.active_frame)
00078 self.update_color_label(self.editor.active_frame)
00079
00080 elif level & 4:
00081 if self.editor.active_frame is not None:
00082 self.update_values(self.editor.active_frame)
00083 self.update_color_label(self.editor.active_frame)
00084
00085 def update_widget(self, frame):
00086
00087
00088
00089
00090
00091
00092 self.mesh_label.hide()
00093 self.mesh_button.hide()
00094 self.diameter_label.hide()
00095 self.diameter_spinbox.hide()
00096 self.length_label.hide()
00097 self.length_spinbox.hide()
00098 self.width_label.hide()
00099 self.width_spinbox.hide()
00100 self.height_label.hide()
00101 self.height_spinbox.hide()
00102
00103 if frame is None or frame.style == "none":
00104 self.widget.setEnabled(False)
00105 return
00106
00107 if frame.style == "mesh":
00108 self.mesh_label.show()
00109 self.mesh_button.show()
00110 elif frame.style == "sphere":
00111 self.diameter_label.show()
00112 self.diameter_spinbox.show()
00113 else:
00114 self.length_label.show()
00115 self.length_spinbox.show()
00116 self.width_label.show()
00117 self.width_spinbox.show()
00118 if frame.style == "cube":
00119 self.height_label.show()
00120 self.height_spinbox.show()
00121
00122 self.widget.setEnabled(True)
00123
00124 def update_values(self, frame):
00125 if frame is None or frame.style == "none":
00126 return
00127
00128 if frame.style == "mesh":
00129 self.mesh_label.setText(frame.path)
00130 elif frame.style == "sphere":
00131 self.diameter_spinbox.setValue(frame.diameter)
00132 else:
00133 self.length_spinbox.setValue(frame.length)
00134 self.width_spinbox.setValue(frame.width)
00135 if frame.style == "cube":
00136 self.height_spinbox.setValue(frame.height)
00137
00138 def update_color_label(self, frame):
00139 if frame is None:
00140 values = "{}, {}, {}, {}".format(200, 200, 200, 255)
00141 else:
00142 values = "{}, {}, {}, {}".format(frame.color[0]*255, frame.color[1]*255, frame.color[2]*255, frame.color[3]*255)
00143 self.color_label.setStyleSheet("QLabel { background-color: rgba("+values+"); }")
00144
00145 @Slot(float)
00146 def diameter_changed(self):
00147 if self.editor.active_frame.diameter != self.diameter_spinbox.value():
00148 self.editor.command(Command_SetGeometry(self.editor, self.editor.active_frame, "diameter", self.diameter_spinbox.value()))
00149
00150 @Slot(float)
00151 def length_changed(self):
00152 if self.editor.active_frame.length != self.length_spinbox.value():
00153 self.editor.command(Command_SetGeometry(self.editor, self.editor.active_frame, "length", self.length_spinbox.value()))
00154
00155 @Slot(float)
00156 def width_changed(self):
00157 if self.editor.active_frame.width != self.width_spinbox.value():
00158 self.editor.command(Command_SetGeometry(self.editor, self.editor.active_frame, "width", self.width_spinbox.value()))
00159
00160 @Slot(float)
00161 def height_changed(self):
00162 if self.editor.active_frame.height != self.height_spinbox.value():
00163 self.editor.command(Command_SetGeometry(self.editor, self.editor.active_frame, "height", self.height_spinbox.value()))
00164
00165 @Slot()
00166 def btn_open_mesh_clicked(self):
00167 path = QtGui.QFileDialog.getOpenFileName(None, 'Open Mesh', '/home', 'Mesh Files (*.stl *.dae)')[0]
00168 self.editor.command(Command_SetGeometry(self.editor, self.editor.active_frame, "path", path))
00169
00170
00171 @Slot(bool)
00172 def btn_color_clicked(self, checked):
00173 frame = self.editor.active_frame
00174 color = QtGui.QColorDialog.getColor(QtGui.QColor(frame.color[0]*255, frame.color[1]*255, frame.color[2]*255, frame.color[3]*255), None, "Select Color", options=QtGui.QColorDialog.ShowAlphaChannel)
00175 self.editor.command(Command_SetStyleColor(self.editor, frame, color.getRgbF()))
00176
00177