tkmilan.mixin#
All the mixin classes, to be reused internally.
Functions
|
Classes
|
Full container state. |
|
Parent class of all containers. |
|
Parent class of menu widgets |
Mixin for all stateful widgets. |
|
Mixin class for container widgets. |
|
Mixin class for single widgets. |
|
Mixin class for variable traces. |
|
Mixin class for widget validation, for single widgets. |
|
|
Parent class of all widgets. |
|
Parent class of all proxy widgets. |
|
Parent class of all single widgets. |
- class tkmilan.mixin.ContainerState(swidgets: Mapping[str, SingleWidget], cwidgets: Mapping[str, ContainerWidget | MenuWidget], variables: Mapping[str, Variable], wvariables: Mapping[str, Variable], vwidgets: Mapping[str, Sequence[str]], vid_upstream: Set[str], hswidgets: Set[SingleWidget], hcwidgets: Set[ContainerWidget])#
Bases:
objectFull container state.
- Parameters:
swidgets (Mapping[str, SingleWidget]) – Single Widgets
cwidgets (Mapping[str, ContainerWidget | MenuWidget]) – Container or Menu Widgets
variables (Mapping[str, Variable]) – Attached Variables
wvariables (Mapping[str, Variable]) – Mapping VariableID -> Variable object
vwidgets (Mapping[str, Sequence[str]]) – Mapping VariableID -> Widget Name list
vid_upstream (Set[str]) – Set of upstream VariableID
hswidgets (Set[SingleWidget]) – Helper Single Widgets. Technically not considered as “state”, only matters for tracing purposes. Includes widgets that might be ignored using
ignoreContainerState, check this when using if this is not intended.hcwidgets (Set[ContainerWidget]) – Helper Container Widgets. Technically not considered as “state”, only matters for tracing purposes.
- class tkmilan.mixin.ContainerWidget(*, gkeys: Iterable[str] | None = None)#
Bases:
MixinWidget,MixinStateContainer,MixinTracesParent class of all containers.
- gvar(name: str) Variable#
Get a variable attached to this container, by name.
Fails if it does not exist.
- Parameters:
name (str) – The variable name to search for.
- init_container(*args, layout: str | None = '', **kwargs) None#
Setup all the container stuff.
Includes: - Variable settings - Sub-Widget settings - Layout - Traces (from
MixinTraces) - Defaults
- pad_container(pad: int, *, recursive: bool = True, _level: int = 0) None#
Pad this container widget, recursively.
This requires more than a simple blind application of padding to all widgets. It will also take into account containers with a single widget,
layout_padable(skipping unsupported containers), and proxy widgets. Guarantee the padding distance between widgets and the container ispad.In particular, this will pad all widgets on the right/bottom, and also pad the left/top widgets on the left/top grid location, creating uniform padding in all directions.
The padding configuration will be applied recursively by default, see
recursiveto disable this.- Parameters:
pad (int) – The padding distance, in pixels. See above for details on how this applied.
recursive (bool) – Apply the same padding to child containers. Enabled by default.
See also
See
RootWindow’rpadfor automatic application to all widgets, down from the root window.
- pgrid(*children: None | str | MixinWidget, row: bool = True, column: bool = True, _internal: bool = False, sticky: None | CP | Sticky = None, **arguments: Any) None#
Configure the grid rows and columns for the given widgets.
For widgets that span more than one row or column, the settings are changed for all rows or columns.
- Parameters:
children (None | str | MixinWidget) – Widgets to consider. Accepts the widget objects, or strings (searches
widgetsfor the corresponding object). Accepts and skipsNonevalues (useful for conditional widgets). All widgets must be direct children of this widget.row (bool) – Configure the rows. Defaults to
True.column (bool) – Configure the columns. Defaults to
True.arguments (Any) – Arguments passed to the configuration functions: columnconfigure / rowconfigure.
Other arguments are passed to each individual widget, using
cgrid:- Parameters:
sticky (None | CP | Sticky) – Configure the
stickygrid settings. Accepts aCPobject (seemodel.CP_S), or amodel.Stickydirectly. When set toNone, nothing is changed. Defaults toNone.
See also
See
cgridfor a similar function that takes only the individual settings, and works on the widget itself.Note
To configure only rows or columns, see
pgrid_randpgrid_cfor a more ergonomic API. See alsopgrid_allto act on all children.Warning
Make sure to include proxied widgets as children (
MixinWidget.wproxy), there is a warning on debug mode, but this might change in the future.
- pgrid_c(*children: str | MixinWidget, **arguments: Any) None#
Wraps
pgrid, acting only on columns.See
pgrid, sets onlycolumntoTrue.
- pgrid_r(*children: str | MixinWidget, **arguments: Any) None#
Wraps
pgrid, acting only on rows.See
pgrid, sets onlyrowtoTrue.
- set_gui_state(state: GuiState | None = None, _sub: bool = True, **kwargs) GuiState#
Set GUI State for itself, and optionally, for all sub-widgets.
Warning
Don’t use this directly, unless you really know what you are doing.
- Parameters:
_sub (bool) – Automatically run
set_gui_substatewith the samemodel.GuiStateobject. Defaults toTrue. Useful only for implementing special containers.
See also
MixinWidget.gstate: Property changed for all sub-widgets.
- set_gui_substate(state: GuiState) None#
Set GUI State for all sub-widgets.
Warning
Don’t use this directly, unless you really know what you are doing.
Note
To control the GUI subwidget handling, this function can be redefined (using extra care), using something like this:
def set_gui_substate(self, state: tkmilan.model.GuiState): if self.some_condition is True: # Manipulate the `model.GuiState` object state.enabled = False super().set_gui_substate(state)
See also
MixinWidget.gstate: Property changed for all sub-widgets.
- setup_adefaults() None#
Runs after all widgets are stable.
Avoid changing state on this function.
Note
Available for subclass redefinition.
See also
setup_defaults: Run code right after this widget is setup, before all widgets are stable.
- setup_container_layout(olayout: str | None) None#
“Internal” alternative to
setup_layout.This is mostly useful for complex widgets, to keep the convenience of the existing
setup_layoutcall for the final instances, but allow for class-level adjustments.This runs just before
setup_layout.Warning
Don’t use this directly, unless you know what you doing. Use
setup_layout.- Parameters:
olayout (str | None) – This is string originally used for layout. See
self.layoutfor the processed version.
Note
Available for subclass redefinition, mostly for complex widgets.
- setup_defaults() None#
Runs after the widget is completely setup.
Note this runs before the parent widget is complete ready.
Useful to set default values. Do not configure layout-related settings here, see
setup_layout.Note
Available for subclass redefinition.
See also
setup_adefaults: Run code after all widgets are stable (including parent widgets in the tree).
- setup_gstate_valid(*, nowarn: bool = False, childMatch: Iterable[SingleWidget] = (), childSkip: Iterable[SingleWidget] = ()) None#
Configure setting the
model.GuiStatevalidparameter for this GUI.Since this is still a “hack”, it’s not enabled automatically nor in a nice declarative way. This might interact with other features, it is only a preview for now.
This is not recursive, child containers DO NOT inherit this setting. There’s no support for child containers anyway, make sure to use this only for simple containers, no nesting.
To setup this, call this function inside the widgets’
setup_defaultsfunction, before other widget state changes. This usestraceinternally, so that’s another feature that might not work perfectly.Use the
nowarnparameter if you confirmed it works properly, to avoid a spurious warning. This is not the default, make sure you really test this properly.Use the
childMatchparameter to “tie” the container valid state to those child single widgets. This should include any child labels, that should be ignored when calculating the new state, but set with the container state.childSkipwill avoid setting the state on those widgets.Warning
This is not fully baked, but can be used carefully, with extra testing.
- setup_layout(layout: str | None) None#
Useful for manual adjustments to the automatic layout.
This runs after all automatic layout settings are configured.
- Parameters:
layout (str | None) – This is the processed version of the layout string.
Note
Available for subclass redefinition.
- setup_state(**kwargs) Mapping[str, WidgetDynamicState]#
Define an object that will be cached forever.
This can have a static object, or a dynamic
callable.See
MixinState.wstate_static,stateSetup.
- setup_widgets(*args, **kwargs) Mapping[str, MixinWidget] | None#
Define the sub widgets here.
Return a
dictfor a custom mapping, orNonefor automatic mapping.
- trace(*args, trace_vupstream: Set[str] | None = None, **kwargs: Any) str#
Trace the variable associated to the current widget.
The underlying function is
tkmilan.var.trace, check it for more detailed documentation.- Parameters:
function – The callback function.
trace_name – A name for the trace reference. Must be unique for the widget. Optional, uses an automatic name otherwise.
kwargs (Any) – Passed to the
tkmilan.var.tracefunction.
See also
Use
atraceto combine a trace with amodel.TimeoutIdle. Usetracevto consider the named container variable.
- var(cls: Type[Variable], *, value: Any | None = None, name: str | None = None, vname: str | None = None) Variable#
“Attach” a new variable to this container.
- Parameters:
cls (Type[Variable]) – The variable class.
name (str | None) – The variable name, on the widget namespace. Optional, defaults to
vname.value (Any | None) – The default value. Optional, defaults to
None.vname (str | None) – The variable name, on the global namespace. Optional, defaults to an autogenerated name.
See also
Note
The
vnameis defined in a global namespace, common to the entire application. This can be used to define common variables across different widgets, but this is not default behaviour since it violates the principle of least surprise.
- varSpec(cls: Type[Spec], spec: Any, *, name: str | None = None, vname: str | None = None) Spec#
“Attach” a new
specified variableto this container.- Parameters:
cls (Type[Spec]) – The variable class.
name (str | None) – The variable name, on the widget namespace. Optional, defaults to
vname.spec (Any) – The specification to creating the new variable.
vname (str | None) – The variable name, on the global namespace. Optional, defaults to an autogenerated name.
See also
Note
The
vnameis defined in a global namespace, common to the entire application. This can be used to define common variables across different widgets, but this is not default behaviour since it violates the principle of least surprise.
- widgets_class(*classes: Type[MixinWidget]) Iterable[MixinWidget]#
Filter widgets by type.
Filter all child widgets by type. Very useful to apply settings to a subset of all child widgets.
Consider proxy widgets, do the right thing.
- Parameters:
classes (Type[MixinWidget]) – Widget Types, as classes.
See also
See
widgets_rclassto filter recursively. Seewidgets_exceptto reverse filter child widgets.
- widgets_except(*widgets: str | MixinWidget) Iterable[MixinWidget]#
Reverse-filter widgets by instance.
Filter all child widgets by inverting a given list, i.e. produce all other widgets. Supports strings. Very useful to apply settings to a subset of all child widgets.
Consider proxy widgets, do the right thing.
- Parameters:
widgets (str | MixinWidget) – Skip these widget objects or strings (searches
widgetsfor the corresponding object). All widgets must be direct children of this widget.
See also
See
widgets_classto filter child widgets by class. Seewidgets_exceptfor the direct filter.
- widgets_only(*widgets: str | MixinWidget) Iterable[MixinWidget]#
Filter widgets by name.
Filter all child widget by producing the given widgets. Supports strings.
Consider proxy widgets, do the right thing.
- Parameters:
widgets (str | MixinWidget) – Include these widget objects or strings (searches
widgetsfor the corresponding object). All widgets must be direct children of this widget.
See also
See
widgets_exceptfor the inverted filter.Note
This seems worthless, but can be very useful to gather a list of child widgets when
setup_widgetsreturns a mapping, just give the string keys.
- widgets_rclass(*classes: Type[MixinWidget]) Iterable[MixinWidget]#
Filter widgets by type, recursively.
Filter all child widgets by type, including children of child containers. Very useful to apply settings to a subset of all child widgets, on recursive containers.
Consider proxy widgets, do the right thing.
- Parameters:
classes (Type[MixinWidget]) – Widget Types, as classes.
See also
See
widgets_classto filter only for the current children.
- wimage(key: str) Image | None#
Wraper for
RootWindow.wimage.
- property gsize: GridSize#
GUI grid size (according to the current child widgets).
Follow
MixinWidget.ignoreContainerLayoutsetting.
- layout: str | None = ''#
Store the processed layout
- layout_autoadjust: bool = False#
Should this container have its child widgets automatically adjusted, based on their types.
This adjusts child widgets based on its type in specific ways.
Currently implemented adjustments:
Separator: Setweight=0to all rows/columns containing this type, based on itsorientation.
Note
This has important performance implications, so it is disabled by default. The widgets that can be adjusted are flagged as a warning on debug mode, so they can be manually toggled.
- layout_autogrow: bool = True#
Should this container have its child columns and rows grow automatically.
This is equivalent to configuring the grid with the option
weight=1.
- layout_autohide: bool = True#
Should this container have its child with
ignoreContainerLayoutremoved from the grid.Enabled by default, do not change this unless there are any problems.
- layout_expand: bool = True#
Should this container expand to fill the space on the parent widget.
Note this affects the parent grid, not the child grid on this container.
- layout_padable: bool = True#
Should this container’s children be automatically padded, when requested.
Most containers behave well when padding children, but some are problematic, mark those at class level (set
layout_padable = False).
- widgets: Mapping[str, MixinWidget]#
Store mapping between widget name and
widget object.See
setup_widgets.
- class tkmilan.mixin.MenuWidget(*, gkeys: Iterable[str] | None = None)#
Bases:
MixinWidget,MixinStateContainer,MixinTracesParent class of menu widgets
Setup all the menu stuff.
Includes: - Variable settings - Traces (from
MixinTraces)
- setup_state(**kwargs) Mapping[str, WidgetDynamicState]#
Define an object that will be cached forever.
This can have a static object, or a dynamic
callable.See
MixinState.wstate_static,stateSetup.
- trace(*args, trace_vupstream: Set[str] | None = None, **kwargs: Any) str#
Trace the variable associated to the current widget.
The underlying function is
tkmilan.var.trace, check it for more detailed documentation.- Parameters:
function – The callback function.
trace_name – A name for the trace reference. Must be unique for the widget. Optional, uses an automatic name otherwise.
kwargs (Any) – Passed to the
tkmilan.var.tracefunction.
See also
Use
atraceto combine a trace with amodel.TimeoutIdle. Usetracevto consider the named container variable.
- wimage(key: str) Image | None#
Wraper for
RootWindow.wimage.
- cspec: Tuple[MenuElement, ...]#
Store the children specification
- class tkmilan.mixin.MixinState#
Bases:
objectMixin for all stateful widgets.
- setup_state()#
Define an object that will be cached forever.
This can have a static object, or a dynamic
callable.
- state_get(**kwargs)#
Define how to get the widget state.
The kwargs are only passed for Dynamic State widgets
- state_set(state, substate: bool, **kwargs)#
Define how to set the widget state.
The kwargs are only passed for Dynamic State widgets
- isNoneable: bool | None = None#
Define if a
Noneresult leads to skipping this widget on the state result.This applies to both static and dynamic state calculations. Defaults to
None, so that it can be overriden by subclasses.For dynamic calculations, the results for some widgets might vary depending on where the root state starts, so they will be unpredictable. When the state is taken as a whole (the simple usage), it is predictable.
Note
The default
Nonevalue for this variable is invalid. The subclass must define this.
- property stateSetup#
Obtain the state setup.
This takes into account the
wstate_staticflag, producing a static object or a callable.This should always be used,
MixinState.setup_stateis only a definition.
- property wstate#
Widget State
- wstate_static: bool = True#
Define if the
MixinState.setup_statecache is static. or a callable for dynamic calculations.See
stateSetup.
- class tkmilan.mixin.MixinStateContainer#
Bases:
MixinStateMixin class for container widgets.
To ignore a container state, define this on the subclass:
def setup_state(self, **kwargs): return {}
Note
When subclassing this, define
MixinState.setup_stateto return a dictionary mapping subwidget identifier toWidgetDynamicState.- state_get(*, vid_upstream: Set[str] | None = None, **kwargs) Any#
Define how to get the widget state.
The kwargs are only passed for Dynamic State widgets
- state_set(state, substate, *, vid_upstream: Set[str] | None = None, **kwargs) None#
Define how to set the widget state.
The kwargs are only passed for Dynamic State widgets
Save the attached
Menustate as a regular container element, with this key. WhenNone, the state is not part of this container state.This only makes sense for the
RootWindow, other containers should not have child menus.
- wstate_single: None | bool | str = None#
Mark the container state as “single”, including only the state for this child. The value should be a string indicating the state key.
Truemeans the only existing key should be considered. This should be used only when the key name is dynamic and cannot be statically determined.Should only be enabled where there is a single child element, this is verified when getting the value. Use
MixinWidget.ignoreContainerStateto ignore other widgets.This creates no performance improvements, it is only useful to simplify the state.
Note
To skip the warning about a container with a single widget on debug binaries, mark the widget class with
wstate_single = False. This works exactly as the defaultNone, without the warning.
- wstate_single_wstate: bool = False#
When the container state is “single”, particularly setting
wstate_single=True, mark the state as correctly empty, so the parent function can turn aWState/WStateRinto a single element.Should only be enabled where
wstate_singleis set to True and there are no child elements, this is verified when getting the value.
- wstate_static: bool = False#
Define if the
MixinState.setup_statecache is static. or a callable for dynamic calculations.See
stateSetup.
- class tkmilan.mixin.MixinStateSingle#
Bases:
MixinStateMixin class for single widgets.
Note
When subclassing this, define
MixinState.setup_stateto return the variable containing the widget state.- state_get(**kwargs)#
Define how to get the widget state.
The kwargs are only passed for Dynamic State widgets
- state_set(state, substate: bool, **kwargs)#
Define how to set the widget state.
The kwargs are only passed for Dynamic State widgets
- wstate_static: bool = True#
Define if the
MixinState.setup_statecache is static. or a callable for dynamic calculations.See
stateSetup.
- class tkmilan.mixin.MixinTraces#
Bases:
objectMixin class for variable traces.
- atrace(function: Callable, **kwargs: Any) str#
Trace the variable associated to the current widget, but run the callback when there’s nothing else to do.
This is an efficient way of combining
tracewith amodel.TimeoutIdle. Useful if the tracing call runs too soon and needs to be delayed by the minimum amount of time possible.- Parameters:
function (Callable) – The callback function.
kwargs (Any) – Passed to
tracefunction.
- trace(function: Callable, *, trace_name: str | None = None, **kwargs: Any) str#
Trace the variable associated to the current widget.
The underlying function is
tkmilan.var.trace, check it for more detailed documentation.- Parameters:
function (Callable) – The callback function.
trace_name (str | None) – A name for the trace reference. Must be unique for the widget. Optional, uses an automatic name otherwise.
kwargs (Any) – Passed to the
tkmilan.var.tracefunction.
See also
Use
atraceto combine a trace with amodel.TimeoutIdle. Usetracevto consider the named container variable.
- tracev(vname: str, function: Callable, *, trace_name: str | None = None, **kwargs: Any) str#
Trace the named variable attached to the current container widget.
The underlying function is
tkmilan.var.trace, check it for more detailed documentation.See also
Use
traceto consider the current widget variable instead.
- class tkmilan.mixin.MixinValidationSingle#
Bases:
objectMixin class for widget validation, for single widgets.
- doValidation(n=None, i=None, t=None) None#
Force widget Post-Validation.
Wraps the upstream function with optional arguments, to be used directly on
trace,Binding, etc.All arguments are ignored.
- eSet(label: str) Callable[[...], None]#
Return an event function to set the state a certain label.
- eSetValue(value: Any) Callable[[...], None]#
Wraper for
eSet, to set a value instead.Requires the widget to have a
specificed variable.
- putTooltip(tooltipClass: Union[bool, Type[Tooltip]] = True, **tt_kwargs) MixinValidationSingle#
Setup the tooltip object for the validation settings on itself.
This creates the
Tooltipobject according to the settings, attached to the current widget. SeeVSettingsfor tooltip related settings. The widget must setup the validation already, but must not define an existing tooltip object (parametertt).This is designed to be used inside the
setup_widgetsfunction, like this:def setup_widgets(self, ...): self.w1 = Widget(self, ...).putTooltip(...)
This is usually called “method chaining”, or “fluent interface”.
- Parameters:
tooltipClass (Union[bool, Type[Tooltip]]) –
The class to instance as the tooltip object. Must be a
Tooltip, orTrueto useTooltipValidation.Defaults to
True.
All other keyword arguments are passed to the
Tooltipcreation.Note
This is incompatible with
attachTooltip, do not mix them on the same widget.
- setDefault() None#
Set the current state to the default label.
- setup_validation(vstate: VState, vwhy: VWhy | None = None) bool | None#
Define the “natural” widget validation, checking the state validation.
Some widgets might have a different “natural” widget validation function.
When this does not apply, use
fn.validation_pass.
- class tkmilan.mixin.MixinWidget(*, gkeys: Iterable[str] | None = None)#
Bases:
objectParent class of all widgets.
- Parameters:
gkeys (Iterable[str] | None) – Append widget-specific
model.GuiStatekeys to common listmodel.GUI_STATES_common.
- _bindings: MutableMapping[str, Binding]#
Store all widget
Bindingobjects, keyed by name (seebinding).
- _tidles: MutableMapping[str, TimeoutIdle]#
Store some widget
TimeoutIdleobjects, keyed by name (seetidle).
- attachTooltip(tooltipClass: Optional[Type[Tooltip]] = None, **tt_kwargs)#
Setup a tooltip object for the current widget.
This creates a basic
Tooltipobject according to the given arguments, attached to the current widget. Saves the tooltip object intt.This is designed to be used inside the
setup_widgetsfunction, like this:def setup_widgets(self, ...): self.w1 = Widget(self, ...).attachTooltip(...)
This is usually called “method chaining”, or “fluent interface”.
- Parameters:
tooltipClass (Optional[Type[Tooltip]]) –
The class to instance as the tooltip object. Must be a
Tooltip, orNoneto useTooltipSingleStatic.Defaults to
True.
All other keyword arguments are passed to the
Tooltipcreation.Note
This is not to be confused with the validation tooltips, see
putTooltip. This is incompatible withputTooltip, do not mix them on the same widget.
- binding(sequence: str, *args, key: str | None = None, immediate: bool = True, **kwargs) Binding#
Create a
model.Bindingfor this widget.Stores all widget bindings on a per-instance dictionary, for later usage. Note that all dictionary keys must be different. For the same bindings on a single widget, this requires passing the
keyargument.See the
Tkbind documentation.- Parameters:
key (str | None) – Optional. Defaults to the
sequenceitself. Useful to support multiple bindings on the same sequence.immediate (bool) – Passed to the upstream object, default to enabling the binding on creation. This is the opposite from upstream.
All other arguments are passed to the
model.Bindingobject.
- cgrid(*, sticky: Sticky, **kwargs) None#
Configure parent widget grid settings.
There is no Python documentation, see
Tkgrid configure documentation.- Parameters:
sticky (Sticky) – Configure the
stickygrid settings.
All other arguments are passed to the upstream
gridfunction.See also
See
pgridfor a simular function that works on the parent container widget.Note
This function can replace:
w.grid(sticky=tkmilan.tk.NSEW)
with:
w.cgrid(sticky=tkmilan.S.ALL)
- galternate_toggle(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None)#
Toggle the
alternatemodel.GuiStatestate, if available.Equivalent to
self.alternate = model.GuiState(enabled=not self.gstate.alternate).For performance reasons, the validation for
alternatestate is only done on debug mode.- Parameters:
_arg1 (Any | None) – Unused, included for API compatibility with
Tkevents_arg2 (Any | None) – Unused, included for API compatibility with
Tktraces_arg3 (Any | None) – Unused, included for API compatibility with
Tkevent loop.
- genabled(state: bool | None)#
Manipulate the
GuiStateenabledstate.Equivalent to
self.gstate = model.GuiState(enabled=state).- Parameters:
state (bool | None) – The
enabledstate.
- genabled_toggle(_arg1: Any | None = None, _arg2: Any | None = None, _arg3: Any | None = None)#
Toggle the
GuiStateenabledstate.Equivalent to
self.gstate = model.GuiState(enabled=not self.gstate.enabled).- Parameters:
_arg1 (Any | None) – Unused, included for API compatibility with
Tkevents_arg2 (Any | None) – Unused, included for API compatibility with
Tktraces_arg3 (Any | None) – Unused, included for API compatibility with
Tkevent loop.
- putAuto(value: bool | None = False) MixinWidget#
Set the
isAutomarker on itself.See
MixinWidget.isAutofor more information on the possible values. Defaults toFalse.This is designed to be used inside the
setup_widgetsfunction, like this:def setup_widgets(self, ...): self.w1 = Widget(self, ...).putAuto() # No GUI No State self.w1 = Widget(self, ...).putAuto(None) # No GUI Yes State
This is usually called “method chaining”, or “fluent interface”.
- putHelper(value: bool = True) MixinWidget#
DEPRECATED. See
putAuto.
- putIgnoreLayout(value: bool = True) MixinWidget#
Set the
ignoreContainerLayoutmarker on itself.This is designed to be used inside the
setup_widgetsfunction, like this:def setup_widgets(self, ...): self.w1 = Widget(self, ...).putIgnoreLayout()
This is usually called “method chaining”, or “fluent interface”.
- putIgnoreState(value: bool = True) MixinWidget#
Set the
ignoreContainerStatemarker on itself.This is designed to be used inside the
setup_widgetsfunction, like this:def setup_widgets(self, ...): self.w1 = Widget(self, ...).putIgnoreState()
This is usually called “method chaining”, or “fluent interface”.
- putIgnoreTrace(value: bool = True) MixinWidget#
Set the
ignoreContainerTracemarker on itself.This is designed to be used inside the
setup_widgetsfunction, like this:def setup_widgets(self, ...): self.w1 = Widget(self, ...).putIgnoreTrace()
This is usually called “method chaining”, or “fluent interface”.
- setup_grid(fmt: str | GridCoordinates, **kwargs) None#
Configure the grid for the current widget.
fmtcan be given as amodel.GridCoordinates, or as a singlestr, to be parsed bymodel.GridCoordinates.parse.- Parameters:
fmt (str | GridCoordinates) – The grid configuration format. Specified above.
kwargs – Passed upstream
See also
wgrid: Get the current widget grid coordinates.
- tidle(action: Callable, *args, key: str | None = None, **kwargs) TimeoutIdle#
Create a
model.TimeoutIdlefor this widget.Stores all idle timeouts created using this function on a per-instance dictionary, for later usage. If the
actionis not a “real” function, this requires passing thekeyargument.- Parameters:
key (str | None) – Optional. Defaults to the
actionname.
All other arguments are passed to
model.TimeoutIdleobject.
- wgeometry(*, size: bool = True, s_requested: bool = False) WidgetGeometry#
Get the widget geometry information.
- Parameters:
size (bool) – Consider the widget size, width and height. Considered by default.
s_requested (bool) – When calculating the size, use the requested size. Unset by default.
- Returns:
Return a
model.WidgetGeometryobject with the widget information.- Return type:
- wroot_search() RootWindow#
Alternative to
wrootthat crawls the widget tree.Use the
wparentproprety.See also
wroot: Simpler alternative to this function, crawling the widget tree. Requires all widgets to be stable.
- wsize(*, requested: bool = False) PixelSize#
Get the widget size.
Each widget has several “sizes”.
The default is the actual size. This is the current size of the widget. Note that this size can be
1pixel for height and width, when the widget is first created (see “requested size” for an alternative).The requested size (controlled by
requested) is the “natural” size of the widget, requested to the window manager. This should be stable, but it might not be the real size. It is available as soon as the widget is created.
See upstream winfo documentation.
- Parameters:
requested (bool) – When calculating the size, use the requested size. Unset by default.
- Returns:
Return a
model.PixelSizeobject with the widget size.- Return type:
- gkeys: FrozenSet[str]#
The supported
model.GuiStatekeys.
- ignoreContainerLayout: bool = False#
Ignore this widget when performing automatic layout.
See also
See
putIgnoreLayoutfor an ergonomic way to set this on child widgets.
- ignoreContainerState: bool = False#
Ignore this widget’s state when included on a container.
See also
See
putIgnoreStatefor an ergonomic way to set this on child widgets.
- ignoreContainerTrace: bool = False#
When this widget is included on a container, do not consider it for tracing purposes.
See also
See
putIgnoreTracefor an ergonomic way to set this on child widgets.
- isAuto: bool | None#
Marker that tracks the automatic state setup.
One of the following values:
True: Include on automatic widget and GUI states. Default.False: No automatic widget state, but keep in on the GUI state. This makes the widget stateless, but it still participates in the automatic GUI state changes. Very useful for helper containers.None: No automatic widget nor GUI states. This makes the widget basically invisible.
Note
This was called
isHelperin older versions. Turn allisHelper=FalseintoisAuto=False(unless you have a good reason to isolate GUI state).See also
See
putAutofor an ergonomic way to set this on child widgets.
- proxee: Optional[MixinWidget] = None#
Link to the corresponding proxied widget, if exists.
See also
The base
ProxyWidgetclass.
- property size_screen: PixelSize#
The screen size.
This is a global property, but it’s available in every widget.
- property size_vroot: PixelSize#
The VirtualRoot size.
This is a global property, but it’s available in every widget.
- styleID: str | None = None#
StyleID for this widget. See
RootWindow.styleIDs.
- tt: Optional[Tooltip] = None#
The simply attached tooltip.
It is possible to attach multiple tooltips, but that is usually rare. This should only be modified by the
attachTooltipfunction.See also
The related
attachTooltipfunction.
- property wgrid: GridCoordinates | None#
Get the widget grid coordinates, if the widget is visible.
- Returns:
Return a
model.GridCoordinatesobject with the widget information. If the wiget was hidden, returnNone.This is also available for the root widget (
wroot) for completeness, but that doesn’t really correspond to any grid, returnNone.This is also available for
SecondaryWindowwidgets, but it does not support any kind of grid, returnNone.
See also
setup_grid: Change the widget grid coordinates.
- wparent: Optional[MixinWidget] = None#
A reference to the parent widget.
- wproxy: Optional[MixinWidget] = None#
Link to the corresponding proxy widget, if exists.
See also
The base
ProxyWidgetclass.
- property wroot: RootWindow#
Get the root widget, directly.
Does not use the
wparentproperty to crawl the widget tree to the top, so that it might be called before that setup is done (during setup of lower widgets, for example).
- property wview: WidgetView | None#
Get the widget view information.
- Returns:
Return a
model.WidgetViewobject with the view information, if the widget supports scrolling in at least one axis. If the widget does not support scrolling, returnsNone.
- class tkmilan.mixin.ProxyWidget(*args, **kwargs)#
Bases:
SingleWidgetParent class of all proxy widgets. Special case of
SingleWidget.This is implemented as a class initializer that sets up the
wproxy/proxeereferences, and returns the child instance.Note that creating an instance of this type will return the child widget instance, not the proxy object. The rest of the library is aware of this. The
ProxyWidgetobject is available on thewproxyvalue.Note
When implementing subclasses, take care not to alias any children argument with proxy arguments. Use a per-class prefix, or
proxyprefix for common arguments. SeeScrolledWidgetfor an example (notescroll*` and ``proxyStyleIDarguments).See also
Check the Python documentation for the difference between
object.__new__andobject.__init__.
- class tkmilan.mixin.SingleWidget(*, gkeys: Iterable[str] | None = None)#
Bases:
MixinWidget,MixinStateSingle,MixinTracesParent class of all single widgets.
- init_single(vspec: None | Variable | VSpec = None, gkeys: Iterable[str] | None = None) None#
Setup all single widget stuff.
Includes:
Variable settings (Supports creating new variables)
tkmilan.mixin.MixinState.isNoneablecalculation
- setup_state()#
Define an object that will be cached forever.
This can have a static object, or a dynamic
callable.
- wimage(key: str) Image | None#
Wraper for
RootWindow.wimage.
- layout_padable: bool = True#
Should this widget be automatically padded, when requested.