Skip to content

Commit

Permalink
Merge pull request #230 from slarosa/master
Browse files Browse the repository at this point in the history
[New Python Console] - remember last used location for Open Tool
  • Loading branch information
timlinux committed Sep 14, 2012
2 parents 396f363 + 89e75cf commit 5b91b38
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 23 deletions.
44 changes: 29 additions & 15 deletions python/console.py
Expand Up @@ -100,33 +100,36 @@ def __init__(self, parent=None):
self.clearButton = QAction(parent)
self.clearButton.setCheckable(False)
self.clearButton.setEnabled(True)
self.clearButton.setIcon(QIcon("icon/iconClearConsole.png"))
self.clearButton.setMenuRole(QAction.PreferencesRole)
self.clearButton.setIconVisibleInMenu(True)
self.clearButton.setToolTip('Clear console')
## Action for paste snippets code
self.clearButton = QAction(parent)
self.clearButton.setCheckable(False)
self.clearButton.setEnabled(True)
self.clearButton.setIcon(QIcon(os.path.dirname(__file__) + "/iconConsole/iconClearConsole.png"))
self.clearButton.setMenuRole(QAction.PreferencesRole)
self.clearButton.setIconVisibleInMenu(True)
self.clearButton.setToolTip('Clear console')
self.clearButton.setText('Clear console')
## Action for paste snippets code
# self.currentLayerButton = QAction(parent)
# self.currentLayerButton.setCheckable(False)
# self.currentLayerButton.setEnabled(True)
# self.currentLayerButton.setIcon(QIcon("icon/iconTempConsole.png"))
# self.currentLayerButton.setMenuRole(QAction.PreferencesRole)
# self.currentLayerButton.setIconVisibleInMenu(True)
##
## Import Sextante class
self.loadSextanteButton = QAction(parent)
self.loadSextanteButton.setCheckable(False)
self.loadSextanteButton.setEnabled(True)
self.loadSextanteButton.setIcon(QIcon(os.path.dirname(__file__) + "iconConsole/iconSextanteConsole.png"))
self.loadSextanteButton.setMenuRole(QAction.PreferencesRole)
self.loadSextanteButton.setIconVisibleInMenu(True)
self.loadSextanteButton.setToolTip('Import sextante class')
self.loadSextanteButton.setText('Import sextante class')
## Import QgisInterface class
self.loadIfaceButton = QAction(parent)
self.loadIfaceButton.setCheckable(False)
self.loadIfaceButton.setEnabled(True)
self.loadIfaceButton.setIcon(QIcon(os.path.dirname(__file__) + "/iconConsole/iconTempConsole.png"))
self.loadIfaceButton.setMenuRole(QAction.PreferencesRole)
self.loadIfaceButton.setIconVisibleInMenu(True)
self.loadIfaceButton.setToolTip('Import iface class')
self.loadIfaceButton.setText('Import iface class')
## Action for Open File
self.openFileButton = QAction(parent)
self.openFileButton.setCheckable(False)
Expand All @@ -135,14 +138,16 @@ def __init__(self, parent=None):
self.openFileButton.setMenuRole(QAction.PreferencesRole)
self.openFileButton.setIconVisibleInMenu(True)
self.openFileButton.setToolTip('Open script file')
self.openFileButton.setText('Open script file')
## Action for Save File
self.saveFileButton = QAction(parent)
self.saveFileButton.setCheckable(False)
self.saveFileButton.setEnabled(True)
self.saveFileButton.setIcon(QIcon(os.path.dirname(__file__) + "/iconConsole/iconSaveConsole.png"))
self.saveFileButton.setMenuRole(QAction.PreferencesRole)
self.saveFileButton.setIconVisibleInMenu(True)
self.saveFileButton.setToolTip('Save to file')
self.saveFileButton.setToolTip('Save to script file')
self.saveFileButton.setText('Save to script file')
## Action for Run script
self.runButton = QAction(parent)
self.runButton.setCheckable(False)
Expand All @@ -151,6 +156,7 @@ def __init__(self, parent=None):
self.runButton.setMenuRole(QAction.PreferencesRole)
self.runButton.setIconVisibleInMenu(True)
self.runButton.setToolTip('Run command')
self.runButton.setText('Run')
## Help action
self.helpButton = QAction(parent)
self.helpButton.setCheckable(False)
Expand All @@ -159,10 +165,12 @@ def __init__(self, parent=None):
self.helpButton.setMenuRole(QAction.PreferencesRole)
self.helpButton.setIconVisibleInMenu(True)
self.helpButton.setToolTip('Help')
self.helpButton.setText('Help')

