Public Member Functions | Public Attributes | List of all members
INIXApp.ResourceInstance Class Reference

Represents a resource and manages its state. More...

Inherits object.

Public Member Functions

def GetParent
 Returns the resource instance for the parent resource. More...
 
def GetState
 Returns the state of this resource. More...
 
def GetMethodCallIncoAction
 Constructs an INCO event action that calls a method of this object. More...
 
def PutOrCreateIncoVariable
 Set a custom INCO variable in the application menu plugin. More...
 
def FindResource
 Get the absolute path of a specified resource. More...
 
def AddResource
 Insert an additional resource into the application. More...
 
def Remove
 Removes this resource from the application. More...
 
def GetTarget
 Returns the target for this resource. More...
 
def GetPrefsFolder
 Resource-specific preferences folder. More...
 
def Select
 Displays this resource and selects its work place. More...
 
Methods to be Overridden by Subclasses
def OnDidEnter
 Called when this resource is displayed. More...
 
def OnWillLeave
 Called when this resource ceases to be displayed. More...
 
def OnDidCreatePage
 Called after the page of this resource is created. More...
 
def OnWillDestroyPage
 Called before the page of this resource is destroyed. More...
 
def OnDidLoad
 Called after this resource is loaded. More...
 
def OnWillUnload
 Called before this resource is unloaded. More...
 
def OnDidPreload
 Called after this resource is preloaded. More...
 
def PopulateCommandsMenu
 Called to build the commands menu of this resource. More...
 
def OnTargetChanged
 Called when the target for this resource changes. More...
 
def GetTargets
 Called to fill the target selection menu. More...
 
def GetDefaultTarget
 Determine the initial target to use with this resource. More...
 
Private Methods - Don't Use
def GetResourcesSearchPath
 
def AddSubresource
 
def Duplicate
 
def Load
 
def Unload
 
def Display
 
def Undisplay
 
def CreateCommandsMenu
 
def DestroyCommandsMenu
 
def UpdateDefaultResources
 
def GetNamePath
 
def AddCommands
 
def OnExpandDynamicMenu
 
def RunDeprecatedEventScript
 
def SetWindowTitle
 

Public Attributes

 indexPath
 The index path of this resource in the application menu. More...
 
 title
 The human-readable title of this resource. More...
 
 longtitle
 A long version of the human-readable title of this resource. More...
 
 inheritanceChain
 Load locations of this resource and the ones it inherits from. More...
 
 loadLocation
 The load location (absolute file system path) of this resource. More...
 
 name
 The disambiguated file system name of this resource. More...
 
 usedBinaries
 The UsedBinaries dictionary from resource.prp. More...
 
 resourceDefaults
 The ResourceDefaults dictionary from resource.prp. More...
 
 version
 The Version string from resource.prp. More...
 
 children
 A list containing the resource instances for the subresources of this resource. More...
 
 childrenByName
 A dictionary mapping the names of the subresources of this resource to their resource instances. More...
 
 workPlace
 The INCO path of the work place this resource is currently displayed in. More...
 
 pageIncoPath
 The INCO path of the page of this resource. More...
 
 commandsIndexPath
 The index path of the commands menu of this resource, if any. More...
 

Detailed Description

Represents a resource and manages its state.

For every resource that is present in the application menu, an instance of this class (or a subclass) is kept by INIXApp. Given its index path, it can be retrieved by GetResourceInstance().

Member Function Documentation

def INIXApp.ResourceInstance.AddResource (   self,
  aResourceName,
  abUseExisting,
  abDisplay = True 
)

Insert an additional resource into the application.

The new resource is inserted as a subresource of this resource, after any existing subresources. If it is located in any of the folders searched by FindResource(), aResourceName can be a relative path, otherwise it must be absolute (obtained e.g. from calling FindResource() on a different resource instance). If abUseExisting is True, this resource is first searched for an existing subresource with the given load location, which is used if found. If abUseExisting is False, a new resource is inserted in any case. The new resource is displayed, unless abDisplay is False, and its ResourceInstance is returned.

def INIXApp.ResourceInstance.FindResource (   self,
  aResourceName 
)

Get the absolute path of a specified resource.

If aResource is a relative path, search for it first in the _Resources_ folders of this resource and its bases in the inheritance chain, then in all _Resources_ folders in the path up the file system hierarchy from this resource's load location (i.e. two resources that live in the same Resources folder can refer to each other by their simple names), then in a possible folder named "resource" above that (assumed to be an uninstalled version of $(INDEL_ROOT)/share/resource), and finally in $(INDEL_ROOT)/share/resource. Absolute paths are returned as-is, provided they name a valid resource. Returns None if no valid resource was found.

def INIXApp.ResourceInstance.GetDefaultTarget (   self)

Determine the initial target to use with this resource.

This method is called on the top-level resource when it is entered for the first time and no saved state exists yet (e.g. on a fresh installation). The string it returns is then used as the target of the application, i.e. put into the global Prop.Target variable.

This implementation returns the first target registered at the INCOServer, preferring types in the order PCIMaster, NETMaster, INCOSio, PPCMaster, Alias, RemoteMaster. Subclasses may want to override it to return e.g. "..." or "" instead.

