Events

class mechanica.MxEventBase(*args, **kwargs)
last_fired

Record of last time fired

times_fired

Record of how many times fired

remove() void

Designates event for removal

mechanica.Event

alias of mechanica.mechanica.MxEventPy

class mechanica.MxEvent(*args)

Bases: mechanica.mechanica.MxEventBase

Construct an instance using functions

Parameters
  • invokeMethod (MxEventMethod) – an invoke function

  • predicateMethod (MxEventMethod) – a predicate function

class mechanica.MxEventPy(invokeExecutor: mechanica.mechanica.MxEventPyInvokePyExecutor, predicateExecutor: Optional[mechanica.mechanica.MxEventPyPredicatePyExecutor] = None)

Bases: mechanica.mechanica.MxEventBase

mechanica.on_event(invoke_method, predicate_method=None)

Creates and registers an event using prescribed invoke and predicate python function executors

Parameters
  • invoke_method (PyObject) – an invoke method; evaluated when an event occurs. Takes an MxEvent instance as argument and returns 0 on success, 1 on error

  • predicate_method – optional predicate method; decides if an event occurs. Takes a MxEvent instance as argument and returns 1 to trigger event, -1 on error and 0 otherwise

mechanica.TimeEvent

alias of mechanica.mechanica.MxTimeEventPy

class mechanica.MxTimeEventPy(period: double const &, invokeExecutor: MxTimeEventPyInvokePyExecutor, predicateExecutor: MxTimeEventPyPredicatePyExecutor = None, nextTimeSetter: MxTimeEventNextTimeSetter * = None, start_time: double const & = 0, end_time: double const & = -1)

Bases: mechanica.mechanica.MxEventBase

next_time

Next time of evaluation

period

Period of evaluation

start_time

Start time of evaluations

end_time

End time of evaluations

mechanica.on_time(period, invoke_method, predicate_method=None, distribution='default', start_time=0.0, end_time=- 1.0)

Like on_event, but for an event that occurs at regular intervals.

Parameters
  • period (float) – period of event

  • invoke_method (PyObject) – an invoke method; evaluated when an event occurs. Takes an MxTimeEvent instance as argument and returns 0 on success, 1 on error

  • predicate_method – optional predicate method; decides if an event occurs. Takes a MxTimeEvent instance as argument and returns 1 to trigger event, -1 on error and 0 otherwise

  • distribution (str) – distribution by which the next event time is selected

  • start_time (str) – time after which the event can occur

  • end_time (str) – time before which the event can occur; a negative value is interpreted as until ‘forever’

mechanica.ParticleEvent

alias of mechanica.mechanica.MxParticleEventPy

class mechanica.MxParticleEvent(*args)

Bases: mechanica.mechanica.MxEventBase

targetType

Target particle type of this event

targetParticle

Target particle of an event evaluation

class mechanica.MxParticleEventPy(*args)

Bases: mechanica.mechanica.MxParticleEvent

mechanica.on_particle(ptype, invoke_method, predicate_method=None, selector='default', single: bool = False)

Like on_event, but for a particle of a particular particle type.

Parameters
  • ptype (MxParticleType) – the type of particle to select

  • invoke_method (PyObject) – an invoke method; evaluated when an event occurs. Takes an MxParticleEvent instance as argument and returns 0 on success, 1 on error

  • predicate_method – optional predicate method; decides if an event occurs. Takes a MxParticleEvent instance as argument and returns 1 to trigger event, -1 on error and 0 otherwise

  • selector (str) – name of particle selector

  • single (bool) – flag to only trigger event once and then return

mechanica.ParticleTimeEvent

alias of mechanica.mechanica.MxParticleTimeEventPy

class mechanica.MxParticleTimeEvent(*args)

Bases: mechanica.mechanica.MxEventBase

targetType

Target particle type of this event

targetParticle

Target particle of an event evaluation

next_time

Next time at which an evaluation occurs

period

Period of event evaluations

start_time

Time at which evaluations begin

end_time

Time at which evaluations stop

class mechanica.MxParticleTimeEventPy(*args)

Bases: mechanica.mechanica.MxParticleTimeEvent

mechanica.on_particletime(ptype, period, invoke_method, predicate_method=None, distribution='default', start_time=0.0, end_time=- 1.0, selector='default')

A combination of on_time and on_particle.

Parameters
  • ptype (MxParticleType) – the type of particle to select

  • period (float) – period of event

  • invoke_method (PyObject) – an invoke method; evaluated when an event occurs. Takes an MxTimeEvent instance as argument and returns 0 on success, 1 on error

  • predicate_method – optional predicate method; decides if an event occurs. Takes a MxTimeEvent instance as argument and returns 1 to trigger event, -1 on error and 0 otherwise

  • distribution (str) – distribution by which the next event time is selected

  • start_time (str) – time after which the event can occur

  • end_time (str) – time before which the event can occur; a negative value is interpreted as until ‘forever’

  • selector (str) – name of particle selector

mechanica.KeyEvent

alias of mechanica.mechanica.MxKeyEvent

class mechanica.MxKeyEvent(glfw_event: Magnum::Platform::GlfwApplication::KeyEvent * = None)
property key_name: str

Key pressed for this event

mechanica.on_keypress(invoke_method)

Registers a callback for handling keyboard events

Parameters

invoke_method (PyObject) – an invoke method; evaluated when an event occurs. Takes an MxKeyEvent instance as argument and returns None