def load_offline_docs(self): self.main_win.switch_to_info_tab() pdf_path = os.path.join(self.pdf, "SoundSpeedManager.pdf") if not os.path.exists(pdf_path): logger.warning("unable to find offline manual at %s" % pdf_path) return explore_folder(pdf_path)
def on_export_profile_btn(self): logger.debug("export profiles clicked") if len(self.selected_writers) == 0: msg = "Select output formats before data export!" QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) return settings = QtCore.QSettings() select_output_folder = self.selectFolder.isChecked() settings.setValue("select_output_folder", select_output_folder) output_folders = dict() # each writer may potentially have is own folder if select_output_folder: dlg = OutputFoldersDialog(main_win=self.main_win, lib=self.lib, writers=self.selected_writers, parent=self) dlg.exec_() output_folders = dlg.output_folders if len(output_folders) == 0: return # case where all the writers will write to the same folder if len(output_folders) == 0: for writer in self.selected_writers: output_folders[writer] = self.lib.outputs_folder settings.setValue("export_folder", self.lib.outputs_folder) logger.debug('output folder: %s' % self.lib.outputs_folder) # CARIS-specific check for file concatenation for writer in self.selected_writers: if writer == 'caris': caris_path = os.path.join(output_folders[writer], "CARIS", self.lib.current_project + ".svp") if os.path.exists(caris_path): msg = "An existing CARIS file is present in the output folder.\n\n" \ "Do you want to remove it to avoid possible profile duplications?" # noinspection PyCallByClass ret = QtGui.QMessageBox.question( self, "CARIS export", msg, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if ret == QtGui.QMessageBox.Yes: os.remove(caris_path) break # special case for Fugro ISS format force_writer_instrument_for_next_casts = None custom_writer_instrument = None # actually do the export current_project = None format_ok = False opened_folders = list() export_open_folder = self.openFolder.isChecked() settings.setValue("export_open_folder", export_open_folder) all_exported = True for pk in self._pks: success = self.lib.load_profile(pk, skip_atlas=True) if not success: # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Database", "Unable to load profile #%02d!" % pk, QtGui.QMessageBox.Ok) continue # special case: synthetic profile and NCEI skip_export = False for writer in self.selected_writers: if writer != 'ncei': continue if self.lib.ssp.l[0].meta.sensor_type == Dicts.sensor_types[ 'Synthetic']: msg = "Attempt to export a synthetic profile in NCEI format!" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) skip_export = True continue if self.lib.current_project == 'default': msg = "The 'default' project cannot be used for NCEI export.\n\n" \ "Rename the project in the Database tab!" if self.lib.setup.noaa_tools: msg += "\n\nRecommend in project_survey format, e.g. OPR-P999-RA-17_H12345" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) skip_export = True continue if self.lib.setup.noaa_tools and self.lib.not_noaa_project( self.lib.current_project): if self.lib.not_noaa_project(current_project, format_ok): current_project, format_ok = self.lib.cb.ask_formatted_text( default=self.lib.noaa_project) if self.lib.not_noaa_project(current_project, format_ok): msg = "The project name cannot be used for NCEI export.\n\n" \ "Rename the project in the Database tab!\n\n" \ "Recommend \"project_survey\" format, e.g. OPR-P999-RA-17_H12345" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) skip_export = True continue if not self.lib.ssp.cur.meta.survey or \ not self.lib.ssp.cur.meta.vessel or \ not self.lib.ssp.cur.meta.institution: msg = "Survey, vessel, and institution metadata are mandatory for NCEI export.\n\n" \ "To fix the issue:\n" \ "- Load the profile (if not already loaded)\n" \ "- Set the missing values using the Metadata button on the Editor tool bar\n" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) skip_export = True continue # special case for Fugro ISS format with NCEI format if self.lib.ssp.cur.meta.probe_type == Dicts.probe_types[ 'ISS']: logger.info("special case: NCEI and ISS format") if force_writer_instrument_for_next_casts is None: msg = "Enter the instrument type and model \n(if you don't know, leave it blank):" instrument, flag = self.lib.cb.ask_text_with_flag( "ISS for NCEI", msg, flag_label="Apply to all the next profiles") logger.debug("user input for ISS: %s, %r" % (instrument, flag)) # if empty, we just use the sensor type if instrument is None or instrument == "": instrument = self.lib.ssp.cur.meta.sensor if flag: # to skip the user dialog for next casts force_writer_instrument_for_next_casts = instrument else: force_writer_instrument_for_next_casts = None custom_writer_instrument = instrument else: # user asked to apply to all the next profiles custom_writer_instrument = force_writer_instrument_for_next_casts if skip_export: all_exported = False continue self.progress.start(text="Exporting profile #%02d" % pk) try: self.progress.update(value=60) self.lib.export_data( data_paths=output_folders, data_formats=self.selected_writers, custom_writer_instrument=custom_writer_instrument) except RuntimeError as e: self.progress.end() msg = "Issue in exporting the data for profile #%02d.\nReason: %s" % ( pk, e) # noinspection PyCallByClass QtGui.QMessageBox.critical(self, "Export error", msg, QtGui.QMessageBox.Ok) continue self.progress.end() # opening the output folder if export_open_folder: for output_folder in output_folders.values(): if output_folder not in opened_folders: explore_folder(output_folder) # open the output folder opened_folders.append(output_folder) if all_exported: msg = "Profiles successfully exported!" # noinspection PyCallByClass QtGui.QMessageBox.information(self, "Export profile", msg, QtGui.QMessageBox.Ok) else: msg = "At least one profile had issues in being exported!" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export profile", msg, QtGui.QMessageBox.Ok) self.accept()
def open_folder(self): explore_folder(self.data_folder)
def open_smartmap(self): url = 'https://www.hydroffice.org/smartmap/' explore_folder(url)
def load_online_docs(self): self.main_win.switch_to_info_tab() url = 'https://www.hydroffice.org/manuals/soundspeed/index.html' explore_folder(url)
def on_export_profile_btn(self): logger.debug("export profile clicked") if len(self.selected_writers) == 0: msg = "Select output formats before data export!" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) return # special case for Fugro ISS format iss_writer_instrument = None custom_writer_instrument = None # special case: synthetic profile and NCEI for writer in self.selected_writers: if writer != 'ncei': continue if self.lib.ssp.l[0].meta.sensor_type == Dicts.sensor_types[ 'Synthetic']: msg = "Attempt to export a synthetic profile in NCEI format!" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) return if self.lib.current_project == 'default': msg = "The 'default' project cannot be used for NCEI export.\n\n" \ "Rename the project in the Database tab!" if self.lib.setup.noaa_tools: msg += "\n\nRecommend in project_survey format, e.g. OPR-P999-RA-17_H12345" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) return if self.lib.setup.noaa_tools and self.lib.not_noaa_project( self.lib.current_project): current_project, format_ok = self.lib.cb.ask_formatted_text( default=self.lib.noaa_project) if self.lib.not_noaa_project(current_project, format_ok): msg = "The project name cannot be used for NCEI export.\n\n" \ "Rename the project in the Database tab!\n\n" \ "Recommend \"project_survey\" format, e.g. OPR-P999-RA-17_H12345" # noinspection PyCallByClass QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) return if not self.lib.ssp.cur.meta.survey or \ not self.lib.ssp.cur.meta.vessel or \ not self.lib.ssp.cur.meta.institution: msg = "Survey, vessel, and institution metadata are mandatory for NCEI export.\n\n" \ "To fix the issue:\n" \ "- Load the profile (if not already loaded)\n" \ "- Set the missing values using the Metadata button on the Editor tool bar\n" QtGui.QMessageBox.warning(self, "Export warning", msg, QtGui.QMessageBox.Ok) return # special case for Fugro ISS format with NCEI format if self.lib.ssp.cur.meta.probe_type == Dicts.probe_types['ISS']: logger.info("special case: NCEI and ISS format") if custom_writer_instrument is None: msg = "Enter the instrument type and model \n(if you don't know, leave it blank):" instrument = self.lib.cb.ask_text("ISS for NCEI", msg) # if empty, we just use the sensor type if instrument is None or instrument == "": instrument = self.lib.ssp.cur.meta.sensor custom_writer_instrument = instrument settings = QtCore.QSettings() select_output_folder = self.selectFolder.isChecked() settings.setValue("select_output_folder", select_output_folder) output_folders = dict() # each writer may potentially have is own folder if select_output_folder: dlg = OutputFoldersDialog(main_win=self.main_win, lib=self.lib, writers=self.selected_writers, parent=self) dlg.exec_() output_folders = dlg.output_folders if len(output_folders) == 0: return # case where all the writers will write to the same folder if len(output_folders) == 0: for writer in self.selected_writers: output_folders[writer] = self.lib.outputs_folder settings.setValue("export_folder", self.lib.outputs_folder) logger.debug('output folder: %s' % self.lib.outputs_folder) # ask user for basename basenames = dict() # NCEI has special filename convention if (len(self.selected_writers) == 1) and (self.selected_writers[0] == 'ncei'): pass else: basename_msg = "Enter output basename (without extension):" while True: # noinspection PyCallByClass basename, ok = QtGui.QInputDialog.getText( self, "Output basename", basename_msg, text=self.lib.cur_basename) if not ok: return for writer in self.selected_writers: basenames[writer] = basename break # actually do the export self.progress.start() try: self.lib.export_data( data_paths=output_folders, data_files=basenames, data_formats=self.selected_writers, custom_writer_instrument=custom_writer_instrument) except RuntimeError as e: self.progress.end() msg = "Issue in exporting the data.\nReason: %s" % e # noinspection PyCallByClass QtGui.QMessageBox.critical(self, "Export error", msg, QtGui.QMessageBox.Ok) return # opening the output folder export_open_folder = self.openFolder.isChecked() settings.setValue("export_open_folder", export_open_folder) if export_open_folder: opened_folders = list() for output_folder in output_folders.values(): if output_folder not in opened_folders: explore_folder(output_folder) # open the output folder opened_folders.append(output_folder) self.progress.end() else: self.progress.end() msg = "Profile successfully exported!" # noinspection PyCallByClass QtGui.QMessageBox.information(self, "Export profile", msg, QtGui.QMessageBox.Ok) self.accept()
def test_explore_folder_with_fake_path(self): self.assertFalse(helper.explore_folder('z:/fake/path'))