code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
if self.list_store[path][self.DATA_TYPE_AS_STRING_STORAGE_ID] == new_data_type_as_string:
return
gv_name = self.list_store[path][self.NAME_STORAGE_ID]
if not self.global_variable_is_editable(gv_name, 'Type change'):
return
old_value = self.model.global_va... | def apply_new_global_variable_type(self, path, new_data_type_as_string) | Change global variable value according handed string
Updates the global variable data type only if different.
:param path: The path identifying the edited global variable tree view row, can be str, int or tuple.
:param str new_data_type_as_string: New global variable data type as string | 3.226514 | 3.135681 | 1.028968 |
if info['method_name'] in ['set_locked_variable'] or info['result'] is Exception:
return
if info['method_name'] in ['lock_variable', 'unlock_variable']:
key = info.kwargs.get('key', info.args[1]) if len(info.args) > 1 else info.kwargs['key']
if key in self.... | def assign_notification_from_gvm(self, model, prop_name, info) | Handles gtkmvc3 notification from global variable manager
Calls update of whole list store in case new variable was added. Avoids to run updates without reasonable change.
Holds tree store and updates row elements if is-locked or global variable value changes. | 2.681235 | 2.441365 | 1.098252 |
# logger.info("update")
self.list_store_iterators = {}
self.list_store.clear()
keys = self.model.global_variable_manager.get_all_keys()
keys.sort()
for key in keys:
iter = self.list_store.append([key,
self.mo... | def update_global_variables_list_store(self) | Updates the global variable list store
Triggered after creation or deletion of a variable has taken place. | 3.137583 | 3.110155 | 1.008819 |
for lib in os.listdir(lib_path):
if os.path.isdir(os.path.join(lib_path, lib)) and not '.' == lib[0]:
if os.path.exists(os.path.join(os.path.join(lib_path, lib), "statemachine.yaml")) or \
os.path.exists(os.path.join(os.path.join(lib_path, lib), "statemachine.json")):
... | def convert_libraries_in_path(config_path, lib_path, target_path=None) | This function resaves all libraries found at the spcified path
:param lib_path: the path to look for libraries
:return: | 2.171739 | 2.192644 | 0.990466 |
from rafcon.gui.mygaphas.items.state import StateView
from rafcon.gui.mygaphas.items.connection import DataFlowView, TransitionView
if parent_item is None:
items = self.get_all_items()
else:
items = self.get_children(parent_item)
for item in items... | def get_view_for_id(self, view_class, element_id, parent_item=None) | Searches and returns the View for the given id and type
:param view_class: The view type to search for
:param element_id: The id of element of the searched view
:param gaphas.item.Item parent_item: Restrict the search to this parent item
:return: The view for the given id or None if not... | 2.647126 | 2.553217 | 1.036781 |
if trigger_update:
self.update_now()
from gi.repository import Gtk
from gi.repository import GLib
from threading import Event
event = Event()
# Handle all events from gaphas, but not from gtkmvc3
# Make use of the priority, which is higher f... | def wait_for_update(self, trigger_update=False) | Update canvas and handle all events in the gtk queue
:param bool trigger_update: Whether to call update_now() or not | 6.926869 | 6.535037 | 1.059959 |
x, y = self._point.x, self._point.y
self._px, self._py = self._item_point.canvas.get_matrix_i2i(self._item_point,
self._item_target).transform_point(x, y)
return self._px, self._py | def _get_value(self) | Return two delegating variables. Each variable should contain
a value attribute with the real value. | 6.491399 | 5.550013 | 1.169619 |
# If the parameter is already a type, return it
if string_value in ['None', type(None).__name__]:
return type(None)
if isinstance(string_value, type) or isclass(string_value):
return string_value
# Get object associated with string
# First check whether we are having a built in... | def convert_string_to_type(string_value) | Converts a string into a type or class
:param string_value: the string to be converted, e.g. "int"
:return: The type derived from string_value, e.g. int | 3.601211 | 3.490487 | 1.031722 |
from ast import literal_eval
try:
if data_type in (str, type(None)):
converted_value = str(string_value)
elif data_type == int:
converted_value = int(string_value)
elif data_type == float:
converted_value = float(string_value)
elif data_t... | def convert_string_value_to_type_value(string_value, data_type) | Helper function to convert a given string to a given data type
:param str string_value: the string to convert
:param type data_type: the target data type
:return: the converted value | 2.046653 | 2.08637 | 0.980963 |
assert isinstance(inheriting_type, type) or isclass(inheriting_type)
assert isinstance(base_type, type) or isclass(base_type)
if inheriting_type == base_type:
return True
else:
if len(inheriting_type.__bases__) != 1:
return False
return type_inherits_of_type(inh... | def type_inherits_of_type(inheriting_type, base_type) | Checks whether inheriting_type inherits from base_type
:param str inheriting_type:
:param str base_type:
:return: True is base_type is base of inheriting_type | 1.840659 | 2.069887 | 0.889256 |
'''Used to clear the result tables in the OEDB. Caution!
This deletes EVERY RESULT SET!'''
from egoio.db_tables.model_draft import EgoGridPfHvResultBus as BusResult,\
EgoGridPfHvResultBusT as BusTResult,\
EgoGridPfHvResultStorage as StorageResult,\
EgoGridPfHvResultStorageT as S... | def clear_results_db(session) | Used to clear the result tables in the OEDB. Caution!
This deletes EVERY RESULT SET! | 2.412887 | 2.031622 | 1.187665 |
script_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'sql_scripts'))
script_str = open(os.path.join(script_dir, scriptname)).read()
conn.execution_options(autocommit=True).execute(script_str)
return | def run_sql_script(conn, scriptname='results_md2grid.sql') | This function runs .sql scripts in the folder 'sql_scripts' | 2.306512 | 2.295202 | 1.004928 |
if version is None:
ormcls_prefix = 'EgoGridPfHvExtension'
else:
ormcls_prefix = 'EgoPfHvExtension'
# Adding overlay-network to existing network
scenario = NetworkScenario(session,
version = version,
p... | def extension (network, session, version, scn_extension, start_snapshot,
end_snapshot, **kwargs) | Function that adds an additional network to the existing network container.
The new network can include every PyPSA-component (e.g. buses, lines, links).
To connect it to the existing network, transformers are needed.
All components and its timeseries of the additional scenario need to be insert... | 6.186745 | 4.959028 | 1.247572 |
if args['gridversion'] == None:
ormclass = getattr(import_module('egoio.db_tables.model_draft'),
'EgoGridPfHvExtensionLine')
else:
ormclass = getattr(import_module('egoio.db_tables.grid'),
'EgoPfHvExtensionLine')
query = sessi... | def decommissioning(network, session, args, **kwargs) | Function that removes components in a decommissioning-scenario from
the existing network container.
Currently, only lines can be decommissioned.
All components of the decommissioning scenario need to be inserted in
the fitting 'model_draft.ego_grid_pf_hv_extension_' table.
The scn_n... | 4.704024 | 3.906228 | 1.204237 |
# Calculate square of the distance between two points (Pythagoras)
distance = (x1.values- x0.values)*(x1.values- x0.values)\
+ (y1.values- y0.values)*(y1.values- y0.values)
return distance | def distance(x0, x1, y0, y1) | Function that calculates the square of the distance between two points.
Parameters
-----
x0: x - coordinate of point 0
x1: x - coordinate of point 1
y0: y - coordinate of point 0
y1: y - coordinate of point 1
Returns
------
distance : float
square ... | 3.430827 | 3.683234 | 0.931471 |
bus1_index = network.buses.index[network.buses.index == bus1]
forbidden_buses = np.append(
bus1_index.values, network.lines.bus1[
network.lines.bus0 == bus1].values)
forbidden_buses = np.append(
forbidden_buses, network.lines.bus0[network.lines.bus1 == bus1].values)
... | def calc_nearest_point(bus1, network) | Function that finds the geographical nearest point in a network from a given bus.
Parameters
-----
bus1: float
id of bus
network: Pypsa network container
network including the comparable buses
Returns
------
bus0 : float
bus_id of nearest point | 1.983712 | 1.969637 | 1.007146 |
try:
self._mapped[name] = getattr(self._pkg, self._prefix + name)
except AttributeError:
print('Warning: Relation %s does not exist.' % name) | def map_ormclass(self, name) | Populate _mapped attribute with orm class
Parameters
----------
name : str
Component part of orm class name. Concatenated with _prefix. | 7.450035 | 5.081833 | 1.466013 |
try:
ormclass = self._mapped['TempResolution']
if self.version:
tr = self.session.query(ormclass).filter(
ormclass.temp_id == self.temp_id).filter(
ormclass.version == self.version).one()
else:
... | def configure_timeindex(self) | Construct a DateTimeIndex with the queried temporal resolution,
start- and end_snapshot. | 3.908154 | 3.389949 | 1.152865 |
ormclass = self._mapped[name]
query = self.session.query(ormclass)
if name != carr_ormclass:
query = query.filter(
ormclass.scn_name == self.scn_name)
if self.version:
query = query.filter(ormclass.version == self.version)
# T... | def fetch_by_relname(self, name) | Construct DataFrame with component data from filtered table data.
Parameters
----------
name : str
Component name.
Returns
-------
pd.DataFrame
Component data. | 4.71945 | 4.831366 | 0.976836 |
ormclass = self._mapped[name]
# TODO: This is implemented in a not very robust way.
id_column = re.findall(r'[A-Z][^A-Z]*', name)[0] + '_' + 'id'
id_column = id_column.lower()
query = self.session.query(
getattr(ormclass, id_column),
getattr(or... | def series_fetch_by_relname(self, name, column) | Construct DataFrame with component timeseries data from filtered
table data.
Parameters
----------
name : str
Component name.
column : str
Component field with timevarying data.
Returns
-------
pd.DataFrame
Component d... | 4.227688 | 4.321485 | 0.978295 |
# TODO: build_network takes care of divergences in database design and
# future PyPSA changes from PyPSA's v0.6 on. This concept should be
# replaced, when the oedb has a revision system in place, because
# sometime this will break!!!
if network != None:
net... | def build_network(self, network=None, *args, **kwargs) | Core method to construct PyPSA Network object. | 4.603702 | 4.466286 | 1.030767 |
logger.debug("Starting execution of {0}{1}".format(self, " (backwards)" if self.backward_execution else ""))
self.setup_run()
try:
concurrency_history_item = self.setup_forward_or_backward_execution()
concurrency_queue = self.start_child_states(concurrency_histo... | def run(self) | This defines the sequence of actions that are taken when the preemptive concurrency state is executed
:return: | 3.731566 | 3.680545 | 1.013862 |
valid, message = super(PreemptiveConcurrencyState, self)._check_transition_validity(check_transition)
if not valid:
return False, message
# Only transitions to the parent state are allowed
if check_transition.to_state != self.state_id:
return False, "On... | def _check_transition_validity(self, check_transition) | Transition of BarrierConcurrencyStates must least fulfill the condition of a ContainerState.
Start transitions are forbidden in the ConcurrencyState
:param check_transition: the transition to check for validity
:return: | 4.646904 | 4.052197 | 1.146761 |
try:
self.relieve_model(self.state_machine_model)
assert self.__buffered_root_state_model is self.state_machine_model.root_state
self.relieve_model(self.__buffered_root_state_model)
self.state_machine_model = None
self.__buffered_root_state_mo... | def prepare_destruction(self) | Prepares the model for destruction
Un-registers itself as observer from the state machine and the root state | 5.79204 | 5.121108 | 1.131013 |
# search for traceable path -> list of action to undo and list of action to redo
logger.info("Going to history status #{0}".format(pointer_on_version_to_recover))
undo_redo_list = self.modifications.get_undo_redo_list_from_active_trail_history_item_to_version_id(pointer_on_version_to_re... | def recover_specific_version(self, pointer_on_version_to_recover) | Recovers a specific version of the all_time_history element by doing several undos and redos.
:param pointer_on_version_to_recover: the id of the list element which is to recover
:return: | 3.948186 | 3.862692 | 1.022133 |
# logger.verbose("states_after: " + str(NotificationOverview(info, False, self.__class__.__name__)))
if self.busy or info.method_name == 'state_change' and \
info.kwargs.prop_name == 'state' and \
info.kwargs.method_name in BY_EXECUTION_TRIGGERED_OBSERVABLE_STAT... | def assign_notification_states_after(self, model, prop_name, info) | This method is called, when any state, transition, data flow, etc. within the state machine modifications. This
then typically requires a redraw of the graphical editor, to display these modifications immediately.
:param model: The state machine model
:param prop_name: The property that was chan... | 8.167478 | 8.238979 | 0.991322 |
all_trail_action = [a.version_id for a in self.single_trail_history() if a is not None]
all_active_action = self.get_all_active_actions()
undo_redo_list = []
_undo_redo_list = []
intermediate_version_id = version_id
if self.with_verbose:
logger.verbo... | def get_undo_redo_list_from_active_trail_history_item_to_version_id(self, version_id) | Perform fast search from currently active branch to specific version_id and collect all recovery steps. | 2.268956 | 2.256384 | 1.005572 |
default_pos = constants.DEFAULT_PANE_POS[config_id]
position = global_runtime_config.get_config_value(config_id, default_pos)
pane_id = constants.PANE_ID[config_id]
self.view[pane_id].set_position(position) | def set_pane_position(self, config_id) | Adjusts the position of a GTK Pane to a value stored in the runtime config file. If there was no value
stored, the pane's position is set to a default value.
:param config_id: The pane identifier saved in the runtime config file | 4.236751 | 4.413372 | 0.95998 |
# TODO: find nice solution
# this in only required if the GUI is terminated via Ctrl+C signal
if not self.view:
# this means that the main window is currently under destruction
return
execution_engine = rafcon.core.singleton.state_machine_execution_engi... | def model_changed(self, model, prop_name, info) | Highlight buttons according actual execution status. Furthermore it triggers the label redraw of the active
state machine. | 4.560692 | 4.220871 | 1.08051 |
# TODO think about to may substitute Controller- by View-objects it is may the better design
if controller not in self.get_child_controllers():
return
# logger.info("focus controller {0}".format(controller))
if not self.modification_history_was_focused and isinstance... | def focus_notebook_page_of_controller(self, controller) | Puts the focus on the given child controller
The method implements focus request of the notebooks in left side-bar of the main window. Thereby it is the
master-function of focus pattern of the notebooks in left side-bar.
Actual pattern is:
* Execution-History is put to focus any time r... | 6.491298 | 5.421757 | 1.197268 |
undocked_window_name = window_key.lower() + '_window'
widget_name = window_key.lower()
undocked_window_view = getattr(self.view, undocked_window_name)
undocked_window = undocked_window_view.get_top_widget()
if os.getenv("RAFCON_START_MINIMIZED", False):
undoc... | def undock_sidebar(self, window_key, widget=None, event=None) | Undock/separate sidebar into independent window
The sidebar is undocked and put into a separate new window. The sidebar is hidden in the main-window by
triggering the method on_[widget_name]_hide_clicked(). Triggering this method shows the
[widget_name]_return_button in the main-window, which d... | 4.197514 | 3.753184 | 1.118387 |
config_parameter_undocked = window_key + '_WINDOW_UNDOCKED'
config_id_for_pane_position = window_key + '_DOCKED_POS'
undocked_window_name = window_key.lower() + '_window'
widget_name = window_key.lower()
undocked_window_view = getattr(self.view, undocked_window_name)
... | def redock_sidebar(self, window_key, sidebar_name, controller_name, widget, event=None) | Redock/embed sidebar into main window
The size & position of the open window are saved to the runtime_config file, the sidebar is redocked back
to the main-window, and the left-bar window is hidden. The undock button of the bar is made visible again. | 4.819772 | 4.671369 | 1.031769 |
title = gui_helper_label.set_notebook_title(notebook, page_num, title_label)
window.reset_title(title, notebook_identifier)
self.on_switch_page_check_collapse_button(notebook, page_num) | def on_notebook_tab_switch(self, notebook, page, page_num, title_label, window, notebook_identifier) | Triggered whenever a left-bar notebook tab is changed.
Updates the title of the corresponding notebook and updates the title of the left-bar window in case un-docked.
:param notebook: The GTK notebook where a tab-change occurred
:param page_num: The page number of the currently-selected tab
... | 7.939572 | 8.668283 | 0.915934 |
self.currently_pressed_keys.add(event.keyval)
if event.keyval in [Gdk.KEY_Tab, Gdk.KEY_ISO_Left_Tab] and event.state & Gdk.ModifierType.CONTROL_MASK:
self.toggle_sidebars() | def _on_key_press(self, widget, event) | Updates the currently pressed keys
In addition, the sidebars are toggled if <Ctrl><Tab> is pressed.
:param Gtk.Widget widget: The main window
:param Gdk.Event event: The key press event | 3.277093 | 2.604164 | 1.258405 |
plugins.run_hook("pre_destruction")
logger.debug("Saving runtime config to {0}".format(global_runtime_config.config_file_path))
# store pane last positions
for key, widget_name in constants.PANE_ID.items():
global_runtime_config.store_widget_properties(self.view[wi... | def prepare_destruction(self) | Saves current configuration of windows and panes to the runtime config file, before RAFCON is closed. | 9.521328 | 8.798313 | 1.082177 |
if self.backward_execution:
# pop the return item of this concurrency state to get the correct scoped data
last_history_item = self.execution_history.pop_last_item()
assert isinstance(last_history_item, ReturnItem)
self.scoped_data = last_history_item.sco... | def setup_forward_or_backward_execution(self) | Sets up the execution of the concurrency states dependent on if the state is executed forward of backward.
:return: | 5.151146 | 5.024583 | 1.025189 |
self.state_execution_status = StateExecutionStatus.EXECUTE_CHILDREN
# actually the queue is not needed in the barrier concurrency case
# to avoid code duplication both concurrency states have the same start child function
concurrency_queue = queue.Queue(maxsize=0) # infinite Qu... | def start_child_states(self, concurrency_history_item, do_not_start_state=None) | Utility function to start all child states of the concurrency state.
:param concurrency_history_item: each concurrent child branch gets an execution history stack of this
concurrency history item
:param do_not_start_state: optionally the id of a state can be pass... | 6.080011 | 5.879165 | 1.034162 |
state.join()
if state.backward_execution:
self.backward_execution = True
state.state_execution_status = StateExecutionStatus.INACTIVE
# care for the history items
if not self.backward_execution:
state.concurrency_queue = None
# add th... | def join_state(self, state, history_index, concurrency_history_item) | a utility function to join a state
:param state: the state to join
:param history_index: the index of the execution history stack in the concurrency history item
for the given state
:param concurrency_history_item: the concurrency history item that stores the exe... | 9.835636 | 8.660387 | 1.135704 |
# backward_execution needs to be True to signal the parent container state the backward execution
self.backward_execution = True
# pop the ConcurrencyItem as we are leaving the barrier concurrency state
last_history_item = self.execution_history.pop_last_item()
assert is... | def finalize_backward_execution(self) | Utility function to finalize the backward execution of the concurrency state.
:return: | 7.945756 | 7.530684 | 1.055118 |
final_outcome = outcome
self.write_output_data()
self.check_output_data_type()
self.execution_history.push_return_history_item(self, CallType.CONTAINER, self, self.output_data)
self.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE
singleton.stat... | def finalize_concurrency_state(self, outcome) | Utility function to finalize the forward execution of the concurrency state.
:param outcome:
:return: | 9.692798 | 9.775061 | 0.991584 |
if not port:
return 0.
parent_state_v = self.get_parent_state_v()
if parent_state_v is port.parent: # port of connection's parent state
return port.port_size[1]
return max(port.port_size[1] * 1.5, self._calc_line_width() / 1.3) | def _head_length(self, port) | Distance from the center of the port to the perpendicular waypoint | 7.158689 | 6.750638 | 1.060446 |
super(DataPortListController, self).register_view(view)
view['name_col'].add_attribute(view['name_text'], 'text', self.NAME_STORAGE_ID)
view['data_type_col'].add_attribute(view['data_type_text'], 'text', self.DATA_TYPE_NAME_STORAGE_ID)
if not isinstance(self.model.state, Librar... | def register_view(self, view) | Called when the View was registered | 2.553553 | 2.558073 | 0.998233 |
try:
data_port_id = self.list_store[path][self.ID_STORAGE_ID]
self.toggle_runtime_value_usage(data_port_id)
except TypeError as e:
logger.exception("Error while trying to change the use_runtime_value flag") | def on_use_runtime_value_toggled(self, widget, path) | Try to set the use runtime value flag to the newly entered one | 6.598111 | 5.816149 | 1.134447 |
if isinstance(self.model.state, LibraryState):
use_runtime_value = model.get_value(iter, self.USE_RUNTIME_VALUE_STORAGE_ID)
if use_runtime_value:
cell.set_property("editable", True)
cell.set_property('text', model.get_value(iter, self.RUNTIME_VALU... | def _default_value_cell_data_func(self, tree_view_column, cell, model, iter, data=None) | Function set renderer properties for every single cell independently
The function controls the editable and color scheme for every cell in the default value column according
the use_runtime_value flag and whether the state is a library state.
:param tree_view_column: the Gtk.TreeViewColumn to ... | 2.597966 | 2.28954 | 1.134711 |
tmp = self._get_new_list_store()
for data_port_m in self.data_port_model_list:
data_port_id = data_port_m.data_port.data_port_id
data_type = data_port_m.data_port.data_type
# get name of type (e.g. ndarray)
data_type_name = data_type.__name__
... | def _reload_data_port_list_store(self) | Reloads the input data port list store from the data port models | 2.700651 | 2.630518 | 1.026661 |
try:
data_port_id = self.list_store[path][self.ID_STORAGE_ID]
if self.state_data_port_dict[data_port_id].name != new_name:
self.state_data_port_dict[data_port_id].name = new_name
except (TypeError, ValueError) as e:
logger.exception("Error whi... | def _apply_new_data_port_name(self, path, new_name) | Applies the new name of the data port defined by path
:param str path: The path identifying the edited data port
:param str new_name: New name | 3.629204 | 4.033229 | 0.899826 |
try:
data_port_id = self.list_store[path][self.ID_STORAGE_ID]
if self.state_data_port_dict[data_port_id].data_type.__name__ != new_data_type_str:
self.state_data_port_dict[data_port_id].change_data_type(new_data_type_str)
except ValueError as e:
... | def _apply_new_data_port_type(self, path, new_data_type_str) | Applies the new data type of the data port defined by path
:param str path: The path identifying the edited data port
:param str new_data_type_str: New data type as str | 3.366891 | 3.416393 | 0.98551 |
try:
data_port_id = self.list_store[path][self.ID_STORAGE_ID]
if isinstance(self.model.state, LibraryState):
# this always has to be true, as the runtime value column can only be edited
# if the use_runtime_value flag is True
if se... | def _apply_new_data_port_default_value(self, path, new_default_value_str) | Applies the new default value of the data port defined by path
:param str path: The path identifying the edited variable
:param str new_default_value_str: New default value as string | 3.706137 | 3.78034 | 0.980371 |
if not isinstance(model, AbstractStateModel):
return
# store port selection
path_list = None
if self.view is not None:
model, path_list = self.tree_view.get_selection().get_selected_rows()
selected_data_port_ids = [self.list_store[path[0]][self.ID... | def _data_ports_changed(self, model) | Reload list store and reminds selection when the model was changed | 4.241735 | 3.730609 | 1.137009 |
if ("_input_runtime_value" in info.method_name or
info.method_name in ['use_runtime_value_input_data_ports',
'input_data_port_runtime_values']) and \
self.model is model:
self._data_ports_changed(model) | def runtime_values_changed(self, model, prop_name, info) | Handle cases for the library runtime values | 8.809652 | 8.717129 | 1.010614 |
try:
new_data_port_ids = gui_helper_state_machine.add_data_port_to_selected_states('OUTPUT', int, [self.model])
if new_data_port_ids:
self.select_entry(new_data_port_ids[self.model.state])
except ValueError:
pass | def add_new_data_port(self) | Add a new port with default values and select it | 7.509953 | 7.251656 | 1.035619 |
if hasattr(callback, '__call__'): # Is the callback really a function?
if action not in self.__action_to_callbacks:
self.__action_to_callbacks[action] = []
self.__action_to_callbacks[action].append(callback)
controller = None
try:
... | def add_callback_for_action(self, action, callback) | Adds a callback function to an action
The method checks whether both action and callback are valid. If so, the callback is added to the list of
functions called when the action is triggered.
:param str action: An action like 'add', 'copy', 'info'
:param callback: A callback function, w... | 2.22535 | 2.266219 | 0.981966 |
if action in self.__action_to_callbacks:
if callback in self.__action_to_callbacks[action]:
self.__action_to_callbacks[action].remove(callback) | def remove_callback_for_action(self, action, callback) | Remove a callback for a specific action
This is mainly for cleanup purposes or a plugin that replaces a GUI widget.
:param str action: the cation of which the callback is going to be remove
:param callback: the callback to be removed | 2.19158 | 2.856265 | 0.767289 |
res = False
if action in self.__action_to_callbacks:
for callback_function in self.__action_to_callbacks[action]:
try:
ret = callback_function(key_value, modifier_mask)
# If at least one controller returns True, the whole resul... | def trigger_action(self, action, key_value, modifier_mask) | Calls the appropriate callback function(s) for the given action
:param str action: The name of the action that was triggered
:param key_value: The key value of the shortcut that caused the trigger
:param modifier_mask: The modifier mask of the shortcut that caused the trigger
:return: W... | 4.096416 | 3.91554 | 1.046194 |
# TODO that could need a second clean up
# avoid updates because of state destruction
if 'before' in info and info['method_name'] == "remove_state":
if info.instance is self.model.state:
self.no_update_state_destruction = True
else:
... | def check_info_on_no_update_flags(self, info) | Stop updates while multi-actions | 4.024997 | 4.000334 | 1.006165 |
if is_execution_status_update_notification_from_state_machine_model(prop_name, info):
return
# do not update while multi-actions
self.check_info_on_no_update_flags(info) | def before_notification_state_machine_observation_control(self, model, prop_name, info) | Check for multi-actions and set respective no update flags. | 14.933337 | 9.465046 | 1.577735 |
if not isinstance(parameters, dict):
raise TypeError("parameters must be a dict")
hash = self._parameter_hash(parameters)
if name not in self._cache:
self._cache[name] = {}
self._cache[name][hash.hexdigest()] = value | def store_value(self, name, value, parameters=None) | Stores the value of a certain variable
The value of a variable with name 'name' is stored together with the parameters that were used for the
calculation.
:param str name: The name of the variable
:param value: The value to be cached
:param dict parameters: The parameters on wh... | 3.25289 | 3.659101 | 0.888986 |
if not isinstance(parameters, dict):
raise TypeError("parameters must a dict")
if name not in self._cache:
return None
hash = self._parameter_hash(parameters)
hashdigest = hash.hexdigest()
return self._cache[name].get(hashdigest, None) | def get_value(self, name, parameters=None) | Return the value of a cached variable if applicable
The value of the variable 'name' is returned, if no parameters are passed or if all parameters are identical
to the ones stored for the variable.
:param str name: Name of teh variable
:param dict parameters: Current parameters or None... | 4.326558 | 4.395818 | 0.984244 |
for key, value in parameters.items():
if isinstance(value, (int, float)):
parameters[key] = str(Decimal(value).normalize(self._context)) | def _normalize_number_values(self, parameters) | Assures equal precision for all number values | 3.628039 | 2.937323 | 1.235151 |
super(AbstractTreeViewController, self).register_view(view)
self.signal_handlers.append((self._tree_selection,
self._tree_selection.connect('changed', self.selection_changed)))
# self.handler_ids.append((self.tree_view,
# ... | def register_view(self, view) | Register callbacks for button press events and selection changed | 3.990283 | 3.869623 | 1.031181 |
if not self.MODEL_STORAGE_ID:
return None, None
# avoid selection requests on empty tree views -> case warnings in gtk3
if len(self.store) == 0:
paths = []
else:
model, paths = self._tree_selection.get_selected_rows()
# get all relat... | def get_view_selection(self) | Get actual tree selection object and all respective models of selected rows | 6.697413 | 5.595521 | 1.196924 |
sm_selection, sm_filtered_selected_model_set = self.get_state_machine_selection()
tree_selection, selected_model_list = self.get_view_selection()
return tree_selection, selected_model_list, sm_selection, sm_filtered_selected_model_set | def get_selections(self) | Get current model selection status in state machine selection (filtered according the purpose of the widget)
and tree selection of the widget | 5.119807 | 3.490244 | 1.466891 |
if self.CORE_ELEMENT_CLASS in signal_msg.arg.affected_core_element_classes:
self.update_selection_sm_prior() | def state_machine_selection_changed(self, state_machine_m, signal_name, signal_msg) | Notify tree view about state machine selection | 22.633049 | 23.24556 | 0.97365 |
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
self.on_add(None)
return True | def add_action_callback(self, *event) | Callback method for add action | 9.393428 | 9.904023 | 0.948446 |
if react_to_event(self.view, self.tree_view, event) and \
not (self.active_entry_widget and not is_event_of_key_string(event, 'Delete')):
self.on_remove(None)
return True | def remove_action_callback(self, *event) | Callback method for remove action
The method checks whether a shortcut ('Delete') is in the gui config model which shadow the delete functionality
of maybe active a entry widget. If a entry widget is active the remove callback return with None. | 10.405983 | 9.180543 | 1.133482 |
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
sm_selection, sm_selected_model_list = self.get_state_machine_selection()
# only list specific elements are copied by widget
if sm_selection is not None:
sm_sele... | def copy_action_callback(self, *event) | Callback method for copy action | 9.05398 | 9.150001 | 0.989506 |
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None:
sm_selection, sm_selected_model_list = self.get_state_machine_selection()
# only list specific elements are cut by widget
if sm_selection is not None:
sm_selecti... | def cut_action_callback(self, *event) | Callback method for copy action | 9.316975 | 9.528921 | 0.977758 |
current_row_path, current_focused_column = self.tree_view.get_cursor()
# print(current_row_path, current_focused_column)
if isinstance(widget, Gtk.TreeView) and not self.active_entry_widget: # avoid jumps for active entry widget
pass
# cursor motion/selection ch... | def tree_view_keypress_callback(self, widget, event) | General method to adapt widget view and controller behavior according the key press/release and
button release events
Here the scrollbar motion to follow key cursor motions in editable is already in.
:param Gtk.TreeView widget: The tree view the controller use
:param Gdk.Event even... | 5.102525 | 5.069104 | 1.006593 |
super(ListViewController, self).register_view(view)
self.tree_view.connect('button_press_event', self.mouse_click) | def register_view(self, view) | Register callbacks for button press events and selection changed | 5.843558 | 4.996548 | 1.169519 |
path_list = None
if self.view is not None:
model, path_list = self.tree_view.get_selection().get_selected_rows()
old_path = self.get_path()
models = [self.list_store[path][self.MODEL_STORAGE_ID] for path in path_list] if path_list else []
if models:
... | def on_remove(self, widget, data=None) | Removes respective selected core elements and select the next one | 4.303499 | 3.889465 | 1.10645 |
sm_selection = self.model.get_state_machine_m().selection if self.model.get_state_machine_m() else None
return sm_selection, sm_selection.get_selected_elements_of_core_class(self.CORE_ELEMENT_CLASS) if sm_selection else set() | def get_state_machine_selection(self) | An abstract getter method for state machine selection
The method maybe has to be re-implemented by inherit classes and hands generally a filtered set of
selected elements.
:return: selection object it self, filtered set of selected elements
:rtype: rafcon.gui.selection.Selection, set | 6.636998 | 5.440664 | 1.219887 |
if event.get_button()[1] == 1: # Left mouse button
path_info = self.tree_view.get_path_at_pos(int(event.x), int(event.y))
if path_info: # Valid entry was clicked on
path = path_info[0]
iter = self.list_store.get_iter(path)
model ... | def _handle_double_click(self, event) | Double click with left mouse button focuses the element | 4.889108 | 4.648222 | 1.051823 |
if self._do_selection_update:
return
self._do_selection_update = True
tree_selection, selected_model_list, sm_selection, sm_selected_model_list = self.get_selections()
if tree_selection is not None:
for path, row in enumerate(self.list_store):
... | def update_selection_sm_prior(self) | State machine prior update of tree selection | 2.667987 | 2.614482 | 1.020465 |
if self._do_selection_update:
return
self._do_selection_update = True
tree_selection, selected_model_list, sm_selection, sm_selected_model_list = self.get_selections()
if isinstance(sm_selection, Selection):
sm_selection.handle_prepared_selection_of_core_... | def update_selection_self_prior(self) | Tree view prior update of state machine selection | 5.941355 | 5.644749 | 1.052545 |
for row_num, element_row in enumerate(self.list_store):
# Compare data port ids
if element_row[self.ID_STORAGE_ID] == core_element_id:
if by_cursor:
self.tree_view.set_cursor(row_num)
else:
self.tree_view.ge... | def select_entry(self, core_element_id, by_cursor=True) | Selects the row entry belonging to the given core_element_id by cursor or tree selection | 4.24907 | 4.142933 | 1.025619 |
for row_num, element_row in enumerate(self.list_store):
# Compare data port ids
if element_row[self.ID_STORAGE_ID] == core_element_id:
return row_num, | def get_path_for_core_element(self, core_element_id) | Get path to the row representing core element described by handed core_element_id
:param core_element_id: Core element identifier used in the respective list store column
:rtype: tuple
:return: path | 8.966764 | 8.033739 | 1.116138 |
def iter_all_children(row_iter, function, function_args):
if isinstance(row_iter, Gtk.TreeIter):
function(row_iter, *function_args)
for n in reversed(range(self.tree_store.iter_n_children(row_iter))):
child_iter = self.tree_store.iter_nth_... | def iter_tree_with_handed_function(self, function, *function_args) | Iterate tree view with condition check function | 2.725703 | 2.692082 | 1.012489 |
selected_path = self.tree_store.get_path(state_row_iter)
tree_model_row = self.tree_store[selected_path]
model = tree_model_row[self.MODEL_STORAGE_ID]
if model not in sm_selected_model_list and model in selected_model_list:
self._tree_selection.unselect_iter(state_r... | def update_selection_sm_prior_condition(self, state_row_iter, selected_model_list, sm_selected_model_list) | State machine prior update of tree selection for one tree model row | 2.550776 | 2.325239 | 1.096995 |
selected_path = self.tree_store.get_path(state_row_iter)
tree_model_row = self.tree_store[selected_path]
model = tree_model_row[self.MODEL_STORAGE_ID]
if model in sm_selected_model_set and model not in selected_model_list:
sm_selected_model_set.remove(model)
... | def update_selection_self_prior_condition(self, state_row_iter, sm_selected_model_set, selected_model_list) | Tree view prior update of one model in the state machine selection | 2.343041 | 2.211264 | 1.059593 |
if self._do_selection_update:
return
self._do_selection_update = True
tree_selection, selected_model_list, sm_selection, sm_selected_model_set = self.get_selections()
if isinstance(sm_selection, Selection):
# current sm_selected_model_set will be updated ... | def update_selection_self_prior(self) | Tree view prior update of state machine selection | 10.39471 | 9.976997 | 1.041868 |
if self._do_selection_update:
return
self._do_selection_update = True
tree_selection, selected_model_list, sm_selection, sm_selected_model_list = self.get_selections()
if tree_selection is not None:
# self._logger.info("SM SELECTION IS: {2}\n{0}, \n{1}".f... | def update_selection_sm_prior(self) | State machine prior update of tree selection | 4.636228 | 4.527913 | 1.023922 |
path = self.get_path_for_core_element(core_element_id)
if path:
if by_cursor:
self.tree_view.set_cursor(path)
else:
self.tree_view.get_selection().select_path(path)
else:
self._logger.warning("Path not valid: {0} (by_cu... | def select_entry(self, core_element_id, by_cursor=True) | Selects the row entry belonging to the given core_element_id by cursor or tree selection | 2.6224 | 2.486602 | 1.054612 |
return isinstance(var, tuple) and len(var) == 2 and all(isinstance(val, (int, float)) for val in var) | def contains_geometric_info(var) | Check whether the passed variable is a tuple with two floats or integers | 2.884372 | 2.009351 | 1.435474 |
parent_size = parent_state_m.get_meta_data_editor()['size']
if not contains_geometric_info(parent_size):
raise ValueError("Invalid state size: {}".format(parent_size))
# use handed number of child states and otherwise take number of child states from parent state model
num_child_state = le... | def generate_default_state_meta_data(parent_state_m, canvas=None, num_child_state=None, gaphas_editor=True) | Generate default meta data for a child state according its parent state
The function could work with the handed num_child_state if all child state are not drawn, till now.
The method checks if the parents meta data is consistent in canvas state view and model if a canvas instance is
handed.
:param r... | 3.309534 | 3.111191 | 1.063751 |
# print("old boundary", left, right, top, bottom)
width = right - left
width = frame['size'][0] if width < frame['size'][0] else width
left -= 0.5 * clearance * width
left = 0 if left < 0 else left
right += 0.5 * clearance * width
height = bottom - top
height = frame['size'][1] if... | def add_boundary_clearance(left, right, top, bottom, frame, clearance=0.1) | Increase boundary size
The function increase the space between top and bottom and between left and right parameters.
The increase performed on the biggest size/frame so max(size boundary, size frame)
:param float left: lower x-axis value
:param float right: upper x-axis value
:param float top: low... | 1.925711 | 1.980811 | 0.972183 |
# print("parent_size ->", parent_size)
margin = cal_margin(parent_size)
# Add margin and ensure that the upper left corner is within the state
if group:
# frame of grouped state
rel_pos = max(left - margin, 0), max(top - margin, 0)
# Add margin and ensure that the lower righ... | def cal_frame_according_boundaries(left, right, top, bottom, parent_size, gaphas_editor=True, group=True) | Generate margin and relative position and size handed boundary parameter and parent size | 3.218989 | 3.072284 | 1.047751 |
# print("\n", "#"*30, "offset models", pos_offset, "#"*30)
# Update relative position of states within the container in order to maintain their absolute position
for child_state_m in models_dict['states'].values():
old_rel_pos = child_state_m.get_meta_data_editor(for_gaphas=gaphas_editor)['rel_... | def offset_rel_pos_of_all_models_in_dict(models_dict, pos_offset, gaphas_editor=True) | Add position offset to all handed models in dict | 2.469538 | 2.495083 | 0.989762 |
if state_m.meta_data_was_scaled:
return
state_m.income.set_meta_data_editor('rel_pos', state_m.state_copy.income.get_meta_data_editor()['rel_pos'])
# print("scale_library_ports_meta_data ", state_m.get_meta_data_editor()['size'], \)
# state_m.state_copy.get_meta_data_editor()['size']
... | def scale_library_ports_meta_data(state_m, gaphas_editor=True) | Scale the ports of library model accordingly relative to state_copy meta size.
The function assumes that the meta data of ports of the state_copy of the library was copied to
respective elements in the library and that those was not adjusted before. | 4.172741 | 3.839067 | 1.086916 |
assert isinstance(library_state_m, LibraryStateModel)
# For library states with an ExecutionState as state_copy, scaling does not make sense
if not isinstance(library_state_m.state_copy, ContainerStateModel):
return
# use same size for state copy and put rel_pos to zero
library_meta = ... | def scale_library_content(library_state_m, gaphas_editor=True) | Scales the meta data of the content of a LibraryState
The contents of the `LibraryStateModel` `library_state_m` (i.e., the `state_copy` and all it children/state
elements) to fit the current size of the `LibraryStateModel`.
:param LibraryStateModel library_state_m: The library who's content is to... | 5.058358 | 4.796364 | 1.054623 |
for port_m in port_models:
old_rel_pos = port_m.get_meta_data_editor(for_gaphas=gaphas_editor)[rel_pos_key]
port_m.set_meta_data_editor(rel_pos_key, mult_two_vectors(factor, old_rel_pos), from_gaphas=gaphas_editor) | def _resize_port_models_list(port_models, rel_pos_key, factor, gaphas_editor=True) | Resize relative positions a list of (data or logical) port models | 4.19843 | 4.106029 | 1.022504 |
for connection_m in connection_models:
# print("old_waypoints", connection_m.get_meta_data_editor(for_gaphas=gaphas_editor), connection_m.core_element)
old_waypoints = connection_m.get_meta_data_editor(for_gaphas=gaphas_editor)['waypoints']
new_waypoints = []
for waypoint in old... | def _resize_connection_models_list(connection_models, factor, gaphas_editor=True) | Resize relative positions of way points of a list of connection/linkage models | 3.331422 | 3.201525 | 1.040573 |
# print("scale ports", factor, state_m, gaphas_editor)
if not gaphas_editor and isinstance(state_m, ContainerStateModel):
port_models = state_m.input_data_ports[:] + state_m.output_data_ports[:] + state_m.scoped_variables[:]
else:
port_models = state_m.input_data_ports[:] + state_m.outp... | def resize_state_port_meta(state_m, factor, gaphas_editor=True) | Resize data and logical ports relative positions | 3.457237 | 3.423993 | 1.009709 |
# print("START RESIZE OF STATE", state_m.get_meta_data_editor(for_gaphas=gaphas_editor), state_m)
old_rel_pos = state_m.get_meta_data_editor(for_gaphas=gaphas_editor)['rel_pos']
# print("old_rel_pos state", old_rel_pos, state_m.core_element)
state_m.set_meta_data_editor('rel_pos', mult_two_vectors(... | def resize_state_meta(state_m, factor, gaphas_editor=True) | Resize state meta data recursive what includes also LibraryStateModels meta data and its internal state_copy | 2.231805 | 2.145092 | 1.040424 |
old_parent_rel_pos = models_dict['state'].get_meta_data_editor()['rel_pos']
offset_rel_pos_of_all_models_in_dict(models_dict, pos_offset=old_parent_rel_pos)
return True | def offset_rel_pos_of_models_meta_data_according_parent_state(models_dict) | Offset meta data of state elements according the area used indicated by the state meta data.
The offset_rel_pos_of_models_meta_data_according_parent_state offset the position of all handed old elements
in the dictionary.
:param models_dict: dict that hold lists of meta data with state attribute consistent... | 5.319411 | 7.329438 | 0.72576 |
left, right, top, bottom = get_boundaries_of_elements_in_dict(models_dict=models_dict)
parent_size = models_dict['state'].parent.get_meta_data_editor()['size']
_, rel_pos, size = cal_frame_according_boundaries(left, right, top, bottom, parent_size)
# Set size and position of new container state
... | def scale_meta_data_according_states(models_dict) | Offset meta data of state elements according the area used indicated by the states and
maybe scoped variables (in case of OpenGL editor) meta data.
Method is used by group states to set the offset for the elements in the new container state.
The method needs some generalisation to create methods to easily ... | 5.346093 | 5.206895 | 1.026733 |
if not state_m.parent:
logger.warning("A state can not have a closest sibling state if it has not parent as {0}".format(state_m))
return
margin = cal_margin(state_m.parent.get_meta_data_editor()['size'])
pos = state_m.get_meta_data_editor()['rel_pos']
size = state_m.get_meta_data_e... | def get_closest_sibling_state(state_m, from_logical_port=None) | Calculate the closest sibling also from optional logical port of handed state model
:param StateModel state_m: Reference State model the closest sibling state should be find for
:param str from_logical_port: The logical port of handed state model to be used as reference.
:rtype: tuple
:return: distance... | 3.194667 | 3.176892 | 1.005595 |
non_empty_lists_dict = {key: elems for key, elems in self.model_copies.items() if elems}
port_attrs = ['input_data_ports', 'output_data_ports', 'scoped_variables', 'outcomes']
port_is_pasted = any([key in non_empty_lists_dict for key in port_attrs])
return non_empty_lists_dict, ... | def get_action_arguments(self, target_state_m) | Collect argument attributes for action signal
Use non empty list dict to create arguments for action signal msg and logger messages. The action parent model
can be different then the target state model because logical and data port changes also may influence the
linkage, see action-module (undo... | 6.026086 | 5.282622 | 1.140738 |
assert isinstance(selection, Selection)
self.__create_core_and_model_object_copies(selection, smart_selection_adaption) | def copy(self, selection, smart_selection_adaption=True) | Copy all selected items to the clipboard using smart selection adaptation by default
:param selection: the current selection
:param bool smart_selection_adaption: flag to enable smart selection adaptation mode
:return: | 9.400084 | 11.919557 | 0.788627 |
assert isinstance(selection, Selection)
import rafcon.gui.helpers.state_machine as gui_helper_state_machine
if gui_helper_state_machine.is_selection_inside_of_library_state(selected_elements=selection.get_all()):
logger.warning("Cut is not performed because elements inside... | def cut(self, selection, smart_selection_adaption=False) | Cuts all selected items and copy them to the clipboard using smart selection adaptation by default
:param selection: the current selection
:param bool smart_selection_adaption: flag to enable smart selection adaptation mode
:return: | 5.293198 | 5.3654 | 0.986543 |
# reset selections
for state_element_attr in ContainerState.state_element_attrs:
self.model_copies[state_element_attr] = []
# reset parent state_id the copied elements are taken from
self.copy_parent_state_id = None
self.reset_clipboard_mapping_dicts() | def reset_clipboard(self) | Resets the clipboard, so that old elements do not pollute the new selection that is copied into the
clipboard.
:return: | 12.767175 | 13.68332 | 0.933047 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.