widget

        classDiagram
  CachedClass <|-- Widget
  CharmyObject <|-- Widget
  CharmyObject <|-- WidgetProfile
  EventHandling <|-- Widget
  EventHandling <|-- WidgetProfile
    

Charmy widgets base class

class charmy.widgets.widget.Widget(parent: Container | None = None, profiles: dict[str, WidgetProfile] | None = None)

基类:CharmyObject, EventHandling, CachedClass

Widget base class.

ProfileType

WidgetProfile 的别名

__init__(parent: Container | None = None, profiles: dict[str, WidgetProfile] | None = None) None

To initialize a widget.

Profiles

Profiles are used to specify the appearance of a specific widget, including its shape, color, text(s) or element(s) inside… Each widget's profiles are stored in attribute profiles, in form of {"state name": WidgetProfile()}.

Each widget comes with default profiles config, which can be changed by specifying profiles when initializing them. Contents specified in profiles arg will override defaults (Note: minimum overriding unit is a WidgetProfile instance specified for a specific state).

The default state's profile is a fallback profile.

param parent:

Parent of the widget, or None in with context

param profiles:

Profiles config of the widget

parent: Container
profiles: dict[str, WidgetProfile]
theme: Optional[styles.theme.Theme]
is_visible: bool
layout_profile: layout_profiles.LayoutProfile
state: str
property pos: tuple[int, int]

Position of the widget.

property x: int

x-position of the widget.

property y: int

y-position of the widget.

property abs_pos: tuple[int, int]

Absolute position of the widget in its root container.

property size: PropType
property width: int

Width of the widget.

property height: int

Height of the widget.

property root_container: Window

Get the root container that contains the widget.

Return window:

Either the window, or None meaning that not contained in a root container

draw(*args, **kwargs) Self

Draw the widget, does nothing on base class.

place(pos: tuple[int, int], size: tuple[int, int] | None = None) Self

Add the widget to parent, using place layout.

参数:
  • pos -- The position to place the widget

  • size -- The size of this widget

destroy() None

Destroy a widget when no longer needed.

class charmy.widgets.widget.WidgetProfile(fallback_state: str = 'default', size: tuple[int, int] | ~charmy.utils.var.Var[tuple[int, int]] | ~charmy.utils.marks.Mark=<charmy.utils.marks.Mark object>)

基类:CharmyObject, EventHandling

Class to store configs of a specific widget under a specific state.

Each WidgetProfile represents a profile for Widget. Further, ButtonProfile for Button, TextProfile for Text, and so on. An instance of WidgetProfile or its subclasses comes with default values for such type of widget. These default values will be affected by themes.

fallback_state: str = 'default'
size: tuple[int, int] | Var[tuple[int, int]] | Mark = <charmy.utils.marks.Mark object>
classmethod default() Self

To generate a profile with full default values for this widget.

classmethod references(target: str) Var

To represent a profile var.

__init__(fallback_state: str = 'default', size: tuple[int, int] | ~charmy.utils.var.Var[tuple[int, int]] | ~charmy.utils.marks.Mark=<charmy.utils.marks.Mark object>) None