Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #387 from slarosa/pyqgis-console
Add QgsMessageBar for pyqgis console
  • Loading branch information
timlinux committed Jan 15, 2013
2 parents 0357f0f + 6768327 commit ce64ede
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
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
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
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 ce64ede

Please sign in to comment.