mxcubecore.BaseHardwareObjects#

Classes

ConfiguredObject(name)

Superclass for classes that take configuration from YAML files

DefaultSpecificState(value)

Placeholder enumeration for HardwareObject-specific states

Device(name)

Old superclass for devices

DeviceContainer()

Device ocntainer class - old style

DeviceContainerNode(node_name)

Class serves solely to provide a single supercalss combining HardwareObjectNode and DeviceContaine

Equipment(name)

Equipment class -old style

HardwareObject(rootName)

Xml-configured hardware object

HardwareObjectMixin()

Functionality for either xml- or yaml-configured HardwareObjects

HardwareObjectNode(node_name)

Hardware Object Node

HardwareObjectState(value)

Enumeration of common states, shared between all HardwareObjects

HardwareObjectYaml(name)

Yaml-configured hardware object.

Null(*args, **kwargs)

This class ignores all parameters passed when constructing or calling instances and traps all attribute and method requests.

Procedure(name)

PropertySet()

Property Set

class mxcubecore.BaseHardwareObjects.ConfiguredObject(name: str)[source]#

Bases: object

Superclass for classes that take configuration from YAML files

Parameters:

name (str) –

property all_objects_by_role: OrderedDict[str, Self | None]#

All contained Objects mapped by role (in specification order).

Includes objects defined in subclasses.

Returns:

Contained objects mapped by role.

Return type:

OrderedDict[str, Union[Self, None]]

property all_roles: Tuple[str]#

Tuple of all content object roles, in definition and loading order

Returns:

Content object roles

Return type:

Tuple[str]

init() None[source]#

Object initialisation - executed after loading contents

Return type:

None

property procedures: OrderedDict[str, Self]#

Procedures attached to this object mapped by name (in specification order).

Returns:

Object procedures.

Return type:

OrderedDict[str, Self]

replace_object(role: str, new_object: object) None[source]#

Replace already defined Object with a new one - for runtime use

Parameters:
  • role (str) – Role name of contained Object

  • new_object (object) – New contained Object

Raises:

ValueError – If contained object role is unknown.

Return type:

None

class mxcubecore.BaseHardwareObjects.DefaultSpecificState(value)[source]#

Bases: Enum

Placeholder enumeration for HardwareObject-specific states

class mxcubecore.BaseHardwareObjects.Device(name)[source]#

Bases: HardwareObject

Old superclass for devices

Signals:

  • “deviceReady”

  • “deviceNotReady”

NB Deprecated - should be replaced by AbstractActuator

is_ready()[source]#

Convenience function: Check if the object state is READY.

The same effect could be achieved with `python self.get_state() == self.STATES.READY `

Returns:

True if ready, otherwise False.

Return type:

bool

class mxcubecore.BaseHardwareObjects.DeviceContainer[source]#

Bases: object

Device ocntainer class - old style

NB Deprecated. Once DeviceContainerNode is removed, this clould be merged into Equipment

class mxcubecore.BaseHardwareObjects.DeviceContainerNode(node_name: str)[source]#

Bases: HardwareObjectNode, DeviceContainer

Class serves solely to provide a single supercalss combining HardwareObjectNode and DeviceContaine

TODO.This class is Deprecated.

it is only used once, in HardwareObjectFileParser.HardwareObjectHandler.startElement And that use looks like it could be replaced by something else

Parameters:

node_name (str) –

class mxcubecore.BaseHardwareObjects.Equipment(name)[source]#

Bases: HardwareObject, DeviceContainer

Equipment class -old style

Signals:

  • equipmentReady”

  • “equipmentNotReady”

NB This class needs refactoring. Since many (soon: all??) contained

objects are no longer of class Device, the code in here is unlikely to work.

is_ready()[source]#

Convenience function: Check if the object state is READY.

The same effect could be achieved with `python self.get_state() == self.STATES.READY `

Returns:

