Exemple #1
0
    def setData(self, data):
        self.closeContext()
        if self.data and data and data.domain.checksum() == self.data.domain.checksum():
            return

        self.attrsCombo.clear()
        self.data = self.isDataWithClass(data, orange.VarTypes.Discrete) and data or None
        
        self.targetCombo.clear()
        if self.data:
            model = VariableListModel(list(data.domain.attributes))
            self.attrsCombo.setModel(model)
            self.basstat = getCached(data, orange.DomainBasicAttrStat, (data,))
            
#            self.attrsCombo.adjustSize()
            self.attridx = 0
            self.cbAttributeSelected()
            self.tree = orange.TreeClassifier(domain = data.domain)
            self.tree.descender = orange.TreeDescender_UnknownMergeAsBranchSizes()
            self.tree.tree = self.newTreeNode(self.data)
            # set target class combo
            self.targetCombo.addItems([name for name in self.tree.tree.examples.domain.classVar.values])
            self.targetClass = 0
            self.openContext("", self.tree.domain)
        else:
            self.tree = None
            self.infoa.setText("No tree.")
            self.infob.setText("")
            self.send("Classifier", self.tree)
            self.send("Tree Learner", self.learner)
            self.openContext("", None)

        self.send("Data", None)
        self.updateTree()
        self.v.invisibleRootItem().child(0).setSelected(1)
Exemple #2
0
    def __init__(self, parent=None, signalManger=None, title="Data Sort"):
        super(OWDataSort, self).__init__(parent, signalManger, title,
                                         wantMainArea=False)

        #: Mapping (feature.name, feature.var_type) to (sort_index, sort_order)
        #: where sirt index is the position of the feature in the sortByModel
        #: and sort_order the Qt.SortOrder flag
        self.sortroles = {}

        self.autoCommit = False
        self._outputChanged = False

        box = OWGUI.widgetBox(self.controlArea, "Sort By Features")
        self.sortByView = QListView()
        self.sortByView.setItemDelegate(SortParamDelegate(self))
        self.sortByView.setSelectionMode(QListView.ExtendedSelection)
        self.sortByView.setDragDropMode(QListView.DragDrop)
        self.sortByView.setDefaultDropAction(Qt.MoveAction)
        self.sortByView.viewport().setAcceptDrops(True)

        self.sortByModel = VariableListModel(
            flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable |
                  Qt.ItemIsDragEnabled | Qt.ItemIsEditable
        )
        self.sortByView.setModel(self.sortByModel)

        box.layout().addWidget(self.sortByView)

        box = OWGUI.widgetBox(self.controlArea, "Unused Features")
        self.unusedView = QListView()
        self.unusedView.setSelectionMode(QListView.ExtendedSelection)
        self.unusedView.setDragDropMode(QListView.DragDrop)
        self.unusedView.setDefaultDropAction(Qt.MoveAction)
        self.unusedView.viewport().setAcceptDrops(True)

        self.unusedModel = VariableListModel(
            flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable |
                  Qt.ItemIsDragEnabled
        )
        self.unusedView.setModel(self.unusedModel)

        box.layout().addWidget(self.unusedView)

        box = OWGUI.widgetBox(self.controlArea, "Output")
        cb = OWGUI.checkBox(box, self, "autoCommit", "Auto commit")
        b = OWGUI.button(box, self, "Commit", callback=self.commit)
        OWGUI.setStopper(self, b, cb, "_outputChanged", callback=self.commit)
Exemple #3
0
    def setData(self, data):
        self.data = data
        self.closeContext("")
        self.information(0)
        self.error(0)
        self.imageAttrCB.clear()
        self.titleAttrCB.clear()
        self.clearScene()

        if data is not None:
            self.allAttrs = data.domain.variables + data.domain.getmetas(
            ).values()
            self.stringAttrs = [
                attr for attr in self.allAttrs
                if isinstance(attr, Orange.feature.String)
            ]

            self.stringAttrs = sorted(self.stringAttrs,
                                      key=lambda attr: 0
                                      if "type" in attr.attributes else 1)

            self.imageAttrCB.setModel(VariableListModel(self.stringAttrs))
            self.titleAttrCB.setModel(VariableListModel(self.allAttrs))

            self.openContext("", data)

            self.imageAttr = max(
                min(self.imageAttr,
                    len(self.stringAttrs) - 1), 0)
            self.titleAttr = max(min(self.titleAttr,
                                     len(self.allAttrs) - 1), 0)

            if self.stringAttrs:
                self.setupScene()
        else:
            self.info.setText("Waiting for input\n")
