Skip to content

Commit

Permalink
Don't spam message bar with more of the same error
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Sep 28, 2015
1 parent 6cf2dd0 commit 216821f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/gui/qgsmessagebar.sip
Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions python/utils.py
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmessagebar.h
Expand Up @@ -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 );
Expand Down

0 comments on commit 216821f

Please sign in to comment.