PlasmaCalcs.tools.oop_tools.manage_attrs.IncrementableAttrManager

class PlasmaCalcs.tools.oop_tools.manage_attrs.IncrementableAttrManager(obj, default=0, *, step=1)

Bases: object

an incrementable attribute, and methods to manage other attributes when it is incremented or decremented.
__init__(obj, default=0, *, step=1)

Methods

__init__(obj[, default, step])

clear()

increment()

use_obj_attrs_at(value, *[, ...])

use_obj_attrs_at_next(**attrs_and_values)

using_obj_attrs_at(value, **attrs_and_values)

using_obj_attrs_at_next(**attrs_and_values)

Attributes

incrementable_attr_manager_value

obj

clear()
set self.value to self.default, and empty self._using_at.
increment()
context manager which increments self.value upon entry, and restores old value upon exit.
CAUTION: this is a context manager; it will not increment self.value until entered,
via “with” statement, e.g. “with self.increment(): …”.
property incrementable_attr_manager_value
alias to value
property obj
gets self._obj(), or just self._obj if not self._obj_is_weakref.
use_obj_attrs_at(value, *, remove_after_decrementing_to=UNSET, **attrs_and_values)
tell self to set attrs of obj when self.value == value.
More precisely:
- when self incremented OR decremented to value,
UsingAttrs(self.obj, attrs_and_values).enter_handle_attrs()
- when self incremented beyond value OR decremented beyond value,
UsingAttrs(…).exit_handle_attrs()
remove_after_decrementing_to: UNSET, None, or int
- when self decremented to remove_after_decrementing_to,
also remove these “use_obj_attrs_at” commands.
Note: this should always be < value, otherwise will raise ValueError.
UNSET –> use self.default.
None –> never remove these commands as a result of decrementing.
int –> remove these commands as soon as value is decremented to this value.
Note: to decrease chances of mistakes / ambiguity,
raise ValueError if value <= self.value, or if value <= remove_after_decrementing_to
value <= self.value, OR
value <= remove_after_decrementing_to.
(This method is only responsible for putting these attrs and values into self._using_at;
the “real work” happens in self.incremented, _on_incremented, and _on_decremented.)
use_obj_attrs_at_next(**attrs_and_values)
tell self to set attrs of obj when self.increment() is next entered.
Equivalent to self.use_obj_attrs_at(self.value + self.step, **attrs_and_values),
with remove_after_decrementing_to = self.value.
using_obj_attrs_at(value, **attrs_and_values)
context manager which tells self to set attrs of obj when self.value == value.
Equivalent to calling self.use_obj_attrs_at(…) upon entry (and doing nothing upon exit).
using_obj_attrs_at_next(**attrs_and_values)
context manager which tells self to set attrs of obj when self.increment() is next entered.
Equivalent to calling self.use_obj_attrs_at_next(…) upon entry (and doing nothing upon exit).