def load_performance(self): """ Gets a filename for a JSON file specifying aircraft performance and initializes an SimpleAircraft model. """ filename = get_open_filename(self, "Open Aircraft Performance JSON File", constants.MSS_CONFIG_PATH, "Performance File (*.json)", pickertag="filepicker_default") if filename is not None: try: performance = config_loader(config_file=filename) self.aircraft = aircrafts.SimpleAircraft(performance) self.lbAircraftName.setText(self.aircraft.name) self.dsbTakeoffWeight.setValue(self.aircraft.takeoff_weight) if not any( hasattr(self.aircraft, _x) for _x in ("fuel", "empty_weight")): raise KeyError("empty_weight") if hasattr(self.aircraft, "empty_weight"): self.dsbEmptyWeight.setValue(self.aircraft.empty_weight) else: self.dsbEmptyWeight.setValue(self.aircraft.takeoff_weight - self.aircraft.fuel) self.update_parent_performance() except KeyError as ex: QtWidgets.QMessageBox.critical( self, self.tr("Performance JSON Load"), self.tr(f"JSON File missing '{ex}' entry")) except (FatalUserError, ValueError) as ex: QtWidgets.QMessageBox.critical( self, self.tr("Performance JSON Load"), self.tr(f"JSON File has Syntax Problems:\n{ex}"))
def load_performance(self): """ Gets a filename for a JSON file specifying aircraft performance and initializes an SimpleAircraft model. """ filename = get_open_filename(self, "Open Aircraft Performance JSON File", constants.MSS_CONFIG_PATH, "Performance File (*.json)", pickertag="filepicker_default") if filename is not None: try: performance = config_loader(config_file=filename) self.aircraft = aircrafts.SimpleAircraft(performance) self.lbAircraftName.setText(self.aircraft.name) self.dsbTakeoffWeight.setValue(self.aircraft.takeoff_weight) self.dsbFuel.setValue(self.aircraft.fuel) except KeyError as ex: QtWidgets.QMessageBox.critical( self, self.tr("Performance JSON Load"), self.tr("JSON File missing '{}' entry".format(ex))) except (FatalUserError, ValueError) as ex: QtWidgets.QMessageBox.critical( self, self.tr("Performance JSON Load"), self.tr("JSON File has Syntax Problems:\n{}".format(ex)))
def load_function_wrapper(self): filename = get_open_filename(self, "Import Flight Track", self.last_save_directory, "All Files (*." + extension + ")", pickertype=pickertype) if filename is not None: try: ft_name, new_waypoints = function(filename) # wildcard exception to be resilient against error introduced by user code except Exception as ex: logging.error("file io plugin error: %s %s", type(ex), ex) QtWidgets.QMessageBox.critical( self, self.tr("file io plugin error"), self.tr(f"ERROR: {type(ex)} {ex}")) else: if not ft_name: ft_name = filename waypoints_model = ft.WaypointsTableModel( name=ft_name, waypoints=new_waypoints) listitem = QFlightTrackListWidgetItem( waypoints_model, self.listFlightTracks) listitem.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.listFlightTracks.setCurrentItem(listitem) self.activate_flight_track(listitem)
def set_exported_file(self): file_path = get_open_filename( self, "Open ftml file", "", "Flight Track Files (*.ftml)") if file_path is not None: file_name = fs.path.basename(file_path) with open_fs(fs.path.dirname(file_path)) as file_dir: file_content = file_dir.readtext(file_name) self.add_proj_dialog.f_content = file_content self.add_proj_dialog.selectedFile.setText(file_name)
def file_open(self): file_path = get_open_filename(self, "Open file", MSS_CONFIG_PATH, "Text documents (*.json)") if file_path is not None: file_name = fs.path.basename(file_path) with fs.open_fs(fs.path.dirname(file_path)) as file_dir: self.file_content = file_dir.readtext(file_name) self.path = file_path self.editor.setPlainText(self.file_content) self.update_title()
def select_file(self): """Slot that opens a file dialog to choose a file with satellite overpass predictions. """ filename = get_open_filename( self, "Open NASA satellite overpass prediction", os.path.join(os.path.dirname(self.leFile.text())), "All Files (*)", pickertag="filepicker_satellitetrack") if not filename: return self.leFile.setText(filename) save_settings_qsettings(self.settings_tag, {"filename": filename})
def load_config_file(self): """ Loads a config file and potentially restarts the application """ ret = QtWidgets.QMessageBox.warning( self, self.tr("Mission Support System"), self.tr("Opening a config file will reset application. Continue?"), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if ret == QtWidgets.QMessageBox.Yes: filename = get_open_filename(self, "Open Config file", constants.MSS_CONFIG_PATH, "Config Files (*.json)") if filename is not None: constants.CACHED_CONFIG_FILE = filename self.restart_application()
def handle_upload(self): img_type = "Image (*.png *.gif *.jpg *jpeg *.bmp)" doc_type = "Document (*.*)" file_filter = f'{img_type};;{doc_type}' file_path = get_open_filename(self, "Select a file", "", file_filter) if file_path is None or file_path == "": return file_type = file_path.split('.')[-1] self.attachment = file_path if file_type in ['png', 'gif', 'jpg', 'jpeg', 'bmp']: self.attachment_type = MessageType.IMAGE self.display_uploaded_img(file_path) else: self.attachment_type = MessageType.DOCUMENT self.display_uploaded_document(file_path) self.uploadBtn.setVisible(False) self.cancelBtn.setVisible(True) self.previewBtn.setVisible(False)
def import_config(self): file_path = get_open_filename( self, "Import config", "", ";;".join(["JSON Files (*.json)", "All Files (*.*)"])) if not file_path: return # load data from selected file dir_name, file_name = fs.path.split(file_path) with fs.open_fs(dir_name) as _fs: if _fs.exists(file_name): file_content = _fs.readtext(file_name) try: json_file_data = json.loads( file_content, object_pairs_hook=dict_raise_on_duplicates_empty) except json.JSONDecodeError as e: show_popup(self, "Error while loading file", e) logging.error(f"Error while loading json file {e}") return except ValueError as e: show_popup(self, "Invalid keys detected", e) logging.error(f"Error while loading json file {e}") return if json_file_data: json_model_data = self.json_model.serialize() options = merge_data(copy.deepcopy(json_model_data), json_file_data) if options == json_model_data: self.statusbar.showMessage("No option with new values found") return # replace existing data with new data self.json_model.init(options, editable_keys=True, editable_values=True) self.view.setColumnWidth(0, self.view.width() // 2) self.set_noneditable_items(QtCore.QModelIndex()) self.update_view() self.statusbar.showMessage("Successfully imported config") logging.debug("Imported new config data from file") else: self.statusbar.showMessage("No data found in the file") logging.debug("No data found in the file, using existing settings")
def open_flight_track(self): """Slot for the 'Open Flight Track' menu entry. Opens a QFileDialog and passes the result to createNewFlightTrack(). """ filename = get_open_filename( self, "Open Flight Track", self.last_save_directory, "Flight Track Files (*.ftml)", pickertag="filepicker_default") if filename is not None: try: if filename.endswith('.ftml'): self.create_new_flight_track(filename=filename) else: QtWidgets.QMessageBox.warning(self, "Open flight track", "No supported file extension recognized!\n{:}".format(filename)) except (SyntaxError, OSError, IOError) as ex: QtWidgets.QMessageBox.critical( self, self.tr("Problem while opening flight track FTML:"), self.tr("ERROR: {} {}".format(type(ex), ex)))
def handle_import(self): file_path = get_open_filename(self, "Select a file", "", "Flight track (*.ftml)") if file_path is None: return dir_path, file_name = fs.path.split(file_path) with open_fs(dir_path) as file_dir: xml_content = file_dir.readtext(file_name) try: model = ft.WaypointsTableModel(xml_content=xml_content) except SyntaxError: show_popup(self, "Import Failed", f"The file - {file_name}, does not contain valid XML") return self.waypoints_model = model if self.workLocallyCheckBox.isChecked(): self.waypoints_model.save_to_ftml(self.local_ftml_file) self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed) else: self.conn.save_file(self.token, self.active_pid, xml_content, comment=None) self.waypoints_model.dataChanged.connect(self.handle_waypoints_changed) self.reload_view_windows() show_popup(self, "Import Success", f"The file - {file_name}, was imported successfully!", 1)