Skip to content

Instantly share code, notes, and snippets.

@slarosa
Last active December 11, 2015 02:59
Show Gist options
  • Save slarosa/4534480 to your computer and use it in GitHub Desktop.
Save slarosa/4534480 to your computer and use it in GitHub Desktop.
diff --git a/python/console/console.py b/python/console/console.py
index 6dd69f1..670e3a3 100644
--- a/python/console/console.py
+++ b/python/console/console.py
@@ -340,6 +340,7 @@ class PythonConsoleWidget(QWidget):
sF.write('\n')
sF.write(s)
sF.close()
+ self.callWidgetMessageBar('Script was correctly saved.')
def openHelp(self):
self.helpDlg.show()
@@ -351,6 +352,9 @@ class PythonConsoleWidget(QWidget):
def prefChanged(self):
self.edit.refreshLexerProperties()
self.textEditOut.refreshLexerProperties()
+
+ def callWidgetMessageBar(self, text):
+ self.textEditOut.widgetMessageBar(iface, text)
if __name__ == '__main__':
a = QApplication(sys.argv)
diff --git a/python/console/console_output.py b/python/console/console_output.py
index 2183997..2108cab 100644
--- a/python/console/console_output.py
+++ b/python/console/console_output.py
@@ -25,6 +25,7 @@ from PyQt4.Qsci import (QsciScintilla,
QsciScintillaBase,
QsciLexerPython)
from qgis.core import QgsApplication
+from qgis.gui import QgsMessageBar
import sys
class writeOut:
@@ -72,6 +73,17 @@ class EditorOutput(QsciScintilla):
self.parent = parent
self.edit = self.parent.edit
+ # Creates layout for message bar
+ self.layout = QGridLayout(self)
+ self.layout.setContentsMargins(0, 0, 0, 0)
+ spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
+ self.layout.addItem(spacerItem, 1, 0, 1, 1)
+
+ self.infoBar = QgsMessageBar(self)
+ sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
+ self.infoBar.setSizePolicy(sizePolicy)
+ self.layout.addWidget(self.infoBar, 0, 0, 1, 1)
+
# Enable non-ascii chars for editor
self.setUtf8(True)
@@ -269,3 +281,7 @@ class EditorOutput(QsciScintilla):
except urllib2.URLError, e:
print "## Connection error ##"
print "## " + str(e.args) + " ##"
+
+ def widgetMessageBar(self, iface, text):
+ timeout = iface.messageTimeout()
+ return self.infoBar.pushMessage(text, QgsMessageBar.INFO, timeout)
diff --git a/python/console/console_sci.py b/python/console/console_sci.py
index 10208fe..1bf0c55 100644
--- a/python/console/console_sci.py
+++ b/python/console/console_sci.py
@@ -40,6 +40,8 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
super(PythonEdit,self).__init__(parent)
code.InteractiveInterpreter.__init__(self, locals=None)
+ self.parent = parent
+
# Enable non-ascii chars for editor
self.setUtf8(True)
@@ -500,17 +502,14 @@ class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
if cmd in ('_save', '_clear', '_clearAll', '_pyqgis', '_api'):
if cmd == '_save':
self.writeHistoryFile()
- print QCoreApplication.translate("PythonConsole",
- "## History saved successfully ##")
+ self.parent.callWidgetMessageBar('History saved successfully')
elif cmd == '_clear':
self.clearHistoryFile()
- print QCoreApplication.translate("PythonConsole",
- "## History cleared successfully ##")
+ self.parent.callWidgetMessageBar('History cleared successfully')
elif cmd == '_clearAll':
self.history = QStringList()
self.clearHistoryFile()
- print QCoreApplication.translate("PythonConsole",
- "## Session and file history cleared successfully ##")
+ self.parent.callWidgetMessageBar('Session and file history cleared successfully')
elif cmd == '_pyqgis':
webbrowser.open( "http://www.qgis.org/pyqgis-cookbook/" )
elif cmd == '_api':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment