session: Application session support

A session provides access to most of the application’s state. At a minimum, it does not include the operating system state, like the current directory, nor the environment, nor any Python interpreter state – e.g., the exception hook, module globals, etc.

Code should be designed to support multiple sessions per process since it is easier to start with that assumption rather than add it later. Possible uses of multiple sessions include: one session per tabbed graphics window, or for comparing two sessions.

Session data, ie., data that is archived, uses the State API.

class Scenes(session)

Bases: chimera.core.state.State

Manage scenes within a session

delete(name)

Delete named scene

metadata(name)

Return scene’s metadata

names()

Return list of scene names

restore(name)

Restore session to the state represented in the named scene.

save(name, metadata=None)

Save snapshot of current state in a scene.

The state consists of the registered attributes that support the State API. The metadata should be a dictionary of metadata about the scene. For example, a thumbnail image. metadata contents must be serializable like State data.

class Session

Bases: object

Session management

The metadata attribute should be a dictionary with information about the session, e.g., a thumbnail, a description, the author, etc.

To preemptively detect problems where different tools want to use the same session attribute, session attributes may only be assigned to once, and may not be deleted. Attributes that support the State API are included Consequently, each attribute is an instance that supports the State API.

Each session attribute, that should be archived, must implement the State API, and is then automatically archived.

class_name_of_unique_id(uid)

Extract class name associated with unique id for messages

class_of_unique_id(uid, base_class)

Return class associated with unique id

Parameters:

uid : unique identifer for class

base_class : the expected base class of the class

tool_name : internal name of tool that provides class

If not given, then it must be in the chimera core.

tool_version : the tool’s version

If not given, then it must be in the chimera core.

Raises:

KeyError

metadata = None

session metadata

read_metadata(stream, skip_version=False)

Deserialize session metadata from stream.

replace_attribute(name, value)

Explictly replace attribute with alternate implementation

replace_state_manager(tag, manager)

Explictly replace state manager with alternate implementation

reset()

Reset session to data-less state

restore(stream, version=None)

Deserialize session from stream.

restore_unique_id(obj, uid)

Restore unique identifier for an object

save(stream)

Serialize session to stream.

unique_id(obj, tool_info=None)

Return a unique identifier for an object in session

Consequently, the identifier is composed of simple data types.

Parameters:

obj : any object

tool_info : optional ToolInfo instance

Explicitly denote which tool object comes from.

unique_obj(uid)

Return the object that corresponds to the unique identifier

common_startup(sess)

Initialize session with common data managers

dump(session, filename, output=None)

dump contents of session for debugging

save(session, filename, **kw)

command line version of saving a session