def __save_project(self): if self.__is_project_loaded(): success = self.project_manager.save() if success: show_message(self, MESSAGE_SAVE) else: show_message(self, MESSAGE_SAVE_ERROR)
def update_settings(self): for k, v in self.setting_lines.items(): for p in self.plugin_manager.plugins: if k in p.get_settings(): self.settings_manager.update_plugin_setting( p.name, k, v.text()) self.settings_manager.save() show_message(self, "Settings updated!")
def __open_file(self, path): project_path = self.project_manager.state['project_path'] if project_path is None: show_message(self, MESSAGE_PROJECT_NOTLOADED) return editor = None if self.settings_manager.default_editor is not None: editor = self.settings_manager.default_editor submission = self.project_manager.get_current_submission() open_file(os.path.join(submission.path, path), editor)
def __export(self): if self.__is_project_loaded(): export_dir = show_directory_request(self, "Export Destination", home()) if export_dir is None or export_dir == '': show_message(self, "No export destination was chosen.") return project_dir = os.path.join( os.path.dirname( self.project_manager.get_current_submission().path)) export_path = os.path.join( export_dir, os.path.basename(project_dir) + "_QG_EXPORT.json") with open(export_path, 'w') as f: json.dump(self.project_manager.get_submissions_json(), f) show_message(self, "Files exported to {}".format(export_path))
def __add_files(self): if self.__is_project_loaded(): files = show_files_request(self, "Choose files to add", home()) if len(files) == 0: show_message(self, "No files added.") return for f in files: for s in self.project_manager.state['submissions']: new_path = os.path.join(s.path, os.path.basename(f)) print(new_path) shutil.copyfile(f, new_path) self.update_fileview() message = ( "The following files were added to all submissions folders\n\n" "{}".format("\n".join(files))) show_message(self, message)
def __add_requirement(self): if self.__is_project_loaded(): while True: res = show_request(self, "New requirement:") if res is None: return elif res == '': show_message(self, "Not a valid requirement.") else: break submissions = self.project_manager.state['submissions'] for i in range(0, len(submissions)): submissions[i].add_requirement(res) self.requirement_model.replace_data( self.project_manager.get_current_submission().requirements)
def __open_project(self): while True: source_directory = show_directory_request( self, "Choose project directory", WORKSPACE_PATH) if source_directory is None or source_directory == '': return else: success = self.project_manager.load(source_directory) if success: message = "Project loaded!" show_message(self, message) self.update_fileview() return else: show_message(self, MESSAGE_INVALID_SOURCE)
def __update_editor(self): text = self.editor_line.text() if text is None or text == '' or text == 'default': self.settings_manager.default_editor = '' self.settings_manager.save() show_message(self, "Default settings active.") elif shutil.which(text) is None: show_message(self, "Invalid executable path.") else: self.settings_manager.default_editor = text self.settings_manager.save() show_message(self, "Editor updated!")
def __new_project(self): while True: name = show_request(self, "New Project Name") if name == '': show_message(self, MESSAGE_INVALID_NAME) elif name is None: return else: break full_path = os.path.join(WORKSPACE_PATH, name) if is_directory(full_path): yes = show_warning(self, MESSAGE_PROJECT_EXISTS) if yes: overwrite(full_path) else: return else: os.mkdir(full_path) while True: source_directory = show_directory_request( self, "Choose source directory", home()) if source_directory is None or source_directory == '': if os.path.isdir(full_path): os.rmdir(full_path) break else: success = self.project_manager.new(full_path, source_directory) if success: message = "Project setup complete!" show_message(self, message) self.update_fileview() return else: if os.path.isdir(full_path): os.rmdir(full_path) show_message(self, MESSAGE_INVALID_SOURCE)
def show_message(self, message): show_message(self.ui_delegator.delegate, message)
def __show_help(self): show_message(self, MESSAGE_SETTINGS_EDITOR_HELP)
def __is_project_loaded(self): if self.project_manager.is_project_loaded(): return True else: show_message(self, MESSAGE_PROJECT_NOTLOADED) return False
def __about(self): show_message(self, MESSAGE_ABOUT)