Working Sets¶
- class WorkingSet.WorkingSet¶
Bases:
objectA class encapsulating a map of Scene Graph locations to states, to which elements can be added and removed, triggering callbacks if specified.
- class State¶
Bases:
objectAn ‘enumeration’ of possible location states for use in a
WorkingSet.- Empty = 1¶
- Excluded = 8¶
- ExcludedWithChildren = 16¶
- Included = 2¶
- IncludedWithChildren = 4¶
- classmethod coerceToBitmask(bitmaskOrStates)¶
- Return type
int- Parameters
bitmaskOrStates (
intorlistofintorNone) – A numerical value representing some state values bitwise combined into a single value, or a list of state values, orNoneto indicate all possible states.- Returns
A bitmask representing the states represented by the given bitmask or states.
- Note
A
bitmaskOrStatesvalue of None, 0 or an empty list will return a bitmask representing all possible states.
- classmethod fromStateString(stateString)¶
Turns the given state string representation into the actual state value.
- Return type
intorNone- Parameters
stateString (
str) – The string representation of the state.- Returns
The state value, or
Noneif the given state string doesn’t map to a known state.
- classmethod getBitmaskFromStates(states)¶
Turns the given list of state values into a numerical value representing a combination of those states.
- Return type
int- Parameters
states (
listofint) – A list of the states values for which a bitmask should be returned.- Returns
A numerical value representing the given state values bitwise combined into a single value.
- classmethod getStateString(state)¶
Turns the given state into a string that represents it. e.g. WorkingSet.State.Included will return “Included”.
- Return type
str- Parameters
state (
int) – The state to convert to a string.- Returns
The string representation of the given state.
- classmethod getStatesFromBitmask(bitmask)¶
Turns the given numerical value representing a combination of states into a list of state values.
- Return type
listofint- Parameters
bitmask (
int) – A numerical value representing some state values bitwise combined into a single value.- Returns
A list of the states which match the given bitmask.
- classmethod getValidStates()¶
- Return type
listofint- Returns
A list of all valid states.
- classmethod getValidStatesBitmask()¶
- Return type
int- Returns
A bitmask representing all valid states.
- classmethod validate(state)¶
Validates the given state against the list of all valid states. If the given state is found to not be valid, a ValueError is raised.
- Parameters
state (
int) – The state to validate.- Raises
ValueError – When the given state is not valid.
- __init__()¶
Initializes an instance of the class.
- addAllowedStatesChangedCallback(callback)¶
Adds the given callback function to a list of functions that will be executed when the Working Set’s allowed states change.
The callback is expected to have the following signature:
function(allowedStates: list, workingSet: WorkingSet, sender: object)
Where:
allowedStatesis alistofintrepresenting the new allowed states for the Working SetworkingSetis theWorkingSetthat is causing the callbacksenderis theobjectthat caused the request to change the Working Set, orNoneif one wasn’t provided.
- Parameters
callback (
callable) – The callback to be called when the allowed states for the Working Set are changed.- Raises
ValueError – If the given callback doesn’t have the expected signature.
- addLocationStateChangedCallback(callback)¶
Adds the given callback function to a list of functions that will be executed when a location in the Working Set’s state changes.
The callback is expected to have the following signature:
function(locationStateChanges: list, workingSet: WorkingSet, sender: object)
Where:
locationStateChangesis alistoftuplesof the form(locationPath, oldState, newState).When the location path is first added to the Working Set, the oldState will be
NoneWhen the location path is removed from the Working Set, the newState will be
None
workingSetis theWorkingSetthat is causing the callbacksenderis theobjectthat caused the request to change the Working Set, orNoneif one wasn’t provided.
- Parameters
callback (
callable) – The callback to set to be called when locations are added, removed, or have their states changed in the Working Set.- Raises
ValueError – If the given callback doesn’t have the expected signature.
- addWorkingSetClearedCallback(callback)¶
Adds the given callback function to a list of functions that will be executed when the Working Set is cleared via a call to
clear().The callback is expected to have the following signature:
function(workingSet: WorkingSet)
Where:
workingSetis theWorkingSetthat is causing the callback
- Parameters
callback (
callable) – The callback to set to be called when the Working Set is cleared.- Raises
ValueError – If the given callback doesn’t have the expected signature.
- asGroupAttribute()¶
- Return type
- Returns
A group attribute containing child attributes representing the locations which have been added to the maps for this Working Set.
- clear(clearAllowedStates=False, sender=None, useCallbacks=True)¶
Removes all locations that are currently stored in the Working Set.
- Return type
bool- Parameters
sender (
objectorNone) – The object that initiated the change.clearAllowedStates (
bool) – A flag indicating whether locations with a subset of allowed states should have this restriction cleared.useCallbacks (
bool) – Whether or not to raise callbacks if any changes are made.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.
- clearLocations(locationPathOrPaths, clearAllowedStates=False, clearGiven=True, clearChildren=False, sender=None, useCallbacks=True)¶
Removes the given location path or location paths from the Working Set. Optionally also removes all states for child location paths of the given location paths.
- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths that should all be removed.clearAllowedStates (
bool) – Flag to control whether to clear the allowed states for the given location paths, and their children ifclearChildrenisTrue.clearGiven (
bool) – Flag to control whether to remove the state for the given location paths. IfclearChildren,clearGivenandclearAllowedStatesare allFalse, this function will have no effect.clearChildren (
bool) – Flag to control whether to clear all location paths beneath the given location paths.sender (
objectorNone) – The object that initiated the change.useCallbacks (
bool) – Whether or not to raise callbacks if any changes are made.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.
- containsLocation(locationPath)¶
- Return type
bool- Parameters
locationPath (
str) – The path of the location whose membership of this Working Set will be tested.- Returns
Trueif the given location path has an entry in the Working Set, otherwiseFalse.
- excludeLocations(locationPathOrPaths, allowedStates=None, sender=None)¶
Convenience function that calls
setLocationStates()withWorkingSet.State.Excludedas the given locations’ state.- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths that should all be set to Excluded.allowedStates (
intorlistofintorNone) – A list of states which the given locations should be allowed to have, or a single numerical value created from the bit-wise OR of such states, orNoneif the locations should be able to have any state.sender (
objectorNone) – The object that initiated the change.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.
- excludeLocationsWithChildren(locationPathOrPaths, allowedStates=None, sender=None)¶
Convenience function that calls
setLocationStates()withWorkingSet.State.ExcludedWithChildrenas the given locations’ state.- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths that should all be set to ExcludedWithChildren.allowedStates (
intorlistofintorNone) – A list of states which the given locations should be allowed to have, or a single numerical value created from the bit-wise OR of such states, orNoneif the locations should be able to have any state.sender (
objectorNone) – The object that initiated the change.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.
- classmethod fromGroupAttribute(groupAttribute, sender=None, useCallbacks=True, workingSetInstance=None)¶
Populates a Working Set from a GroupAttribute that was previously created via
asGroupAttribute().In addition to being able to be called as a class method, this is also available as an instance method, in the form
myWorkingSet.fromGroupAttribute(myGroupAttribute). When called as a class method, a newWorkingSetwill be constructed and populated from the GroupAttribute. When called as an instance method, the WorkingSet on which it was called will be cleared and updated using the GroupAttribute’s contents.- Return type
- Parameters
groupAttribute (
FnAttribute.GroupAttribute) – The GroupAttribute whose children should be used to populate the Working Set. This GroupAttribute is expected to have been created through a call toasGroupAttribute().sender (
objectorNone) – The object that initiated the change.useCallbacks (
bool) – Whether or not to raise callbacks if any changes are made.workingSetInstance (
WorkingSetorNone) – An optionalWorkingSetto (clear and) update using the GroupAttribute. If this isNone, a newWorkingSetwill be created and updated.
- Returns
The Working Set that was updated with the GroupAttribute.
- Raises
TypeError – If the given groupAttribute argument is not a valid
FnAttribute.GroupAttribute.
- getAllowedStates()¶
- Return type
listofint- Returns
A list of numerical values representing the states which this Working Set can contain.
- See
- getLocationAllowedStates(locationPath)¶
- Return type
listofint- Parameters
locationPath (
str) – The path of the location for which the allowed states should be returned.- Returns
A list of numerical values representing the states which the given location is allowed to have.
- getLocationState(locationPath)¶
- Return type
int- Parameters
locationPath (
str) – The location path to query the state for.- Returns
The state associated with the given location path. This will be
WorkingSet.State.Emptyif the location path is not found.
- getLocations(rootPath=None)¶
- Return type
listofstr- Parameters
rootPath (
strorNone) – The path beneath which (excluding itself) locations should be returned. IfNone, all locations in the tree are returned.- Returns
A list of all locations that are currently known by the Working Set, regardless of their assigned state.
- getLocationsAndStates(rootPath=None)¶
- Return type
listoftupleof(str, int)- Parameters
rootPath (
strorNone) – The path beneath which (excluding itself) locations should be returned. IfNone, all locations in the tree are returned.- Returns
A list of all locations and their states that are currently known by the Working Set.
- getLocationsByState(state, rootPath=None)¶
- Return type
listofstr- Parameters
state (
int) – The state to get the locations for.rootPath (
strorNone) – The path beneath which (excluding itself) matching locations should be returned. IfNone, all matching locations in the tree are returned.
- Returns
A list of all locations that are currently set to the given state.
- getMinimumAllowedStateForLocation(locationPath)¶
- Return type
intorNone- Parameters
locationPath (
str) – The path of the location whose minimum allowed state should be returned.- Returns
The state with the smallest value which is allowed for the given location
- getNumLocations(rootPath=None)¶
- Return type
int- Parameters
rootPath (
strorNone) – The path beneath which (excluding itself) the number of locations should be returned. IfNone, the total number of locations in the tree is returned.- Returns
The number of locations known by this Working Set.
- getRootLocations()¶
- Return type
listofstr- Returns
A list of all “root” (top most) locations stored in the Working Set.
- includeLocations(locationPathOrPaths, allowedStates=None, sender=None)¶
Convenience function that calls
setLocationStates()withWorkingSet.State.Includedas the given locations’ state.- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths that should all be set to Included.allowedStates (
intorlistofintorNone) – A list of states which the given locations should be allowed to have, or a single numerical value created from the bit-wise OR of such states, orNoneif the locations should be able to have any state.sender (
objectorNone) – The object that initiated the change.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.
- includeLocationsWithChildren(locationPathOrPaths, allowedStates=None, sender=None)¶
Convenience function that calls
setLocationStates()withWorkingSet.State.IncludedWithChildrenas the given locations’ state.- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths that should all be set to IncludedWithChildren.allowedStates (
intorlistofintorNone) – A list of states which the given locations should be allowed to have, or a single numerical value created from the bit-wise OR of such states, orNoneif the locations should be able to have any state.sender (
objectorNone) – The object that initiated the change.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.
- isIncludedLeafLocation(locationPath)¶
Determines whether the given location path is a leaf location with respect to the Working Set, i.e. if it is “Included”, does not include children by inheritance, and does not have any explicitly included children.
- Return type
bool- Parameters
locationPath (
str) – The location path to check.- Returns
Trueif the given location path is an included leaf location, otherwiseFalse.
- isStateAllowed(state)¶
- Return type
bool- Parameters
state (
int) – The state to test whether the Working Set can contain it.- Returns
Trueif the Working Set can contain the given state, otherwiseFalse.- See
- isStateAllowedForLocation(locationPath, state)¶
- Return type
bool- Parameters
locationPath (
str) – The path of the location to test whether it can have the given state.state (
int) – The state to test whether the given location is allowed to have.
- Returns
Trueif the given location path can have the given state, otherwiseFalse.
- iterateLocationAncestors(locationPath, includeLocation=False)¶
An iterator over tuples of absolute location paths and their assigned states, in decreasing depth order, for ancestors of the given location path whose state is not “Empty”.
- Return type
generator- Parameters
locationPath (
str) – The location path to test.includeLocation (
bool) – IfTrue, iterate fromlocationPath, rather than its parent.
- Returns
A
generatorobject that will walk over ancestor (location, state) tuples.
- matchesAnyChildren(locationPath, checkInheritance=False)¶
Determines whether any descendants of the given location path are included in the Working Set. By default, only checks whether descendants of the given location path are explicitly included.
- Return type
bool- Parameters
locationPath (
str) – The location path to search beneath for included locations.checkInheritance (
bool) – Flag indicating whether to also consider inclusion by inheritance from the given location path and its ancestors.
- Returns
Trueif any locations beneath the given location path match the Working Set, otherwiseFalse.
- matchesChildrenByInheritance(locationPath)¶
Determines whether children of the given location path would be included by inheritance (in the absence of local state).
- Return type
bool- Parameters
locationPath (
str) – The location path to check.- Returns
Trueif children of the given location path would be included by inheritance.
- matchesLocation(locationPath)¶
Determines whether the given location path is logically included, i.e. is explicitly included, or is included by inheritance and is not explicitly excluded.
- Return type
bool- Parameters
locationPath (
str) – The location path to test.- Returns
Trueif the location matches, otherwiseFalse.
- removeAllCallbacks()¶
Removes all currently registered callbacks from the Working Set.
- removeAllowedStatesChangedCallback(callback)¶
Removes a callback for when the Working Set’s allowed states are changed.
- Parameters
callback (
callable) – The callback function to remove.
- removeLocationStateChangedCallback(callback)¶
Removes a callback for when a location’s state is changed.
- Parameters
callback (
callable) – The callback function to remove.
- removeWorkingSetClearedCallback(callback)¶
Removes a callback for when a location’s state is changed.
- Parameters
callback (
callable) – The callback function to remove.
- setAllowedStates(allowedStates, sender=None)¶
Sets the allowed states of the Working Set. Note that a state of “Empty” is always implicitly allowed for a Working Set, as this represents a location not being present in the map.
- Return type
bool- Parameters
allowedStates (
intorlistofintorNone) – A list of states which the Working Set should be be able to contain, or a single numerical value created from the bit-wise OR of such states, orNoneif the Working Set should be able to contain any state.sender (
objectorNone) – The object that initiated the change.
- Returns
Trueif the allowed states of the Working Set changed, otherwiseFalseif no changes were made to the Working Set.- Note
Any locations currently in the map which have a state which is not in the given allowed states will be removed from the the Working Set.
- setLocationAllowedStates(locationPathOrPaths, allowedStates, sender=None)¶
Sets the allowed states of the given locations.
- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths whose allowed states should be set.allowedStates (
intorlistofintorNone) – A list of states which the given locations should be allowed to have, or a single numerical value created from the bit-wise OR of such states, orNoneif the locations should be able to have any state.sender (
objectorNone) – The object that initiated the change.
- Returns
Trueif any of the locations had their allowed states changed, otherwiseFalseno changes were made to the Working Set.
- setLocationStates(locationPathOrPaths, state, allowedStates=None, sender=None, useCallbacks=True)¶
Update the given location or list of locations to all have the given state value.
- Return type
bool- Parameters
locationPathOrPaths (
strorlistofstr) – Either a single location path string, or a list of location paths that should all be set to the given state.state (
int) – The state to set all the given location paths to.allowedStates (
intorlistofintorNone) – A list of states which the given locations should be allowed to have, or a single numerical value created from the bit-wise OR of such states, orNoneif the locations should be able to have any state.sender (
objectorNone) – The object that initiated the change.useCallbacks (
bool) – Whether or not to raise callbacks if any changes are made.
- Returns
Trueif any changes were made to the Working Set, otherwiseFalse.- Raises
ValueError – If the given state is not allowed for this Working Set.
Managing Working Sets¶
- class WorkingSetManager.WorkingSetManager¶
Bases:
objectClass implementing a global storage for
WorkingSetinstances. When a module wishes to access a Working Set they can callgetOrCreateWorkingSet()with the name of theWorkingSetinstance they are interested in.- LiveRenderUpdatesWorkingSetName = 'liveRenderUpdates'¶
- RenderWorkingSetName = 'render'¶
- ViewerVisibilityWorkingSetName = 'viewerVisibility'¶
- classmethod clearOnSceneChangeCallback()¶
Clears any previously set callback for
onSceneLoadoronNewSceneevents. This restores the default Working Set manager behaviour.
- classmethod clearWorkingSetOnSceneChange(workingSetName)¶
Adds the given named Working Set to the list of Working Sets to be cleared when an onNewScene or onSceneLoad callback occurs (when a new scene is opened, or when an existing scene is opened).
- Parameters
workingSetName (
str) – The name of the Working Set to add to the list of those to be cleared.
- static deleteWorkingSet(name)¶
- Parameters
name (
str) – The name of the Working Set to delete.
- static getOrCreateWorkingSet(name, sender=None)¶
- Return type
WorkingSet- Parameters
name (
str) – The name of the Working Set to get or create.- Returns
The existing Working Set, or a newly created Working Set, if none existed with the specified name.
- static getPersistentWorkingSetNames()¶
- Return type
listofstr- Returns
The names of Working Sets stored in the Working Set manager which cannot be deleted.
- static getWorkingSetNames()¶
- Return type
listofstr- Returns
The names of Working Sets stored in the Working Set manager.
- static isWorkingSetPersistent(name)¶
- Return type
bool- Parameters
name (
str) – The name of the Working Set to return whether it can be deleted.- Returns
Trueif the Working Set with the given name can be deleted, otherwiseFalse
- classmethod setOnSceneChangeCallback(callback)¶
Sets a callback which will be triggered when
onSceneLoadoronNewSceneevents take place. This allows users to customize the behaviour of the Working Set manager when scenes are changed. The callback is not expected to take any arguments.- Parameters
callback (
callable) – The callback to set.
- static setOpArgs(op, opArgName, workingSetName, txn=None, opType=None, opArgs=None, updateOnWorkingSetChanges=True)¶
Sets the Op args for the given Op to contain information about the Working Set of the given name, and optionally registers a callback to update this Op arg when the contents of the Working Set changes.
This allows Working Sets to be used to modify Op args without any UI interaction - e.g. in script mode.
- Parameters
op (
FnGeolibOp) – The Op which should have the contents of the Working Set of the given name passed into it as an Op arg.opArgName (
str) – The name of the Op arg into which the Working Set contents should be passed.workingSetName (
str) – The name of a Working Set registered in the Working Set manager.txn (
FnGeolib.GeolibRuntime.TransactionorNone) – An optional transaction to use. If given, no commits will be made to the runtime. IfNone, a new transaction will be created and committed to the runtime.opType (
strorNone) – The type of the Op. IfNone, the existing Op type for the given Op will be used.opArgs (
FnAttribute.GroupAttributeorNone) – The args for the Op. IfNone, the existing args for the given Op will be used.updateOnWorkingSetChanges (
bool) – A flag indicating whether a callback should be registered to update the given Op’s args when the contents of the Working Set of the given name changes.
- static setWorkingSetPersistent(name, persistent=True)¶
- Parameters
name (
str) – The name of the Working Set to set whether it can be deleted.persistent (
bool) – A flag indicating whether the Working Set with the given name name should be able to be deleted.