Skip to content

Commit 18df003

Browse files
committedOct 22, 2015
Use front window to show python error if there is message bar
1 parent c7eef14 commit 18df003

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed
 

‎python/utils.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,35 @@ def showException(type, value, tb, msg, messagebar=False):
7575
QgsMessageLog.logMessage(logmessage, title)
7676

7777
blockingdialog = QApplication.instance().activeModalWidget()
78+
window = QApplication.instance().activeWindow()
7879

79-
if messagebar and iface and not blockingdialog:
80-
item = iface.messageBar().currentItem()
81-
if item and item.property("Error") == msg:
82-
# Return of we already have a message with the same error message
83-
return
84-
85-
widget = iface.messageBar().createMessage(title, msg + " See message log (Python Error) for more details.")
86-
widget.setProperty("Error", msg)
87-
stackbutton = QPushButton("Stack trace", pressed=functools.partial(open_stack_dialog, type, value, tb, msg))
88-
button = QPushButton("View message log", pressed=show_message_log)
89-
widget.layout().addWidget(stackbutton)
90-
widget.layout().addWidget(button)
91-
iface.messageBar().pushWidget(widget, QgsMessageBar.WARNING)
92-
else:
80+
# Still show the normal blocking dialog in this case for now.
81+
if blockingdialog or not window or not messagebar or not iface:
9382
open_stack_dialog(type, value, tb, msg)
83+
return
84+
85+
bar = iface.messageBar()
86+
87+
# If it's not the main window see if we can find a message bar to report the error in
88+
if not window.objectName() == "QgisApp":
89+
widgets = window.findChildren(QgsMessageBar)
90+
if widgets:
91+
# Grab the first message bar for now
92+
bar = widgets[0]
93+
94+
95+
item = bar.currentItem()
96+
if item and item.property("Error") == msg:
97+
# Return of we already have a message with the same error message
98+
return
99+
100+
widget = bar.createMessage(title, msg + " See message log (Python Error) for more details.")
101+
widget.setProperty("Error", msg)
102+
stackbutton = QPushButton("Stack trace", pressed=functools.partial(open_stack_dialog, type, value, tb, msg))
103+
button = QPushButton("View message log", pressed=show_message_log)
104+
widget.layout().addWidget(stackbutton)
105+
widget.layout().addWidget(button)
106+
bar.pushWidget(widget, QgsMessageBar.WARNING)
94107

95108

96109
def show_message_log(pop_error=True):

0 commit comments

Comments
 (0)
Please sign in to comment.