def get_des_nt_constr(self, des_count_attr_name: str, des_nt_class_name: str, nt_key_prfx: str) -> callable: """ Getter method for desired namedtuple constructor Parameters ---------- des_count_attr_name: str name of attribute holding count info des_nt_class_name: str name of the namedtuple callable created nt_key_prfx: str prefix for namedtuple keys Returns ------- callable namedtuple callable """ entries_count = getattr(self, des_count_attr_name) chck_entries_count = safe_to_int(entries_count) # print('{}_{}'.format(nt_key_prfx, str(0))) entries_names = \ ['{}_{}'.format(nt_key_prfx, entry_id) for entry_id in range(1, int(chck_entries_count) + 1)] # print(entries_names) return namedtuple(des_nt_class_name, ' '.join(entries_names))
def extract_param( self, line_to_parse: str, setting_oper_regex: str = '\\s{0,1}=\\s', comment_regex: str = '^%') -> tuple or None: """ Parses single line in search of the param indicator regex - if found extracts the param name and the default/assigned value Parameters ---------- line_to_parse: str input line to be scanned for param regex setting_oper_regex: str regex to find setting operator inside parsed line comment_regex: str regex to determine if line is commented Returns ------- tuple or None (param name, default/provided param value) """ print('\n \n # # # # # # #') print('parsing param from line') print(line_to_parse) if re.search(comment_regex, line_to_parse): print('this is a commented line - skipping') return None raw_param_name = re.search(setting_oper_regex, line_to_parse) if not raw_param_name: print('No setter regex found') return None param_key = line_to_parse[:raw_param_name.start()] param_value_raw = \ re.sub('[\n\t]$', '', line_to_parse[raw_param_name.end():]) # conversion param_value = safe_to_float(param_value_raw) if not param_value: param_value = safe_to_int(param_value_raw) if not param_value: param_value = param_value_raw.strip() print(param_key, param_value) # print( # line_to_parse[:raw_param_name.start()], # line_to_parse[raw_param_name.end():]) # return line_to_parse[:raw_param_name.start()], \ # line_to_parse[raw_param_name.end():] return param_key, param_value
def _set_tb_saved_cfg_dict(self): """ Sets dict to be saved based on disabled controls and tabs Returns ------- """ tb_saved_dict = {} # self.dsbld_sctns self._set_dsbld_sctns() for section_key, section in self.su2_cfg_obj.parsed_su2_cfg.items(): if section_key not in self.dsbld_sctns: sctn_params_dict = {} for param_name, param_dict in section.items(): print(param_name) print(param_dict) if param_dict['control_toogle'].value: sctn_params_dict[param_name] = {} sctn_params_dict[param_name]['tooltip'] = \ param_dict['tooltip'] saved_param_val = None if 'iter' in param_name or 'ITER' in param_name: print('converting to float') float_frm_str = \ safe_to_float(param_dict['control'].value) if not float_frm_str: saved_param_val = None else: saved_param_val = \ safe_to_int(float_frm_str) if not saved_param_val: print('conv to int failed') saved_param_val = param_dict['control'].value sctn_params_dict[param_name]['value'] = saved_param_val # param_dict['control'].value if sctn_params_dict: tb_saved_dict[section_key] = sctn_params_dict self.tb_saved_dict = tb_saved_dict
def _get_vert_tab_w(self, width_decrement: int = 250) -> VerticalTabsWidget: """ Getter for vertical tabs widget width_decrement: int the number of pxls to reduce tabs width Returns ------- VerticalTabsWidget VerticalTabsWidget with desired tabs """ width, height = get_screen_res() alwd_width = width - width_decrement min_des_width = safe_to_int(val_to_cast=alwd_width * 0.9) if not self.su2_cfg: raise ValueError('SU2 cfg obejct can t be empty') return \ VerticalTabsWidget( su2_cfg_obj=self.su2_cfg, # initial_max_height=height, initial_min_width=min_des_width, initial_max_width=alwd_width)
def get_param_allowed_vals( self, param_default_value: str, raw_pre_param_comment: str, curr_chunk_name: str, yes_no_allowed_vals_rgx: str = '(\\(|\\s)(YES|NO)(,\\s|\\/)(YES|NO)(\\)|\\s)', common_allowed_vals_rgx: str = '(\\(|\\s)(([A-Z]{1,})((\\_|\\-){0,1})([A-Z]{1,})' '(,\\s){0,1}){1,}(\\)|\\s)', # common_allowed_vals_rgx='(\(|\s)(((\_|\-){0,1}([A-Z]{1,})(\_|\-){0,1}){1,}(,\s){0,1}){1,}(\)|\s)', different_sections: tuple = (('OPTIMAL_SHAPE_DESIGN_DEFINITION', ''),)) -> tuple or None: """ Gets available options (if they are given) for a given param line Parameters ---------- param_default_value: str extracted default value of the parameter raw_pre_param_comment: str extracted comment preceding the parameter flattened to single string curr_chunk_name: str the extracted namae of currently processed chunk yes_no_allowed_vals_rgx: str rgx used for YES/NO allowed values extraction common_allowed_vals_rgx: str rgx for all other allowed vals extraction different_sections: tuple tuple-like dict storing special sections rgxs ina way ((chunk name, chunk rgx), ..) Returns ------- tuple or None tuple with possible options for a given parameter """ is_param_string = False cast_defualt_val = safe_to_int(param_default_value) if not cast_defualt_val: cast_defualt_val = safe_to_float(param_default_value) if not cast_defualt_val: is_param_string = True if not is_param_string: return None # check trivial case - YES/No dict # raw_pre_param_cmnt_no_t = raw_pre_param_comment.replace('\n', '') # pre_param_comment = raw_pre_param_cmnt_no_t.replace('\t', '') pre_param_comment = \ self._get_fixed_pre_param_cmnt( raw_pre_param_cmnt=raw_pre_param_comment) print('pre_param_comment') print(pre_param_comment) if self._is_yes_no_opts( pre_param_comment, yes_no_rgx=yes_no_allowed_vals_rgx): return self.yes_no_allowed_vals different_sections_info = {} for section_name, section_rgx in unpack_tuple_of_tuples( different_sections): different_sections_info[section_name] = section_rgx if curr_chunk_name in different_sections_info.keys(): # parse chunk using special provided rgx return None else: print('common_allowed_vals_rgx') print(common_allowed_vals_rgx) print('pre_param_comment') print(pre_param_comment) opts_founds_occurances = \ re.search(common_allowed_vals_rgx, pre_param_comment) print('opts_founds_occurances') print(opts_founds_occurances) if not opts_founds_occurances: return None found_string = \ get_found_str(pre_param_comment, opts_founds_occurances) found_opts = self.get_allowed_vals_tuple_from_str(found_string) return found_opts
def __init__(self, point_count: str or int, point_attr_prfx: str = 'point'): self.point_count = safe_to_int(point_count) self.point_attr_prfx = point_attr_prfx self._set_all_points_attrs()