예제 #1
0
파일: utils.py 프로젝트: QtWorks/QGIS
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 iface else None

    # 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, Qgis.Warning)
예제 #2
0
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)
 def choose_linked_feature():
     dlg = QApplication.activeModalWidget()
     dlg.setSelectedFeatures([f.id()])
     dlg.accept()
예제 #4
0
 def choose_linked_feature():
     dlg = QApplication.activeModalWidget()
     dlg.setSelectedFeatures([f.id()])
     dlg.accept()