self.toolBar.addAction(self.clearButton)
#self.toolBar.addAction(self.currentLayerButton)
self.toolBar.addAction(self.loadIfaceButton)
self.toolBar.addAction(self.loadSextanteButton)
self.toolBar.addAction(self.openFileButton)
self.toolBar.addAction(self.saveFileButton)
self.toolBar.addAction(self.helpButton)
Expand All @@ -182,6 +190,7 @@ def __init__(self, parent=None):
self.clearButton.triggered.connect(self.edit.clearConsole)
#self.currentLayerButton.triggered.connect(self.cLayer)
self.loadIfaceButton.triggered.connect(self.iface)
self.loadSextanteButton.activated.connect(self.sextante)
self.runButton.triggered.connect(self.edit.entered)
self.openFileButton.triggered.connect(self.openScriptFile)
self.saveFileButton.triggered.connect(self.saveScriptFile)
Expand All @@ -192,20 +201,28 @@ def __init__(self, parent=None):

def cLayer(self):
self.edit.commandConsole('cLayer')

def sextante(self):
self.edit.commandConsole('sextante')

def iface(self):
self.edit.commandConsole('iface')

def openScriptFile(self):
settings = QSettings()
lastDirPath = settings.value("/pythonConsole/lastDirPath").toString()
scriptFile = QFileDialog.getOpenFileName(
self, "Open File", "", "Script file (*.py)")
self, "Open File", lastDirPath, "Script file (*.py)")
if scriptFile.isEmpty() == False:
oF = open(scriptFile, 'r')
listScriptFile = []
for line in oF:
if line != "\n":
listScriptFile.append(line)
self.edit.insertTextFromFile(listScriptFile)

lastDirPath = QFileInfo(scriptFile).path()
settings.setValue("/pythonConsole/lastDirPath", QVariant(scriptFile))


def saveScriptFile(self):
Expand All @@ -223,13 +240,10 @@ def saveScriptFile(self):
is_first_line = True
for s in listText:
if s[0:3] in (">>>", "..."):
s.replace(">>> ", "")
s.replace("... ", "")
s.replace(">>> ", "").replace("... ", "")
if is_first_line:
# see, no write() in this branch
is_first_line = False
else:
# we've just written a line; add a newline
sF.write('\n')
sF.write(s)
sF.close()
Expand Down
16 changes: 8 additions & 8 deletions python/console_sci.py
Expand Up @@ -21,9 +21,10 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.Qsci import *
from PyQt4.Qsci import QsciScintilla, QsciScintillaBase, QsciLexerPython
#from qgis.utils import iface
from PyQt4.Qsci import (QsciScintilla,
QsciScintillaBase,
QsciLexerPython,
QsciAPIs)

import sys
import os
Expand All @@ -32,11 +33,6 @@

_init_commands = ["from qgis.core import *", "import qgis.utils"]

_console = None

_old_stdout = sys.stdout
_console_output = None

class PythonEdit(QsciScintilla, code.InteractiveInterpreter):
def __init__(self, parent=None):
#QsciScintilla.__init__(self, parent)
Expand Down Expand Up @@ -136,6 +132,10 @@ def commandConsole(self, command):
"""Import QgisInterface class"""
self.append('from qgis.utils import iface')
self.move_cursor_to_end()
elif command == "sextante":
"""Import Sextante class"""
self.append('from sextante.core.Sextante import Sextante')
self.move_cursor_to_end()
elif command == "cLayer":
"""Retrive current Layer from map camvas"""
self.append('cLayer = iface.mapCanvas().currentLayer()')
Expand Down
4 changes: 4 additions & 0 deletions python/helpConsole/help.htm
Expand Up @@ -43,6 +43,10 @@ <h2>Python Console for QGIS</h2>
<td>Tool to import iface class</td>
</tr>
<tr>
<td><img src="../iconConsole/iconSextanteConsole.png" /></td>
<td>Tool to import Sextante class</td>
</tr>
<tr>
<td><img src="../iconConsole/iconOpenConsole.png" /></td>
<td>Tool to open a python script and load in console</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions python/iconConsole/CMakeLists.txt
Expand Up @@ -3,6 +3,7 @@ iconClearConsole.png
iconOpenConsole.png
iconRunConsole.png
iconTempConsole.png
iconSextanteConsole.png
iconSaveConsole.png
iconHelpConsole.png
imgHelpDialog.png
Expand Down
Binary file modified python/iconConsole/iconClearConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/iconConsole/iconHelpConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/iconConsole/iconOpenConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/iconConsole/iconRunConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/iconConsole/iconSaveConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added python/iconConsole/iconSextanteConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python/iconConsole/iconTempConsole.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5b91b38

Please sign in to comment.