def export_empty_text_from_hdf5(unit_type, unit_min, unit_max, filename, path_prj): # headers headers = unit_type.replace(" ", "") headers = headers.replace("discharge", "Q") headers = headers.replace(" ", "") # lines linetext1 = str(unit_min) linetext2 = str(unit_max) text = headers + "\n" + linetext1 + "\n" + linetext2 # export try: output_full_path = os.path.join( path_prj, "output", "text", os.path.splitext(filename)[0] + "_empty_chronicle.txt") with open(output_full_path, 'wt') as f: # change decimal point locale = QLocale() if locale.decimalPoint() == ",": text = text.replace('.', ',') f.write(text) return True except: return False
class EditingDelegate(QItemDelegate): def __init__(self): super().__init__() self.__locale = QLocale(QLocale.English) def createEditor(self, parent, style=None, index=None): editor = QDoubleSpinBox(parent) editor.setMinimum(0.01) editor.setMaximum(1000000.00) editor.setLocale(self.__locale) return editor def setModelData(self, editor, model, index): text = str(editor.value()) text += '0' if len(text.split(self.__locale.decimalPoint())[-1]) == 1 else '' model.setData(index, text, Qt.EditRole) def setEditorData(self, editor, index): if index.model().data(index, Qt.EditRole) is None: return value = float(index.model().data(index, Qt.EditRole)) editor.setValue(value)
def export_text_interpolatevalues(state, data_to_table, horiz_headers, vertical_headers, data_2d, types, project_properties): filename = data_2d.filename path_prj = project_properties["path_prj"] unit_type = data_2d.unit_type fish_names = list(horiz_headers) # prep data for fish_num, fish_name in enumerate(fish_names): if "osi_" in fish_name: fish_names[fish_num] = fish_name.replace("osi_", "") if "wua_" in fish_name: fish_names[fish_num] = fish_name.replace("wua_", "") if "ua_" in fish_name: fish_names[fish_num] = fish_name.replace("ua_", "") # header 1 if project_properties['language'] == 0: if len(types.keys()) > 1: # date date_type = types["date"] header = 'reach\tdate\tunit' else: header = 'reach\tunit' else: if len(types.keys()) > 1: # date date_type = types["date"] header = 'troncon\tdate\tunit' else: header = 'troncon\tunit' header += "".join( ['\tOSI' + str(i) for i in range(int(len(fish_names) / 3))]) header += "".join( ['\tWUA' + str(i) for i in range(int(len(fish_names) / 3))]) header += "".join( ['\tUA' + str(i) for i in range(int(len(fish_names) / 3))]) header += '\n' # header 2 if len(types.keys()) > 1: # date header += '[]\t[' + date_type + ']\t[' + unit_type + ']' else: header += '[]\t[' + unit_type + ']' header += "".join(['\t[]' for _ in range(int(len(fish_names) / 3))]) header += "".join(['\t[m2]' for _ in range(int(len(fish_names) / 3))]) header += "".join(['\t[%]' for _ in range(int(len(fish_names) / 3))]) header += '\n' # header 3 if len(types.keys()) > 1: # date header += 'all\tall\tall' else: header += 'all\tall' for fish_name in fish_names: if "units" in fish_name: pass else: header += '\t' + fish_name.replace(' ', '_') # lines linetext = "" # for each line for row_index in range(len(vertical_headers)): # print("line", line) if len(types.keys()) > 1: # date linetext += "0" + "\t" + str(vertical_headers[row_index]) + "\t" else: linetext += "0" + "\t" + str(vertical_headers[row_index]) + "\t" # for each column for column_name in horiz_headers: hab_data = data_to_table[column_name][row_index] if not hab_data: linetext += "None" + "\t" if hab_data: # change decimal point locale = QLocale() if locale.decimalPoint() == ",": hab_data = str(hab_data).replace('.', ',') linetext += str(hab_data) + "\t" # new line linetext += "\n" text = header + "\n" + linetext # export try: output_full_path = os.path.join( path_prj, "output", "text", os.path.splitext(filename)[0] + "_interpolate_chronicle.txt") with open(output_full_path, 'wt') as f: f.write(text) state.value = 100 # process finished except: print('Error: ' + 'File not exported as it may be opened by another program.')