def __init__(self, parent=None, signalManager=None, name="Preprocess"): OWWidget.__init__(self, parent, signalManager, name) self.inputs = [("Example Table", ExampleTable, self.setData) ] #, ("Learner", orange.Learner, self.setLearner)] self.outputs = [("Preprocess", orngWrap.PreprocessedLearner), ("Preprocessed Example Table", ExampleTable) ] #, ("Preprocessor", orange.Preprocessor)] self.autoCommit = False self.changedFlag = False # self.allSchemas = [PreprocessorSchema("Default" , [Preprocessor_discretize(method=orange.EntropyDiscretization()), Preprocessor_dropMissing()])] self.allSchemas = [("Default", [ Preprocessor_discretizeEntropy( method=orange.EntropyDiscretization()), Preprocessor_dropMissing() ], 0)] self.lastSelectedSchemaIndex = 0 self.preprocessorsList = PyListModel([], self) box = OWGUI.widgetBox(self.controlArea, "Preprocessors", addSpace=True) box.layout().setSpacing(1) self.setStyleSheet("QListView::item { margin: 1px;}") self.preprocessorsListView = QListView() self.preprocessorsListSelectionModel = ListSingleSelectionModel( self.preprocessorsList, self) self.preprocessorsListView.setItemDelegate( PreprocessorItemDelegate(self)) self.preprocessorsListView.setModel(self.preprocessorsList) self.preprocessorsListView.setSelectionModel( self.preprocessorsListSelectionModel) self.preprocessorsListView.setSelectionMode(QListView.SingleSelection) self.connect(self.preprocessorsListSelectionModel, SIGNAL("selectedIndexChanged(QModelIndex)"), self.onPreprocessorSelection) self.connect(self.preprocessorsList, SIGNAL("dataChanged(QModelIndex, QModelIndex)"), lambda arg1, arg2: self.commitIf) box.layout().addWidget(self.preprocessorsListView) self.addPreprocessorAction = QAction("+", self) self.addPreprocessorAction.pyqtConfigure( toolTip="Add a new preprocessor to the list") self.removePreprocessorAction = QAction("-", self) self.removePreprocessorAction.pyqtConfigure( toolTip="Remove selected preprocessor from the list") self.removePreprocessorAction.setEnabled(False) self.connect( self.preprocessorsListSelectionModel, SIGNAL("selectedIndexChanged(QModelIndex)"), lambda index: self. removePreprocessorAction.setEnabled(index.isValid())) actionsWidget = ModelActionsWidget( [self.addPreprocessorAction, self.removePreprocessorAction]) actionsWidget.layout().setSpacing(1) actionsWidget.layout().addStretch(10) box.layout().addWidget(actionsWidget) self.connect(self.addPreprocessorAction, SIGNAL("triggered()"), self.onAddPreprocessor) self.connect(self.removePreprocessorAction, SIGNAL("triggered()"), self.onRemovePreprocessor) box = OWGUI.widgetBox(self.controlArea, "Saved Schemas", addSpace=True) self.schemaFilterEdit = OWGUIEx.LineEditFilter(self) box.layout().addWidget(self.schemaFilterEdit) self.schemaList = PyListModel([], self, flags=Qt.ItemIsSelectable | Qt.ItemIsEditable | Qt.ItemIsEnabled) self.schemaListProxy = PySortFilterProxyModel(filter_fmt="{0.name}", parent=self) self.schemaListProxy.setFilterCaseSensitivity(Qt.CaseInsensitive) self.schemaListProxy.setSourceModel(self.schemaList) self.schemaListView = QListView() self.schemaListView.setItemDelegate(PreprocessorSchemaDelegate(self)) # self.schemaListView.setModel(self.schemaList) self.schemaListView.setModel(self.schemaListProxy) self.connect(self.schemaFilterEdit, SIGNAL("textEdited(QString)"), self.schemaListProxy.setFilterRegExp) box.layout().addWidget(self.schemaListView) self.schemaListSelectionModel = ListSingleSelectionModel( self.schemaListProxy, self) self.schemaListView.setSelectionMode(QListView.SingleSelection) self.schemaListView.setSelectionModel(self.schemaListSelectionModel) self.connect(self.schemaListSelectionModel, SIGNAL("selectedIndexChanged(QModelIndex)"), self.onSchemaSelection) self.addSchemaAction = QAction("+", self) self.addSchemaAction.pyqtConfigure( toolTip="Add a new preprocessor schema") self.updateSchemaAction = QAction("Update", self) self.updateSchemaAction.pyqtConfigure( toolTip="Save changes made in the current schema") self.removeSchemaAction = QAction("-", self) self.removeSchemaAction.pyqtConfigure(toolTip="Remove selected schema") self.updateSchemaAction.setEnabled(False) self.removeSchemaAction.setEnabled(False) actionsWidget = ModelActionsWidget([]) actionsWidget.addAction(self.addSchemaAction) actionsWidget.addAction(self.updateSchemaAction).setSizePolicy( QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) actionsWidget.addAction(self.removeSchemaAction) actionsWidget.layout().setSpacing(1) box.layout().addWidget(actionsWidget) self.connect(self.addSchemaAction, SIGNAL("triggered()"), self.onAddSchema) self.connect(self.updateSchemaAction, SIGNAL("triggered()"), self.onUpdateSchema) self.connect(self.removeSchemaAction, SIGNAL("triggered()"), self.onRemoveSchema) self.addPreprocessorsMenuActions = actions = [] for name, pp, kwargs in self.preprocessors: action = QAction(name, self) self.connect(action, SIGNAL("triggered()"), lambda pp=pp, kwargs=kwargs: self.addPreprocessor( pp(**kwargs))) actions.append(action) box = OWGUI.widgetBox(self.controlArea, "Output") cb = OWGUI.checkBox(box, self, "autoCommit", "Commit on any change", callback=self.commitIf) b = OWGUI.button(box, self, "Commit", callback=self.commit) OWGUI.setStopper(self, b, cb, "changedFlag", callback=self.commitIf) self.mainAreaStack = QStackedLayout() self.stackedEditorsCache = {} OWGUI.widgetBox(self.mainArea, orientation=self.mainAreaStack) self.data = None self.learner = None self.loadSettings() self.activateLoadedSettings()