def INIXApp.ResourceInstance.GetMethodCallIncoAction (   self,
  aMethodName,
  aArguments 
)

Constructs an INCO event action that calls a method of this object.

Parameters
aMethodNameName of the method to call.
aArguments(optional variable argument list) Arguments to the method. Must be strings.

The string generated by this method looks about like this:

Python> callresourcemethod.py i_3_1 MyMethod "Argument 1" "Argument 2"

but its exact form is considered an implementation detail.

def INIXApp.ResourceInstance.GetParent (   self)

Returns the resource instance for the parent resource.

None if this is the top-level resource.

def INIXApp.ResourceInstance.GetPrefsFolder (   self)

Resource-specific preferences folder.

Returns the absolute path to a folder where this resource may store arbitrary preferences files (for things that can't be stored in persistent resource properties). This folder is not used by INIXApp internally. The folder may or may not exist, the caller is responsible for creating it if necessary.

def INIXApp.ResourceInstance.GetState (   self)

Returns the state of this resource.

The return value is one of the following constants:

  • INIXApp.STATE_PRELOADED: The resource is listed in the menu and its resource.prp file has been read, but its list of subresources hasn't been evaluated yet. children and childrenByName are None.
  • INIXApp.STATE_LOADED: Resource properties have been fully loaded and user preferences restored, the subresources are at least in PRELOADED state and are listed in children and childrenByName. workPlace and pageIncoPath are None.
  • INIXApp.STATE_DISPLAYED: The resource is displayed in a work place. workPlace is set, and pageIncoPath is set if the resource has a page.
  • INIXApp.STATE_HIDDEN: Only occurs for resources that have a page and whose UnloadOnLeave property is set to True. The resource is not displayed anymore, but its page is still hidden in a work place. workPlace is None, pageIncoPath is set.

See the state diagram in Resource Life Cycle for details about these states and their transitions.

def INIXApp.ResourceInstance.GetTarget (   self)

Returns the target for this resource.

If your resource has a notion of "the target", this is how you should query it. Returns the contents of the Prop.Target variable of the first among this resource's work place, its parent plugin, grandparent etc. for which it is not empty. If the resource is not currently displayed, returns the contents of the global Prop.Target variable.

Also registers the resource to be notified of changes to the target by calls to OnTargetChanged() while the resource is being displayed in its current work place. Therefore, if a resource is interested in such notifications, it should call GetTarget() at least once in its OnDidEnter method.

def INIXApp.ResourceInstance.GetTargets (   self,
  aSupertarget 
)

Called to fill the target selection menu.

This method is called on the top-level resource when the user brings up the target selection menu. aSupertarget is "" to get the top-level targets (the server ("...") and its immediate subtargets) or a target path to get the subtargets of that specific target. Returns a list of target names (not paths).

This implementation fetches all available targets. A common reason for overriding this method in a subclass is restricting the set of available targets by calling the superclass and then filtering the returned list.

Such implementations should not attempt to communicate with all targets in the list, as some might not be online and waiting for communication timeouts would block the UI for too long. Communication with aSupertarget is acceptable (provided that it stops after the first communication timeout).

def INIXApp.ResourceInstance.OnDidCreatePage (   self)

Called after the page of this resource is created.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified every time the page of this resource is created, after page properties have been restored from defaults and persistent storage. Not called if this resource does not have a page.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnDidCreatePage(self)).

def INIXApp.ResourceInstance.OnDidEnter (   self)

Called when this resource is displayed.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified every time the resource is displayed.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnDidEnter(self)).

def INIXApp.ResourceInstance.OnDidLoad (   self)

Called after this resource is loaded.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified when this resource is loaded, after resource properties have been restored from defaults and persistent storage.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnDidLoad(self)).

def INIXApp.ResourceInstance.OnDidPreload (   self)

Called after this resource is preloaded.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified when this resource is preloaded and has appeared in the application menu.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnDidPreload(self)).

def INIXApp.ResourceInstance.OnTargetChanged (   self,
  aNewTarget 
)

Called when the target for this resource changes.

Override this to be notified of changes to "the target" (see GetTarget()) while the resource is displayed in a work place.

For efficiency, this will only be called after the resource has announced interest by calling GetTarget() at least once since being displayed in the current work place (usually, in the OnDidEnter() method). Not called while the resource is not displayed.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnTargetChanged(self, aNewTarget)).

def INIXApp.ResourceInstance.OnWillDestroyPage (   self)

Called before the page of this resource is destroyed.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified every time the page of this resource is destroyed, before page properties have been saved to persistent storage. Not called if this resource does not have a page.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnWillDestroyPage(self)).

def INIXApp.ResourceInstance.OnWillLeave (   self)

Called when this resource ceases to be displayed.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified every time the resource disappears from view.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnWillLeave(self)).

def INIXApp.ResourceInstance.OnWillUnload (   self)

Called before this resource is unloaded.

Override this in your ResourceInstance subclass (see The resource.py Script) to be notified when this resource is unloaded at application shutdown, before resource properties have been saved to persistent storage.

See Resource Life Cycle for details on the calling sequence of these methods.

