Source code for opimodel.actions
[docs]class ActionsModel(object):
"""
Represents all actions attached to a widget.
"""
def __init__(self, hook_first=True, hook_all=False):
"""
Args:
hook_first: whether first action is executed on mouse click
hook_all: whether all actions are executed on mouse click
"""
self._actions = []
self._hook_first = hook_first
self._hook_all = hook_all
[docs] def add_action(self, action):
self._actions.append(action)
[docs] def set_hook_first(self, hook_first):
self._hook_first = hook_first
[docs] def get_hook_first(self):
return self._hook_first
[docs] def set_hook_all(self, hook_all):
self._hook_all = hook_all
[docs] def get_hook_all(self):
return self._hook_all
def __getitem__(self, index):
return self._actions[index]
def __len__(self):
return len(self._actions)
[docs]class WritePv(object):
"""
Action that writes the specified value to a named PV.
"""
def __init__(self, pv, value, description=''):
"""
Construct WritePv action.
Args:
pv name of PV to write, this can include macros
value to write
description to display
"""
self.pv_name = pv
self.description = description
self.value = value
self.timeout = 10
[docs]class ExecuteCommand(object):
"""
Action that executes a script command in the specified directory.
"""
OPI_DIR = '$(opi.dir)'
HOME_DIR = '$(user.home)'
def __init__(self, command, description, directory=OPI_DIR):
"""
Construct ExecuteCommand action.
The directory can be a real path or one of the predefined helper macros:
OPI_DIR: the directory containing the OPI file
HOME_DIR: users home directory
Args:
command to execute
description to display
directory to execute the script
"""
self.command = command
self.description = description
self.command_directory = directory
self.wait_time = 10
[docs]class OpenOpi(object):
"""Action that opens another opi file."""
REPLACE_CURRENT = 0
WORKBENCH_TAB = 1
WORKBENCH_TAB_LEFT = 2
WORKBENCH_TAB_RIGHT = 3
WORKBENCH_TAB_TOP = 4
WORKBENCH_TAB_BOTTOM = 5
DETACHED_TAB = 6
NEW_WORKBENCH = 7
STANDALONE = 8
def __init__(self, path, mode=STANDALONE, macros=None, parent_macros=True):
"""
Construct OpenOpi action.
Args:
path of opi to open
mode determining how the opi opens
macros: dict of macros with which to open the opi
parent_macros: whether to inherit parent macros
"""
self.path = path
self.mode = mode
self._macros = {} if macros is None else macros
self._parent_macros = parent_macros
[docs] def get_macros(self):
"""Get the macros dict.
Returns:
dict: the macros dict
"""
return self._macros
[docs] def get_parent_macros(self):
"""Get whether parent macros should be inherited.
Returns:
boolean: whether parent macros should be inherited
"""
return self._parent_macros
[docs]class Exit(object):
"""Action that closes the current opi."""