repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
DLR-RM/RAFCON | source/rafcon/gui/controllers/utils/extended_controller.py | ExtendedController.remove_controller | def remove_controller(self, controller):
"""Remove child controller and destroy it
Removes all references to the child controller and calls destroy() on the controller.
:param str | ExtendedController controller: Either the child controller object itself or its registered name
:return: Whether the controller was existing
:rtype: bool
"""
# Get name of controller
if isinstance(controller, ExtendedController):
# print(self.__class__.__name__, " remove ", controller.__class__.__name__)
for key, child_controller in self.__child_controllers.items():
if controller is child_controller:
break
else:
return False
else:
key = controller
# print(self.__class__.__name__, " remove key ", key, self.__child_controllers.keys())
if key in self.__child_controllers:
if self.__shortcut_manager is not None:
self.__action_registered_controllers.remove(self.__child_controllers[key])
self.__child_controllers[key].unregister_actions(self.__shortcut_manager)
self.__child_controllers[key].destroy()
del self.__child_controllers[key]
# print("removed", controller.__class__.__name__ if not isinstance(controller, str) else controller)
return True
# print("do not remove", controller.__class__.__name__)
return False | python | def remove_controller(self, controller):
"""Remove child controller and destroy it
Removes all references to the child controller and calls destroy() on the controller.
:param str | ExtendedController controller: Either the child controller object itself or its registered name
:return: Whether the controller was existing
:rtype: bool
"""
# Get name of controller
if isinstance(controller, ExtendedController):
# print(self.__class__.__name__, " remove ", controller.__class__.__name__)
for key, child_controller in self.__child_controllers.items():
if controller is child_controller:
break
else:
return False
else:
key = controller
# print(self.__class__.__name__, " remove key ", key, self.__child_controllers.keys())
if key in self.__child_controllers:
if self.__shortcut_manager is not None:
self.__action_registered_controllers.remove(self.__child_controllers[key])
self.__child_controllers[key].unregister_actions(self.__shortcut_manager)
self.__child_controllers[key].destroy()
del self.__child_controllers[key]
# print("removed", controller.__class__.__name__ if not isinstance(controller, str) else controller)
return True
# print("do not remove", controller.__class__.__name__)
return False | [
"def",
"remove_controller",
"(",
"self",
",",
"controller",
")",
":",
"# Get name of controller",
"if",
"isinstance",
"(",
"controller",
",",
"ExtendedController",
")",
":",
"# print(self.__class__.__name__, \" remove \", controller.__class__.__name__)",
"for",
"key",
",",
... | Remove child controller and destroy it
Removes all references to the child controller and calls destroy() on the controller.
:param str | ExtendedController controller: Either the child controller object itself or its registered name
:return: Whether the controller was existing
:rtype: bool | [
"Remove",
"child",
"controller",
"and",
"destroy",
"it"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/utils/extended_controller.py#L67-L96 | train | 40,500 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/utils/extended_controller.py | ExtendedController.register_actions | def register_actions(self, shortcut_manager):
"""Register callback methods for triggered actions in all child controllers.
:param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings
between shortcuts and actions.
"""
assert isinstance(shortcut_manager, ShortcutManager)
self.__shortcut_manager = shortcut_manager
for controller in list(self.__child_controllers.values()):
if controller not in self.__action_registered_controllers:
try:
controller.register_actions(shortcut_manager)
except Exception as e:
logger.error("Error while registering action for {0}: {1}".format(controller.__class__.__name__, e))
self.__action_registered_controllers.append(controller) | python | def register_actions(self, shortcut_manager):
"""Register callback methods for triggered actions in all child controllers.
:param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings
between shortcuts and actions.
"""
assert isinstance(shortcut_manager, ShortcutManager)
self.__shortcut_manager = shortcut_manager
for controller in list(self.__child_controllers.values()):
if controller not in self.__action_registered_controllers:
try:
controller.register_actions(shortcut_manager)
except Exception as e:
logger.error("Error while registering action for {0}: {1}".format(controller.__class__.__name__, e))
self.__action_registered_controllers.append(controller) | [
"def",
"register_actions",
"(",
"self",
",",
"shortcut_manager",
")",
":",
"assert",
"isinstance",
"(",
"shortcut_manager",
",",
"ShortcutManager",
")",
"self",
".",
"__shortcut_manager",
"=",
"shortcut_manager",
"for",
"controller",
"in",
"list",
"(",
"self",
"."... | Register callback methods for triggered actions in all child controllers.
:param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings
between shortcuts and actions. | [
"Register",
"callback",
"methods",
"for",
"triggered",
"actions",
"in",
"all",
"child",
"controllers",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/utils/extended_controller.py#L147-L162 | train | 40,501 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/utils/extended_controller.py | ExtendedController.destroy | def destroy(self):
"""Recursively destroy all Controllers
The method remove all controllers, which calls the destroy method of the child controllers. Then,
all registered models are relieved and and the widget hand by the initial view argument is destroyed.
"""
self.disconnect_all_signals()
controller_names = [key for key in self.__child_controllers]
for controller_name in controller_names:
self.remove_controller(controller_name)
self.relieve_all_models()
if self.parent:
self.__parent = None
if self._view_initialized:
# print(self.__class__.__name__, "destroy view", self.view, self)
self.view.get_top_widget().destroy()
self.view = None
self._Observer__PROP_TO_METHS.clear() # prop name --> set of observing methods
self._Observer__METH_TO_PROPS.clear() # method --> set of observed properties
self._Observer__PAT_TO_METHS.clear() # like __PROP_TO_METHS but only for pattern names (to optimize search)
self._Observer__METH_TO_PAT.clear() # method --> pattern
self._Observer__PAT_METH_TO_KWARGS.clear() # (pattern, method) --> info
self.observe = None
else:
logger.warning("The controller {0} seems to be destroyed before the view was fully initialized. {1} "
"Check if you maybe do not call {2} or there exist most likely threading problems."
"".format(self.__class__.__name__, self.model, ExtendedController.register_view)) | python | def destroy(self):
"""Recursively destroy all Controllers
The method remove all controllers, which calls the destroy method of the child controllers. Then,
all registered models are relieved and and the widget hand by the initial view argument is destroyed.
"""
self.disconnect_all_signals()
controller_names = [key for key in self.__child_controllers]
for controller_name in controller_names:
self.remove_controller(controller_name)
self.relieve_all_models()
if self.parent:
self.__parent = None
if self._view_initialized:
# print(self.__class__.__name__, "destroy view", self.view, self)
self.view.get_top_widget().destroy()
self.view = None
self._Observer__PROP_TO_METHS.clear() # prop name --> set of observing methods
self._Observer__METH_TO_PROPS.clear() # method --> set of observed properties
self._Observer__PAT_TO_METHS.clear() # like __PROP_TO_METHS but only for pattern names (to optimize search)
self._Observer__METH_TO_PAT.clear() # method --> pattern
self._Observer__PAT_METH_TO_KWARGS.clear() # (pattern, method) --> info
self.observe = None
else:
logger.warning("The controller {0} seems to be destroyed before the view was fully initialized. {1} "
"Check if you maybe do not call {2} or there exist most likely threading problems."
"".format(self.__class__.__name__, self.model, ExtendedController.register_view)) | [
"def",
"destroy",
"(",
"self",
")",
":",
"self",
".",
"disconnect_all_signals",
"(",
")",
"controller_names",
"=",
"[",
"key",
"for",
"key",
"in",
"self",
".",
"__child_controllers",
"]",
"for",
"controller_name",
"in",
"controller_names",
":",
"self",
".",
... | Recursively destroy all Controllers
The method remove all controllers, which calls the destroy method of the child controllers. Then,
all registered models are relieved and and the widget hand by the initial view argument is destroyed. | [
"Recursively",
"destroy",
"all",
"Controllers"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/utils/extended_controller.py#L186-L212 | train | 40,502 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/utils/extended_controller.py | ExtendedController.observe_model | def observe_model(self, model):
"""Make this model observable within the controller
The method also keeps track of all observed models, in order to be able to relieve them later on.
:param gtkmvc3.Model model: The model to be observed
"""
self.__registered_models.add(model)
return super(ExtendedController, self).observe_model(model) | python | def observe_model(self, model):
"""Make this model observable within the controller
The method also keeps track of all observed models, in order to be able to relieve them later on.
:param gtkmvc3.Model model: The model to be observed
"""
self.__registered_models.add(model)
return super(ExtendedController, self).observe_model(model) | [
"def",
"observe_model",
"(",
"self",
",",
"model",
")",
":",
"self",
".",
"__registered_models",
".",
"add",
"(",
"model",
")",
"return",
"super",
"(",
"ExtendedController",
",",
"self",
")",
".",
"observe_model",
"(",
"model",
")"
] | Make this model observable within the controller
The method also keeps track of all observed models, in order to be able to relieve them later on.
:param gtkmvc3.Model model: The model to be observed | [
"Make",
"this",
"model",
"observable",
"within",
"the",
"controller"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/utils/extended_controller.py#L214-L222 | train | 40,503 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/utils/extended_controller.py | ExtendedController.relieve_model | def relieve_model(self, model):
"""Do no longer observe the model
The model is also removed from the internal set of tracked models.
:param gtkmvc3.Model model: The model to be relieved
"""
self.__registered_models.remove(model)
return super(ExtendedController, self).relieve_model(model) | python | def relieve_model(self, model):
"""Do no longer observe the model
The model is also removed from the internal set of tracked models.
:param gtkmvc3.Model model: The model to be relieved
"""
self.__registered_models.remove(model)
return super(ExtendedController, self).relieve_model(model) | [
"def",
"relieve_model",
"(",
"self",
",",
"model",
")",
":",
"self",
".",
"__registered_models",
".",
"remove",
"(",
"model",
")",
"return",
"super",
"(",
"ExtendedController",
",",
"self",
")",
".",
"relieve_model",
"(",
"model",
")"
] | Do no longer observe the model
The model is also removed from the internal set of tracked models.
:param gtkmvc3.Model model: The model to be relieved | [
"Do",
"no",
"longer",
"observe",
"the",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/utils/extended_controller.py#L224-L232 | train | 40,504 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/utils/extended_controller.py | ExtendedController.relieve_all_models | def relieve_all_models(self):
"""Relieve all registered models
The method uses the set of registered models to relieve them.
"""
map(self.relieve_model, list(self.__registered_models))
self.__registered_models.clear() | python | def relieve_all_models(self):
"""Relieve all registered models
The method uses the set of registered models to relieve them.
"""
map(self.relieve_model, list(self.__registered_models))
self.__registered_models.clear() | [
"def",
"relieve_all_models",
"(",
"self",
")",
":",
"map",
"(",
"self",
".",
"relieve_model",
",",
"list",
"(",
"self",
".",
"__registered_models",
")",
")",
"self",
".",
"__registered_models",
".",
"clear",
"(",
")"
] | Relieve all registered models
The method uses the set of registered models to relieve them. | [
"Relieve",
"all",
"registered",
"models"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/utils/extended_controller.py#L234-L240 | train | 40,505 |
DLR-RM/RAFCON | source/rafcon/core/state_elements/data_port.py | DataPort.change_data_type | def change_data_type(self, data_type, default_value=None):
"""This method changes both the data type and default value. If one of the parameters does not fit,
an exception is thrown and no property is changed. Using this method ensures a consistent data type
and default value and only notifies once.
:param data_type: The new data type
:param default_value: The new default value
:return:
"""
old_data_type = self.data_type
self.data_type = data_type
if default_value is None:
default_value = self.default_value
if type_helpers.type_inherits_of_type(type(default_value), self._data_type):
self._default_value = default_value
else:
if old_data_type.__name__ == "float" and data_type == "int":
if self.default_value:
self._default_value = int(default_value)
else:
self._default_value = 0
elif old_data_type.__name__ == "int" and data_type == "float":
if self.default_value:
self._default_value = float(default_value)
else:
self._default_value = 0.0
else:
self._default_value = None | python | def change_data_type(self, data_type, default_value=None):
"""This method changes both the data type and default value. If one of the parameters does not fit,
an exception is thrown and no property is changed. Using this method ensures a consistent data type
and default value and only notifies once.
:param data_type: The new data type
:param default_value: The new default value
:return:
"""
old_data_type = self.data_type
self.data_type = data_type
if default_value is None:
default_value = self.default_value
if type_helpers.type_inherits_of_type(type(default_value), self._data_type):
self._default_value = default_value
else:
if old_data_type.__name__ == "float" and data_type == "int":
if self.default_value:
self._default_value = int(default_value)
else:
self._default_value = 0
elif old_data_type.__name__ == "int" and data_type == "float":
if self.default_value:
self._default_value = float(default_value)
else:
self._default_value = 0.0
else:
self._default_value = None | [
"def",
"change_data_type",
"(",
"self",
",",
"data_type",
",",
"default_value",
"=",
"None",
")",
":",
"old_data_type",
"=",
"self",
".",
"data_type",
"self",
".",
"data_type",
"=",
"data_type",
"if",
"default_value",
"is",
"None",
":",
"default_value",
"=",
... | This method changes both the data type and default value. If one of the parameters does not fit,
an exception is thrown and no property is changed. Using this method ensures a consistent data type
and default value and only notifies once.
:param data_type: The new data type
:param default_value: The new default value
:return: | [
"This",
"method",
"changes",
"both",
"the",
"data",
"type",
"and",
"default",
"value",
".",
"If",
"one",
"of",
"the",
"parameters",
"does",
"not",
"fit",
"an",
"exception",
"is",
"thrown",
"and",
"no",
"property",
"is",
"changed",
".",
"Using",
"this",
"... | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_elements/data_port.py#L189-L219 | train | 40,506 |
DLR-RM/RAFCON | source/rafcon/core/state_elements/data_port.py | DataPort.check_default_value | def check_default_value(self, default_value, data_type=None):
"""Check whether the passed default value suits to the passed data type. If no data type is passed, the
data type of the data port is used. If the default value does not fit, an exception is thrown. If the default
value is of type string, it is tried to convert that value to the data type.
:param default_value: The default value to check
:param data_type: The data type to use
:raises exceptions.AttributeError: if check fails
:return: The converted default value
"""
if data_type is None:
data_type = self.data_type
if default_value is not None:
# If the default value is passed as string, we have to convert it to the data type
if isinstance(default_value, string_types):
if len(default_value) > 1 and default_value[0] == '$':
return default_value
if default_value == "None":
return None
default_value = type_helpers.convert_string_value_to_type_value(default_value, data_type)
if default_value is None:
raise AttributeError("Could not convert default value '{0}' to data type '{1}'.".format(
default_value, data_type))
else:
if not isinstance(default_value, self.data_type):
if self._no_type_error_exceptions:
logger.warning("Handed default value '{0}' is of type '{1}' but data port data type is {2} {3}."
"".format(default_value, type(default_value), data_type, self))
else:
raise TypeError("Handed default value '{0}' is of type '{1}' but data port data type is {2}"
"{3} of {4}.".format(default_value, type(default_value), data_type,
self,
self.parent.get_path() if self.parent is not None else ""))
return default_value | python | def check_default_value(self, default_value, data_type=None):
"""Check whether the passed default value suits to the passed data type. If no data type is passed, the
data type of the data port is used. If the default value does not fit, an exception is thrown. If the default
value is of type string, it is tried to convert that value to the data type.
:param default_value: The default value to check
:param data_type: The data type to use
:raises exceptions.AttributeError: if check fails
:return: The converted default value
"""
if data_type is None:
data_type = self.data_type
if default_value is not None:
# If the default value is passed as string, we have to convert it to the data type
if isinstance(default_value, string_types):
if len(default_value) > 1 and default_value[0] == '$':
return default_value
if default_value == "None":
return None
default_value = type_helpers.convert_string_value_to_type_value(default_value, data_type)
if default_value is None:
raise AttributeError("Could not convert default value '{0}' to data type '{1}'.".format(
default_value, data_type))
else:
if not isinstance(default_value, self.data_type):
if self._no_type_error_exceptions:
logger.warning("Handed default value '{0}' is of type '{1}' but data port data type is {2} {3}."
"".format(default_value, type(default_value), data_type, self))
else:
raise TypeError("Handed default value '{0}' is of type '{1}' but data port data type is {2}"
"{3} of {4}.".format(default_value, type(default_value), data_type,
self,
self.parent.get_path() if self.parent is not None else ""))
return default_value | [
"def",
"check_default_value",
"(",
"self",
",",
"default_value",
",",
"data_type",
"=",
"None",
")",
":",
"if",
"data_type",
"is",
"None",
":",
"data_type",
"=",
"self",
".",
"data_type",
"if",
"default_value",
"is",
"not",
"None",
":",
"# If the default value... | Check whether the passed default value suits to the passed data type. If no data type is passed, the
data type of the data port is used. If the default value does not fit, an exception is thrown. If the default
value is of type string, it is tried to convert that value to the data type.
:param default_value: The default value to check
:param data_type: The data type to use
:raises exceptions.AttributeError: if check fails
:return: The converted default value | [
"Check",
"whether",
"the",
"passed",
"default",
"value",
"suits",
"to",
"the",
"passed",
"data",
"type",
".",
"If",
"no",
"data",
"type",
"is",
"passed",
"the",
"data",
"type",
"of",
"the",
"data",
"port",
"is",
"used",
".",
"If",
"the",
"default",
"va... | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_elements/data_port.py#L221-L257 | train | 40,507 |
DLR-RM/RAFCON | source/rafcon/core/interface.py | create_folder_cmd_line | def create_folder_cmd_line(query, default_name=None, default_path=None):
"""Queries the user for a path to be created
:param str query: Query that asks the user for a specific folder path to be created
:param str default_name: Default name of the folder to be created
:param str default_path: Path in which the folder is created if the user doesn't specify a path
:return: Input path from the user or `default_path` if nothing is specified or None if directory could ne be created
:rtype: str
"""
default = None
if default_name and default_path:
default = os.path.join(default_path, default_name)
user_input = input(query + ' [default {}]: '.format(default))
if len(user_input) == 0:
user_input = default
if not user_input:
return None
if not os.path.isdir(user_input):
try:
os.makedirs(user_input)
except OSError:
return None
return user_input | python | def create_folder_cmd_line(query, default_name=None, default_path=None):
"""Queries the user for a path to be created
:param str query: Query that asks the user for a specific folder path to be created
:param str default_name: Default name of the folder to be created
:param str default_path: Path in which the folder is created if the user doesn't specify a path
:return: Input path from the user or `default_path` if nothing is specified or None if directory could ne be created
:rtype: str
"""
default = None
if default_name and default_path:
default = os.path.join(default_path, default_name)
user_input = input(query + ' [default {}]: '.format(default))
if len(user_input) == 0:
user_input = default
if not user_input:
return None
if not os.path.isdir(user_input):
try:
os.makedirs(user_input)
except OSError:
return None
return user_input | [
"def",
"create_folder_cmd_line",
"(",
"query",
",",
"default_name",
"=",
"None",
",",
"default_path",
"=",
"None",
")",
":",
"default",
"=",
"None",
"if",
"default_name",
"and",
"default_path",
":",
"default",
"=",
"os",
".",
"path",
".",
"join",
"(",
"def... | Queries the user for a path to be created
:param str query: Query that asks the user for a specific folder path to be created
:param str default_name: Default name of the folder to be created
:param str default_path: Path in which the folder is created if the user doesn't specify a path
:return: Input path from the user or `default_path` if nothing is specified or None if directory could ne be created
:rtype: str | [
"Queries",
"the",
"user",
"for",
"a",
"path",
"to",
"be",
"created"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/interface.py#L42-L65 | train | 40,508 |
DLR-RM/RAFCON | source/rafcon/core/interface.py | save_folder_cmd_line | def save_folder_cmd_line(query, default_name=None, default_path=None):
"""Queries the user for a path or file to be saved into
The folder or file has not to be created already and will not be created by this function. The parent directory
of folder and file has to exist otherwise the function will return None.
:param str query: Query that asks the user for a specific folder/file path to be created
:param str default_name: Default name of the folder to be created
:param str default_path: Path in which the folder is created if the user doesn't specify a path
:return: Input path from the user or `default_path` if nothing is specified and None if directory does not exist
:rtype: str
"""
default = None
if default_name and default_path:
default = os.path.join(default_path, default_name)
user_input = input(query + ' [default {}]: '.format(default))
if len(user_input) == 0:
user_input = default
if not user_input or not os.path.isdir(os.path.dirname(user_input)):
return None
return user_input | python | def save_folder_cmd_line(query, default_name=None, default_path=None):
"""Queries the user for a path or file to be saved into
The folder or file has not to be created already and will not be created by this function. The parent directory
of folder and file has to exist otherwise the function will return None.
:param str query: Query that asks the user for a specific folder/file path to be created
:param str default_name: Default name of the folder to be created
:param str default_path: Path in which the folder is created if the user doesn't specify a path
:return: Input path from the user or `default_path` if nothing is specified and None if directory does not exist
:rtype: str
"""
default = None
if default_name and default_path:
default = os.path.join(default_path, default_name)
user_input = input(query + ' [default {}]: '.format(default))
if len(user_input) == 0:
user_input = default
if not user_input or not os.path.isdir(os.path.dirname(user_input)):
return None
return user_input | [
"def",
"save_folder_cmd_line",
"(",
"query",
",",
"default_name",
"=",
"None",
",",
"default_path",
"=",
"None",
")",
":",
"default",
"=",
"None",
"if",
"default_name",
"and",
"default_path",
":",
"default",
"=",
"os",
".",
"path",
".",
"join",
"(",
"defau... | Queries the user for a path or file to be saved into
The folder or file has not to be created already and will not be created by this function. The parent directory
of folder and file has to exist otherwise the function will return None.
:param str query: Query that asks the user for a specific folder/file path to be created
:param str default_name: Default name of the folder to be created
:param str default_path: Path in which the folder is created if the user doesn't specify a path
:return: Input path from the user or `default_path` if nothing is specified and None if directory does not exist
:rtype: str | [
"Queries",
"the",
"user",
"for",
"a",
"path",
"or",
"file",
"to",
"be",
"saved",
"into"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/interface.py#L70-L91 | train | 40,509 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/transitions.py | StateTransitionsListController.remove_core_element | def remove_core_element(self, model):
"""Remove respective core element of handed transition model
:param TransitionModel model: Transition model which core element should be removed
:return:
"""
assert model.transition.parent is self.model.state or model.transition.parent is self.model.parent.state
gui_helper_state_machine.delete_core_element_of_model(model) | python | def remove_core_element(self, model):
"""Remove respective core element of handed transition model
:param TransitionModel model: Transition model which core element should be removed
:return:
"""
assert model.transition.parent is self.model.state or model.transition.parent is self.model.parent.state
gui_helper_state_machine.delete_core_element_of_model(model) | [
"def",
"remove_core_element",
"(",
"self",
",",
"model",
")",
":",
"assert",
"model",
".",
"transition",
".",
"parent",
"is",
"self",
".",
"model",
".",
"state",
"or",
"model",
".",
"transition",
".",
"parent",
"is",
"self",
".",
"model",
".",
"parent",
... | Remove respective core element of handed transition model
:param TransitionModel model: Transition model which core element should be removed
:return: | [
"Remove",
"respective",
"core",
"element",
"of",
"handed",
"transition",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/transitions.py#L172-L179 | train | 40,510 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/transitions.py | StateTransitionsListController._update_internal_data_base | def _update_internal_data_base(self):
""" Updates Internal combo knowledge for any actual transition by calling get_possible_combos_for_transition-
function for those.
"""
model = self.model
# print("clean data base")
### FOR COMBOS
# internal transitions
# - take all internal states
# - take all not used internal outcomes of this states
# external transitions
# - take all external states
# - take all external outcomes
# - take all not used own outcomes
### LINKING
# internal -> transition_id -> from_state = outcome combos
# -> ...
# external -> state -> outcome combos
self.combo['internal'] = {}
self.combo['external'] = {}
self.combo['free_from_states'] = {}
self.combo['free_from_outcomes_dict'] = {}
self.combo['free_ext_from_outcomes_dict'] = {}
self.combo['free_ext_from_outcomes_dict'] = {}
if isinstance(model, ContainerStateModel):
# check for internal combos
for transition_id, transition in model.state.transitions.items():
self.combo['internal'][transition_id] = {}
[from_state_combo, from_outcome_combo,
to_state_combo, to_outcome_combo,
free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(transition, self.model, self.model)
self.combo['internal'][transition_id]['from_state'] = from_state_combo
self.combo['internal'][transition_id]['from_outcome'] = from_outcome_combo
self.combo['internal'][transition_id]['to_state'] = to_state_combo
self.combo['internal'][transition_id]['to_outcome'] = to_outcome_combo
self.combo['free_from_states'] = free_from_states
self.combo['free_from_outcomes_dict'] = free_from_outcomes_dict
if not model.state.transitions:
[x, y, z, v, free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(None, self.model, self.model)
self.combo['free_from_states'] = free_from_states
self.combo['free_from_outcomes_dict'] = free_from_outcomes_dict
# TODO check why the can happen should not be handed always the LibraryStateModel
if not (self.model.state.is_root_state or self.model.state.is_root_state_of_library):
# check for external combos
for transition_id, transition in model.parent.state.transitions.items():
if transition.from_state == model.state.state_id or transition.to_state == model.state.state_id:
self.combo['external'][transition_id] = {}
[from_state_combo, from_outcome_combo,
to_state_combo, to_outcome_combo,
free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(transition, self.model.parent, self.model, True)
self.combo['external'][transition_id]['from_state'] = from_state_combo
self.combo['external'][transition_id]['from_outcome'] = from_outcome_combo
self.combo['external'][transition_id]['to_state'] = to_state_combo
self.combo['external'][transition_id]['to_outcome'] = to_outcome_combo
self.combo['free_ext_from_states'] = free_from_states
self.combo['free_ext_from_outcomes_dict'] = free_from_outcomes_dict
if not model.parent.state.transitions:
[x, y, z, v, free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(None, self.model.parent, self.model, True)
self.combo['free_ext_from_states'] = free_from_states
self.combo['free_ext_from_outcomes_dict'] = free_from_outcomes_dict | python | def _update_internal_data_base(self):
""" Updates Internal combo knowledge for any actual transition by calling get_possible_combos_for_transition-
function for those.
"""
model = self.model
# print("clean data base")
### FOR COMBOS
# internal transitions
# - take all internal states
# - take all not used internal outcomes of this states
# external transitions
# - take all external states
# - take all external outcomes
# - take all not used own outcomes
### LINKING
# internal -> transition_id -> from_state = outcome combos
# -> ...
# external -> state -> outcome combos
self.combo['internal'] = {}
self.combo['external'] = {}
self.combo['free_from_states'] = {}
self.combo['free_from_outcomes_dict'] = {}
self.combo['free_ext_from_outcomes_dict'] = {}
self.combo['free_ext_from_outcomes_dict'] = {}
if isinstance(model, ContainerStateModel):
# check for internal combos
for transition_id, transition in model.state.transitions.items():
self.combo['internal'][transition_id] = {}
[from_state_combo, from_outcome_combo,
to_state_combo, to_outcome_combo,
free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(transition, self.model, self.model)
self.combo['internal'][transition_id]['from_state'] = from_state_combo
self.combo['internal'][transition_id]['from_outcome'] = from_outcome_combo
self.combo['internal'][transition_id]['to_state'] = to_state_combo
self.combo['internal'][transition_id]['to_outcome'] = to_outcome_combo
self.combo['free_from_states'] = free_from_states
self.combo['free_from_outcomes_dict'] = free_from_outcomes_dict
if not model.state.transitions:
[x, y, z, v, free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(None, self.model, self.model)
self.combo['free_from_states'] = free_from_states
self.combo['free_from_outcomes_dict'] = free_from_outcomes_dict
# TODO check why the can happen should not be handed always the LibraryStateModel
if not (self.model.state.is_root_state or self.model.state.is_root_state_of_library):
# check for external combos
for transition_id, transition in model.parent.state.transitions.items():
if transition.from_state == model.state.state_id or transition.to_state == model.state.state_id:
self.combo['external'][transition_id] = {}
[from_state_combo, from_outcome_combo,
to_state_combo, to_outcome_combo,
free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(transition, self.model.parent, self.model, True)
self.combo['external'][transition_id]['from_state'] = from_state_combo
self.combo['external'][transition_id]['from_outcome'] = from_outcome_combo
self.combo['external'][transition_id]['to_state'] = to_state_combo
self.combo['external'][transition_id]['to_outcome'] = to_outcome_combo
self.combo['free_ext_from_states'] = free_from_states
self.combo['free_ext_from_outcomes_dict'] = free_from_outcomes_dict
if not model.parent.state.transitions:
[x, y, z, v, free_from_states, free_from_outcomes_dict] = \
self.get_possible_combos_for_transition(None, self.model.parent, self.model, True)
self.combo['free_ext_from_states'] = free_from_states
self.combo['free_ext_from_outcomes_dict'] = free_from_outcomes_dict | [
"def",
"_update_internal_data_base",
"(",
"self",
")",
":",
"model",
"=",
"self",
".",
"model",
"# print(\"clean data base\")",
"### FOR COMBOS",
"# internal transitions",
"# - take all internal states",
"# - take all not used internal outcomes of this states",
"# external transition... | Updates Internal combo knowledge for any actual transition by calling get_possible_combos_for_transition-
function for those. | [
"Updates",
"Internal",
"combo",
"knowledge",
"for",
"any",
"actual",
"transition",
"by",
"calling",
"get_possible_combos_for_transition",
"-",
"function",
"for",
"those",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/transitions.py#L421-L498 | train | 40,511 |
DLR-RM/RAFCON | source/rafcon/gui/models/auto_backup.py | move_dirty_lock_file | def move_dirty_lock_file(dirty_lock_file, sm_path):
""" Move the dirt_lock file to the sm_path and thereby is not found by auto recovery of backup anymore """
if dirty_lock_file is not None \
and not dirty_lock_file == os.path.join(sm_path, dirty_lock_file.split(os.sep)[-1]):
logger.debug("Move dirty lock from root tmp folder {0} to state machine folder {1}"
"".format(dirty_lock_file, os.path.join(sm_path, dirty_lock_file.split(os.sep)[-1])))
os.rename(dirty_lock_file, os.path.join(sm_path, dirty_lock_file.split(os.sep)[-1])) | python | def move_dirty_lock_file(dirty_lock_file, sm_path):
""" Move the dirt_lock file to the sm_path and thereby is not found by auto recovery of backup anymore """
if dirty_lock_file is not None \
and not dirty_lock_file == os.path.join(sm_path, dirty_lock_file.split(os.sep)[-1]):
logger.debug("Move dirty lock from root tmp folder {0} to state machine folder {1}"
"".format(dirty_lock_file, os.path.join(sm_path, dirty_lock_file.split(os.sep)[-1])))
os.rename(dirty_lock_file, os.path.join(sm_path, dirty_lock_file.split(os.sep)[-1])) | [
"def",
"move_dirty_lock_file",
"(",
"dirty_lock_file",
",",
"sm_path",
")",
":",
"if",
"dirty_lock_file",
"is",
"not",
"None",
"and",
"not",
"dirty_lock_file",
"==",
"os",
".",
"path",
".",
"join",
"(",
"sm_path",
",",
"dirty_lock_file",
".",
"split",
"(",
"... | Move the dirt_lock file to the sm_path and thereby is not found by auto recovery of backup anymore | [
"Move",
"the",
"dirt_lock",
"file",
"to",
"the",
"sm_path",
"and",
"thereby",
"is",
"not",
"found",
"by",
"auto",
"recovery",
"of",
"backup",
"anymore"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/auto_backup.py#L92-L98 | train | 40,512 |
DLR-RM/RAFCON | source/rafcon/gui/models/auto_backup.py | AutoBackupModel.write_backup_meta_data | def write_backup_meta_data(self):
"""Write the auto backup meta data into the current tmp-storage path"""
auto_backup_meta_file = os.path.join(self._tmp_storage_path, FILE_NAME_AUTO_BACKUP)
storage.storage_utils.write_dict_to_json(self.meta, auto_backup_meta_file) | python | def write_backup_meta_data(self):
"""Write the auto backup meta data into the current tmp-storage path"""
auto_backup_meta_file = os.path.join(self._tmp_storage_path, FILE_NAME_AUTO_BACKUP)
storage.storage_utils.write_dict_to_json(self.meta, auto_backup_meta_file) | [
"def",
"write_backup_meta_data",
"(",
"self",
")",
":",
"auto_backup_meta_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_tmp_storage_path",
",",
"FILE_NAME_AUTO_BACKUP",
")",
"storage",
".",
"storage_utils",
".",
"write_dict_to_json",
"(",
"self",... | Write the auto backup meta data into the current tmp-storage path | [
"Write",
"the",
"auto",
"backup",
"meta",
"data",
"into",
"the",
"current",
"tmp",
"-",
"storage",
"path"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/auto_backup.py#L398-L401 | train | 40,513 |
DLR-RM/RAFCON | source/rafcon/gui/models/auto_backup.py | AutoBackupModel.update_last_backup_meta_data | def update_last_backup_meta_data(self):
"""Update the auto backup meta data with internal recovery information"""
self.meta['last_backup']['time'] = get_time_string_for_float(self.last_backup_time)
self.meta['last_backup']['file_system_path'] = self._tmp_storage_path
self.meta['last_backup']['marked_dirty'] = self.state_machine_model.state_machine.marked_dirty | python | def update_last_backup_meta_data(self):
"""Update the auto backup meta data with internal recovery information"""
self.meta['last_backup']['time'] = get_time_string_for_float(self.last_backup_time)
self.meta['last_backup']['file_system_path'] = self._tmp_storage_path
self.meta['last_backup']['marked_dirty'] = self.state_machine_model.state_machine.marked_dirty | [
"def",
"update_last_backup_meta_data",
"(",
"self",
")",
":",
"self",
".",
"meta",
"[",
"'last_backup'",
"]",
"[",
"'time'",
"]",
"=",
"get_time_string_for_float",
"(",
"self",
".",
"last_backup_time",
")",
"self",
".",
"meta",
"[",
"'last_backup'",
"]",
"[",
... | Update the auto backup meta data with internal recovery information | [
"Update",
"the",
"auto",
"backup",
"meta",
"data",
"with",
"internal",
"recovery",
"information"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/auto_backup.py#L403-L407 | train | 40,514 |
DLR-RM/RAFCON | source/rafcon/gui/models/auto_backup.py | AutoBackupModel.update_last_sm_origin_meta_data | def update_last_sm_origin_meta_data(self):
"""Update the auto backup meta data with information of the state machine origin"""
# TODO finally maybe remove this when all backup features are integrated into one backup-structure
# data also used e.g. to backup tabs
self.meta['last_saved']['time'] = self.state_machine_model.state_machine.last_update
self.meta['last_saved']['file_system_path'] = self.state_machine_model.state_machine.file_system_path | python | def update_last_sm_origin_meta_data(self):
"""Update the auto backup meta data with information of the state machine origin"""
# TODO finally maybe remove this when all backup features are integrated into one backup-structure
# data also used e.g. to backup tabs
self.meta['last_saved']['time'] = self.state_machine_model.state_machine.last_update
self.meta['last_saved']['file_system_path'] = self.state_machine_model.state_machine.file_system_path | [
"def",
"update_last_sm_origin_meta_data",
"(",
"self",
")",
":",
"# TODO finally maybe remove this when all backup features are integrated into one backup-structure",
"# data also used e.g. to backup tabs",
"self",
".",
"meta",
"[",
"'last_saved'",
"]",
"[",
"'time'",
"]",
"=",
"... | Update the auto backup meta data with information of the state machine origin | [
"Update",
"the",
"auto",
"backup",
"meta",
"data",
"with",
"information",
"of",
"the",
"state",
"machine",
"origin"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/auto_backup.py#L409-L414 | train | 40,515 |
DLR-RM/RAFCON | source/rafcon/gui/models/auto_backup.py | AutoBackupModel._check_for_dyn_timed_auto_backup | def _check_for_dyn_timed_auto_backup(self):
""" The method implements the timed storage feature.
The method re-initiating a new timed thread if the state-machine not already stored to backup
(what could be caused by the force_temp_storage_interval) or force the storing of the state-machine if there
is no new request for a timed backup. New timed backup request are intrinsically represented by
self._timer_request_time and initiated by the check_for_auto_backup-method.
The feature uses only one thread for each ModificationHistoryModel and lock to be thread save.
"""
current_time = time.time()
self.timer_request_lock.acquire()
# sm = self.state_machine_model.state_machine
# TODO check for self._timer_request_time is None to avoid and reset auto-backup in case and fix it better
if self._timer_request_time is None:
# logger.warning("timer_request is None")
return self.timer_request_lock.release()
if self.timed_temp_storage_interval < current_time - self._timer_request_time:
# logger.info("{0} Perform timed auto-backup of state-machine {1}.".format(time.time(),
# sm.state_machine_id))
self.check_for_auto_backup(force=True)
else:
duration_to_wait = self.timed_temp_storage_interval - (current_time - self._timer_request_time)
hard_limit_duration_to_wait = self.force_temp_storage_interval - (current_time - self.last_backup_time)
hard_limit_active = hard_limit_duration_to_wait < duration_to_wait
# logger.info('{2} restart_thread {0} time to go {1}, hard limit {3}'.format(sm.state_machine_id,
# duration_to_wait, time.time(),
# hard_limit_active))
if hard_limit_active:
self.set_timed_thread(hard_limit_duration_to_wait, self.check_for_auto_backup, True)
else:
self.set_timed_thread(duration_to_wait, self._check_for_dyn_timed_auto_backup)
self.timer_request_lock.release() | python | def _check_for_dyn_timed_auto_backup(self):
""" The method implements the timed storage feature.
The method re-initiating a new timed thread if the state-machine not already stored to backup
(what could be caused by the force_temp_storage_interval) or force the storing of the state-machine if there
is no new request for a timed backup. New timed backup request are intrinsically represented by
self._timer_request_time and initiated by the check_for_auto_backup-method.
The feature uses only one thread for each ModificationHistoryModel and lock to be thread save.
"""
current_time = time.time()
self.timer_request_lock.acquire()
# sm = self.state_machine_model.state_machine
# TODO check for self._timer_request_time is None to avoid and reset auto-backup in case and fix it better
if self._timer_request_time is None:
# logger.warning("timer_request is None")
return self.timer_request_lock.release()
if self.timed_temp_storage_interval < current_time - self._timer_request_time:
# logger.info("{0} Perform timed auto-backup of state-machine {1}.".format(time.time(),
# sm.state_machine_id))
self.check_for_auto_backup(force=True)
else:
duration_to_wait = self.timed_temp_storage_interval - (current_time - self._timer_request_time)
hard_limit_duration_to_wait = self.force_temp_storage_interval - (current_time - self.last_backup_time)
hard_limit_active = hard_limit_duration_to_wait < duration_to_wait
# logger.info('{2} restart_thread {0} time to go {1}, hard limit {3}'.format(sm.state_machine_id,
# duration_to_wait, time.time(),
# hard_limit_active))
if hard_limit_active:
self.set_timed_thread(hard_limit_duration_to_wait, self.check_for_auto_backup, True)
else:
self.set_timed_thread(duration_to_wait, self._check_for_dyn_timed_auto_backup)
self.timer_request_lock.release() | [
"def",
"_check_for_dyn_timed_auto_backup",
"(",
"self",
")",
":",
"current_time",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"timer_request_lock",
".",
"acquire",
"(",
")",
"# sm = self.state_machine_model.state_machine",
"# TODO check for self._timer_request_time is ... | The method implements the timed storage feature.
The method re-initiating a new timed thread if the state-machine not already stored to backup
(what could be caused by the force_temp_storage_interval) or force the storing of the state-machine if there
is no new request for a timed backup. New timed backup request are intrinsically represented by
self._timer_request_time and initiated by the check_for_auto_backup-method.
The feature uses only one thread for each ModificationHistoryModel and lock to be thread save. | [
"The",
"method",
"implements",
"the",
"timed",
"storage",
"feature",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/auto_backup.py#L429-L460 | train | 40,516 |
DLR-RM/RAFCON | source/rafcon/gui/models/auto_backup.py | AutoBackupModel.check_for_auto_backup | def check_for_auto_backup(self, force=False):
""" The method implements the checks for possible auto backup of the state-machine according duration till
the last change together with the private method _check_for_dyn_timed_auto_backup.
If the only_fix_interval is True this function is called ones in the beginning and is called by a timed-
threads in a fix interval.
:param force: is a flag that force the temporary backup of the state-machine to the tmp-folder
:return:
"""
if not self.timed_temp_storage_enabled:
return
sm = self.state_machine_model.state_machine
current_time = time.time()
if not self.only_fix_interval and not self.marked_dirty:
# logger.info("adjust last_backup_time " + str(sm.state_machine_id))
self.last_backup_time = current_time # used as 'last-modification-not-backup-ed' time
is_not_timed_or_reached_time_to_force = \
current_time - self.last_backup_time > self.force_temp_storage_interval or self.only_fix_interval
if (sm.marked_dirty and is_not_timed_or_reached_time_to_force) or force:
if not self.only_fix_interval or self.marked_dirty:
thread = threading.Thread(target=self.perform_temp_storage)
thread.start()
# self.last_backup_time = current_time # used as 'last-backup' time
if self.only_fix_interval:
self.set_timed_thread(self.force_temp_storage_interval, self.check_for_auto_backup)
else:
if not self.only_fix_interval:
self.timer_request_lock.acquire()
if self._timer_request_time is None:
# logger.info('{0} start_thread {1}'.format(current_time, sm.state_machine_id))
self._timer_request_time = current_time
self.set_timed_thread(self.timed_temp_storage_interval, self._check_for_dyn_timed_auto_backup)
else:
# logger.info('{0} update_thread {1}'.format(current_time, sm.state_machine_id))
self._timer_request_time = current_time
self.timer_request_lock.release()
else:
self.set_timed_thread(self.force_temp_storage_interval, self.check_for_auto_backup) | python | def check_for_auto_backup(self, force=False):
""" The method implements the checks for possible auto backup of the state-machine according duration till
the last change together with the private method _check_for_dyn_timed_auto_backup.
If the only_fix_interval is True this function is called ones in the beginning and is called by a timed-
threads in a fix interval.
:param force: is a flag that force the temporary backup of the state-machine to the tmp-folder
:return:
"""
if not self.timed_temp_storage_enabled:
return
sm = self.state_machine_model.state_machine
current_time = time.time()
if not self.only_fix_interval and not self.marked_dirty:
# logger.info("adjust last_backup_time " + str(sm.state_machine_id))
self.last_backup_time = current_time # used as 'last-modification-not-backup-ed' time
is_not_timed_or_reached_time_to_force = \
current_time - self.last_backup_time > self.force_temp_storage_interval or self.only_fix_interval
if (sm.marked_dirty and is_not_timed_or_reached_time_to_force) or force:
if not self.only_fix_interval or self.marked_dirty:
thread = threading.Thread(target=self.perform_temp_storage)
thread.start()
# self.last_backup_time = current_time # used as 'last-backup' time
if self.only_fix_interval:
self.set_timed_thread(self.force_temp_storage_interval, self.check_for_auto_backup)
else:
if not self.only_fix_interval:
self.timer_request_lock.acquire()
if self._timer_request_time is None:
# logger.info('{0} start_thread {1}'.format(current_time, sm.state_machine_id))
self._timer_request_time = current_time
self.set_timed_thread(self.timed_temp_storage_interval, self._check_for_dyn_timed_auto_backup)
else:
# logger.info('{0} update_thread {1}'.format(current_time, sm.state_machine_id))
self._timer_request_time = current_time
self.timer_request_lock.release()
else:
self.set_timed_thread(self.force_temp_storage_interval, self.check_for_auto_backup) | [
"def",
"check_for_auto_backup",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"timed_temp_storage_enabled",
":",
"return",
"sm",
"=",
"self",
".",
"state_machine_model",
".",
"state_machine",
"current_time",
"=",
"time",
".",
"ti... | The method implements the checks for possible auto backup of the state-machine according duration till
the last change together with the private method _check_for_dyn_timed_auto_backup.
If the only_fix_interval is True this function is called ones in the beginning and is called by a timed-
threads in a fix interval.
:param force: is a flag that force the temporary backup of the state-machine to the tmp-folder
:return: | [
"The",
"method",
"implements",
"the",
"checks",
"for",
"possible",
"auto",
"backup",
"of",
"the",
"state",
"-",
"machine",
"according",
"duration",
"till",
"the",
"last",
"change",
"together",
"with",
"the",
"private",
"method",
"_check_for_dyn_timed_auto_backup",
... | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/auto_backup.py#L501-L543 | train | 40,517 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_icons.py | StateIconController.on_mouse_click | def on_mouse_click(self, widget, event):
"""state insertion on mouse click
:param widget:
:param Gdk.Event event: mouse click event
"""
import rafcon.gui.helpers.state_machine as gui_helper_state_machine
if self.view.get_path_at_pos(int(event.x), int(event.y)) is not None \
and len(self.view.get_selected_items()) > 0:
return gui_helper_state_machine.insert_state_into_selected_state(self._get_state(), False) | python | def on_mouse_click(self, widget, event):
"""state insertion on mouse click
:param widget:
:param Gdk.Event event: mouse click event
"""
import rafcon.gui.helpers.state_machine as gui_helper_state_machine
if self.view.get_path_at_pos(int(event.x), int(event.y)) is not None \
and len(self.view.get_selected_items()) > 0:
return gui_helper_state_machine.insert_state_into_selected_state(self._get_state(), False) | [
"def",
"on_mouse_click",
"(",
"self",
",",
"widget",
",",
"event",
")",
":",
"import",
"rafcon",
".",
"gui",
".",
"helpers",
".",
"state_machine",
"as",
"gui_helper_state_machine",
"if",
"self",
".",
"view",
".",
"get_path_at_pos",
"(",
"int",
"(",
"event",
... | state insertion on mouse click
:param widget:
:param Gdk.Event event: mouse click event | [
"state",
"insertion",
"on",
"mouse",
"click"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_icons.py#L81-L90 | train | 40,518 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_icons.py | StateIconController.on_mouse_motion | def on_mouse_motion(self, widget, event):
"""selection on mouse over
:param widget:
:param Gdk.Event event: mouse motion event
"""
path = self.view.get_path_at_pos(int(event.x), int(event.y))
if path is not None:
self.view.select_path(path)
else:
self.view.unselect_all() | python | def on_mouse_motion(self, widget, event):
"""selection on mouse over
:param widget:
:param Gdk.Event event: mouse motion event
"""
path = self.view.get_path_at_pos(int(event.x), int(event.y))
if path is not None:
self.view.select_path(path)
else:
self.view.unselect_all() | [
"def",
"on_mouse_motion",
"(",
"self",
",",
"widget",
",",
"event",
")",
":",
"path",
"=",
"self",
".",
"view",
".",
"get_path_at_pos",
"(",
"int",
"(",
"event",
".",
"x",
")",
",",
"int",
"(",
"event",
".",
"y",
")",
")",
"if",
"path",
"is",
"no... | selection on mouse over
:param widget:
:param Gdk.Event event: mouse motion event | [
"selection",
"on",
"mouse",
"over"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_icons.py#L92-L102 | train | 40,519 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_icons.py | StateIconController._get_state | def _get_state(self):
"""get state instance which was clicked on
:return: State that represents the icon which was clicked on
:rtype: rafcon.core.states.State
"""
selected = self.view.get_selected_items()
if not selected:
return
shorthand, state_class = self.view.states[selected[0][0]]
return state_class() | python | def _get_state(self):
"""get state instance which was clicked on
:return: State that represents the icon which was clicked on
:rtype: rafcon.core.states.State
"""
selected = self.view.get_selected_items()
if not selected:
return
shorthand, state_class = self.view.states[selected[0][0]]
return state_class() | [
"def",
"_get_state",
"(",
"self",
")",
":",
"selected",
"=",
"self",
".",
"view",
".",
"get_selected_items",
"(",
")",
"if",
"not",
"selected",
":",
"return",
"shorthand",
",",
"state_class",
"=",
"self",
".",
"view",
".",
"states",
"[",
"selected",
"[",... | get state instance which was clicked on
:return: State that represents the icon which was clicked on
:rtype: rafcon.core.states.State | [
"get",
"state",
"instance",
"which",
"was",
"clicked",
"on"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_icons.py#L104-L115 | train | 40,520 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/outcomes.py | StateOutcomesListController.apply_new_outcome_name | def apply_new_outcome_name(self, path, new_name):
"""Apply the newly entered outcome name it is was changed
:param str path: The path string of the renderer
:param str new_name: Newly entered outcome name
"""
# Don't do anything if outcome name didn't change
if new_name == self.list_store[path][self.NAME_STORAGE_ID]:
return
outcome = self.list_store[path][self.CORE_STORAGE_ID]
try:
outcome.name = new_name
logger.debug("Outcome name changed to '{0}'".format(outcome.name))
except (ValueError, TypeError) as e:
logger.warning("The name of the outcome could not be changed: {0}".format(e))
self.list_store[path][self.NAME_STORAGE_ID] = outcome.name | python | def apply_new_outcome_name(self, path, new_name):
"""Apply the newly entered outcome name it is was changed
:param str path: The path string of the renderer
:param str new_name: Newly entered outcome name
"""
# Don't do anything if outcome name didn't change
if new_name == self.list_store[path][self.NAME_STORAGE_ID]:
return
outcome = self.list_store[path][self.CORE_STORAGE_ID]
try:
outcome.name = new_name
logger.debug("Outcome name changed to '{0}'".format(outcome.name))
except (ValueError, TypeError) as e:
logger.warning("The name of the outcome could not be changed: {0}".format(e))
self.list_store[path][self.NAME_STORAGE_ID] = outcome.name | [
"def",
"apply_new_outcome_name",
"(",
"self",
",",
"path",
",",
"new_name",
")",
":",
"# Don't do anything if outcome name didn't change",
"if",
"new_name",
"==",
"self",
".",
"list_store",
"[",
"path",
"]",
"[",
"self",
".",
"NAME_STORAGE_ID",
"]",
":",
"return",... | Apply the newly entered outcome name it is was changed
:param str path: The path string of the renderer
:param str new_name: Newly entered outcome name | [
"Apply",
"the",
"newly",
"entered",
"outcome",
"name",
"it",
"is",
"was",
"changed"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/outcomes.py#L107-L123 | train | 40,521 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/outcomes.py | StateOutcomesListController.on_to_state_edited | def on_to_state_edited(self, renderer, path, new_state_identifier):
"""Connects the outcome with a transition to the newly set state
:param Gtk.CellRendererText renderer: The cell renderer that was edited
:param str path: The path string of the renderer
:param str new_state_identifier: An identifier for the new state that was selected
"""
def do_self_transition_check(t_id, new_state_identifier):
# add self transition meta data
if 'self' in new_state_identifier.split('.'):
insert_self_transition_meta_data(self.model, t_id, 'outcomes_widget', combined_action=True)
outcome_id = self.list_store[path][self.ID_STORAGE_ID]
if outcome_id in self.dict_to_other_state or outcome_id in self.dict_to_other_outcome:
transition_parent_state = self.model.parent.state
if outcome_id in self.dict_to_other_state:
t_id = self.dict_to_other_state[outcome_id][2]
else:
t_id = self.dict_to_other_outcome[outcome_id][2]
if new_state_identifier is not None:
to_state_id = new_state_identifier.split('.')[1]
if not transition_parent_state.transitions[t_id].to_state == to_state_id:
try:
transition_parent_state.transitions[t_id].modify_target(to_state=to_state_id)
do_self_transition_check(t_id, new_state_identifier)
except ValueError as e:
logger.warning("The target of transition couldn't be modified: {0}".format(e))
else:
try:
transition_parent_state.remove_transition(t_id)
except AttributeError as e:
logger.warning("The transition couldn't be removed: {0}".format(e))
else: # there is no transition till now
if new_state_identifier is not None and not self.model.state.is_root_state:
transition_parent_state = self.model.parent.state
to_state_id = new_state_identifier.split('.')[1]
try:
t_id = transition_parent_state.add_transition(from_state_id=self.model.state.state_id,
from_outcome=outcome_id,
to_state_id=to_state_id,
to_outcome=None, transition_id=None)
do_self_transition_check(t_id, new_state_identifier)
except (ValueError, TypeError) as e:
logger.warning("The transition couldn't be added: {0}".format(e))
return
else:
logger.debug("outcome-editor got None in to_state-combo-change no transition is added") | python | def on_to_state_edited(self, renderer, path, new_state_identifier):
"""Connects the outcome with a transition to the newly set state
:param Gtk.CellRendererText renderer: The cell renderer that was edited
:param str path: The path string of the renderer
:param str new_state_identifier: An identifier for the new state that was selected
"""
def do_self_transition_check(t_id, new_state_identifier):
# add self transition meta data
if 'self' in new_state_identifier.split('.'):
insert_self_transition_meta_data(self.model, t_id, 'outcomes_widget', combined_action=True)
outcome_id = self.list_store[path][self.ID_STORAGE_ID]
if outcome_id in self.dict_to_other_state or outcome_id in self.dict_to_other_outcome:
transition_parent_state = self.model.parent.state
if outcome_id in self.dict_to_other_state:
t_id = self.dict_to_other_state[outcome_id][2]
else:
t_id = self.dict_to_other_outcome[outcome_id][2]
if new_state_identifier is not None:
to_state_id = new_state_identifier.split('.')[1]
if not transition_parent_state.transitions[t_id].to_state == to_state_id:
try:
transition_parent_state.transitions[t_id].modify_target(to_state=to_state_id)
do_self_transition_check(t_id, new_state_identifier)
except ValueError as e:
logger.warning("The target of transition couldn't be modified: {0}".format(e))
else:
try:
transition_parent_state.remove_transition(t_id)
except AttributeError as e:
logger.warning("The transition couldn't be removed: {0}".format(e))
else: # there is no transition till now
if new_state_identifier is not None and not self.model.state.is_root_state:
transition_parent_state = self.model.parent.state
to_state_id = new_state_identifier.split('.')[1]
try:
t_id = transition_parent_state.add_transition(from_state_id=self.model.state.state_id,
from_outcome=outcome_id,
to_state_id=to_state_id,
to_outcome=None, transition_id=None)
do_self_transition_check(t_id, new_state_identifier)
except (ValueError, TypeError) as e:
logger.warning("The transition couldn't be added: {0}".format(e))
return
else:
logger.debug("outcome-editor got None in to_state-combo-change no transition is added") | [
"def",
"on_to_state_edited",
"(",
"self",
",",
"renderer",
",",
"path",
",",
"new_state_identifier",
")",
":",
"def",
"do_self_transition_check",
"(",
"t_id",
",",
"new_state_identifier",
")",
":",
"# add self transition meta data",
"if",
"'self'",
"in",
"new_state_id... | Connects the outcome with a transition to the newly set state
:param Gtk.CellRendererText renderer: The cell renderer that was edited
:param str path: The path string of the renderer
:param str new_state_identifier: An identifier for the new state that was selected | [
"Connects",
"the",
"outcome",
"with",
"a",
"transition",
"to",
"the",
"newly",
"set",
"state"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/outcomes.py#L125-L171 | train | 40,522 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/outcomes.py | StateOutcomesListController.on_to_outcome_edited | def on_to_outcome_edited(self, renderer, path, new_outcome_identifier):
"""Connects the outcome with a transition to the newly set outcome
:param Gtk.CellRendererText renderer: The cell renderer that was edited
:param str path: The path string of the renderer
:param str new_outcome_identifier: An identifier for the new outcome that was selected
"""
if self.model.parent is None:
return
outcome_id = self.list_store[path][self.ID_STORAGE_ID]
transition_parent_state = self.model.parent.state
if outcome_id in self.dict_to_other_state or outcome_id in self.dict_to_other_outcome:
if outcome_id in self.dict_to_other_state:
t_id = self.dict_to_other_state[outcome_id][2]
else:
t_id = self.dict_to_other_outcome[outcome_id][2]
if new_outcome_identifier is not None:
new_to_outcome_id = int(new_outcome_identifier.split('.')[2])
if not transition_parent_state.transitions[t_id].to_outcome == new_to_outcome_id:
to_state_id = self.model.parent.state.state_id
try:
transition_parent_state.transitions[t_id].modify_target(to_state=to_state_id,
to_outcome=new_to_outcome_id)
except ValueError as e:
logger.warning("The target of transition couldn't be modified: {0}".format(e))
else:
transition_parent_state.remove_transition(t_id)
else: # there is no transition till now
if new_outcome_identifier is not None:
to_outcome = int(new_outcome_identifier.split('.')[2])
try:
self.model.parent.state.add_transition(from_state_id=self.model.state.state_id,
from_outcome=outcome_id,
to_state_id=self.model.parent.state.state_id,
to_outcome=to_outcome, transition_id=None)
except (ValueError, TypeError) as e:
logger.warning("The transition couldn't be added: {0}".format(e))
else:
logger.debug("outcome-editor got None in to_outcome-combo-change no transition is added") | python | def on_to_outcome_edited(self, renderer, path, new_outcome_identifier):
"""Connects the outcome with a transition to the newly set outcome
:param Gtk.CellRendererText renderer: The cell renderer that was edited
:param str path: The path string of the renderer
:param str new_outcome_identifier: An identifier for the new outcome that was selected
"""
if self.model.parent is None:
return
outcome_id = self.list_store[path][self.ID_STORAGE_ID]
transition_parent_state = self.model.parent.state
if outcome_id in self.dict_to_other_state or outcome_id in self.dict_to_other_outcome:
if outcome_id in self.dict_to_other_state:
t_id = self.dict_to_other_state[outcome_id][2]
else:
t_id = self.dict_to_other_outcome[outcome_id][2]
if new_outcome_identifier is not None:
new_to_outcome_id = int(new_outcome_identifier.split('.')[2])
if not transition_parent_state.transitions[t_id].to_outcome == new_to_outcome_id:
to_state_id = self.model.parent.state.state_id
try:
transition_parent_state.transitions[t_id].modify_target(to_state=to_state_id,
to_outcome=new_to_outcome_id)
except ValueError as e:
logger.warning("The target of transition couldn't be modified: {0}".format(e))
else:
transition_parent_state.remove_transition(t_id)
else: # there is no transition till now
if new_outcome_identifier is not None:
to_outcome = int(new_outcome_identifier.split('.')[2])
try:
self.model.parent.state.add_transition(from_state_id=self.model.state.state_id,
from_outcome=outcome_id,
to_state_id=self.model.parent.state.state_id,
to_outcome=to_outcome, transition_id=None)
except (ValueError, TypeError) as e:
logger.warning("The transition couldn't be added: {0}".format(e))
else:
logger.debug("outcome-editor got None in to_outcome-combo-change no transition is added") | [
"def",
"on_to_outcome_edited",
"(",
"self",
",",
"renderer",
",",
"path",
",",
"new_outcome_identifier",
")",
":",
"if",
"self",
".",
"model",
".",
"parent",
"is",
"None",
":",
"return",
"outcome_id",
"=",
"self",
".",
"list_store",
"[",
"path",
"]",
"[",
... | Connects the outcome with a transition to the newly set outcome
:param Gtk.CellRendererText renderer: The cell renderer that was edited
:param str path: The path string of the renderer
:param str new_outcome_identifier: An identifier for the new outcome that was selected | [
"Connects",
"the",
"outcome",
"with",
"a",
"transition",
"to",
"the",
"newly",
"set",
"outcome"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/outcomes.py#L173-L213 | train | 40,523 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/outcomes.py | StateOutcomesListController.remove_core_element | def remove_core_element(self, model):
"""Remove respective core element of handed outcome model
:param OutcomeModel model: Outcome model which core element should be removed
:return:
"""
assert model.outcome.parent is self.model.state
gui_helper_state_machine.delete_core_element_of_model(model) | python | def remove_core_element(self, model):
"""Remove respective core element of handed outcome model
:param OutcomeModel model: Outcome model which core element should be removed
:return:
"""
assert model.outcome.parent is self.model.state
gui_helper_state_machine.delete_core_element_of_model(model) | [
"def",
"remove_core_element",
"(",
"self",
",",
"model",
")",
":",
"assert",
"model",
".",
"outcome",
".",
"parent",
"is",
"self",
".",
"model",
".",
"state",
"gui_helper_state_machine",
".",
"delete_core_element_of_model",
"(",
"model",
")"
] | Remove respective core element of handed outcome model
:param OutcomeModel model: Outcome model which core element should be removed
:return: | [
"Remove",
"respective",
"core",
"element",
"of",
"handed",
"outcome",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/outcomes.py#L225-L232 | train | 40,524 |
DLR-RM/RAFCON | source/rafcon/gui/views/state_editor/state_editor.py | StateEditorView.bring_tab_to_the_top | def bring_tab_to_the_top(self, tab_label):
"""Find tab with label tab_label in list of notebook's and set it to the current page.
:param tab_label: String containing the label of the tab to be focused
"""
page = self.page_dict[tab_label]
for notebook in self.notebook_names:
page_num = self[notebook].page_num(page)
if not page_num == -1:
self[notebook].set_current_page(page_num)
break | python | def bring_tab_to_the_top(self, tab_label):
"""Find tab with label tab_label in list of notebook's and set it to the current page.
:param tab_label: String containing the label of the tab to be focused
"""
page = self.page_dict[tab_label]
for notebook in self.notebook_names:
page_num = self[notebook].page_num(page)
if not page_num == -1:
self[notebook].set_current_page(page_num)
break | [
"def",
"bring_tab_to_the_top",
"(",
"self",
",",
"tab_label",
")",
":",
"page",
"=",
"self",
".",
"page_dict",
"[",
"tab_label",
"]",
"for",
"notebook",
"in",
"self",
".",
"notebook_names",
":",
"page_num",
"=",
"self",
"[",
"notebook",
"]",
".",
"page_num... | Find tab with label tab_label in list of notebook's and set it to the current page.
:param tab_label: String containing the label of the tab to be focused | [
"Find",
"tab",
"with",
"label",
"tab_label",
"in",
"list",
"of",
"notebook",
"s",
"and",
"set",
"it",
"to",
"the",
"current",
"page",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/views/state_editor/state_editor.py#L133-L143 | train | 40,525 |
DLR-RM/RAFCON | source/rafcon/gui/utils/comparison.py | compare_variables | def compare_variables(tree_model, iter1, iter2, user_data=None):
"""Triggered upon updating the list of global variables
Helper method to sort global variables alphabetically.
:param tree_model: Tree model implementing the Gtk.TreeSortable interface.
:param iter1: Points at a row.
:param iter2: Points at a row.
"""
path1 = tree_model.get_path(iter1)[0]
path2 = tree_model.get_path(iter2)[0]
# get key of first variable
name1 = tree_model[path1][0]
# get key of second variable
name2 = tree_model[path2][0]
name1_as_bits = ' '.join(format(ord(x), 'b') for x in name1)
name2_as_bits = ' '.join(format(ord(x), 'b') for x in name2)
if name1_as_bits == name2_as_bits:
return 0
elif name1_as_bits > name2_as_bits:
return 1
else:
return -1 | python | def compare_variables(tree_model, iter1, iter2, user_data=None):
"""Triggered upon updating the list of global variables
Helper method to sort global variables alphabetically.
:param tree_model: Tree model implementing the Gtk.TreeSortable interface.
:param iter1: Points at a row.
:param iter2: Points at a row.
"""
path1 = tree_model.get_path(iter1)[0]
path2 = tree_model.get_path(iter2)[0]
# get key of first variable
name1 = tree_model[path1][0]
# get key of second variable
name2 = tree_model[path2][0]
name1_as_bits = ' '.join(format(ord(x), 'b') for x in name1)
name2_as_bits = ' '.join(format(ord(x), 'b') for x in name2)
if name1_as_bits == name2_as_bits:
return 0
elif name1_as_bits > name2_as_bits:
return 1
else:
return -1 | [
"def",
"compare_variables",
"(",
"tree_model",
",",
"iter1",
",",
"iter2",
",",
"user_data",
"=",
"None",
")",
":",
"path1",
"=",
"tree_model",
".",
"get_path",
"(",
"iter1",
")",
"[",
"0",
"]",
"path2",
"=",
"tree_model",
".",
"get_path",
"(",
"iter2",
... | Triggered upon updating the list of global variables
Helper method to sort global variables alphabetically.
:param tree_model: Tree model implementing the Gtk.TreeSortable interface.
:param iter1: Points at a row.
:param iter2: Points at a row. | [
"Triggered",
"upon",
"updating",
"the",
"list",
"of",
"global",
"variables"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/utils/comparison.py#L15-L37 | train | 40,526 |
DLR-RM/RAFCON | source/rafcon/core/state_machine_manager.py | StateMachineManager.reset_dirty_flags | def reset_dirty_flags(self):
"""Set all marked_dirty flags of the state machine to false."""
for sm_id, sm in self.state_machines.items():
sm.marked_dirty = False | python | def reset_dirty_flags(self):
"""Set all marked_dirty flags of the state machine to false."""
for sm_id, sm in self.state_machines.items():
sm.marked_dirty = False | [
"def",
"reset_dirty_flags",
"(",
"self",
")",
":",
"for",
"sm_id",
",",
"sm",
"in",
"self",
".",
"state_machines",
".",
"items",
"(",
")",
":",
"sm",
".",
"marked_dirty",
"=",
"False"
] | Set all marked_dirty flags of the state machine to false. | [
"Set",
"all",
"marked_dirty",
"flags",
"of",
"the",
"state",
"machine",
"to",
"false",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_machine_manager.py#L81-L84 | train | 40,527 |
DLR-RM/RAFCON | source/rafcon/core/state_machine_manager.py | StateMachineManager.add_state_machine | def add_state_machine(self, state_machine):
"""Add a state machine to the list of managed state machines. If there is no active state machine set yet,
then set as active state machine.
:param state_machine: State Machine Object
:raises exceptions.AttributeError: if the passed state machine was already added of is of a wrong type
"""
if not isinstance(state_machine, StateMachine):
raise AttributeError("State machine must be of type StateMachine")
if state_machine.file_system_path is not None:
if self.is_state_machine_open(state_machine.file_system_path):
raise AttributeError("The state machine is already open {0}".format(state_machine.file_system_path))
logger.debug("Add new state machine with id {0}".format(state_machine.state_machine_id))
self._state_machines[state_machine.state_machine_id] = state_machine
return state_machine.state_machine_id | python | def add_state_machine(self, state_machine):
"""Add a state machine to the list of managed state machines. If there is no active state machine set yet,
then set as active state machine.
:param state_machine: State Machine Object
:raises exceptions.AttributeError: if the passed state machine was already added of is of a wrong type
"""
if not isinstance(state_machine, StateMachine):
raise AttributeError("State machine must be of type StateMachine")
if state_machine.file_system_path is not None:
if self.is_state_machine_open(state_machine.file_system_path):
raise AttributeError("The state machine is already open {0}".format(state_machine.file_system_path))
logger.debug("Add new state machine with id {0}".format(state_machine.state_machine_id))
self._state_machines[state_machine.state_machine_id] = state_machine
return state_machine.state_machine_id | [
"def",
"add_state_machine",
"(",
"self",
",",
"state_machine",
")",
":",
"if",
"not",
"isinstance",
"(",
"state_machine",
",",
"StateMachine",
")",
":",
"raise",
"AttributeError",
"(",
"\"State machine must be of type StateMachine\"",
")",
"if",
"state_machine",
".",
... | Add a state machine to the list of managed state machines. If there is no active state machine set yet,
then set as active state machine.
:param state_machine: State Machine Object
:raises exceptions.AttributeError: if the passed state machine was already added of is of a wrong type | [
"Add",
"a",
"state",
"machine",
"to",
"the",
"list",
"of",
"managed",
"state",
"machines",
".",
"If",
"there",
"is",
"no",
"active",
"state",
"machine",
"set",
"yet",
"then",
"set",
"as",
"active",
"state",
"machine",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_machine_manager.py#L93-L107 | train | 40,528 |
DLR-RM/RAFCON | source/rafcon/core/state_machine_manager.py | StateMachineManager.remove_state_machine | def remove_state_machine(self, state_machine_id):
"""Remove the state machine for a specified state machine id from the list of registered state machines.
:param state_machine_id: the id of the state machine to be removed
"""
import rafcon.core.singleton as core_singletons
removed_state_machine = None
if state_machine_id in self._state_machines:
logger.debug("Remove state machine with id {0}".format(state_machine_id))
removed_state_machine = self._state_machines.pop(state_machine_id)
else:
logger.error("There is no state_machine with state_machine_id: %s" % state_machine_id)
return removed_state_machine
# destroy execution history
removed_state_machine.destroy_execution_histories()
return removed_state_machine | python | def remove_state_machine(self, state_machine_id):
"""Remove the state machine for a specified state machine id from the list of registered state machines.
:param state_machine_id: the id of the state machine to be removed
"""
import rafcon.core.singleton as core_singletons
removed_state_machine = None
if state_machine_id in self._state_machines:
logger.debug("Remove state machine with id {0}".format(state_machine_id))
removed_state_machine = self._state_machines.pop(state_machine_id)
else:
logger.error("There is no state_machine with state_machine_id: %s" % state_machine_id)
return removed_state_machine
# destroy execution history
removed_state_machine.destroy_execution_histories()
return removed_state_machine | [
"def",
"remove_state_machine",
"(",
"self",
",",
"state_machine_id",
")",
":",
"import",
"rafcon",
".",
"core",
".",
"singleton",
"as",
"core_singletons",
"removed_state_machine",
"=",
"None",
"if",
"state_machine_id",
"in",
"self",
".",
"_state_machines",
":",
"l... | Remove the state machine for a specified state machine id from the list of registered state machines.
:param state_machine_id: the id of the state machine to be removed | [
"Remove",
"the",
"state",
"machine",
"for",
"a",
"specified",
"state",
"machine",
"id",
"from",
"the",
"list",
"of",
"registered",
"state",
"machines",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_machine_manager.py#L110-L126 | train | 40,529 |
DLR-RM/RAFCON | source/rafcon/core/state_machine_manager.py | StateMachineManager.get_active_state_machine | def get_active_state_machine(self):
"""Return a reference to the active state-machine
"""
if self._active_state_machine_id in self._state_machines:
return self._state_machines[self._active_state_machine_id]
else:
return None | python | def get_active_state_machine(self):
"""Return a reference to the active state-machine
"""
if self._active_state_machine_id in self._state_machines:
return self._state_machines[self._active_state_machine_id]
else:
return None | [
"def",
"get_active_state_machine",
"(",
"self",
")",
":",
"if",
"self",
".",
"_active_state_machine_id",
"in",
"self",
".",
"_state_machines",
":",
"return",
"self",
".",
"_state_machines",
"[",
"self",
".",
"_active_state_machine_id",
"]",
"else",
":",
"return",
... | Return a reference to the active state-machine | [
"Return",
"a",
"reference",
"to",
"the",
"active",
"state",
"-",
"machine"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_machine_manager.py#L128-L134 | train | 40,530 |
DLR-RM/RAFCON | source/rafcon/core/state_machine_manager.py | StateMachineManager.get_open_state_machine_of_file_system_path | def get_open_state_machine_of_file_system_path(self, file_system_path):
"""Return a reference to the state machine with respective path if open
"""
for sm in self.state_machines.values():
if sm.file_system_path == file_system_path:
return sm | python | def get_open_state_machine_of_file_system_path(self, file_system_path):
"""Return a reference to the state machine with respective path if open
"""
for sm in self.state_machines.values():
if sm.file_system_path == file_system_path:
return sm | [
"def",
"get_open_state_machine_of_file_system_path",
"(",
"self",
",",
"file_system_path",
")",
":",
"for",
"sm",
"in",
"self",
".",
"state_machines",
".",
"values",
"(",
")",
":",
"if",
"sm",
".",
"file_system_path",
"==",
"file_system_path",
":",
"return",
"sm... | Return a reference to the state machine with respective path if open | [
"Return",
"a",
"reference",
"to",
"the",
"state",
"machine",
"with",
"respective",
"path",
"if",
"open"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_machine_manager.py#L136-L141 | train | 40,531 |
DLR-RM/RAFCON | source/rafcon/gui/views/undocked_window.py | UndockedWindowView.reset_title | def reset_title(self, title, notebook_identifier):
"""Triggered whenever a notebook tab is switched in the left bar.
Resets the title of the un-docked window to the format 'upper_open_tab / lower_open_tab'
:param title: The name of the newly selected tab
:param notebook: string taking one of two values 'upper' or 'lower' indicating which notebook was changed
"""
current_title = self.get_top_widget().get_title()
upper_title = current_title.split('/')[0].strip()
lower_title = current_title.split('/')[1].strip()
if notebook_identifier == 'upper':
new_title = title + ' / ' + lower_title
else:
new_title = upper_title + ' / ' + title
self['headerbar'].props.title = new_title | python | def reset_title(self, title, notebook_identifier):
"""Triggered whenever a notebook tab is switched in the left bar.
Resets the title of the un-docked window to the format 'upper_open_tab / lower_open_tab'
:param title: The name of the newly selected tab
:param notebook: string taking one of two values 'upper' or 'lower' indicating which notebook was changed
"""
current_title = self.get_top_widget().get_title()
upper_title = current_title.split('/')[0].strip()
lower_title = current_title.split('/')[1].strip()
if notebook_identifier == 'upper':
new_title = title + ' / ' + lower_title
else:
new_title = upper_title + ' / ' + title
self['headerbar'].props.title = new_title | [
"def",
"reset_title",
"(",
"self",
",",
"title",
",",
"notebook_identifier",
")",
":",
"current_title",
"=",
"self",
".",
"get_top_widget",
"(",
")",
".",
"get_title",
"(",
")",
"upper_title",
"=",
"current_title",
".",
"split",
"(",
"'/'",
")",
"[",
"0",
... | Triggered whenever a notebook tab is switched in the left bar.
Resets the title of the un-docked window to the format 'upper_open_tab / lower_open_tab'
:param title: The name of the newly selected tab
:param notebook: string taking one of two values 'upper' or 'lower' indicating which notebook was changed | [
"Triggered",
"whenever",
"a",
"notebook",
"tab",
"is",
"switched",
"in",
"the",
"left",
"bar",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/views/undocked_window.py#L57-L72 | train | 40,532 |
DLR-RM/RAFCON | source/rafcon/gui/helpers/state.py | add_state | def add_state(container_state_m, state_type):
"""Add a state to a container state
Adds a state of type state_type to the given container_state
:param rafcon.gui.models.container_state.ContainerState container_state_m: A model of a container state to add
the new state to
:param rafcon.core.enums.StateType state_type: The type of state that should be added
:return: True if successful, False else
"""
if container_state_m is None:
logger.error("Cannot add a state without a parent.")
return False
if not isinstance(container_state_m, StateModel) or \
(isinstance(container_state_m, StateModel) and not isinstance(container_state_m, ContainerStateModel)):
logger.error("Parent state must be a container, for example a Hierarchy State." + str(container_state_m))
return False
state_class = state_type_to_state_class_dict.get(state_type, None)
if state_class is None:
logger.error("Cannot create state of type {0}".format(state_type))
return False
new_state = state_class()
from rafcon.gui.models.abstract_state import get_state_model_class_for_state
new_state_m = get_state_model_class_for_state(new_state)(new_state)
gui_helper_meta_data.put_default_meta_on_state_m(new_state_m, container_state_m)
container_state_m.expected_future_models.add(new_state_m)
container_state_m.state.add_state(new_state)
return True | python | def add_state(container_state_m, state_type):
"""Add a state to a container state
Adds a state of type state_type to the given container_state
:param rafcon.gui.models.container_state.ContainerState container_state_m: A model of a container state to add
the new state to
:param rafcon.core.enums.StateType state_type: The type of state that should be added
:return: True if successful, False else
"""
if container_state_m is None:
logger.error("Cannot add a state without a parent.")
return False
if not isinstance(container_state_m, StateModel) or \
(isinstance(container_state_m, StateModel) and not isinstance(container_state_m, ContainerStateModel)):
logger.error("Parent state must be a container, for example a Hierarchy State." + str(container_state_m))
return False
state_class = state_type_to_state_class_dict.get(state_type, None)
if state_class is None:
logger.error("Cannot create state of type {0}".format(state_type))
return False
new_state = state_class()
from rafcon.gui.models.abstract_state import get_state_model_class_for_state
new_state_m = get_state_model_class_for_state(new_state)(new_state)
gui_helper_meta_data.put_default_meta_on_state_m(new_state_m, container_state_m)
container_state_m.expected_future_models.add(new_state_m)
container_state_m.state.add_state(new_state)
return True | [
"def",
"add_state",
"(",
"container_state_m",
",",
"state_type",
")",
":",
"if",
"container_state_m",
"is",
"None",
":",
"logger",
".",
"error",
"(",
"\"Cannot add a state without a parent.\"",
")",
"return",
"False",
"if",
"not",
"isinstance",
"(",
"container_state... | Add a state to a container state
Adds a state of type state_type to the given container_state
:param rafcon.gui.models.container_state.ContainerState container_state_m: A model of a container state to add
the new state to
:param rafcon.core.enums.StateType state_type: The type of state that should be added
:return: True if successful, False else | [
"Add",
"a",
"state",
"to",
"a",
"container",
"state"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/helpers/state.py#L113-L144 | train | 40,533 |
DLR-RM/RAFCON | source/rafcon/gui/helpers/state.py | extract_child_models_of_state | def extract_child_models_of_state(state_m, new_state_class):
"""Retrieve child models of state model
The function extracts the child state and state element models of the given state model into a dict. It only
extracts those properties that are required for a state of type `new_state_class`. Transitions are always left out.
:param state_m: state model of which children are to be extracted from
:param new_state_class: The type of the new class
:return:
"""
# check if root state and which type of state
assert isinstance(state_m, StateModel)
assert issubclass(new_state_class, State)
orig_state = state_m.state # only here to get the input parameter of the Core-function
current_state_is_container = isinstance(orig_state, ContainerState)
new_state_is_container = issubclass(new_state_class, ContainerState)
# define which model references to hold for new state
required_model_properties = ['input_data_ports', 'output_data_ports', 'outcomes', 'income']
obsolete_model_properties = []
if current_state_is_container and new_state_is_container: # hold some additional references
# transition are removed when changing the state type, thus do not copy them
required_model_properties.extend(['states', 'data_flows', 'scoped_variables'])
obsolete_model_properties.append('transitions')
elif current_state_is_container:
obsolete_model_properties.extend(['states', 'transitions', 'data_flows', 'scoped_variables'])
def get_element_list(state_m, prop_name):
if prop_name == 'income':
return [state_m.income]
wrapper = getattr(state_m, prop_name)
# ._obj is needed as gaphas wraps observable lists and dicts into a gaphas.support.ObsWrapper
list_or_dict = wrapper._obj
if isinstance(list_or_dict, list):
return list_or_dict[:] # copy list
return list(list_or_dict.values()) # dict
required_child_models = {}
for prop_name in required_model_properties:
required_child_models[prop_name] = get_element_list(state_m, prop_name)
obsolete_child_models = {}
for prop_name in obsolete_model_properties:
obsolete_child_models[prop_name] = get_element_list(state_m, prop_name)
# Special handling of BarrierState, which includes the DeciderState that always becomes obsolete
if isinstance(state_m, ContainerStateModel):
decider_state_m = state_m.states.get(UNIQUE_DECIDER_STATE_ID, None)
if decider_state_m:
if new_state_is_container:
required_child_models['states'].remove(decider_state_m)
obsolete_child_models['states'] = [decider_state_m]
return required_child_models, obsolete_child_models | python | def extract_child_models_of_state(state_m, new_state_class):
"""Retrieve child models of state model
The function extracts the child state and state element models of the given state model into a dict. It only
extracts those properties that are required for a state of type `new_state_class`. Transitions are always left out.
:param state_m: state model of which children are to be extracted from
:param new_state_class: The type of the new class
:return:
"""
# check if root state and which type of state
assert isinstance(state_m, StateModel)
assert issubclass(new_state_class, State)
orig_state = state_m.state # only here to get the input parameter of the Core-function
current_state_is_container = isinstance(orig_state, ContainerState)
new_state_is_container = issubclass(new_state_class, ContainerState)
# define which model references to hold for new state
required_model_properties = ['input_data_ports', 'output_data_ports', 'outcomes', 'income']
obsolete_model_properties = []
if current_state_is_container and new_state_is_container: # hold some additional references
# transition are removed when changing the state type, thus do not copy them
required_model_properties.extend(['states', 'data_flows', 'scoped_variables'])
obsolete_model_properties.append('transitions')
elif current_state_is_container:
obsolete_model_properties.extend(['states', 'transitions', 'data_flows', 'scoped_variables'])
def get_element_list(state_m, prop_name):
if prop_name == 'income':
return [state_m.income]
wrapper = getattr(state_m, prop_name)
# ._obj is needed as gaphas wraps observable lists and dicts into a gaphas.support.ObsWrapper
list_or_dict = wrapper._obj
if isinstance(list_or_dict, list):
return list_or_dict[:] # copy list
return list(list_or_dict.values()) # dict
required_child_models = {}
for prop_name in required_model_properties:
required_child_models[prop_name] = get_element_list(state_m, prop_name)
obsolete_child_models = {}
for prop_name in obsolete_model_properties:
obsolete_child_models[prop_name] = get_element_list(state_m, prop_name)
# Special handling of BarrierState, which includes the DeciderState that always becomes obsolete
if isinstance(state_m, ContainerStateModel):
decider_state_m = state_m.states.get(UNIQUE_DECIDER_STATE_ID, None)
if decider_state_m:
if new_state_is_container:
required_child_models['states'].remove(decider_state_m)
obsolete_child_models['states'] = [decider_state_m]
return required_child_models, obsolete_child_models | [
"def",
"extract_child_models_of_state",
"(",
"state_m",
",",
"new_state_class",
")",
":",
"# check if root state and which type of state",
"assert",
"isinstance",
"(",
"state_m",
",",
"StateModel",
")",
"assert",
"issubclass",
"(",
"new_state_class",
",",
"State",
")",
... | Retrieve child models of state model
The function extracts the child state and state element models of the given state model into a dict. It only
extracts those properties that are required for a state of type `new_state_class`. Transitions are always left out.
:param state_m: state model of which children are to be extracted from
:param new_state_class: The type of the new class
:return: | [
"Retrieve",
"child",
"models",
"of",
"state",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/helpers/state.py#L233-L286 | train | 40,534 |
DLR-RM/RAFCON | source/rafcon/gui/helpers/state.py | create_state_model_for_state | def create_state_model_for_state(new_state, meta, state_element_models):
"""Create a new state model with the defined properties
A state model is created for a state of the type of new_state. All child models in state_element_models (
model list for port, connections and states) are added to the new model.
:param StateModel new_state: The new state object with the correct type
:param Vividict meta: Meta data for the state model
:param list state_element_models: All state element and child state models of the original state model
:return: New state model for new_state with all childs of state_element_models
"""
from rafcon.gui.models.abstract_state import get_state_model_class_for_state
state_m_class = get_state_model_class_for_state(new_state)
new_state_m = state_m_class(new_state, meta=meta, load_meta_data=False, expected_future_models=state_element_models)
error_msg = "New state has not re-used all handed expected future models."
check_expected_future_model_list_is_empty(new_state_m, msg=error_msg)
return new_state_m | python | def create_state_model_for_state(new_state, meta, state_element_models):
"""Create a new state model with the defined properties
A state model is created for a state of the type of new_state. All child models in state_element_models (
model list for port, connections and states) are added to the new model.
:param StateModel new_state: The new state object with the correct type
:param Vividict meta: Meta data for the state model
:param list state_element_models: All state element and child state models of the original state model
:return: New state model for new_state with all childs of state_element_models
"""
from rafcon.gui.models.abstract_state import get_state_model_class_for_state
state_m_class = get_state_model_class_for_state(new_state)
new_state_m = state_m_class(new_state, meta=meta, load_meta_data=False, expected_future_models=state_element_models)
error_msg = "New state has not re-used all handed expected future models."
check_expected_future_model_list_is_empty(new_state_m, msg=error_msg)
return new_state_m | [
"def",
"create_state_model_for_state",
"(",
"new_state",
",",
"meta",
",",
"state_element_models",
")",
":",
"from",
"rafcon",
".",
"gui",
".",
"models",
".",
"abstract_state",
"import",
"get_state_model_class_for_state",
"state_m_class",
"=",
"get_state_model_class_for_s... | Create a new state model with the defined properties
A state model is created for a state of the type of new_state. All child models in state_element_models (
model list for port, connections and states) are added to the new model.
:param StateModel new_state: The new state object with the correct type
:param Vividict meta: Meta data for the state model
:param list state_element_models: All state element and child state models of the original state model
:return: New state model for new_state with all childs of state_element_models | [
"Create",
"a",
"new",
"state",
"model",
"with",
"the",
"defined",
"properties"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/helpers/state.py#L289-L306 | train | 40,535 |
DLR-RM/RAFCON | source/rafcon/gui/helpers/state.py | prepare_state_m_for_insert_as | def prepare_state_m_for_insert_as(state_m_to_insert, previous_state_size):
"""Prepares and scales the meta data to fit into actual size of the state."""
# TODO check how much code is duplicated or could be reused for library fit functionality meta data helper
# TODO DO REFACTORING !!! and move maybe the hole method to meta data and rename it
if isinstance(state_m_to_insert, AbstractStateModel) and \
not gui_helper_meta_data.model_has_empty_meta(state_m_to_insert):
if isinstance(state_m_to_insert, ContainerStateModel):
# print("TARGET1", state_m_to_insert.state.state_element_attrs)
models_dict = {'state': state_m_to_insert}
for state_element_key in state_m_to_insert.state.state_element_attrs:
state_element_list = getattr(state_m_to_insert, state_element_key)
# Some models are hold in a gtkmvc3.support.wrappers.ObsListWrapper, not a list
if hasattr(state_element_list, 'keys'):
state_element_list = state_element_list.values()
models_dict[state_element_key] = {elem.core_element.core_element_id: elem for elem in state_element_list}
resize_factor = gui_helper_meta_data.scale_meta_data_according_state(models_dict, as_template=True)
gui_helper_meta_data.resize_income_of_state_m(state_m_to_insert, resize_factor)
elif isinstance(state_m_to_insert, StateModel):
# print("TARGET2", state_m_to_insert.state.state_element_attrs)
if previous_state_size:
current_size = state_m_to_insert.get_meta_data_editor()['size']
factor = gui_helper_meta_data.divide_two_vectors(current_size, previous_state_size)
state_m_to_insert.set_meta_data_editor('size', previous_state_size)
factor = (min(*factor), min(*factor))
gui_helper_meta_data.resize_state_meta(state_m_to_insert, factor)
else:
logger.debug("For insert as template of {0} no resize of state meta data is performed because "
"the meta data has empty fields.".format(state_m_to_insert))
# library state is not resize because its ports became resized indirectly -> see was resized flag
elif not isinstance(state_m_to_insert, LibraryStateModel):
raise TypeError("For insert as template of {0} no resize of state meta data is performed because "
"state model type is not ContainerStateModel or StateModel".format(state_m_to_insert))
else:
logger.info("For insert as template of {0} no resize of state meta data is performed because the meta data has "
"empty fields.".format(state_m_to_insert)) | python | def prepare_state_m_for_insert_as(state_m_to_insert, previous_state_size):
"""Prepares and scales the meta data to fit into actual size of the state."""
# TODO check how much code is duplicated or could be reused for library fit functionality meta data helper
# TODO DO REFACTORING !!! and move maybe the hole method to meta data and rename it
if isinstance(state_m_to_insert, AbstractStateModel) and \
not gui_helper_meta_data.model_has_empty_meta(state_m_to_insert):
if isinstance(state_m_to_insert, ContainerStateModel):
# print("TARGET1", state_m_to_insert.state.state_element_attrs)
models_dict = {'state': state_m_to_insert}
for state_element_key in state_m_to_insert.state.state_element_attrs:
state_element_list = getattr(state_m_to_insert, state_element_key)
# Some models are hold in a gtkmvc3.support.wrappers.ObsListWrapper, not a list
if hasattr(state_element_list, 'keys'):
state_element_list = state_element_list.values()
models_dict[state_element_key] = {elem.core_element.core_element_id: elem for elem in state_element_list}
resize_factor = gui_helper_meta_data.scale_meta_data_according_state(models_dict, as_template=True)
gui_helper_meta_data.resize_income_of_state_m(state_m_to_insert, resize_factor)
elif isinstance(state_m_to_insert, StateModel):
# print("TARGET2", state_m_to_insert.state.state_element_attrs)
if previous_state_size:
current_size = state_m_to_insert.get_meta_data_editor()['size']
factor = gui_helper_meta_data.divide_two_vectors(current_size, previous_state_size)
state_m_to_insert.set_meta_data_editor('size', previous_state_size)
factor = (min(*factor), min(*factor))
gui_helper_meta_data.resize_state_meta(state_m_to_insert, factor)
else:
logger.debug("For insert as template of {0} no resize of state meta data is performed because "
"the meta data has empty fields.".format(state_m_to_insert))
# library state is not resize because its ports became resized indirectly -> see was resized flag
elif not isinstance(state_m_to_insert, LibraryStateModel):
raise TypeError("For insert as template of {0} no resize of state meta data is performed because "
"state model type is not ContainerStateModel or StateModel".format(state_m_to_insert))
else:
logger.info("For insert as template of {0} no resize of state meta data is performed because the meta data has "
"empty fields.".format(state_m_to_insert)) | [
"def",
"prepare_state_m_for_insert_as",
"(",
"state_m_to_insert",
",",
"previous_state_size",
")",
":",
"# TODO check how much code is duplicated or could be reused for library fit functionality meta data helper",
"# TODO DO REFACTORING !!! and move maybe the hole method to meta data and rename it... | Prepares and scales the meta data to fit into actual size of the state. | [
"Prepares",
"and",
"scales",
"the",
"meta",
"data",
"to",
"fit",
"into",
"actual",
"size",
"of",
"the",
"state",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/helpers/state.py#L414-L454 | train | 40,536 |
DLR-RM/RAFCON | source/rafcon/gui/helpers/state.py | insert_state_as | def insert_state_as(target_state_m, state, as_template):
""" Add a state into a target state
In case the state to be insert is a LibraryState it can be chosen to be insert as template.
:param rafcon.gui.models.container_state.ContainerStateModel target_state_m: State model of the target state
:param rafcon.core.states.State state: State to be insert as template or not
:param bool as_template: The flag determines if a handed state of type LibraryState is insert as template
:return:
"""
if not isinstance(target_state_m, ContainerStateModel) or \
not isinstance(target_state_m.state, ContainerState):
logger.error("States can only be inserted in container states")
return False
state_m = get_state_model_class_for_state(state)(state)
if not as_template:
gui_helper_meta_data.put_default_meta_on_state_m(state_m, target_state_m)
# If inserted as template, we have to extract the state_copy and respective model
else:
assert isinstance(state, LibraryState)
old_lib_state_m = state_m
state_m = state_m.state_copy
previous_state_size = state_m.get_meta_data_editor()['size']
gui_helper_meta_data.put_default_meta_on_state_m(state_m, target_state_m)
# TODO check if the not as template case maybe has to be run with the prepare call
prepare_state_m_for_insert_as(state_m, previous_state_size)
old_lib_state_m.prepare_destruction(recursive=False)
# explicit secure that there is no state_id conflict within target state child states
while state_m.state.state_id in target_state_m.state.states:
state_m.state.change_state_id()
target_state_m.expected_future_models.add(state_m)
target_state_m.state.add_state(state_m.state)
# secure possible missing models to be generated
update_models_recursively(state_m, expected=False) | python | def insert_state_as(target_state_m, state, as_template):
""" Add a state into a target state
In case the state to be insert is a LibraryState it can be chosen to be insert as template.
:param rafcon.gui.models.container_state.ContainerStateModel target_state_m: State model of the target state
:param rafcon.core.states.State state: State to be insert as template or not
:param bool as_template: The flag determines if a handed state of type LibraryState is insert as template
:return:
"""
if not isinstance(target_state_m, ContainerStateModel) or \
not isinstance(target_state_m.state, ContainerState):
logger.error("States can only be inserted in container states")
return False
state_m = get_state_model_class_for_state(state)(state)
if not as_template:
gui_helper_meta_data.put_default_meta_on_state_m(state_m, target_state_m)
# If inserted as template, we have to extract the state_copy and respective model
else:
assert isinstance(state, LibraryState)
old_lib_state_m = state_m
state_m = state_m.state_copy
previous_state_size = state_m.get_meta_data_editor()['size']
gui_helper_meta_data.put_default_meta_on_state_m(state_m, target_state_m)
# TODO check if the not as template case maybe has to be run with the prepare call
prepare_state_m_for_insert_as(state_m, previous_state_size)
old_lib_state_m.prepare_destruction(recursive=False)
# explicit secure that there is no state_id conflict within target state child states
while state_m.state.state_id in target_state_m.state.states:
state_m.state.change_state_id()
target_state_m.expected_future_models.add(state_m)
target_state_m.state.add_state(state_m.state)
# secure possible missing models to be generated
update_models_recursively(state_m, expected=False) | [
"def",
"insert_state_as",
"(",
"target_state_m",
",",
"state",
",",
"as_template",
")",
":",
"if",
"not",
"isinstance",
"(",
"target_state_m",
",",
"ContainerStateModel",
")",
"or",
"not",
"isinstance",
"(",
"target_state_m",
".",
"state",
",",
"ContainerState",
... | Add a state into a target state
In case the state to be insert is a LibraryState it can be chosen to be insert as template.
:param rafcon.gui.models.container_state.ContainerStateModel target_state_m: State model of the target state
:param rafcon.core.states.State state: State to be insert as template or not
:param bool as_template: The flag determines if a handed state of type LibraryState is insert as template
:return: | [
"Add",
"a",
"state",
"into",
"a",
"target",
"state"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/helpers/state.py#L457-L498 | train | 40,537 |
DLR-RM/RAFCON | source/rafcon/gui/helpers/state.py | substitute_state_as | def substitute_state_as(target_state_m, state, as_template, keep_name=False):
""" Substitute a target state with a handed state
The method generates a state model for the state to be inserted and use function substitute_state to finally
substitute the state.
In case the state to be inserted is a LibraryState it can be chosen to be inserted as template.
It can be chosen that the inserted state keeps the name of the target state.
:param rafcon.gui.models.state.AbstractStateModel target_state_m: State model of the state to be substituted
:param rafcon.core.states.State state: State to be inserted
:param bool as_template: The flag determines if a handed state of type LibraryState is insert as template
:param bool keep_name: The flag to keep the name of the target state
:return:
"""
state_m = get_state_model_class_for_state(state)(state)
# If inserted as template, we have to extract the state_copy and model otherwise keep original name
if as_template:
assert isinstance(state_m, LibraryStateModel)
state_m = state_m.state_copy
state_m.state.parent = None
if keep_name:
state_m.state.name = target_state_m.state.name
assert target_state_m.parent.states[target_state_m.state.state_id] is target_state_m
substitute_state(target_state_m, state_m, as_template) | python | def substitute_state_as(target_state_m, state, as_template, keep_name=False):
""" Substitute a target state with a handed state
The method generates a state model for the state to be inserted and use function substitute_state to finally
substitute the state.
In case the state to be inserted is a LibraryState it can be chosen to be inserted as template.
It can be chosen that the inserted state keeps the name of the target state.
:param rafcon.gui.models.state.AbstractStateModel target_state_m: State model of the state to be substituted
:param rafcon.core.states.State state: State to be inserted
:param bool as_template: The flag determines if a handed state of type LibraryState is insert as template
:param bool keep_name: The flag to keep the name of the target state
:return:
"""
state_m = get_state_model_class_for_state(state)(state)
# If inserted as template, we have to extract the state_copy and model otherwise keep original name
if as_template:
assert isinstance(state_m, LibraryStateModel)
state_m = state_m.state_copy
state_m.state.parent = None
if keep_name:
state_m.state.name = target_state_m.state.name
assert target_state_m.parent.states[target_state_m.state.state_id] is target_state_m
substitute_state(target_state_m, state_m, as_template) | [
"def",
"substitute_state_as",
"(",
"target_state_m",
",",
"state",
",",
"as_template",
",",
"keep_name",
"=",
"False",
")",
":",
"state_m",
"=",
"get_state_model_class_for_state",
"(",
"state",
")",
"(",
"state",
")",
"# If inserted as template, we have to extract the s... | Substitute a target state with a handed state
The method generates a state model for the state to be inserted and use function substitute_state to finally
substitute the state.
In case the state to be inserted is a LibraryState it can be chosen to be inserted as template.
It can be chosen that the inserted state keeps the name of the target state.
:param rafcon.gui.models.state.AbstractStateModel target_state_m: State model of the state to be substituted
:param rafcon.core.states.State state: State to be inserted
:param bool as_template: The flag determines if a handed state of type LibraryState is insert as template
:param bool keep_name: The flag to keep the name of the target state
:return: | [
"Substitute",
"a",
"target",
"state",
"with",
"a",
"handed",
"state"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/helpers/state.py#L597-L623 | train | 40,538 |
DLR-RM/RAFCON | source/rafcon/utils/multi_event.py | orify | def orify(e, changed_callback):
"""Add another event to the multi_event
:param e: the event to be added to the multi_event
:param changed_callback: a method to call if the event status changes, this method has access to the multi_event
:return:
"""
if not hasattr(e, "callbacks"): # Event has not been orified yet
e._set = e.set
e._clear = e.clear
e.set = lambda: or_set(e)
e.clear = lambda: or_clear(e)
e.callbacks = list()
# Keep track of one callback per multi event
e.callbacks.append(changed_callback) | python | def orify(e, changed_callback):
"""Add another event to the multi_event
:param e: the event to be added to the multi_event
:param changed_callback: a method to call if the event status changes, this method has access to the multi_event
:return:
"""
if not hasattr(e, "callbacks"): # Event has not been orified yet
e._set = e.set
e._clear = e.clear
e.set = lambda: or_set(e)
e.clear = lambda: or_clear(e)
e.callbacks = list()
# Keep track of one callback per multi event
e.callbacks.append(changed_callback) | [
"def",
"orify",
"(",
"e",
",",
"changed_callback",
")",
":",
"if",
"not",
"hasattr",
"(",
"e",
",",
"\"callbacks\"",
")",
":",
"# Event has not been orified yet",
"e",
".",
"_set",
"=",
"e",
".",
"set",
"e",
".",
"_clear",
"=",
"e",
".",
"clear",
"e",
... | Add another event to the multi_event
:param e: the event to be added to the multi_event
:param changed_callback: a method to call if the event status changes, this method has access to the multi_event
:return: | [
"Add",
"another",
"event",
"to",
"the",
"multi_event"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/multi_event.py#L44-L58 | train | 40,539 |
DLR-RM/RAFCON | source/rafcon/utils/multi_event.py | create | def create(*events):
"""Creates a new multi_event
The multi_event listens to all events passed in the "events" parameter.
:param events: a list of threading.Events
:return: The multi_event
:rtype: threading.Event
"""
or_event = threading.Event()
def changed():
if any([event.is_set() for event in events]):
or_event.set()
else:
or_event.clear()
for e in events:
orify(e, changed)
changed()
return or_event | python | def create(*events):
"""Creates a new multi_event
The multi_event listens to all events passed in the "events" parameter.
:param events: a list of threading.Events
:return: The multi_event
:rtype: threading.Event
"""
or_event = threading.Event()
def changed():
if any([event.is_set() for event in events]):
or_event.set()
else:
or_event.clear()
for e in events:
orify(e, changed)
changed()
return or_event | [
"def",
"create",
"(",
"*",
"events",
")",
":",
"or_event",
"=",
"threading",
".",
"Event",
"(",
")",
"def",
"changed",
"(",
")",
":",
"if",
"any",
"(",
"[",
"event",
".",
"is_set",
"(",
")",
"for",
"event",
"in",
"events",
"]",
")",
":",
"or_even... | Creates a new multi_event
The multi_event listens to all events passed in the "events" parameter.
:param events: a list of threading.Events
:return: The multi_event
:rtype: threading.Event | [
"Creates",
"a",
"new",
"multi_event"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/multi_event.py#L61-L82 | train | 40,540 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/logging_console.py | LoggingConsoleController.model_changed | def model_changed(self, model, prop_name, info):
""" React to configuration changes
Update internal hold enable state, propagates it to view and refresh the text buffer."""
current_enables = self._get_config_enables()
if not self._enables == current_enables:
# check if filtered buffer update needed
filtered_buffer_update_needed = True
if all(self._enables[key] == current_enables[key] for key in ['VERBOSE', 'DEBUG', 'INFO', 'WARNING', 'ERROR']):
follow_mode_key = 'CONSOLE_FOLLOW_LOGGING'
only_follow_mode_changed = self._enables[follow_mode_key] != current_enables[follow_mode_key]
filtered_buffer_update_needed = not only_follow_mode_changed
self._enables = current_enables
self.view.set_enables(self._enables)
if filtered_buffer_update_needed:
self.update_filtered_buffer()
else:
self.view.scroll_to_cursor_onscreen() | python | def model_changed(self, model, prop_name, info):
""" React to configuration changes
Update internal hold enable state, propagates it to view and refresh the text buffer."""
current_enables = self._get_config_enables()
if not self._enables == current_enables:
# check if filtered buffer update needed
filtered_buffer_update_needed = True
if all(self._enables[key] == current_enables[key] for key in ['VERBOSE', 'DEBUG', 'INFO', 'WARNING', 'ERROR']):
follow_mode_key = 'CONSOLE_FOLLOW_LOGGING'
only_follow_mode_changed = self._enables[follow_mode_key] != current_enables[follow_mode_key]
filtered_buffer_update_needed = not only_follow_mode_changed
self._enables = current_enables
self.view.set_enables(self._enables)
if filtered_buffer_update_needed:
self.update_filtered_buffer()
else:
self.view.scroll_to_cursor_onscreen() | [
"def",
"model_changed",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"current_enables",
"=",
"self",
".",
"_get_config_enables",
"(",
")",
"if",
"not",
"self",
".",
"_enables",
"==",
"current_enables",
":",
"# check if filtered buffer upda... | React to configuration changes
Update internal hold enable state, propagates it to view and refresh the text buffer. | [
"React",
"to",
"configuration",
"changes"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/logging_console.py#L102-L120 | train | 40,541 |
DLR-RM/RAFCON | source/rafcon/utils/filesystem.py | create_path | def create_path(path):
"""Creates a absolute path in the file system.
:param path: The path to be created
"""
import os
if not os.path.exists(path):
os.makedirs(path) | python | def create_path(path):
"""Creates a absolute path in the file system.
:param path: The path to be created
"""
import os
if not os.path.exists(path):
os.makedirs(path) | [
"def",
"create_path",
"(",
"path",
")",
":",
"import",
"os",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"os",
".",
"makedirs",
"(",
"path",
")"
] | Creates a absolute path in the file system.
:param path: The path to be created | [
"Creates",
"a",
"absolute",
"path",
"in",
"the",
"file",
"system",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/filesystem.py#L27-L34 | train | 40,542 |
DLR-RM/RAFCON | source/rafcon/utils/filesystem.py | get_md5_file_hash | def get_md5_file_hash(filename):
"""Calculates the MD5 hash of a file
:param str filename: The filename (including the path) of the file
:return: Md5 hash of the file
:rtype: str
"""
import hashlib
BLOCKSIZE = 65536
hasher = hashlib.md5()
with open(filename, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
return hasher.hexdigest() | python | def get_md5_file_hash(filename):
"""Calculates the MD5 hash of a file
:param str filename: The filename (including the path) of the file
:return: Md5 hash of the file
:rtype: str
"""
import hashlib
BLOCKSIZE = 65536
hasher = hashlib.md5()
with open(filename, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
return hasher.hexdigest() | [
"def",
"get_md5_file_hash",
"(",
"filename",
")",
":",
"import",
"hashlib",
"BLOCKSIZE",
"=",
"65536",
"hasher",
"=",
"hashlib",
".",
"md5",
"(",
")",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"afile",
":",
"buf",
"=",
"afile",
".",
"rea... | Calculates the MD5 hash of a file
:param str filename: The filename (including the path) of the file
:return: Md5 hash of the file
:rtype: str | [
"Calculates",
"the",
"MD5",
"hash",
"of",
"a",
"file"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/filesystem.py#L37-L52 | train | 40,543 |
DLR-RM/RAFCON | source/rafcon/utils/filesystem.py | file_needs_update | def file_needs_update(target_file, source_file):
"""Checks if target_file is not existing or differing from source_file
:param target_file: File target for a copy action
:param source_file: File to be copied
:return: True, if target_file not existing or differing from source_file, else False
:rtype: False
"""
if not os.path.isfile(target_file) or get_md5_file_hash(target_file) != get_md5_file_hash(source_file):
return True
return False | python | def file_needs_update(target_file, source_file):
"""Checks if target_file is not existing or differing from source_file
:param target_file: File target for a copy action
:param source_file: File to be copied
:return: True, if target_file not existing or differing from source_file, else False
:rtype: False
"""
if not os.path.isfile(target_file) or get_md5_file_hash(target_file) != get_md5_file_hash(source_file):
return True
return False | [
"def",
"file_needs_update",
"(",
"target_file",
",",
"source_file",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"target_file",
")",
"or",
"get_md5_file_hash",
"(",
"target_file",
")",
"!=",
"get_md5_file_hash",
"(",
"source_file",
")",
":",
... | Checks if target_file is not existing or differing from source_file
:param target_file: File target for a copy action
:param source_file: File to be copied
:return: True, if target_file not existing or differing from source_file, else False
:rtype: False | [
"Checks",
"if",
"target_file",
"is",
"not",
"existing",
"or",
"differing",
"from",
"source_file"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/filesystem.py#L55-L65 | train | 40,544 |
DLR-RM/RAFCON | source/rafcon/utils/filesystem.py | copy_file_if_update_required | def copy_file_if_update_required(source_file, target_file):
"""Copies source_file to target_file if latter one in not existing or outdated
:param source_file: Source file of the copy operation
:param target_file: Target file of the copy operation
"""
if file_needs_update(target_file, source_file):
shutil.copy(source_file, target_file) | python | def copy_file_if_update_required(source_file, target_file):
"""Copies source_file to target_file if latter one in not existing or outdated
:param source_file: Source file of the copy operation
:param target_file: Target file of the copy operation
"""
if file_needs_update(target_file, source_file):
shutil.copy(source_file, target_file) | [
"def",
"copy_file_if_update_required",
"(",
"source_file",
",",
"target_file",
")",
":",
"if",
"file_needs_update",
"(",
"target_file",
",",
"source_file",
")",
":",
"shutil",
".",
"copy",
"(",
"source_file",
",",
"target_file",
")"
] | Copies source_file to target_file if latter one in not existing or outdated
:param source_file: Source file of the copy operation
:param target_file: Target file of the copy operation | [
"Copies",
"source_file",
"to",
"target_file",
"if",
"latter",
"one",
"in",
"not",
"existing",
"or",
"outdated"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/filesystem.py#L68-L75 | train | 40,545 |
DLR-RM/RAFCON | source/rafcon/utils/filesystem.py | read_file | def read_file(file_path, filename=None):
""" Open file by path and optional filename
If no file name is given the path is interpreted as direct path to the file to be read.
If there is no file at location the return value will be None to offer a option for case handling.
:param str file_path: Path string.
:param str filename: File name of the file to be read.
:return: None or str
"""
file_path = os.path.realpath(file_path)
if filename:
file_path = os.path.join(file_path, filename)
file_content = None
if os.path.isfile(file_path):
with open(file_path, 'r') as file_pointer:
file_content = file_pointer.read()
return file_content | python | def read_file(file_path, filename=None):
""" Open file by path and optional filename
If no file name is given the path is interpreted as direct path to the file to be read.
If there is no file at location the return value will be None to offer a option for case handling.
:param str file_path: Path string.
:param str filename: File name of the file to be read.
:return: None or str
"""
file_path = os.path.realpath(file_path)
if filename:
file_path = os.path.join(file_path, filename)
file_content = None
if os.path.isfile(file_path):
with open(file_path, 'r') as file_pointer:
file_content = file_pointer.read()
return file_content | [
"def",
"read_file",
"(",
"file_path",
",",
"filename",
"=",
"None",
")",
":",
"file_path",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"file_path",
")",
"if",
"filename",
":",
"file_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"file_path",
",",
... | Open file by path and optional filename
If no file name is given the path is interpreted as direct path to the file to be read.
If there is no file at location the return value will be None to offer a option for case handling.
:param str file_path: Path string.
:param str filename: File name of the file to be read.
:return: None or str | [
"Open",
"file",
"by",
"path",
"and",
"optional",
"filename"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/filesystem.py#L78-L97 | train | 40,546 |
DLR-RM/RAFCON | source/rafcon/utils/filesystem.py | clean_file_system_paths_from_not_existing_paths | def clean_file_system_paths_from_not_existing_paths(file_system_paths):
"""Cleans list of paths from elements that do not exist
If a path is no more valid/existing, it is removed from the list.
:param list[str] file_system_paths: list of file system paths to be checked for existing
"""
paths_to_delete = []
for path in file_system_paths:
if not os.path.exists(path):
paths_to_delete.append(path)
for path in paths_to_delete:
file_system_paths.remove(path) | python | def clean_file_system_paths_from_not_existing_paths(file_system_paths):
"""Cleans list of paths from elements that do not exist
If a path is no more valid/existing, it is removed from the list.
:param list[str] file_system_paths: list of file system paths to be checked for existing
"""
paths_to_delete = []
for path in file_system_paths:
if not os.path.exists(path):
paths_to_delete.append(path)
for path in paths_to_delete:
file_system_paths.remove(path) | [
"def",
"clean_file_system_paths_from_not_existing_paths",
"(",
"file_system_paths",
")",
":",
"paths_to_delete",
"=",
"[",
"]",
"for",
"path",
"in",
"file_system_paths",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"paths_to_delete",
... | Cleans list of paths from elements that do not exist
If a path is no more valid/existing, it is removed from the list.
:param list[str] file_system_paths: list of file system paths to be checked for existing | [
"Cleans",
"list",
"of",
"paths",
"from",
"elements",
"that",
"do",
"not",
"exist"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/filesystem.py#L123-L135 | train | 40,547 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel.update_models | def update_models(self, model, name, info):
""" This method is always triggered when the core state changes
It keeps the following models/model-lists consistent:
input-data-port models
output-data-port models
outcome models
"""
if info.method_name in ["add_input_data_port", "remove_input_data_port", "input_data_ports"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("input_data_port")
elif info.method_name in ["add_output_data_port", "remove_output_data_port", "output_data_ports"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("output_data_port")
elif info.method_name in ["add_income", "remove_income", "income"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("income")
elif info.method_name in ["add_outcome", "remove_outcome", "outcomes"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("outcome")
else:
return
if "add" in info.method_name:
self.add_missing_model(model_list, data_list, model_name, model_class, model_key)
elif "remove" in info.method_name:
destroy = info.kwargs.get('destroy', True)
self.remove_specific_model(model_list, info.result, model_key, destroy)
elif info.method_name in ["input_data_ports", "output_data_ports", "income", "outcomes"]:
self.re_initiate_model_list(model_list, data_list, model_name, model_class, model_key) | python | def update_models(self, model, name, info):
""" This method is always triggered when the core state changes
It keeps the following models/model-lists consistent:
input-data-port models
output-data-port models
outcome models
"""
if info.method_name in ["add_input_data_port", "remove_input_data_port", "input_data_ports"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("input_data_port")
elif info.method_name in ["add_output_data_port", "remove_output_data_port", "output_data_ports"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("output_data_port")
elif info.method_name in ["add_income", "remove_income", "income"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("income")
elif info.method_name in ["add_outcome", "remove_outcome", "outcomes"]:
(model_list, data_list, model_name, model_class, model_key) = self.get_model_info("outcome")
else:
return
if "add" in info.method_name:
self.add_missing_model(model_list, data_list, model_name, model_class, model_key)
elif "remove" in info.method_name:
destroy = info.kwargs.get('destroy', True)
self.remove_specific_model(model_list, info.result, model_key, destroy)
elif info.method_name in ["input_data_ports", "output_data_ports", "income", "outcomes"]:
self.re_initiate_model_list(model_list, data_list, model_name, model_class, model_key) | [
"def",
"update_models",
"(",
"self",
",",
"model",
",",
"name",
",",
"info",
")",
":",
"if",
"info",
".",
"method_name",
"in",
"[",
"\"add_input_data_port\"",
",",
"\"remove_input_data_port\"",
",",
"\"input_data_ports\"",
"]",
":",
"(",
"model_list",
",",
"da... | This method is always triggered when the core state changes
It keeps the following models/model-lists consistent:
input-data-port models
output-data-port models
outcome models | [
"This",
"method",
"is",
"always",
"triggered",
"when",
"the",
"core",
"state",
"changes"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L139-L165 | train | 40,548 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel._load_income_model | def _load_income_model(self):
""" Create income model from core income """
self._add_model(self.income, self.state.income, IncomeModel) | python | def _load_income_model(self):
""" Create income model from core income """
self._add_model(self.income, self.state.income, IncomeModel) | [
"def",
"_load_income_model",
"(",
"self",
")",
":",
"self",
".",
"_add_model",
"(",
"self",
".",
"income",
",",
"self",
".",
"state",
".",
"income",
",",
"IncomeModel",
")"
] | Create income model from core income | [
"Create",
"income",
"model",
"from",
"core",
"income"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L181-L183 | train | 40,549 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel._load_outcome_models | def _load_outcome_models(self):
""" Create outcome models from core outcomes """
self.outcomes = []
for outcome in self.state.outcomes.values():
self._add_model(self.outcomes, outcome, OutcomeModel) | python | def _load_outcome_models(self):
""" Create outcome models from core outcomes """
self.outcomes = []
for outcome in self.state.outcomes.values():
self._add_model(self.outcomes, outcome, OutcomeModel) | [
"def",
"_load_outcome_models",
"(",
"self",
")",
":",
"self",
".",
"outcomes",
"=",
"[",
"]",
"for",
"outcome",
"in",
"self",
".",
"state",
".",
"outcomes",
".",
"values",
"(",
")",
":",
"self",
".",
"_add_model",
"(",
"self",
".",
"outcomes",
",",
"... | Create outcome models from core outcomes | [
"Create",
"outcome",
"models",
"from",
"core",
"outcomes"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L185-L189 | train | 40,550 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel.re_initiate_model_list | def re_initiate_model_list(self, model_list_or_dict, core_objects_dict, model_name, model_class, model_key):
"""Recreate model list
The method re-initiate a handed list or dictionary of models with the new dictionary of core-objects.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_objects_dict: new dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return:
"""
if model_name == "income":
if self.income.income != self.state.income:
self._add_model(self.income, self.state.income, IncomeModel)
return
for _ in range(len(model_list_or_dict)):
self.remove_additional_model(model_list_or_dict, core_objects_dict, model_name, model_key)
if core_objects_dict:
for _ in core_objects_dict:
self.add_missing_model(model_list_or_dict, core_objects_dict, model_name, model_class, model_key) | python | def re_initiate_model_list(self, model_list_or_dict, core_objects_dict, model_name, model_class, model_key):
"""Recreate model list
The method re-initiate a handed list or dictionary of models with the new dictionary of core-objects.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_objects_dict: new dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return:
"""
if model_name == "income":
if self.income.income != self.state.income:
self._add_model(self.income, self.state.income, IncomeModel)
return
for _ in range(len(model_list_or_dict)):
self.remove_additional_model(model_list_or_dict, core_objects_dict, model_name, model_key)
if core_objects_dict:
for _ in core_objects_dict:
self.add_missing_model(model_list_or_dict, core_objects_dict, model_name, model_class, model_key) | [
"def",
"re_initiate_model_list",
"(",
"self",
",",
"model_list_or_dict",
",",
"core_objects_dict",
",",
"model_name",
",",
"model_class",
",",
"model_key",
")",
":",
"if",
"model_name",
"==",
"\"income\"",
":",
"if",
"self",
".",
"income",
".",
"income",
"!=",
... | Recreate model list
The method re-initiate a handed list or dictionary of models with the new dictionary of core-objects.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_objects_dict: new dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return: | [
"Recreate",
"model",
"list"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L191-L214 | train | 40,551 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel._add_model | def _add_model(self, model_list_or_dict, core_element, model_class, model_key=None, load_meta_data=True):
"""Adds one model for a given core element.
The method will add a model for a given core object and checks if there is a corresponding model object in the
future expected model list. The method does not check if an object with corresponding model has already been
inserted.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_element: the core element to a model for, can be state or state element
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:param load_meta_data: specific argument for loading meta data
:return:
"""
found_model = self._get_future_expected_model(core_element)
if found_model:
found_model.parent = self
if model_class is IncomeModel:
self.income = found_model if found_model else IncomeModel(core_element, self)
return
if model_key is None:
model_list_or_dict.append(found_model if found_model else model_class(core_element, self))
else:
model_list_or_dict[model_key] = found_model if found_model else model_class(core_element, self,
load_meta_data=load_meta_data) | python | def _add_model(self, model_list_or_dict, core_element, model_class, model_key=None, load_meta_data=True):
"""Adds one model for a given core element.
The method will add a model for a given core object and checks if there is a corresponding model object in the
future expected model list. The method does not check if an object with corresponding model has already been
inserted.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_element: the core element to a model for, can be state or state element
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:param load_meta_data: specific argument for loading meta data
:return:
"""
found_model = self._get_future_expected_model(core_element)
if found_model:
found_model.parent = self
if model_class is IncomeModel:
self.income = found_model if found_model else IncomeModel(core_element, self)
return
if model_key is None:
model_list_or_dict.append(found_model if found_model else model_class(core_element, self))
else:
model_list_or_dict[model_key] = found_model if found_model else model_class(core_element, self,
load_meta_data=load_meta_data) | [
"def",
"_add_model",
"(",
"self",
",",
"model_list_or_dict",
",",
"core_element",
",",
"model_class",
",",
"model_key",
"=",
"None",
",",
"load_meta_data",
"=",
"True",
")",
":",
"found_model",
"=",
"self",
".",
"_get_future_expected_model",
"(",
"core_element",
... | Adds one model for a given core element.
The method will add a model for a given core object and checks if there is a corresponding model object in the
future expected model list. The method does not check if an object with corresponding model has already been
inserted.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_element: the core element to a model for, can be state or state element
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:param load_meta_data: specific argument for loading meta data
:return: | [
"Adds",
"one",
"model",
"for",
"a",
"given",
"core",
"element",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L216-L244 | train | 40,552 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel.add_missing_model | def add_missing_model(self, model_list_or_dict, core_elements_dict, model_name, model_class, model_key):
"""Adds one missing model
The method will search for the first core-object out of core_object_dict
not represented in the list or dict of models handed by model_list_or_dict, adds it and returns without continue
to search for more objects which maybe are missing in model_list_or_dict with respect to the
core_object_dict.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_elements_dict: dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return: True, is a new model was added, False else
:rtype: bool
"""
def core_element_has_model(core_object):
for model_or_key in model_list_or_dict:
model = model_or_key if model_key is None else model_list_or_dict[model_or_key]
if core_object is getattr(model, model_name):
return True
return False
if model_name == "income":
self._add_model(self.income, self.state.income, IncomeModel)
return
for core_element in core_elements_dict.values():
if core_element_has_model(core_element):
continue
# get expected model and connect it to self or create a new model
new_model = self._get_future_expected_model(core_element)
if new_model:
new_model.parent = self
else:
if type_helpers.type_inherits_of_type(model_class, StateModel):
new_model = model_class(core_element, self, expected_future_models=self.expected_future_models)
self.expected_future_models = new_model.expected_future_models # update reused models
new_model.expected_future_models = set() # clean the field because should not be used further
else:
new_model = model_class(core_element, self)
# insert new model into list or dict
if model_key is None:
model_list_or_dict.append(new_model)
else:
model_list_or_dict[getattr(core_element, model_key)] = new_model
return True
return False | python | def add_missing_model(self, model_list_or_dict, core_elements_dict, model_name, model_class, model_key):
"""Adds one missing model
The method will search for the first core-object out of core_object_dict
not represented in the list or dict of models handed by model_list_or_dict, adds it and returns without continue
to search for more objects which maybe are missing in model_list_or_dict with respect to the
core_object_dict.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_elements_dict: dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return: True, is a new model was added, False else
:rtype: bool
"""
def core_element_has_model(core_object):
for model_or_key in model_list_or_dict:
model = model_or_key if model_key is None else model_list_or_dict[model_or_key]
if core_object is getattr(model, model_name):
return True
return False
if model_name == "income":
self._add_model(self.income, self.state.income, IncomeModel)
return
for core_element in core_elements_dict.values():
if core_element_has_model(core_element):
continue
# get expected model and connect it to self or create a new model
new_model = self._get_future_expected_model(core_element)
if new_model:
new_model.parent = self
else:
if type_helpers.type_inherits_of_type(model_class, StateModel):
new_model = model_class(core_element, self, expected_future_models=self.expected_future_models)
self.expected_future_models = new_model.expected_future_models # update reused models
new_model.expected_future_models = set() # clean the field because should not be used further
else:
new_model = model_class(core_element, self)
# insert new model into list or dict
if model_key is None:
model_list_or_dict.append(new_model)
else:
model_list_or_dict[getattr(core_element, model_key)] = new_model
return True
return False | [
"def",
"add_missing_model",
"(",
"self",
",",
"model_list_or_dict",
",",
"core_elements_dict",
",",
"model_name",
",",
"model_class",
",",
"model_key",
")",
":",
"def",
"core_element_has_model",
"(",
"core_object",
")",
":",
"for",
"model_or_key",
"in",
"model_list_... | Adds one missing model
The method will search for the first core-object out of core_object_dict
not represented in the list or dict of models handed by model_list_or_dict, adds it and returns without continue
to search for more objects which maybe are missing in model_list_or_dict with respect to the
core_object_dict.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_elements_dict: dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_class: model-class of the elements that should be insert
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return: True, is a new model was added, False else
:rtype: bool | [
"Adds",
"one",
"missing",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L246-L296 | train | 40,553 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel.remove_additional_model | def remove_additional_model(self, model_list_or_dict, core_objects_dict, model_name, model_key, destroy=True):
"""Remove one unnecessary model
The method will search for the first model-object out of
model_list_or_dict that represents no core-object in the dictionary of core-objects handed by core_objects_dict,
remove it and return without continue to search for more model-objects which maybe are unnecessary, too.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_objects_dict: dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return:
"""
if model_name == "income":
self.income.prepare_destruction()
self.income = None
return
for model_or_key in model_list_or_dict:
model = model_or_key if model_key is None else model_list_or_dict[model_or_key]
found = False
for core_object in core_objects_dict.values():
if core_object is getattr(model, model_name):
found = True
break
if not found:
if model_key is None:
if destroy:
model.prepare_destruction()
model_list_or_dict.remove(model)
else:
if destroy:
model_list_or_dict[model_or_key].prepare_destruction()
del model_list_or_dict[model_or_key]
return | python | def remove_additional_model(self, model_list_or_dict, core_objects_dict, model_name, model_key, destroy=True):
"""Remove one unnecessary model
The method will search for the first model-object out of
model_list_or_dict that represents no core-object in the dictionary of core-objects handed by core_objects_dict,
remove it and return without continue to search for more model-objects which maybe are unnecessary, too.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_objects_dict: dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return:
"""
if model_name == "income":
self.income.prepare_destruction()
self.income = None
return
for model_or_key in model_list_or_dict:
model = model_or_key if model_key is None else model_list_or_dict[model_or_key]
found = False
for core_object in core_objects_dict.values():
if core_object is getattr(model, model_name):
found = True
break
if not found:
if model_key is None:
if destroy:
model.prepare_destruction()
model_list_or_dict.remove(model)
else:
if destroy:
model_list_or_dict[model_or_key].prepare_destruction()
del model_list_or_dict[model_or_key]
return | [
"def",
"remove_additional_model",
"(",
"self",
",",
"model_list_or_dict",
",",
"core_objects_dict",
",",
"model_name",
",",
"model_key",
",",
"destroy",
"=",
"True",
")",
":",
"if",
"model_name",
"==",
"\"income\"",
":",
"self",
".",
"income",
".",
"prepare_dest... | Remove one unnecessary model
The method will search for the first model-object out of
model_list_or_dict that represents no core-object in the dictionary of core-objects handed by core_objects_dict,
remove it and return without continue to search for more model-objects which maybe are unnecessary, too.
:param model_list_or_dict: could be a list or dictionary of one model type
:param core_objects_dict: dictionary of one type of core-elements (rafcon.core)
:param model_name: prop_name for the core-element hold by the model, this core-element is covered by the model
:param model_key: if model_list_or_dict is a dictionary the key is the id of the respective element
(e.g. 'state_id')
:return: | [
"Remove",
"one",
"unnecessary",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L317-L352 | train | 40,554 |
DLR-RM/RAFCON | source/rafcon/gui/models/state.py | StateModel._get_future_expected_model | def _get_future_expected_model(self, core_element):
"""Hand model for an core element from expected model list and remove the model from this list"""
for model in self.expected_future_models:
if model.core_element is core_element:
# print("expected_future_model found -> remove model:", model, [model], id(model))
self.expected_future_models.remove(model)
return model
return None | python | def _get_future_expected_model(self, core_element):
"""Hand model for an core element from expected model list and remove the model from this list"""
for model in self.expected_future_models:
if model.core_element is core_element:
# print("expected_future_model found -> remove model:", model, [model], id(model))
self.expected_future_models.remove(model)
return model
return None | [
"def",
"_get_future_expected_model",
"(",
"self",
",",
"core_element",
")",
":",
"for",
"model",
"in",
"self",
".",
"expected_future_models",
":",
"if",
"model",
".",
"core_element",
"is",
"core_element",
":",
"# print(\"expected_future_model found -> remove model:\", mod... | Hand model for an core element from expected model list and remove the model from this list | [
"Hand",
"model",
"for",
"an",
"core",
"element",
"from",
"expected",
"model",
"list",
"and",
"remove",
"the",
"model",
"from",
"this",
"list"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/state.py#L354-L361 | train | 40,555 |
DLR-RM/RAFCON | source/rafcon/gui/models/config_model.py | ConfigModel.as_dict | def as_dict(self, use_preliminary=False):
"""Create a copy of the config in form of a dict
:param bool use_preliminary: Whether to include the preliminary config
:return: A dict with the copy of the config
:rtype: dict
"""
config = dict()
for key in self.config.keys:
if use_preliminary and key in self.preliminary_config:
value = self.preliminary_config[key]
else:
value = self.config.get_config_value(key)
config[key] = value
return config | python | def as_dict(self, use_preliminary=False):
"""Create a copy of the config in form of a dict
:param bool use_preliminary: Whether to include the preliminary config
:return: A dict with the copy of the config
:rtype: dict
"""
config = dict()
for key in self.config.keys:
if use_preliminary and key in self.preliminary_config:
value = self.preliminary_config[key]
else:
value = self.config.get_config_value(key)
config[key] = value
return config | [
"def",
"as_dict",
"(",
"self",
",",
"use_preliminary",
"=",
"False",
")",
":",
"config",
"=",
"dict",
"(",
")",
"for",
"key",
"in",
"self",
".",
"config",
".",
"keys",
":",
"if",
"use_preliminary",
"and",
"key",
"in",
"self",
".",
"preliminary_config",
... | Create a copy of the config in form of a dict
:param bool use_preliminary: Whether to include the preliminary config
:return: A dict with the copy of the config
:rtype: dict | [
"Create",
"a",
"copy",
"of",
"the",
"config",
"in",
"form",
"of",
"a",
"dict"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/config_model.py#L45-L59 | train | 40,556 |
DLR-RM/RAFCON | source/rafcon/gui/models/config_model.py | ConfigModel.update_config | def update_config(self, config_dict, config_file):
"""Update the content and reference of the config
:param dict config_dict: The new configuration
:param str config_file: The new file reference
"""
config_path = path.dirname(config_file)
self.config.config_file_path = config_file
self.config.path = config_path
for config_key, config_value in config_dict.items():
if config_value != self.config.get_config_value(config_key):
self.set_preliminary_config_value(config_key, config_value) | python | def update_config(self, config_dict, config_file):
"""Update the content and reference of the config
:param dict config_dict: The new configuration
:param str config_file: The new file reference
"""
config_path = path.dirname(config_file)
self.config.config_file_path = config_file
self.config.path = config_path
for config_key, config_value in config_dict.items():
if config_value != self.config.get_config_value(config_key):
self.set_preliminary_config_value(config_key, config_value) | [
"def",
"update_config",
"(",
"self",
",",
"config_dict",
",",
"config_file",
")",
":",
"config_path",
"=",
"path",
".",
"dirname",
"(",
"config_file",
")",
"self",
".",
"config",
".",
"config_file_path",
"=",
"config_file",
"self",
".",
"config",
".",
"path"... | Update the content and reference of the config
:param dict config_dict: The new configuration
:param str config_file: The new file reference | [
"Update",
"the",
"content",
"and",
"reference",
"of",
"the",
"config"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/config_model.py#L61-L72 | train | 40,557 |
DLR-RM/RAFCON | source/rafcon/gui/models/config_model.py | ConfigModel.get_current_config_value | def get_current_config_value(self, config_key, use_preliminary=True, default=None):
"""Returns the current config value for the given config key
:param str config_key: Config key who's value is requested
:param bool use_preliminary: Whether the preliminary config should be queried first
:param default: The value to return if config key does not exist
:return: Copy of the config value
"""
if use_preliminary and config_key in self.preliminary_config:
return copy(self.preliminary_config[config_key])
return copy(self.config.get_config_value(config_key, default)) | python | def get_current_config_value(self, config_key, use_preliminary=True, default=None):
"""Returns the current config value for the given config key
:param str config_key: Config key who's value is requested
:param bool use_preliminary: Whether the preliminary config should be queried first
:param default: The value to return if config key does not exist
:return: Copy of the config value
"""
if use_preliminary and config_key in self.preliminary_config:
return copy(self.preliminary_config[config_key])
return copy(self.config.get_config_value(config_key, default)) | [
"def",
"get_current_config_value",
"(",
"self",
",",
"config_key",
",",
"use_preliminary",
"=",
"True",
",",
"default",
"=",
"None",
")",
":",
"if",
"use_preliminary",
"and",
"config_key",
"in",
"self",
".",
"preliminary_config",
":",
"return",
"copy",
"(",
"s... | Returns the current config value for the given config key
:param str config_key: Config key who's value is requested
:param bool use_preliminary: Whether the preliminary config should be queried first
:param default: The value to return if config key does not exist
:return: Copy of the config value | [
"Returns",
"the",
"current",
"config",
"value",
"for",
"the",
"given",
"config",
"key"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/config_model.py#L74-L84 | train | 40,558 |
DLR-RM/RAFCON | source/rafcon/gui/models/config_model.py | ConfigModel.set_preliminary_config_value | def set_preliminary_config_value(self, config_key, config_value):
"""Stores a config value as preliminary new value
The config value is not yet applied to the configuration. If the value is identical to the one from the
configuration, the entry is deleted from the preliminary config.
:param str config_key: Key of the entry
:param config_value: New value
"""
if config_value != self.config.get_config_value(config_key):
self.preliminary_config[config_key] = config_value
# If the value was reverted to its original value, we can remove the entry
elif config_key in self.preliminary_config:
del self.preliminary_config[config_key] | python | def set_preliminary_config_value(self, config_key, config_value):
"""Stores a config value as preliminary new value
The config value is not yet applied to the configuration. If the value is identical to the one from the
configuration, the entry is deleted from the preliminary config.
:param str config_key: Key of the entry
:param config_value: New value
"""
if config_value != self.config.get_config_value(config_key):
self.preliminary_config[config_key] = config_value
# If the value was reverted to its original value, we can remove the entry
elif config_key in self.preliminary_config:
del self.preliminary_config[config_key] | [
"def",
"set_preliminary_config_value",
"(",
"self",
",",
"config_key",
",",
"config_value",
")",
":",
"if",
"config_value",
"!=",
"self",
".",
"config",
".",
"get_config_value",
"(",
"config_key",
")",
":",
"self",
".",
"preliminary_config",
"[",
"config_key",
"... | Stores a config value as preliminary new value
The config value is not yet applied to the configuration. If the value is identical to the one from the
configuration, the entry is deleted from the preliminary config.
:param str config_key: Key of the entry
:param config_value: New value | [
"Stores",
"a",
"config",
"value",
"as",
"preliminary",
"new",
"value"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/config_model.py#L86-L99 | train | 40,559 |
DLR-RM/RAFCON | source/rafcon/gui/models/config_model.py | ConfigModel.apply_preliminary_config | def apply_preliminary_config(self, save=True):
"""Applies the preliminary config to the configuration
:param bool save: Whether the config file is be be written to the file system
:return: Whether the applied changes require a refresh of the state machines
:rtype: bool
"""
state_machine_refresh_required = False
for config_key, config_value in self.preliminary_config.items():
self.config.set_config_value(config_key, config_value)
if config_key in self.config.keys_requiring_state_machine_refresh:
state_machine_refresh_required = True
elif config_key in self.config.keys_requiring_restart:
self.changed_keys_requiring_restart.add(config_key)
if config_key == 'AUTO_RECOVERY_LOCK_ENABLED':
import rafcon.gui.models.auto_backup
if config_value:
rafcon.gui.models.auto_backup.generate_rafcon_instance_lock_file()
else:
rafcon.gui.models.auto_backup.remove_rafcon_instance_lock_file()
self.preliminary_config.clear()
if save:
self.config.save_configuration()
return state_machine_refresh_required | python | def apply_preliminary_config(self, save=True):
"""Applies the preliminary config to the configuration
:param bool save: Whether the config file is be be written to the file system
:return: Whether the applied changes require a refresh of the state machines
:rtype: bool
"""
state_machine_refresh_required = False
for config_key, config_value in self.preliminary_config.items():
self.config.set_config_value(config_key, config_value)
if config_key in self.config.keys_requiring_state_machine_refresh:
state_machine_refresh_required = True
elif config_key in self.config.keys_requiring_restart:
self.changed_keys_requiring_restart.add(config_key)
if config_key == 'AUTO_RECOVERY_LOCK_ENABLED':
import rafcon.gui.models.auto_backup
if config_value:
rafcon.gui.models.auto_backup.generate_rafcon_instance_lock_file()
else:
rafcon.gui.models.auto_backup.remove_rafcon_instance_lock_file()
self.preliminary_config.clear()
if save:
self.config.save_configuration()
return state_machine_refresh_required | [
"def",
"apply_preliminary_config",
"(",
"self",
",",
"save",
"=",
"True",
")",
":",
"state_machine_refresh_required",
"=",
"False",
"for",
"config_key",
",",
"config_value",
"in",
"self",
".",
"preliminary_config",
".",
"items",
"(",
")",
":",
"self",
".",
"co... | Applies the preliminary config to the configuration
:param bool save: Whether the config file is be be written to the file system
:return: Whether the applied changes require a refresh of the state machines
:rtype: bool | [
"Applies",
"the",
"preliminary",
"config",
"to",
"the",
"configuration"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/models/config_model.py#L101-L125 | train | 40,560 |
DLR-RM/RAFCON | source/rafcon/core/state_elements/state_element.py | StateElement.parent | def parent(self, parent):
"""Setter for the parent state of the state element
:param rafcon.core.states.state.State parent: Parent state or None
"""
if parent is None:
self._parent = None
else:
from rafcon.core.states.state import State
assert isinstance(parent, State)
old_parent = self.parent
self._parent = ref(parent)
valid, message = self._check_validity()
if not valid:
if not old_parent:
self._parent = None
else:
self._parent = ref(old_parent)
class_name = self.__class__.__name__
if global_config.get_config_value("LIBRARY_RECOVERY_MODE") is True:
do_delete_item = True
# In case of just the data type is wrong raise an Exception but keep the data flow
if "not have matching data types" in message:
do_delete_item = False
self._parent = ref(parent)
raise RecoveryModeException("{0} invalid within state \"{1}\" (id {2}): {3}".format(
class_name, parent.name, parent.state_id, message), do_delete_item=do_delete_item)
else:
raise ValueError("{0} invalid within state \"{1}\" (id {2}): {3} {4}".format(
class_name, parent.name, parent.state_id, message, self)) | python | def parent(self, parent):
"""Setter for the parent state of the state element
:param rafcon.core.states.state.State parent: Parent state or None
"""
if parent is None:
self._parent = None
else:
from rafcon.core.states.state import State
assert isinstance(parent, State)
old_parent = self.parent
self._parent = ref(parent)
valid, message = self._check_validity()
if not valid:
if not old_parent:
self._parent = None
else:
self._parent = ref(old_parent)
class_name = self.__class__.__name__
if global_config.get_config_value("LIBRARY_RECOVERY_MODE") is True:
do_delete_item = True
# In case of just the data type is wrong raise an Exception but keep the data flow
if "not have matching data types" in message:
do_delete_item = False
self._parent = ref(parent)
raise RecoveryModeException("{0} invalid within state \"{1}\" (id {2}): {3}".format(
class_name, parent.name, parent.state_id, message), do_delete_item=do_delete_item)
else:
raise ValueError("{0} invalid within state \"{1}\" (id {2}): {3} {4}".format(
class_name, parent.name, parent.state_id, message, self)) | [
"def",
"parent",
"(",
"self",
",",
"parent",
")",
":",
"if",
"parent",
"is",
"None",
":",
"self",
".",
"_parent",
"=",
"None",
"else",
":",
"from",
"rafcon",
".",
"core",
".",
"states",
".",
"state",
"import",
"State",
"assert",
"isinstance",
"(",
"p... | Setter for the parent state of the state element
:param rafcon.core.states.state.State parent: Parent state or None | [
"Setter",
"for",
"the",
"parent",
"state",
"of",
"the",
"state",
"element"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_elements/state_element.py#L96-L128 | train | 40,561 |
DLR-RM/RAFCON | source/rafcon/core/state_elements/state_element.py | StateElement._change_property_with_validity_check | def _change_property_with_validity_check(self, property_name, value):
"""Helper method to change a property and reset it if the validity check fails
:param str property_name: The name of the property to be changed, e.g. '_data_flow_id'
:param value: The new desired value for this property
:raises exceptions.ValueError: if a property could not be changed
"""
assert isinstance(property_name, string_types)
old_value = getattr(self, property_name)
setattr(self, property_name, value)
valid, message = self._check_validity()
if not valid:
setattr(self, property_name, old_value)
class_name = self.__class__.__name__
raise ValueError("The {2}'s '{0}' could not be changed: {1}".format(property_name[1:], message, class_name)) | python | def _change_property_with_validity_check(self, property_name, value):
"""Helper method to change a property and reset it if the validity check fails
:param str property_name: The name of the property to be changed, e.g. '_data_flow_id'
:param value: The new desired value for this property
:raises exceptions.ValueError: if a property could not be changed
"""
assert isinstance(property_name, string_types)
old_value = getattr(self, property_name)
setattr(self, property_name, value)
valid, message = self._check_validity()
if not valid:
setattr(self, property_name, old_value)
class_name = self.__class__.__name__
raise ValueError("The {2}'s '{0}' could not be changed: {1}".format(property_name[1:], message, class_name)) | [
"def",
"_change_property_with_validity_check",
"(",
"self",
",",
"property_name",
",",
"value",
")",
":",
"assert",
"isinstance",
"(",
"property_name",
",",
"string_types",
")",
"old_value",
"=",
"getattr",
"(",
"self",
",",
"property_name",
")",
"setattr",
"(",
... | Helper method to change a property and reset it if the validity check fails
:param str property_name: The name of the property to be changed, e.g. '_data_flow_id'
:param value: The new desired value for this property
:raises exceptions.ValueError: if a property could not be changed | [
"Helper",
"method",
"to",
"change",
"a",
"property",
"and",
"reset",
"it",
"if",
"the",
"validity",
"check",
"fails"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_elements/state_element.py#L169-L184 | train | 40,562 |
DLR-RM/RAFCON | source/rafcon/core/state_elements/state_element.py | StateElement._check_validity | def _check_validity(self):
"""Checks the validity of the state element's properties
Some validity checks can only be performed by the parent. Thus, the existence of a parent and a check
function must be ensured and this function be queried.
:return: validity and messages
:rtype: bool, str
"""
from rafcon.core.states.state import State
if not self.parent:
return True, "no parent"
if not isinstance(self.parent, State):
return True, "no parental check"
return self.parent.check_child_validity(self) | python | def _check_validity(self):
"""Checks the validity of the state element's properties
Some validity checks can only be performed by the parent. Thus, the existence of a parent and a check
function must be ensured and this function be queried.
:return: validity and messages
:rtype: bool, str
"""
from rafcon.core.states.state import State
if not self.parent:
return True, "no parent"
if not isinstance(self.parent, State):
return True, "no parental check"
return self.parent.check_child_validity(self) | [
"def",
"_check_validity",
"(",
"self",
")",
":",
"from",
"rafcon",
".",
"core",
".",
"states",
".",
"state",
"import",
"State",
"if",
"not",
"self",
".",
"parent",
":",
"return",
"True",
",",
"\"no parent\"",
"if",
"not",
"isinstance",
"(",
"self",
".",
... | Checks the validity of the state element's properties
Some validity checks can only be performed by the parent. Thus, the existence of a parent and a check
function must be ensured and this function be queried.
:return: validity and messages
:rtype: bool, str | [
"Checks",
"the",
"validity",
"of",
"the",
"state",
"element",
"s",
"properties"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/state_elements/state_element.py#L186-L201 | train | 40,563 |
DLR-RM/RAFCON | share/examples/plugins/templates/gtkmvc_template_observer.py | RootStateModificationObserver.register_new_state_machines | def register_new_state_machines(self, model, prop_name, info):
""" The method register self as observer newly added StateMachineModels after those were added to the list of
state_machines hold by observed StateMachineMangerModel. The method register as observer of observable
StateMachineMangerModel.state_machines."""
if info['method_name'] == '__setitem__':
self.observe_model(info['args'][1])
self.logger.info(NotificationOverview(info))
elif info['method_name'] == '__delitem__':
pass
else:
self.logger.warning(NotificationOverview(info)) | python | def register_new_state_machines(self, model, prop_name, info):
""" The method register self as observer newly added StateMachineModels after those were added to the list of
state_machines hold by observed StateMachineMangerModel. The method register as observer of observable
StateMachineMangerModel.state_machines."""
if info['method_name'] == '__setitem__':
self.observe_model(info['args'][1])
self.logger.info(NotificationOverview(info))
elif info['method_name'] == '__delitem__':
pass
else:
self.logger.warning(NotificationOverview(info)) | [
"def",
"register_new_state_machines",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"if",
"info",
"[",
"'method_name'",
"]",
"==",
"'__setitem__'",
":",
"self",
".",
"observe_model",
"(",
"info",
"[",
"'args'",
"]",
"[",
"1",
"]",
"... | The method register self as observer newly added StateMachineModels after those were added to the list of
state_machines hold by observed StateMachineMangerModel. The method register as observer of observable
StateMachineMangerModel.state_machines. | [
"The",
"method",
"register",
"self",
"as",
"observer",
"newly",
"added",
"StateMachineModels",
"after",
"those",
"were",
"added",
"to",
"the",
"list",
"of",
"state_machines",
"hold",
"by",
"observed",
"StateMachineMangerModel",
".",
"The",
"method",
"register",
"a... | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/share/examples/plugins/templates/gtkmvc_template_observer.py#L23-L33 | train | 40,564 |
DLR-RM/RAFCON | share/examples/plugins/templates/gtkmvc_template_observer.py | MetaSignalModificationObserver.observe_root_state_assignments | def observe_root_state_assignments(self, model, prop_name, info):
""" The method relieves observed root_state models and observes newly assigned root_state models.
"""
if info['old']:
self.relieve_model(info['old'])
if info['new']:
self.observe_model(info['new'])
self.logger.info("Exchange observed old root_state model with newly assigned one. sm_id: {}"
"".format(info['new'].state.parent.state_machine_id)) | python | def observe_root_state_assignments(self, model, prop_name, info):
""" The method relieves observed root_state models and observes newly assigned root_state models.
"""
if info['old']:
self.relieve_model(info['old'])
if info['new']:
self.observe_model(info['new'])
self.logger.info("Exchange observed old root_state model with newly assigned one. sm_id: {}"
"".format(info['new'].state.parent.state_machine_id)) | [
"def",
"observe_root_state_assignments",
"(",
"self",
",",
"model",
",",
"prop_name",
",",
"info",
")",
":",
"if",
"info",
"[",
"'old'",
"]",
":",
"self",
".",
"relieve_model",
"(",
"info",
"[",
"'old'",
"]",
")",
"if",
"info",
"[",
"'new'",
"]",
":",
... | The method relieves observed root_state models and observes newly assigned root_state models. | [
"The",
"method",
"relieves",
"observed",
"root_state",
"models",
"and",
"observes",
"newly",
"assigned",
"root_state",
"models",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/share/examples/plugins/templates/gtkmvc_template_observer.py#L106-L114 | train | 40,565 |
DLR-RM/RAFCON | share/examples/plugins/templates/gtkmvc_template_observer.py | MetaSignalModificationObserver.observe_meta_signal_changes | def observe_meta_signal_changes(self, changed_model, prop_name, info):
"""" The method prints the structure of all meta_signal-notifications as log-messages.
"""
self.logger.info(NotificationOverview(info)) | python | def observe_meta_signal_changes(self, changed_model, prop_name, info):
"""" The method prints the structure of all meta_signal-notifications as log-messages.
"""
self.logger.info(NotificationOverview(info)) | [
"def",
"observe_meta_signal_changes",
"(",
"self",
",",
"changed_model",
",",
"prop_name",
",",
"info",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"NotificationOverview",
"(",
"info",
")",
")"
] | The method prints the structure of all meta_signal-notifications as log-messages. | [
"The",
"method",
"prints",
"the",
"structure",
"of",
"all",
"meta_signal",
"-",
"notifications",
"as",
"log",
"-",
"messages",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/share/examples/plugins/templates/gtkmvc_template_observer.py#L117-L120 | train | 40,566 |
DLR-RM/RAFCON | source/rafcon/utils/vividict.py | Vividict.set_dict | def set_dict(self, new_dict):
"""Sets the dictionary of the Vividict
The method is able to handle nested dictionaries, by calling the method recursively.
:param new_dict: The dict that will be added to the own dict
"""
for key, value in new_dict.items():
if isinstance(value, dict):
self[str(key)] = Vividict(value)
else:
self[str(key)] = value | python | def set_dict(self, new_dict):
"""Sets the dictionary of the Vividict
The method is able to handle nested dictionaries, by calling the method recursively.
:param new_dict: The dict that will be added to the own dict
"""
for key, value in new_dict.items():
if isinstance(value, dict):
self[str(key)] = Vividict(value)
else:
self[str(key)] = value | [
"def",
"set_dict",
"(",
"self",
",",
"new_dict",
")",
":",
"for",
"key",
",",
"value",
"in",
"new_dict",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"self",
"[",
"str",
"(",
"key",
")",
"]",
"=",
"Vividic... | Sets the dictionary of the Vividict
The method is able to handle nested dictionaries, by calling the method recursively.
:param new_dict: The dict that will be added to the own dict | [
"Sets",
"the",
"dictionary",
"of",
"the",
"Vividict"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/vividict.py#L58-L69 | train | 40,567 |
DLR-RM/RAFCON | source/rafcon/utils/vividict.py | Vividict.vividict_to_dict | def vividict_to_dict(vividict):
"""Helper method to create Python dicts from arbitrary Vividict objects
:param Vividict vividict: A Vividict to be converted
:return: A Python dict
:rtype: dict
"""
try:
from numpy import ndarray
except ImportError:
ndarray = dict
dictionary = {}
def np_to_native(np_val):
"""Recursively convert numpy values to native Python values
- Converts matrices to lists
- Converts numpy.dtypes to float/int etc
:param np_val: value to convert
:return: value as native Python value
"""
if isinstance(np_val, dict):
for key, value in np_val.items():
np_val[key] = np_to_native(value)
# The following condition cannot hold true if no numpy is installed, as ndarray is set to dict, which was
# already handled in the previous condition
elif isinstance(np_val, ndarray):
# noinspection PyUnresolvedReferences
np_val = np_val.tolist()
if isinstance(np_val, (list, tuple)):
native_list = [np_to_native(val) for val in np_val]
if isinstance(np_val, tuple):
return tuple(native_list)
return native_list
if not hasattr(np_val, 'dtype'): # Nothing to convert
return np_val
return np_val.item() # Get the gloat/int etc value
for key, value in vividict.items():
# Convert numpy values to native Python values
value = np_to_native(value)
if isinstance(value, Vividict):
value = Vividict.vividict_to_dict(value)
dictionary[key] = value
return dictionary | python | def vividict_to_dict(vividict):
"""Helper method to create Python dicts from arbitrary Vividict objects
:param Vividict vividict: A Vividict to be converted
:return: A Python dict
:rtype: dict
"""
try:
from numpy import ndarray
except ImportError:
ndarray = dict
dictionary = {}
def np_to_native(np_val):
"""Recursively convert numpy values to native Python values
- Converts matrices to lists
- Converts numpy.dtypes to float/int etc
:param np_val: value to convert
:return: value as native Python value
"""
if isinstance(np_val, dict):
for key, value in np_val.items():
np_val[key] = np_to_native(value)
# The following condition cannot hold true if no numpy is installed, as ndarray is set to dict, which was
# already handled in the previous condition
elif isinstance(np_val, ndarray):
# noinspection PyUnresolvedReferences
np_val = np_val.tolist()
if isinstance(np_val, (list, tuple)):
native_list = [np_to_native(val) for val in np_val]
if isinstance(np_val, tuple):
return tuple(native_list)
return native_list
if not hasattr(np_val, 'dtype'): # Nothing to convert
return np_val
return np_val.item() # Get the gloat/int etc value
for key, value in vividict.items():
# Convert numpy values to native Python values
value = np_to_native(value)
if isinstance(value, Vividict):
value = Vividict.vividict_to_dict(value)
dictionary[key] = value
return dictionary | [
"def",
"vividict_to_dict",
"(",
"vividict",
")",
":",
"try",
":",
"from",
"numpy",
"import",
"ndarray",
"except",
"ImportError",
":",
"ndarray",
"=",
"dict",
"dictionary",
"=",
"{",
"}",
"def",
"np_to_native",
"(",
"np_val",
")",
":",
"\"\"\"Recursively conver... | Helper method to create Python dicts from arbitrary Vividict objects
:param Vividict vividict: A Vividict to be converted
:return: A Python dict
:rtype: dict | [
"Helper",
"method",
"to",
"create",
"Python",
"dicts",
"from",
"arbitrary",
"Vividict",
"objects"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/vividict.py#L90-L136 | train | 40,568 |
DLR-RM/RAFCON | source/rafcon/utils/vividict.py | Vividict.to_yaml | def to_yaml(cls, dumper, vividict):
"""Implementation for the abstract method of the base class YAMLObject
"""
dictionary = cls.vividict_to_dict(vividict)
node = dumper.represent_mapping(cls.yaml_tag, dictionary)
return node | python | def to_yaml(cls, dumper, vividict):
"""Implementation for the abstract method of the base class YAMLObject
"""
dictionary = cls.vividict_to_dict(vividict)
node = dumper.represent_mapping(cls.yaml_tag, dictionary)
return node | [
"def",
"to_yaml",
"(",
"cls",
",",
"dumper",
",",
"vividict",
")",
":",
"dictionary",
"=",
"cls",
".",
"vividict_to_dict",
"(",
"vividict",
")",
"node",
"=",
"dumper",
".",
"represent_mapping",
"(",
"cls",
".",
"yaml_tag",
",",
"dictionary",
")",
"return",... | Implementation for the abstract method of the base class YAMLObject | [
"Implementation",
"for",
"the",
"abstract",
"method",
"of",
"the",
"base",
"class",
"YAMLObject"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/utils/vividict.py#L139-L144 | train | 40,569 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.get_selected_object | def get_selected_object(self):
""" Gets the selected object in the treeview
:return:
"""
model, paths = self.tree_view.get_selection().get_selected_rows()
if len(paths) == 1:
return self.tree_store.get_iter(paths[0]), paths[0]
else:
return None, paths | python | def get_selected_object(self):
""" Gets the selected object in the treeview
:return:
"""
model, paths = self.tree_view.get_selection().get_selected_rows()
if len(paths) == 1:
return self.tree_store.get_iter(paths[0]), paths[0]
else:
return None, paths | [
"def",
"get_selected_object",
"(",
"self",
")",
":",
"model",
",",
"paths",
"=",
"self",
".",
"tree_view",
".",
"get_selection",
"(",
")",
".",
"get_selected_rows",
"(",
")",
"if",
"len",
"(",
"paths",
")",
"==",
"1",
":",
"return",
"self",
".",
"tree_... | Gets the selected object in the treeview
:return: | [
"Gets",
"the",
"selected",
"object",
"in",
"the",
"treeview"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L127-L136 | train | 40,570 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.on_add | def on_add(self, widget, new_dict=False):
"""" Adds a new entry to the semantic data of a state. Reloads the tree store.
:param widget: The source widget of the action
:param bool new_dict: A flag to indicate if the new value is of type dict
:return:
"""
self.semantic_data_counter += 1
treeiter, path = self.get_selected_object()
value = dict() if new_dict else "New Value"
# get target dict path
if treeiter:
target_dict_path_as_list = self.tree_store[path][self.ID_STORAGE_ID]
if not self.tree_store[path][self.IS_DICT_STORAGE_ID]:
target_dict_path_as_list.pop()
else:
target_dict_path_as_list = []
# generate key
target_dict = self.model.state.get_semantic_data(target_dict_path_as_list)
new_key_string = generate_semantic_data_key(list(target_dict.keys()))
self.model.state.add_semantic_data(target_dict_path_as_list, value, new_key_string)
self.reload_tree_store_data()
# jump to new element
self.select_entry(target_dict_path_as_list + [new_key_string])
logger.debug("Added new semantic data entry!")
return True | python | def on_add(self, widget, new_dict=False):
"""" Adds a new entry to the semantic data of a state. Reloads the tree store.
:param widget: The source widget of the action
:param bool new_dict: A flag to indicate if the new value is of type dict
:return:
"""
self.semantic_data_counter += 1
treeiter, path = self.get_selected_object()
value = dict() if new_dict else "New Value"
# get target dict path
if treeiter:
target_dict_path_as_list = self.tree_store[path][self.ID_STORAGE_ID]
if not self.tree_store[path][self.IS_DICT_STORAGE_ID]:
target_dict_path_as_list.pop()
else:
target_dict_path_as_list = []
# generate key
target_dict = self.model.state.get_semantic_data(target_dict_path_as_list)
new_key_string = generate_semantic_data_key(list(target_dict.keys()))
self.model.state.add_semantic_data(target_dict_path_as_list, value, new_key_string)
self.reload_tree_store_data()
# jump to new element
self.select_entry(target_dict_path_as_list + [new_key_string])
logger.debug("Added new semantic data entry!")
return True | [
"def",
"on_add",
"(",
"self",
",",
"widget",
",",
"new_dict",
"=",
"False",
")",
":",
"self",
".",
"semantic_data_counter",
"+=",
"1",
"treeiter",
",",
"path",
"=",
"self",
".",
"get_selected_object",
"(",
")",
"value",
"=",
"dict",
"(",
")",
"if",
"ne... | Adds a new entry to the semantic data of a state. Reloads the tree store.
:param widget: The source widget of the action
:param bool new_dict: A flag to indicate if the new value is of type dict
:return: | [
"Adds",
"a",
"new",
"entry",
"to",
"the",
"semantic",
"data",
"of",
"a",
"state",
".",
"Reloads",
"the",
"tree",
"store",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L138-L168 | train | 40,571 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.on_remove | def on_remove(self, widget, data=None):
""" Removes an entry of semantic data of a state.
:param widget:
:return:
"""
treeiter, path = self.get_selected_object()
if not treeiter:
return
# check if an element is selected
dict_path_as_list = self.tree_store[path][self.ID_STORAGE_ID]
logger.debug("Deleting semantic data entry with name {}!".format(dict_path_as_list[-1]))
self.model.state.remove_semantic_data(dict_path_as_list)
self.reload_tree_store_data()
# hold cursor position where the last element was removed
try:
self.select_entry(self.tree_store[path][self.ID_STORAGE_ID])
except IndexError:
if len(self.tree_store):
if len(path) > 1:
possible_before_path = tuple(list(path[:-1]) + [path[-1] - 1])
if possible_before_path[-1] > -1:
self.select_entry(self.tree_store[possible_before_path][self.ID_STORAGE_ID])
else:
self.select_entry(self.tree_store[path[:-1]][self.ID_STORAGE_ID])
else:
self.select_entry(self.tree_store[path[0] - 1][self.ID_STORAGE_ID])
return True | python | def on_remove(self, widget, data=None):
""" Removes an entry of semantic data of a state.
:param widget:
:return:
"""
treeiter, path = self.get_selected_object()
if not treeiter:
return
# check if an element is selected
dict_path_as_list = self.tree_store[path][self.ID_STORAGE_ID]
logger.debug("Deleting semantic data entry with name {}!".format(dict_path_as_list[-1]))
self.model.state.remove_semantic_data(dict_path_as_list)
self.reload_tree_store_data()
# hold cursor position where the last element was removed
try:
self.select_entry(self.tree_store[path][self.ID_STORAGE_ID])
except IndexError:
if len(self.tree_store):
if len(path) > 1:
possible_before_path = tuple(list(path[:-1]) + [path[-1] - 1])
if possible_before_path[-1] > -1:
self.select_entry(self.tree_store[possible_before_path][self.ID_STORAGE_ID])
else:
self.select_entry(self.tree_store[path[:-1]][self.ID_STORAGE_ID])
else:
self.select_entry(self.tree_store[path[0] - 1][self.ID_STORAGE_ID])
return True | [
"def",
"on_remove",
"(",
"self",
",",
"widget",
",",
"data",
"=",
"None",
")",
":",
"treeiter",
",",
"path",
"=",
"self",
".",
"get_selected_object",
"(",
")",
"if",
"not",
"treeiter",
":",
"return",
"# check if an element is selected",
"dict_path_as_list",
"=... | Removes an entry of semantic data of a state.
:param widget:
:return: | [
"Removes",
"an",
"entry",
"of",
"semantic",
"data",
"of",
"a",
"state",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L180-L209 | train | 40,572 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.add_items_to_tree_iter | def add_items_to_tree_iter(self, input_dict, treeiter, parent_dict_path=None):
""" Adds all values of the input dict to self.tree_store
:param input_dict: The input dictionary holds all values, which are going to be added.
:param treeiter: The pointer inside the tree store to add the input dict
:return:
"""
if parent_dict_path is None:
parent_dict_path = []
self.get_view_selection()
for key, value in sorted(input_dict.items()):
element_dict_path = copy.copy(parent_dict_path) + [key]
if isinstance(value, dict):
new_iter = self.tree_store.append(treeiter, [key, "", True, element_dict_path])
self.add_items_to_tree_iter(value, new_iter, element_dict_path)
else:
self.tree_store.append(treeiter, [key, value, False, element_dict_path]) | python | def add_items_to_tree_iter(self, input_dict, treeiter, parent_dict_path=None):
""" Adds all values of the input dict to self.tree_store
:param input_dict: The input dictionary holds all values, which are going to be added.
:param treeiter: The pointer inside the tree store to add the input dict
:return:
"""
if parent_dict_path is None:
parent_dict_path = []
self.get_view_selection()
for key, value in sorted(input_dict.items()):
element_dict_path = copy.copy(parent_dict_path) + [key]
if isinstance(value, dict):
new_iter = self.tree_store.append(treeiter, [key, "", True, element_dict_path])
self.add_items_to_tree_iter(value, new_iter, element_dict_path)
else:
self.tree_store.append(treeiter, [key, value, False, element_dict_path]) | [
"def",
"add_items_to_tree_iter",
"(",
"self",
",",
"input_dict",
",",
"treeiter",
",",
"parent_dict_path",
"=",
"None",
")",
":",
"if",
"parent_dict_path",
"is",
"None",
":",
"parent_dict_path",
"=",
"[",
"]",
"self",
".",
"get_view_selection",
"(",
")",
"for"... | Adds all values of the input dict to self.tree_store
:param input_dict: The input dictionary holds all values, which are going to be added.
:param treeiter: The pointer inside the tree store to add the input dict
:return: | [
"Adds",
"all",
"values",
"of",
"the",
"input",
"dict",
"to",
"self",
".",
"tree_store"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L211-L227 | train | 40,573 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.reload_tree_store_data | def reload_tree_store_data(self):
""" Reloads the data of the tree store
:return:
"""
model, paths = self.tree_view.get_selection().get_selected_rows()
self.tree_store.clear()
self.add_items_to_tree_iter(self.model.state.semantic_data, None)
self.tree_view.expand_all()
try:
for path in paths:
self.tree_view.get_selection().select_path(path)
except ValueError:
pass | python | def reload_tree_store_data(self):
""" Reloads the data of the tree store
:return:
"""
model, paths = self.tree_view.get_selection().get_selected_rows()
self.tree_store.clear()
self.add_items_to_tree_iter(self.model.state.semantic_data, None)
self.tree_view.expand_all()
try:
for path in paths:
self.tree_view.get_selection().select_path(path)
except ValueError:
pass | [
"def",
"reload_tree_store_data",
"(",
"self",
")",
":",
"model",
",",
"paths",
"=",
"self",
".",
"tree_view",
".",
"get_selection",
"(",
")",
".",
"get_selected_rows",
"(",
")",
"self",
".",
"tree_store",
".",
"clear",
"(",
")",
"self",
".",
"add_items_to_... | Reloads the data of the tree store
:return: | [
"Reloads",
"the",
"data",
"of",
"the",
"tree",
"store"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L229-L244 | train | 40,574 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.copy_action_callback | def copy_action_callback(self, *event):
"""Add a copy of all selected row dict value pairs to the clipboard"""
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
_, dict_paths = self.get_view_selection()
selected_data_list = []
for dict_path_as_list in dict_paths:
value = self.model.state.semantic_data
for path_element in dict_path_as_list:
value = value[path_element]
selected_data_list.append((path_element, value))
rafcon.gui.clipboard.global_clipboard.set_semantic_dictionary_list(selected_data_list) | python | def copy_action_callback(self, *event):
"""Add a copy of all selected row dict value pairs to the clipboard"""
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
_, dict_paths = self.get_view_selection()
selected_data_list = []
for dict_path_as_list in dict_paths:
value = self.model.state.semantic_data
for path_element in dict_path_as_list:
value = value[path_element]
selected_data_list.append((path_element, value))
rafcon.gui.clipboard.global_clipboard.set_semantic_dictionary_list(selected_data_list) | [
"def",
"copy_action_callback",
"(",
"self",
",",
"*",
"event",
")",
":",
"if",
"react_to_event",
"(",
"self",
".",
"view",
",",
"self",
".",
"tree_view",
",",
"event",
")",
"and",
"self",
".",
"active_entry_widget",
"is",
"None",
":",
"_",
",",
"dict_pat... | Add a copy of all selected row dict value pairs to the clipboard | [
"Add",
"a",
"copy",
"of",
"all",
"selected",
"row",
"dict",
"value",
"pairs",
"to",
"the",
"clipboard"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L256-L266 | train | 40,575 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.paste_action_callback | def paste_action_callback(self, *event):
"""Add clipboard key value pairs into all selected sub-dictionary"""
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
_, dict_paths = self.get_view_selection()
selected_data_list = rafcon.gui.clipboard.global_clipboard.get_semantic_dictionary_list()
# enforce paste on root level if semantic data empty or nothing is selected
if not dict_paths and not self.model.state.semantic_data:
dict_paths = [[]]
for target_dict_path_as_list in dict_paths:
prev_value = self.model.state.semantic_data
value = self.model.state.semantic_data
for path_element in target_dict_path_as_list:
prev_value = value
value = value[path_element]
if not isinstance(value, dict) and len(dict_paths) <= 1: # if one selection take parent
target_dict_path_as_list.pop(-1)
value = prev_value
if isinstance(value, dict):
for key_to_paste, value_to_add in selected_data_list:
self.model.state.add_semantic_data(target_dict_path_as_list, value_to_add, key_to_paste)
self.reload_tree_store_data() | python | def paste_action_callback(self, *event):
"""Add clipboard key value pairs into all selected sub-dictionary"""
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
_, dict_paths = self.get_view_selection()
selected_data_list = rafcon.gui.clipboard.global_clipboard.get_semantic_dictionary_list()
# enforce paste on root level if semantic data empty or nothing is selected
if not dict_paths and not self.model.state.semantic_data:
dict_paths = [[]]
for target_dict_path_as_list in dict_paths:
prev_value = self.model.state.semantic_data
value = self.model.state.semantic_data
for path_element in target_dict_path_as_list:
prev_value = value
value = value[path_element]
if not isinstance(value, dict) and len(dict_paths) <= 1: # if one selection take parent
target_dict_path_as_list.pop(-1)
value = prev_value
if isinstance(value, dict):
for key_to_paste, value_to_add in selected_data_list:
self.model.state.add_semantic_data(target_dict_path_as_list, value_to_add, key_to_paste)
self.reload_tree_store_data() | [
"def",
"paste_action_callback",
"(",
"self",
",",
"*",
"event",
")",
":",
"if",
"react_to_event",
"(",
"self",
".",
"view",
",",
"self",
".",
"tree_view",
",",
"event",
")",
"and",
"self",
".",
"active_entry_widget",
"is",
"None",
":",
"_",
",",
"dict_pa... | Add clipboard key value pairs into all selected sub-dictionary | [
"Add",
"clipboard",
"key",
"value",
"pairs",
"into",
"all",
"selected",
"sub",
"-",
"dictionary"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L268-L290 | train | 40,576 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.cut_action_callback | def cut_action_callback(self, *event):
"""Add a copy and cut all selected row dict value pairs to the clipboard"""
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
_, dict_paths = self.get_view_selection()
stored_data_list = []
for dict_path_as_list in dict_paths:
if dict_path_as_list:
value = self.model.state.semantic_data
for path_element in dict_path_as_list:
value = value[path_element]
stored_data_list.append((path_element, value))
self.model.state.remove_semantic_data(dict_path_as_list)
rafcon.gui.clipboard.global_clipboard.set_semantic_dictionary_list(stored_data_list)
self.reload_tree_store_data() | python | def cut_action_callback(self, *event):
"""Add a copy and cut all selected row dict value pairs to the clipboard"""
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
_, dict_paths = self.get_view_selection()
stored_data_list = []
for dict_path_as_list in dict_paths:
if dict_path_as_list:
value = self.model.state.semantic_data
for path_element in dict_path_as_list:
value = value[path_element]
stored_data_list.append((path_element, value))
self.model.state.remove_semantic_data(dict_path_as_list)
rafcon.gui.clipboard.global_clipboard.set_semantic_dictionary_list(stored_data_list)
self.reload_tree_store_data() | [
"def",
"cut_action_callback",
"(",
"self",
",",
"*",
"event",
")",
":",
"if",
"react_to_event",
"(",
"self",
".",
"view",
",",
"self",
".",
"tree_view",
",",
"event",
")",
"and",
"self",
".",
"active_entry_widget",
"is",
"None",
":",
"_",
",",
"dict_path... | Add a copy and cut all selected row dict value pairs to the clipboard | [
"Add",
"a",
"copy",
"and",
"cut",
"all",
"selected",
"row",
"dict",
"value",
"pairs",
"to",
"the",
"clipboard"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L292-L306 | train | 40,577 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.key_edited | def key_edited(self, path, new_key_str):
""" Edits the key of a semantic data entry
:param path: The path inside the tree store to the target entry
:param str new_key_str: The new value of the target cell
:return:
"""
tree_store_path = self.create_tree_store_path_from_key_string(path) if isinstance(path, string_types) else path
if self.tree_store[tree_store_path][self.KEY_STORAGE_ID] == new_key_str:
return
dict_path = self.tree_store[tree_store_path][self.ID_STORAGE_ID]
old_value = self.model.state.get_semantic_data(dict_path)
self.model.state.remove_semantic_data(dict_path)
if new_key_str == "":
target_dict = self.model.state.semantic_data
for element in dict_path[0:-1]:
target_dict = target_dict[element]
new_key_str = generate_semantic_data_key(list(target_dict.keys()))
new_dict_path = self.model.state.add_semantic_data(dict_path[0:-1], old_value, key=new_key_str)
self._changed_id_to = {':'.join(dict_path): new_dict_path} # use hashable key (workaround for tree view ctrl)
self.reload_tree_store_data() | python | def key_edited(self, path, new_key_str):
""" Edits the key of a semantic data entry
:param path: The path inside the tree store to the target entry
:param str new_key_str: The new value of the target cell
:return:
"""
tree_store_path = self.create_tree_store_path_from_key_string(path) if isinstance(path, string_types) else path
if self.tree_store[tree_store_path][self.KEY_STORAGE_ID] == new_key_str:
return
dict_path = self.tree_store[tree_store_path][self.ID_STORAGE_ID]
old_value = self.model.state.get_semantic_data(dict_path)
self.model.state.remove_semantic_data(dict_path)
if new_key_str == "":
target_dict = self.model.state.semantic_data
for element in dict_path[0:-1]:
target_dict = target_dict[element]
new_key_str = generate_semantic_data_key(list(target_dict.keys()))
new_dict_path = self.model.state.add_semantic_data(dict_path[0:-1], old_value, key=new_key_str)
self._changed_id_to = {':'.join(dict_path): new_dict_path} # use hashable key (workaround for tree view ctrl)
self.reload_tree_store_data() | [
"def",
"key_edited",
"(",
"self",
",",
"path",
",",
"new_key_str",
")",
":",
"tree_store_path",
"=",
"self",
".",
"create_tree_store_path_from_key_string",
"(",
"path",
")",
"if",
"isinstance",
"(",
"path",
",",
"string_types",
")",
"else",
"path",
"if",
"self... | Edits the key of a semantic data entry
:param path: The path inside the tree store to the target entry
:param str new_key_str: The new value of the target cell
:return: | [
"Edits",
"the",
"key",
"of",
"a",
"semantic",
"data",
"entry"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L308-L331 | train | 40,578 |
DLR-RM/RAFCON | source/rafcon/gui/controllers/state_editor/semantic_data_editor.py | SemanticDataEditorController.value_edited | def value_edited(self, path, new_value_str):
""" Adds the value of the semantic data entry
:param path: The path inside the tree store to the target entry
:param str new_value_str: The new value of the target cell
:return:
"""
tree_store_path = self.create_tree_store_path_from_key_string(path) if isinstance(path, string_types) else path
if self.tree_store[tree_store_path][self.VALUE_STORAGE_ID] == new_value_str:
return
dict_path = self.tree_store[tree_store_path][self.ID_STORAGE_ID]
self.model.state.add_semantic_data(dict_path[0:-1], new_value_str, key=dict_path[-1])
self.reload_tree_store_data() | python | def value_edited(self, path, new_value_str):
""" Adds the value of the semantic data entry
:param path: The path inside the tree store to the target entry
:param str new_value_str: The new value of the target cell
:return:
"""
tree_store_path = self.create_tree_store_path_from_key_string(path) if isinstance(path, string_types) else path
if self.tree_store[tree_store_path][self.VALUE_STORAGE_ID] == new_value_str:
return
dict_path = self.tree_store[tree_store_path][self.ID_STORAGE_ID]
self.model.state.add_semantic_data(dict_path[0:-1], new_value_str, key=dict_path[-1])
self.reload_tree_store_data() | [
"def",
"value_edited",
"(",
"self",
",",
"path",
",",
"new_value_str",
")",
":",
"tree_store_path",
"=",
"self",
".",
"create_tree_store_path_from_key_string",
"(",
"path",
")",
"if",
"isinstance",
"(",
"path",
",",
"string_types",
")",
"else",
"path",
"if",
"... | Adds the value of the semantic data entry
:param path: The path inside the tree store to the target entry
:param str new_value_str: The new value of the target cell
:return: | [
"Adds",
"the",
"value",
"of",
"the",
"semantic",
"data",
"entry"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/controllers/state_editor/semantic_data_editor.py#L333-L346 | train | 40,579 |
DLR-RM/RAFCON | source/rafcon/gui/runtime_config.py | RuntimeConfig.store_widget_properties | def store_widget_properties(self, widget, widget_name):
"""Sets configuration values for widgets
If the widget is a window, then the size and position are stored. If the widget is a pane, then only the
position is stored. If the window is maximized the last insert position before being maximized is keep in the
config and the maximized flag set to True. The maximized state and the last size and position are strictly
separated by this.
:param widget: The widget, for which the position (and possibly the size) will be stored.
:param widget_name: The window or widget name of the widget, which constitutes a part of its key in the
configuration file.
"""
if isinstance(widget, Gtk.Window):
maximized = bool(widget.is_maximized())
self.set_config_value('{0}_MAXIMIZED'.format(widget_name), maximized)
if maximized:
return
size = widget.get_size()
self.set_config_value('{0}_SIZE'.format(widget_name), tuple(size))
position = widget.get_position()
self.set_config_value('{0}_POS'.format(widget_name), tuple(position))
else: # Gtk.Paned
position = widget.get_position()
self.set_config_value('{0}_POS'.format(widget_name), position) | python | def store_widget_properties(self, widget, widget_name):
"""Sets configuration values for widgets
If the widget is a window, then the size and position are stored. If the widget is a pane, then only the
position is stored. If the window is maximized the last insert position before being maximized is keep in the
config and the maximized flag set to True. The maximized state and the last size and position are strictly
separated by this.
:param widget: The widget, for which the position (and possibly the size) will be stored.
:param widget_name: The window or widget name of the widget, which constitutes a part of its key in the
configuration file.
"""
if isinstance(widget, Gtk.Window):
maximized = bool(widget.is_maximized())
self.set_config_value('{0}_MAXIMIZED'.format(widget_name), maximized)
if maximized:
return
size = widget.get_size()
self.set_config_value('{0}_SIZE'.format(widget_name), tuple(size))
position = widget.get_position()
self.set_config_value('{0}_POS'.format(widget_name), tuple(position))
else: # Gtk.Paned
position = widget.get_position()
self.set_config_value('{0}_POS'.format(widget_name), position) | [
"def",
"store_widget_properties",
"(",
"self",
",",
"widget",
",",
"widget_name",
")",
":",
"if",
"isinstance",
"(",
"widget",
",",
"Gtk",
".",
"Window",
")",
":",
"maximized",
"=",
"bool",
"(",
"widget",
".",
"is_maximized",
"(",
")",
")",
"self",
".",
... | Sets configuration values for widgets
If the widget is a window, then the size and position are stored. If the widget is a pane, then only the
position is stored. If the window is maximized the last insert position before being maximized is keep in the
config and the maximized flag set to True. The maximized state and the last size and position are strictly
separated by this.
:param widget: The widget, for which the position (and possibly the size) will be stored.
:param widget_name: The window or widget name of the widget, which constitutes a part of its key in the
configuration file. | [
"Sets",
"configuration",
"values",
"for",
"widgets"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/runtime_config.py#L41-L64 | train | 40,580 |
DLR-RM/RAFCON | source/rafcon/gui/runtime_config.py | RuntimeConfig.update_recently_opened_state_machines_with | def update_recently_opened_state_machines_with(self, state_machine):
""" Update recently opened list with file system path of handed state machine model
The inserts handed state machine file system path into the recent opened state machines or moves it to be the
first element in the list.
:param rafcon.core.state_machine.StateMachine state_machine: State machine to check
:return:
"""
if state_machine.file_system_path:
# check if path is in recent path already
# logger.info("update recent state machine: {}".format(sm.file_system_path))
recently_opened_state_machines = self.get_config_value('recently_opened_state_machines', [])
if state_machine.file_system_path in recently_opened_state_machines:
del recently_opened_state_machines[recently_opened_state_machines.index(state_machine.file_system_path)]
recently_opened_state_machines.insert(0, state_machine.file_system_path)
self.set_config_value('recently_opened_state_machines', recently_opened_state_machines) | python | def update_recently_opened_state_machines_with(self, state_machine):
""" Update recently opened list with file system path of handed state machine model
The inserts handed state machine file system path into the recent opened state machines or moves it to be the
first element in the list.
:param rafcon.core.state_machine.StateMachine state_machine: State machine to check
:return:
"""
if state_machine.file_system_path:
# check if path is in recent path already
# logger.info("update recent state machine: {}".format(sm.file_system_path))
recently_opened_state_machines = self.get_config_value('recently_opened_state_machines', [])
if state_machine.file_system_path in recently_opened_state_machines:
del recently_opened_state_machines[recently_opened_state_machines.index(state_machine.file_system_path)]
recently_opened_state_machines.insert(0, state_machine.file_system_path)
self.set_config_value('recently_opened_state_machines', recently_opened_state_machines) | [
"def",
"update_recently_opened_state_machines_with",
"(",
"self",
",",
"state_machine",
")",
":",
"if",
"state_machine",
".",
"file_system_path",
":",
"# check if path is in recent path already",
"# logger.info(\"update recent state machine: {}\".format(sm.file_system_path))",
"recentl... | Update recently opened list with file system path of handed state machine model
The inserts handed state machine file system path into the recent opened state machines or moves it to be the
first element in the list.
:param rafcon.core.state_machine.StateMachine state_machine: State machine to check
:return: | [
"Update",
"recently",
"opened",
"list",
"with",
"file",
"system",
"path",
"of",
"handed",
"state",
"machine",
"model"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/runtime_config.py#L73-L89 | train | 40,581 |
DLR-RM/RAFCON | source/rafcon/gui/runtime_config.py | RuntimeConfig.extend_recently_opened_by_current_open_state_machines | def extend_recently_opened_by_current_open_state_machines(self):
""" Update list with all in the state machine manager opened state machines """
from rafcon.gui.singleton import state_machine_manager_model as state_machine_manager_m
for sm_m in state_machine_manager_m.state_machines.values():
self.update_recently_opened_state_machines_with(sm_m.state_machine) | python | def extend_recently_opened_by_current_open_state_machines(self):
""" Update list with all in the state machine manager opened state machines """
from rafcon.gui.singleton import state_machine_manager_model as state_machine_manager_m
for sm_m in state_machine_manager_m.state_machines.values():
self.update_recently_opened_state_machines_with(sm_m.state_machine) | [
"def",
"extend_recently_opened_by_current_open_state_machines",
"(",
"self",
")",
":",
"from",
"rafcon",
".",
"gui",
".",
"singleton",
"import",
"state_machine_manager_model",
"as",
"state_machine_manager_m",
"for",
"sm_m",
"in",
"state_machine_manager_m",
".",
"state_machi... | Update list with all in the state machine manager opened state machines | [
"Update",
"list",
"with",
"all",
"in",
"the",
"state",
"machine",
"manager",
"opened",
"state",
"machines"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/runtime_config.py#L91-L95 | train | 40,582 |
DLR-RM/RAFCON | source/rafcon/gui/runtime_config.py | RuntimeConfig.prepare_recently_opened_state_machines_list_for_storage | def prepare_recently_opened_state_machines_list_for_storage(self):
""" Reduce number of paths in the recent opened state machines to limit from gui config """
from rafcon.gui.singleton import global_gui_config
num = global_gui_config.get_config_value('NUMBER_OF_RECENT_OPENED_STATE_MACHINES_STORED')
state_machine_paths = self.get_config_value('recently_opened_state_machines', [])
self.set_config_value('recently_opened_state_machines', state_machine_paths[:num]) | python | def prepare_recently_opened_state_machines_list_for_storage(self):
""" Reduce number of paths in the recent opened state machines to limit from gui config """
from rafcon.gui.singleton import global_gui_config
num = global_gui_config.get_config_value('NUMBER_OF_RECENT_OPENED_STATE_MACHINES_STORED')
state_machine_paths = self.get_config_value('recently_opened_state_machines', [])
self.set_config_value('recently_opened_state_machines', state_machine_paths[:num]) | [
"def",
"prepare_recently_opened_state_machines_list_for_storage",
"(",
"self",
")",
":",
"from",
"rafcon",
".",
"gui",
".",
"singleton",
"import",
"global_gui_config",
"num",
"=",
"global_gui_config",
".",
"get_config_value",
"(",
"'NUMBER_OF_RECENT_OPENED_STATE_MACHINES_STOR... | Reduce number of paths in the recent opened state machines to limit from gui config | [
"Reduce",
"number",
"of",
"paths",
"in",
"the",
"recent",
"opened",
"state",
"machines",
"to",
"limit",
"from",
"gui",
"config"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/runtime_config.py#L97-L102 | train | 40,583 |
DLR-RM/RAFCON | source/rafcon/gui/runtime_config.py | RuntimeConfig.clean_recently_opened_state_machines | def clean_recently_opened_state_machines(self):
"""Remove state machines who's file system path does not exist"""
state_machine_paths = self.get_config_value('recently_opened_state_machines', [])
filesystem.clean_file_system_paths_from_not_existing_paths(state_machine_paths)
self.set_config_value('recently_opened_state_machines', state_machine_paths) | python | def clean_recently_opened_state_machines(self):
"""Remove state machines who's file system path does not exist"""
state_machine_paths = self.get_config_value('recently_opened_state_machines', [])
filesystem.clean_file_system_paths_from_not_existing_paths(state_machine_paths)
self.set_config_value('recently_opened_state_machines', state_machine_paths) | [
"def",
"clean_recently_opened_state_machines",
"(",
"self",
")",
":",
"state_machine_paths",
"=",
"self",
".",
"get_config_value",
"(",
"'recently_opened_state_machines'",
",",
"[",
"]",
")",
"filesystem",
".",
"clean_file_system_paths_from_not_existing_paths",
"(",
"state_... | Remove state machines who's file system path does not exist | [
"Remove",
"state",
"machines",
"who",
"s",
"file",
"system",
"path",
"does",
"not",
"exist"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/gui/runtime_config.py#L104-L108 | train | 40,584 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.pause | def pause(self):
"""Set the execution mode to paused
"""
if self.state_machine_manager.active_state_machine_id is None:
logger.info("'Pause' is not a valid action to initiate state machine execution.")
return
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_pause_states()
logger.debug("Pause execution ...")
self.set_execution_mode(StateMachineExecutionStatus.PAUSED) | python | def pause(self):
"""Set the execution mode to paused
"""
if self.state_machine_manager.active_state_machine_id is None:
logger.info("'Pause' is not a valid action to initiate state machine execution.")
return
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_pause_states()
logger.debug("Pause execution ...")
self.set_execution_mode(StateMachineExecutionStatus.PAUSED) | [
"def",
"pause",
"(",
"self",
")",
":",
"if",
"self",
".",
"state_machine_manager",
".",
"active_state_machine_id",
"is",
"None",
":",
"logger",
".",
"info",
"(",
"\"'Pause' is not a valid action to initiate state machine execution.\"",
")",
"return",
"if",
"self",
"."... | Set the execution mode to paused | [
"Set",
"the",
"execution",
"mode",
"to",
"paused"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L70-L80 | train | 40,585 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.finished_or_stopped | def finished_or_stopped(self):
""" Condition check on finished or stopped status
The method returns a value which is equivalent with not 'active' status of the current state machine.
:return: outcome of condition check stopped or finished
:rtype: bool
"""
return (self._status.execution_mode is StateMachineExecutionStatus.STOPPED) or \
(self._status.execution_mode is StateMachineExecutionStatus.FINISHED) | python | def finished_or_stopped(self):
""" Condition check on finished or stopped status
The method returns a value which is equivalent with not 'active' status of the current state machine.
:return: outcome of condition check stopped or finished
:rtype: bool
"""
return (self._status.execution_mode is StateMachineExecutionStatus.STOPPED) or \
(self._status.execution_mode is StateMachineExecutionStatus.FINISHED) | [
"def",
"finished_or_stopped",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"_status",
".",
"execution_mode",
"is",
"StateMachineExecutionStatus",
".",
"STOPPED",
")",
"or",
"(",
"self",
".",
"_status",
".",
"execution_mode",
"is",
"StateMachineExecutionStatu... | Condition check on finished or stopped status
The method returns a value which is equivalent with not 'active' status of the current state machine.
:return: outcome of condition check stopped or finished
:rtype: bool | [
"Condition",
"check",
"on",
"finished",
"or",
"stopped",
"status"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L82-L91 | train | 40,586 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.start | def start(self, state_machine_id=None, start_state_path=None):
""" Start state machine
If no state machine is running start a specific state machine.
If no state machine is provided the currently active state machine is started.
If there is already a state machine running, just resume it without taking the passed state_machine_id argument
into account.
:param state_machine_id: The id if the state machine to be started
:param start_state_path: The path of the state in the state machine, from which the execution will start
:return:
"""
if not self.finished_or_stopped():
logger.debug("Resume execution engine ...")
self.run_to_states = []
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_resume_states()
if isinstance(state_machine_id, int) and \
state_machine_id != self.state_machine_manager.get_active_state_machine().state_machine_id:
logger.info("Resumed state machine with id {0} but start of state machine id {1} was requested."
"".format(self.state_machine_manager.get_active_state_machine().state_machine_id,
state_machine_id))
self.set_execution_mode(StateMachineExecutionStatus.STARTED)
else:
# do not start another state machine before the old one did not finish its execution
if self.state_machine_running:
logger.warning("An old state machine is still running! Make sure that it terminates,"
" before you can start another state machine! {0}".format(self))
return
logger.debug("Start execution engine ...")
if state_machine_id is not None:
self.state_machine_manager.active_state_machine_id = state_machine_id
if not self.state_machine_manager.active_state_machine_id:
logger.error("There exists no active state machine!")
return
self.set_execution_mode(StateMachineExecutionStatus.STARTED)
self.start_state_paths = []
if start_state_path:
path_list = start_state_path.split("/")
cur_path = ""
for path in path_list:
if cur_path == "":
cur_path = path
else:
cur_path = cur_path + "/" + path
self.start_state_paths.append(cur_path)
self._run_active_state_machine() | python | def start(self, state_machine_id=None, start_state_path=None):
""" Start state machine
If no state machine is running start a specific state machine.
If no state machine is provided the currently active state machine is started.
If there is already a state machine running, just resume it without taking the passed state_machine_id argument
into account.
:param state_machine_id: The id if the state machine to be started
:param start_state_path: The path of the state in the state machine, from which the execution will start
:return:
"""
if not self.finished_or_stopped():
logger.debug("Resume execution engine ...")
self.run_to_states = []
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_resume_states()
if isinstance(state_machine_id, int) and \
state_machine_id != self.state_machine_manager.get_active_state_machine().state_machine_id:
logger.info("Resumed state machine with id {0} but start of state machine id {1} was requested."
"".format(self.state_machine_manager.get_active_state_machine().state_machine_id,
state_machine_id))
self.set_execution_mode(StateMachineExecutionStatus.STARTED)
else:
# do not start another state machine before the old one did not finish its execution
if self.state_machine_running:
logger.warning("An old state machine is still running! Make sure that it terminates,"
" before you can start another state machine! {0}".format(self))
return
logger.debug("Start execution engine ...")
if state_machine_id is not None:
self.state_machine_manager.active_state_machine_id = state_machine_id
if not self.state_machine_manager.active_state_machine_id:
logger.error("There exists no active state machine!")
return
self.set_execution_mode(StateMachineExecutionStatus.STARTED)
self.start_state_paths = []
if start_state_path:
path_list = start_state_path.split("/")
cur_path = ""
for path in path_list:
if cur_path == "":
cur_path = path
else:
cur_path = cur_path + "/" + path
self.start_state_paths.append(cur_path)
self._run_active_state_machine() | [
"def",
"start",
"(",
"self",
",",
"state_machine_id",
"=",
"None",
",",
"start_state_path",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"finished_or_stopped",
"(",
")",
":",
"logger",
".",
"debug",
"(",
"\"Resume execution engine ...\"",
")",
"self",
".... | Start state machine
If no state machine is running start a specific state machine.
If no state machine is provided the currently active state machine is started.
If there is already a state machine running, just resume it without taking the passed state_machine_id argument
into account.
:param state_machine_id: The id if the state machine to be started
:param start_state_path: The path of the state in the state machine, from which the execution will start
:return: | [
"Start",
"state",
"machine"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L94-L147 | train | 40,587 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.stop | def stop(self):
"""Set the execution mode to stopped
"""
logger.debug("Stop the state machine execution ...")
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_preempt_states()
self.__set_execution_mode_to_stopped()
# Notifies states waiting in step mode or those that are paused about execution stop
self._status.execution_condition_variable.acquire()
self._status.execution_condition_variable.notify_all()
self._status.execution_condition_variable.release()
self.__running_state_machine = None | python | def stop(self):
"""Set the execution mode to stopped
"""
logger.debug("Stop the state machine execution ...")
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_preempt_states()
self.__set_execution_mode_to_stopped()
# Notifies states waiting in step mode or those that are paused about execution stop
self._status.execution_condition_variable.acquire()
self._status.execution_condition_variable.notify_all()
self._status.execution_condition_variable.release()
self.__running_state_machine = None | [
"def",
"stop",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"\"Stop the state machine execution ...\"",
")",
"if",
"self",
".",
"state_machine_manager",
".",
"get_active_state_machine",
"(",
")",
"is",
"not",
"None",
":",
"self",
".",
"state_machine_manager... | Set the execution mode to stopped | [
"Set",
"the",
"execution",
"mode",
"to",
"stopped"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L150-L162 | train | 40,588 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.join | def join(self, timeout=None):
"""Blocking wait for the execution to finish
:param float timeout: Maximum time to wait or None for infinitely
:return: True if the execution finished, False if no state machine was started or a timeout occurred
:rtype: bool
"""
if self.__wait_for_finishing_thread:
if not timeout:
# signal handlers won't work if timeout is None and the thread is joined
while True:
self.__wait_for_finishing_thread.join(0.5)
if not self.__wait_for_finishing_thread.isAlive():
break
else:
self.__wait_for_finishing_thread.join(timeout)
return not self.__wait_for_finishing_thread.is_alive()
else:
logger.warning("Cannot join as state machine was not started yet.")
return False | python | def join(self, timeout=None):
"""Blocking wait for the execution to finish
:param float timeout: Maximum time to wait or None for infinitely
:return: True if the execution finished, False if no state machine was started or a timeout occurred
:rtype: bool
"""
if self.__wait_for_finishing_thread:
if not timeout:
# signal handlers won't work if timeout is None and the thread is joined
while True:
self.__wait_for_finishing_thread.join(0.5)
if not self.__wait_for_finishing_thread.isAlive():
break
else:
self.__wait_for_finishing_thread.join(timeout)
return not self.__wait_for_finishing_thread.is_alive()
else:
logger.warning("Cannot join as state machine was not started yet.")
return False | [
"def",
"join",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"self",
".",
"__wait_for_finishing_thread",
":",
"if",
"not",
"timeout",
":",
"# signal handlers won't work if timeout is None and the thread is joined",
"while",
"True",
":",
"self",
".",
"__w... | Blocking wait for the execution to finish
:param float timeout: Maximum time to wait or None for infinitely
:return: True if the execution finished, False if no state machine was started or a timeout occurred
:rtype: bool | [
"Blocking",
"wait",
"for",
"the",
"execution",
"to",
"finish"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L164-L183 | train | 40,589 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine._run_active_state_machine | def _run_active_state_machine(self):
"""Store running state machine and observe its status
"""
# Create new concurrency queue for root state to be able to synchronize with the execution
self.__running_state_machine = self.state_machine_manager.get_active_state_machine()
if not self.__running_state_machine:
logger.error("The running state machine must not be None")
self.__running_state_machine.root_state.concurrency_queue = queue.Queue(maxsize=0)
if self.__running_state_machine:
self.__running_state_machine.start()
self.__wait_for_finishing_thread = threading.Thread(target=self._wait_for_finishing)
self.__wait_for_finishing_thread.start()
else:
logger.warning("Currently no active state machine! Please create a new state machine.")
self.set_execution_mode(StateMachineExecutionStatus.STOPPED) | python | def _run_active_state_machine(self):
"""Store running state machine and observe its status
"""
# Create new concurrency queue for root state to be able to synchronize with the execution
self.__running_state_machine = self.state_machine_manager.get_active_state_machine()
if not self.__running_state_machine:
logger.error("The running state machine must not be None")
self.__running_state_machine.root_state.concurrency_queue = queue.Queue(maxsize=0)
if self.__running_state_machine:
self.__running_state_machine.start()
self.__wait_for_finishing_thread = threading.Thread(target=self._wait_for_finishing)
self.__wait_for_finishing_thread.start()
else:
logger.warning("Currently no active state machine! Please create a new state machine.")
self.set_execution_mode(StateMachineExecutionStatus.STOPPED) | [
"def",
"_run_active_state_machine",
"(",
"self",
")",
":",
"# Create new concurrency queue for root state to be able to synchronize with the execution",
"self",
".",
"__running_state_machine",
"=",
"self",
".",
"state_machine_manager",
".",
"get_active_state_machine",
"(",
")",
"... | Store running state machine and observe its status | [
"Store",
"running",
"state",
"machine",
"and",
"observe",
"its",
"status"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L195-L212 | train | 40,590 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine._wait_for_finishing | def _wait_for_finishing(self):
"""Observe running state machine and stop engine if execution has finished"""
self.state_machine_running = True
self.__running_state_machine.join()
self.__set_execution_mode_to_finished()
self.state_machine_manager.active_state_machine_id = None
plugins.run_on_state_machine_execution_finished()
# self.__set_execution_mode_to_stopped()
self.state_machine_running = False | python | def _wait_for_finishing(self):
"""Observe running state machine and stop engine if execution has finished"""
self.state_machine_running = True
self.__running_state_machine.join()
self.__set_execution_mode_to_finished()
self.state_machine_manager.active_state_machine_id = None
plugins.run_on_state_machine_execution_finished()
# self.__set_execution_mode_to_stopped()
self.state_machine_running = False | [
"def",
"_wait_for_finishing",
"(",
"self",
")",
":",
"self",
".",
"state_machine_running",
"=",
"True",
"self",
".",
"__running_state_machine",
".",
"join",
"(",
")",
"self",
".",
"__set_execution_mode_to_finished",
"(",
")",
"self",
".",
"state_machine_manager",
... | Observe running state machine and stop engine if execution has finished | [
"Observe",
"running",
"state",
"machine",
"and",
"stop",
"engine",
"if",
"execution",
"has",
"finished"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L214-L222 | train | 40,591 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.backward_step | def backward_step(self):
"""Take a backward step for all active states in the state machine
"""
logger.debug("Executing backward step ...")
self.run_to_states = []
self.set_execution_mode(StateMachineExecutionStatus.BACKWARD) | python | def backward_step(self):
"""Take a backward step for all active states in the state machine
"""
logger.debug("Executing backward step ...")
self.run_to_states = []
self.set_execution_mode(StateMachineExecutionStatus.BACKWARD) | [
"def",
"backward_step",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"\"Executing backward step ...\"",
")",
"self",
".",
"run_to_states",
"=",
"[",
"]",
"self",
".",
"set_execution_mode",
"(",
"StateMachineExecutionStatus",
".",
"BACKWARD",
")"
] | Take a backward step for all active states in the state machine | [
"Take",
"a",
"backward",
"step",
"for",
"all",
"active",
"states",
"in",
"the",
"state",
"machine"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L224-L229 | train | 40,592 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.step_mode | def step_mode(self, state_machine_id=None):
"""Set the execution mode to stepping mode. Transitions are only triggered if a new step is triggered
"""
logger.debug("Activate step mode")
if state_machine_id is not None:
self.state_machine_manager.active_state_machine_id = state_machine_id
self.run_to_states = []
if self.finished_or_stopped():
self.set_execution_mode(StateMachineExecutionStatus.STEP_MODE)
self._run_active_state_machine()
else:
self.set_execution_mode(StateMachineExecutionStatus.STEP_MODE) | python | def step_mode(self, state_machine_id=None):
"""Set the execution mode to stepping mode. Transitions are only triggered if a new step is triggered
"""
logger.debug("Activate step mode")
if state_machine_id is not None:
self.state_machine_manager.active_state_machine_id = state_machine_id
self.run_to_states = []
if self.finished_or_stopped():
self.set_execution_mode(StateMachineExecutionStatus.STEP_MODE)
self._run_active_state_machine()
else:
self.set_execution_mode(StateMachineExecutionStatus.STEP_MODE) | [
"def",
"step_mode",
"(",
"self",
",",
"state_machine_id",
"=",
"None",
")",
":",
"logger",
".",
"debug",
"(",
"\"Activate step mode\"",
")",
"if",
"state_machine_id",
"is",
"not",
"None",
":",
"self",
".",
"state_machine_manager",
".",
"active_state_machine_id",
... | Set the execution mode to stepping mode. Transitions are only triggered if a new step is triggered | [
"Set",
"the",
"execution",
"mode",
"to",
"stepping",
"mode",
".",
"Transitions",
"are",
"only",
"triggered",
"if",
"a",
"new",
"step",
"is",
"triggered"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L232-L245 | train | 40,593 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.run_to_selected_state | def run_to_selected_state(self, path, state_machine_id=None):
"""Execute the state machine until a specific state. This state won't be executed. This is an asynchronous task
"""
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_resume_states()
if not self.finished_or_stopped():
logger.debug("Resume execution engine and run to selected state!")
self.run_to_states = []
self.run_to_states.append(path)
self.set_execution_mode(StateMachineExecutionStatus.RUN_TO_SELECTED_STATE)
else:
logger.debug("Start execution engine and run to selected state!")
if state_machine_id is not None:
self.state_machine_manager.active_state_machine_id = state_machine_id
self.set_execution_mode(StateMachineExecutionStatus.RUN_TO_SELECTED_STATE)
self.run_to_states = []
self.run_to_states.append(path)
self._run_active_state_machine() | python | def run_to_selected_state(self, path, state_machine_id=None):
"""Execute the state machine until a specific state. This state won't be executed. This is an asynchronous task
"""
if self.state_machine_manager.get_active_state_machine() is not None:
self.state_machine_manager.get_active_state_machine().root_state.recursively_resume_states()
if not self.finished_or_stopped():
logger.debug("Resume execution engine and run to selected state!")
self.run_to_states = []
self.run_to_states.append(path)
self.set_execution_mode(StateMachineExecutionStatus.RUN_TO_SELECTED_STATE)
else:
logger.debug("Start execution engine and run to selected state!")
if state_machine_id is not None:
self.state_machine_manager.active_state_machine_id = state_machine_id
self.set_execution_mode(StateMachineExecutionStatus.RUN_TO_SELECTED_STATE)
self.run_to_states = []
self.run_to_states.append(path)
self._run_active_state_machine() | [
"def",
"run_to_selected_state",
"(",
"self",
",",
"path",
",",
"state_machine_id",
"=",
"None",
")",
":",
"if",
"self",
".",
"state_machine_manager",
".",
"get_active_state_machine",
"(",
")",
"is",
"not",
"None",
":",
"self",
".",
"state_machine_manager",
".",
... | Execute the state machine until a specific state. This state won't be executed. This is an asynchronous task | [
"Execute",
"the",
"state",
"machine",
"until",
"a",
"specific",
"state",
".",
"This",
"state",
"won",
"t",
"be",
"executed",
".",
"This",
"is",
"an",
"asynchronous",
"task"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L280-L298 | train | 40,594 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine._wait_while_in_pause_or_in_step_mode | def _wait_while_in_pause_or_in_step_mode(self):
""" Waits as long as the execution_mode is in paused or step_mode
"""
while (self._status.execution_mode is StateMachineExecutionStatus.PAUSED) \
or (self._status.execution_mode is StateMachineExecutionStatus.STEP_MODE):
try:
self._status.execution_condition_variable.acquire()
self.synchronization_counter += 1
logger.verbose("Increase synchronization_counter: " + str(self.synchronization_counter))
self._status.execution_condition_variable.wait()
finally:
self._status.execution_condition_variable.release() | python | def _wait_while_in_pause_or_in_step_mode(self):
""" Waits as long as the execution_mode is in paused or step_mode
"""
while (self._status.execution_mode is StateMachineExecutionStatus.PAUSED) \
or (self._status.execution_mode is StateMachineExecutionStatus.STEP_MODE):
try:
self._status.execution_condition_variable.acquire()
self.synchronization_counter += 1
logger.verbose("Increase synchronization_counter: " + str(self.synchronization_counter))
self._status.execution_condition_variable.wait()
finally:
self._status.execution_condition_variable.release() | [
"def",
"_wait_while_in_pause_or_in_step_mode",
"(",
"self",
")",
":",
"while",
"(",
"self",
".",
"_status",
".",
"execution_mode",
"is",
"StateMachineExecutionStatus",
".",
"PAUSED",
")",
"or",
"(",
"self",
".",
"_status",
".",
"execution_mode",
"is",
"StateMachin... | Waits as long as the execution_mode is in paused or step_mode | [
"Waits",
"as",
"long",
"as",
"the",
"execution_mode",
"is",
"in",
"paused",
"or",
"step_mode"
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L300-L311 | train | 40,595 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine._wait_if_required | def _wait_if_required(self, container_state, next_child_state_to_execute, woke_up_from_pause_or_step_mode):
""" Calls a blocking wait for the calling thread, depending on the execution mode.
:param container_state: the current hierarhcy state to handle the execution mode for
:param next_child_state_to_execute: the next child state for :param container_state to be executed
:param woke_up_from_pause_or_step_mode: a flag to check if the execution just woke up from paused- or step-mode
"""
wait = True
# if there is a state in self.run_to_states then RAFCON was commanded
# a) a step_over
# b) a step_out
# c) a run_until
for state_path in copy.deepcopy(self.run_to_states):
next_child_state_path = None
# can be None in case of no transition given
if next_child_state_to_execute:
next_child_state_path = next_child_state_to_execute.get_path()
if state_path == container_state.get_path():
# the execution did a whole step_over inside hierarchy state "state" (case a) )
# or a whole step_out into the hierarchy state "state" (case b) )
# thus we delete its state path from self.run_to_states
# and wait for another step (of maybe different kind)
wait = True
self.run_to_states.remove(state_path)
break
elif state_path == next_child_state_path:
# this is the case that execution has reached a specific state explicitly marked via
# run_to_selected_state() (case c) )
# if this is the case run_to_selected_state() is finished and the execution
# has to wait for new execution commands
wait = True
self.run_to_states.remove(state_path)
break
# don't wait if its just a normal step
else:
wait = False
# do not break here, the state_path may be of another state machine branch
# break
# don't wait if the the execution just woke up from step mode or pause
if wait and not woke_up_from_pause_or_step_mode:
logger.debug("Stepping mode: waiting for next step!")
try:
self._status.execution_condition_variable.acquire()
self.synchronization_counter += 1
logger.verbose("Increase synchronization_counter: " + str(self.synchronization_counter))
self._status.execution_condition_variable.wait()
finally:
self._status.execution_condition_variable.release()
# if the status was set to PAUSED or STEP_MODE don't wake up!
self._wait_while_in_pause_or_in_step_mode()
# container_state was notified => thus, a new user command was issued, which has to be handled!
container_state.execution_history.new_execution_command_handled = False | python | def _wait_if_required(self, container_state, next_child_state_to_execute, woke_up_from_pause_or_step_mode):
""" Calls a blocking wait for the calling thread, depending on the execution mode.
:param container_state: the current hierarhcy state to handle the execution mode for
:param next_child_state_to_execute: the next child state for :param container_state to be executed
:param woke_up_from_pause_or_step_mode: a flag to check if the execution just woke up from paused- or step-mode
"""
wait = True
# if there is a state in self.run_to_states then RAFCON was commanded
# a) a step_over
# b) a step_out
# c) a run_until
for state_path in copy.deepcopy(self.run_to_states):
next_child_state_path = None
# can be None in case of no transition given
if next_child_state_to_execute:
next_child_state_path = next_child_state_to_execute.get_path()
if state_path == container_state.get_path():
# the execution did a whole step_over inside hierarchy state "state" (case a) )
# or a whole step_out into the hierarchy state "state" (case b) )
# thus we delete its state path from self.run_to_states
# and wait for another step (of maybe different kind)
wait = True
self.run_to_states.remove(state_path)
break
elif state_path == next_child_state_path:
# this is the case that execution has reached a specific state explicitly marked via
# run_to_selected_state() (case c) )
# if this is the case run_to_selected_state() is finished and the execution
# has to wait for new execution commands
wait = True
self.run_to_states.remove(state_path)
break
# don't wait if its just a normal step
else:
wait = False
# do not break here, the state_path may be of another state machine branch
# break
# don't wait if the the execution just woke up from step mode or pause
if wait and not woke_up_from_pause_or_step_mode:
logger.debug("Stepping mode: waiting for next step!")
try:
self._status.execution_condition_variable.acquire()
self.synchronization_counter += 1
logger.verbose("Increase synchronization_counter: " + str(self.synchronization_counter))
self._status.execution_condition_variable.wait()
finally:
self._status.execution_condition_variable.release()
# if the status was set to PAUSED or STEP_MODE don't wake up!
self._wait_while_in_pause_or_in_step_mode()
# container_state was notified => thus, a new user command was issued, which has to be handled!
container_state.execution_history.new_execution_command_handled = False | [
"def",
"_wait_if_required",
"(",
"self",
",",
"container_state",
",",
"next_child_state_to_execute",
",",
"woke_up_from_pause_or_step_mode",
")",
":",
"wait",
"=",
"True",
"# if there is a state in self.run_to_states then RAFCON was commanded",
"# a) a step_over",
"# b) a ste... | Calls a blocking wait for the calling thread, depending on the execution mode.
:param container_state: the current hierarhcy state to handle the execution mode for
:param next_child_state_to_execute: the next child state for :param container_state to be executed
:param woke_up_from_pause_or_step_mode: a flag to check if the execution just woke up from paused- or step-mode | [
"Calls",
"a",
"blocking",
"wait",
"for",
"the",
"calling",
"thread",
"depending",
"on",
"the",
"execution",
"mode",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L313-L364 | train | 40,596 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.handle_execution_mode | def handle_execution_mode(self, container_state, next_child_state_to_execute=None):
"""Checks the current execution status and returns it.
Depending on the execution state, the calling thread (currently only hierarchy states) waits for the
execution to continue.
If the execution mode is any of the step modes, a condition variable stops the current execution,
until it gets notified by the step_*() or backward_step() functions.
:param container_state: the container_state, for which the execution mode is handled
:param next_child_state_to_execute: is the next child state of :param state to be executed
:return: the current state machine execution status
"""
self.state_counter_lock.acquire()
self.state_counter += 1
# logger.verbose("Increase state_counter!" + str(self.state_counter))
self.state_counter_lock.release()
woke_up_from_pause_or_step_mode = False
if (self._status.execution_mode is StateMachineExecutionStatus.PAUSED) \
or (self._status.execution_mode is StateMachineExecutionStatus.STEP_MODE):
self._wait_while_in_pause_or_in_step_mode()
# new command was triggered => execution command has to handled
container_state.execution_history.new_execution_command_handled = False
woke_up_from_pause_or_step_mode = True
# no elif here: if the execution woke up from e.g. paused mode, it has to check the current execution mode
if self._status.execution_mode is StateMachineExecutionStatus.STARTED:
# logger.debug("Execution engine started!")
pass
elif self._status.execution_mode is StateMachineExecutionStatus.STOPPED:
logger.debug("Execution engine stopped. State '{0}' is going to quit in the case of "
"no preemption handling has to be done!".format(container_state.name))
elif self._status.execution_mode is StateMachineExecutionStatus.FINISHED:
# this must never happen during execution of the execution engine
raise Exception
else: # all other step modes
logger.verbose("before wait")
self._wait_if_required(container_state, next_child_state_to_execute, woke_up_from_pause_or_step_mode)
logger.verbose("after wait")
# calculate states to which should be run
if self._status.execution_mode is StateMachineExecutionStatus.BACKWARD:
pass
elif self._status.execution_mode is StateMachineExecutionStatus.FORWARD_INTO:
pass
elif self._status.execution_mode is StateMachineExecutionStatus.FORWARD_OVER:
if not container_state.execution_history.new_execution_command_handled:
# the state that called this method is a hierarchy state => thus we save this state and wait until
# thise very state will execute its next state; only then we will wait on the condition variable
self.run_to_states.append(container_state.get_path())
else:
pass
elif self._status.execution_mode is StateMachineExecutionStatus.FORWARD_OUT:
from rafcon.core.states.state import State
if isinstance(container_state.parent, State):
if not container_state.execution_history.new_execution_command_handled:
from rafcon.core.states.library_state import LibraryState
if isinstance(container_state.parent, LibraryState):
parent_path = container_state.parent.parent.get_path()
else:
parent_path = container_state.parent.get_path()
self.run_to_states.append(parent_path)
else:
pass
else:
# if step_out is called from the highest level just run the state machine to the end
self.run_to_states = []
self.set_execution_mode(StateMachineExecutionStatus.STARTED)
elif self._status.execution_mode is StateMachineExecutionStatus.RUN_TO_SELECTED_STATE:
# "run_to_states" were already updated thus doing nothing
pass
container_state.execution_history.new_execution_command_handled = True
# in the case that the stop method wakes up the paused or step mode a StateMachineExecutionStatus.STOPPED
# will be returned
return_value = self._status.execution_mode
return return_value | python | def handle_execution_mode(self, container_state, next_child_state_to_execute=None):
"""Checks the current execution status and returns it.
Depending on the execution state, the calling thread (currently only hierarchy states) waits for the
execution to continue.
If the execution mode is any of the step modes, a condition variable stops the current execution,
until it gets notified by the step_*() or backward_step() functions.
:param container_state: the container_state, for which the execution mode is handled
:param next_child_state_to_execute: is the next child state of :param state to be executed
:return: the current state machine execution status
"""
self.state_counter_lock.acquire()
self.state_counter += 1
# logger.verbose("Increase state_counter!" + str(self.state_counter))
self.state_counter_lock.release()
woke_up_from_pause_or_step_mode = False
if (self._status.execution_mode is StateMachineExecutionStatus.PAUSED) \
or (self._status.execution_mode is StateMachineExecutionStatus.STEP_MODE):
self._wait_while_in_pause_or_in_step_mode()
# new command was triggered => execution command has to handled
container_state.execution_history.new_execution_command_handled = False
woke_up_from_pause_or_step_mode = True
# no elif here: if the execution woke up from e.g. paused mode, it has to check the current execution mode
if self._status.execution_mode is StateMachineExecutionStatus.STARTED:
# logger.debug("Execution engine started!")
pass
elif self._status.execution_mode is StateMachineExecutionStatus.STOPPED:
logger.debug("Execution engine stopped. State '{0}' is going to quit in the case of "
"no preemption handling has to be done!".format(container_state.name))
elif self._status.execution_mode is StateMachineExecutionStatus.FINISHED:
# this must never happen during execution of the execution engine
raise Exception
else: # all other step modes
logger.verbose("before wait")
self._wait_if_required(container_state, next_child_state_to_execute, woke_up_from_pause_or_step_mode)
logger.verbose("after wait")
# calculate states to which should be run
if self._status.execution_mode is StateMachineExecutionStatus.BACKWARD:
pass
elif self._status.execution_mode is StateMachineExecutionStatus.FORWARD_INTO:
pass
elif self._status.execution_mode is StateMachineExecutionStatus.FORWARD_OVER:
if not container_state.execution_history.new_execution_command_handled:
# the state that called this method is a hierarchy state => thus we save this state and wait until
# thise very state will execute its next state; only then we will wait on the condition variable
self.run_to_states.append(container_state.get_path())
else:
pass
elif self._status.execution_mode is StateMachineExecutionStatus.FORWARD_OUT:
from rafcon.core.states.state import State
if isinstance(container_state.parent, State):
if not container_state.execution_history.new_execution_command_handled:
from rafcon.core.states.library_state import LibraryState
if isinstance(container_state.parent, LibraryState):
parent_path = container_state.parent.parent.get_path()
else:
parent_path = container_state.parent.get_path()
self.run_to_states.append(parent_path)
else:
pass
else:
# if step_out is called from the highest level just run the state machine to the end
self.run_to_states = []
self.set_execution_mode(StateMachineExecutionStatus.STARTED)
elif self._status.execution_mode is StateMachineExecutionStatus.RUN_TO_SELECTED_STATE:
# "run_to_states" were already updated thus doing nothing
pass
container_state.execution_history.new_execution_command_handled = True
# in the case that the stop method wakes up the paused or step mode a StateMachineExecutionStatus.STOPPED
# will be returned
return_value = self._status.execution_mode
return return_value | [
"def",
"handle_execution_mode",
"(",
"self",
",",
"container_state",
",",
"next_child_state_to_execute",
"=",
"None",
")",
":",
"self",
".",
"state_counter_lock",
".",
"acquire",
"(",
")",
"self",
".",
"state_counter",
"+=",
"1",
"# logger.verbose(\"Increase state_cou... | Checks the current execution status and returns it.
Depending on the execution state, the calling thread (currently only hierarchy states) waits for the
execution to continue.
If the execution mode is any of the step modes, a condition variable stops the current execution,
until it gets notified by the step_*() or backward_step() functions.
:param container_state: the container_state, for which the execution mode is handled
:param next_child_state_to_execute: is the next child state of :param state to be executed
:return: the current state machine execution status | [
"Checks",
"the",
"current",
"execution",
"status",
"and",
"returns",
"it",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L366-L449 | train | 40,597 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.execute_state_machine_from_path | def execute_state_machine_from_path(self, state_machine=None, path=None, start_state_path=None, wait_for_execution_finished=True):
""" A helper function to start an arbitrary state machine at a given path.
:param path: The path where the state machine resides
:param start_state_path: The path to the state from which the execution will start
:return: a reference to the created state machine
"""
import rafcon.core.singleton
from rafcon.core.storage import storage
rafcon.core.singleton.library_manager.initialize()
if not state_machine:
state_machine = storage.load_state_machine_from_path(path)
rafcon.core.singleton.state_machine_manager.add_state_machine(state_machine)
rafcon.core.singleton.state_machine_execution_engine.start(
state_machine.state_machine_id, start_state_path=start_state_path)
if wait_for_execution_finished:
self.join()
self.stop()
return state_machine | python | def execute_state_machine_from_path(self, state_machine=None, path=None, start_state_path=None, wait_for_execution_finished=True):
""" A helper function to start an arbitrary state machine at a given path.
:param path: The path where the state machine resides
:param start_state_path: The path to the state from which the execution will start
:return: a reference to the created state machine
"""
import rafcon.core.singleton
from rafcon.core.storage import storage
rafcon.core.singleton.library_manager.initialize()
if not state_machine:
state_machine = storage.load_state_machine_from_path(path)
rafcon.core.singleton.state_machine_manager.add_state_machine(state_machine)
rafcon.core.singleton.state_machine_execution_engine.start(
state_machine.state_machine_id, start_state_path=start_state_path)
if wait_for_execution_finished:
self.join()
self.stop()
return state_machine | [
"def",
"execute_state_machine_from_path",
"(",
"self",
",",
"state_machine",
"=",
"None",
",",
"path",
"=",
"None",
",",
"start_state_path",
"=",
"None",
",",
"wait_for_execution_finished",
"=",
"True",
")",
":",
"import",
"rafcon",
".",
"core",
".",
"singleton"... | A helper function to start an arbitrary state machine at a given path.
:param path: The path where the state machine resides
:param start_state_path: The path to the state from which the execution will start
:return: a reference to the created state machine | [
"A",
"helper",
"function",
"to",
"start",
"an",
"arbitrary",
"state",
"machine",
"at",
"a",
"given",
"path",
"."
] | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L476-L497 | train | 40,598 |
DLR-RM/RAFCON | source/rafcon/core/execution/execution_engine.py | ExecutionEngine.set_execution_mode | def set_execution_mode(self, execution_mode, notify=True):
""" An observed setter for the execution mode of the state machine status. This is necessary for the
monitoring client to update the local state machine in the same way as the root state machine of the server.
:param execution_mode: the new execution mode of the state machine
:raises exceptions.TypeError: if the execution mode is of the wrong type
"""
if not isinstance(execution_mode, StateMachineExecutionStatus):
raise TypeError("status must be of type StateMachineExecutionStatus")
self._status.execution_mode = execution_mode
if notify:
self._status.execution_condition_variable.acquire()
self._status.execution_condition_variable.notify_all()
self._status.execution_condition_variable.release() | python | def set_execution_mode(self, execution_mode, notify=True):
""" An observed setter for the execution mode of the state machine status. This is necessary for the
monitoring client to update the local state machine in the same way as the root state machine of the server.
:param execution_mode: the new execution mode of the state machine
:raises exceptions.TypeError: if the execution mode is of the wrong type
"""
if not isinstance(execution_mode, StateMachineExecutionStatus):
raise TypeError("status must be of type StateMachineExecutionStatus")
self._status.execution_mode = execution_mode
if notify:
self._status.execution_condition_variable.acquire()
self._status.execution_condition_variable.notify_all()
self._status.execution_condition_variable.release() | [
"def",
"set_execution_mode",
"(",
"self",
",",
"execution_mode",
",",
"notify",
"=",
"True",
")",
":",
"if",
"not",
"isinstance",
"(",
"execution_mode",
",",
"StateMachineExecutionStatus",
")",
":",
"raise",
"TypeError",
"(",
"\"status must be of type StateMachineExec... | An observed setter for the execution mode of the state machine status. This is necessary for the
monitoring client to update the local state machine in the same way as the root state machine of the server.
:param execution_mode: the new execution mode of the state machine
:raises exceptions.TypeError: if the execution mode is of the wrong type | [
"An",
"observed",
"setter",
"for",
"the",
"execution",
"mode",
"of",
"the",
"state",
"machine",
"status",
".",
"This",
"is",
"necessary",
"for",
"the",
"monitoring",
"client",
"to",
"update",
"the",
"local",
"state",
"machine",
"in",
"the",
"same",
"way",
... | 24942ef1a904531f49ab8830a1dbb604441be498 | https://github.com/DLR-RM/RAFCON/blob/24942ef1a904531f49ab8830a1dbb604441be498/source/rafcon/core/execution/execution_engine.py#L500-L513 | train | 40,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.