The overriding implementation must include a call to the superclass (ResourceInstanceBase.OnWillUnload(self)).

def INIXApp.ResourceInstance.PopulateCommandsMenu (   self)

Called to build the commands menu of this resource.

This method is called after this resource has created its top-level command menu item, in an undifferentiated state (i.e. no Action or OnExpand set yet), and stored its index path in self.commandsIndexPath. It is expected to fill in the contents (usually, subitems) of this menu item.

The default implementation in ResourceInstance fills in the commands defined in resource.prp. Therefore, if you override this in your ResourceInstance subclass (see The resource.py Script), and have commands defined in resource.prp, your implementation should include a call to the superclass (ResourceInstanceBase.PopulateCommandsMenu(self)).

If, after the return from this method, the commands menu has neither subitems nor an OnExpand action, it is removed from the menu again.

Overriding this method is one possibility of creating a dynamic commands menu at run time. The other is defining the top-level item as DYNAMIC in resource.prp (see Commands). In particular, the PopulateCommandsMenu approach is the appropriate one when the menu can be empty or not depending on run-time conditions, since the DYNAMIC one would not hide an empty menu.

def INIXApp.ResourceInstance.PutOrCreateIncoVariable (   self,
  aKey,
  aValue 
)

Set a custom INCO variable in the application menu plugin.

The user data variable App.Menu.Items.<self.indexPath>.<aKey> is created if it does not exist yet and set to value aValue.

Returns the INCO path of the variable.

def INIXApp.ResourceInstance.Remove (   self)

Removes this resource from the application.

Leaves the resource if it is displayed, saves persistent resource properties, and removes the resource from the menu.

After this call, the resource instance is considered to be in an unusable final state and no further method calls or attribute accesses should be made on it.

def INIXApp.ResourceInstance.Select (   self,
  abNewWorkPlace = False 
)

Displays this resource and selects its work place.

For abNewWorkPlace absent or False, the resource, if not visible already, is opened in an existing work place, as if its button in the menu had been clicked (in the default state of the work place switch). For abNewWorkPlace True, it or a duplicate is opened in a new work place, as if the menu button had been clicked with the shift key pressed. Finally, its work place is selected.

Member Data Documentation

INIXApp.ResourceInstance.children

A list containing the resource instances for the subresources of this resource.

Sorted in the same order as the resources appear in the menu. Empty if there are no subresources.

This property is only filled in for resources in LOADED state (see GetState()) or later, in PRELOADED state is is None.

INIXApp.ResourceInstance.childrenByName

A dictionary mapping the names of the subresources of this resource to their resource instances.

This property is only filled in for resources in LOADED state (see GetState()) or later, in PRELOADED state is is None.

INIXApp.ResourceInstance.commandsIndexPath

The index path of the commands menu of this resource, if any.

Set if commands for this resource are present in the commands menu, None otherwise.

INIXApp.ResourceInstance.indexPath

The index path of this resource in the application menu.

Uniquely identifies the resource as long as it is present in the current application (but not necessarily any longer, in particular across application launches, if resources were added and removed at run time).

INIXApp.ResourceInstance.inheritanceChain

Load locations of this resource and the ones it inherits from.

A list of the load locations (absolute file system paths) of this resource, the one specified in its Base property, the base's base etc., in this order.

INIXApp.ResourceInstance.loadLocation

The load location (absolute file system path) of this resource.

(first element of inheritanceChain, only presented as a separate attribute for convenience).

INIXApp.ResourceInstance.longtitle

A long version of the human-readable title of this resource.

Used for the window title if this is the top-level resource.

Possibly localized in a future version of INIXApp.

INIXApp.ResourceInstance.name

The disambiguated file system name of this resource.

This is the last path component of loadLocation, possibly with an appended number to make it unique among its sibling resources.

See also
childrenByName
INIXApp.ResourceInstance.pageIncoPath

The INCO path of the page of this resource.

Set if there is a page and it is either DISPLAYED or HIDDEN (see GetState()), None otherwise.

INIXApp.ResourceInstance.resourceDefaults

The ResourceDefaults dictionary from resource.prp.

There is rarely a need to access this directly. Once a resource is in STATE_LOADED, the properties defined in here are available as attributes of the resource instance, with their current values restored from persistent storage. Only use this if you need to know the default value of a property (rather than the current one) and/or if you need to deal with the possibility of the resource still being in STATE_PRELOADED.

Don't modify this or you may mess up persistence of resource properties.

INIXApp.ResourceInstance.title

The human-readable title of this resource.

Used in the application menu and various other places.

Possibly localized in a future version of INIXApp.

INIXApp.ResourceInstance.usedBinaries

The UsedBinaries dictionary from resource.prp.

A list of all used binaries. On every binary the option switch to show its version should be included. This Version will be displayed in the About INIX box.

Don't modify this or you may mess up persistence of resource properties.

INIXApp.ResourceInstance.version

The Version string from resource.prp.

INIXApp.ResourceInstance.workPlace

The INCO path of the work place this resource is currently displayed in.

None if the resource is not displayed.


The documentation for this class was generated from the following file:

Generated by doxygen 1.8.8