True if ready, otherwise False.

Return type:

bool

class mxcubecore.BaseHardwareObjects.HardwareObject(rootName: str)[source]#

Bases: HardwareObjectNode, HardwareObjectMixin

Xml-configured hardware object

Parameters:

rootName (str) –

commit_changes() None[source]#

Commit last changes back to configuration.

Return type:

None

property exported_attributes: Dict[str, Any]#

Get exported attributes.

Returns:

Exported attributes.

Return type:

Dict[str, Any]

init() None[source]#

Hardware object init.

Return type:

None

rewrite_xml(xml: bytes | Any) None[source]#

Rewrite XML conifguration file.

Parameters:

xml (Union[bytes, Any]) – XML source to write to file.

Return type:

None

xml_source() str | Any[source]#

Get XML configuration source.

Returns:

XML source.

Return type:

Union[str, Any]

class mxcubecore.BaseHardwareObjects.HardwareObjectMixin[source]#

Bases: CommandContainer

Functionality for either xml- or yaml-configured HardwareObjects

Signals emited:

  • stateChanged

  • specificStateChanged

SPECIFIC_STATES#

enum.Enum: Placeholder for HardwareObject-specific states. To be overridden

alias of DefaultSpecificState

STATES#

enum.Enum: General states, shared between all HardwareObjects. Do not overridde

alias of HardwareObjectState

abort() None[source]#

Immediately terminate HardwareObject action.

Should not happen in state READY.

Return type:

None

clear_gevent() None[source]#

Clear gevent tasks, called when disconnecting a HardwareObject.

Override in subclasses as needed.

Return type:

None

connect(sender: str | object | Any, signal: str | Any, slot: Callable | None = None) None[source]#

Connect a signal sent by self to a slot.

The functions provides syntactic sugar ; Instead of `python self.connect(self, "signal", slot) ` it is possible to do `python self.connect("signal", slot) `

TODO: This would be much nicer if refactored as `python def connect(self, signal, slot, sender=None) `

Parameters:
  • sender (Union[str, object, Any]) – If a string, interprted as the signal.

  • signal (Union[str, Any]) – In practice a string, or dispatcher.

  • slot. (Any if sender is a string interpreted as the) –

  • slot (Optional[Callable], optional) – In practice a functon or method.

  • None. (Defaults to) –

Raises:

ValueError – If slot is None and “sender” parameter is not a string.

Return type:

None

disconnect(sender: str | object | Any, signal: str | Any, slot: Callable | None = None) None[source]#

Disconnect a signal sent by self to a slot.

The functions provides syntactic sugar ; Instead of `python self.connect(self, "signal", slot) ` it is possible to do `python self.connect("signal", slot) `

TODO: This would be much nicer if refactored as `python def disconnect(self, signal, slot, sender=None): ... `

Parameters:
  • sender (Union[str, object, Any]) – If a string, interprted as the signal.

  • signal (Union[str, Any]) – In practice a string, or dispatcher.

  • slot. (Any if sender is a string interpreted as the) –

  • slot (Optional[Callable], optional) – In practice a functon or method.

  • None. (Defaults to) –

Raises:

ValueError – If slot is None and “sender” parameter is not a string.

Return type:

None

emit(signal: str | object | Any, *args) None[source]#

Emit signal. Accepts both multiple args and a single tuple of args.

TODO: This function would be unnecessary if all callers used `python dispatcher.send(signal, self, *argtuple) `

Parameters:
  • signal (Union[str, object, Any]) – In practice a string, or dispatcher.

  • *args (tuple) – Arguments sent with signal.

Return type:

None

execute_exported_command(cmd_name: str, args: Dict[str, Any]) Any[source]#

Execute exported command.

Parameters:
  • cmd_name (str) – Command name.

  • args (Dict[str, Any]) – Command arguments.

Returns:

Command execution output.

Return type:

Any

property exported_attributes: Dict[str, Any]#

