idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
27,100 | def hide_busy ( self , check_next_impact = True ) : self . progress_bar . hide ( ) self . show_question_button . setVisible ( True ) self . question_group . setEnabled ( True ) self . question_group . setVisible ( False ) if check_next_impact : self . validate_impact_function ( ) self . repaint ( ) disable_busy_cursor ... | A helper function to indicate processing is done . |
27,101 | def show_impact ( self , report_path ) : with codecs . open ( report_path , 'r' , 'utf-8' ) as report_file : report = report_file . read ( ) self . print_button . setEnabled ( True ) send_static_message ( self , report ) self . show_question_button . setVisible ( True ) self . question_group . setEnabled ( True ) self ... | Show the report . |
27,102 | def show_generic_keywords ( self , layer ) : keywords = KeywordIO ( layer ) self . print_button . setEnabled ( False ) try : message = keywords . to_message ( ) send_static_message ( self , message ) except InvalidMessageItemError : pass self . show_question_button . setVisible ( False ) self . question_group . setEnab... | Show the keywords defined for the active layer . |
27,103 | def layer_changed ( self , layer ) : if self . get_layers_lock or layer is None : return if not self . _has_active_layer ( ) : if self . conflicting_plugin_detected : send_static_message ( self , conflicting_plugin_message ( ) ) else : send_static_message ( self , getting_started_message ( ) ) try : keywords = self . k... | Handler for when the QGIS active layer is changed . |
27,104 | def save_state ( self ) : state = { 'hazard' : self . hazard_layer_combo . currentText ( ) , 'exposure' : self . exposure_layer_combo . currentText ( ) , 'aggregation' : self . aggregation_layer_combo . currentText ( ) , 'report' : self . results_webview . page ( ) . currentFrame ( ) . toHtml ( ) } self . state = state | Save the current state of the ui to an internal class member . |
27,105 | def restore_state ( self ) : if self . state is None : return for myCount in range ( 0 , self . exposure_layer_combo . count ( ) ) : item_text = self . exposure_layer_combo . itemText ( myCount ) if item_text == self . state [ 'exposure' ] : self . exposure_layer_combo . setCurrentIndex ( myCount ) break for myCount in... | Restore the state of the dock to the last known state . |
27,106 | def define_user_analysis_extent ( self , extent , crs ) : extent = QgsGeometry . fromRect ( extent ) self . extent . set_user_extent ( extent , crs ) self . validate_impact_function ( ) | Slot called when user has defined a custom analysis extent . |
27,107 | def _search_inasafe_layer ( self ) : selected_nodes = self . iface . layerTreeView ( ) . selectedNodes ( ) for selected_node in selected_nodes : tree_layers = [ child for child in selected_node . children ( ) if ( isinstance ( child , QgsLayerTreeLayer ) ) ] for tree_layer in tree_layers : layer = tree_layer . layer ( ... | Search for an inasafe layer in an active group . |
27,108 | def _visible_layers_count ( self ) : treeroot = QgsProject . instance ( ) . layerTreeRoot ( ) return len ( [ lyr for lyr in treeroot . findLayers ( ) if lyr . isVisible ( ) ] ) | Calculate the number of visible layers in the legend . |
27,109 | def _validate_question_area ( self ) : hazard_index = self . hazard_layer_combo . currentIndex ( ) exposure_index = self . exposure_layer_combo . currentIndex ( ) if hazard_index == - 1 or exposure_index == - 1 : if self . conflicting_plugin_detected : message = conflicting_plugin_message ( ) else : message = getting_s... | Helper method to evaluate the current state of the dialog . |
27,110 | def default_value ( self , default_value ) : if default_value not in self . default_values : if len ( self . default_labels ) == len ( self . default_values ) : self . default_values [ - 1 ] = default_value else : self . default_values . append ( default_value ) self . _default_value = default_value | Setter for default_value . |
27,111 | def classFactory ( iface ) : try : from parameters . generic_parameter import GenericParameter except ImportError : QMessageBox . warning ( None , QCoreApplication . translate ( '@default' , 'InaSAFE submodule not found' ) , QCoreApplication . translate ( '@default' , 'InaSAFE could not find the submodule "parameters".... | Load Plugin class from file Plugin . |
27,112 | def metadata_converter_help ( ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( heading ( ) ) message . add ( content ( ) ) return message | Help message for metadata converter Dialog . |
27,113 | def qt_at_least ( needed_version , test_version = None ) : major , minor , patch = needed_version . split ( '.' ) needed_version = '0x0%s0%s0%s' % ( major , minor , patch ) needed_version = int ( needed_version , 0 ) installed_version = Qt . QT_VERSION if test_version is not None : installed_version = test_version if n... | Check if the installed Qt version is greater than the requested |
27,114 | def disable_busy_cursor ( ) : while QgsApplication . instance ( ) . overrideCursor ( ) is not None and QgsApplication . instance ( ) . overrideCursor ( ) . shape ( ) == QtCore . Qt . WaitCursor : QgsApplication . instance ( ) . restoreOverrideCursor ( ) | Disable the hourglass cursor and listen for layer changes . |
27,115 | def subcategories_for_layer ( self ) : purpose = self . parent . step_kw_purpose . selected_purpose ( ) layer_geometry_key = self . parent . get_layer_geometry_key ( ) if purpose == layer_purpose_hazard : return hazards_for_layer ( layer_geometry_key ) elif purpose == layer_purpose_exposure : return exposures_for_layer... | Return a list of valid subcategories for a layer . Subcategory is hazard type or exposure type . |
27,116 | def on_lstSubcategories_itemSelectionChanged ( self ) : self . clear_further_steps ( ) subcategory = self . selected_subcategory ( ) if not subcategory : return self . lblDescribeSubcategory . setText ( subcategory [ 'description' ] ) icon_path = get_image_path ( subcategory ) self . lblIconSubcategory . setPixmap ( QP... | Update subcategory description label . |
27,117 | def selected_subcategory ( self ) : item = self . lstSubcategories . currentItem ( ) try : return definition ( item . data ( QtCore . Qt . UserRole ) ) except ( AttributeError , NameError ) : return None | Obtain the subcategory selected by user . |
27,118 | def set_widgets ( self ) : self . clear_further_steps ( ) purpose = self . parent . step_kw_purpose . selected_purpose ( ) self . lstSubcategories . clear ( ) self . lblDescribeSubcategory . setText ( '' ) self . lblIconSubcategory . setPixmap ( QPixmap ( ) ) self . lblSelectSubcategory . setText ( get_question_text ( ... | Set widgets on the Subcategory tab . |
27,119 | def select_output_directory ( self ) : input_layer_path = self . layer . source ( ) input_file_name = os . path . basename ( input_layer_path ) input_extension = os . path . splitext ( input_file_name ) [ 1 ] current_file_path = self . output_path_line_edit . text ( ) if not current_file_path or not os . path . exists ... | Select output directory |
27,120 | def show_current_metadata ( self ) : LOGGER . debug ( 'Showing layer: ' + self . layer . name ( ) ) keywords = KeywordIO ( self . layer ) content_html = keywords . to_message ( ) . to_html ( ) full_html = html_header ( ) + content_html + html_footer ( ) self . metadata_preview_web_view . setHtml ( full_html ) | Show metadata of the current selected layer . |
27,121 | def get_user_name ( ) : if sys . platform == 'win32' : user = os . getenv ( 'USERNAME' ) else : user = os . getenv ( 'LOGNAME' ) return user | Get user name provide by operating system |
27,122 | def get_host_name ( ) : if sys . platform == 'win32' : host = os . getenv ( 'COMPUTERNAME' ) else : host = os . uname ( ) [ 1 ] return host | Get host name provide by operating system |
27,123 | def compute_checksum ( filename , max_length = 2 ** 20 ) : fid = open ( filename , 'rb' ) crcval = safe_crc ( fid . read ( max_length ) ) fid . close ( ) return crcval | Compute the CRC32 checksum for specified file |
27,124 | def clean_line ( str , delimiter ) : return [ x . strip ( ) for x in str . strip ( ) . split ( delimiter ) if x != '' ] | Split string on given delimiter remove whitespace from each field . |
27,125 | def string_to_char ( l ) : if not l : return [ ] if l == [ '' ] : l = [ ' ' ] maxlen = reduce ( max , map ( len , l ) ) ll = [ x . ljust ( maxlen ) for x in l ] result = [ ] for s in ll : result . append ( [ x for x in s ] ) return result | Convert 1 - D list of strings to 2 - D list of chars . |
27,126 | def get_vars_in_expression ( source ) : import compiler from compiler . ast import Node def get_vars_body ( node , var_list = [ ] ) : if isinstance ( node , Node ) : if node . __class__ . __name__ == 'Name' : for child in node . getChildren ( ) : if child not in var_list : var_list . append ( child ) for child in node ... | Get list of variable names in a python expression . |
27,127 | def tar_file ( files , tarname ) : if isinstance ( files , basestring ) : files = [ files ] o = tarfile . open ( tarname , 'w:gz' ) for file in files : o . add ( file ) o . close ( ) | Compress a file or directory into a tar file . |
27,128 | def untar_file ( tarname , target_dir = '.' ) : o = tarfile . open ( tarname , 'r:gz' ) members = o . getmembers ( ) for member in members : o . extract ( member , target_dir ) o . close ( ) | Uncompress a tar file . |
27,129 | def get_file_hexdigest ( filename , blocksize = 1024 * 1024 * 10 ) : if hashlib . __name__ == 'hashlib' : m = hashlib . md5 ( ) else : m = hashlib . new ( ) fd = open ( filename , 'r' ) while True : data = fd . read ( blocksize ) if len ( data ) == 0 : break m . update ( data ) fd . close ( ) return m . hexdigest ( ) | Get a hex digest of a file . |
27,130 | def make_digest_file ( data_file , digest_file ) : hexdigest = get_file_hexdigest ( data_file ) fd = open ( digest_file , 'w' ) fd . write ( hexdigest ) fd . close ( ) | Create a file containing the hex digest string of a data file . |
27,131 | def file_length ( in_file ) : fid = open ( in_file ) data = fid . readlines ( ) fid . close ( ) return len ( data ) | Function to return the length of a file . |
27,132 | def convert_geojson_to_shapefile ( geojson_path ) : layer = QgsVectorLayer ( geojson_path , 'vector layer' , 'ogr' ) if not layer . isValid ( ) : return False shapefile_path = os . path . splitext ( geojson_path ) [ 0 ] + '.shp' QgsVectorFileWriter . writeAsVectorFormat ( layer , shapefile_path , 'utf-8' , layer . crs ... | Convert geojson file to shapefile . |
27,133 | def peta_bencana_help ( ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( heading ( ) ) message . add ( content ( ) ) return message | Help message for PetaBencana dialog . |
27,134 | def add ( self , item , header_flag = False , align = None ) : if self . _is_stringable ( item ) or self . _is_qstring ( item ) : self . cells . append ( Cell ( item , header = header_flag , align = align ) ) elif isinstance ( item , Cell ) : self . cells . append ( item ) elif isinstance ( item , Image ) : self . cell... | Add a Cell to the row |
27,135 | def generate_insufficient_overlap_message ( e , exposure_geoextent , exposure_layer , hazard_geoextent , hazard_layer , viewport_geoextent ) : description = tr ( 'There was insufficient overlap between the input layers and / or the ' 'layers and the viewable area. Please select two overlapping layers ' 'and zoom or pan... | Generate insufficient overlap message . |
27,136 | def singleton ( class_ ) : instances = { } def get_instance ( * args , ** kwargs ) : if class_ not in instances : instances [ class_ ] = class_ ( * args , ** kwargs ) return instances [ class_ ] return get_instance | Singleton definition . |
27,137 | def population_chart_legend_extractor ( impact_report , component_metadata ) : context = { } context [ 'inasafe_resources_base_dir' ] = resources_path ( ) population_donut_path = impact_report . component_absolute_output_path ( 'population-chart-png' ) css_label_classes = [ ] try : population_chart_context = impact_rep... | Extracting legend of population chart . |
27,138 | def infographic_people_section_notes_extractor ( impact_report , component_metadata ) : extra_args = component_metadata . extra_args provenance = impact_report . impact_function . provenance hazard_keywords = provenance [ 'hazard_keywords' ] exposure_keywords = provenance [ 'exposure_keywords' ] context = { } context [... | Extracting notes for people section in the infographic . |
27,139 | def is_ready_to_next_step ( self ) : if self . mode == EDIT_MODE : return False for combo_box in self . exposure_combo_boxes : if combo_box . currentIndex ( ) > 0 : return True if self . use_default_thresholds : return True return False | Check if the step is complete . |
27,140 | def set_wizard_step_description ( self ) : subcategory = self . parent . step_kw_subcategory . selected_subcategory ( ) field = self . parent . step_kw_field . selected_fields ( ) is_raster = is_raster_layer ( self . parent . layer ) if is_raster : if self . layer_mode == layer_mode_continuous : text_label = multiple_c... | Set the text for description . |
27,141 | def edit_button_clicked ( self , edit_button , exposure_combo_box , exposure ) : classification = self . get_classification ( exposure_combo_box ) if self . mode == CHOOSE_MODE : self . mode = EDIT_MODE self . active_exposure = exposure for exposure_edit_button in self . exposure_edit_buttons : exposure_edit_button . s... | Method to handle when an edit button is clicked . |
27,142 | def set_widgets ( self ) : self . clear ( ) self . layer_mode = self . parent . step_kw_layermode . selected_layermode ( ) self . layer_purpose = self . parent . step_kw_purpose . selected_purpose ( ) self . set_current_state ( ) self . set_wizard_step_description ( ) self . setup_left_panel ( ) self . show_current_sta... | Set widgets on the Multi classification step . |
27,143 | def add_buttons ( self , classification ) : if self . layer_mode == layer_mode_continuous [ 'key' ] : self . restore_default_button = QPushButton ( tr ( 'Restore Default' ) ) self . restore_default_button . clicked . connect ( partial ( self . restore_default_button_clicked , classification = classification ) ) self . ... | Helper to setup 3 buttons . |
27,144 | def update_dragged_item_flags ( self , item ) : if int ( item . flags ( ) & Qt . ItemIsDropEnabled ) and int ( item . flags ( ) & Qt . ItemIsDragEnabled ) : item . setFlags ( item . flags ( ) & ~ Qt . ItemIsDropEnabled ) | Fix the drop flag after the item is dropped . |
27,145 | def cancel_button_clicked ( self ) : self . mode = CHOOSE_MODE for i in range ( len ( self . exposures ) ) : if i == self . special_case_index : self . exposure_edit_buttons [ i ] . setEnabled ( False ) self . exposure_combo_boxes [ i ] . setEnabled ( False ) continue if self . get_classification ( self . exposure_comb... | Action for cancel button clicked . |
27,146 | def save_button_clicked ( self , classification ) : if self . layer_mode == layer_mode_continuous : thresholds = self . get_threshold ( ) classification_class = { 'classes' : thresholds , 'active' : True } if self . thresholds . get ( self . active_exposure [ 'key' ] ) : for current_classification in list ( self . thre... | Action for save button clicked . |
27,147 | def restore_default_button_clicked ( self , classification ) : class_dict = { } for the_class in classification . get ( 'classes' ) : class_dict [ the_class [ 'key' ] ] = { 'numeric_default_min' : the_class [ 'numeric_default_min' ] , 'numeric_default_max' : the_class [ 'numeric_default_max' ] , } for key , value in li... | Action for restore default button clicked . |
27,148 | def get_threshold ( self ) : value_map = dict ( ) for key , value in list ( self . threshold_classes . items ( ) ) : value_map [ key ] = [ value [ 0 ] . value ( ) , value [ 1 ] . value ( ) , ] return value_map | Return threshold based on current state . |
27,149 | def set_current_state ( self ) : if not self . thresholds : self . thresholds = self . parent . get_existing_keyword ( 'thresholds' ) if not self . value_maps : self . value_maps = self . parent . get_existing_keyword ( 'value_maps' ) | Helper to set the state of the step from current keywords . |
27,150 | def classifications_combo_box_changed ( self , index , exposure , exposure_combo_box , edit_button ) : edit_button . setEnabled ( bool ( index ) ) classification = self . get_classification ( exposure_combo_box ) self . activate_classification ( exposure , classification ) clear_layout ( self . right_layout ) self . sh... | Action when classification combo box changed . |
27,151 | def activate_classification ( self , exposure , classification = None ) : if self . layer_mode == layer_mode_continuous : selected_unit = self . parent . step_kw_unit . selected_unit ( ) [ 'key' ] target = self . thresholds . get ( exposure [ 'key' ] ) if target is None : self . thresholds [ exposure [ 'key' ] ] = { } ... | Set active to True for classification for the exposure . |
27,152 | def set_inasafe_default_value_qsetting ( qsetting , category , inasafe_field_key , value ) : key = 'inasafe/default_value/%s/%s' % ( category , inasafe_field_key ) qsetting . setValue ( key , value ) | Helper method to set inasafe default value to qsetting . |
27,153 | def get_inasafe_default_value_qsetting ( qsetting , category , inasafe_field_key ) : key = 'inasafe/default_value/%s/%s' % ( category , inasafe_field_key ) default_value = qsetting . value ( key ) if default_value is None : if category == GLOBAL : inasafe_field = definition ( inasafe_field_key ) default_value = inasafe... | Helper method to get the inasafe default value from qsetting . |
27,154 | def download ( self ) : self . output_file = QFile ( self . output_path ) if not self . output_file . open ( QFile . WriteOnly ) : raise IOError ( self . output_file . errorString ( ) ) self . downloaded_file_buffer = QByteArray ( ) request = QNetworkRequest ( self . url ) self . reply = self . manager . get ( request ... | Downloading the file . |
27,155 | def get_buffer ( self ) : buffer_size = self . reply . size ( ) data = self . reply . read ( buffer_size ) self . downloaded_file_buffer . append ( data ) | Get buffer from self . reply and store it to our buffer container . |
27,156 | def on_leTitle_textChanged ( self ) : self . parent . pbnNext . setEnabled ( bool ( self . leTitle . text ( ) ) ) | Unlock the Next button |
27,157 | def set_widgets ( self ) : if self . parent . layer : if self . parent . get_existing_keyword ( 'title' ) : title = self . parent . get_existing_keyword ( 'title' ) else : title = self . parent . layer . name ( ) self . leTitle . setText ( title ) | Set widgets on the Title tab . |
27,158 | def start_capture ( self ) : previous_map_tool = self . canvas . mapTool ( ) if previous_map_tool != self . tool : self . previous_map_tool = previous_map_tool self . canvas . setMapTool ( self . tool ) self . hide ( ) | Start capturing the rectangle . |
27,159 | def stop_capture ( self ) : self . _populate_coordinates ( ) self . canvas . setMapTool ( self . previous_map_tool ) self . show ( ) | Stop capturing the rectangle and reshow the dialog . |
27,160 | def clear ( self ) : self . tool . reset ( ) self . _populate_coordinates ( ) self . hazard_exposure_view_extent . setChecked ( True ) | Clear the currently set extent . |
27,161 | def reject ( self ) : self . canvas . unsetMapTool ( self . tool ) if self . previous_map_tool != self . tool : self . canvas . setMapTool ( self . previous_map_tool ) self . tool . reset ( ) self . extent_selector_closed . emit ( ) super ( ExtentSelectorDialog , self ) . reject ( ) | User rejected the rectangle . |
27,162 | def accept ( self ) : mode = None if self . hazard_exposure_view_extent . isChecked ( ) : mode = HAZARD_EXPOSURE_VIEW elif self . exposure_only . isChecked ( ) : mode = EXPOSURE elif self . hazard_exposure_only . isChecked ( ) : mode = HAZARD_EXPOSURE elif self . hazard_exposure_bookmark . isChecked ( ) : mode = HAZARD... | User accepted the rectangle . |
27,163 | def _are_coordinates_valid ( self ) : try : QgsPointXY ( self . x_minimum . value ( ) , self . y_maximum . value ( ) ) QgsPointXY ( self . x_maximum . value ( ) , self . y_minimum . value ( ) ) except ValueError : return False return True | Check if the coordinates are valid . |
27,164 | def _coordinates_changed ( self ) : if self . _are_coordinates_valid ( ) : point1 = QgsPointXY ( self . x_minimum . value ( ) , self . y_maximum . value ( ) ) point2 = QgsPointXY ( self . x_maximum . value ( ) , self . y_minimum . value ( ) ) rect = QgsRectangle ( point1 , point2 ) self . tool . set_rectangle ( rect ) | Handle a change in the coordinate input boxes . |
27,165 | def _populate_coordinates ( self ) : rect = self . tool . rectangle ( ) self . blockSignals ( True ) if not rect . isEmpty ( ) : self . x_minimum . setValue ( rect . xMinimum ( ) ) self . y_minimum . setValue ( rect . yMinimum ( ) ) self . x_maximum . setValue ( rect . xMaximum ( ) ) self . y_maximum . setValue ( rect ... | Update the UI with the current active coordinates . |
27,166 | def bookmarks_index_changed ( self ) : index = self . bookmarks_list . currentIndex ( ) if index >= 0 : self . tool . reset ( ) rectangle = self . bookmarks_list . itemData ( index ) self . tool . set_rectangle ( rectangle ) self . canvas . setExtent ( rectangle ) self . ok_button . setEnabled ( True ) else : self . ok... | Update the UI when the bookmarks combobox has changed . |
27,167 | def on_hazard_exposure_bookmark_toggled ( self , enabled ) : if enabled : self . bookmarks_index_changed ( ) else : self . ok_button . setEnabled ( True ) self . _populate_coordinates ( ) | Update the UI when the user toggles the bookmarks radiobutton . |
27,168 | def _populate_bookmarks_list ( self ) : db_file_path = QgsApplication . qgisUserDatabaseFilePath ( ) db = sqlite3 . connect ( db_file_path ) cursor = db . cursor ( ) cursor . execute ( 'SELECT COUNT(*) ' 'FROM sqlite_master ' 'WHERE type=\'table\' ' 'AND name=\'tbl_bookmarks\';' ) number_of_rows = cursor . fetchone ( )... | Read the sqlite database and populate the bookmarks list . |
27,169 | def basestring_to_message ( text ) : if isinstance ( text , Message ) : return text elif text is None : return '' else : report = m . Message ( ) report . add ( text ) return report | Convert a basestring to a Message object if needed . |
27,170 | def get_error_message ( exception , context = None , suggestion = None ) : name , trace = humanise_exception ( exception ) problem = m . Message ( name ) if exception is None or exception == '' : problem . append = m . Text ( tr ( 'No details provided' ) ) else : if hasattr ( exception , 'message' ) and isinstance ( ex... | Convert exception into an ErrorMessage containing a stack trace . |
27,171 | def humanise_exception ( exception ) : trace = '' . join ( traceback . format_tb ( sys . exc_info ( ) [ 2 ] ) ) name = exception . __class__ . __name__ return name , trace | Humanise a python exception by giving the class name and traceback . |
27,172 | def html_to_file ( html , file_path = None , open_browser = False ) : if file_path is None : file_path = unique_filename ( suffix = '.html' ) html = html with codecs . open ( file_path , 'w' , encoding = 'utf-8' ) as f : f . write ( html ) if open_browser : open_in_browser ( file_path ) | Save the html to an html file adapting the paths to the filesystem . |
27,173 | def is_keyword_version_supported ( keyword_version , inasafe_version = inasafe_keyword_version ) : def minor_version ( version ) : version_split = version . split ( '.' ) return version_split [ 0 ] + '.' + version_split [ 1 ] keyword_version = minor_version ( keyword_version ) inasafe_version = minor_version ( inasafe_... | Check if the keyword version is supported by this InaSAFE version . |
27,174 | def write_json ( data , filename ) : def custom_default ( obj ) : if obj is None or ( hasattr ( obj , 'isNull' ) and obj . isNull ( ) ) : return '' raise TypeError with open ( filename , 'w' ) as json_file : json . dump ( data , json_file , indent = 2 , default = custom_default ) | Custom handler for writing json file in InaSAFE . |
27,175 | def monkey_patch_keywords ( layer ) : keyword_io = KeywordIO ( ) try : layer . keywords = keyword_io . read_keywords ( layer ) except ( NoKeywordsFoundError , MetadataReadError ) : layer . keywords = { } if not layer . keywords . get ( 'inasafe_fields' ) : layer . keywords [ 'inasafe_fields' ] = { } if not layer . keyw... | In InaSAFE V4 we do monkey patching for keywords . |
27,176 | def readable_os_version ( ) : if platform . system ( ) == 'Linux' : return _linux_os_release ( ) elif platform . system ( ) == 'Darwin' : return ' {version}' . format ( version = platform . mac_ver ( ) [ 0 ] ) elif platform . system ( ) == 'Windows' : return platform . platform ( ) | Give a proper name for OS version |
27,177 | def is_plugin_installed ( name ) : for directory in plugin_paths : if isdir ( join ( directory , name ) ) : return True return False | Check if a plugin is installed even if it s not enabled . |
27,178 | def reload_inasafe_modules ( module_name = None ) : if not module_name : module_name = 'safe' list_modules = list ( sys . modules . keys ( ) ) for module in list_modules : if not sys . modules [ module ] : continue if module . startswith ( module_name ) : del sys . modules [ module ] | Reload python modules . |
27,179 | def populate_field_list ( self , excluded_fields = None ) : if excluded_fields is None : excluded_fields = [ ] self . field_list . clear ( ) for field in self . layer . fields ( ) : if field . name ( ) in excluded_fields : continue if field . type ( ) not in qvariant_numbers : continue field_item = QListWidgetItem ( se... | Helper to add field of the layer to the list . |
27,180 | def get_parameter_value ( self ) : parameters = self . parameter_container . get_parameters ( True ) field_parameters = { } value_parameters = { } for parameter in parameters : if parameter . selected_option_type ( ) in [ SINGLE_DYNAMIC , STATIC ] : value_parameters [ parameter . guid ] = parameter . value elif paramet... | Get parameter of the tab . |
27,181 | def update_footer ( self ) : field_item = self . field_list . currentItem ( ) if not field_item : self . footer_label . setText ( '' ) return field_name = field_item . data ( Qt . UserRole ) field = self . layer . fields ( ) . field ( field_name ) index = self . layer . fields ( ) . lookupField ( field_name ) unique_va... | Update footer when the field list change . |
27,182 | def drop_remove ( * args , ** kwargs ) : dropped_item = args [ 0 ] field_list = kwargs [ 'field_list' ] num_duplicate = 0 for i in range ( field_list . count ( ) ) : if dropped_item . text ( ) == field_list . item ( i ) . text ( ) : num_duplicate += 1 if num_duplicate > 1 : field_list . takeItem ( field_list . row ( dr... | Action when we need to remove dropped item . |
27,183 | def smart_clip ( layer_to_clip , mask_layer ) : output_layer_name = smart_clip_steps [ 'output_layer_name' ] writer = create_memory_layer ( output_layer_name , layer_to_clip . geometryType ( ) , layer_to_clip . crs ( ) , layer_to_clip . fields ( ) ) writer . startEditing ( ) request = QgsFeatureRequest ( ) . setSubsetO... | Smart clip a vector layer with another . |
27,184 | def missing_keyword_message ( sender , missing_keyword_exception ) : warning_heading = m . Heading ( tr ( 'Missing Keyword' ) , ** WARNING_STYLE ) warning_message = tr ( 'There is missing keyword that needed for this analysis.' ) detail_heading = m . Heading ( tr ( 'Detail' ) , ** DETAILS_STYLE ) suggestion_heading = m... | Display an error when there is missing keyword . |
27,185 | def conflicting_plugin_message ( ) : message = m . Message ( ) message . add ( LOGO_ELEMENT ) message . add ( m . Heading ( tr ( 'Conflicting plugin detected' ) , ** WARNING_STYLE ) ) notes = m . Paragraph ( conflicting_plugin_string ( ) ) message . add ( notes ) return message | Unfortunately one plugin is conflicting with InaSAFE . |
27,186 | def getting_started_message ( ) : message = m . Message ( ) message . add ( LOGO_ELEMENT ) message . add ( m . Heading ( tr ( 'Getting started' ) , ** INFO_STYLE ) ) notes = m . Paragraph ( tr ( 'These are the minimum steps you need to follow in order ' 'to use InaSAFE:' ) ) message . add ( notes ) basics_list = m . Nu... | Generate a message for initial application state . |
27,187 | def ready_message ( ) : title = m . Heading ( tr ( 'Ready' ) , ** PROGRESS_UPDATE_STYLE ) notes = m . Paragraph ( tr ( 'You can now proceed to run your analysis by clicking the ' ) , m . EmphasizedText ( tr ( 'Run' ) , ** KEYWORD_STYLE ) , tr ( 'button.' ) ) message = m . Message ( LOGO_ELEMENT , title , notes ) return... | Helper to create a message indicating inasafe is ready . |
27,188 | def show_keyword_version_message ( sender , keyword_version , inasafe_version ) : LOGGER . debug ( 'Showing Mismatch Version Message' ) message = generate_input_error_message ( tr ( 'Layer Keyword\'s Version Mismatch:' ) , m . Paragraph ( tr ( 'Your layer\'s keyword\'s version ({layer_version}) does not ' 'match with y... | Show a message indicating that the keywords version is mismatch |
27,189 | def show_keywords_need_review_message ( sender , message = None ) : LOGGER . debug ( 'Showing incorrect keywords for v4 message' ) message = generate_input_error_message ( tr ( 'Layer Keywords Outdated:' ) , m . Paragraph ( tr ( 'Please update the keywords for your layers and then ' 'try to run the analysis again. Use ... | Show a message keywords are not adequate to run an analysis . |
27,190 | def generate_input_error_message ( header , text ) : report = m . Message ( ) report . add ( LOGO_ELEMENT ) report . add ( m . Heading ( header , ** WARNING_STYLE ) ) report . add ( text ) return report | Generate an error message with a header and a text . |
27,191 | def enable_messaging ( message_viewer , sender = dispatcher . Any ) : LOGGER . debug ( 'enable_messaging %s %s' % ( message_viewer , sender ) ) dispatcher . connect ( message_viewer . dynamic_message_event , signal = DYNAMIC_MESSAGE_SIGNAL , sender = sender ) dispatcher . connect ( message_viewer . static_message_event... | Set up the dispatcher for messaging . |
27,192 | def options_help ( ) : message = m . Message ( ) message . add ( m . Brand ( ) ) message . add ( heading ( ) ) message . add ( content ( ) ) return message | Help message for options dialog . |
27,193 | def minimum_needs_extractor ( impact_report , component_metadata ) : context = { } extra_args = component_metadata . extra_args analysis_layer = impact_report . analysis analysis_keywords = analysis_layer . keywords [ 'inasafe_fields' ] use_rounding = impact_report . impact_function . use_rounding header = resolve_from... | Extracting minimum needs of the impact layer . |
27,194 | def to_text ( self ) : if self . items is None : return else : text = '' for item in self . items : text += ' - %s\n' % item . to_text ( ) return text | Render a Text MessageElement as plain text . |
27,195 | def deep_convert_dict ( value ) : to_ret = value if isinstance ( value , OrderedDict ) : to_ret = dict ( value ) try : for k , v in to_ret . items ( ) : to_ret [ k ] = deep_convert_dict ( v ) except AttributeError : pass return to_ret | Converts any OrderedDict elements in a value to ordinary dictionaries safe for storage in QSettings |
27,196 | def set_general_setting ( key , value , qsettings = None ) : if not qsettings : qsettings = QSettings ( ) qsettings . setValue ( key , deep_convert_dict ( value ) ) | Set value to QSettings based on key . |
27,197 | def general_setting ( key , default = None , expected_type = None , qsettings = None ) : if qsettings is None : qsettings = QSettings ( ) try : if isinstance ( expected_type , type ) : return qsettings . value ( key , default , type = expected_type ) else : return qsettings . value ( key , default ) except TypeError as... | Helper function to get a value from settings . |
27,198 | def set_setting ( key , value , qsettings = None ) : full_key = '%s/%s' % ( APPLICATION_NAME , key ) set_general_setting ( full_key , value , qsettings ) | Set value to QSettings based on key in InaSAFE scope . |
27,199 | def setting ( key , default = None , expected_type = None , qsettings = None ) : if default is None : default = inasafe_default_settings . get ( key , None ) full_key = '%s/%s' % ( APPLICATION_NAME , key ) return general_setting ( full_key , default , expected_type , qsettings ) | Helper function to get a value from settings under InaSAFE scope . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.