def get_settings_and_export_layer(layer, parent_widget=None): """ Prompt the user for layer export settings, and perform the layer export. """ sourceTags = [True for l in layer.datasources] for i, source in enumerate(layer.datasources): if not hasattr(source, "dataSlot"): sourceTags[i] = False if not any(sourceTags): raise RuntimeError( "can not export from a non-lazyflow data source (layer=%r, datasource=%r)" % (type(layer), type(layer.datasources[0]))) if not _has_lazyflow: raise RuntimeError("lazyflow not installed") import lazyflow dataSlots = [ slot.dataSlot for (slot, isSlot) in zip(layer.datasources, sourceTags) if isSlot is True ] opStackChannels = lazyflow.operators.OpMultiArrayStacker( dataSlots[0].getRealOperator().parent) for slot in dataSlots: assert isinstance( slot, lazyflow.graph.Slot), "slot is of type %r" % (type(slot)) assert isinstance( slot.getRealOperator(), lazyflow.graph.Operator), "slot's operator is of type %r" % (type( slot.getRealOperator())) opStackChannels.AxisFlag.setValue("c") opStackChannels.Images.resize(len(dataSlots)) for i, islot in enumerate(opStackChannels.Images): islot.connect(dataSlots[i]) # Create an operator to do the work from lazyflow.operators.ioOperators import OpFormattedDataExport opExport = OpFormattedDataExport(parent=opStackChannels.parent) opExport.OutputFilenameFormat.setValue(encode_from_qstring(layer.name)) opExport.Input.connect(opStackChannels.Output) opExport.TransactionSlot.setValue(True) # Use this dialog to populate the operator's slot settings settingsDlg = DataExportOptionsDlg(parent_widget, opExport) # If user didn't cancel, run the export now. if (settingsDlg.exec_() == DataExportOptionsDlg.Accepted): helper = ExportHelper(parent_widget) helper.run(opExport) # Clean up our temporary operators opExport.cleanUp() opStackChannels.cleanUp()
def _onSave(self): # If we are actually playing a recording right now, then the "Stop Recording" action gets triggered as the last step. # Ignore it. if self._recorder is None: return self.commentsDisplayEdit.setFocus(True) self._autopaused = False if not self._recorder.paused: self._onPause(False) self.startButton.setEnabled(True) settings = QSettings("Ilastik", "Event Recorder") variant = settings.value("recordings_directory") if not variant.isNull(): default_dir = str( variant.toString() ) else: import ilastik ilastik_module_root = os.path.split(ilastik.__file__)[0] ilastik_repo_root = os.path.split( ilastik_module_root )[0] default_dir = os.path.join( ilastik_repo_root, "tests" ) now = datetime.datetime.now() timestr = "{:04d}{:02d}{:02d}-{:02d}{:02d}".format( now.year, now.month, now.day, now.hour, now.minute ) default_script_path = os.path.join( default_dir, "recording-{timestr}.py".format( timestr=timestr ) ) dlg = QFileDialog(self, "Save Playback Script", default_script_path, "Ilastik event playback scripts (*.py)") dlg.setObjectName("event_recorder_save_dlg") dlg.setAcceptMode(QFileDialog.AcceptSave) dlg.setOptions( QFileDialog.Options(QFileDialog.DontUseNativeDialog) ) dlg.exec_() # If the user cancelled, stop now if dlg.result() == QFileDialog.Rejected: return script_path = encode_from_qstring( dlg.selectedFiles()[0] ) # Remember the directory as our new default default_dir = os.path.split(script_path)[0] settings.setValue( "recordings_directory", default_dir ) with open(script_path, 'w') as f: self._recorder.writeScript(f) self._saved = True
def get_settings_and_export_layer(layer, parent_widget=None): """ Prompt the user for layer export settings, and perform the layer export. """ sourceTags = [True for l in layer.datasources] for i, source in enumerate(layer.datasources): if not hasattr(source, "dataSlot"): sourceTags[i] = False if not any(sourceTags): raise RuntimeError("can not export from a non-lazyflow data source (layer=%r, datasource=%r)" % (type(layer), type(layer.datasources[0])) ) if not _has_lazyflow: raise RuntimeError("lazyflow not installed") import lazyflow dataSlots = [slot.dataSlot for (slot, isSlot) in zip(layer.datasources, sourceTags) if isSlot is True] opStackChannels = lazyflow.operators.OpMultiArrayStacker(dataSlots[0].getRealOperator().parent) for slot in dataSlots: assert isinstance(slot, lazyflow.graph.Slot), "slot is of type %r" % (type(slot)) assert isinstance(slot.getRealOperator(), lazyflow.graph.Operator), "slot's operator is of type %r" % (type(slot.getRealOperator())) opStackChannels.AxisFlag.setValue("c") opStackChannels.Images.resize(len(dataSlots)) for i,islot in enumerate(opStackChannels.Images): islot.connect(dataSlots[i]) # Create an operator to do the work from lazyflow.operators.ioOperators import OpFormattedDataExport opExport = OpFormattedDataExport( parent=opStackChannels.parent ) opExport.OutputFilenameFormat.setValue( encode_from_qstring(layer.name) ) opExport.Input.connect( opStackChannels.Output ) opExport.TransactionSlot.setValue(True) # Use this dialog to populate the operator's slot settings settingsDlg = DataExportOptionsDlg( parent_widget, opExport ) # If user didn't cancel, run the export now. if ( settingsDlg.exec_() == DataExportOptionsDlg.Accepted ): helper = ExportHelper( parent_widget ) helper.run(opExport) # Clean up our temporary operators opExport.cleanUp() opStackChannels.cleanUp()
def createEditor(self, parent, option, index): """ Create an editor widget. Note that the LayerWidget always uses persistent editors. """ layer = index.data().toPyObject() if isinstance(layer, Layer): editor = LayerItemWidget(parent=parent) editor.is_editor = True # We set a custom objectName for debug and eventcapture testing purposes. objName = encode_from_qstring(layer.name) editor.setObjectName("LayerItemWidget_{}".format(objName)) editor.setAutoFillBackground(True) editor.setPalette(option.palette) editor.setBackgroundRole(QPalette.Highlight) editor.layer = layer self._editors[layer] = editor return editor else: QStyledItemDelegate.createEditor(self, parent, option, index)
def extract_numeric_size(txt): split = encode_from_qstring(txt.toString()).split() if len(split) == 0: return 0.0 else: return float(split[0])