def uninstall_collection(self): """Slot called when user clicks the uninstall button.""" # get the QModelIndex for the item to be uninstalled uninstall_index = self.list_view_collections.currentIndex() coll_id = self._selected_collection_id try: self.collection_manager.uninstall(coll_id) except Exception as e: LOGGER.error('Could not uninstall collection ' + config.COLLECTIONS[coll_id]['name'] + ':\n' + str(e)) else: QMessageBox.information( self, 'Resource Sharing', 'The collection was successfully uninstalled!') self.reload_collections_model() # Fix the GUI currentMenuRow = self.menu_list_widget.currentRow() self.set_current_tab(currentMenuRow) self.populate_repositories_widget() rowCount = self.collection_proxy.rowCount() if rowCount > 0: # Set the current (and selected) row in the listview newRow = uninstall_index.row() # Check if this was the last element rowCount = self.collection_proxy.rowCount() if newRow == rowCount: newRow = newRow - 1 # Select the new current element newIndex = self.collections_model.createIndex(newRow, 0) selection_model = self.list_view_collections.selectionModel() selection_model.setCurrentIndex(newIndex, selection_model.ClearAndSelect) # Get the id of the current collection proxyModel = self.list_view_collections.model() proxyIndex = proxyModel.index(newRow, 0) current_coll_id = proxyIndex.data(COLLECTION_ID_ROLE) self._selected_collection_id = current_coll_id # Update buttons status = config.COLLECTIONS[current_coll_id]['status'] if status == COLLECTION_INSTALLED_STATUS: self.button_install.setEnabled(True) self.button_install.setText('Reinstall') self.button_open.setEnabled(True) self.button_uninstall.setEnabled(True) else: self.button_install.setEnabled(True) self.button_install.setText('Install') self.button_open.setEnabled(False) self.button_uninstall.setEnabled(False) # Update the web_view_details frame self.show_collection_metadata(current_coll_id) else: self.button_install.setEnabled(False) self.button_install.setText('Install') self.button_open.setEnabled(False) self.button_uninstall.setEnabled(False)
def uninstall_collection(self): """Slot called when user clicks uninstall button.""" try: self.collection_manager.uninstall(self._selected_collection_id) except Exception as e: raise self.reload_collections_model() QMessageBox.information( self, 'Resource Sharing', 'The collection is uninstalled succesfully!')
def install_finished(self): # Process the result self.progress_dialog.hide() if self.installer_worker.install_status: self.reload_collections_model() message = '%s is installed successfully' % ( config.COLLECTIONS[self._selected_collection_id]['name']) else: message = self.installer_worker.error_message QMessageBox.information(self, 'Resource Sharing', message) # Clean up the worker and thread self.installer_worker.deleteLater() self.installer_thread.quit() self.installer_thread.wait() self.installer_thread.deleteLater()
def install_finished(self): # Process the result self.progress_dialog.hide() installStatus = self.installer_worker.install_status if not installStatus: message = self.installer_worker.error_message # Clean up the worker and thread self.installer_worker.deleteLater() self.installer_thread.quit() self.installer_thread.wait() self.installer_thread.deleteLater() if installStatus: self.reload_collections_model() # Report what has been installed message = ('<b>%s</b> was successfully installed, ' 'containing:\n<ul>' % (config.COLLECTIONS[self._sel_coll_id]['name'])) number = 0 for type_, description in SUPPORTED_RESOURCES_MAP.items(): if type_ in config.COLLECTIONS[self._sel_coll_id].keys(): number = config.COLLECTIONS[self._sel_coll_id][type_] message += (f'\n<li>{number} {description}' f'{"s" if number > 1 else ""}' f'</li>') message += '\n</ul>' QMessageBox.information(self, 'Resource Sharing', message) self.populate_repositories_widget() # Set the selection oldRow = self.current_index.row() newIndex = self.collections_model.createIndex(oldRow, 0) selection_model = self.list_view_collections.selectionModel() selection_model.setCurrentIndex(newIndex, selection_model.ClearAndSelect) selection_model.select(newIndex, selection_model.ClearAndSelect) # Update the buttons self.button_install.setEnabled(True) self.button_install.setText('Reinstall') self.button_open.setEnabled(True) self.button_uninstall.setEnabled(True) self.show_collection_metadata(self._sel_coll_id)
def handle_token(self, answer): """Handle the API answer when asked for a token. This handles the API answer. If it has sent an access token, it calls the initialization function. If not, it raises an error, and ask for new IDs """ logger.info("Asked a token and got a reply from the API.") bytarray = answer.readAll() content = str(bytarray) parsed_content = json.loads(content) if "access_token" in parsed_content: logger.info("The API reply is an access token : " "the request worked as expected.") # TO DO : Appeler la fonction d'initialisation self.token = "Bearer " + parsed_content["access_token"] if self.savedSearch == "first": self.requestStatusClear = True self.set_widget_status() else: self.requestStatusClear = True self.send_request_to_isogeo_api(self.token) # TO DO : Distinguer plusieurs cas d"erreur elif "error" in parsed_content: logger.error("The API reply is an error. Id and secret must be " "invalid. Asking for them again.") QMessageBox.information( iface.mainWindow(), self.tr("Error"), parsed_content["error"]) self.requestStatusClear = True self.auth_prompt_form.show() else: self.requestStatusClear = True logger.error("The API reply has an unexpected form : " "{0}".format(parsed_content)) QMessageBox.information( iface.mainWindow(), self.tr("Error"), self.tr("Unknown error"))
def install_finished(self): # Process the result self.progress_dialog.hide() installStatus = self.installer_worker.install_status if not installStatus: message = self.installer_worker.error_message # Clean up the worker and thread self.installer_worker.deleteLater() self.installer_thread.quit() self.installer_thread.wait() self.installer_thread.deleteLater() if installStatus: self.reload_collections_model() # Report what has been installed message = '<b>%s</b> was successfully installed, containing:\n<ul>' % ( config.COLLECTIONS[self._selected_collection_id]['name']) number = 0 if 'style' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['style'] message = message + '\n<li> ' + str( number) + ' Layer style (QML) file' if number > 1: message = message + 's' if 'symbol' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['symbol'] message = message + '\n<li> ' + str( number) + ' XML symbol file' if number > 1: message = message + 's' if 'svg' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['svg'] message = message + '\n<li> ' + str(number) + ' SVG file' if number > 1: message = message + 's' if 'models' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['models'] message = message + '\n<li> ' + str(number) + ' model' if number > 1: message = message + 's' if 'expressions' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['expressions'] message = message + '\n<li> ' + str( number) + ' expression file' if number > 1: message = message + 's' if 'processing' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['processing'] message = message + '\n<li> ' + str( number) + ' processing script' if number > 1: message = message + 's' if 'rscripts' in config.COLLECTIONS[ self._selected_collection_id].keys(): number = config.COLLECTIONS[ self._selected_collection_id]['rscripts'] message = message + '\n<li> ' + str(number) + ' R script' if number > 1: message = message + 's' message = message + '\n</ul>' QMessageBox.information(self, 'Resource Sharing', message) self.populate_repositories_widget() # Set the selection oldRow = self.current_index.row() newIndex = self.collections_model.createIndex(oldRow, 0) selection_model = self.list_view_collections.selectionModel() selection_model.setCurrentIndex(newIndex, selection_model.ClearAndSelect) selection_model.select(newIndex, selection_model.ClearAndSelect) # Update the buttons self.button_install.setEnabled(True) self.button_install.setText('Reinstall') self.button_open.setEnabled(True) self.button_uninstall.setEnabled(True) self.show_collection_metadata(self._selected_collection_id)
def processFinished(self): self.stopProcessing() QMessageBox.information(self, self.tr("OQ-Consolidate: Info"), 'Consolidation complete.') self.restoreGui()
def test_proxy_configuration(self): """Check adequation between system and QGIS proxy configuration. If a proxy configuration is set up for the computer, and for QGIS. If none or both is set up, pass. But if there is a proxy config for the computer but not in QGIS, pops an alert message. """ system_proxy_config = getproxies() if system_proxy_config == {}: logger.info("No proxy found on the OS: OK.") return 0 else: qgis_proxy = qsettings.value("proxy/proxyEnabled", "") if str(qgis_proxy) == "true": http = system_proxy_config.get('http') if http is None: pass else: elements = http.split(':') if len(elements) == 2: host = elements[0] port = elements[1] qgis_host = qsettings.value("proxy/proxyHost", "") qgis_port = qsettings.value("proxy/proxyPort", "") if qgis_host == host: if qgis_port == port: logger.info("A proxy is set up both in QGIS " "and the OS and they match => " "Proxy config : OK") pass else: QMessageBox.information(iface.mainWindow( ), self.tr("Alert", "Tools"), self.tr("Proxy issue : \nQGIS and your OS " "have different proxy set up.", "Tools")) else: QMessageBox.information(iface.mainWindow( ), self.tr("Alert", "Tools"), self.tr("Proxy issue : \nQGIS and your OS have" " different proxy set ups.", "Tools")) elif len(elements) == 3 and elements[0] == 'http': host_short = elements[1][2:] host_long = elements[0] + ':' + elements[1] port = elements[2] qgis_host = qsettings.value("proxy/proxyHost", "") qgis_port = qsettings.value("proxy/proxyPort", "") if qgis_host == host_short or qgis_host == host_long: if qgis_port == port: logger.info("A proxy is set up both in QGIS" " and the OS and they match " "=> Proxy config : OK") pass else: logger.error("OS and QGIS proxy ports do not " "match. => Proxy config: not OK") QMessageBox.information(iface.mainWindow( ), self.tr("Alert", "Tools"), self.tr("Proxy issue : \nQGIS and your OS" " have different proxy set ups.", "Tools")) else: logger.error("OS and QGIS proxy hosts do not " "match. => Proxy config: not OK") QMessageBox.information(iface.mainWindow( ), self.tr("Alert", "Tools"), self.tr("Proxy issue : \nQGIS and your OS have" " different proxy set ups.", "Tools")) else: logger.error("OS uses a proxy but it isn't set up in QGIS." " => Proxy config: not OK") QMessageBox.information(iface.mainWindow( ), self.tr("Alert", "Tools"), self.tr("Proxy issue : \nYou have a proxy set up on your" " OS but none in QGIS.\nPlease set it up in " "'Preferences/Options/Network'.", "Tools"))
# Sample script for QGIS Init Script # This script will open an info dialog from qgis.PyQt.QtGui import QMessageBox QMessageBox.information(None, "Hello", "Hello World!")