def cut_save(self, save_as): if self.cut_widget.first_idx is None or self.cut_widget.second_idx is None: show_error(_('Border error'), _('You must define boundary points.')) return if not save_as: answer = show_warning_yes_no( _('Warning'), _('Initial data will be deleted.\n' 'This action cannot be undone. Resume?')) if answer == QMessageBox.No: return if self.cut_widget.first_idx == self.cut_widget.second_idx: self.cut_widget.second_idx += 1 filename = self.cut_widget.shortcut_object start = self.cut_widget.first_idx finish = self.cut_widget.second_idx time = self.objects[filename]['time'][start:finish] lon_lat = self.objects[filename]['lon_lat'][start:finish] height = self.objects[filename]['object'].pos[start:finish, 2] magnet = self.objects[filename]['magnet'][start:finish] object = { 'time': time, 'lon_lat': lon_lat, 'height': height, 'magnet': magnet } self.parent.project_instance.add_magnet_from_memory( filename, object, save_as) self.cut_widget.close()
def add_magnet_from_memory(self, filename, object, save_as=True): path_to_save = os.path.join(self.files_path, self.magnetic_tracks_data.attrib['name']) time = object['time'] lon_lat = object['lon_lat'] height = object['height'] magnet = object['magnet'] if os.path.isfile(os.path.join(path_to_save, filename)): show_error( _('File warning'), _('<html>There is a file with the same name in the project directory.\n' 'Please rename imported file <b>{}</b> and try again.</html>' ).format(filename)) save_as = True if save_as: filename = QFileDialog.getSaveFileName( None, _("Save File"), path_to_save, "Magnetic track files (*.magnete)")[0] if not filename: return else: filename = os.path.join(path_to_save, filename) if os.path.basename( filename) in self.parent.three_d_widget.three_d_plot.objects: self.parent.three_d_widget.three_d_plot.remove_object( os.path.basename(filename)) it = 0 self.progress.open() QApplication.processEvents() try: with open(filename, 'w') as file: for i in range(len(time)): value = (it + 1) / len(time) * 60 it += 1 self.progress.setValue(value) file.write('{} {} {} {} {}\n'.format( time[i], lon_lat[i][1], lon_lat[i][0], height[i], magnet[i])) except FileNotFoundError: return if not self.magnetic_tracks_data.xpath( "//magnetic_tracks_data[@filename='{}']".format( os.path.basename(filename))): ET.SubElement( self.magnetic_tracks_data, 'magnetic_tracks_data', { 'filename': '{}'.format(os.path.basename(filename)), 'indicator': 'Off' }) self.parent.three_d_widget.three_d_plot.add_fly( filename, self.progress, value + 18) self.write_proj_tree() self.send_tree_to_view() self.progress.setValue(100)
def upload_file_to_device(self): if not self.parent.geoshark_widget.device_on_connect or self.server is None: return file = self.left_file_model.filePath(self.lefttableview.currentIndex()) filename = file.split('/')[-1] url = 'http://{}/data/{}'.format(self.server, '/'.join(self.right_file_model_path)) filesize = os.path.getsize(file) if filesize == 0: show_error(_('File error'), _('File size must be non zero.')) return progress = ProgressBar(text=_('Upload File Into GeoShark'), window_title=_('Upload file to GeoShark')) encoder = MultipartEncoder( fields={'upload_file': (filename, open(file, 'rb'))} # added mime-type here ) data = MultipartEncoderMonitor(encoder, lambda monitor: progress.update((monitor.bytes_read/filesize)*99)) try: res = requests.post(url, data=data, headers={'Content-Type': encoder.content_type}, timeout=5) except requests.exceptions.RequestException: progress.close() show_error(_('GeoShark error'), _('GeoShark is not responding.')) return if res.ok: progress.update(100) self.right_file_model_update()
def error(self, error_code): print("error code: {}".format(error_code)) print(self.client.errorString()) show_error( _('GeoShark error'), _('GeoShark is not responding.\n{}.').format( self.client.errorString())) if error_code != 0: self.signal_disconnect.emit()
def check_active_directory(self): url = 'http://{}/active_dir'.format(self.server) try: res = requests.get(url) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('Can not check session.\nGeoShark is not responding.')) return if res.ok: self.parent.file_manager_widget.set_active_path(res.text)
def add_magnet_data(self): files = QFileDialog.getOpenFileNames( None, _("Select one or more files to open"), self.files_path, "Magnetic track files (*.magnete)")[0] if not files: return it = 0 self.progress.setWindowTitle(_("Load files")) self.progress.open() QApplication.processEvents() for file in files: destination = os.path.join( self.files_path, self.magnetic_tracks_data.attrib['name'], os.path.basename(file)) if not os.path.exists(destination): copyfile(file, destination) ET.SubElement( self.magnetic_tracks_data, 'magnetic_tracks_data', { 'filename': '{}'.format(os.path.basename(destination)), 'indicator': 'Off' }) elif os.path.samefile(file, destination): if not self.magnetic_tracks_data.xpath( "//magnetic_tracks_data[@filename='{}']".format( os.path.basename(destination))): ET.SubElement( self.magnetic_tracks_data, 'magnetic_tracks_data', { 'filename': '{}'.format( os.path.basename(destination)), 'indicator': 'Off' }) else: continue elif os.path.exists(destination): show_error( _('File warning'), _('<html>There is a file with the same name in the project directory.\n' 'Please rename imported file <b>{}</b> and try again.</html>' ).format(os.path.basename(file))) continue else: continue value = (it + 1) / len(files) * 99 it += 1 QApplication.processEvents() self.parent.three_d_widget.three_d_plot.add_fly( destination, self.progress, value) self.write_proj_tree() self.send_tree_to_view() self.progress.setValue(100)
def start_stop_session(self, var): var = 'start' if var else 'stop' url = 'http://{}/command'.format(self.server) try: res = requests.post(url, data=var, timeout=1) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('Can not {} session.\nGeoShark is not responding.').format(var)) self.toggle.change_state() return if res.ok: print(res.text)
def check_session(self): url = 'http://{}/command'.format(self.server) try: res = requests.get(url) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('Can not check active directory.\nGeoShark is not responding.')) return if res.ok: if res.text == 'Session active.\n' and not self.toggle.switch_on: self.toggle.change_state() elif res.text == 'Session stopped.\n' and self.toggle.switch_on: self.toggle.change_state()
def download_file_from_device(self, device_path=None, pc_path=None): if not self.parent.geoshark_widget.device_on_connect or self.server is None: return if not device_path: fileName = self.find_selected_idx() if fileName: fileName = fileName.data() device_path = '/'.join(self.right_file_model_path + [fileName]) else: return right_file_model_filename = device_path.split('/')[-1] save_to_file = '{}/{}'.format(self.left_file_model_path, right_file_model_filename) \ if not pc_path else '{}/{}'.format(pc_path, right_file_model_filename) if os.path.isfile(save_to_file): answer = show_warning_yes_no(_('File warning'), _('There is a file with the same name in PC.\n' 'Do you want to rewrite <b>{}</b>?'.format(right_file_model_filename))) if answer == QMessageBox.No: return url = 'http://{}/data/{}'.format(self.server, device_path) try: b = bytearray() res = requests.get(url, timeout=5, stream=True) if res.ok: progress = QProgressBar() progress.setFormat(right_file_model_filename) self.file_manager_layout.addWidget(progress, 6, 12, 1, 9) total_length = int(res.headers.get('content-length')) len_b = 0 for chunk in tee_to_bytearray(res, b): len_b += len(chunk) progress.setValue((len_b/total_length)*99) QApplication.processEvents() else: return except: self.file_manager_layout.addWidget(self.right_file_model_auto_sync_label, 6, 12, 1, 9) show_error(_('GeoShark error'), _('GeoShark is not responding.')) return if res.ok: progress.setValue(100) with open(save_to_file, 'wb') as file: file.write(b) for i in reversed(range(self.file_manager_layout.count())): if isinstance(self.file_manager_layout.itemAt(i).widget(), QProgressBar): self.file_manager_layout.itemAt(i).widget().setParent(None) self.file_manager_layout.addWidget(self.right_file_model_auto_sync_label, 6, 12, 1, 9)
def get_folder_list(self, folder_path=None): if self.server is None: return if folder_path is None: folder_path = '/'.join(self.right_file_model_path) url = 'http://{}/data/{}'.format(self.server, folder_path) try: res = requests.get(url, timeout=1) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('GeoShark is not responding.')) return if res.ok: res = res.json() return res else: return None
def apply_clicked(self): self.auto_state = True if self.auto_radiobtn.isChecked() else False if self.auto_state: self.set_values() self.recolor_signal.emit(self.min, self.max) else: if len(self.min_value.text()) == 0 or len( self.max_value.text()) == 0: show_error(_('Border error'), _('Please fill Max, Min values or\nchoose Auto.')) return if float(self.min_value.text()) > float(self.max_value.text()): show_error(_('Border error'), _('Max must be more than Min')) return self.set_values(min=float(self.min_value.text()), max=float(self.max_value.text())) self.recolor_signal.emit(self.min, self.max)
def get_update_tree(self): if self.server is None: return url = 'http://{}/spec_update'.format(self.server) try: res = requests.get(url, timeout=1) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('GeoShark is not responding.')) return if res.ok: res = res.json() else: return it = iter(res.keys()) root = next(it) self.update_tree.clear() self.parent.configuration_widget.fill_tree(self.update_tree, res[root])
def apply_settings(self, close=False): if len(self.lineEdit_ip.text().split( '.')) == 4 and self.parent.app_settings.value( 'ip') != self.lineEdit_ip.text(): self.parent.client.close() self.signal_ip_changed.emit(self.lineEdit_ip.text()) elif len(self.lineEdit_ip.text().split('.')) < 4: show_error(_('IP error'), _('IP address is not correct.')) if self.parent.app_settings.value( 'language') != self.language_combo.currentText()[:2].lower(): self.signal_language_changed.emit( self.language_combo.currentText()[:2].lower()) self.signal_decimate_changed.emit(self.decimate_lineedit.text()) self.parent.file_manager_widget.left_file_model_auto_sync_label.setText( self.left_folder_tracked.text()) if close: self.close()
def delete_file_from_file_model(self, index=None): selected = self.find_selected_idx() if index is None and selected is None: return if index is None: index = selected model = index.model() index_row = index.row() path = model.filePath(index) if hasattr(model, 'filePath') else model.index(index_row, 0).data() answer = show_warning_yes_no(_('Remove File warning'), _('Do you really want to remove:\n{}').format(path)) if answer == QMessageBox.No: return if isinstance(model, QFileSystemModel): model.remove(index) elif isinstance(model, QStandardItemModel): if not self.parent.geoshark_widget.device_on_connect or self.server is None: return filename = self.right_file_model.item(index.row(), 0).text() path = '/'.join(self.right_file_model_path + [filename]) url = 'http://{}/data/{}'.format(self.server, path) try: res = requests.delete(url) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('GeoShark is not responding.')) return if res.ok: self.right_file_model_update() elif res.status_code == 400: self.right_file_model.removeRow(index.row()) elif res.status_code == 409: show_error(_('GeoShark error'), _('Request declined - directory is the part of active session working directory.')) return
def upload_update_file(self, file_url): if self.server is None: return url = 'http://{}/update'.format(self.server) filesize = os.path.getsize(file_url) if filesize == 0: show_error(_('File error'), _('File size must be non zero.')) return filename = (os.path.basename(file_url)) encoder = MultipartEncoder( fields={'update_file': ( filename, open(file_url, 'rb'))} # added mime-type here ) monitor = MultipartEncoderMonitor( encoder, lambda m: self.progress.setValue( (m.bytes_read / filesize) * 99)) try: res = requests.post(url, data=monitor, headers={'Content-Type': monitor.content_type}, timeout=5) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('Unable to upload file. GeoShark is not responding.')) self.progress.setValue(0) return if res.ok: self.progress.setValue(100) self.label.setStyleSheet('color: rgb(0, 204, 0)') self.label.setText(_('File has been uploaded into GeoShark.')) self.cancel_btn.setText(_('Finish')) else: self.label.setText(_('File has not been uploaded into GeoShark.')) self.label.setStyleSheet('color: rgb(255, 0, 0)')
def set_active_directory(self, item): if not self.parent.geoshark_widget.device_on_connect: return dirname = item.text() url = 'http://{}/active_dir'.format(self.server) try: res = requests.post(url=url, data=dirname, timeout=5) except requests.exceptions.RequestException: show_error(_('GeoShark error'), _('Can not set active directory.\nGeoShark is not responding.')) return if res.ok: self.right_file_model_update() self.set_active_path(dirname) elif res.status_code == 400: show_error(_('GeoShark error'), _('Request declined - request body specifies invalid path.')) return elif res.status_code == 409: show_error(_('GeoShark error'), _('Request declined - switching active directory is forbidden during active session.')) return else: print(res.status_code) return
def add_raw_data(self, extension): files = QFileDialog.getOpenFileNames( None, _("Select one or more files to open"), self.files_path, "{} files ({})".format( self.magnet_field_ext.upper() if extension == '*.' + self.magnet_field_ext else self.gnss_ext.upper(), extension)) if not files[0]: return self.progress.setWindowTitle(_("Load files")) self.progress.open() QApplication.processEvents() for i, file in enumerate(files[0]): if extension == '*.' + self.magnet_field_ext: destination = os.path.join( self.files_path, self.magnetic_field_data.attrib['name'], os.path.basename(file)) else: destination = os.path.join(self.files_path, self.gnss_data.attrib['name'], os.path.basename(file)) if not os.path.exists(destination): copyfile(file, destination) if extension == '*.' + self.magnet_field_ext: ET.SubElement( self.magnetic_field_data, 'magnetic_field_data', { 'filename': '{}'.format( os.path.basename(destination)) }) elif extension == '*.' + self.gnss_ext: ET.SubElement(self.gnss_data, 'gnss_data', { 'filename': '{}'.format(os.path.basename(destination)) }) elif os.path.samefile(file, destination): if extension == '*.' + self.magnet_field_ext and not self.magnetic_field_data.xpath( "//magnetic_field_data[@filename='{}']".format( os.path.basename(destination))): ET.SubElement( self.magnetic_field_data, 'magnetic_field_data', { 'filename': '{}'.format( os.path.basename(destination)) }) elif extension == '*.' + self.gnss_ext and not self.gnss_data.xpath( "//gnss_data[@filename='{}']".format( os.path.basename(destination))): ET.SubElement(self.gnss_data, 'gnss_data', { 'filename': '{}'.format(os.path.basename(destination)) }) else: continue elif os.path.exists(destination): show_error( _('File warning'), _('<html>There is a file with the same name in the project directory.\n' 'Please rename imported file <b>{}</b> and try again.</html>' ).format(os.path.basename(file))) continue self.progress.setValue((i / len(files[0]) * 99)) self.write_proj_tree() self.send_tree_to_view() self.progress.setValue(100)
def create_magnet_files(self, files_list, widget=None): mag_file, second_file = files_list magnetic_path = os.path.join(self.files_path, self.magnetic_field_data.attrib['name']) gnss_path = os.path.join(self.files_path, self.gnss_data.attrib['name']) filename = os.path.splitext(mag_file)[0] widget.second_label.setText(_('Parsing {}').format(mag_file)) mag_values = parse_mag_file(os.path.join(magnetic_path, mag_file), widget.progress) gpst = mag_values[0] / 1e6 freq = mag_values[1] * 0.026062317 if gpst.shape != freq.shape or gpst.shape == (0, ): show_error(_('Matching error'), _('GPS time and frequency don\'t match')) widget.close() return if os.path.splitext(second_file)[-1] == '.' + self.gnss_ext: # do command with RTKLIB and get .pos file bin or txt widget.second_label.setText( _('Creating {}').format('{}.pos').format(filename)) widget.progress.setValue(0) cmd = 'rtk_lib\\convbin.exe -d "{}" "{}"'.format( self.files_path.replace('/', '\\'), os.path.join(gnss_path, '{}.{}'.format(filename, self.gnss_ext)).replace('/', '\\')) if not os.path.isfile( os.path.join(gnss_path, '{}.{}'.format( filename, self.gnss_ext))): show_error( _('Matching error'), _('There is no match .ubx file for <b>{}</b>').format( mag_file)) widget.close() return p1 = subprocess.Popen(cmd, shell=True) out, err = p1.communicate() # if err: # show_error(_('Error'), err.decode('cp866')) # return widget.progress.setValue(50) pos = os.path.join(self.files_path, '{}.pos'.format(filename)).replace('/', '\\') if not os.path.isfile(os.path.join(self.files_path, '{}.obs'.format(filename))) or \ not os.path.isfile(os.path.join(self.files_path, '{}.nav'.format(filename))): show_error( _('RTK LIB error'), _('RTK Lib didn\'t create {}.obs and {}.nav files.\n' 'Please report us about this problem').format( filename, filename)) widget.close() return cmd = 'rtk_lib\\rnx2rtkp.exe -p 0 -o "{}" "{}" "{}"'.format( pos, os.path.join(self.files_path, '{}.obs'.format(filename)).replace('/', '\\'), os.path.join(self.files_path, '{}.nav'.format(filename)).replace('/', '\\')) p2 = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p2.communicate() if not os.path.isfile(os.path.join(self.files_path, '{}.obs'.format(filename))) or \ not os.path.isfile(os.path.join(self.files_path, '{}.nav'.format(filename))): show_error( _('RTK LIB error'), _('RTK Lib didn\'t create {}.pos file.\n' 'Please report us about this problem').format( filename, filename)) widget.close() return # if err: # show_error(_('Error'), err.decode('cp866')) # return elif os.path.splitext(second_file)[-1] == '.pos': pos = second_file else: show_error( _('Matching error'), _('There is no match .ubx or pos file for <b>{}</b>').format( mag_file)) return widget.second_label.setText( _('Creating {}').format('{}.magnete'.format(filename))) widget.progress.setValue(0) magnet_obj = dict() diff = np.diff(gpst) with open(pos, 'r') as pos_file: file = pos_file.readlines() for i in range(len(file))[::-1]: if file[i][0] == '%': file.remove(file[i]) continue week = int(file[0].split()[0]) sec = float(file[0].split()[1]) time = datetime(1980, 1, 6) + timedelta(seconds=(week * 7 * 86400) + sec) time = time.timestamp() gpst[0] = time gpst[1:] = diff + time start = np.argsort(np.absolute(time - gpst))[0] if gpst[start] == gpst[-1]: pos_file.close() list_dir = os.listdir(self.files_path) for file in list_dir: if not os.path.isdir(os.path.join(self.files_path, file)): os.remove(os.path.join(self.files_path, file)) widget.second_label.setText( _('Didn\'t match GPST with time in <b>{}</b> file').format( os.path.basename(second_file))) return length = len(file) time_arr = [] lon_arr = [] lat_arr = [] height_arr = [] magnet_arr = [] for i, line in enumerate(file): if line[0] == '%': continue week = int(line.split()[0]) sec = float(line.split()[1]) time = datetime( 1980, 1, 6) + timedelta(seconds=(week * 7 * 86400) + sec) time = time.timestamp() indices = np.argsort( np.absolute(time - gpst[start:start + 200])) diff = time - gpst[indices[0] + start] if abs(diff) < 0.0015: new_offset = indices[0] + start indices.sort() coeff = np.polyfit( gpst[indices[0] + start:indices[-1] + start], freq[indices[0] + start:indices[-1] + start], 1) poly1d = np.poly1d(coeff) magnet_field = poly1d(time) time_arr.append(time) lon_arr.append(line.split()[1]) lat_arr.append(line.split()[2]) height_arr.append(line.split()[3]) magnet_arr.append(magnet_field) widget.progress.setValue((i / length) * 99) QApplication.processEvents() start = new_offset elif diff > 1: start = np.argsort(np.absolute(time - gpst))[0] if time - gpst[start] > 3: break for file in os.listdir(self.files_path): if not os.path.isdir(os.path.join(self.files_path, file)): os.remove(os.path.join(self.files_path, file)) if len(time_arr) == 0: widget.progress.setValue(100) widget.second_label.setText( _('Didn\'t match GPST with time in <b>{}</b> file').format( os.path.basename(second_file))) else: widget.progress.setValue(100) widget.second_label.setText( _('Magnetic Field Track <b>{}.magnete</b> has been created.'). format(filename)) magnet_obj['time'] = np.array(time_arr) magnet_obj['lon_lat'] = np.column_stack( (np.array(lon_arr), np.array(lat_arr))) magnet_obj['height'] = np.array(height_arr) magnet_obj['magnet'] = np.array(magnet_arr) self.add_magnet_from_memory('{}.magnete'.format(filename), magnet_obj, False)
def add_geo_data(self, filetype): file = QFileDialog.getOpenFileName( None, _("Open file"), self.files_path, "Geo files ({})".format(filetype))[0] if file == '': return self.progress.setWindowTitle(_("Load files")) self.progress.open() QApplication.processEvents() filename, extension = os.path.splitext(os.path.basename(file)) if extension == '.ply': destination = os.path.join(self.files_path, self.geo_data.attrib['name'], os.path.basename(file)) try: if not os.path.exists(destination): self.parent.three_d_widget.three_d_plot.add_terrain( file, self.progress, 55) copyfile(file, destination) ET.SubElement( self.geo_data, 'geo_data', { 'filename': '{}'.format(os.path.basename(file)), 'indicator': 'Off' }) elif os.path.samefile(file, destination): if not self.geo_data.xpath( "//geo_data[@filename='{}']".format( os.path.basename(file))): self.parent.three_d_widget.three_d_plot.add_terrain( file, self.progress, 55) ET.SubElement( self.geo_data, 'geo_data', { 'filename': '{}'.format( os.path.basename(file)), 'indicator': 'Off' }) elif os.path.exists(destination): show_error( _('File warning'), _('<html>There is a file with the same name in the project directory.\n' 'Please rename imported file <b>{}</b> and try again.</html>' ).format(os.path.basename(file))) self.progress.close() return except MemoryError: show_error( _('Memory error'), _("You don't have enough memory for downloading\n{}"). format(file)) self.progress.close() return except Exception as e: show_error( _('File error'), _("File couldn't be downloaded\n{}\n{}").format( file, e.args[0])) self.progress.close() return elif extension == '.tif': destination = os.path.join(self.files_path, self.geo_data.attrib['name'], '{}.ply'.format(filename)) if not os.path.exists(destination): try: self.parent.three_d_widget.three_d_plot.add_terrain( file, self.progress, path_to_save=os.path.join(self.files_path, self.geo_data.attrib['name'], '{}.ply'.format(filename))) ET.SubElement( self.geo_data, 'geo_data', { 'filename': '{}.ply'.format( os.path.basename(filename)), 'indicator': 'Off' }) except AssertionError as e: show_error( _('File error'), _("File couldn't be downloaded\n{}").format(e.args[0])) self.progress.close() return except MemoryError: show_error( _('Memory error'), _("You don't have enough memory for downloading\n{}"). format(file)) self.progress.close() return else: show_error( _('File warning'), _('<html><b>{}.ply</b> is already in the project directory.\n' 'Please, rename file you are trying to import and try again.<html>' ).format(filename)) self.progress.close() return else: return self.write_proj_tree() self.send_tree_to_view() self.progress.setValue(100)
def parse_proj_tree(self, path): try: self.tree = ET.parse(path) self.root = self.tree.getroot() self.magnetic_field_data = self.root.find('magnetic_field_data') self.gnss_data = self.root.find('gnss_data') self.magnetic_tracks_data = self.root.find('magnetic_tracks_data') self.geo_data = self.root.find('geo_data') self.project_utm = self.root.find('project_utm') except ET.XMLSyntaxError: show_error(_('Project error'), _('Couldn\'t open .qmcproj file.')) self.reset_project() return if self.magnetic_field_data is None or self.magnetic_tracks_data is None or self.geo_data is None or self.project_utm is None: show_error(_('Project error'), _('Couldn\'t open .qmcproj file.')) self.reset_project() return self.parent.setWindowTitle('QMCenter — {}'.format(self.project_path)) self.parent.file_manager_widget.left_dir_path.setText( self.root.attrib['path']) self.parent.file_manager_widget.left_file_model_go_to_dir() if self.project_utm.attrib['zone'] != '': try: self.parent.three_d_widget.three_d_plot.utm_zone = int( self.project_utm.attrib['zone']) except ValueError: show_error( _('UTM Zone Error'), _("Can't read UTM zone from project files.\n" "Please set UTM zone manually.")) length = len(self.magnetic_tracks_data.getchildren()) + len( self.geo_data.getchildren()) it = 0 self.progress.open() QApplication.processEvents() for magnet in self.magnetic_tracks_data.getchildren(): file = os.path.join(self.files_path, self.magnetic_tracks_data.attrib['name'], magnet.attrib['filename']) if not os.path.isfile(file): show_error( _('File error'), _('File not found\n{}').format(file.replace('/', '\\'))) self.remove_element(os.path.basename(file)) continue value = (it + 1) / length * 99 it += 1 self.parent.three_d_widget.three_d_plot.add_fly( file, self.progress, value) for geo in self.geo_data.getchildren(): file = os.path.join(self.files_path, self.geo_data.attrib['name'], geo.attrib['filename']) value = (it + 1) / length * 99 it += 1 try: self.parent.three_d_widget.three_d_plot.add_terrain( file, self.progress, value) except FileNotFoundError: show_error( _('File error'), _('File not found\n{}').format(file.replace('/', '\\'))) self.remove_element(os.path.basename(file)) continue except MemoryError: show_error( _('Memory error'), _("You don't have enough memory for downloading\n{}"). format(file)) geo.attrib['indicator'] = 'low_memory' continue except Exception as e: show_error( _('File error'), _("File couldn't be downloaded\n{}\n{}").format( file, e.args[0])) geo.attrib['indicator'] = 'bad_file' continue geo.attrib['indicator'] = 'Off' self.send_tree_to_view() self.write_proj_tree() self.progress.setValue(100)