本文整理汇总了Python中qgis.PyQt.QtWidgets.QApplication.activeWindow方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.activeWindow方法的具体用法?Python QApplication.activeWindow怎么用?Python QApplication.activeWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtWidgets.QApplication
的用法示例。
在下文中一共展示了QApplication.activeWindow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: showException
# 需要导入模块: from qgis.PyQt.QtWidgets import QApplication [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QApplication import activeWindow [as 别名]
def showException(type, value, tb, msg, messagebar=False):
if msg is None:
msg = QCoreApplication.translate("Python", "An error has occurred while executing Python code:")
logmessage = ""
for s in traceback.format_exception(type, value, tb):
logmessage += s.decode("utf-8", "replace") if hasattr(s, "decode") else s
title = QCoreApplication.translate("Python", "Python error")
QgsMessageLog.logMessage(logmessage, title)
try:
blockingdialog = QApplication.instance().activeModalWidget()
window = QApplication.instance().activeWindow()
except:
blockingdialog = QApplication.activeModalWidget()
window = QApplication.activeWindow()
# Still show the normal blocking dialog in this case for now.
if blockingdialog or not window or not messagebar or not iface:
open_stack_dialog(type, value, tb, msg)
return
bar = iface.messageBar()
# If it's not the main window see if we can find a message bar to report the error in
if not window.objectName() == "QgisApp":
widgets = window.findChildren(QgsMessageBar)
if widgets:
# Grab the first message bar for now
bar = widgets[0]
item = bar.currentItem()
if item and item.property("Error") == msg:
# Return of we already have a message with the same error message
return
widget = bar.createMessage(
title, msg + " " + QCoreApplication.translate("Python", "See message log (Python Error) for more details.")
)
widget.setProperty("Error", msg)
stackbutton = QPushButton(
QCoreApplication.translate("Python", "Stack trace"),
pressed=functools.partial(open_stack_dialog, type, value, tb, msg),
)
button = QPushButton(QCoreApplication.translate("Python", "View message log"), pressed=show_message_log)
widget.layout().addWidget(stackbutton)
widget.layout().addWidget(button)
bar.pushWidget(widget, QgsMessageBar.WARNING)