idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
27,200
def export_setting ( file_path , qsettings = None ) : inasafe_settings = { } if not qsettings : qsettings = QSettings ( ) qsettings . beginGroup ( 'inasafe' ) all_keys = qsettings . allKeys ( ) qsettings . endGroup ( ) for key in all_keys : inasafe_settings [ key ] = setting ( key , qsettings = qsettings ) def custom_d...
Export InaSAFE s setting to a file .
27,201
def import_setting ( file_path , qsettings = None ) : with open ( file_path , 'r' ) as f : inasafe_settings = json . load ( f ) if not qsettings : qsettings = QSettings ( ) qsettings . beginGroup ( 'inasafe' ) qsettings . remove ( '' ) qsettings . endGroup ( ) for key , value in list ( inasafe_settings . items ( ) ) : ...
Import InaSAFE s setting from a file .
27,202
def save_boolean_setting ( self , key , check_box ) : set_setting ( key , check_box . isChecked ( ) , qsettings = self . settings )
Save boolean setting according to check_box state .
27,203
def restore_boolean_setting ( self , key , check_box ) : flag = setting ( key , expected_type = bool , qsettings = self . settings ) check_box . setChecked ( flag )
Set check_box according to setting of key .
27,204
def save_text_setting ( self , key , line_edit ) : set_setting ( key , line_edit . text ( ) , self . settings )
Save text setting according to line_edit value .
27,205
def restore_text_setting ( self , key , line_edit ) : value = setting ( key , expected_type = str , qsettings = self . settings ) line_edit . setText ( value )
Set line_edit text according to setting of key .
27,206
def update_earthquake_info ( self ) : self . label_earthquake_model ( ) current_index = self . earthquake_function . currentIndex ( ) model = EARTHQUAKE_FUNCTIONS [ current_index ] notes = '' for note in model [ 'notes' ] : notes += note + '\n\n' citations = '' for citation in model [ 'citations' ] : citations += citat...
Update information about earthquake info .
27,207
def open_keyword_cache_path ( self ) : file_name , __ = QFileDialog . getSaveFileName ( self , self . tr ( 'Set keyword cache file' ) , self . leKeywordCachePath . text ( ) , self . tr ( 'Sqlite DB File (*.db)' ) ) if file_name : self . leKeywordCachePath . setText ( file_name )
Open File dialog to choose the keyword cache path .
27,208
def open_user_directory_path ( self ) : directory_name = QFileDialog . getExistingDirectory ( self , self . tr ( 'Results directory' ) , self . leUserDirectoryPath . text ( ) , QFileDialog . ShowDirsOnly ) if directory_name : self . leUserDirectoryPath . setText ( directory_name )
Open File dialog to choose the user directory path .
27,209
def open_north_arrow_path ( self ) : file_name , __ = QFileDialog . getOpenFileName ( self , self . tr ( 'Set north arrow image file' ) , self . leNorthArrowPath . text ( ) , self . tr ( 'Portable Network Graphics files (*.png *.PNG);;' 'JPEG Images (*.jpg *.jpeg);;' 'GIF Images (*.gif *.GIF);;' 'SVG Images (*.svg *.SV...
Open File dialog to choose the north arrow path .
27,210
def open_organisation_logo_path ( self ) : file_name , __ = QFileDialog . getOpenFileName ( self , self . tr ( 'Set organisation logo file' ) , self . organisation_logo_path_line_edit . text ( ) , self . tr ( 'Portable Network Graphics files (*.png *.PNG);;' 'JPEG Images (*.jpg *.jpeg);;' 'GIF Images (*.gif *.GIF);;' '...
Open File dialog to choose the organisation logo path .
27,211
def open_report_template_path ( self ) : directory_name = QFileDialog . getExistingDirectory ( self , self . tr ( 'Templates directory' ) , self . leReportTemplatePath . text ( ) , QFileDialog . ShowDirsOnly ) if directory_name : self . leReportTemplatePath . setText ( directory_name )
Open File dialog to choose the report template path .
27,212
def toggle_logo_path ( self ) : is_checked = self . custom_organisation_logo_check_box . isChecked ( ) if is_checked : path = setting ( key = 'organisation_logo_path' , default = supporters_logo_path ( ) , expected_type = str , qsettings = self . settings ) else : path = supporters_logo_path ( ) self . organisation_log...
Set state of logo path line edit and button .
27,213
def update_logo_preview ( self ) : logo_path = self . organisation_logo_path_line_edit . text ( ) if os . path . exists ( logo_path ) : icon = QPixmap ( logo_path ) label_size = self . organisation_logo_label . size ( ) label_size . setHeight ( label_size . height ( ) - 2 ) label_size . setWidth ( label_size . width ( ...
Update logo based on the current logo path .
27,214
def set_north_arrow ( self ) : is_checked = self . custom_north_arrow_checkbox . isChecked ( ) if is_checked : path = setting ( key = 'north_arrow_path' , default = default_north_arrow_path ( ) , expected_type = str , qsettings = self . settings ) else : path = default_north_arrow_path ( ) self . leNorthArrowPath . set...
Auto - connect slot activated when north arrow checkbox is toggled .
27,215
def set_user_dir ( self ) : is_checked = self . custom_UseUserDirectory_checkbox . isChecked ( ) if is_checked : path = setting ( key = 'defaultUserDirectory' , default = '' , expected_type = str , qsettings = self . settings ) else : path = temp_dir ( 'impacts' ) self . leUserDirectoryPath . setText ( path ) self . sp...
Auto - connect slot activated when user dir checkbox is toggled .
27,216
def set_templates_dir ( self ) : is_checked = self . custom_templates_dir_checkbox . isChecked ( ) if is_checked : path = setting ( key = 'reportTemplatePath' , default = '' , expected_type = str , qsettings = self . settings ) else : path = '' self . leReportTemplatePath . setText ( path ) self . splitter_custom_repor...
Auto - connect slot activated when templates dir checkbox is toggled .
27,217
def set_org_disclaimer ( self ) : is_checked = self . custom_org_disclaimer_checkbox . isChecked ( ) if is_checked : org_disclaimer = setting ( 'reportDisclaimer' , default = disclaimer ( ) , expected_type = str , qsettings = self . settings ) else : org_disclaimer = disclaimer ( ) self . txtDisclaimer . setPlainText (...
Auto - connect slot activated when org disclaimer checkbox is toggled .
27,218
def restore_default_values_page ( self ) : if self . default_value_parameters : self . default_value_parameters = [ ] if self . default_value_parameter_containers : self . default_value_parameter_containers = [ ] for i in reversed ( list ( range ( self . container_layout . count ( ) ) ) ) : widget = self . container_la...
Setup UI for default values setting .
27,219
def restore_population_parameters ( self , global_default = True ) : if global_default : data = generate_default_profile ( ) else : data = setting ( 'population_preference' , generate_default_profile ( ) ) if not isinstance ( data , dict ) : LOGGER . debug ( 'population parameter is not a dictionary. InaSAFE will use '...
Setup UI for population parameter page from setting .
27,220
def age_ratios ( ) : parameter_container = None youth_ratio = parameter_container . get_parameter_by_guid ( youth_ratio_field [ 'key' ] ) . value adult_ratio = parameter_container . get_parameter_by_guid ( adult_ratio_field [ 'key' ] ) . value elderly_ratio = parameter_container . get_parameter_by_guid ( elderly_ratio_...
Helper to get list of age ratio from the options dialog .
27,221
def is_good_age_ratios ( self ) : ratios = self . age_ratios ( ) if None in ratios : clean_ratios = [ x for x in ratios if x is not None ] ratios . remove ( None ) if sum ( clean_ratios ) > 1 : return False else : if sum ( ratios ) != 1 : return False return True
Method to check the sum of age ratio is 1 .
27,222
def save_default_values ( self ) : for parameter_container in self . default_value_parameter_containers : parameters = parameter_container . get_parameters ( ) for parameter in parameters : set_inasafe_default_value_qsetting ( self . settings , GLOBAL , parameter . guid , parameter . value )
Save InaSAFE default values .
27,223
def restore_defaults_ratio ( self ) : self . is_restore_default = True for i in reversed ( list ( range ( self . container_layout . count ( ) ) ) ) : widget = self . container_layout . itemAt ( i ) . widget ( ) if widget is not None : widget . setParent ( None ) self . restore_default_values_page ( )
Restore InaSAFE default ratio .
27,224
def default_field_to_parameter ( self , default_field ) : if default_field . get ( 'type' ) == QVariant . Double : parameter = FloatParameter ( ) elif default_field . get ( 'type' ) in qvariant_whole_numbers : parameter = IntegerParameter ( ) else : return default_value = default_field . get ( 'default_value' ) if not ...
Obtain parameter from default field .
27,225
def set_welcome_message ( self ) : string = html_header ( ) string += welcome_message ( ) . to_html ( ) string += html_footer ( ) self . welcome_message . setHtml ( string )
Create and insert welcome message .
27,226
def show_welcome_dialog ( self ) : self . welcome_layout . addWidget ( self . welcome_message_check_box ) while self . tabWidget . count ( ) > 3 : self . tabWidget . removeTab ( self . tabWidget . count ( ) - 1 ) self . setWindowTitle ( self . tr ( 'Welcome to InaSAFE %s' % get_version ( ) ) ) self . export_button . hi...
Setup for showing welcome message dialog .
27,227
def export_setting ( self ) : LOGGER . debug ( 'Export button clicked' ) home_directory = os . path . expanduser ( '~' ) file_name = self . organisation_line_edit . text ( ) . replace ( ' ' , '_' ) file_path , __ = QFileDialog . getSaveFileName ( self , self . tr ( 'Export InaSAFE settings' ) , os . path . join ( home_...
Export setting from an existing file .
27,228
def import_setting ( self ) : LOGGER . debug ( 'Import button clicked' ) home_directory = os . path . expanduser ( '~' ) file_path , __ = QFileDialog . getOpenFileName ( self , self . tr ( 'Import InaSAFE settings' ) , home_directory , self . tr ( 'JSON File (*.json)' ) ) if file_path : title = tr ( 'Import InaSAFE Set...
Import setting to a file .
27,229
def specific_notes ( hazard , exposure ) : for item in ITEMS : if item [ 'hazard' ] == hazard and item [ 'exposure' ] == exposure : return item . get ( 'notes' , [ ] ) return [ ]
Return notes which are specific for a given hazard and exposure .
27,230
def specific_actions ( hazard , exposure ) : for item in ITEMS : if item [ 'hazard' ] == hazard and item [ 'exposure' ] == exposure : return item . get ( 'actions' , [ ] ) return [ ]
Return actions which are specific for a given hazard and exposure .
27,231
def data_object ( self ) : data_obj = [ ] for i in range ( 0 , len ( self . data ) ) : obj = { 'value' : self . data [ i ] , 'label' : self . labels [ i ] , 'color' : self . colors [ i ] , } data_obj . append ( obj ) return data_obj
List of dictionary contains value and labels associations .
27,232
def slices ( self ) : labels = self . labels values = self . data hole_percentage = self . inner_radius_ratio radius = self . DEFAULT_RADIUS hole = hole_percentage * radius colors = self . colors stroke_color = self . stroke_color slices_return = [ ] total_values = self . total_value angle = - math . pi / 2 center_poin...
List of dictionary context to generate pie slices in svg .
27,233
def _arc_slice_context ( cls , slice_value , total_values , label , color , stroke_color , radius = 128 , label_position = ( 256 , 0 ) , start_angle = - math . pi / 2 , center_point = ( 128 , 128 ) , hole = 0 ) : try : step_angle = 1.0 * slice_value / total_values * 2 * math . pi except ZeroDivisionError : return None ...
Create arc slice context to be rendered in svg .
27,234
def selected_canvas_agglayer ( self ) : if self . lstCanvasAggLayers . selectedItems ( ) : item = self . lstCanvasAggLayers . currentItem ( ) else : return None try : layer_id = item . data ( QtCore . Qt . UserRole ) except ( AttributeError , NameError ) : layer_id = None layer = QgsProject . instance ( ) . mapLayer ( ...
Obtain the canvas aggregation layer selected by user .
27,235
def set_widgets ( self ) : last_layer = self . parent . layer and self . parent . layer . id ( ) or None self . lblDescribeCanvasAggLayer . clear ( ) self . list_compatible_canvas_layers ( ) self . auto_select_one_item ( self . lstCanvasAggLayers ) if last_layer : layers = [ ] for indx in range ( self . lstCanvasAggLay...
Set widgets on the Aggregation Layer from Canvas tab .
27,236
def layer_definition_type ( layer ) : layer_purposes = [ 'exposure' , 'hazard' ] layer_purpose = [ p for p in layer_purposes if p in layer . keywords ] if not layer_purpose : return None layer_purpose = layer_purpose [ 0 ] return definition ( layer . keywords [ layer_purpose ] )
Returned relevant layer definition based on layer purpose .
27,237
def layer_hazard_classification ( layer ) : if not layer . keywords . get ( 'hazard' ) : return None hazard_classification = None for classification in hazard_classes_all : classification_name = layer . keywords [ 'classification' ] if classification_name == classification [ 'key' ] : hazard_classification = classifica...
Returned this particular hazard classification .
27,238
def jinja2_output_as_string ( impact_report , component_key ) : metadata = impact_report . metadata for c in metadata . components : if c . key == component_key : if c . output_format == 'string' : return c . output or '' elif c . output_format == 'file' : try : filename = os . path . join ( impact_report . output_fold...
Get a given jinja2 component output as string .
27,239
def value_from_field_name ( field_name , analysis_layer ) : field_index = analysis_layer . fields ( ) . lookupField ( field_name ) if field_index < 0 : return None else : feat = QgsFeature ( ) analysis_layer . getFeatures ( ) . nextFeature ( feat ) return feat [ field_index ]
Get the value of analysis layer based on field name .
27,240
def resolve_from_dictionary ( dictionary , key_list , default_value = None ) : try : current_value = dictionary key_list = key_list if isinstance ( key_list , list ) else [ key_list ] for key in key_list : current_value = current_value [ key ] return current_value except KeyError : return default_value
Take value from a given key list from dictionary .
27,241
def retrieve_exposure_classes_lists ( exposure_keywords ) : classification = exposure_keywords . get ( 'classification' ) if not classification : return None exposure_classifications = definition ( classification ) return exposure_classifications [ 'classes' ]
Retrieve exposures classes .
27,242
def initialize_minimum_needs_post_processors ( ) : processors = [ ] for field in minimum_needs_fields : field_key = field [ 'key' ] field_name = field [ 'name' ] field_description = field [ 'description' ] need_parameter = field [ 'need_parameter' ] processor = { 'key' : 'post_processor_{key}' . format ( key = field_ke...
Generate definitions for minimum needs post processors .
27,243
def layer_from_combo ( combo ) : index = combo . currentIndex ( ) if index < 0 : return None layer_id = combo . itemData ( index , Qt . UserRole ) layer = QgsProject . instance ( ) . mapLayer ( layer_id ) return layer
Get the QgsMapLayer currently selected in a combo .
27,244
def add_ordered_combo_item ( combo , text , data = None , count_selected_features = None , icon = None ) : if count_selected_features is not None : text += ' (' + tr ( '{count} selected features' ) . format ( count = count_selected_features ) + ')' size = combo . count ( ) for combo_index in range ( 0 , size ) : item_t...
Add a combo item ensuring that all items are listed alphabetically .
27,245
def send_static_message ( sender , message ) : dispatcher . send ( signal = STATIC_MESSAGE_SIGNAL , sender = sender , message = message )
Send a static message to the listeners .
27,246
def send_dynamic_message ( sender , message ) : dispatcher . send ( signal = DYNAMIC_MESSAGE_SIGNAL , sender = sender , message = message )
Send a dynamic message to the listeners .
27,247
def send_error_message ( sender , error_message ) : dispatcher . send ( signal = ERROR_MESSAGE_SIGNAL , sender = sender , message = error_message )
Send an error message to the listeners .
27,248
def analysis_error ( sender , exception , message ) : LOGGER . exception ( message ) message = get_error_message ( exception , context = message ) send_error_message ( sender , message )
A helper to spawn an error and halt processing .
27,249
def set_default ( self , default ) : try : default_index = self . _parameter . default_values . index ( default ) self . default_input_button_group . button ( default_index ) . setChecked ( True ) except ValueError : last_index = len ( self . _parameter . default_values ) - 1 self . default_input_button_group . button ...
Set default value by item s string .
27,250
def toggle_input ( self ) : current_index = self . input . currentIndex ( ) if self . input . itemData ( current_index , Qt . UserRole ) != ( self . radio_button_enabler ) : self . disable_radio_button ( ) else : self . enable_radio_button ( )
Change behaviour of radio button based on input .
27,251
def set_selected_radio_button ( self ) : dont_use_button = self . default_input_button_group . button ( len ( self . _parameter . default_values ) - 2 ) dont_use_button . setChecked ( True )
Set selected radio button to Do not report .
27,252
def disable_radio_button ( self ) : checked = self . default_input_button_group . checkedButton ( ) if checked : self . default_input_button_group . setExclusive ( False ) checked . setChecked ( False ) self . default_input_button_group . setExclusive ( True ) for button in self . default_input_button_group . buttons (...
Disable radio button group and custom value input area .
27,253
def enable_radio_button ( self ) : for button in self . default_input_button_group . buttons ( ) : button . setEnabled ( True ) self . set_selected_radio_button ( ) self . custom_value . setEnabled ( True )
Enable radio button and custom value input area then set selected radio button to Do not report .
27,254
def earthquake_fatality_rate ( hazard_level ) : earthquake_function = setting ( 'earthquake_function' , EARTHQUAKE_FUNCTIONS [ 0 ] [ 'key' ] , str ) ratio = 0 for model in EARTHQUAKE_FUNCTIONS : if model [ 'key' ] == earthquake_function : eq_function = model [ 'fatality_rates' ] ratio = eq_function ( ) . get ( hazard_l...
Earthquake fatality ratio for a given hazard level .
27,255
def itb_fatality_rates ( ) : mmi_range = list ( range ( 2 , 11 ) ) x = 0.62275231 y = 8.03314466 fatality_rate = { mmi : 0 if mmi < 4 else 10 ** ( x * mmi - y ) for mmi in mmi_range } return fatality_rate
Indonesian Earthquake Fatality Model .
27,256
def pager_fatality_rates ( ) : theta = 13.249 beta = 0.151 mmi_range = list ( range ( 2 , 11 ) ) fatality_rate = { mmi : 0 if mmi < 4 else log_normal_cdf ( mmi , median = theta , sigma = beta ) for mmi in mmi_range } return fatality_rate
USGS Pager fatality estimation model .
27,257
def normal_cdf ( x , mu = 0 , sigma = 1 ) : arg = ( x - mu ) / ( sigma * numpy . sqrt ( 2 ) ) res = ( 1 + erf ( arg ) ) / 2 return res
Cumulative Normal Distribution Function .
27,258
def log_normal_cdf ( x , median = 1 , sigma = 1 ) : return normal_cdf ( numpy . log ( x ) , mu = numpy . log ( median ) , sigma = sigma )
Cumulative Log Normal Distribution Function .
27,259
def erf ( z ) : try : len ( z ) except TypeError : scalar = True z = [ z ] else : scalar = False z = numpy . array ( z ) t = 1.0 / ( 1.0 + 0.5 * numpy . abs ( z ) ) ans = 1 - t * numpy . exp ( - z * z - 1.26551223 + t * ( 1.00002368 + t * ( 0.37409196 + t * ( 0.09678418 + t * ( - 0.18628806 + t * ( 0.27886807 + t * ( -...
Approximation to ERF .
27,260
def current_earthquake_model_name ( ) : default_earthquake_function = setting ( 'earthquake_function' , EARTHQUAKE_FUNCTIONS [ 0 ] [ 'key' ] , str ) current_function = None for model in EARTHQUAKE_FUNCTIONS : if model [ 'key' ] == default_earthquake_function : current_function = model [ 'name' ] return current_function
Human friendly name for the currently active earthquake fatality model .
27,261
def from_counts_to_ratios ( layer ) : output_layer_name = recompute_counts_steps [ 'output_layer_name' ] exposure = definition ( layer . keywords [ 'exposure' ] ) inasafe_fields = layer . keywords [ 'inasafe_fields' ] layer . keywords [ 'title' ] = output_layer_name if not population_count_field [ 'key' ] in inasafe_fi...
Transform counts to ratios .
27,262
def get_value ( self , ** kwargs ) : key = tuple ( kwargs [ group ] for group in self . groups ) if key not in self . data : self . data [ key ] = 0 return self . data [ key ]
Return the value for a specific key .
27,263
def group_values ( self , group_name ) : group_index = self . groups . index ( group_name ) values = [ ] for key in self . data_keys : if key [ group_index ] not in values : values . append ( key [ group_index ] ) return values
Return all distinct group values for given group .
27,264
def from_json ( self , json_string ) : obj = json . loads ( json_string ) self . from_dict ( obj [ 'groups' ] , obj [ 'data' ] ) return self
Override current FlatTable using data from json .
27,265
def from_dict ( self , groups , data ) : self . groups = tuple ( groups ) for item in data : kwargs = { } for i in range ( len ( self . groups ) ) : kwargs [ self . groups [ i ] ] = item [ i ] self . add_value ( item [ - 1 ] , ** kwargs ) return self
Populate FlatTable based on groups and data .
27,266
def needs_calculator_help ( ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( heading ( ) ) message . add ( content ( ) ) return message
Help message for needs calculator dialog .
27,267
def reproject ( layer , output_crs , callback = None ) : output_layer_name = reproject_steps [ 'output_layer_name' ] output_layer_name = output_layer_name % layer . keywords [ 'layer_purpose' ] processing_step = reproject_steps [ 'step_name' ] input_crs = layer . crs ( ) input_fields = layer . fields ( ) feature_count ...
Reproject a vector layer to a specific CRS .
27,268
def set_widgets ( self ) : self . tvBrowserHazard_selection_changed ( ) hazard = self . parent . step_fc_functions1 . selected_value ( layer_purpose_hazard [ 'key' ] ) icon_path = get_image_path ( hazard ) self . lblIconIFCWHazardFromBrowser . setPixmap ( QPixmap ( icon_path ) )
Set widgets on the Hazard Layer From Browser tab .
27,269
def validate_input ( self ) : self . exposure_layer = layer_from_combo ( self . dock . exposure_layer_combo ) self . hazard_layer = layer_from_combo ( self . dock . hazard_layer_combo ) self . aggregation_layer = layer_from_combo ( self . dock . aggregation_layer_combo ) is_valid = True warning_message = None if self ....
Validate the input before saving a scenario .
27,270
def save_scenario ( self , scenario_file_path = None ) : warning_title = tr ( 'InaSAFE Save Scenario Warning' ) is_valid , warning_message = self . validate_input ( ) if not is_valid : QMessageBox . warning ( self , warning_title , warning_message ) return if self . dock . extent . user_extent is not None and self . do...
Save current scenario to a text file .
27,271
def relative_path ( reference_path , input_path ) : start_path = os . path . dirname ( reference_path ) try : relative_path = os . path . relpath ( input_path , start_path ) except ValueError : relative_path = input_path return relative_path
Get the relative path to input_path from reference_path .
27,272
def info ( self ) : return { 'key' : self . key , 'processor' : self . processor , 'extractor' : self . extractor , 'output_path' : self . output_path , 'output_format' : self . output_format , 'template' : self . template , 'type' : type ( self ) }
Short info about the component .
27,273
def info ( self ) : return super ( QgisComposerComponentsMetadata , self ) . info . update ( { 'orientation' : self . orientation , 'page_dpi' : self . page_dpi , 'page_width' : self . page_width , 'page_height' : self . page_height } )
Short info of the metadata .
27,274
def component_by_key ( self , key ) : filtered = [ c for c in self . components if c . key == key ] if filtered : return filtered [ 0 ] return None
Retrieve component by its key .
27,275
def component_by_tags ( self , tags ) : tags_keys = [ t [ 'key' ] for t in tags ] filtered = [ c for c in self . components if set ( tags_keys ) . issubset ( [ ct [ 'key' ] for ct in c . tags ] ) ] return filtered
Retrieve components by tags .
27,276
def _normalize_field_name ( value ) : return_value = re . sub ( r'[^\w\s-]+' , '' , value ) return_value = re . sub ( r'\s+' , '_' , return_value ) return return_value . lower ( )
Normalizing value string used as key and field name .
27,277
def _initializes_minimum_needs_fields ( ) : needs_profile = NeedsProfile ( ) needs_profile . load ( ) fields = [ ] needs_parameters = needs_profile . get_needs_parameters ( ) for need_parameter in needs_parameters : if isinstance ( need_parameter , ResourceParameter ) : format_args = { 'namespace' : minimum_needs_names...
Initialize minimum needs fields .
27,278
def minimum_needs_parameter ( field = None , parameter_name = None ) : try : if field [ 'key' ] : for need_field in minimum_needs_fields : if need_field [ 'key' ] == field [ 'key' ] : return need_field [ 'need_parameter' ] except ( TypeError , KeyError ) : pass if parameter_name : for need_field in minimum_needs_fields...
Get minimum needs parameter from a given field .
27,279
def step_type ( self ) : if 'stepfc' in self . __class__ . __name__ . lower ( ) : return STEP_FC if 'stepkw' in self . __class__ . __name__ . lower ( ) : return STEP_KW
Whether it s a IFCW step or Keyword Wizard Step .
27,280
def help ( self ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( self . help_heading ( ) ) message . add ( self . help_content ( ) ) return message
Return full help message for the step wizard .
27,281
def help_heading ( self ) : message = m . Heading ( tr ( 'Help for {step_name}' ) . format ( step_name = self . step_name ) , ** SUBSECTION_STYLE ) return message
Helper method that returns just the header .
27,282
def get_help_html ( message = None ) : html = html_help_header ( ) if message is None : message = dock_help ( ) html += message . to_html ( ) html += html_footer ( ) return html
Create the HTML content for the help dialog or for external browser
27,283
def show_help ( message = None ) : help_path = mktemp ( '.html' ) with open ( help_path , 'wb+' ) as f : help_html = get_help_html ( message ) f . write ( help_html . encode ( 'utf8' ) ) path_with_protocol = 'file://' + help_path QDesktopServices . openUrl ( QUrl ( path_with_protocol ) )
Open an help message in the user s browser
27,284
def definitions_help ( ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( heading ( ) ) message . add ( content ( ) ) return message
Help message for Definitions .
27,285
def _make_defaults_hazard_table ( ) : table = m . Table ( style_class = 'table table-condensed table-striped' ) row = m . Row ( ) row . add ( m . Cell ( tr ( '' ) , header = True ) ) row . add ( m . Cell ( tr ( 'Name' ) , header = True ) ) row . add ( m . Cell ( tr ( 'Affected' ) , header = True ) ) row . add ( m . Cel...
Build headers for a table related to hazard classes .
27,286
def _make_defaults_exposure_table ( ) : table = m . Table ( style_class = 'table table-condensed table-striped' ) row = m . Row ( ) row . add ( m . Cell ( tr ( 'Name' ) , header = True ) ) row . add ( m . Cell ( tr ( 'Default values' ) , header = True ) ) table . add ( row ) return table
Build headers for a table related to exposure classes .
27,287
def _add_dict_to_bullets ( target , value ) : actions = value . get ( 'action_list' ) notes = value . get ( 'item_list' ) items_tobe_added = [ ] if actions : items_tobe_added = actions elif notes : items_tobe_added = notes if items_tobe_added : for item in items_tobe_added : target . add ( m . Text ( item ) ) return ta...
Add notes and actions in dictionary to the bullets
27,288
def selected_canvas_explayer ( self ) : if self . lstCanvasExpLayers . selectedItems ( ) : item = self . lstCanvasExpLayers . currentItem ( ) else : return None try : layer_id = item . data ( Qt . UserRole ) except ( AttributeError , NameError ) : layer_id = None layer = QgsProject . instance ( ) . mapLayer ( layer_id ...
Obtain the canvas exposure layer selected by user .
27,289
def set_widgets ( self ) : last_layer = self . parent . layer and self . parent . layer . id ( ) or None self . lblDescribeCanvasExpLayer . clear ( ) self . list_compatible_canvas_layers ( ) self . auto_select_one_item ( self . lstCanvasExpLayers ) if last_layer : layers = [ ] for indx in range ( self . lstCanvasExpLay...
Set widgets on the Exposure Layer From Canvas tab .
27,290
def IP_verified ( directory , extensions_to_ignore = None , directories_to_ignore = None , files_to_ignore = None , verbose = False ) : oldpath = None all_files = 0 ok_files = 0 all_files_accounted_for = True for dirpath , filename in identify_datafiles ( directory , extensions_to_ignore , directories_to_ignore , files...
Find and audit potential data files that might violate IP
27,291
def identify_datafiles ( root , extensions_to_ignore = None , directories_to_ignore = None , files_to_ignore = None ) : for dirpath , dirnames , filenames in walk ( root ) : for ignore in directories_to_ignore : if ignore in dirnames : dirnames . remove ( ignore ) for filename in filenames : ignore = False for ext in e...
Identify files that might contain data
27,292
def data ( self ) : if len ( self . widget_items ) == 0 : return data = { } for hazard_item in self . widget_items : hazard = hazard_item . data ( 0 , Qt . UserRole ) data [ hazard ] = { } classification_items = [ hazard_item . child ( i ) for i in range ( hazard_item . childCount ( ) ) ] for classification_item in cla...
Get the data from the current state of widgets .
27,293
def data ( self , profile_data ) : default_profile = generate_default_profile ( ) self . clear ( ) for hazard in sorted ( default_profile . keys ( ) ) : classifications = default_profile [ hazard ] hazard_widget_item = QTreeWidgetItem ( ) hazard_widget_item . setData ( 0 , Qt . UserRole , hazard ) hazard_widget_item . ...
Set data for the widget .
27,294
def selected_functions_2 ( self ) : selection = self . tblFunctions2 . selectedItems ( ) if len ( selection ) != 1 : return [ ] return selection [ 0 ] . data ( RoleFunctions )
Obtain functions available for hazard and exposure selected by user .
27,295
def set_widgets ( self ) : self . tblFunctions2 . clear ( ) hazard , exposure , _ , _ = self . parent . selected_impact_function_constraints ( ) hazard_layer_geometries = get_allowed_geometries ( layer_purpose_hazard [ 'key' ] ) exposure_layer_geometries = get_allowed_geometries ( layer_purpose_exposure [ 'key' ] ) sel...
Set widgets on the Impact Functions Table 2 tab .
27,296
def setValue ( self , p_float ) : p_float = p_float * 100 super ( PercentageSpinBox , self ) . setValue ( p_float )
Override method to set a value to show it as 0 to 100 .
27,297
def impact_path ( self , value ) : self . _impact_path = value if value is None : self . action_show_report . setEnabled ( False ) self . action_show_log . setEnabled ( False ) self . report_path = None self . log_path = None else : self . action_show_report . setEnabled ( True ) self . action_show_log . setEnabled ( T...
Setter to impact path .
27,298
def contextMenuEvent ( self , event ) : context_menu = QMenu ( self ) action_select_all = self . page ( ) . action ( QtWebKitWidgets . QWebPage . SelectAll ) action_select_all . setEnabled ( not self . page_to_text ( ) == '' ) context_menu . addAction ( action_select_all ) action_copy = self . page ( ) . action ( QtWeb...
Slot automatically called by Qt on right click on the WebView .
27,299
def static_message_event ( self , sender , message ) : self . static_message_count += 1 if message == self . static_message : return _ = sender self . dynamic_messages = [ ] self . static_message = message self . show_messages ( )
Static message event handler - set message state based on event .