Skip to content

Commit

Permalink
Add QgsMessageBar for pyqgis console
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed Jan 15, 2013
1 parent 0357f0f commit 6768327
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
21 changes: 18 additions & 3 deletions python/console/console_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
QsciScintillaBase,
QsciLexerPython)
from qgis.core import QgsApplication
from qgis.gui import QgsMessageBar
import sys

class writeOut:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
11 changes: 5 additions & 6 deletions python/console/console_sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 6768327

Please sign in to comment.