def check_project(self): percorso = QgsProject.instance().homePath() dir_output = "/".join(percorso.split("/")[:-1]) nome = percorso.split("/")[-1] # detect MzSTools project if os.path.exists(os.path.join( percorso, "progetto")) and os.path.exists( os.path.join(percorso, "progetto", "versione.txt")): QgsMessageLog.logMessage("MzSTools project detected", "MzSTools", Qgis.Info) QgsMessageLog.logMessage("Checking svg symbols...", "MzSTools", Qgis.Info) dir_svg_input = os.path.join(self.plugin_dir, "img", "svg") dir_svg_output = self.plugin_dir.split("python")[0] + "svg" if not os.path.exists(dir_svg_output): QgsMessageLog.logMessage( f"Copying svg symbols in {dir_svg_output}", "MzSTools", Qgis.Info) shutil.copytree(dir_svg_input, dir_svg_output) else: QgsMessageLog.logMessage( f"Updating svg symbols in {dir_svg_output}", "MzSTools", Qgis.Info) src_files = os.listdir(dir_svg_input) for file_name in src_files: full_file_name = os.path.join(dir_svg_input, file_name) if os.path.isfile(full_file_name): shutil.copy(full_file_name, dir_svg_output) QgsMessageLog.logMessage("Comparing project and plugin versions", "MzSTools", Qgis.Info) vers_data = os.path.join( os.path.dirname(QgsProject.instance().fileName()), "progetto", "versione.txt", ) try: with open(vers_data, "r") as f: proj_vers = f.read() with open( os.path.join(os.path.dirname(__file__), "versione.txt")) as nf: new_proj_vers = nf.read() if proj_vers < new_proj_vers: QgsMessageLog.logMessage("Project needs updating!", "MzSTools", Qgis.Info) qApp.processEvents() self.project_update_dlg.aggiorna( percorso, dir_output, nome, proj_vers, new_proj_vers) except Exception as ex: QgsMessageLog.logMessage(f"Error: {ex}", "MzSTools", Qgis.Critical)
def processAlgorithm(self, progress): postString = self.defineProcess() qDebug(postString) self.wps = ExecutionResult(self.getLiteralResult, self.getResultFile, self.errorResult, None) self.wps.executeProcess(self.process.processUrl, postString) #Wait for answer while not self.wps.finished(): qApp.processEvents()
def __init__(self, iface): self.iface = iface self.plugin_dir = os.path.dirname(__file__) self.windowTitle = "3Di Modeller Interface - Powered by QGIS" self.app = QApplication.instance() self.QApp = QCoreApplication.instance() if self.QApp is None: self.QApp = QApplication(sys.argv) self.QApp.startingUp() self.QApp.processEvents() self.app.startDragTime() self.iface.initializationCompleted.connect(self.customization) qApp.processEvents() self.applyStyle()
def initGui(self): QSettings().setValue("/qgis/hideSplash", True) qApp.processEvents() icon = QIcon(":/3Di_images/3Di_images/images/logo.png") self.app.setWindowIcon(icon) self.iface.mainWindow().setWindowIcon(icon) self.iface.mainWindow().setWindowTitle(self.windowTitle) qApp.processEvents() if not self.iface.mainWindow().isVisible(): self.splash_pix = QPixmap(":/3Di_images/3Di_images/images/splash.png") self.splash = QSplashScreen(self.splash_pix, Qt.WindowStaysOnTopHint) self.splash = QSplashScreen(self.splash_pix) self.splash.setMask(self.splash_pix.mask()) self.splash.show() qApp.processEvents() self.applyStyle() self.addHelpMenuItem() return
def getProcessDescription(self): self.process.requestDescribeProcess() #Wait for answer while not self.process.loaded(): qApp.processEvents()
def customization(self): self.splash.finish(self.iface.mainWindow()) self.iface.mainWindow().setWindowTitle(self.windowTitle) qApp.processEvents() self.applyStyle()
def unload(self): qApp.processEvents() self.iface.initializationCompleted.disconnect(self.customization) self.helpAction.deleteLater() return
def download_and_open_qgis_project(self, project_file_str, nome_file): """ # Slot for exposing the same-name function to Javascript. # Save the given project to the filesystem and open it in QGis. The recognition of *.qgs and *.qgz is carried out checking the string content. :param project_file_str: The project file which could be either a *.qgs or *.qgz UTF-8 encoded string :type project_file_str: str :param nome_file: The file name :type nome_file: str """ if not self.check_download_folder(): return False destination_path = os.path.join(self.download_folder_path, nome_file) # In case the file is a *.qgs (which is a XML file) is expected to start with either "DOCTYPE" (which should # have been removed during the upload, though) or "<QGIS" lowered = project_file_str.lower() if lowered.startswith("<!doctype") or lowered.startswith("<qgis"): destination_path = destination_path + ".qgs" try: with codecs.open(destination_path, "w", "utf-8") as f: f.write(project_file_str) except Exception as e: QMessageBox.critical( None, "Errore scaricamento", "Non e' stato possibile salvare in locale il file di progetto " + nome_file + ".qgs") raise # In case it is a zip file, it is expected to start with "PK" elif lowered.startswith("pk"): destination_path = destination_path + ".qgz" try: # Generating the byte array (explicitly using the default utf-8 anyway) tmp_encoded = codecs.encode(project_file_str, encoding="utf-8") # Decoding from "UTF-8" to a byte array project_file_str = codecs.decode(tmp_encoded, encoding="utf-8") # The user base is using Windows OS. The *.zip archive are ANSI encoded by empirical observation project_file_bytes = codecs.encode(project_file_str, encoding="ansi") with codecs.open(destination_path, 'wb') as f: f.write(project_file_bytes) except Exception as e: QMessageBox.critical( None, "Errore scaricamento", "Non e' stato possibile salvare in locale il file di progetto " + nome_file + ".qgz") raise else: QMessageBox.critical( None, "Errore scaricamento", "Non e' stato possibile salvare in locale il file di progetto " + nome_file + "\n\nNon e' stato possibile individuare il tipo di file dal suo contenuto" ) raise Exception( "Non e' stato possibile individuare il tipo di file dal suo contenuto" ) print("chiude progetto corrente") QgsProject.instance().clear() qApp.processEvents() #Wait untill GUI Update print("apre progetto " + destination_path) QgsProject.instance().read(destination_path)