Get exported attributes.

Returns:

Dictionary containing the method signature and JSONSchema. Follows the format; ```python {

”schema”: <JSONSchema string>, “signaure”: <list of argument names>,

Return type:

Dict[str, Any]

force_emit_signals() None[source]#

Emits all hardware object signals

The method is called from the gui via beamline object to ensure that bricks have values after the initialization. Problem arrise when a hardware object is used by several bricks. If first brick connects to some signal emited by a brick then other bricks connecting to the same signal will not receive the values on the startup. The easiest solution is to call force_emit_signals method directly after the initialization of the beamline object

Return type:

None

get_specific_state() Any | None[source]#

Getter for specific_state attribute. Override if needed.

Returns:

Specific state enum or None.

Return type:

Union[Any, None]

get_state() HardwareObjectState[source]#

Getter for state attribute.

Implementations must query the hardware directly, to ensure current results.

Returns:

Current state.

Return type:

HardwareObjectState

init() None[source]#

‘public’ post-initialization method. Override as needed.

For ConfiguredObjects called after loading contained objects.

Return type:

None

is_ready() bool[source]#

Convenience function: Check if the object state is READY.

The same effect could be achieved with `python self.get_state() == self.STATES.READY `

Returns:

True if ready, otherwise False.

Return type:

bool

property pydantic_model: Dict[str, Type[BaseModel]]#

Get object Pydantic models.

Returns:

Pydantic models for object.

Return type:

Dict[str, Type[BaseModel]]

re_emit_values() None[source]#

Update values for all internal attributes

Should be expanded in subclasse with more updatable attributes (e.g. value, limits)

Return type:

None

stop() None[source]#

Gentler (?) alternative to abort.

Override as necessary to implement.

Return type:

None

update_specific_state(state: Any | None = None) None[source]#

Update self._specific_state, and emit specificStateChanged if appropriate.

Parameters:
  • state (Optional[Any], optional) – Specific state - the enumeration will be

  • None. (specific for each HardwareObject class. Defaults to) –

Raises:

ValueError – If state specified is invalid.

Return type:

None

update_state(state: HardwareObjectState | None = None) None[source]#

Update self._state, and emit signal stateChanged if the state has changed.

Parameters:

state (Optional[HardwareObjectState], optional) – State. Defaults to None.

Raises:

ValueError – If state specified is invalid.

Return type:

None

wait_ready(timeout: float | None = None) None[source]#

Wait timeout seconds till object is ready.

If timeout is None: wait forever.

Parameters:

timeout (Optional[float], optional) – Timeout (seconds). Defaults to None.

Return type:

None

class mxcubecore.BaseHardwareObjects.HardwareObjectNode(node_name: str)[source]#

Bases: object

Hardware Object Node

Parameters:

node_name (str) –

add_object(name: str, hw_object: HardwareObject | None, role: str | None = None) None[source]#

Add hardware object mapped by name.

Parameters:
  • name (str) – Name.

  • hw_object (Union[HardwareObject, None]) – Hardware object.

  • role (Optional[str], optional) – Role. Defaults to None.

Return type:

None

add_reference(name: str, reference: str, role: str | None = None) None[source]#

Add hardware object reference.

Parameters:
  • name (str) – Name.

  • reference (str) – Xpath reference.

  • role (Union[str, None], optional) – Role. Defaults to None.

Return type:

None

get_object_by_role(role: str) HardwareObject | None[source]#

Get hardware object by role.

Parameters:

role (str) – Role.

Returns:

Hardware object.

Return type:

Union[HardwareObject, None]

get_objects(object_name: str) Generator[HardwareObject | None, None, None][source]#

Get hardware objects by name.

Parameters:

object_name (str) – Name.

Yields:

Union[HardwareObject, None] – Hardware object.

Return type:

Generator[HardwareObject | None, None, None]

get_properties() PropertySet[source]#

Get properties.

Returns:

Properties.

Return type:

PropertySet

get_property(name: str, default_value: Any | None = None) Any[source]#

Get property value.

Parameters:
  • name (str) – Name

  • default_value (Optional[Any], optional) – Default value. Defaults to None.

Returns:

Property value.

Return type:

Any

get_roles() List[str][source]#

Get hardware object roles.

Returns:

List of hardware object roles.

Return type:

List[str]

get_xml_path() str | None[source]#

Get XML file path.

Returns:

XML file path.

Return type:

Union[str, None]

has_object(object_name: str) bool[source]#

Check if has hardware object by name.

Parameters:

object_name (str) – Name.

Returns:

True if object name in hardware object node, otherwise False.

Return type:

bool

name() str[source]#

Get node name.

Returns:

Name.

Return type:

str

objects_names() List[str | None][source]#

Return hardware object names.

Returns:

List of hardware object names.

Return type:

List[Union[str, None]]

print_log(log_type: str = 'HWR', level: str = 'debug', msg: str = '') None[source]#

Print message to logger.

Parameters:
  • log_type (str, optional) – Logger type. Defaults to “HWR”.

  • level (str, optional) – Logger level. Defaults to “debug”.

  • msg (str, optional) – Message to log. Defaults to “”.

Return type:

None

resolve_references() None[source]#

Resolve hardware objects from defined references.

Return type:

None

set_name(name: str) None[source]#

Set node name

Parameters:

name (str) – Name to set.

Return type:

None

set_path(path: str) None[source]#

Set the ‘path’ of the Hardware Object in the XML file describing it (the path follows the XPath syntax)

Parameters:

path (str) – String representing the path of the Hardware Object in its file

Return type:

None

set_property(name: str, value: Any) None[source]#

Set property value.

Parameters:
  • name (str) – Name.

  • value (Any) – Value.

Return type:

None

static set_user_file_directory(user_file_directory: str) None[source]#

Set user file directory.

Parameters:

user_file_directory (str) – User file directory path.

Return type:

None

class mxcubecore.BaseHardwareObjects.HardwareObjectState(value)[source]#

Bases: Enum

Enumeration of common states, shared between all HardwareObjects

class mxcubecore.BaseHardwareObjects.HardwareObjectYaml(name: str)[source]#

Bases: ConfiguredObject, HardwareObjectMixin

Yaml-configured hardware object.

For use when we move configuration out of xml and into yaml.

The class is needed only to provide a single superclass that combines ConfiguredObject and HardwareObjectMixin

Parameters:

name (str) –

class mxcubecore.BaseHardwareObjects.Null(*args, **kwargs)[source]#

Bases: object

This class ignores all parameters passed when constructing or calling instances and traps all attribute and method requests. Instances of it always (and reliably) do ‘nothing’.

The code might benefit from implementing some further special Python methods depending on the context in which its instances are used. Especially when comparing and coercing Null objects the respective methods’ iimplementation will depend very much on the environment and, hence, these special methods are not provided here.

class mxcubecore.BaseHardwareObjects.Procedure(name: str)[source]#

Bases: HardwareObject

Parameters:

name (str) –

userName() str[source]#

Get procedure user name.

Returns:

Username.

Return type:

str

class mxcubecore.BaseHardwareObjects.PropertySet[source]#

Bases: dict

Property Set

get_changes() Generator[tuple, None, None][source]#

Get property changes since the last time checked.

Yields:

Generator[tuple, None, None] – Property changes.

Return type:

Generator[tuple, None, None]

get_properties_path() Iterator[tuple][source]#

Get Property Paths.

Returns:

Iterator for property paths.

Return type:

Iterator[tuple]

set_property_path(name: str, path: str | Any) None[source]#

Set Property Path.

Parameters:
  • name (str) – Name.

  • path (Union[str, Any]) – Path.

Return type:

None