Skip to content
Permalink
Browse files
Add QgsMessageBar for pyqgis console
  • Loading branch information
slarosa committed Jan 15, 2013
1 parent 0357f0f commit 6768327edb699ea6ec19fee280bd82e3a2ca35ca
Showing with 27 additions and 9 deletions.
  1. +4 −0 python/console/console.py
  2. +18 −3 python/console/console_output.py
  3. +5 −6 python/console/console_sci.py
@@ -340,6 +340,7 @@ def saveScriptFile(self):
sF.write('\n')
sF.write(s)
sF.close()
self.callWidgetMessageBar('Script was correctly saved.')

def openHelp(self):
self.helpDlg.show()
@@ -351,6 +352,9 @@ def openSettings(self):
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)
@@ -25,6 +25,7 @@
QsciScintillaBase,
QsciLexerPython)
from qgis.core import QgsApplication
from qgis.gui import QgsMessageBar
import sys

class writeOut:
@@ -72,6 +73,17 @@ def __init__(self, parent=None):
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)
# messageBar instance
self.infoBar = QgsMessageBar()
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)

@@ -265,7 +277,10 @@ def pastebin(self):
link = i.replace('<a href="',"").strip()
if link:
QApplication.clipboard().setText(link)
print "## URL copied to clipboard ##"
self.parent.callWidgetMessageBar('URL copied to clipboard')
except urllib2.URLError, e:
print "## Connection error ##"
print "## " + str(e.args) + " ##"
self.parent.callWidgetMessageBar('Connection error: ' + str(e.args))

def widgetMessageBar(self, iface, text):
timeout = iface.messageTimeout()
self.infoBar.pushMessage(text, QgsMessageBar.INFO, timeout)
@@ -40,6 +40,8 @@ def __init__(self, parent=None):
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 @@ def runCommand(self, cmd):
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':

0 comments on commit 6768327

Please sign in to comment.