tkmilan.var#
Variable classes. Extends the existing variable types defined in tkinter.
Module Attributes
Generic Type-Checking variable type for |
|
Generic Type-Checking variable type for |
|
Mapping between |
|
Configure widget validation to enhance the tooltip information with |
Functions
|
Trace the variable |
Classes
|
Value holder for |
|
Value holder for |
|
Value holder for |
|
Represent a range to limit a value, for simple integers. |
|
A bounded variant of the |
|
An unbounded variant of the |
|
Generic value holder for a sequence of object of |
|
Abstract parent class for validated |
|
Abstract parent class for validated |
|
Abstract parent class for validated |
|
Specifies a static list of labels. |
|
Specifies a static mapping between labels and its corresponding values. |
|
Value holder for |
|
Value holder for a list of |
|
Parent class for all value holders |
|
Synthetic value holder for an aggregation of other variables. |
|
Value holder for |
- class tkmilan.var.Boolean(master=None, value=None, name=None)#
Bases:
BooleanVar,VariableValue holder for
bool.
- class tkmilan.var.Double(master=None, value=None, name=None)#
Bases:
DoubleVar,VariableValue holder for
float.
- class tkmilan.var.Int(master=None, value=None, name=None)#
Bases:
IntVar,VariableValue holder for
int.
- class tkmilan.var.Limit(limit: LimitBounded | LimitUnbounded, *args, **kwargs)#
Bases:
SpecParsed[int]Represent a range to limit a value, for simple integers.
The range is represented as the
containerparameter, one of theLimitBoundedorLimitUnbounded <validation.LimitUnbounded>.When instancing directly, the
limitparameter will instance the right subclass. This means this class can not be instanced directly without arguments, and when instance with a validation representation, it will create an object of the right subclass.- Parameters:
limit (LimitBounded | LimitUnbounded) – The validation representation for this type. Mandatory.
All other arguments are passed to the right subclass.
- getLabel(value: spvT | None) str#
Return the label corresponding to the given
value.This is very efficient.
See also
The upstream function this aliases is
SpecParsed.getLabel.
- get_spinargs(*, dincrement: float = 1.0) Tuple[float, float, float]#
Get all
SpinboxNvalue arguments.- Parameters:
dincrement (float) – Default
incrementvalue, when the limit does not support it. Defaults to1.0.
- Return Value:
Returns a tuple with three floating point values:
fromtoincrement
- container: LimitBounded | LimitUnbounded#
The container object representing the specification, a mapping between label and value.
Follows the
mappingclass interface.
- class tkmilan.var.LimitBounded(limit: LimitBounded | LimitUnbounded, *args, **kwargs)#
Bases:
Limit,SpecCountableA bounded variant of the
Limitrange.Since this is bounded, it’s a countable specification.
- Parameters:
limit (LimitBounded | LimitUnbounded) – The
LimitBoundedrange object..name – Name of the variable (passed to
String). Optional, defaults to an autogenerated name.
Note
The
nameis defined in a global namespace, common to the entire application.- container: LimitBounded | LimitUnbounded#
The container object representing the specification, a mapping between label and value.
Follows the
mappingclass interface.
- ldefault: str#
The default label to be shown to the user.
- class tkmilan.var.LimitUnbounded(limit: LimitBounded | LimitUnbounded, *args, **kwargs)#
Bases:
LimitAn unbounded variant of the
Limitrange.Since this is unbounded, it’s not a countable specification.
- Parameters:
limit (LimitBounded | LimitUnbounded) – The
LimitUnboundedrange object.name – Name of the variable (passed to
String). Optional, defaults to an autogenerated name.
Note
The
nameis defined in a global namespace, common to the entire application.- container: LimitBounded | LimitUnbounded#
The container object representing the specification, a mapping between label and value.
Follows the
mappingclass interface.
- ldefault: str#
The default label to be shown to the user.
- class tkmilan.var.ObjectList(master=None, value=None, name=None)#
Bases:
Variable,Generic[objT]Generic value holder for a sequence of object of
objTtype.Just keep an instance variable with the “actual” value. Pretend the value is just an empty
str.See also
StringList: Simpler version of this, supports onlystr.
- class tkmilan.var.Spec(spec: VSpec | None = None, *args, **kwargs)#
Bases:
StringAbstract parent class for validated
Stringvariables.This variable tracks the label value, but also its valid states, which makes it so that the state type is a
model.VState, not a simplestr.Note that this might specify a complex validation, not just a list of discrete values, nor a continous range, for example.
Note
This should not be instanced directly, it’s a parent class to be subclassed on other variable types.
See also
For a countable variant of this, see
SpecCountable. For a valued variant of this, seeSpecParsed.- __contains__(label: str) bool#
Check if the
labellabel satisfies the specification.Wraps the
containerinterface.Should be used as
label in Spec.
- get() VState[bool]#
Returns the value of the variable, as
VState.The
valuealternates betweenTruefor valid labels, andNonefor invalid labels.
- set(state: str | VState[bool])#
Set the variable to
state.Only the label is set, either for direct
strorVState.Note
In debug mode, when setting the variable using a
VState, thevalueitself is re-validated.
- container: Container[str]#
The container object representing the specification.
Follows the
containerclass interface.
- ldefault: str#
The default label to be shown to the user.
- class tkmilan.var.SpecCountable(spec: VSpec | None = None, *args, **kwargs)#
Bases:
SpecAbstract parent class for validated
Stringvariables, with countable amount of valid alternatives.This is an alternative to
Spec, when the amount of possible valid values is countable.Note
This should not be instanced directly, it’s a parent class to be subclassed on other variable types.
See also
For a simpler version of this, see
Spec. For a valued variant of the base class, seeSpecParsed.- __contains__(label: str) bool#
Check if the
labellabel satisfies the specification.Wraps the
containerinterface.Should be used as
label in Spec.
- __len__() int#
Count how many labels this specification contains.
Should be used as
len(SpecCountable).
- lall() Sequence[str]#
Get all valid labels supported by this variable.
- container: Container[str]#
The container object representing the specification.
Follows the
containerclass interface.
- ldefault: str#
The default label to be shown to the user.
- class tkmilan.var.SpecParsed(spec: VSpec | None = None, *args, **kwargs)#
-
Abstract parent class for validated
Stringvariables, with a parsed value (instead of a boolean validation).Note
This should not be instanced directly, it’s a parent class to be subclassed on other variable types.
See also
For a simpler version of this, see
Spec. For a countable variant of the base class, seeSpecCountable.- get() VState[spvT | None]#
Returns the value of the variable, as
VState.The
valuealternates between the parsed label, andNonefor invalid labels.See also
The base class version is
Spec.get. It is compatible, but with different semantics.
- getLabel(value: spvT | None) str#
Return the first label corresponding to the given
value.This is not very efficient, and the mapping might not be bi-injective. It’s mostly implemented for completeness’ sake.
- Returns:
lemptyif the value is not valid.- Return type:
str
- set(state: str | VState[spvT | None])#
Set the variable to
state.Only the label is set, either for direct
strorVState.Note
In debug mode, when setting the variable using a
VState, thevalueitself is re-validated.In debug mode, mark the variable with
_complexValidation = Trueto skip the validation about broken VState.See also
The base class version is
Spec.set. It is compatible, but with different semantics.
- container: Mapping[str, spvT]#
The container object representing the specification, a mapping between label and value.
Follows the
mappingclass interface.
- lempty: str = ''#
The default label for invalid values.
This is only necessary on rare circumstances. Should map to an invalid value.
- class tkmilan.var.StaticList(spec: VSpec | None = None, *args, **kwargs)#
Bases:
SpecCountableSpecifies a static list of labels.
- Parameters:
Note
The
nameis defined in a global namespace, common to the entire application.- container: Container[str]#
The container object representing the specification.
Follows the
containerclass interface.
- ldefault: str#
The default label to be shown to the user.
- class tkmilan.var.StaticMap(spec: VSpec | None = None, *args, **kwargs)#
Bases:
SpecCountable,SpecParsed[spvT]Specifies a static mapping between labels and its corresponding values.
- Parameters:
Note
The
nameis defined in a global namespace, common to the entire application.- getLabel(value: spvT | None) str#
Return the label corresponding to the given
value.This is very efficient, and the mapping is enforced to be bi-injective.
See also
The upstream function this aliases is
SpecParsed.getLabel.
- container: Container[str]#
The container object representing the specification, a mapping between label and value.
Follows the
mappingclass interface.
- ldefault: str#
The default label to be shown to the user.
- class tkmilan.var.String(master=None, value=None, name=None)#
Bases:
StringVar,VariableValue holder for
str.
- class tkmilan.var.StringList(master=None, value=None, name=None)#
Bases:
VariableValue holder for a list of
str.In
Tk, everything is a string and the syntax for lists is similar to Python, so this is technically supported, but sounds like a coincidence.Works well, though.
See also
ObjectListfor an arbitrary list of Python objects.- get() Iterable[str]#
Return value of variable.
- set(value: Iterable[str]) None#
Set the variable to VALUE.
- class tkmilan.var.Variable(master=None, value=None, name=None)#
Bases:
VariableParent class for all value holders
- ignoreContainerTrace: bool = False#
When this variable is attached to a container, do not consider it for tracing purposes.
- ready: bool = True#
Check if the variable is ready for usage.
Defaults to
True, this exists for compatibility withaggregator.
- class tkmilan.var.aggregator(master=None, value=None, name=None, *, cwidget: tkmilan_mixin.MixinWidget)#
Bases:
VariableSynthetic value holder for an aggregation of other variables.
Useful for container widgets.
- get() None#
Return value of variable.
- set(value: None = None)#
Set the variable to VALUE.
- property ready: bool#
Check if the variable is ready for usage.
- tout: TimeoutIdle | None#
Hold the
TimeoutIdleobject that indicates this variable is setup.Since this variable is a synthetic variable, useful only when triggered from other function, it needs configuration before it can be used. For optimisation reasons, this is not done right on
__init__like most other variables.Defaults to
None, indicating it is not ready. Seeready.
- class tkmilan.var.nothing(master=None, value=None, name=None)#
Bases:
VariableValue holder for
None.Useful for widgets that don’t store anything, like buttons.
- get()#
Return value of variable.
- set(value: None)#
Set the variable to VALUE.
- class tkmilan.var.objT#
Generic Type-Checking variable type for
ObjectList.This is a
typing.TypeVar, to be used only when typechecking. Seetyping.alias of TypeVar(‘objT’)
- class tkmilan.var.spvT#
Generic Type-Checking variable type for
SpecParsed.This is a
typing.TypeVar, to be used only when typechecking. Seetyping.alias of TypeVar(‘spvT’)
- tkmilan.var.trace(var: Variable, function: Callable, *, trace_mode: Literal['read', 'write', 'unset'] = 'write', trace_initial: bool = False, **kwargs: Any) str#
Trace the variable
var.There is no Python documentation, see
Tktrace variable documentation.The
functionarguments will be:var: The traced variableetype: The trace mode (seetrace_mode)The other given
kwargs
It is possible to run the function as soon as the trace is defined. This is useful if the trace is used to keep state in sync.
- Parameters:
var (Variable) – The traced variable.
function (Callable) – The callback function.
trace_mode (Literal['read', 'write', 'unset']) – The trace mode, when should the callback be invoked.
Nonewhen running on the initial function call (seetrace_initial).trace_initial (bool) – Run the callback function on start. Runs async (similar to
model.TimeoutIdle).kwargs (Any) – Passed to the callback function.
- Returns:
Return the function identifier, as stored by
Tk.- Return type:
str
- tkmilan.var.MAP_VALIDATIONS = {<class 'tkmilan.validation.StaticList'>: <class 'tkmilan.var.StaticList'>, <class 'tkmilan.validation.StaticMap'>: <class 'tkmilan.var.StaticMap'>, <class 'tkmilan.validation.LimitBounded'>: <class 'tkmilan.var.LimitBounded'>, <class 'tkmilan.validation.LimitUnbounded'>: <class 'tkmilan.var.LimitUnbounded'>}#
Mapping between
validation.VSpecrepresentations, and the corresponding variable class.
- tkmilan.var.ValidationLimit = VSettings(postVar=True, postInitial=True, fn=<function __vfn_limit>, fnSimple=False, tt=None, ttSimple=False, tkWhen='none')#
Configure widget validation to enhance the tooltip information with
Specviolation information.This distinguishes between an invalid value, and a value outside the
Spec. This is more apparent onLimit.This is only experimental code, but should work as intended on this narrow case.
To be used as:
Widget(self, ... validation=var.ValidationLimit, ... ).putTooltip()