def showHtmlMessage(self, title, html): """ Show a message dialog with an HTML body. """ # noinspection PyArgumentList dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle(self._translate(title)) dlg.setMessage(html, QgsMessageOutput.MessageHtml) dlg.showMessage()
def about_triggered(self): # noinspection PyArgumentList dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle(self.tr("Plugin info")) dlg.setMessage(self._plugin_details("oscertstore"), QgsMessageOutput.MessageHtml) dlg.showMessage()
def showLayerInfo(server, userName, repoName, layerName): infoJson = server.layerInfo(userName, repoName, layerName) txt = asHTML(infoJson) dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle("Layer " + layerName) dlg.setMessage(txt, QgsMessageOutput.MessageHtml) dlg.showMessage()
def validateBeforePublication(self): names = [] errors = set() for i in range(self.listLayers.count()): item = self.listLayers.item(i) widget = self.listLayers.itemWidget(item) if widget.checked(): name = widget.name() for c in "?&=#": if c in name: errors.add("Unsupported character in layer name: " + c) if name in names: errors.add("Several layers with the same name") names.append(name) if errors: txt = '''<p><b>Cannot publish data.</b></p> <p>The following issues were found:<p><ul><li>%s</li></ul> ''' % "</li><li>".join(errors) dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle("Publish") dlg.setMessage(txt, QgsMessageOutput.MessageHtml) dlg.showMessage() return False else: return True
def previewMetadata(self): if self.currentLayer is None: return html = self.currentLayer.htmlMetadata() dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle("Layer metadata") dlg.setMessage(html, QgsMessageOutput.MessageHtml) dlg.showMessage()
def open_stack_dialog(type, value, tb, msg, pop_error=True): if pop_error and iface is not None: iface.messageBar().popWidget() if msg is None: msg = QCoreApplication.translate( 'Python', 'An error has occurred while executing Python code:') # TODO Move this to a template HTML file txt = u'''<font color="red"><b>{msg}</b></font> <br> <h3>{main_error}</h3> <pre> {error} </pre> <br> <b>{version_label}</b> {num} <br> <b>{qgis_label}</b> {qversion} {qgisrelease}, {devversion} <br> <h4>{pypath_label}</h4> <ul> {pypath} </ul>''' error = '' lst = traceback.format_exception(type, value, tb) for s in lst: error += s.decode('utf-8', 'replace') if hasattr(s, 'decode') else s error = error.replace('\n', '<br>') main_error = lst[-1].decode('utf-8', 'replace') if hasattr( lst[-1], 'decode') else lst[-1] version_label = QCoreApplication.translate('Python', 'Python version:') qgis_label = QCoreApplication.translate('Python', 'QGIS version:') pypath_label = QCoreApplication.translate('Python', 'Python Path:') txt = txt.format(msg=msg, main_error=main_error, error=error, version_label=version_label, num=sys.version, qgis_label=qgis_label, qversion=Qgis.QGIS_VERSION, qgisrelease=Qgis.QGIS_RELEASE_NAME, devversion=Qgis.QGIS_DEV_VERSION, pypath_label=pypath_label, pypath=u"".join(u"<li>{}</li>".format(path) for path in sys.path)) txt = txt.replace(' ', ' ') # preserve whitespaces for nicer output dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle(msg) dlg.setMessage(txt, QgsMessageOutput.MessageHtml) dlg.showMessage()
def openDetails(self, name): warnings, errors = self.results[name] w = "<br><br>".join(warnings) e = "<br><br>".join(errors) txt = "<p><b>%s</b></p>%s<p><b>%s</b></p>%s" % ( self.tr("Warnings:"), w, self.tr("Errors:"), e) dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle(self.tr("Wanings / Errors")) dlg.setMessage(txt, QgsMessageOutput.MessageHtml) dlg.showMessage()
def showHtmlMessage(self, title, html): """ Show a message dialog with an HTML body. The title is automatically translated. :param title: Header of the HTML dialog (set to "" if no header is required). :param html: The HTML body to display. """ dlg = QgsMessageOutput.createMessageOutput() # noqa dlg.setTitle(self._translate(title)) dlg.setMessage(html, QgsMessageOutput.MessageHtml) dlg.showMessage()
def open_stack_dialog(type, value, tb, msg, pop_error=True): if pop_error: iface.messageBar().popWidget() if msg is None: msg = QCoreApplication.translate("Python", "An error has occurred while executing Python code:") # TODO Move this to a template HTML file txt = u"""<font color="red"><b>{msg}</b></font> <br> <h3>{main_error}</h3> <pre> {error} </pre> <br> <b>{version_label}</b> {num} <br> <b>{qgis_label}</b> {qversion} {qgisrelease}, {devversion} <br> <h4>{pypath_label}</h4> <ul> {pypath} </ul>""" error = "" lst = traceback.format_exception(type, value, tb) for s in lst: error += s.decode("utf-8", "replace") if hasattr(s, "decode") else s error = error.replace("\n", "<br>") main_error = lst[-1].decode("utf-8", "replace") if hasattr(lst[-1], "decode") else lst[-1] version_label = QCoreApplication.translate("Python", "Python version:") qgis_label = QCoreApplication.translate("Python", "QGIS version:") pypath_label = QCoreApplication.translate("Python", "Python Path:") txt = txt.format( msg=msg, main_error=main_error, error=error, version_label=version_label, num=sys.version, qgis_label=qgis_label, qversion=QGis.QGIS_VERSION, qgisrelease=QGis.QGIS_RELEASE_NAME, devversion=QGis.QGIS_DEV_VERSION, pypath_label=pypath_label, pypath=u"".join(u"<li>{}</li>".format(path) for path in sys.path), ) txt = txt.replace(" ", " ") # preserve whitespaces for nicer output dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle(msg) dlg.setMessage(txt, QgsMessageOutput.MessageHtml) dlg.showMessage()
def validateMetadata(self): if self.currentLayer is None: return self.storeMetadata() validator = QgsNativeMetadataValidator() result, errors = validator.validate(self.metadata[self.currentLayer]) if result: txt = self.tr("No validation errors") else: txt = self.tr( "The following issues were found:") + "<br>" + "<br>".join([ "<b>%s</b>:%s" % (err.section, err.note) for err in errors ]) dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle(self.tr("Metadata validation")) dlg.setMessage(txt, QgsMessageOutput.MessageHtml) dlg.showMessage()
def showException(type, value, tb, msg): lst = traceback.format_exception(type, value, tb) if msg == None: msg = QCoreApplication.translate('Python', 'An error has occured while executing Python code:') txt = '<font color="red">%s</font><br><br>' % msg for s in lst: txt += s.decode('utf-8', 'replace') txt += '<br>%s<br>%s<br><br>' % (QCoreApplication.translate('Python','Python version:'), sys.version) txt += '<br>%s<br>%s %s, %s<br><br>' % (QCoreApplication.translate('Python','QGIS version:'), QGis.QGIS_VERSION, QGis.QGIS_RELEASE_NAME, QGis.QGIS_DEV_VERSION) txt += '%s %s' % (QCoreApplication.translate('Python','Python path:'), str(sys.path)) txt = txt.replace('\n', '<br>') txt = txt.replace(' ', ' ') # preserve whitespaces for nicer output from qgis.core import QgsMessageOutput msg = QgsMessageOutput.createMessageOutput() msg.setTitle(QCoreApplication.translate('Python', 'Python error')) msg.setMessage(txt, QgsMessageOutput.MessageHtml) msg.showMessage()
def showException(type, value, tb, msg): lst = traceback.format_exception(type, value, tb) if msg == None: msg = QCoreApplication.translate('Python', 'An error has occured while executing Python code:') txt = '<font color="red">%s</font><br><br><pre>' % msg for s in lst: txt += s.decode('utf-8', 'replace') txt += '</pre><br>%s<br>%s<br><br>' % (QCoreApplication.translate('Python','Python version:'), sys.version) txt += '<br>%s<br>%s %s, %s<br><br>' % (QCoreApplication.translate('Python','QGIS version:'), QGis.QGIS_VERSION, QGis.QGIS_RELEASE_NAME, QGis.QGIS_DEV_VERSION) txt += '%s %s' % (QCoreApplication.translate('Python','Python path:'), str(sys.path)) txt = txt.replace('\n', '<br>') txt = txt.replace(' ', ' ') # preserve whitespaces for nicer output from qgis.core import QgsMessageOutput msg = QgsMessageOutput.createMessageOutput() msg.setTitle(QCoreApplication.translate('Python', 'Python error')) msg.setMessage(txt, QgsMessageOutput.MessageHtml) msg.showMessage()
def showException(type, value, tb, msg): lst = traceback.format_exception(type, value, tb) if msg == None: msg = QCoreApplication.translate("Python", "An error has occured while executing Python code:") txt = '<font color="red">%s</font><br><br>' % msg for s in lst: txt += s.decode("utf-8", "replace") txt += "<br>%s<br>%s<br><br>" % (QCoreApplication.translate("Python", "Python version:"), sys.version) txt += "<br>%s<br>%s %s, %s<br><br>" % ( QCoreApplication.translate("Python", "QGIS version:"), QGis.QGIS_VERSION, QGis.QGIS_RELEASE_NAME, QGis.QGIS_DEV_VERSION, ) txt += "%s %s" % (QCoreApplication.translate("Python", "Python path:"), str(sys.path)) txt = txt.replace("\n", "<br>") txt = txt.replace(" ", " ") # preserve whitespaces for nicer output from qgis.core import QgsMessageOutput msg = QgsMessageOutput.createMessageOutput() msg.setTitle(QCoreApplication.translate("Python", "Python error")) msg.setMessage(txt, QgsMessageOutput.MessageHtml) msg.showMessage()
def about(self): cfg = configparser.ConfigParser() cfg.read(os.path.join(pluginPath, 'metadata.txt')) info = cfg['general'] html = '<style>body, table {padding:0px; margin:0px; font-family:verdana; font-size: 1.1em;}</style>' html += '<body>' html += '<table cellspacing="4" width="100%"><tr><td>' html += '<h1>{}</h1>'.format(info['name']) html += '<h3>{}</h3>'.format(info['description']) if info['about'] != '': html += info['about'].replace('\n', '<br/>') html += '<br/><br/>' if info['category'] != '': html += '{}: {} <br/>'.format('Category', info['category']) if info['tags'] != '': html += '{}: {} <br/>'.format('Tags', info['tags']) if info['homepage'] != '' or info['tracker'] != '' or info[ 'code_repository'] != '': html += 'More info:' if info['homepage'] != '': html += '<a href="{}">{}</a> '.format( info['homepage'], 'Homepage') if info['tracker'] != '': html += '<a href="{}">{}</a> '.format( info['tracker'], 'Bug tracker') if info['repository'] != '': html += '<a href="{}">{}</a> '.format( info['repository'], 'Code repository') html += '<br/>' html += '<br/>' if info['email'] != '': html += '{}: <a href="mailto:{}">{}</a>'.format( 'Author', info['email'], info['author']) html += '<br/><br/>' elif info['author'] != '': html += '{}: {}'.format('Author', info['author']) html += '<br/><br/>' if info['version'] != '': html += 'Installed version: {}<br/>'.format(info['version']) if 'changelog' in info and info['changelog'] != '': html += '<br/>' changelog = 'Changelog:<br/>{} <br/>'.format(info['changelog']) html += changelog.replace('\n', '<br/>') html += '</td></tr></table>' html += '</body>' dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle('Plugin Info') dlg.setMessage(html, QgsMessageOutput.MessageHtml) dlg.showMessage()
def showMore(): dlg = QgsMessageOutput.createMessageOutput() dlg.setTitle('Profile errors') dlg.setMessage("<br><br>".join(pluginErrors), QgsMessageOutput.MessageHtml) dlg.showMessage()
def show_details(details): dialog = QgsMessageOutput.createMessageOutput() dialog.setTitle(title) dialog.setMessage(long_message, QgsMessageOutput.MessageHtml) dialog.showMessage()