idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
40,300 | def substitute_selected_state ( state , as_template = False , keep_name = False ) : 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 = r... | Substitute the selected state with the handed state |
40,301 | def modify_origin ( self , from_state , from_outcome ) : 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 tr... | Set both from_state and from_outcome at the same time to modify transition origin |
40,302 | def modify_target ( self , to_state , to_outcome = None ) : 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 t... | Set both to_state and to_outcome at the same time to modify transition target |
40,303 | def global_variable_is_editable ( self , gv_name , intro_message = 'edit' ) : 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 | Check whether global variable is locked |
40,304 | def on_add ( self , widget , data = None ) : 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 globa... | Create a global variable with default value and select its row |
40,305 | def on_lock ( self , widget , data = None ) : 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 :... | Locks respective selected core element |
40,306 | def remove_core_element ( self , model ) : 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. -> {0}" "" . f... | Remove respective core element of handed global variable name |
40,307 | def assign_notification_from_gvm ( self , model , prop_name , info ) : 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 ) >... | Handles gtkmvc3 notification from global variable manager |
40,308 | def update_global_variables_list_store ( self ) : 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 . model . global_variable_manager . get_data_type ( key ) ... | Updates the global variable list store |
40,309 | def get_view_for_id ( self , view_class , element_id , parent_item = None ) : 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 ... | Searches and returns the View for the given id and type |
40,310 | def wait_for_update ( self , trigger_update = False ) : if trigger_update : self . update_now ( ) from gi . repository import Gtk from gi . repository import GLib from threading import Event event = Event ( ) def priority_handled ( event ) : event . set ( ) priority = ( GLib . PRIORITY_HIGH_IDLE + GLib . PRIORITY_DEFAU... | Update canvas and handle all events in the gtk queue |
40,311 | def _get_value ( self ) : 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 | Return two delegating variables . Each variable should contain a value attribute with the real value . |
40,312 | def convert_string_to_type ( string_value ) : if string_value in [ 'None' , type ( None ) . __name__ ] : return type ( None ) if isinstance ( string_value , type ) or isclass ( string_value ) : return string_value if sys . version_info >= ( 3 , ) : import builtins as builtins23 else : import __builtin__ as builtins23 i... | Converts a string into a type or class |
40,313 | def convert_string_value_to_type_value ( string_value , data_type ) : 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... | Helper function to convert a given string to a given data type |
40,314 | def type_inherits_of_type ( inheriting_type , base_type ) : 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 t... | Checks whether inheriting_type inherits from base_type |
40,315 | def clear_results_db ( session ) : from egoio . db_tables . model_draft import EgoGridPfHvResultBus as BusResult , EgoGridPfHvResultBusT as BusTResult , EgoGridPfHvResultStorage as StorageResult , EgoGridPfHvResultStorageT as StorageTResult , EgoGridPfHvResultGenerator as GeneratorResult , EgoGridPfHvResultGeneratorT a... | Used to clear the result tables in the OEDB . Caution! This deletes EVERY RESULT SET! |
40,316 | def run_sql_script ( conn , scriptname = 'results_md2grid.sql' ) : 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_st... | This function runs . sql scripts in the folder sql_scripts |
40,317 | def distance ( x0 , x1 , y0 , y1 ) : distance = ( x1 . values - x0 . values ) * ( x1 . values - x0 . values ) + ( y1 . values - y0 . values ) * ( y1 . values - y0 . values ) return distance | Function that calculates the square of the distance between two points . |
40,318 | def calc_nearest_point ( bus1 , network ) : 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 [ netwo... | Function that finds the geographical nearest point in a network from a given bus . |
40,319 | def map_ormclass ( self , name ) : try : self . _mapped [ name ] = getattr ( self . _pkg , self . _prefix + name ) except AttributeError : print ( 'Warning: Relation %s does not exist.' % name ) | Populate _mapped attribute with orm class |
40,320 | def configure_timeindex ( self ) : 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 : tr = self . session . query ( ormclass ) . filter ( or... | Construct a DateTimeIndex with the queried temporal resolution start - and end_snapshot . |
40,321 | def fetch_by_relname ( self , name ) : 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 ) if name == 'Transformer' ... | Construct DataFrame with component data from filtered table data . |
40,322 | def series_fetch_by_relname ( self , name , column ) : ormclass = self . _mapped [ name ] 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 ( ormclass , column ) [ self . start_snapshot : s... | Construct DataFrame with component timeseries data from filtered table data . |
40,323 | def build_network ( self , network = None , * args , ** kwargs ) : if network != None : network = network else : network = pypsa . Network ( ) network . set_snapshots ( self . timeindex ) timevarying_override = False if pypsa . __version__ == '0.11.0' : old_to_new_name = { 'Generator' : { 'p_min_pu_fixed' : 'p_min_pu' ... | Core method to construct PyPSA Network object . |
40,324 | def run ( self ) : 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_history_item ) fin... | This defines the sequence of actions that are taken when the preemptive concurrency state is executed |
40,325 | def _check_transition_validity ( self , check_transition ) : valid , message = super ( PreemptiveConcurrencyState , self ) . _check_transition_validity ( check_transition ) if not valid : return False , message if check_transition . to_state != self . state_id : return False , "Only transitions to the parent state are ... | Transition of BarrierConcurrencyStates must least fulfill the condition of a ContainerState . Start transitions are forbidden in the ConcurrencyState |
40,326 | def recover_specific_version ( self , pointer_on_version_to_recover ) : 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_recover ) logger . debug ( "... | Recovers a specific version of the all_time_history element by doing several undos and redos . |
40,327 | def get_undo_redo_list_from_active_trail_history_item_to_version_id ( self , version_id ) : 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_i... | Perform fast search from currently active branch to specific version_id and collect all recovery steps . |
40,328 | def set_pane_position ( self , config_id ) : 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 ) | 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 . |
40,329 | def model_changed ( self , model , prop_name , info ) : if not self . view : return execution_engine = rafcon . core . singleton . state_machine_execution_engine label_string = str ( execution_engine . status . execution_mode ) label_string = label_string . replace ( "STATE_MACHINE_EXECUTION_STATUS." , "" ) self . view... | Highlight buttons according actual execution status . Furthermore it triggers the label redraw of the active state machine . |
40,330 | def focus_notebook_page_of_controller ( self , controller ) : if controller not in self . get_child_controllers ( ) : return if not self . modification_history_was_focused and isinstance ( controller , ModificationHistoryTreeController ) and self . view is not None : self . view . bring_tab_to_the_top ( 'history' ) sel... | Puts the focus on the given child controller |
40,331 | def on_notebook_tab_switch ( self , notebook , page , page_num , title_label , window , notebook_identifier ) : 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 ) | Triggered whenever a left - bar notebook tab is changed . |
40,332 | def _on_key_press ( self , widget , event ) : 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 ( ) | Updates the currently pressed keys |
40,333 | def prepare_destruction ( self ) : plugins . run_hook ( "pre_destruction" ) logger . debug ( "Saving runtime config to {0}" . format ( global_runtime_config . config_file_path ) ) for key , widget_name in constants . PANE_ID . items ( ) : global_runtime_config . store_widget_properties ( self . view [ widget_name ] , k... | Saves current configuration of windows and panes to the runtime config file before RAFCON is closed . |
40,334 | def setup_forward_or_backward_execution ( self ) : if self . backward_execution : last_history_item = self . execution_history . pop_last_item ( ) assert isinstance ( last_history_item , ReturnItem ) self . scoped_data = last_history_item . scoped_data concurrency_history_item = self . execution_history . get_last_hist... | Sets up the execution of the concurrency states dependent on if the state is executed forward of backward . |
40,335 | def start_child_states ( self , concurrency_history_item , do_not_start_state = None ) : self . state_execution_status = StateExecutionStatus . EXECUTE_CHILDREN concurrency_queue = queue . Queue ( maxsize = 0 ) for index , state in enumerate ( self . states . values ( ) ) : if state is not do_not_start_state : state . ... | Utility function to start all child states of the concurrency state . |
40,336 | def join_state ( self , state , history_index , concurrency_history_item ) : state . join ( ) if state . backward_execution : self . backward_execution = True state . state_execution_status = StateExecutionStatus . INACTIVE if not self . backward_execution : state . concurrency_queue = None state . execution_history . ... | a utility function to join a state |
40,337 | def finalize_backward_execution ( self ) : self . backward_execution = True last_history_item = self . execution_history . pop_last_item ( ) assert isinstance ( last_history_item , ConcurrencyItem ) last_history_item = self . execution_history . pop_last_item ( ) assert isinstance ( last_history_item , CallItem ) self ... | Utility function to finalize the backward execution of the concurrency state . |
40,338 | def finalize_concurrency_state ( self , outcome ) : 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_... | Utility function to finalize the forward execution of the concurrency state . |
40,339 | def _head_length ( self , port ) : if not port : return 0. parent_state_v = self . get_parent_state_v ( ) if parent_state_v is port . parent : return port . port_size [ 1 ] return max ( port . port_size [ 1 ] * 1.5 , self . _calc_line_width ( ) / 1.3 ) | Distance from the center of the port to the perpendicular waypoint |
40,340 | def on_use_runtime_value_toggled ( self , widget , path ) : 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" ) | Try to set the use runtime value flag to the newly entered one |
40,341 | def _default_value_cell_data_func ( self , tree_view_column , cell , model , iter , data = None ) : 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_pro... | Function set renderer properties for every single cell independently |
40,342 | def _reload_data_port_list_store ( self ) : 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 data_type_name = data_type . __name__ data_type_module = data_type . __module__ if data_... | Reloads the input data port list store from the data port models |
40,343 | def _apply_new_data_port_name ( self , path , new_name ) : 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 . except... | Applies the new name of the data port defined by path |
40,344 | def _apply_new_data_port_type ( self , path , new_data_type_str ) : 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 )... | Applies the new data type of the data port defined by path |
40,345 | def _apply_new_data_port_default_value ( self , path , new_default_value_str ) : try : data_port_id = self . list_store [ path ] [ self . ID_STORAGE_ID ] if isinstance ( self . model . state , LibraryState ) : if self . list_store [ path ] [ self . USE_RUNTIME_VALUE_STORAGE_ID ] : self . set_data_port_runtime_value ( d... | Applies the new default value of the data port defined by path |
40,346 | def _data_ports_changed ( self , model ) : if not isinstance ( model , AbstractStateModel ) : return 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_STORAGE_ID ] for pat... | Reload list store and reminds selection when the model was changed |
40,347 | def runtime_values_changed ( self , model , prop_name , info ) : 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 ) | Handle cases for the library runtime values |
40,348 | def add_new_data_port ( self ) : 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 | Add a new port with default values and select it |
40,349 | def add_callback_for_action ( self , action , callback ) : if hasattr ( callback , '__call__' ) : if action not in self . __action_to_callbacks : self . __action_to_callbacks [ action ] = [ ] self . __action_to_callbacks [ action ] . append ( callback ) controller = None try : controller = callback . __self__ except At... | Adds a callback function to an action |
40,350 | def remove_callback_for_action ( self , action , callback ) : if action in self . __action_to_callbacks : if callback in self . __action_to_callbacks [ action ] : self . __action_to_callbacks [ action ] . remove ( callback ) | Remove a callback for a specific action |
40,351 | def check_info_on_no_update_flags ( self , info ) : if 'before' in info and info [ 'method_name' ] == "remove_state" : if info . instance is self . model . state : self . no_update_state_destruction = True else : removed_state_id = info . args [ 1 ] if len ( info . args ) > 1 else info . kwargs [ 'state_id' ] if remove... | Stop updates while multi - actions |
40,352 | def before_notification_state_machine_observation_control ( self , model , prop_name , info ) : if is_execution_status_update_notification_from_state_machine_model ( prop_name , info ) : return self . check_info_on_no_update_flags ( info ) | Check for multi - actions and set respective no update flags . |
40,353 | def store_value ( self , name , value , parameters = None ) : 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 | Stores the value of a certain variable |
40,354 | def get_value ( self , name , parameters = None ) : 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 ) | Return the value of a cached variable if applicable |
40,355 | def _normalize_number_values ( self , parameters ) : for key , value in parameters . items ( ) : if isinstance ( value , ( int , float ) ) : parameters [ key ] = str ( Decimal ( value ) . normalize ( self . _context ) ) | Assures equal precision for all number values |
40,356 | def get_view_selection ( self ) : if not self . MODEL_STORAGE_ID : return None , None if len ( self . store ) == 0 : paths = [ ] else : model , paths = self . _tree_selection . get_selected_rows ( ) selected_model_list = [ ] for path in paths : model = self . store [ path ] [ self . MODEL_STORAGE_ID ] selected_model_li... | Get actual tree selection object and all respective models of selected rows |
40,357 | def state_machine_selection_changed ( self , state_machine_m , signal_name , signal_msg ) : if self . CORE_ELEMENT_CLASS in signal_msg . arg . affected_core_element_classes : self . update_selection_sm_prior ( ) | Notify tree view about state machine selection |
40,358 | def remove_action_callback ( self , * event ) : 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 | Callback method for remove action |
40,359 | def _apply_value_on_edited_and_focus_out ( self , renderer , apply_method ) : assert isinstance ( renderer , Gtk . CellRenderer ) def remove_all_handler ( renderer ) : def remove_handler ( widget , data_name ) : handler_id = getattr ( widget , data_name ) if widget . handler_is_connected ( handler_id ) : widget . disco... | Sets up the renderer to apply changed when loosing focus |
40,360 | def on_remove ( self , widget , data = None ) : 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... | Removes respective selected core elements and select the next one |
40,361 | def get_state_machine_selection ( self ) : 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 ( ) | An abstract getter method for state machine selection |
40,362 | def _handle_double_click ( self , event ) : if event . get_button ( ) [ 1 ] == 1 : path_info = self . tree_view . get_path_at_pos ( int ( event . x ) , int ( event . y ) ) if path_info : path = path_info [ 0 ] iter = self . list_store . get_iter ( path ) model = self . list_store . get_value ( iter , self . MODEL_STORA... | Double click with left mouse button focuses the element |
40,363 | def iter_tree_with_handed_function ( self , function , * function_args ) : 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 =... | Iterate tree view with condition check function |
40,364 | def update_selection_sm_prior_condition ( self , state_row_iter , selected_model_list , sm_selected_model_list ) : 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_lis... | State machine prior update of tree selection for one tree model row |
40,365 | def update_selection_self_prior_condition ( self , state_row_iter , sm_selected_model_set , selected_model_list ) : 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 an... | Tree view prior update of one model in the state machine selection |
40,366 | def contains_geometric_info ( var ) : return isinstance ( var , tuple ) and len ( var ) == 2 and all ( isinstance ( val , ( int , float ) ) for val in var ) | Check whether the passed variable is a tuple with two floats or integers |
40,367 | def generate_default_state_meta_data ( parent_state_m , canvas = None , num_child_state = None , gaphas_editor = True ) : 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 ) ) num_child_s... | Generate default meta data for a child state according its parent state |
40,368 | def add_boundary_clearance ( left , right , top , bottom , frame , clearance = 0.1 ) : 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 [ '... | Increase boundary size |
40,369 | def cal_frame_according_boundaries ( left , right , top , bottom , parent_size , gaphas_editor = True , group = True ) : margin = cal_margin ( parent_size ) if group : rel_pos = max ( left - margin , 0 ) , max ( top - margin , 0 ) size = ( min ( right - left + 2 * margin , parent_size [ 0 ] - rel_pos [ 0 ] ) , min ( bo... | Generate margin and relative position and size handed boundary parameter and parent size |
40,370 | def offset_rel_pos_of_all_models_in_dict ( models_dict , pos_offset , gaphas_editor = True ) : for child_state_m in models_dict [ 'states' ] . values ( ) : old_rel_pos = child_state_m . get_meta_data_editor ( for_gaphas = gaphas_editor ) [ 'rel_pos' ] child_state_m . set_meta_data_editor ( 'rel_pos' , add_pos ( old_rel... | Add position offset to all handed models in dict |
40,371 | def scale_library_ports_meta_data ( state_m , gaphas_editor = True ) : 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' ] ) factor = divide_two_vectors ( state_m . get_meta_data_editor ( ) [ 'size' ] , s... | 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 . |
40,372 | def resize_state_port_meta ( state_m , factor , gaphas_editor = True ) : 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 [ : ] + s... | Resize data and logical ports relative positions |
40,373 | def resize_state_meta ( state_m , factor , gaphas_editor = True ) : old_rel_pos = state_m . get_meta_data_editor ( for_gaphas = gaphas_editor ) [ 'rel_pos' ] state_m . set_meta_data_editor ( 'rel_pos' , mult_two_vectors ( factor , old_rel_pos ) , from_gaphas = gaphas_editor ) old_size = state_m . get_meta_data_editor (... | Resize state meta data recursive what includes also LibraryStateModels meta data and its internal state_copy |
40,374 | def offset_rel_pos_of_models_meta_data_according_parent_state ( models_dict ) : 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 | Offset meta data of state elements according the area used indicated by the state meta data . |
40,375 | def get_closest_sibling_state ( state_m , from_logical_port = None ) : 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_... | Calculate the closest sibling also from optional logical port of handed state model |
40,376 | def get_action_arguments ( self , target_state_m ) : 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 ]... | Collect argument attributes for action signal |
40,377 | def cut ( self , selection , smart_selection_adaption = False ) : 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 ( ... | Cuts all selected items and copy them to the clipboard using smart selection adaptation by default |
40,378 | def reset_clipboard ( self ) : for state_element_attr in ContainerState . state_element_attrs : self . model_copies [ state_element_attr ] = [ ] self . copy_parent_state_id = None self . reset_clipboard_mapping_dicts ( ) | Resets the clipboard so that old elements do not pollute the new selection that is copied into the clipboard . |
40,379 | def do_selection_reduction_to_one_parent ( selection ) : all_models_selected = selection . get_all ( ) parent_m_count_dict = { } for model in all_models_selected : parent_m_count_dict [ model . parent ] = parent_m_count_dict [ model . parent ] + 1 if model . parent in parent_m_count_dict else 1 parent_m = None current_... | Find and reduce selection to one parent state . |
40,380 | def __create_core_and_model_object_copies ( self , selection , smart_selection_adaption ) : all_models_selected = selection . get_all ( ) if not all_models_selected : logger . warning ( "Nothing to copy because state machine selection is empty." ) return parent_m = self . do_selection_reduction_to_one_parent ( selectio... | Copy all elements of a selection . |
40,381 | def destroy_all_models_in_dict ( target_dict ) : if target_dict : for model_list in target_dict . values ( ) : if isinstance ( model_list , ( list , tuple ) ) : for model in model_list : model . prepare_destruction ( ) if model . _parent : model . _parent = None else : raise Exception ( "wrong data in clipboard" ) | Method runs the prepare destruction method of models which are assumed in list or tuple as values within a dict |
40,382 | def destroy ( self ) : self . destroy_all_models_in_dict ( self . model_copies ) self . model_copies = None self . copy_parent_state_id = None self . outcome_id_mapping_dict = None self . port_id_mapping_dict = None self . state_id_mapping_dict = None | Destroys the clipboard by relieving all model references . |
40,383 | def extend_extents ( extents , factor = 1.1 ) : width = extents [ 2 ] - extents [ 0 ] height = extents [ 3 ] - extents [ 1 ] add_width = ( factor - 1 ) * width add_height = ( factor - 1 ) * height x1 = extents [ 0 ] - add_width / 2 x2 = extents [ 2 ] + add_width / 2 y1 = extents [ 1 ] - add_height / 2 y2 = extents [ 3 ... | Extend a given bounding box |
40,384 | def calc_rel_pos_to_parent ( canvas , item , handle ) : from gaphas . item import NW if isinstance ( item , ConnectionView ) : return item . canvas . get_matrix_i2i ( item , item . parent ) . transform_point ( * handle . pos ) parent = canvas . get_parent ( item ) if parent : return item . canvas . get_matrix_i2i ( ite... | This method calculates the relative position of the given item s handle to its parent |
40,385 | def assert_exactly_one_true ( bool_list ) : assert isinstance ( bool_list , list ) counter = 0 for item in bool_list : if item : counter += 1 return counter == 1 | This method asserts that only one value of the provided list is True . |
40,386 | def get_state_id_for_port ( port ) : parent = port . parent from rafcon . gui . mygaphas . items . state import StateView if isinstance ( parent , StateView ) : return parent . model . state . state_id | This method returns the state ID of the state containing the given port |
40,387 | def get_port_for_handle ( handle , state ) : from rafcon . gui . mygaphas . items . state import StateView if isinstance ( state , StateView ) : if state . income . handle == handle : return state . income else : for outcome in state . outcomes : if outcome . handle == handle : return outcome for input in state . input... | Looks for and returns the PortView to the given handle in the provided state |
40,388 | def create_new_connection ( from_port , to_port ) : from rafcon . gui . mygaphas . items . ports import ScopedVariablePortView , LogicPortView , DataPortView if isinstance ( from_port , LogicPortView ) and isinstance ( to_port , LogicPortView ) : return add_transition_to_state ( from_port , to_port ) elif isinstance ( ... | Checks the type of connection and tries to create it |
40,389 | def add_data_flow_to_state ( from_port , to_port ) : from rafcon . gui . mygaphas . items . ports import InputPortView , OutputPortView , ScopedVariablePortView from rafcon . gui . models . container_state import ContainerStateModel from_state_v = from_port . parent to_state_v = to_port . parent from_state_m = from_sta... | Interface method between Gaphas and RAFCON core for adding data flows |
40,390 | def add_transition_to_state ( from_port , to_port ) : from rafcon . gui . mygaphas . items . ports import IncomeView , OutcomeView from_state_v = from_port . parent to_state_v = to_port . parent from_state_m = from_state_v . model to_state_m = to_state_v . model from_state_id = from_state_m . state . state_id to_state_... | Interface method between Gaphas and RAFCON core for adding transitions |
40,391 | def get_relative_positions_of_waypoints ( transition_v ) : handles_list = transition_v . handles ( ) rel_pos_list = [ ] for handle in handles_list : if handle in transition_v . end_handles ( include_waypoints = True ) : continue rel_pos = transition_v . canvas . get_matrix_i2i ( transition_v , transition_v . parent ) .... | This method takes the waypoints of a connection and returns all relative positions of these waypoints . |
40,392 | def update_meta_data_for_transition_waypoints ( graphical_editor_view , transition_v , last_waypoint_list , publish = True ) : from rafcon . gui . mygaphas . items . connection import TransitionView assert isinstance ( transition_v , TransitionView ) transition_m = transition_v . model waypoint_list = get_relative_posi... | This method updates the relative position meta data of the transitions waypoints if they changed |
40,393 | def update_meta_data_for_port ( graphical_editor_view , item , handle ) : from rafcon . gui . mygaphas . items . ports import IncomeView , OutcomeView , InputPortView , OutputPortView , ScopedVariablePortView for port in item . get_all_ports ( ) : if not handle or handle is port . handle : rel_pos = ( port . handle . p... | This method updates the meta data of the states ports if they changed . |
40,394 | def update_meta_data_for_name_view ( graphical_editor_view , name_v , publish = True ) : from gaphas . item import NW rel_pos = calc_rel_pos_to_parent ( graphical_editor_view . editor . canvas , name_v , name_v . handles ( ) [ NW ] ) state_v = graphical_editor_view . editor . canvas . get_parent ( name_v ) state_v . mo... | This method updates the meta data of a name view . |
40,395 | def update_meta_data_for_state_view ( graphical_editor_view , state_v , affects_children = False , publish = True ) : from gaphas . item import NW update_meta_data_for_port ( graphical_editor_view , state_v , None ) if affects_children : update_meta_data_for_name_view ( graphical_editor_view , state_v . name_view , pub... | This method updates the meta data of a state view |
40,396 | def remove ( self ) : self . canvas . get_first_view ( ) . unselect_item ( self ) for child in self . canvas . get_children ( self ) [ : ] : child . remove ( ) self . remove_income ( ) for outcome_v in self . outcomes [ : ] : self . remove_outcome ( outcome_v ) for input_port_v in self . inputs [ : ] : self . remove_in... | Remove recursively all children and then the StateView itself |
40,397 | def show_content ( self , with_content = False ) : if isinstance ( self . model , LibraryStateModel ) and self . model . show_content ( ) : return not with_content or isinstance ( self . model . state_copy , ContainerStateModel ) return False | Checks if the state is a library with the show_content flag set |
40,398 | def _calculate_port_pos_on_line ( self , port_num , side_length , port_width = None ) : if port_width is None : port_width = 2 * self . border_width border_size = self . border_width pos = 0.5 * border_size + port_num * port_width outermost_pos = max ( side_length / 2. , side_length - 0.5 * border_size - port_width ) p... | Calculate the position of a port on a line |
40,399 | def load_objects_from_json ( path , as_dict = False ) : f = open ( path , 'r' ) if as_dict : result = json . load ( f ) else : result = json . load ( f , cls = JSONObjectDecoder , substitute_modules = substitute_modules ) f . close ( ) return result | Loads a dictionary from a json file . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.