def populate(self):
        #self.ui.treeWidget.setColumnCount(2)
        for pluginName, features in self.featureDict.items():
            if pluginName == "TestFeatures" and not ilastik_config.getboolean(
                    "ilastik", "debug"):
                continue
            parent = QTreeWidgetItem(self.ui.treeWidget)
            parent.setText(0, pluginName)

            parent.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            # hack to ensure checkboxes visible
            parent.setCheckState(0, Qt.Checked)
            parent.setCheckState(0, Qt.Unchecked)
            parent.setExpanded(False)
            self.countChecked[pluginName] = 0
            self.countAll[pluginName] = len(self.featureDict[pluginName])

            advanced_names = []
            simple_names = []
            selected_names = []

            groups = set()
            plugin = pluginManager.getPluginByName(pluginName,
                                                   "ObjectFeatures")
            features_with_props = deepcopy(features)
            if plugin is not None:
                plugin.plugin_object.fill_properties(features_with_props)

            for name in sorted(features.keys()):
                parameters = features[name]

                for prop, prop_value in features_with_props[name].items():
                    if not prop in list(parameters.keys()):
                        # this property has not been added yet (perhaps the feature dictionary has been read from file)
                        # set it now
                        parameters[prop] = prop_value

                try:
                    if parameters['advanced'] is True:
                        advanced_names.append(name)
                    else:
                        simple_names.append(name)
                except KeyError:
                    simple_names.append(name)
                try:
                    groups.add(parameters["group"])
                except KeyError:
                    pass

                if pluginName in self.selectedFeatures:
                    if name in self.selectedFeatures[pluginName]:
                        selected_names.append(name)
            gr_items = {}
            for gr in groups:
                gr_items[gr] = QTreeWidgetItem(parent)
                gr_items[gr].setText(0, gr)
                #gr_items[gr].setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
                gr_items[gr].setExpanded(True)

            for name in simple_names + advanced_names:
                if name in advanced_names and (not name in selected_names):
                    # do not display advanced features, if they have not been selected previously
                    continue
                parameters = features[name]
                if "group" in parameters:
                    item = QTreeWidgetItem(gr_items[parameters["group"]])
                    item.group_name = parameters["group"]
                else:
                    item = QTreeWidgetItem(parent)
                if 'displaytext' in parameters:
                    itemtext = parameters['displaytext']
                else:
                    itemtext = name
                item.setText(0, itemtext)
                item.feature_id = name

                item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                if 'tooltip' in parameters:
                    item.setToolTip(0, parameters['tooltip'])

                # hack to ensure checkboxes visible
                item.setCheckState(0, Qt.Checked)
                item.setCheckState(0, Qt.Unchecked)
                if name in selected_names:
                    item.setCheckState(0, Qt.Checked)
                    self.countChecked[pluginName] += 1
            if self.countChecked[pluginName] == 0:
                parent.setCheckState(0, Qt.Unchecked)
            elif self.countChecked[pluginName] == self.countAll[pluginName]:
                parent.setCheckState(0, Qt.Checked)
            else:
                parent.setCheckState(0, Qt.PartiallyChecked)
            self.updateToolTip(parent)
        # facilitates switching of the CheckBox when clicking on the Text of a QTreeWidgetItem
        self.ui.treeWidget.setCurrentItem(None)
Пример #2
0
    def populate(self):
        #self.ui.treeWidget.setColumnCount(2)
        for pluginName, features in self.featureDict.items():
            if pluginName=="TestFeatures" and not ilastik_config.getboolean("ilastik", "debug"):
                continue
            parent = QTreeWidgetItem(self.ui.treeWidget)
            parent.setText(0, pluginName)

            parent.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
            # hack to ensure checkboxes visible
            parent.setCheckState(0, Qt.Checked)
            parent.setCheckState(0, Qt.Unchecked)
            parent.setExpanded(False)
            self.countChecked[pluginName]=0
            self.countAll[pluginName]=len(self.featureDict[pluginName])

            advanced_names = []
            simple_names = []
            selected_names = []

            groups = set()
            plugin = pluginManager.getPluginByName(pluginName, "ObjectFeatures")
            features_with_props = deepcopy(features)
            if plugin is not None:
                plugin.plugin_object.fill_properties(features_with_props)

            for name in sorted(features.keys()):
                parameters = features[name]

                for prop, prop_value in features_with_props[name].items():
                    if not prop in list(parameters.keys()):
                        # this property has not been added yet (perhaps the feature dictionary has been read from file)
                        # set it now
                        parameters[prop] = prop_value

                try:
                    if parameters['advanced'] is True:
                        advanced_names.append(name)
                    else:
                        simple_names.append(name)
                except KeyError:
                    simple_names.append(name)
                try:
                    groups.add(parameters["group"])
                except KeyError:
                    pass

                if pluginName in self.selectedFeatures:
                    if name in self.selectedFeatures[pluginName]:
                        selected_names.append(name)
            gr_items = {}
            for gr in groups:
                gr_items[gr] = QTreeWidgetItem(parent)
                gr_items[gr].setText(0, gr)
                #gr_items[gr].setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
                gr_items[gr].setExpanded(True)
            
            for name in simple_names+advanced_names:
                if name in advanced_names and (not name in selected_names):
                    # do not display advanced features, if they have not been selected previously
                    continue
                parameters = features[name]
                if "group" in parameters:
                    item = QTreeWidgetItem(gr_items[parameters["group"]])
                    item.group_name = parameters["group"]
                else:
                    item = QTreeWidgetItem(parent)
                if 'displaytext' in parameters:
                    itemtext = parameters['displaytext']
                else:
                    itemtext = name
                item.setText(0, itemtext)
                item.feature_id = name

                item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
                if 'tooltip' in parameters:
                    item.setToolTip(0, parameters['tooltip'])

                # hack to ensure checkboxes visible
                item.setCheckState(0, Qt.Checked)
                item.setCheckState(0, Qt.Unchecked)
                if name in selected_names:
                    item.setCheckState(0, Qt.Checked)
                    self.countChecked[pluginName]+=1
            if self.countChecked[pluginName] == 0:
                parent.setCheckState(0, Qt.Unchecked)
            elif self.countChecked[pluginName] == self.countAll[pluginName]:
                parent.setCheckState(0, Qt.Checked)
            else:
                parent.setCheckState(0, Qt.PartiallyChecked)
            self.updateToolTip(parent)
        # facilitates switching of the CheckBox when clicking on the Text of a QTreeWidgetItem
        self.ui.treeWidget.setCurrentItem(None)