ModelListener (hwx.inspire.ModelListener)#

class ModelListener(*typesOrObjects)#

Bases: object

Listens to the data model for object creation, modification and deletion.

Attribute Table#

Name

Type

contextlib

module

Method Table#

Name

Description

activateModelListener (self, *typesOrObjects)

Activates or start listening to the data model and call the handlers,

deactivateModelListener (self)

Stops listening for data model changes.

isModelListenerActive (self)

Returns, True if the model listener is active else False.

modelListenerInactive (self)

Context to temporarily disable all the callbacks.

onObjectCreated (self, obj)

Implement if interested when an object is created.

onObjectDeleted (self, obj)

Implement if interested when an object is destroyed.

onObjectModified (self, obj, attr)

Implement if interested when an object’s attribute value changes.

onPartAnimationPositionModified (self, part)

Implemented if interested when a part’s animationPosition changes.

Example

Listen to the data model for object creation, modification and deletion#
from hwx import inspire

# define listener actions with methods in a subclass of ModelListener
class MyListener(inspire.ModelListener):
def onObjectCreated(self, obj):
   print(obj, 'created')

def onObjectModified(self, obj, attr):
   print('%s.%s modified' % (obj, attr))

def onObjectDeleted(self, obj):
   print(obj, 'deleted')

# create listener to listen objects' signals
model = inspire.newModel()
myListener = MyListener(inspire.Part)

# create, creation signal will be sent
box = model.createSolidBlock(name="MyBlock")
# modify, modification signal will be sent
box.color = 'green'
# delete, deletetion signal will be sent
box.destroy()

myListener.deactivateModelListener()
inspire.fitView()
onObjectCreated(obj)#

Implement if interested when an object is created.

Not directly supported for Features but you can detect geometry changes

using onObjectModified of the Part.features attribute.

This can be caused by:
  • Explicit object creation.

  • Undo of destroy.

  • Rollback/forward of construction history.

Parameters:

obj (Named) –

onObjectDeleted(obj)#

Implement if interested when an object is destroyed.

This can be caused by:
  • Explicit obj.destroy()

  • Undo of create.

  • Rollback/forward of construction history.

Parameters:

obj (Named) –

onObjectModified(obj, attr)#

Implement if interested when an object’s attribute value changes.

Parameters:
  • obj (Named) – Object whose attribute got modified. Check if attr == ‘features’ to react to geometry changes.

  • attr (str) – Name of attribute like ‘mass’, ‘name’, …

onPartAnimationPositionModified(part)#

Implemented if interested when a part’s animationPosition changes.

This is a temporary state that isn’t recorded in history.

Parameters:

part (Named) –

activateModelListener(*typesOrObjects)#
Activates or start listening to the data model and call the handlers,

when the specified types are created, destroyed or modified.

Parameters:

*typesOrObjects (Part, BC, Motor, ...) – Types or objects to listen to. Sub classes of Named (Features are not supported).

deactivateModelListener()#

Stops listening for data model changes.

modelListenerInactive()#

Context to temporarily disable all the callbacks.

isModelListenerActive()#

Returns, True if the model listener is active else False.