def refresh_app(self): app_settings.app_data_cache.load_cache() self.show_frame() self.view.refresh_all_views() current_project = app_settings.load_current_project() window_title = f"{current_project.location}" self.view.setWindowTitle(window_title)
def on_file_open(self): user_project: UserProject = app_settings.load_current_project() current_project_folder = os.path.dirname(user_project.location) file_location, _ = self.main_window.open_file( "Select Project File", current_project_folder, file_filter="Project Files (*.db)", ) if file_location and file_location != user_project.location: user_project.location = file_location user_project.state = SavedState.SAVED app_settings.save_current_project(user_project) self.reload_app()
def on_export(self): user_project: UserProject = app_settings.load_current_project() current_project_folder = os.path.dirname(user_project.location) file_location, _ = self.main_window.save_file( "Export Environments", current_project_folder, file_filter="Environment Files (*.envs.json)", ) if file_location: envs: List[ Environment ] = app_settings.app_data_reader.get_environments_from_db() envs_json = cattr.unstructure(envs) Path(file_location).write_text(json.dumps(envs_json))
def on_import(self): user_project: UserProject = app_settings.load_current_project() current_project_folder = os.path.dirname(user_project.location) file_location, _ = self.main_window.open_file( "Import Environments", current_project_folder, file_filter="Environment Files (*.envs.json)", ) if file_location: envs_raw_json = Path(file_location).read_text() envs_json = json.loads(envs_raw_json) envs: List[Environment] = cattr.structure(envs_json, List[Environment]) for env in envs: environment_interactor.add_environment(env) app_settings.app_data_writer.signals.environments_imported.emit()
def on_file_save(self, retain_current_project_file=False): user_project: UserProject = app_settings.load_current_project() current_project_folder = os.path.dirname(user_project.location) if user_project.state == SavedState.UN_SAVED: file_location, _ = self.main_window.save_file( "Save Project File", current_project_folder, file_filter="Project Files (*.db)", ) if file_location and file_location != user_project.location: if retain_current_project_file: shutil.copy(user_project.location, file_location) else: shutil.move(user_project.location, file_location) user_project.location = file_location user_project.state = SavedState.SAVED app_settings.save_current_project(user_project) self.reload_app() else: self.main_window.request_presenter.update_current_api_call()
def on_file_save_as(self): user_project: UserProject = app_settings.load_current_project() user_project.state = SavedState.UN_SAVED app_settings.save_current_project(user_project) self.on_file_save(retain_current_project_file=True)