def _initCropListView(self): if self.topLevelOperatorView.Crops.value != {}: self._cropControlUi.cropListModel = CropListModel() crops = self.topLevelOperatorView.Crops.value for key in sorted(crops): newRow = self._cropControlUi.cropListModel.rowCount() crop = Crop( key, [(crops[key]["time"][0], crops[key]["starts"][0], crops[key]["starts"][1], crops[key]["starts"][2]), (crops[key]["time"][1], crops[key]["stops"][0], crops[key]["stops"][1], crops[key]["stops"][2])], QColor(crops[key]["cropColor"][0], crops[key]["cropColor"][1], crops[key]["cropColor"][2]), pmapColor=QColor(crops[key]["pmapColor"][0], crops[key]["pmapColor"][1], crops[key]["pmapColor"][2])) self._cropControlUi.cropListModel.insertRow(newRow, crop) self._cropControlUi.cropListModel.elementSelected.connect( self._onCropSelected) self._cropControlUi.cropListView.setModel( self._cropControlUi.cropListModel) self._cropControlUi.cropListView.updateGeometry() self._cropControlUi.cropListView.update() self._cropControlUi.cropListView.selectRow(0) self._maxCropNumUsed = len(crops) else: self.editor.cropModel.set_volume_shape_3d( self.editor.dataShape[1:4]) self.newCrop() self.setCrop()
def _addNewCrop(self): QApplication.setOverrideCursor(Qt.WaitCursor) """ Add a new crop to the crop list GUI control. Return the new number of crops in the control. """ color = self.getNextCropColor() crop = Crop( self.getNextCropName(), self.get_roi_4d(), color, pmapColor=self.getNextPmapColor(), ) crop.nameChanged.connect(self._updateCropShortcuts) crop.nameChanged.connect(self.onCropNameChanged) crop.colorChanged.connect(self.onCropColorChanged) crop.pmapColorChanged.connect(self.onPmapColorChanged) newRow = self._cropControlUi.cropListModel.rowCount() self._cropControlUi.cropListModel.insertRow(newRow, crop) if self._allowDeleteLastCropOnly: # make previous crop unremovable if newRow > 0: self._cropControlUi.cropListModel.makeRowPermanent(newRow - 1) newColorIndex = self._cropControlUi.cropListModel.index(newRow, 0) self.onCropListDataChanged( newColorIndex, newColorIndex ) # Make sure crop layer colortable is in sync with the new color # Update operator with new name operator_names = self._croppingSlots.cropNames.value if len(operator_names) < self._cropControlUi.cropListModel.rowCount(): operator_names.append(crop.name) try: self._croppingSlots.cropNames.setValue(operator_names, check_changed=False) except: # I have no idea why this is, but sometimes PyQt "loses" exceptions here. # Print it out before it's too late! log_exception( logger, "Logged the above exception just in case PyQt loses it.") raise # Call the 'changed' callbacks immediately to initialize any listeners self.onCropNameChanged() self.onCropColorChanged() self.onPmapColorChanged() self._maxCropNumUsed += 1 self._updateCropShortcuts() e = self._cropControlUi.cropListModel.rowCount() > 0 QApplication.restoreOverrideCursor()