Don't spam message bar with more of the same error

This commit is contained in:
Nathan Woodrow 2015-09-28 17:33:13 +10:00
parent 6cf2dd0a4c
commit 216821ff38
3 changed files with 10 additions and 0 deletions

View File

@ -49,6 +49,8 @@ class QgsMessageBar: QFrame
//! convenience method for pushing a message with title to the bar
void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );
QgsMessageBarItem *currentItem();
signals:
//! emitted when a message widget is added to the bar
void widgetAdded( QgsMessageBarItem *item );

View File

@ -87,7 +87,13 @@ def showException(type, value, tb, msg, messagebar=False):
QgsMessageLog.logMessage(logmessage, title)
if messagebar and iface:
item = iface.messageBar().currentItem()
if item and item.property("Error") == msg:
# Return of we already have a message with the same error message
return
widget = iface.messageBar().createMessage(title, msg + " See message log (Python Error) for more details.")
widget.setProperty("Error", msg)
button = QPushButton("View message log", pressed=iface.openMessageLog)
widget.layout().addWidget(button)
iface.messageBar().pushWidget(widget, QgsMessageBar.WARNING)

View File

@ -91,6 +91,8 @@ class GUI_EXPORT QgsMessageBar: public QFrame
//! convenience method for pushing a message with title to the bar
void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );
QgsMessageBarItem *currentItem() { return mCurrentItem; }
signals:
//! emitted when a message widget is added to the bar
void widgetAdded( QgsMessageBarItem *item );