Modify the state of a check button by index. Callbacks will be triggered if :attr:`!eventson` is True. Parameters ---------- index : int Index of the check button to toggle. state : bool, optional If a boolean value, set the
(self, index, state=None)
| 1395 | self._init_status(actives) |
| 1396 | |
| 1397 | def set_active(self, index, state=None): |
| 1398 | """ |
| 1399 | Modify the state of a check button by index. |
| 1400 | |
| 1401 | Callbacks will be triggered if :attr:`!eventson` is True. |
| 1402 | |
| 1403 | Parameters |
| 1404 | ---------- |
| 1405 | index : int |
| 1406 | Index of the check button to toggle. |
| 1407 | |
| 1408 | state : bool, optional |
| 1409 | If a boolean value, set the state explicitly. If no value is |
| 1410 | provided, the state is toggled. |
| 1411 | |
| 1412 | Raises |
| 1413 | ------ |
| 1414 | ValueError |
| 1415 | If *index* is invalid. |
| 1416 | TypeError |
| 1417 | If *state* is not boolean. |
| 1418 | """ |
| 1419 | if index not in range(len(self.labels)): |
| 1420 | raise ValueError(f'Invalid CheckButton index: {index}') |
| 1421 | _api.check_isinstance((bool, None), state=state) |
| 1422 | |
| 1423 | invisible = colors.to_rgba('none') |
| 1424 | |
| 1425 | facecolors = self._buttons.get_facecolor() |
| 1426 | if state is None: |
| 1427 | state = colors.same_color(facecolors[index], invisible) |
| 1428 | facecolors[index] = self._active_check_colors[index] if state else invisible |
| 1429 | self._buttons.set_facecolor(facecolors) |
| 1430 | |
| 1431 | if self.drawon: |
| 1432 | if self._useblit and self.canvas.supports_blit: |
| 1433 | background = self._load_blit_background() |
| 1434 | if background is not None: |
| 1435 | self.canvas.restore_region(background) |
| 1436 | self.ax.draw_artist(self._buttons) |
| 1437 | self.canvas.blit(self.ax.bbox) |
| 1438 | else: |
| 1439 | self.canvas.draw() |
| 1440 | |
| 1441 | if self.eventson: |
| 1442 | self._observers.process('clicked', self.labels[index].get_text()) |
| 1443 | |
| 1444 | def _init_status(self, actives): |
| 1445 | """ |