def setTable(self, data, reset=False): name_row, name_column = [], [] self.blockSignals(True) self.setColumnCount(max(map(len, data.values()))) self.setRowCount(len(data.keys())) # - Populate for n, layer in enumerate(sorted(data.keys())): name_row.append(layer) for m, key in enumerate(data[layer].keys()): # -- Build name column name_column.append(key) # -- Selectively add data if m == 0: newitem = QtGui.QTableWidgetItem(str(data[layer][key])) newitem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) newitem.setCheckState(QtCore.Qt.Unchecked) self.setItem(n, m, newitem) if 0 < m < 3: combo = QtGui.QComboBox() if m % 2: combo.setStyleSheet( 'QComboBox { background-color: rgba(255, 0, 0, 15); }' ) else: combo.setStyleSheet( 'QComboBox { background-color: rgba(0, 255, 0, 15); }' ) combo.addItems(data[layer][key]) self.setCellWidget(n, m, combo) if 2 < m < len(data[layer].keys()): spin = QtGui.QDoubleSpinBox() if m <= 6: spin.setSuffix(' u') if m % 2: spin.setStyleSheet( 'QDoubleSpinBox { background-color: rgba(255, 0, 0, 15); }' ) else: spin.setStyleSheet( 'QDoubleSpinBox { background-color: rgba(0, 255, 0, 15); }' ) spin.setMinimum(0.) spin.setMaximum(1000.) if 7 <= m <= 8: spin.setSuffix(' u') if m % 2: spin.setStyleSheet( 'QDoubleSpinBox { background-color: rgba(255, 200, 0, 25); }' ) else: spin.setStyleSheet( 'QDoubleSpinBox { background-color: rgba(255, 200, 0, 25); }' ) spin.setMinimum(0.) spin.setMaximum(1000.) if 9 <= m <= 10: spin.setSuffix(' %') spin.setStyleSheet( 'QDoubleSpinBox { background-color: rgba(0, 0, 255, 15); }' ) spin.setMinimum(0.) spin.setMaximum(500.) if 10 < m: spin.setMinimum(0) spin.setMaximum(1) spin.setSingleStep(0.01) spin.setValue(data[layer][key]) self.setCellWidget(n, m, spin) self.setHorizontalHeaderLabels(name_column) self.setVerticalHeaderLabels(name_row) self.blockSignals(False)
def __init__(self): super(curveEq, self).__init__() # - Basic operations self.btn_tunni = QtGui.QPushButton('&Tunni (Auto)') self.btn_prop = QtGui.QPushButton('Set &Handles') self.btn_prop_30 = QtGui.QPushButton('30%') self.btn_prop_50 = QtGui.QPushButton('50%') self.btn_prop_00 = QtGui.QPushButton('Retract') self.btn_hobby = QtGui.QPushButton('Set &Curvature') self.btn_hobby_get = QtGui.QPushButton('Get') self.btn_hobby_swap = QtGui.QPushButton('Swap') self.btn_hobby_90 = QtGui.QPushButton('.90') self.btn_hobby_80 = QtGui.QPushButton('.80') self.btn_hobby_85 = QtGui.QPushButton('.85') self.spn_hobby0 = QtGui.QDoubleSpinBox() self.spn_hobby1 = QtGui.QDoubleSpinBox() self.spn_hobby0.setValue(0.95) self.spn_hobby1.setValue(0.95) self.spn_hobby0.setSingleStep(0.05) self.spn_hobby1.setSingleStep(0.05) self.spn_prop = QtGui.QDoubleSpinBox() self.spn_prop.setValue(0.30) self.spn_prop.setSingleStep(0.1) self.btn_tunni.setToolTip('Apply Tunni curve optimization') self.btn_hobby.setToolTip('Set Hobby spline curvature') self.btn_hobby_swap.setToolTip('Swap START, END curvatures') self.btn_hobby_get.setToolTip( 'Get curvature for current selected\nsegment at active layer.') self.btn_prop.setToolTip( 'Set handle length in proportion to bezier node distance') self.spn_hobby0.setToolTip('Curvature at the START of Bezier segment.') self.spn_hobby1.setToolTip('Curvature at the END of Bezier segment.') self.spn_prop.setToolTip( 'Handle length in proportion to curve length.') self.btn_tunni.clicked.connect(lambda: self.eqContour('tunni')) self.btn_prop.clicked.connect(lambda: self.eqContour('prop')) self.btn_prop_00.clicked.connect( lambda: self.eqContour('prop_value', value=0)) self.btn_prop_30.clicked.connect( lambda: self.eqContour('prop_value', value=.30)) self.btn_prop_50.clicked.connect( lambda: self.eqContour('prop_value', value=.50)) self.btn_hobby_swap.clicked.connect(self.hobby_swap) self.btn_hobby_get.clicked.connect(self.hobby_get) self.btn_hobby.clicked.connect(lambda: self.eqContour('hobby')) self.btn_hobby_90.clicked.connect( lambda: self.eqContour('hobby_value', value=.90)) self.btn_hobby_80.clicked.connect( lambda: self.eqContour('hobby_value', value=.80)) self.btn_hobby_85.clicked.connect( lambda: self.eqContour('hobby_value', value=.85)) # -- Build: Curve optimization self.addWidget(self.btn_tunni, 0, 0, 1, 6) self.addWidget(QtGui.QLabel('Curve: Handles proportion (BCP length)'), 1, 0, 1, 6) self.addWidget(self.spn_prop, 2, 0, 1, 1) self.addWidget(self.btn_prop, 2, 1, 1, 5) self.addWidget(self.btn_prop_50, 3, 0, 1, 2) self.addWidget(self.btn_prop_00, 3, 2, 1, 2) self.addWidget(self.btn_prop_30, 3, 4, 1, 2) self.addWidget(QtGui.QLabel('Curve: Hobby curvature (Curve tension)'), 4, 0, 1, 6) self.addWidget(self.btn_hobby_get, 5, 0, 1, 2) self.addWidget(self.spn_hobby0, 5, 2, 1, 1) self.addWidget(self.spn_hobby1, 5, 3, 1, 1) self.addWidget(self.btn_hobby_swap, 5, 4, 1, 2) self.addWidget(self.btn_hobby, 6, 0, 1, 6) self.addWidget(self.btn_hobby_90, 7, 0, 1, 2) self.addWidget(self.btn_hobby_85, 7, 2, 1, 2) self.addWidget(self.btn_hobby_80, 7, 4, 1, 2) self.setColumnStretch(0, 1) self.setColumnStretch(4, 0) self.setColumnStretch(5, 0) self.setColumnStretch(6, 0) self.setColumnStretch(7, 0)