code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
refresh_required = self.core_config_model.apply_preliminary_config() refresh_required |= self.gui_config_model.apply_preliminary_config() if not self.gui_config_model.config.get_config_value("SESSION_RESTORE_ENABLED"): import rafcon.gui.backup.session as backup_session ...
def _on_apply_button_clicked(self, *args)
Apply button clicked: Apply the configuration
6.223845
5.950992
1.04585
old_library_name = self.library_list_store[int(path)][self.KEY_STORAGE_ID] if old_library_name == new_library_name: return library_path = self.library_list_store[int(path)][self.VALUE_STORAGE_ID] library_config = self.core_config_model.get_current_config_value("LIBR...
def _on_library_name_changed(self, renderer, path, new_library_name)
Callback handling a change of a library name :param Gtk.CellRenderer renderer: Cell renderer showing the library name :param path: Path of library within the list store :param str new_library_name: New library name
3.363974
3.358936
1.0015
library_name = self.library_list_store[int(path)][self.KEY_STORAGE_ID] library_config = self.core_config_model.get_current_config_value("LIBRARY_PATHS", use_preliminary=True, default={}) library_config[library_nam...
def _on_library_path_changed(self, renderer, path, new_library_path)
Callback handling a change of a library path :param Gtk.CellRenderer renderer: Cell renderer showing the library path :param path: Path of library within the list store :param str new_library_path: New library path
4.393106
4.410828
0.995982
action = self.shortcut_list_store[int(path)][self.KEY_STORAGE_ID] old_shortcuts = self.gui_config_model.get_current_config_value("SHORTCUTS", use_preliminary=True)[action] from ast import literal_eval try: new_shortcuts = literal_eval(new_shortcuts) if n...
def _on_shortcut_changed(self, renderer, path, new_shortcuts)
Callback handling a change of a shortcut :param Gtk.CellRenderer renderer: Cell renderer showing the shortcut :param path: Path of shortcuts within the list store :param str new_shortcuts: New shortcuts
3.499081
3.367236
1.039155
config_key = list_store[int(path)][self.KEY_STORAGE_ID] old_value = config_m.get_current_config_value(config_key, use_preliminary=True) if old_value == new_value: return # Try to maintain the correct data type, which is extracted from the old value if isins...
def _on_config_value_changed(self, renderer, path, new_value, config_m, list_store)
Callback handling a change of a config value :param Gtk.CellRenderer renderer: Cell renderer showing the shortcut :param path: Path of shortcuts within the list store :param ConfigModel config_m: The config model that is to be changed :param Gtk.ListStore list_store: The list store that...
2.42375
2.532436
0.957082
dialog = Gtk.Dialog(title_text, self.view["preferences_window"], flags=0, buttons= (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)) label = Gtk.Label(label=description) ...
def _config_chooser_dialog(self, title_text, description)
Dialog to select which config shall be exported :param title_text: Title text :param description: Description
2.222763
2.362332
0.940919
for key, value in dict_to_check.items(): if object_to_check is value: return True return False
def check_if_dict_contains_object_reference_in_values(object_to_check, dict_to_check)
Method to check if an object is inside the values of a dict. A simple object_to_check in dict_to_check.values() does not work as it uses the __eq__ function of the object and not the object reference. :param object_to_check: The target object. :param dict_to_check: The dict to search in. :return:
2.55808
3.140399
0.814572
super(StateDataFlowsListController, self).register_view(view) def cell_text(column, cell_renderer, model, iter, container_model): df_id = model.get_value(iter, self.ID_STORAGE_ID) in_external = 'external' if model.get_value(iter, self.IS_EXTERNAL_STORAGE_ID) else 'inter...
def register_view(self, view)
Called when the View was registered
2.066969
2.060462
1.003158
assert model.data_flow.parent is self.model.state or model.data_flow.parent is self.model.parent.state gui_helper_state_machine.delete_core_element_of_model(model)
def remove_core_element(self, model)
Remove respective core element of handed data flow model :param DataFlowModel model: Data Flow model which core element should be removed :return:
11.193481
10.059389
1.11274
super(StateDataFlowsEditorController, self).register_view(view) view['add_d_button'].connect('clicked', self.df_list_ctrl.on_add) view['remove_d_button'].connect('clicked', self.df_list_ctrl.on_remove) view['connected_to_d_checkbutton'].connect('toggled', self.toggled_button, 'd...
def register_view(self, view)
Called when the View was registered Can be used e.g. to connect signals. Here, the destroy signal is connected to close the application
2.788078
2.88951
0.964897
# load default input data for the state self._root_state.input_data = self._root_state.get_default_input_values_for_state(self._root_state) self._root_state.output_data = self._root_state.create_output_dictionary_for_state(self._root_state) new_execution_history = self._add_new_...
def start(self)
Starts the execution of the root state.
4.690015
4.170424
1.12459
self._root_state.join() # execution finished, close execution history log file (if present) if len(self._execution_histories) > 0: if self._execution_histories[-1].execution_history_storage is not None: set_read_and_writable_for_all = global_config.get_config...
def join(self)
Wait for root state to finish execution
5.126686
4.563489
1.123414
state_v = self.parent center = self.handle.pos margin = self.port_side_size / 4. if self.side in [SnappedSide.LEFT, SnappedSide.RIGHT]: height, width = self.port_size else: width, height = self.port_size upper_left = center[0] - width / 2 ...
def get_port_area(self, view)
Calculates the drawing area affected by the (hovered) port
2.501362
2.403247
1.040826
c = context width, height = self.port_size c.set_line_width(self.port_side_size * 0.03 * self._port_image_cache.multiplicator) # Save/restore context, as we move and rotate the connector to the desired pose c.save() c.rel_move_to(self.port_side_size / 2., self....
def _draw_simple_state_port(self, context, direction, color, transparency)
Draw the port of a simple state (ExecutionState, LibraryState) Connector for execution states can only be connected to the outside. Thus the connector fills the whole border of the state. :param context: Cairo context :param direction: The direction the port is pointing to :par...
5.181937
5.368675
0.965217
c = context width, height = self.port_size c.set_line_width(self.port_side_size / constants.BORDER_WIDTH_OUTLINE_WIDTH_FACTOR * self._port_image_cache.multiplicator) # Save/restore context, as we move and rotate the connector to the desired pose ...
def _draw_container_state_port(self, context, direction, color, transparency)
Draw the port of a container state Connector for container states are split in an inner connector and an outer connector. :param context: Cairo context :param direction: The direction the port is pointing to :param color: Desired color of the port :param float transparency: The...
2.897928
2.877116
1.007234
c = context # Current pos is center # Arrow is drawn upright arrow_height = height / 2.0 # First move to bottom left corner c.rel_move_to(-width / 2., height / 2.) # Draw line to bottom right corner c.rel_line_to(width, 0) # Draw line to...
def _draw_single_connector(context, width, height)
Draw the connector for execution states Connector for execution states can only be connected to the outside. Thus the connector fills the whole border of the state. :param context: Cairo context :param float port_size: The side length of the port
3.530272
3.762968
0.938162
c = context # Current pos is center # Arrow is drawn upright gap = height / 6. connector_height = (height - gap) / 2. # First move to bottom left corner c.rel_move_to(-width / 2., height / 2.) # Draw inner connector (rectangle) c.rel_li...
def _draw_inner_connector(context, width, height)
Draw the connector for container states Connector for container states can be connected from the inside and the outside. Thus the connector is split in two parts: A rectangle on the inside and an arrow on the outside. This methods draws the inner rectangle. :param context: Cairo context ...
4.374054
4.635714
0.943556
c = context # Current pos is center # Arrow is drawn upright arrow_height = height / 2.5 gap = height / 6. connector_height = (height - gap) / 2. # Move to bottom left corner of outer connector c.rel_move_to(-width / 2., -gap / 2.) # Dr...
def _draw_outer_connector(context, width, height)
Draw the outer connector for container states Connector for container states can be connected from the inside and the outside. Thus the connector is split in two parts: A rectangle on the inside and an arrow on the outside. This method draws the outer arrow. :param context: Cairo context ...
3.654794
3.822615
0.956098
c = context # First move to upper left corner c.rel_move_to(-width / 2., -height / 2.) # Draw closed rectangle c.rel_line_to(width, 0) c.rel_line_to(0, height) c.rel_line_to(-width, 0) c.close_path()
def _draw_rectangle(context, width, height)
Draw a rectangle Assertion: The current point is the center point of the rectangle :param context: Cairo context :param width: Width of the rectangle :param height: Height of the rectangle
2.784002
2.964811
0.939015
if direction is Direction.UP: pass elif direction is Direction.RIGHT: context.rotate(deg2rad(90)) elif direction is Direction.DOWN: context.rotate(deg2rad(180)) elif direction is Direction.LEFT: context.rotate(deg2rad(-90))
def _rotate_context(context, direction)
Moves the current position to 'position' and rotates the context according to 'direction' :param context: Cairo context :param direction: Direction enum
2.084343
2.206786
0.944515
c = context cairo_context = c if isinstance(c, CairoBoundingBoxContext): cairo_context = c._cairo # c.set_antialias(Antialias.GOOD) side_length = self.port_side_size layout = PangoCairo.create_layout(cairo_context) font_name = constants.INTE...
def draw_name(self, context, transparency, only_calculate_size=False)
Draws the name of the port Offers the option to only calculate the size of the name. :param context: The context to draw on :param transparency: The transparency of the text :param only_calculate_size: Whether to only calculate the size :return: Size of the name :rtype:...
3.490672
3.414052
1.022443
c = context # Current position is the center of the rectangle c.save() if self.side is SnappedSide.LEFT or self.side is SnappedSide.RIGHT: c.rotate(deg2rad(90)) c.rel_move_to(-width / 2., - height / 2.) c.rel_line_to(width, 0) c.rel_line_to(0...
def _draw_rectangle_path(self, context, width, height, only_get_extents=False)
Draws the rectangle path for the port The rectangle is correctly rotated. Height therefore refers to the border thickness and width to the length of the port. :param context: The context to draw on :param float width: The width of the rectangle :param float height: The height o...
2.78568
2.968282
0.938482
x, y = self.pos.x.value, self.pos.y.value if self.side is SnappedSide.TOP or self.side is SnappedSide.BOTTOM: if x - width / 2. < 0: x = width / 2 elif x + width / 2. > self.parent.width: x = self.parent.width - width / 2. else: ...
def _get_port_center_position(self, width)
Calculates the center position of the port rectangle The port itself can be positioned in the corner, the center of the port rectangle however is restricted by the width of the rectangle. This method therefore calculates the center, depending on the position of the port and the width of the rec...
1.975249
1.964618
1.005411
shortcut_manager.add_callback_for_action('rename', self.rename_selected_state) super(StatesEditorController, self).register_actions(shortcut_manager)
def register_actions(self, shortcut_manager)
Register callback methods for triggered actions :param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings between shortcuts and actions.
7.63071
6.763172
1.128274
config_key = info['args'][1] # config_value = info['args'][2] if config_key == "SOURCE_EDITOR_STYLE": self.reload_style()
def on_config_value_changed(self, config_m, prop_name, info)
Callback when a config value has been changed :param ConfigModel config_m: The config model that has been changed :param str prop_name: Should always be 'config' :param dict info: Information e.g. about the changed config key
7.82051
10.05301
0.777927
page_id = self.view.notebook.get_current_page() if page_id == -1: return None page = self.view.notebook.get_nth_page(page_id) state_identifier = self.get_state_identifier_for_page(page) return self.tabs[state_identifier]['state_m']
def get_current_state_m(self)
Returns the state model of the currently open tab
3.600548
3.188548
1.129212
if self.current_state_machine_m is not None: selection = self.current_state_machine_m.selection if len(selection.states) > 0: self.activate_state_tab(selection.get_selected_state())
def state_machine_manager_notification(self, model, property, info)
Triggered whenever a new state machine is created, or an existing state machine is selected.
5.576884
5.050957
1.104124
tabs_to_close = [] for state_identifier, tab_dict in list(self.tabs.items()): if tab_dict['sm_id'] not in self.model.state_machine_manager.state_machines: tabs_to_close.append(state_identifier) for state_identifier, tab_dict in list(self.closed_tabs.items()):...
def clean_up_tabs(self)
Method remove state-tabs for those no state machine exists anymore.
2.53805
2.204739
1.15118
if info['method_name'] == '__setitem__': state_machine_m = info.args[1] self.observe_model(state_machine_m)
def state_machines_set_notification(self, model, prop_name, info)
Observe all open state machines and their root states
8.18209
7.564607
1.081628
if info['method_name'] == '__delitem__': state_machine_m = info["result"] try: self.relieve_model(state_machine_m) except KeyError: pass self.clean_up_tabs()
def state_machines_del_notification(self, model, prop_name, info)
Relive models of closed state machine
8.918965
7.322429
1.218034
state_identifier = self.get_state_identifier(state_m) if state_identifier in self.closed_tabs: state_editor_ctrl = self.closed_tabs[state_identifier]['controller'] state_editor_view = state_editor_ctrl.view handler_id = self.closed_tabs[state_identifier]['so...
def add_state_editor(self, state_m)
Triggered whenever a state is selected. :param state_m: The selected state model.
3.464252
3.52117
0.983835
state_identifier = self.get_state_identifier(state_m) if state_identifier in self.tabs: tab_list = self.tabs elif state_identifier in self.closed_tabs: tab_list = self.closed_tabs else: logger.warning('It was tried to check a source script of...
def script_text_changed(self, text_buffer, state_m)
Update gui elements according text buffer changes Checks if the dirty flag needs to be set and the tab label to be updated. :param TextBuffer text_buffer: Text buffer of the edited script :param rafcon.gui.models.state.StateModel state_m: The state model related to the text buffer :ret...
3.77999
3.755959
1.006398
# logger.info("destroy page %s" % tab_dict['controller'].model.state.get_path()) if tab_dict['source_code_changed_handler_id'] is not None: handler_id = tab_dict['source_code_changed_handler_id'] if tab_dict['controller'].view.source_view.get_buffer().handler_is_connecte...
def destroy_page(self, tab_dict)
Destroys desired page Disconnects the page from signals and removes interconnection to parent-controller or observables. :param tab_dict: Tab-dictionary that holds all necessary information of a page and state-editor.
4.103363
4.107583
0.998973
# delete old controller references if delete and state_identifier in self.closed_tabs: self.destroy_page(self.closed_tabs[state_identifier]) del self.closed_tabs[state_identifier] # check for open page of state if state_identifier in self.tabs: ...
def close_page(self, state_identifier, delete=True)
Closes the desired page The page belonging to the state with the specified state_identifier is closed. If the deletion flag is set to False, the controller of the page is stored for later usage. :param state_identifier: Identifier of the page's state :param delete: Whether to delete th...
3.414668
3.316875
1.029483
for state_identifier, page_info in list(self.tabs.items()): if page_info['state_m'] is state_m: return page_info['page'], state_identifier return None, None
def find_page_of_state_m(self, state_m)
Return the identifier and page of a given state model :param state_m: The state model to be searched :return: page containing the state and the state_identifier
4.331541
3.999563
1.083003
[page, state_identifier] = self.find_page_of_state_m(state_m) if page: self.close_page(state_identifier, delete=False)
def on_tab_close_clicked(self, event, state_m)
Triggered when the states-editor close button is clicked Closes the tab. :param state_m: The desired state model (the selected state)
6.912268
9.219593
0.749737
[page, state_identifier] = self.find_page_of_state_m(state_m) if not page: return self.tabs[state_identifier]['is_sticky'] = not self.tabs[state_identifier]['is_sticky'] page.sticky_button.set_active(self.tabs[state_identifier]['is_sticky'])
def on_toggle_sticky_clicked(self, event, state_m)
Callback for the "toggle-sticky-check-button" emitted by custom TabLabel widget.
3.589506
3.345207
1.073029
states_to_be_closed = [] for state_identifier in self.tabs: states_to_be_closed.append(state_identifier) for state_identifier in states_to_be_closed: self.close_page(state_identifier, delete=False)
def close_all_pages(self)
Closes all tabs of the states editor
3.610941
2.94552
1.22591
states_to_be_closed = [] for state_identifier in self.tabs: state_m = self.tabs[state_identifier]["state_m"] if state_m.state.get_state_machine().state_machine_id == sm_id: states_to_be_closed.append(state_identifier) for state_identifier in state...
def close_pages_for_specific_sm_id(self, sm_id)
Closes all tabs of the states editor for a specific sm_id
3.110053
2.782727
1.117628
page = notebook.get_nth_page(page_num) # find state of selected tab for tab_info in list(self.tabs.values()): if tab_info['page'] is page: state_m = tab_info['state_m'] sm_id = state_m.state.get_state_machine().state_machine_id ...
def on_switch_page(self, notebook, page_pointer, page_num, user_param1=None)
Update state selection when the active tab was changed
4.02425
3.813593
1.055238
# The current shown state differs from the desired one current_state_m = self.get_current_state_m() if current_state_m is not state_m: state_identifier = self.get_state_identifier(state_m) # The desired state is not open, yet if state_identifier not ...
def activate_state_tab(self, state_m)
Opens the tab for the specified state model The tab with the given state model is opened or set to foreground. :param state_m: The desired state model (the selected state)
4.031179
4.044315
0.996752
# Only if the user didn't deactivate this behaviour if not global_gui_config.get_config_value('KEEP_ONLY_STICKY_STATES_OPEN', True): return page_id = self.view.notebook.get_current_page() # No tabs are open if page_id == -1: return page ...
def keep_only_sticked_and_selected_tabs(self)
Close all tabs, except the currently active one and all sticked ones
3.287895
3.159964
1.040485
if model is not self.current_state_machine_m or len(self.current_state_machine_m.ongoing_complex_actions) > 0: return state_machine_m = model assert isinstance(state_machine_m.selection, Selection) if len(state_machine_m.selection.states) == 1 and len(state_machine_m...
def selection_notification(self, model, property, info)
If a single state is selected, open the corresponding tab
4.303152
3.95606
1.087737
# avoid updates or checks because of execution status updates if is_execution_status_update_notification_from_state_machine_model(prop_name, info): return overview = NotificationOverview(info, False, self.__class__.__name__) changed_model = overview['model'][-1] ...
def notify_state_name_change(self, model, prop_name, info)
Checks whether the name of a state was changed and change the tab label accordingly
9.614471
8.658356
1.110427
state_identifier = self.get_state_identifier(state_m) if state_identifier not in self.tabs and state_identifier not in self.closed_tabs: return tab_info = self.tabs[state_identifier] if state_identifier in self.tabs else self.closed_tabs[state_identifier] page = tab_...
def update_tab_label(self, state_m)
Update all tab labels :param rafcon.state_machine.states.state.State state_m: State model who's tab label is to be updated
3.672212
3.975778
0.923646
for identifier, page_info in list(self.tabs.items()): if page_info["page"] is page: # reference comparison on purpose return identifier
def get_state_identifier_for_page(self, page)
Return the state identifier for a given page
9.670745
8.561078
1.129618
selection = self.current_state_machine_m.selection if len(selection.states) == 1 and len(selection) == 1: selected_state = selection.get_selected_state() self.activate_state_tab(selected_state) _, state_identifier = self.find_page_of_state_m(selected_state) ...
def rename_selected_state(self, key_value, modifier_mask)
Callback method for shortcut action rename Searches for a single selected state model and open the according page. Page is created if it is not existing. Then the rename method of the state controller is called. :param key_value: :param modifier_mask:
5.602394
5.648518
0.991834
semantic_data_id_counter = -1 while True: semantic_data_id_counter += 1 if "semantic data key " + str(semantic_data_id_counter) not in used_semantic_keys: break return "semantic data key " + str(semantic_data_id_counter)
def generate_semantic_data_key(used_semantic_keys)
Create a new and unique semantic data key :param list used_semantic_keys: Handed list of keys already in use :rtype: str :return: semantic_data_id
2.379038
2.461093
0.966659
new_state_id = ''.join(random.choice(chars) for x in range(size)) while used_state_ids is not None and new_state_id in used_state_ids: new_state_id = ''.join(random.choice(chars) for x in range(size)) return new_state_id
def state_id_generator(size=STATE_ID_LENGTH, chars=string.ascii_uppercase, used_state_ids=None)
Create a new and unique state id Generates an id for a state. It randomly samples from random ascii uppercase letters size times and concatenates them. If the id already exists it draws a new one. :param size: the length of the generated keys :param chars: the set of characters a sample draws from ...
1.56592
1.714835
0.913161
new_global_variable_id = ''.join(random.choice(chars) for x in range(size)) while new_global_variable_id in used_global_variable_ids: new_global_variable_id = ''.join(random.choice(chars) for x in range(size)) used_global_variable_ids.append(new_global_variable_id) return new_global_variabl...
def global_variable_id_generator(size=10, chars=string.ascii_uppercase)
Create a new and unique global variable id Generates an id for a global variable. It randomly samples from random ascii uppercase letters size times and concatenates them. If the id already exists it draws a new one. :param size: the length of the generated keys :param chars: the set of characters a s...
1.491206
1.742993
0.855544
glColor4f(self.r, self.g, self.b, self.a)
def set(self)
Set the color as current OpenGL color
4.165053
2.525102
1.64946
# Obtain a reference to the OpenGL drawable # and rendering context. gldrawable = self.get_gl_drawable() glcontext = self.get_gl_context() # logger.debug("configure") # OpenGL begin if not gldrawable or not gldrawable.gl_begin(glcontext): ret...
def _configure(self, *args)
Configure viewport This method is called when the widget is resized or something triggers a redraw. The method configures the view to show all elements in an orthogonal perspective.
3.97844
3.626659
1.096998
left, right, _, _ = self.get_view_coordinates() width = right - left display_width = self.get_allocation().width return display_width / float(width)
def pixel_to_size_ratio(self)
Calculates the ratio between pixel and OpenGL distances OpenGL keeps its own coordinate system. This method can be used to transform between pixel and OpenGL coordinates. :return: pixel/size ratio
5.92576
7.105135
0.834011
# Obtain a reference to the OpenGL drawable # and rendering context. gldrawable = self.get_gl_drawable() glcontext = self.get_gl_context() # OpenGL begin if not gldrawable or not gldrawable.gl_begin(glcontext): return False # logger.debug("e...
def expose_init(self, *args)
Process the drawing routine
5.272615
5.092952
1.035277
# Obtain a reference to the OpenGL drawable # and rendering context. gldrawable = self.get_gl_drawable() # glcontext = self.get_gl_context() if not gldrawable: return # Put the buffer on the screen! if gldrawable.is_double_buffered(): ...
def expose_finish(self, *args)
Finish drawing process
5.350825
5.07171
1.055034
if not waypoints: waypoints = [] # "Generate" unique ID for each object id = self.name_counter self.name_counter += 1 glPushName(id) self._set_closest_stroke_width(width) color = self.transition_color if not selected else self.transition_sel...
def draw_transition(self, from_pos, to_pos, width, waypoints=None, selected=False, depth=0)
Draw a state with the given properties This method is called by the controller to draw the specified transition. :param tuple from_pos: Starting position :param tuple to_pos: Ending position :param float width: A measure for the width of a transition line :param list waypoints:...
4.112155
4.089287
1.005592
stroke_width = height / 8. if bold: stroke_width = height / 5. color.set() self._set_closest_stroke_width(stroke_width) glMatrixMode(GL_MODELVIEW) glPushMatrix() pos_y -= height if not align_right: glTranslatef(pos_x, pos_y...
def _write_string(self, string, pos_x, pos_y, height, color, bold=False, align_right=False, depth=0.)
Write a string Writes a string with a simple OpenGL method in the given size at the given position. :param string: The string to draw :param pos_x: x starting position :param pos_y: y starting position :param height: desired height :param bold: flag whether to use a bol...
3.268149
3.388632
0.964445
glSelectBuffer(self.name_counter * 6) viewport = glGetInteger(GL_VIEWPORT) glMatrixMode(GL_PROJECTION) glPushMatrix() glRenderMode(GL_SELECT) glLoadIdentity() if width < 1: width = 1 if height < 1: height = 1 po...
def prepare_selection(self, pos_x, pos_y, width, height)
Prepares the selection rendering In order to find out the object being clicked on, the scene has to be rendered again around the clicked position :param pos_x: x coordinate :param pos_y: y coordinate
4.160958
4.445416
0.936011
hits = glRenderMode(GL_RENDER) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) return hits
def find_selection()
Finds the selected ids After the scene has been rendered again in selection mode, this method gathers and returns the ids of the selected object and restores the matrices. :return: The selection stack
4.114277
4.974849
0.827015
# Adapt line width to zooming level width *= self.pixel_to_size_ratio() / 6. stroke_width_range = glGetFloatv(GL_LINE_WIDTH_RANGE) stroke_width_granularity = glGetFloatv(GL_LINE_WIDTH_GRANULARITY) if width < stroke_width_range[0]: glLineWidth(stroke_width_r...
def _set_closest_stroke_width(self, width)
Sets the line width to the closest supported one Not all line widths are supported. This function queries both minimum and maximum as well as the step size of the line width and calculates the width, which is closest to the given one. This width is then set. :param width: The desired line widt...
3.070551
3.411148
0.900152
visible = False # Check whether circle center is in the viewport if not self.point_outside_view((pos_x, pos_y)): visible = True # Check whether at least on point on the border of the circle is within the viewport if not visible: for i in range(0,...
def _draw_circle(self, pos_x, pos_y, radius, depth, stroke_width=1., fill_color=None, border_color=None, from_angle=0., to_angle=2 * pi)
Draws a circle Draws a circle with a line segment a desired position with desired size. :param float pos_x: Center x position :param float pos_y: Center y position :param float depth: The Z layer :param float radius: Radius of the circle
2.60751
2.700736
0.965481
left, right, bottom, top = self.get_view_coordinates() glOrtho(left, right, bottom, top, -10, 0)
def _apply_orthogonal_view(self)
Orthogonal view with respect to current aspect ratio
4.769867
4.458532
1.069829
if how == 'daily': hours = 24 if how == 'weekly': hours = 168 aggregation = tsam.TimeSeriesAggregation( timeseries_df, noTypicalPeriods=typical_periods, rescaleClusterPeriods=False, hoursPerPeriod=hours, clusterMethod='hierarchical') timese...
def tsam_cluster(timeseries_df, typical_periods=10, how='daily')
Parameters ---------- df : pd.DataFrame DataFrame with timeseries to cluster Returns ------- timeseries : pd.DataFrame Clustered timeseries
5.393949
5.563223
0.969573
network.snapshot_weightings = network.snapshot_weightings.loc[dates] network.snapshots = network.snapshot_weightings.index # set new snapshot weights from cluster_weights snapshot_weightings = [] for i in cluster_weights.values(): x = 0 while x < hours: snapshot_wei...
def update_data_frames(network, cluster_weights, dates, hours)
Updates the snapshots, snapshots weights and the dataframes based on the original data in the network and the medoids created by clustering these original data. Parameters ----------- network : pyPSA network object cluster_weights: dictionary dates: Datetimeindex Returns ------- ...
3.20695
3.442115
0.93168
sus = network.storage_units # take every first hour of the clustered days network.model.period_starts = network.snapshot_weightings.index[0::24] network.model.storages = sus.index def day_rule(m, s, p): return ( m.state_of_charge[s, p] == m.state...
def daily_bounds(network, snapshots)
This will bound the storage level to 0.5 max_level every 24th hour.
7.49559
6.975823
1.07451
if os.environ.get("RAFCON_CHECK_INSTALLATION", False) == "True": rafcon_root = os.path.dirname(rafcon.__file__) installation.assets_folder = os.path.join(rafcon_root, 'gui', 'assets') installation.share_folder = os.path.join(os.path.dirname(os.path.dirname(rafcon_root)), 'share') ...
def setup_installation()
Install necessary GUI resources By default, RAFCON should be installed via `setup.py` (`pip install rafcon`). Thereby, all resources are being installed. However, if this is not the case, one can set the `RAFCON_CHECK_INSTALLATION` env variable to `True`. Then, the installation will be performed befo...
4.522538
3.288424
1.375291
default_config_path = filesystem.get_default_config_path() filesystem.create_path(default_config_path) parser = core_singletons.argument_parser parser.add_argument('-n', '--new', action='store_true', help=_("whether to create a new state-machine")) parser.add_argument('-o', '--open', action='s...
def setup_argument_parser()
Sets up teh parser with the required arguments :return: The parser object
3.274115
3.314132
0.987925
super(ScopedVariableListController, self).register_view(view) view['name_col'].add_attribute(view['name_text'], 'text', self.NAME_STORAGE_ID) if not isinstance(self.model.state, LibraryState) and self.model.state.get_next_upper_library_root_state() is None: view['name_text'...
def register_view(self, view)
Called when the View was registered
2.591107
2.581347
1.003781
shortcut_manager.add_callback_for_action("delete", self.remove_action_callback) shortcut_manager.add_callback_for_action("add", self.add_action_callback) shortcut_manager.add_callback_for_action("copy", self.copy_action_callback) shortcut_manager.add_callback_for_action("cut", s...
def register_actions(self, shortcut_manager)
Register callback methods for triggered actions :param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings between shortcuts and actions.
1.867138
1.766154
1.057177
if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None: if not global_clipboard.model_copies["scoped_variables"] and \ (global_clipboard.model_copies["input_data_ports"] or global_clipboard.model_copies["output_data_...
def paste_action_callback(self, *event)
Callback method for paste action The method trigger the clipboard paste of the list of scoped variables in the clipboard or in case this list is empty and there are other port types selected in the clipboard it will trigger the paste with convert flag. The convert flag will cause the inserti...
6.98951
5.800163
1.205054
if isinstance(self.model, ContainerStateModel): try: scoped_var_ids = gui_helper_state_machine.add_scoped_variable_to_selected_states(selected_states=[self.model]) if scoped_var_ids: self.select_entry(scoped_var_ids[self.model.state]) ...
def on_add(self, widget, data=None)
Create a new scoped variable with default values
6.979266
6.048639
1.153857
assert model.scoped_variable.parent is self.model.state gui_helper_state_machine.delete_core_element_of_model(model)
def remove_core_element(self, model)
Remove respective core element of handed scoped variable model :param ScopedVariableModel model: Scoped variable model which core element should be removed :return:
25.168547
17.780899
1.415482
data_port_id = self.list_store[path][self.ID_STORAGE_ID] try: if self.model.state.scoped_variables[data_port_id].name != new_name: self.model.state.scoped_variables[data_port_id].name = new_name except TypeError as e: logger.error("Error while cha...
def apply_new_scoped_variable_name(self, path, new_name)
Applies the new name of the scoped variable defined by path :param str path: The path identifying the edited variable :param str new_name: New name
4.505025
5.177615
0.870097
data_port_id = self.list_store[path][self.ID_STORAGE_ID] try: if self.model.state.scoped_variables[data_port_id].data_type.__name__ != new_variable_type_str: self.model.state.scoped_variables[data_port_id].change_data_type(new_variable_type_str) except ValueE...
def apply_new_scoped_variable_type(self, path, new_variable_type_str)
Applies the new data type of the scoped variable defined by path :param str path: The path identifying the edited variable :param str new_variable_type_str: New data type as str
3.722109
3.866957
0.962542
data_port_id = self.get_list_store_row_from_cursor_selection()[self.ID_STORAGE_ID] try: if str(self.model.state.scoped_variables[data_port_id].default_value) != new_default_value_str: self.model.state.scoped_variables[data_port_id].default_value = new_default_value_s...
def apply_new_scoped_variable_default_value(self, path, new_default_value_str)
Applies the new default value of the scoped variable defined by path :param str path: The path identifying the edited variable :param str new_default_value_str: New default value as string
4.323805
4.608503
0.938223
if isinstance(self.model, ContainerStateModel): tmp = self.get_new_list_store() for sv_model in self.model.scoped_variables: data_type = sv_model.scoped_variable.data_type # get name of type (e.g. ndarray) data_type_name = data_ty...
def reload_scoped_variables_list_store(self)
Reloads the scoped variable list store from the data port models
3.398252
3.306623
1.027711
from rafcon.gui.singleton import state_machine_manager_model, global_runtime_config from rafcon.gui.models.auto_backup import AutoBackupModel from rafcon.gui.models import AbstractStateModel from rafcon.gui.singleton import main_window_controller # check if there are dirty state machines -> use...
def store_session()
Stores reference backup information for all open tabs into runtime config The backup of never stored tabs (state machines) and not stored state machine changes will be triggered a last time to secure data lose.
4.525039
4.282642
1.0566
if not method_name: method_name = level_name.lower() if hasattr(logging, level_name): raise AttributeError('{} already defined in logging module'.format(level_name)) if hasattr(logging, method_name): raise AttributeError('{} already defined in logging module'.format(method_name...
def add_logging_level(level_name, level_num, method_name=None)
Add new logging level Comprehensively adds a new logging level to the `logging` module and the currently configured logging class. `method_name` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()` (usually just `logging.Logger`). If `method_name` is ...
1.292507
1.525426
0.847309
if name in existing_loggers: return existing_loggers[name] # Ensure that all logger are within the RAFCON root namespace namespace = name if name.startswith(rafcon_root + ".") else rafcon_root + "." + name logger = logging.getLogger(namespace) logger.propagate = True existing_logge...
def get_logger(name)
Returns a logger for the given name The function is basically a wrapper for logging.getLogger and only ensures that the namespace is within "rafcon." and that the propagation is enabled. :param str name: The namespace of the new logger :return: Logger object with given namespace :rtype: logging.Lo...
4.778547
3.337781
1.431654
start_time = time.time() if path is None: if interface.open_folder_func is None: logger.error("No function defined for opening a folder") return load_path = interface.open_folder_func("Please choose the folder of the state machine") if load_path is None: ...
def open_state_machine(path=None, recent_opened_notification=False)
Open a state machine from respective file system path :param str path: file system path to the state machine :param bool recent_opened_notification: flags that indicates that this call also should update recently open :rtype rafcon.core.state_machine.StateMachine :return: opened state machine
3.395712
3.318293
1.023331
state_machine_manager_model = rafcon.gui.singleton.state_machine_manager_model selected_state_machine_model = state_machine_manager_model.get_selected_state_machine_model() if selected_state_machine_model is None: logger.warning("Can not 'save state machine as' because no state machine is sele...
def save_state_machine_as(path=None, recent_opened_notification=False, as_copy=False)
Store selected state machine to path If there is no handed path the interface dialog "create folder" is used to collect one. The state machine finally is stored by the save_state_machine function. :param str path: Path of state machine folder where selected state machine should be stored :param bool...
3.229078
3.060852
1.054961
# check if the/a state machine is still running if not state_machine_execution_engine.finished_or_stopped(): if selected_sm_id is None or selected_sm_id == state_machine_manager.active_state_machine_id: message_string = "A state machine is still running. This state machine can only be ...
def is_state_machine_stopped_to_proceed(selected_sm_id=None, root_window=None)
Check if state machine is stopped and in case request user by dialog how to proceed The function checks if a specific state machine or by default all state machines have stopped or finished execution. If a state machine is still running the user is ask by dialog window if those should be stopped or not. ...
5.076875
5.034065
1.008504
selected_sm_id = rafcon.gui.singleton.state_machine_manager_model.selected_state_machine_id selected_sm = state_machine_manager.state_machines[selected_sm_id] state_machines_editor_ctrl = rafcon.gui.singleton.main_window_controller.get_controller('state_machines_editor_ctrl') states_editor_ctrl = ...
def refresh_selected_state_machine()
Reloads the selected state machine.
3.805719
3.780906
1.006563
state_machines_editor_ctrl = rafcon.gui.singleton.main_window_controller.get_controller('state_machines_editor_ctrl') states_editor_ctrl = rafcon.gui.singleton.main_window_controller.get_controller('states_editor_ctrl') if force: pass # no checks direct refresh else: # check if a...
def refresh_all(force=False)
Remove/close all libraries and state machines and reloads them freshly from the file system :param bool force: Force flag to avoid any checks
4.2764
4.15418
1.029421
if isinstance(model, AbstractStateModel) and model.state.is_root_state: logger.warning("Deletion is not allowed. {0} is root state of state machine.".format(model.core_element)) return False state_m = model.parent if state_m is None: msg = "Model has no parent from which it coul...
def delete_core_element_of_model(model, raise_exceptions=False, recursive=True, destroy=True, force=False)
Deletes respective core element of handed model of its state machine If the model is one of state, data flow or transition, it is tried to delete that model together with its data from the corresponding state machine. :param model: The model of respective core element to delete :param bool raise_excep...
3.592269
3.453966
1.040042
# If only one model is given, make a list out of it if not hasattr(models, '__iter__'): models = [models] return sum(delete_core_element_of_model(model, raise_exceptions, recursive=recursive, destroy=destroy, force=force) for model in models)
def delete_core_elements_of_models(models, raise_exceptions=True, recursive=True, destroy=True, force=False)
Deletes all respective core elements for the given models Calls the :func:`delete_core_element_of_model` for all given models. :param models: A single model or a list of models of respective core element to be deleted :param bool raise_exceptions: Whether to raise exceptions or log error messages in case ...
3.06818
2.914803
1.05262
if state_machine_m is None: state_machine_m = rafcon.gui.singleton.state_machine_manager_model.get_selected_state_machine_model() if state_machine_m is None and selected_elements is None: return False selection_in_lib = [] selected_elements = state_machine_m.selection.get_all() if s...
def is_selection_inside_of_library_state(state_machine_m=None, selected_elements=None)
Check if handed or selected elements are inside of library state If no state machine model or selected_elements are handed the method is searching for the selected state machine and its selected elements. If selected_elements list is handed handed state machine model is ignored. :param rafcon.gui.models.s...
4.699001
4.461244
1.053294
assert isinstance(state_machine_m, StateMachineModel) if state_type not in list(StateType): state_type = StateType.EXECUTION if len(state_machine_m.selection.states) != 1: logger.warning("Please select exactly one desired parent state, before adding a new state") return st...
def add_new_state(state_machine_m, state_type)
Triggered when shortcut keys for adding a new state are pressed, or Menu Bar "Edit, Add State" is clicked. Adds a new state only if the parent state (selected state) is a container state, and if the graphical editor or the state machine tree are in focus.
5.553478
5.430242
1.022695
smm_m = rafcon.gui.singleton.state_machine_manager_model if not isinstance(state, State): logger.warning("A state is needed to be insert not {0}".format(state)) return False if not smm_m.selected_state_machine_id: logger.warning("Please select a container state within a state ...
def insert_state_into_selected_state(state, as_template=False)
Adds a State to the selected state :param state: the state which is inserted :param as_template: If a state is a library state can be insert as template :return: boolean: success of the insertion
4.693799
4.55207
1.031135
# print("substitute_selected_state", state, as_template) assert isinstance(state, State) from rafcon.core.states.barrier_concurrency_state import DeciderState if isinstance(state, DeciderState): raise ValueError("State of type DeciderState can not be substituted.") smm_m = rafcon.gui.s...
def substitute_selected_state(state, as_template=False, keep_name=False)
Substitute the selected state with the handed state :param rafcon.core.states.state.State state: A state of any functional type that derives from State :param bool as_template: The flag determines if a handed the state of type LibraryState is insert as template :return:
5.42246
5.022994
1.079527
clusters = set(self.clustering.busmap.values) n = len(clusters) self.stats = {'clusters': pd.DataFrame( index=sorted(clusters), columns=["decompose", "spread", "transfer"])} profile = cProfile.Profile() for i, cluster in enumerate(sorted(clusters)...
def solve(self, scenario, solver)
Decompose each cluster into separate units and try to optimize them separately :param scenario: :param solver: Solver that may be used to optimize partial networks
3.200046
3.189132
1.003422
if not (from_state is None and from_outcome is None): if not isinstance(from_state, string_types): raise ValueError("Invalid transition origin port: from_state must be a string") if not isinstance(from_outcome, int): raise ValueError("Invalid tran...
def modify_origin(self, from_state, from_outcome)
Set both from_state and from_outcome at the same time to modify transition origin :param str from_state: State id of the origin state :param int from_outcome: Outcome id of the origin port :raises exceptions.ValueError: If parameters have wrong types or the new transition is not valid
2.35801
2.09575
1.125139
if not (to_state is None and (to_outcome is not int and to_outcome is not None)): if not isinstance(to_state, string_types): raise ValueError("Invalid transition target port: to_state must be a string") if not isinstance(to_outcome, int) and to_outcome is not Non...
def modify_target(self, to_state, to_outcome=None)
Set both to_state and to_outcome at the same time to modify transition target :param str to_state: State id of the target state :param int to_outcome: Outcome id of the target port :raises exceptions.ValueError: If parameters have wrong types or the new transition is not valid
2.622053
2.377715
1.102762
ExtendedController.register_view(self, view) # no super to avoid sm based selection initialization view['name_text'].set_property('editable', True) view['value_text'].set_property('editable', True) view['type_text'].set_property('editable', True) self.tree_view.connect...
def register_view(self, view)
Called when the View was registered
2.736313
2.794478
0.979186
if self.model.global_variable_manager.is_locked(gv_name): logger.error("{1} of global variable '{0}' is not possible, as it is locked".format(gv_name, intro_message)) return False return True
def global_variable_is_editable(self, gv_name, intro_message='edit')
Check whether global variable is locked :param str gv_name: Name of global variable to be checked :param str intro_message: Message which is used form a useful logger error message if needed :return:
4.298891
3.740559
1.149264
gv_name = "new_global_%s" % self.global_variable_counter self.global_variable_counter += 1 try: self.model.global_variable_manager.set_variable(gv_name, None) except (RuntimeError, AttributeError, TypeError) as e: logger.warning("Addition of new global va...
def on_add(self, widget, data=None)
Create a global variable with default value and select its row Triggered when the add button in the global variables tab is clicked.
4.377875
4.20059
1.042205
path_list = None if self.view is not None: model, path_list = self.tree_view.get_selection().get_selected_rows() models = [self.list_store[path][self.MODEL_STORAGE_ID] for path in path_list] if path_list else [] if models: if len(models) > 1: ...
def on_lock(self, widget, data=None)
Locks respective selected core element
4.631305
4.318314
1.07248
gv_name = model if self.global_variable_is_editable(gv_name, "Deletion"): try: self.model.global_variable_manager.delete_variable(gv_name) except AttributeError as e: logger.warning("The respective global variable '{1}' couldn't be removed...
def remove_core_element(self, model)
Remove respective core element of handed global variable name :param str model: String that is the key/gv_name of core element which should be removed :return:
9.856748
8.552226
1.152536
gv_name = self.list_store[path][self.NAME_STORAGE_ID] if gv_name == new_gv_name or not self.global_variable_is_editable(gv_name, 'Name change'): return data_value = self.model.global_variable_manager.get_representation(gv_name) data_type = self.model.global_variable...
def apply_new_global_variable_name(self, path, new_gv_name)
Change global variable name/key according handed string Updates the global variable name only if different and already in list store. :param path: The path identifying the edited global variable tree view row, can be str, int or tuple. :param str new_gv_name: New global variable name
4.146838
4.065977
1.019887
if self.list_store[path][self.DATA_TYPE_AS_STRING_STORAGE_ID] == new_value_as_string: return gv_name = self.list_store[path][self.NAME_STORAGE_ID] if not self.global_variable_is_editable(gv_name, 'Change of value'): return data_type = self.model.global_va...
def apply_new_global_variable_value(self, path, new_value_as_string)
Change global variable value according handed string Updates the global variable value only if new value string is different to old representation. :param path: The path identifying the edited global variable tree view row, can be str, int or tuple. :param str new_value_as_string: New global v...
3.187848
3.12029
1.021651