Create a list of `Option` instances for the options sidebar.
(self)
| 554 | ) |
| 555 | |
| 556 | def _create_options(self) -> list[OptionCategory[Any]]: |
| 557 | """ |
| 558 | Create a list of `Option` instances for the options sidebar. |
| 559 | """ |
| 560 | |
| 561 | def enable(attribute: str, value: Any = True) -> bool: |
| 562 | setattr(self, attribute, value) |
| 563 | |
| 564 | # Return `True`, to be able to chain this in the lambdas below. |
| 565 | return True |
| 566 | |
| 567 | def disable(attribute: str) -> bool: |
| 568 | setattr(self, attribute, False) |
| 569 | return True |
| 570 | |
| 571 | def simple_option( |
| 572 | title: str, |
| 573 | description: str, |
| 574 | field_name: str, |
| 575 | values: tuple[str, str] = ("off", "on"), |
| 576 | ) -> Option[str]: |
| 577 | "Create Simple on/of option." |
| 578 | |
| 579 | def get_current_value() -> str: |
| 580 | return values[bool(getattr(self, field_name))] |
| 581 | |
| 582 | def get_values() -> dict[str, Callable[[], bool]]: |
| 583 | return { |
| 584 | values[1]: lambda: enable(field_name), |
| 585 | values[0]: lambda: disable(field_name), |
| 586 | } |
| 587 | |
| 588 | return Option( |
| 589 | title=title, |
| 590 | description=description, |
| 591 | get_values=get_values, |
| 592 | get_current_value=get_current_value, |
| 593 | ) |
| 594 | |
| 595 | brightness_values = [1.0 / 20 * value for value in range(0, 21)] |
| 596 | |
| 597 | return [ |
| 598 | OptionCategory( |
| 599 | "Input", |
| 600 | [ |
| 601 | Option( |
| 602 | title="Editing mode", |
| 603 | description="Vi or emacs key bindings.", |
| 604 | get_current_value=lambda: ["Emacs", "Vi"][self.vi_mode], |
| 605 | get_values=lambda: { |
| 606 | "Emacs": lambda: disable("vi_mode"), |
| 607 | "Vi": lambda: enable("vi_mode"), |
| 608 | }, |
| 609 | ), |
| 610 | Option( |
| 611 | title="Cursor shape", |
| 612 | description="Change the cursor style, possibly according " |
| 613 | "to the Vi input mode.", |
no test coverage detected