当前位置: 首页>>代码示例>>Python>>正文


Python QApplication.instance方法代码示例

本文整理汇总了Python中qgis.PyQt.QtWidgets.QApplication.instance方法的典型用法代码示例。如果您正苦于以下问题:Python QApplication.instance方法的具体用法?Python QApplication.instance怎么用?Python QApplication.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.PyQt.QtWidgets.QApplication的用法示例。


在下文中一共展示了QApplication.instance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from qgis.PyQt.QtWidgets import QApplication [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QApplication import instance [as 别名]
    def __init__(self, parent=None):
        super(EditorWidgetTms, self).__init__(parent)
        self.setupUi(self)
        self.tms_validator = LineEditColorValidator(self.txtUrl, 'http[s]?://.+', error_tooltip='http{s}://any_text/{z}/{x}/{y}/')
        self.txtCrsId.setValidator(QIntValidator())
        self.txtPostgisCrsId.setValidator(QIntValidator())

        QApplication.instance().focusChanged.connect(self.focus_changed)
开发者ID:nextgis,项目名称:quickmapservices,代码行数:10,代码来源:editor_widget_tms.py

示例2: showException

# 需要导入模块: from qgis.PyQt.QtWidgets import QApplication [as 别名]
# 或者: from qgis.PyQt.QtWidgets.QApplication import instance [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)
开发者ID:rouault,项目名称:Quantum-GIS,代码行数:51,代码来源:utils.py


注:本文中的qgis.PyQt.QtWidgets.QApplication.instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。