Context (hwx.inspire.gui)¶
A context is a GUI action that supports user interaction.
For example it can be used to create the workflow the lets a user create a fastener by selecting two parts.
The context is connected to the GUI by specifying the context class on the parameter of SpriteAction. When the SpriteAction is toggled on, the Context is created (if needed) and activated.
- Activate/Deactivate:
onFirstActivate
onActivate
onDeactivate
onExitAccept
getActiveContext
isactive
- Picking: get objects/features to create new objects
setPickable
onObjectsPicked
onObjectPicked
onPickListChanged
getPickedObjects
addPick
removePick
clearPickList
onPicking
isolatePicked
- Selecting: select objects for editing, popup editor, context menu, …
setSelectable
selectObjects
deselectObjects
clearSelectList
getSelectedObjects
onSelecting
onObjectsSelected
onSelectionChanged
- Pick/Select processing:
showPickedHovered
- Guide the user
showObjectToolTip
showHelpMessage
showHelpTopic
showStatusMessage
popupObjectEditor
popupManipulators
- Object utilities:
noteState
persistedAttributes
- Cursors: set cursor tell the user the ‘state’ of the context
setMainCursor
setCursor
registerCursor
waitCursor
- Messaging: show text message to tell the user the ‘state’ of the context
setHelpTopic
showHelpMessage
clearHelpMessage
showStatusMessage
clearStatusMessage
- Usage Tracking: send the usage message to the license server
reportUsage
reportContextUsage
- ModelListener methods
activateModelListener
deactivateModelListener
onObjectCreated
onObjectDeleted
onObjectModified
onNewProject
- Lower level draw utilities to change how objects are rendered
drawHovered
drawHighlighted
drawUnhighlighted
isHighlighed
setObjectColor
makeModelTransparent
setObjectTransparency
setVisualizationStyle
- Graphics view methods
redrawGraphics
getViewMatrix
fitView
- Optimization methods
disableColorPicking
- Lower level methods to respond to mouse/key signals
onKeyPress
onKeyRelease
onMousePress
onMouseRelease
onMouseMove
onMouseWheel
- KeyModifiers
ctrlDown
altDown
shiftDown
Properties¶
Public Methods¶
classmethod getActiveContext (cls)
classmethod getContextStack (cls)
classmethod popActive (cls)
classmethod popAll (cls)
classmethod reportContextUsage (cls, message, contextName=’’)
Destroy (self)
addEventTool (self, tool, before=False)
addPick (self, obj, makePickable=True)
canIsolate (self, objsToIsolate=None)
clearAllLists (self)
clearHelpMessage (self)
clearPickList (self, makeUnpickable=False)
clearSelectList (self, objects=None)
clearStatusMessage (self)
deselectObjects (self, objects=None)
disableColorPicking (self)
drawHighlighted (self, obj=None, highlight=True)
drawHovered (self, obj=None)
drawUnhighlighted (self, obj=None, highlight=False)
filterSelection (self, objects)
fitView (self, obj=None, padded=True)
getIsolatedPick (self)
getObjectsForIsolate (self, objsToIsolate=None)
getPickedObjects (self)
getSelectedObjects (self, beforeChange=False, active=True, **kwds)
getViewMatrix (self)
initializeCounter (self, counterActionName)
isAllowedToExit (self, exitControl)
isHighlighted (self, obj, highlighted=True)
isPickable (self, obj)
isolatePicked (self, forward=True, pickList=None, padded=None)
makeModelTransparent (self, transparent=True, filter=None)
onAboutToExit (self)
onAboutToSave (self)
onActivate (self)
onDeactivate (self)
onExitAccept (self)
onFirstActivate (self)
onKeyPress (self, event)
onKeyRelease (self, event)
onMouseDoubleClick (self, event)
onMouseMove (self, event)
onMousePress (self, event)
onMouseRelease (self, event)
onMouseWheel (self, event)
onNewProject (self)
onObjectCreated (self, obj)
onObjectDeleted (self, obj)
onObjectModified (self, obj, attr)
onObjectPicked (self, obj, why)
onObjectSelected (self, obj)
onObjectsPicked (self, objects, why)
onObjectsSelected (self, objects)
onPickListChanged (self)
onPicking (self, objects)
onSelecting (self, objects)
onSelectionChanged (self)
popThisBeforeNewPush (self, contextToBePushed)
popupManipulators (self, obj)
popupObjectEditor (self, obj)
popupObjectEditors (self, obj)
processPickListEvent (self, objects)
redrawGraphics (self, now=False)
registerCursor (self, name, icon, mask=’’, x=1, y=1)
removePick (self, obj, makeUnpickable=False)
reportUsage (self, message)
selectObjects (self, objects=None, clear=True)
setCursor (self, name, ignored=True)
setHelpTopic (self, helpTopic)
setMainCursor (self, icon=None, mask=None, x=1, y=1)
setObjectColor (self, obj, color)
setObjectTransparency (self, obj=None)
setPickable (self, pickable=None, ifvisible=False, style=None, **kwds)
setSelectable (self, selectable=None, ifvisible=True, style=None, **kwds)
setVisualizationStyle (self, style)
showHelpMessage (self, message, details=None, helpTopic=None, movie=None, movieTitle=’’, buttons=(), keys=(), width=None, relativeTo=None)
showObjectToolTip (self, obj=None)
showPickedHovered (self, pickedList, cursor=None)
showStatusMessage (self, msg, ms=None)
unsetCursor (self)
updateCounter (self)
waitCursor (self, message=None)
Property Details¶
- property altDown¶
Returns True if Alt key is pressed, False otherwise.
- property ctrlDown¶
Returns True if Control key is pressed, False otherwise.
- property isactive¶
Returns True if this is the current active context, False otherwise.
- property manipulators¶
Most recently popped up gui.Manipulators
- property metaDown¶
Returns True if Meta key is pressed, False otherwise.
- property modelIsTransparent¶
Returns True if the model is transparent, False otherwise.
- property objectEditorDialog¶
Most recently popped up gui.ObjectEditorDialog
- property persistedAttributes¶
Return values from the popup editor which are used to create objects
When a user creates an object, it is selected, the popup editor is displayed. We want to use the values he changed in editor when the next object is created.
- property shiftDown¶
Returns True if Shift key is pressed, False otherwise.
- property usageMessage¶
Returns and ses the usage message to be reported when the context gets activated.
Method Details¶
- classmethod getActiveContext(cls)¶
Returns the current active context.
- classmethod getContextStack(cls)¶
Returns list of pushed contexts.
- classmethod popActive(cls)¶
Removes active context.
- classmethod popAll(cls)¶
Pops all contexts to the idle context.
- classmethod push(cls, name=None, **kwds)¶
Pushs context onto context stack, activates the context.
- param name
The name of context to push. Defaults to calling context.
- type name
str
- param **kwds
Forwarded to context’s onActivate method
- returns
The active context.
- rtype
Context
- classmethod reportContextUsage(cls, message, contextName='')¶
Reports the usage message to the context.
- param message
The message to be reported.
- type message
str
- param contextName
The context to send the message to.
- type contextName
str
- Destroy(self)¶
Destroys this context.
- addEventTool(self, tool, before=False)¶
Add event tool to the context.
- param tool
The tool to be added to context.
- type tool
EventTool
- param before
Determines whether to add the tool in the beginning of events list.
- type before
bool
- addPick(self, obj, makePickable=True)¶
Add the specified object to the PickedList.
- param obj
The object to be added to the PickedList.
- type obj
Union[Named, Feature, Hole]
- param makePickable
Determines whether the object is pickable.
- type makePickable
bool
- canIsolate(self, objsToIsolate=None)¶
Determines if the objects can be isolated.
- param objsToIsolate
Valid choices are - “selectable” - “picked” - “pickable”
- type objsToIsolate
str
- returns
True if the objects can be isolated, False otherwise.
- rtype
bool
- clearAllLists(self)¶
Clears the PickedList and select list.
- clearHelpMessage(self)¶
Undisplays the help message.
- clearPickList(self, makeUnpickable=False)¶
Removes all picked objects from the PickedList.
- param makeUnPickable
Determines whether the object is unpickable.
- type makeUnPickable
bool
- clearSelectList(self, objects=None)¶
Deselects all the selected objects.
- param objects
List of objects to be deselected.
- type objects
list[Union[Named, Feature, Hole]]
- clearStatusMessage(self)¶
Removes the message from the status bar if any.
- deselectObjects(self, objects=None)¶
Deselects the specified objects from the selectList.
- param objects
List of objects to be deselected.
- type objects
list[Union[Named, Feature, Hole]]
- disableColorPicking(self)¶
Disables color based picking while in this context.
Color based picking is the default for picking objects in the graphics view. It is faster than non-color picking, but it can slow down redrawing of the graphics.
You might want to disable it for contexts that require rapid redraws, like animation.
- drawHighlighted(self, obj=None, highlight=True)¶
Renders objects highlighted to show the user objects of interest.
- param obj
The objects to be highlighted.
- type obj
list[Union[Named, Feature, Hole]]
- param highlight
Determines whether to highlight the objects.
- type highlight
bool
- drawHovered(self, obj=None)¶
Draws the object in hover (prehighlight) mode.
It ‘unhovers’ the previous ‘hovered’ from this call.
- param obj
The object to be hovered. Defaults to None, and unhovers all objects.
- type obj
Union[Named, Feature, Hole]
- drawUnhighlighted(self, obj=None, highlight=False)¶
Render objects highlighted to show the user objects of interest.
- param obj
The objects to be highlighted.
- type obj
list[Union[Named, Feature, Hole]]
- param highlight
Determines whether to highlight the objects.
- type highlight
bool
- filterSelection(self, objects)¶
Overload this method to filter selectable objects when selecting from the browser or tables.
- param objects
The list of objects to process events.
- type objects
PickedList
- returns
False to allow other listeners to process the event. True to block.
- rtype
bool
- fitView(self, obj=None, padded=True)¶
Fits view to the specified objects.
- param obj
Object(s) to fit the view to.
- type obj
list[Union[Named, Feature, Hole]]
- param padded
The spacing around objects. True means 4.0 for Features and 1.5 for Objects. False means 1.
- type padded
bool, float
- getIsolatedPick(self)¶
Returns the isolated object(s).
- getObjectsForIsolate(self, objsToIsolate=None)¶
Returns a list of objects that can be isolated.
- param objsToIsolate
Valid choices are - “selectable” - “picked” - “pickable”
- type objsToIsolate
str
- returns
The objects that can be isolated.
- rtype
PickList
- getPickedObjects(self)¶
Returns an ObjectList with the picked objects.
- getSelectedObjects(self, beforeChange=False, active=True, **kwds)¶
Returns an ObjectList with the selected objects.
- param beforeChange
Determines whether to just return the current selected objects.
- type beforeChange
bool
- param active
Determines whether to include only active objects.
- type active
bool
- param **kwds
Keyword arguments for filtering with isa.
- getViewMatrix(self)¶
Returns a Matrix44 to convert from world to view coordinates.
- initializeCounter(self, counterActionName)¶
Gets the SpriteCounterAction by this name and automatically manages it.
- param counterActionName
The name of the SpriteCounterAction.
- type counterActionName
str
- isAllowedToExit(self, exitControl)¶
Called when the user RightMouse clicks or presses escape.
- param exitControl
Valid choices are: - self.RMB_RELEASE - self.ESC_KEY - self.F1_KEY
- type exitControl
int
- returns
[description]
- rtype
[type]
- isHighlighted(self, obj, highlighted=True)¶
Checks if the specified object is drawn highlighted.
- param obj
The objects to be checked.
- type obj
list[Union[Named, Feature, Hole]]
- param highlighted
if True returns True if all object are highlighted. If False return Trues if any of the objects is highlighted.
- type highlighted
bool
- returns
True if one or all object are highlighted, False otherwise.
- rtype
bool
- isPickable(self, obj)¶
Checks if an object is pickable via the PickList or SelectList.
- param obj
The object to be checked.
- type obj
Union[Named, Feature, Hole]
- param filter
The funtion used to filter objects.
- type filter
function
- returns
True if the object is pickable, False otherwise.
- rtype
bool
- isolatePicked(self, forward=True, pickList=None, padded=None)¶
Isolate the next/prev object from the pickList.
Tours the pickList - or the selectable objects, if something is selected. And zooms in on each of the items in the pickList, making that item the only one the user can pick.
- param forward
Determines whether to turn off isolation. None turns off isolation.
- type forward
bool
- param pickList
A PickedList that contains the single or box picked objects.
- type pickList
PickedList
- param padded
The spacing around objects. True means 4.0 for Features, 1.5 for Objects. False means 1.
- type padded
bool | float
- makeModelTransparent(self, transparent=True, filter=None)¶
Makes pickable/selectable objects stand out by making the rest of the objects transparent.
- param transparent
Determines whether to make other objects transparent.
- type transparent
bool
- param filter
The function used to filter objects.
- type filter
function
- onAboutToExit(self)¶
Overload if you need to stop processing something when the user tries to exit the application during a long loop, like doing an analysis.
- onAboutToSave(self)¶
Overload to do something right before Inspire saves an stmod.
If you have a GeneralObject sitting around storing things you don’t want saved in to the stmod, for example.
- onActivate(self)¶
Overload to initialize your context each time it is activated.
- onDeactivate(self)¶
Overload to cleanup your context when it is being deactivated.
- onExitAccept(self)¶
Overload to execute code on right mouse button exit.
Return True to prevent the context from being deactivated.
- onFirstActivate(self)¶
Overload to initialize your context the first time it is activated.
- onKeyPress(self, event)¶
Overload this method to define behaviour when a key is pressed.
- param event
The event being processed.
- type event
Event
- onKeyRelease(self, event)¶
Overload this method to define behaviour when a key is released.
- param event
The event being processed.
- type event
Event
- onMouseDoubleClick(self, event)¶
Overload this method to define behaviour on mouse double click.
- param event
The event being processed.
- type event
Event
- onMouseMove(self, event)¶
Overload this method to define behaviour when mouse moves.
- param event
The event being processed.
- type event
Event
- onMousePress(self, event)¶
Overload this method to define behaviour when mouse is pressed.
- param event
The event being processed.
- type event
Event
- onMouseRelease(self, event)¶
Overload this method to define behaviour when mouse is released.
- param event
The event being processed.
- type event
Event
- onMouseWheel(self, event)¶
Overload this method to define behaviour when mouse wheel is active.
- param event
The event being processed.
- type event
Event
- onNewProject(self)¶
Overload if you need to clean up when a new model is loaded.
- onObjectCreated(self, obj)¶
Overload if interested when an object is created after ListenForModelChanges is called.
- param obj
The event being processed.
- type obj
Event
- onObjectDeleted(self, obj)¶
Overload if interested when an object is deleted after ListenForModelChanges is called.
- param obj
The event being processed.
- type obj
Event
- onObjectModified(self, obj, attr)¶
Overload if interested when an object is modified after ListenForModelChanges is called.
- param obj
The event being processed.
- type obj
Event
- param attr
Name of the attribute that was modified.
- type attr
str
- onObjectPicked(self, obj, why)¶
Called when a pickable object is picked.
This is passed so connector contexts can either:
pick 2 features to create the connector: len (self.pickList) == 2
pick the same feature twice to connect to ground: why=”inlist”
- param objects
A PickedList that contains the single or box picked objects.
- type objects
PickedList
- param why
Valid choices are: - “add” - “remove” - “inlist”
- type why
str
- onObjectSelected(self, obj)¶
Called when an object is selected from any view.
Overload this method to process the selectList when object is selected.
- param obj
The selected object.
- type obj
Union[Named, Feature, Hole]
- onObjectsPicked(self, objects, why)¶
Called when one or more pickable object are picked.
Utility method that calls onObjectPicked for each object in objects. Unless you specify windowing in setPickable it may be easier to overload onObjectPicked instead of this method.
- param objects
A PickedList that contains the single or box picked objects.
- type objects
PickedList
- param why
Valid choices are: - “add” - “remove” - “inlist”
- type why
str
- onObjectsSelected(self, objects)¶
Called when objects are selected from any view.
- param objects
The list of selected objects.
- type objects
PickedList
- onPickListChanged(self)¶
Called when an object is added to/removed from the pickList.
- onPicking(self, objects)¶
Overloaded in derived context to process a pick event.
Called on any mouse move/press/release if any pickable objects are under the mouse or inside the pick window.
- param objects
A PickedList that contains the single or box picked objects.
- type objects
PickedList
- onSelecting(self, objects)¶
Overload this method to process any/all selectList events.
- param objects
The list of selected objects.
- type objects
SelectList
- returns
False to allow other listeners process the event. True to block.
- rtype
bool
- onSelectionChanged(self)¶
Overload this method to process the selectList when it changes.
- pop(self, **kwds)¶
Pops context off context stack, deactivating the context.
- param **kwds
Forwarded to context’s onDeactivate method
- popThisBeforeNewPush(self, contextToBePushed)¶
Specify if the passed context can be pushed on top of the current one.
By default this returns False unless the contextToBePushed._stackable = True.
Overload to support a custom stack of contexts.
- param contextToBePushed
Context about to be pushed.
- type contextToBePushed
gui.Context
- returns
bool
- popupManipulators(self, obj)¶
Overload to popup 1 or more gui.Manipulators when an object is selected.
- param obj
The last selected object.
- type obj
Named
- popupObjectEditor(self, obj)¶
Overload to popup a gui.ObjectEditorDialog when an object is selected.
- param obj
the selected object.
- type obj
Named
- popupObjectEditors(self, obj)¶
Overload this to popup editors when an object of interest is selected.
Editors are ObjectEditorDialog and Manipulator subclasses.
This method defaults to calling popupObjectEditor and popupManipulators so you can optionally implement those instead.
- param obj
The last selected object.
- type obj
Named
- processPickListEvent(self, objects)¶
Called on any mouse move/press/release from the PickList.
- param objects
A PickedList that contains the single or box picked objects.
- type objects
PickedList
- redrawGraphics(self, now=False)¶
Force a redraw of the graphics.
- param now
Determines whether to redraw immediately or on idle.
- type now
bool
- registerCursor(self, name, icon, mask='', x=1, y=1)¶
Cache cursor for lazy create in setCursor.
- param icon
The path to icon file.
- type icon
str
- param mask
The cursor mask.
- type mask
str
- param x
The x location where to place the cursor.
- type x
int
- param y
The y location where to place the cursor.
- type y
int
- removePick(self, obj, makeUnpickable=False)¶
Removes the specified object from the PickedList.
- param obj
The object to be removed from the PickedList.
- type obj
Union[Named, Feature, Hole]
- param makeUnPickable
Determines whether the object is unpickable.
- type makeUnPickable
bool
- reportUsage(self, message)¶
Report the usage message within this context.
- param message
message to be reported.
- type message
str
- selectObjects(self, objects=None, clear=True)¶
Selects the specified objects, if they are instances of the types specified in setSelectable.
- param objects
List of objects to be selected.
- type objects
list[Union[Named, Feature, Hole]]
- param clear
Determines whether to add the objects to selectList.
- type clear
bool
- setCursor(self, name, ignored=True)¶
Set the named cursor if it is not the current one.
- param name
The name of the cursor.
Valid choices are: - “” : The default cursor (arrow) - “MAIN” : show the user what context he is in - ‘+’ : show an object that can be added to the PickedList - ‘-’ : show an object that can be removed from the PickedList - ‘+- : show an object that can be toggled (windowMode) - ‘x’ : show an object that is in the PickedList - .png : The name of an icon file - other : The name of a registered cursor
- type name
str
- param ignored
For backwards compatibility.
- type ignored
bool
- setHelpTopic(self, helpTopic)¶
Sets the help topic to display when F1 is pressed.
- param helpTopic
The help topic to display.
- type helpTopic
str
- setMainCursor(self, icon=None, mask=None, x=1, y=1)¶
Sets the cursor to show what context the user is in.
- param icon
The path to icon file.
- type icon
str
- param mask
The cursor mask.
- type mask
str
- param x
The x location where to place the cursor.
- type x
int
- param y
The y location where to place the cursor.
- type y
int
- setObjectColor(self, obj, color)¶
Draw the unhighlighted object(s) in the specified color.
- param obj
Object(s) to apply the color to
- type obj
Named
- param color
The color to be applied.
- type color
str, list[float]
- setObjectTransparency(self, obj=None)¶
Ensure the transparency of the specfied object is correct or all objects if no object is specified.
- param obj
The object to checked for transparency. If it is None, apply to all objects.
- type obj
Union[Named, Feature, Hole]
- setPickable(self, pickable=None, ifvisible=False, style=None, **kwds)¶
Specifies the object(s)/types(s) that are pickable.
Picked objects are generally used to specify what is passed to the creation of an object. For example, when creating a motor the user picks two features or a fastener.
When objects are picked the onObjectsPicked method is called.
- param pickable
The types/objects that are pickable.
- type pickable
set
- param ifvisible
Determines whether to pick only visible objects.
- type ifvisible
bool
- param style
The picking style.
- type style
str
- param **kwds
TogglePickingStyle kwds, i.e., - windowing = True, # override default - filter = None, # standard setPickable filter - attribute = None, # the object attribute to toggle
- setSelectable(self, selectable=None, ifvisible=True, style=None, **kwds)¶
Determines what objects/types can be selected by the user.
Selected objects are generally the objects being created by the context and when the object is created it is selected. By default the selected objects popup an editor and/or manipulators to modify its values.
Objects can be selected from the browser, tables or the graphics view.
- param selectable
The types and/or objects that can be selected.
- type selectable
list
- param ifvisible
Determines whether to be invisible, when selecting from the graphics view.
- type ifvisible
bool
- param style
The select style.
- type style
str
- param **kwds
Keyword arguments for SelectList.setSelectable.
- setVisualizationStyle(self, style)¶
Internal method to enable context specific rendering.
Supported modes are: - RigidGroupContext
- param style
Name of style (rigidgroup).
- type style
str
- showHelpMessage(self, message, details=None, helpTopic=None, movie=None, movieTitle='', buttons=(), keys=(), width=None, relativeTo=None)¶
Puts a text message under the guide bar to inform the user.
- param message
The message to be printed.
- type message
str
- param details
The longer message that gets displayed when user clicks on message.
- type details
str
- param helpTopic str)
The help topic to display when F1 is pressed.
- param movie
The path to an animated gif file.
- type movie
str
- param movieTitle
The movie title.
- type movieTitle
str
- param buttons
A list of pairs (button, text) where button is a string, which contains a combination of LeftButton, MidButton, RightButton, ShiftButton, ControlButton or AltButton.
- type buttons
list
- param keys
A list of (key, text) where key is the string name.
- type keys
list
- param width
The width of message in pixels.
- type width
int
- param relativeTo
The place where to locate the message.
- type relativeTo
Widget
- showObjectToolTip(self, obj=None)¶
Set tool tip in the graphics window when hovering over an object to let the user know what the object is.
- param obj
The object being hovered.
- type obj
Union[Named, Feature, Hole]
- showPickedHovered(self, pickedList, cursor=None)¶
Draws the objects hovered and sets the cursor, if there are any objects in the pickedList and hovering.
- param pickedList
The list of picked objects.
- type pickedList
PickedList
- param cursor
The cursor type.
- type cursor
str
- returns
False if pickedList is empty or hovering, True otherwise.
- rtype
bool
- showStatusMessage(self, msg, ms=None)¶
Shows a message in the status bar.
- param msg
The message to be shown.
- type msg
str
- param ms
Indicates the miliseconds that the message will stay for.
- type ms
int
- unsetCursor(self)¶
Reset the cursor to the default cursor.
- updateCounter(self)¶
Updates the value that the CounterAction shows.
- waitCursor(self, message=None)¶
Python context for displaying a wait cursor.
- param message
The message to be displayed in the status bar.
- type message
str