code: def on_item_toggled(self, index, state=None):
          
          if not index.data(model.IsIdle):
              return self.info("Cannot toggle")
  
          if not index.data(model.IsOptional):
              return self.info("This item is mandatory")
  
          if state is None:
              state = not index.data(model.IsChecked)
  
          index.model().setData(index, state, model.IsChecked)
  
          # Withdraw option to publish if no instances are toggled
          play = self.findChild(QtWidgets.QWidget, "Play")
          validate = self.findChild(QtWidgets.QWidget, "Validate")
          any_instances = any(index.data(model.IsChecked)
                              for index in self.data["models"]["instances"])
          play.setEnabled(any_instances)
          validate.setEnabled(any_instances)
  
          # Emit signals
          if index.data(model.Type) == "instance":
              instance = self.data["models"]["instances"].items[index.row()]
              util.defer(
                  100, lambda: self.controller.emit_(
                      signal="instanceToggled",
                      kwargs={"new_value": state,
                              "old_value": not state,
                              "instance": instance}))
  
          if index.data(model.Type) == "plugin":
              util.defer(
                  100, lambda: self.controller.emit_(
                      signal="pluginToggled",
                      kwargs={"new_value": state,
                              "old_value": not state,
                              "plugin": index.data(model.Object)}))
docs: An item is requesting to be toggled