Exemple #4
0
    def __init__(self, parent=None, signalManager=None, name="Data Generator"):
        OWWidget.__init__(self, parent, signalManager, name, wantGraph=True)

        self.outputs = [("Data", ExampleTable)]

        self.addClassAsMeta = False
        self.attributes = []
        self.cov = []
        self.commitOnChange = False

        self.loadSettings()

        self.variablesModel = VariableListModel(
            [orange.FloatVariable(name) for name in ["X", "Y"]],
            self,
            flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)

        self.classVariable = orange.EnumVariable("Class label",
                                                 values=["Class 1", "Class 2"],
                                                 baseValue=0)

        w = OWGUI.widgetBox(self.controlArea, "Class Label")

        self.classValuesView = listView = QListView()
        listView.setSelectionMode(QListView.SingleSelection)
        listView.setEditTriggers(QListView.SelectedClicked)

        self.classValuesModel = EnumVariableModel(
            self.classVariable,
            self,
            flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)
        self.classValuesModel.wrap(self.classVariable.values)

        listView.setModel(self.classValuesModel)
        listView.selectionModel().select(self.classValuesModel.index(0),
                                         QItemSelectionModel.ClearAndSelect)
        self.connect(
            listView.selectionModel(),
            SIGNAL("selectionChanged(QItemSelection, QItemSelection)"),
            self.onClassLabelSelection)
        listView.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Maximum)
        w.layout().addWidget(listView)

        self.addClassLabel = addClassLabel = QAction("+", self)
        addClassLabel.pyqtConfigure(
            toolTip="Add class label")  #, icon=QIcon(icon_put))
        self.connect(addClassLabel, SIGNAL("triggered()"),
                     self.addNewClassLabel)

        self.removeClassLabel = removeClassLabel = QAction("-", self)
        removeClassLabel.pyqtConfigure(
            toolTip="Remove class label")  #, icon=QIcon(icon_remove))
        self.connect(removeClassLabel, SIGNAL("triggered()"),
                     self.removeSelectedClassLabel)

        actionsWidget = ModelActionsWidget([addClassLabel, removeClassLabel],
                                           self)
        actionsWidget.layout().addStretch(10)
        actionsWidget.layout().setSpacing(1)

        w.layout().addWidget(actionsWidget)

        toolbox = OWGUI.widgetBox(self.controlArea,
                                  "Tools",
                                  orientation=QGridLayout())
        self.toolActions = QActionGroup(self)
        self.toolActions.setExclusive(True)
        for i, (name, tooltip, tool, icon) in enumerate(self.TOOLS):
            action = QAction(name, self)
            action.setToolTip(tooltip)
            action.setCheckable(True)
            if os.path.exists(icon):
                action.setIcon(QIcon(icon))
            self.connect(action,
                         SIGNAL("triggered()"),
                         lambda tool=tool: self.onToolAction(tool))
            button = QToolButton()
            button.setDefaultAction(action)
            button.setIconSize(QSize(24, 24))
            button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
            button.setSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.Fixed)
            toolbox.layout().addWidget(button, i / 3, i % 3)
            self.toolActions.addAction(action)

        for column in range(3):
            toolbox.layout().setColumnMinimumWidth(column, 10)
            toolbox.layout().setColumnStretch(column, 1)

        self.optionsLayout = QStackedLayout()
        self.toolsStackCache = {}
        optionsbox = OWGUI.widgetBox(self.controlArea,
                                     "Options",
                                     orientation=self.optionsLayout)

        #        OWGUI.checkBox(self.controlArea, self, "addClassAsMeta", "Add class ids as meta attributes")
        OWGUI.rubber(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Commit")

        cb = OWGUI.checkBox(
            box,
            self,
            "commitOnChange",
            "Commit on change",
            tooltip="Send the data on any change.",
            callback=self.commitIf,
        )
        b = OWGUI.button(box,
                         self,
                         "Commit",
                         callback=self.commit,
                         default=True)
        OWGUI.setStopper(self, b, cb, "dataChangedFlag", callback=self.commit)

        self.graph = PaintDataGraph(self)
        self.graph.setAxisScale(QwtPlot.xBottom, 0.0, 1.0)
        self.graph.setAxisScale(QwtPlot.yLeft, 0.0, 1.0)
        self.graph.setAttribute(Qt.WA_Hover, True)
        self.mainArea.layout().addWidget(self.graph)

        self.currentOptionsWidget = None
        self.data = []
        self.dataChangedFlag = False
        self.domain = None

        self.onDomainChanged()
        self.toolActions.actions()[0].trigger()

        self.resize(800, 600)
Exemple #5
0
    def __init__(self, parent=None, signalManager=None, title="Group By"):
        OWWidget.__init__(self,
                          parent,
                          signalManager,
                          title,
                          wantMainArea=False)

        self.inputs = [("Data", Table, self.set_data)]
        self.outputs = [("Data", Table)]

        self.auto_commit = True
        self.hints = {}

        self.state_changed_flag = False

        self.loadSettings()

        #############
        # Data Models
        #############

        self.group_list = VariableListModel(parent=self,
                            flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable | \
                            Qt.ItemIsDragEnabled )
        self.aggregate_list = VariableAggragateModel(parent=self,
                            flags=Qt.ItemIsEnabled | Qt.ItemIsSelectable | \
                            Qt.ItemIsDragEnabled | \
                            Qt.ItemIsEditable)

        self.aggregate_delegate = AggregateDelegate()

        #####
        # GUI
        #####

        box = OWGUI.widgetBox(self.controlArea, "Group By Attributes")
        self.group_view = QListView()
        self.group_view.setSelectionMode(QListView.ExtendedSelection)
        self.group_view.setDragDropMode(QListView.DragDrop)
        self.group_view.setModel(self.group_list)
        #        self.group_view.setDragDropOverwriteMode(True)
        self.group_view.setDefaultDropAction(Qt.MoveAction)
        self.group_view.viewport().setAcceptDrops(True)
        #        self.group_view.setDropIndicatorShown(True)
        self.group_view.setToolTip("A set of attributes to group by (drag \
values to 'Aggregate Attributes' to remove them from this group).")
        box.layout().addWidget(self.group_view)

        box = OWGUI.widgetBox(self.controlArea, "Aggregate Attributes")
        self.aggregate_view = AggregateListView()
        self.aggregate_view.setSelectionMode(QListView.ExtendedSelection)
        self.aggregate_view.setDragDropMode(QListView.DragDrop)
        self.aggregate_view.setItemDelegate(self.aggregate_delegate)
        self.aggregate_view.setModel(self.aggregate_list)
        self.aggregate_view.setEditTriggers(QListView.DoubleClicked
                                            | QListView.EditKeyPressed)
        #        self.aggregate_view.setDragDropOverwriteMode(False)
        self.aggregate_view.setDefaultDropAction(Qt.MoveAction)
        self.aggregate_view.viewport().setAcceptDrops(True)
        self.aggregate_view.setToolTip("Aggregated attributes.")

        box.layout().addWidget(self.aggregate_view)

        OWGUI.rubber(self.controlArea)
        box = OWGUI.widgetBox(self.controlArea, "Commit")
        cb = OWGUI.checkBox(
            box,
            self,
            "auto_commit",
            "Commit on input change.",
            tooltip="Send the data on output on change of input.",
            callback=self.commit_if)
        b = OWGUI.button(box,
                         self,
                         "Commit",
                         callback=self.commit,
                         tooltip="Send data on output.",
                         autoDefault=True)
Exemple #6
0
    def __init__(self, parent=None, signalManager=None, title="Edit Domain"):
        OWWidget.__init__(self, parent, signalManager, title)

        self.inputs = [("Data", Orange.data.Table, self.set_data)]
        self.outputs = [("Data", Orange.data.Table)]

        # Settings

        # Domain change hints maps from input variables description to
        # the modified variables description as returned by
        # `variable_description` function
        self.domain_change_hints = {}
        self.selected_index = 0
        self.auto_commit = False
        self.changed_flag = False

        self.loadSettings()

        #####
        # GUI
        #####

        # The list of domain's variables.
        box = OWGUI.widgetBox(self.controlArea, "Domain Features")
        self.domain_view = QListView()
        self.domain_view.setSelectionMode(QListView.SingleSelection)

        self.domain_model = VariableListModel()

        self.domain_view.setModel(self.domain_model)

        self.connect(
            self.domain_view.selectionModel(),
            SIGNAL("selectionChanged(QItemSelection, QItemSelection)"),
            self.on_selection_changed)

        box.layout().addWidget(self.domain_view)

        # A stack for variable editor widgets.
        box = OWGUI.widgetBox(self.mainArea, "Edit Feature")
        self.editor_stack = QStackedWidget()
        box.layout().addWidget(self.editor_stack)

        box = OWGUI.widgetBox(self.controlArea, "Reset")

        OWGUI.button(box,
                     self,
                     "Reset selected",
                     callback=self.reset_selected,
                     tooltip="Reset changes made to the selected feature")

        OWGUI.button(box,
                     self,
                     "Reset all",
                     callback=self.reset_all,
                     tooltip="Reset all changes made to the domain")

        box = OWGUI.widgetBox(self.controlArea, "Commit")

        b = OWGUI.button(
            box,
            self,
            "&Commit",
            callback=self.commit,
            tooltip="Commit the data with the changed domain",
        )

        cb = OWGUI.checkBox(box,
                            self,
                            "auto_commit",
                            label="Commit automatically",
                            tooltip="Commit the changed domain on any change",
                            callback=self.commit_if)

        OWGUI.setStopper(self, b, cb, "changed_flag", callback=self.commit)

        self._editor_cache = {}
        self.data = None
        self.edited_variable_index = -1

        self.resize(600, 500)