Skip to content

Commit ca20be1

Browse files
committedOct 19, 2012
[FEATURE] - Choose Fontfamily and API files for Python Console
- update Italian translation - added Settings icon for toolbar - update Italian translation fro console_help
1 parent d06203b commit ca20be1

15 files changed

+568
-53
lines changed
 

‎i18n/qgis_it.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6450,6 +6450,10 @@ Cambiare questa situazione prima, perché il plugin OSM non quale layer è la de
64506450
<source>Save to script file</source>
64516451
<translation>Salva file</translation>
64526452
</message>
6453+
<message>
6454+
<source>Settings</source>
6455+
<translation>Impostazioni</translation>
6456+
</message>
64536457
<message>
64546458
<source>Help</source>
64556459
<translation>Aiuto</translation>

‎images/console/iconAboutConsole.png

1.38 KB
Loading

‎images/images.qrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
<file>console/iconClassConsole.png</file>
469469
<file>console/iconSaveConsole.png</file>
470470
<file>console/iconHelpConsole.png</file>
471-
<file>console/iconTempConsole.png</file>
471+
<file>console/iconSettingsConsole.png</file>
472472
<file>console/iconOpenConsole.png</file>
473473
<file>console/iconClearConsole.png</file>
474474
<file>console/imgHelpDialog.png</file>
@@ -478,6 +478,7 @@
478478
<file>console/iconQtCoreConsole.png</file>
479479
<file>console/iconQtGuiConsole.png</file>
480480
<file>console/iconRunConsole.png</file>
481+
<file>console/iconAboutConsole.png</file>
481482
</qresource>
482483
<qresource prefix="/images/tips">
483484
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>

‎python/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ ADD_CUSTOM_COMMAND(TARGET compile_python_files
149149
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
150150
)
151151

152-
FOREACH(file __init__.py utils.py console.py console_sci.py console_help.py)
152+
FILE(GLOB UI_FILES *.ui)
153+
PYQT4_WRAP_UI(PYUI_FILES ${UI_FILES})
154+
ADD_CUSTOM_TARGET(console ALL DEPENDS ${PYUI_FILES})
155+
INSTALL(FILES ${PYUI_FILES} DESTINATION ${QGIS_PYTHON_DIR})
156+
157+
FOREACH(file __init__.py utils.py console.py console_sci.py console_help.py console_settings.py)
153158
ADD_CUSTOM_COMMAND(TARGET compile_python_files
154159
POST_BUILD
155160
COMMAND ${CMAKE_COMMAND} -E copy ${file} ${QGIS_PYTHON_OUTPUT_DIRECTORY}
@@ -163,3 +168,4 @@ PYTHON_INSTALL(utils.py ${QGIS_PYTHON_DIR})
163168
PYTHON_INSTALL(console.py ${QGIS_PYTHON_DIR})
164169
PYTHON_INSTALL(console_sci.py ${QGIS_PYTHON_DIR})
165170
PYTHON_INSTALL(console_help.py ${QGIS_PYTHON_DIR})
171+
PYTHON_INSTALL(console_settings.py ${QGIS_PYTHON_DIR})

‎python/console.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from qgis.utils import iface
2525
from console_sci import PythonEdit
2626
from console_help import HelpDialog
27+
from console_settings import optionsDialog
2728

2829
import sys
2930
import os
@@ -66,7 +67,7 @@ def get_and_clean_data(self):
6667
def flush(self):
6768
pass
6869

69-
sys.stdout = QgisOutputCatcher()
70+
sys.stdout = QgisOutputCatcher()
7071

7172
class PythonConsole(QDockWidget):
7273
def __init__(self, parent=None):
@@ -82,14 +83,14 @@ def __init__(self, parent=None):
8283
if iface and not iface.mainWindow().restoreDockWidget(self):
8384
iface.mainWindow().addDockWidget(Qt.BottomDockWidgetArea, self)
8485

85-
8686
class PythonConsoleWidget(QWidget):
8787
def __init__(self, parent=None):
8888
QWidget.__init__(self, parent)
8989
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
9090

9191
self.widgetButton = QWidget()
92-
92+
self.options = optionsDialog(self)
93+
9394
self.toolBar = QToolBar()
9495
self.toolBar.setEnabled(True)
9596
#self.toolBar.setFont(font)
@@ -121,13 +122,16 @@ def __init__(self, parent=None):
121122
self.clearButton.setIconVisibleInMenu(True)
122123
self.clearButton.setToolTip(clearBt)
123124
self.clearButton.setText(clearBt)
124-
## Action for paste snippets code
125-
# self.currentLayerButton = QAction(parent)
126-
# self.currentLayerButton.setCheckable(False)
127-
# self.currentLayerButton.setEnabled(True)
128-
# self.currentLayerButton.setIcon(QIcon("icon/iconTempConsole.png"))
129-
# self.currentLayerButton.setMenuRole(QAction.PreferencesRole)
130-
# self.currentLayerButton.setIconVisibleInMenu(True)
125+
## Action for settings
126+
optionsBt = QCoreApplication.translate("PythonConsole", "Settings")
127+
self.optionsButton = QAction(parent)
128+
self.optionsButton.setCheckable(False)
129+
self.optionsButton.setEnabled(True)
130+
self.optionsButton.setIcon(QIcon(":/images/console/iconSettingsConsole.png"))
131+
self.optionsButton.setMenuRole(QAction.PreferencesRole)
132+
self.optionsButton.setIconVisibleInMenu(True)
133+
self.optionsButton.setToolTip(optionsBt)
134+
self.optionsButton.setText(optionsBt)
131135
## Action menu for class
132136
actionClassBt = QCoreApplication.translate("PythonConsole", "Import Class")
133137
self.actionClass = QAction(parent)
@@ -232,6 +236,7 @@ def __init__(self, parent=None):
232236
self.toolBar.addAction(self.clearButton)
233237
self.toolBar.addAction(self.actionClass)
234238
self.toolBar.addAction(self.actionScript)
239+
self.toolBar.addAction(self.optionsButton)
235240
self.toolBar.addAction(self.helpButton)
236241
self.toolBar.addAction(self.runButton)
237242
## Menu Import Class
@@ -261,7 +266,7 @@ def __init__(self, parent=None):
261266
self.edit.setFocus()
262267

263268
self.clearButton.triggered.connect(self.edit.clearConsole)
264-
#self.currentLayerButton.triggered.connect(self.cLayer)
269+
self.optionsButton.triggered.connect(self.openSettings)
265270
self.loadIfaceButton.triggered.connect(self.iface)
266271
self.loadSextanteButton.triggered.connect(self.sextante)
267272
self.loadQtCoreButton.triggered.connect(self.qtCore)
@@ -270,9 +275,8 @@ def __init__(self, parent=None):
270275
self.openFileButton.triggered.connect(self.openScriptFile)
271276
self.saveFileButton.triggered.connect(self.saveScriptFile)
272277
self.helpButton.triggered.connect(self.openHelp)
273-
274-
def cLayer(self):
275-
self.edit.commandConsole('cLayer')
278+
QObject.connect(self.options.buttonBox, SIGNAL("accepted()"),
279+
self.prefChanged)
276280

277281
def sextante(self):
278282
self.edit.commandConsole('sextante')
@@ -288,7 +292,7 @@ def qtGui(self):
288292

289293
def openScriptFile(self):
290294
settings = QSettings()
291-
lastDirPath = settings.value("/pythonConsole/lastDirPath").toString()
295+
lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
292296
scriptFile = QFileDialog.getOpenFileName(
293297
self, "Open File", lastDirPath, "Script file (*.py)")
294298
if scriptFile.isEmpty() == False:
@@ -300,7 +304,7 @@ def openScriptFile(self):
300304
self.edit.insertTextFromFile(listScriptFile)
301305

302306
lastDirPath = QFileInfo(scriptFile).path()
303-
settings.setValue("/pythonConsole/lastDirPath", QVariant(scriptFile))
307+
settings.setValue("pythonConsole/lastDirPath", QVariant(scriptFile))
304308

305309

306310
def saveScriptFile(self):
@@ -329,12 +333,18 @@ def saveScriptFile(self):
329333
def openHelp(self):
330334
dlg = HelpDialog()
331335
dlg.exec_()
336+
337+
def openSettings(self):
338+
#options = optionsDialog()
339+
self.options.exec_()
340+
341+
def prefChanged(self):
342+
self.edit.refreshLexerProperties()
332343

333344
def closeEvent(self, event):
334345
self.edit.writeHistoryFile()
335346
QWidget.closeEvent(self, event)
336347

337-
338348
if __name__ == '__main__':
339349
a = QApplication(sys.argv)
340350
console = PythonConsoleWidget()

‎python/console_help/help.htm

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h2 id="headerTitle">Python Console for QGIS</h2>
3434
</tr>
3535
</table>
3636
<p align="justify">
37-
<span id="headerSubject">Python Console based on PyQScintilla2. (Developed by Salvatore Larosa)</span>
37+
<span id="headerSubject">Python Console based on PyQScintilla2.</span>
3838
<br><br>
3939
<span id="headerSubjectMain">To access Quantum GIS environment from this console
4040
use qgis.utils.iface object (instance of QgisInterface class).
@@ -64,16 +64,22 @@ <h4 id="features">Features</h4>
6464
<br>
6565
<li><span id="featuresB">CTRL+ALT+SPACE to view the command history list.</span></li>
6666
<br>
67+
<li><span id="featuresLoadAPI">Open Quantum GIS API documentation by typing <b>_api</b>.</span></li>
68+
<br>
69+
<li><span id="featuresLoadCookBook">Open PyQGIS Cookbook by typing <b>_pyqgis</b>.</span>
70+
</li>
71+
<br>
6772
<li><span id="featuresC">Saves the command history by typing <b>_save</b> or closing the widget.<br>
6873
This command saves the history command in the file ~/.qgis/console_history.txt</span>
6974
</li>
7075
<br>
7176
<li><span id="featuresD">Clears the command history by typing <b>_clear</b>.<br>
72-
This command clears the command history from file ~/.qgis/console_history.txt</span>
77+
This command clears the temporary command history</span>
7378
</li>
7479
<br>
7580
<li><span id="featuresE">Clears completely command history by typing <b>_clearAll</b>.<br>
76-
This command clears completely the command history. It has an irreversible effect.</span>
81+
This command clears completely the command history (both temporary and ~/.qgis/console_history.txt).
82+
It has an irreversible effect.</span>
7783
</li>
7884
</ul>
7985
</p>
@@ -120,6 +126,10 @@ <h4 id="toolbar">Toolbar</h4>
120126
<td><img src="qrc:/images/console/iconSaveConsole.png" /></td>
121127
<td><span id="toolbarScriptSave">Tool to save a python script</span></td>
122128
</tr>
129+
<tr>
130+
<td><img src="qrc:/images/console/iconSettingsConsole.png" /></td>
131+
<td colspan="2"><span id="toolbarSettings">Settings</span></td>
132+
</tr>
123133
<tr>
124134
<td><img src="qrc:/images/console/iconHelpConsole.png" /></td>
125135
<td colspan="2"><span id="toolbarHelp">Help</span></td>

‎python/console_help/i18n/de_DE.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
i18n_dict = {
22
"header.title" : "Python Console für QGIS",
3-
"header.subject" : "Python Console auf PyQScintilla2 basierend (entwickelt von Salvatore Larosa)",
3+
"header.subject" : "Python Console auf PyQScintilla2 basierend",
44
"header.subject.main" : "Das Objekt qgis.utils.iface (Instanz der Klasse QgisInterface) ermöglicht den Zugriff \
55
quf die Quantum GIS Umgebung von der Konsole aus. \
66
Über den defür bestimmten Knopf in der Werkzeugleiste \

‎python/console_help/i18n/en_US.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
i18n_dict = {
22
"header.title" : "Python Console for QGIS",
3-
"header.subject" : "Python Console based on PyQScintilla2. (Developed by Salvatore Larosa)",
3+
"header.subject" : "Python Console based on PyQScintilla2.",
44
"header.subject.main" : "To access Quantum GIS environment from this console \
55
use qgis.utils.iface object (instance of QgisInterface class). \
66
To import the class QgisInterface can also use the dedicated \
@@ -15,6 +15,8 @@ i18n_dict = {
1515
This command clears the command history from file ~/.qgis/console_history.txt",
1616
"features.e" : "Clears completely command history by typing '_clearAll'. \
1717
This command clears completely the command history. It has an irreversible effect.",
18+
"features.api.doc" : "Open Quantum GIS API documentation by typing '_api'.",
19+
"features.pyqgis.doc" : "Open PyQGIS Cookbook by typing '_pyqgis'.",
1820
"toolbar" : "Toolbar",
1921
"toolbar.title" : "The following is a description of the tools in the toolbar:",
2022
"toolbar.clear" : "Tool to clear python console",
@@ -24,6 +26,7 @@ i18n_dict = {
2426
"toolbar.qtgui" : "Tool to import PyQt4.QtGui class",
2527
"toolbar.script.open" : "Tool to open a python script and load in console",
2628
"toolbar.script.save" : "Tool to save a python script",
29+
"toolbar.settings" : "Settings",
2730
"toolbar.help" : "Help",
2831
"toolbar.run" : "Run command (like Enter key pressed)",
2932
"thanks" : "Acknowledgments",

‎python/console_help/i18n/it_IT.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
i18n_dict = {
22
"header.title" : "Console Python per QGIS",
3-
"header.subject" : "Console Python basata su PyQScintilla2. (Sviluppata da Salvatore Larosa)",
3+
"header.subject" : "Console Python basata su PyQScintilla2.",
44
"header.subject.main" : "Per accedere all'ambiente Quantum GIS da questa console \
55
usa l'oggetto qgis.utils.iface (istanza della classe QgisInterface). \
66
Per importare la classe QgisInterface puoi usare anche il bottone dedicato che si trova \
@@ -15,6 +15,8 @@ i18n_dict = {
1515
La cronologia verrà cancellata dal file ~/.qgis/console_history.txt",
1616
"features.e" : "Possibilità di cancellare completamente la cronologia dei comandi digitando '_clearAll'. \
1717
La cronologia verrà cancellata sia dal file che dalla memoria temporanea.",
18+
"features.api.doc" : "Apri la documentazione completa sulle API di QuantumGIS digitando '_api'.",
19+
"features.pyqgis.doc" : "Apri il Cookbook PyQGIS digitando '_pyqgis'.",
1820
"toolbar" : "Toolbar",
1921
"toolbar.title" : "Di seguito la descrizione dei comandi disponibile nella toolbar:",
2022
"toolbar.clear" : "Strumento per pulire la console",
@@ -24,6 +26,7 @@ i18n_dict = {
2426
"toolbar.qtgui" : "Strumento per importare la classe PyQt4.QtGui",
2527
"toolbar.script.open" : "Strumento per aprire un script python da eseguire in console",
2628
"toolbar.script.save" : "Strumento per salvare uno script python sul disco",
29+
"toolbar.settings" : "Impostazioni",
2730
"toolbar.help" : "Aiuto",
2831
"toolbar.run" : "Esegui comando (simile al tasto <Invio>)",
2932
"thanks" : "Ringraziamenti",

‎python/console_help/i18n/ru_RU.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
i18n_dict = {
22
"header.title" : "Консоль Python для QGIS",
3-
"header.subject" : "Консоль Python на основе PyQScintilla2. (Разработана Salvatore Larosa)",
3+
"header.subject" : "Консоль Python на основе PyQScintilla2.",
44
"header.subject.main" : "Для доступа к окружению Quantum GIS из консоли \
55
используйте объект qgis.utils.iface (экземпляр класса QgisInterface). \
66
Также можно импортировать класс QgisInterface при помощи специальной \

‎python/console_help/js/encoding.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $('span#featuresB').text($.i18n._('features.b'));
1010
$('span#featuresC').text($.i18n._('features.c'));
1111
$('span#featuresD').text($.i18n._('features.d'));
1212
$('span#featuresE').text($.i18n._('features.e'));
13+
$('span#featuresLoadAPI').text($.i18n._('features.api.doc'));
14+
$('span#featuresLoadCookBook').text($.i18n._('features.pyqgis.doc'));
1315
$('h4#toolbar').text($.i18n._('toolbar'));
1416
$('span#toolbarTitle').text($.i18n._('toolbar.title'));
1517
$('span#toolbarClear').text($.i18n._('toolbar.clear'));
@@ -20,6 +22,7 @@ $('span#toolbarQtGuiClass').text($.i18n._('toolbar.qtgui'));
2022
$('span#toolbarScriptOpen').text($.i18n._('toolbar.script.open'));
2123
$('span#toolbarScriptSave').text($.i18n._('toolbar.script.save'));
2224
$('span#toolbarHelp').text($.i18n._('toolbar.help'));
25+
$('span#toolbarSettings').text($.i18n._('toolbar.settings'));
2326
$('span#toolbarRun').text($.i18n._('toolbar.run'));
2427
$('h4#thanks').text($.i18n._('thanks'));
2528
$('span#thanksText').text($.i18n._('thanks.text'));

‎python/console_sci.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self, parent=None):
7373
# Set Python lexer
7474
# Set style for Python comments (style number 1) to a fixed-width
7575
# courier.
76-
self.setLexers(True)
76+
self.setLexers()
7777

7878
# Indentation
7979
#self.setAutoIndent(True)
@@ -120,10 +120,11 @@ def showHistory(self):
120120

121121
def autoComplete(self):
122122
self.autoCompleteFromAll()
123-
123+
124124
def clearConsole(self):
125125
"""Clear the contents of the console."""
126-
self.setText('')
126+
self.SendScintilla(QsciScintilla.SCI_CLEARALL)
127+
#self.setText('')
127128
self.insertInitText()
128129
self.displayPrompt(False)
129130
self.setFocus()
@@ -156,32 +157,39 @@ def commandConsole(self, command):
156157
self.append('from PyQt4.QtGui import *')
157158
self.move_cursor_to_end()
158159
self.setFocus()
159-
160-
def setLexers(self, lexer):
160+
161+
def setLexers(self):
161162
from qgis.core import QgsApplication
162-
if lexer:
163-
font = QFont()
164-
font.setFamily('Mono') ## Courier New
165-
font.setFixedPitch(True)
166-
## check platform for font size
167-
if sys.platform.startswith('darwin'):
168-
font.setPointSize(13)
169-
else:
170-
font.setPointSize(10)
171-
self.setFont(font)
172-
self.setMarginsFont(font)
173-
self.lexer = QsciLexerPython()
174-
self.lexer.setDefaultFont(font)
175-
self.lexer.setColor(Qt.red, 1)
176-
self.lexer.setColor(Qt.darkGreen, 5)
177-
self.lexer.setColor(Qt.darkBlue, 15)
178-
self.lexer.setFont(font, 1)
179-
self.lexer.setFont(font, 3)
180-
self.lexer.setFont(font, 4)
181-
self.api = QsciAPIs(self.lexer)
163+
164+
self.lexer = QsciLexerPython()
165+
settings = QSettings()
166+
loadFont = settings.value("pythonConsole/fontfamilytext", "Monospace").toString()
167+
fontSize = settings.value("pythonConsole/fontsize", 10).toInt()[0]
168+
169+
font = QFont(loadFont)
170+
font.setFixedPitch(True)
171+
font.setPointSize(fontSize)
172+
173+
self.lexer.setDefaultFont(font)
174+
self.lexer.setColor(Qt.red, 1)
175+
self.lexer.setColor(Qt.darkGreen, 5)
176+
self.lexer.setColor(Qt.darkBlue, 15)
177+
self.lexer.setFont(font, 1)
178+
self.lexer.setFont(font, 3)
179+
self.lexer.setFont(font, 4)
180+
181+
self.api = QsciAPIs(self.lexer)
182+
chekBoxAPI = settings.value( "pythonConsole/preloadAPI" ).toBool()
183+
if chekBoxAPI:
182184
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
185+
else:
186+
apiPath = settings.value("pythonConsole/userAPI").toStringList()
187+
for i in range(0, len(apiPath)):
188+
self.api.load(QString(unicode(apiPath[i])))
189+
self.api.prepare()
190+
self.lexer.setAPIs(self.api)
183191

184-
self.setLexer(self.lexer)
192+
self.setLexer(self.lexer)
185193

186194
## TODO: show completion list for file and directory
187195

@@ -263,6 +271,9 @@ def new_prompt(self, prompt):
263271
self.ensureCursorVisible()
264272
self.ensureLineVisible(line)
265273

274+
def refreshLexerProperties(self):
275+
self.setLexers()
276+
266277
# def check_selection(self):
267278
# """
268279
# Check if selected text is r/w,
@@ -484,9 +495,10 @@ def currentCommand(self):
484495
return cmd
485496

486497
def runCommand(self, cmd):
498+
import webbrowser
487499
self.updateHistory(cmd)
488500
self.SendScintilla(QsciScintilla.SCI_NEWLINE)
489-
if cmd in ('_save', '_clear', '_clearAll'):
501+
if cmd in ('_save', '_clear', '_clearAll', '_pyqgis', '_api'):
490502
if cmd == '_save':
491503
self.writeHistoryFile()
492504
print QCoreApplication.translate("PythonConsole",
@@ -508,6 +520,11 @@ def runCommand(self, cmd):
508520
self.clearHistoryFile()
509521
print QCoreApplication.translate("PythonConsole",
510522
"## History cleared successfully ##")
523+
elif cmd == '_pyqgis':
524+
webbrowser.open( "http://www.qgis.org/pyqgis-cookbook/" )
525+
elif cmd == '_api':
526+
webbrowser.open( "http://www.qgis.org/api/" )
527+
511528
output = sys.stdout.get_and_clean_data()
512529
if output:
513530
self.append(output)

‎python/console_settings.py

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# -*- coding:utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
Python Conosle for QGIS
5+
-------------------
6+
begin : 2012-09-10
7+
copyright : (C) 2012 by Salvatore Larosa
8+
email : lrssvtml (at) gmail (dot) com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
Some portions of code were taken from https://code.google.com/p/pydee/
20+
"""
21+
22+
from PyQt4.QtCore import *
23+
from PyQt4.QtGui import *
24+
25+
from ui_console_settings import Ui_SettingsDialog
26+
27+
class optionsDialog(QDialog, Ui_SettingsDialog):
28+
def __init__(self, parent):
29+
QDialog.__init__(self, parent)
30+
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Settings Python Console"))
31+
#self.iface = iface
32+
self.parent = parent
33+
self.setupUi(self)
34+
#self.show()
35+
36+
self.listPath = []
37+
38+
self.restoreSettings()
39+
self.initialCheck()
40+
self.fontConfig()
41+
42+
self.lineEdit.setReadOnly(True)
43+
self.tabWidget.setTabText(0, QCoreApplication.translate("PythonConsole", "General"))
44+
self.tabWidget.setTabIcon(0, QIcon(":/images/themes/default/propertyicons/general.png"))
45+
self.tabWidget.setTabText(1, QCoreApplication.translate("PythonConsole", "About"))
46+
self.tabWidget.setTabIcon(1, QIcon(":/images/console/iconAboutConsole.png"))
47+
48+
self.addAPIpath.setIcon(QIcon(":/images/themes/default/symbologyAdd.png"))
49+
self.addAPIpath.setToolTip(QCoreApplication.translate("PythonConsole", "Add API path"))
50+
self.removeAPIpath.setIcon(QIcon(":/images/themes/default/symbologyRemove.png"))
51+
self.removeAPIpath.setToolTip(QCoreApplication.translate("PythonConsole", "Remove API path"))
52+
53+
self.connect( self.preloadAPI,
54+
SIGNAL("stateChanged(int)"), self.initialCheck)
55+
self.connect(self.browseButton,
56+
SIGNAL("clicked()"), self.loadAPIFile)
57+
self.connect(self.addAPIpath,
58+
SIGNAL("clicked()"), self.addAPI)
59+
self.connect(self.removeAPIpath,
60+
SIGNAL("clicked()"), self.removeAPI)
61+
62+
def initialCheck(self):
63+
if self.preloadAPI.isChecked():
64+
self.enableDisable(False)
65+
else:
66+
self.enableDisable(True)
67+
68+
def enableDisable(self, value):
69+
self.tableWidget.setEnabled(value)
70+
self.lineEdit.setEnabled(value)
71+
self.browseButton.setEnabled(value)
72+
self.addAPIpath.setEnabled(value)
73+
self.removeAPIpath.setEnabled(value)
74+
75+
def loadAPIFile(self):
76+
settings = QSettings()
77+
lastDirPath = settings.value("pythonConsole/lastDirAPIPath").toString()
78+
fileAPI = QFileDialog.getOpenFileName(
79+
self, "Open API File", lastDirPath, "API file (*.api)")
80+
self.lineEdit.setText(fileAPI)
81+
82+
lastDirPath = QFileInfo(fileAPI).path()
83+
settings.setValue("pythonConsole/lastDirAPIPath", QVariant(fileAPI))
84+
85+
def accept(self):
86+
if not self.preloadAPI.isChecked():
87+
if self.tableWidget.rowCount() == 0:
88+
QMessageBox.information(self, self.tr("Warning!"),
89+
self.tr('Please specify API file or check "Use preloaded API files"'))
90+
return
91+
self.saveSettings()
92+
self.listPath = []
93+
QDialog.accept( self )
94+
95+
def addAPI(self):
96+
if self.lineEdit.text() == "":
97+
return
98+
path = self.lineEdit.text()
99+
count = self.tableWidget.rowCount()
100+
self.tableWidget.setColumnCount(2)
101+
self.tableWidget.insertRow(count)
102+
pathItem = QTableWidgetItem(path)
103+
pathSplit = path.split("/")
104+
apiName = pathSplit[-1][0:-4]
105+
apiNameItem = QTableWidgetItem(apiName)
106+
self.tableWidget.setItem(count, 0, apiNameItem)
107+
self.tableWidget.setItem(count, 1, pathItem)
108+
self.tableWidget.setHorizontalHeaderLabels([self.tr("API"), self.tr("PATH")])
109+
self.tableWidget.horizontalHeader().setResizeMode(0, QHeaderView.ResizeToContents)
110+
self.tableWidget.horizontalHeader().show()
111+
self.tableWidget.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)
112+
#self.tableWidget.resizeRowsToContents()
113+
self.lineEdit.clear()
114+
115+
def removeAPI(self):
116+
listItemSel = self.tableWidget.selectedIndexes()
117+
#row = self.tableWidget.currentRow()
118+
for indx in listItemSel:
119+
self.tableWidget.removeRow(indx.row())
120+
121+
def fontConfig(self):
122+
#fontFamily = ['Courier','Monospace','Aurulent Sans','Bitstream Vera Serif']
123+
#for i in range(0, len(fontFamily)):
124+
#self.comboBox.addItem(fontFamily[i])
125+
settings = QSettings()
126+
self.fontComboBox.setCurrentIndex(settings.value("pythonConsole/fontfamilyindex").toInt()[0])
127+
128+
def saveSettings(self):
129+
settings = QSettings()
130+
settings.setValue("pythonConsole/preloadAPI", QVariant(self.preloadAPI.isChecked()))
131+
fontFamilyIndex = self.fontComboBox.currentIndex()
132+
settings.setValue("pythonConsole/fontfamilyindex", QVariant(fontFamilyIndex))
133+
fontFamilyText = self.fontComboBox.currentText()
134+
settings.setValue("pythonConsole/fontfamilytext", QVariant(fontFamilyText))
135+
fontSize = self.spinBox.value()
136+
for i in range(0, self.tableWidget.rowCount()):
137+
text = self.tableWidget.item(i, 1).text()
138+
self.listPath.append(text)
139+
settings.setValue("pythonConsole/fontsize", QVariant(fontSize))
140+
settings.setValue("pythonConsole/userAPI", QVariant(self.listPath))
141+
142+
def restoreSettings(self):
143+
settings = QSettings()
144+
self.spinBox.setValue(settings.value("pythonConsole/fontsize").toInt()[0])
145+
self.preloadAPI.setChecked(settings.value( "pythonConsole/preloadAPI" ).toBool())
146+
itemTable = settings.value("pythonConsole/userAPI").toStringList()
147+
for i in range(len(itemTable)):
148+
self.tableWidget.insertRow(i)
149+
self.tableWidget.setColumnCount(2)
150+
pathSplit = itemTable[i].split("/")
151+
apiName = pathSplit[-1][0:-4]
152+
self.tableWidget.setItem(i, 0, QTableWidgetItem(apiName))
153+
self.tableWidget.setItem(i, 1, QTableWidgetItem(itemTable[i]))
154+
self.tableWidget.setHorizontalHeaderLabels([self.tr("API"), self.tr("PATH")])
155+
self.tableWidget.horizontalHeader().setResizeMode(0, QHeaderView.ResizeToContents)
156+
self.tableWidget.horizontalHeader().show()
157+
self.tableWidget.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)
158+
#self.comboBox.setCurrentIndex(settings.value("pythonConsole/fontfamilyindex").toInt()[0])
159+
160+
def reject( self ):
161+
QDialog.reject( self )

‎python/console_settings.ui

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>SettingsDialog</class>
4+
<widget class="QDialog" name="SettingsDialog">
5+
<property name="windowModality">
6+
<enum>Qt::NonModal</enum>
7+
</property>
8+
<property name="geometry">
9+
<rect>
10+
<x>0</x>
11+
<y>0</y>
12+
<width>472</width>
13+
<height>388</height>
14+
</rect>
15+
</property>
16+
<property name="modal">
17+
<bool>true</bool>
18+
</property>
19+
<layout class="QGridLayout" name="gridLayout">
20+
<item row="1" column="0">
21+
<widget class="QDialogButtonBox" name="buttonBox">
22+
<property name="orientation">
23+
<enum>Qt::Horizontal</enum>
24+
</property>
25+
<property name="standardButtons">
26+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
27+
</property>
28+
</widget>
29+
</item>
30+
<item row="0" column="0">
31+
<widget class="QTabWidget" name="tabWidget">
32+
<property name="focusPolicy">
33+
<enum>Qt::NoFocus</enum>
34+
</property>
35+
<property name="currentIndex">
36+
<number>0</number>
37+
</property>
38+
<widget class="QWidget" name="tabGeneral">
39+
<attribute name="title">
40+
<string>Tab 1</string>
41+
</attribute>
42+
<layout class="QGridLayout" name="gridLayout_5">
43+
<item row="1" column="0">
44+
<widget class="QCheckBox" name="preloadAPI">
45+
<property name="text">
46+
<string>Use preloaded API file</string>
47+
</property>
48+
<property name="checked">
49+
<bool>true</bool>
50+
</property>
51+
</widget>
52+
</item>
53+
<item row="0" column="0">
54+
<layout class="QGridLayout" name="gridLayout_4">
55+
<item row="0" column="3">
56+
<widget class="QSpinBox" name="spinBox">
57+
<property name="minimumSize">
58+
<size>
59+
<width>51</width>
60+
<height>26</height>
61+
</size>
62+
</property>
63+
<property name="maximumSize">
64+
<size>
65+
<width>51</width>
66+
<height>26</height>
67+
</size>
68+
</property>
69+
<property name="minimum">
70+
<number>6</number>
71+
</property>
72+
<property name="maximum">
73+
<number>15</number>
74+
</property>
75+
<property name="value">
76+
<number>10</number>
77+
</property>
78+
</widget>
79+
</item>
80+
<item row="0" column="0">
81+
<widget class="QLabel" name="label">
82+
<property name="text">
83+
<string>Font</string>
84+
</property>
85+
</widget>
86+
</item>
87+
<item row="0" column="1">
88+
<widget class="QFontComboBox" name="fontComboBox">
89+
<property name="sizePolicy">
90+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
91+
<horstretch>0</horstretch>
92+
<verstretch>0</verstretch>
93+
</sizepolicy>
94+
</property>
95+
<property name="insertPolicy">
96+
<enum>QComboBox::NoInsert</enum>
97+
</property>
98+
</widget>
99+
</item>
100+
<item row="0" column="2">
101+
<widget class="QLabel" name="label_3">
102+
<property name="text">
103+
<string>Size</string>
104+
</property>
105+
</widget>
106+
</item>
107+
</layout>
108+
</item>
109+
<item row="3" column="0">
110+
<layout class="QGridLayout" name="gridLayout_3">
111+
<item row="0" column="1">
112+
<layout class="QGridLayout" name="gridLayout_2">
113+
<item row="0" column="0">
114+
<widget class="QPushButton" name="addAPIpath">
115+
<property name="sizePolicy">
116+
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
117+
<horstretch>0</horstretch>
118+
<verstretch>0</verstretch>
119+
</sizepolicy>
120+
</property>
121+
<property name="minimumSize">
122+
<size>
123+
<width>32</width>
124+
<height>32</height>
125+
</size>
126+
</property>
127+
<property name="maximumSize">
128+
<size>
129+
<width>32</width>
130+
<height>32</height>
131+
</size>
132+
</property>
133+
<property name="text">
134+
<string/>
135+
</property>
136+
</widget>
137+
</item>
138+
<item row="1" column="0">
139+
<widget class="QPushButton" name="removeAPIpath">
140+
<property name="minimumSize">
141+
<size>
142+
<width>32</width>
143+
<height>32</height>
144+
</size>
145+
</property>
146+
<property name="maximumSize">
147+
<size>
148+
<width>32</width>
149+
<height>32</height>
150+
</size>
151+
</property>
152+
<property name="text">
153+
<string/>
154+
</property>
155+
</widget>
156+
</item>
157+
</layout>
158+
</item>
159+
<item row="1" column="1">
160+
<spacer name="verticalSpacer_2">
161+
<property name="orientation">
162+
<enum>Qt::Vertical</enum>
163+
</property>
164+
<property name="sizeHint" stdset="0">
165+
<size>
166+
<width>20</width>
167+
<height>40</height>
168+
</size>
169+
</property>
170+
</spacer>
171+
</item>
172+
<item row="0" column="0" rowspan="2">
173+
<widget class="QTableWidget" name="tableWidget">
174+
<property name="editTriggers">
175+
<set>QAbstractItemView::NoEditTriggers</set>
176+
</property>
177+
<property name="tabKeyNavigation">
178+
<bool>false</bool>
179+
</property>
180+
<property name="showDropIndicator" stdset="0">
181+
<bool>false</bool>
182+
</property>
183+
<property name="dragDropOverwriteMode">
184+
<bool>false</bool>
185+
</property>
186+
<property name="selectionMode">
187+
<enum>QAbstractItemView::ExtendedSelection</enum>
188+
</property>
189+
<property name="selectionBehavior">
190+
<enum>QAbstractItemView::SelectItems</enum>
191+
</property>
192+
<property name="verticalScrollMode">
193+
<enum>QAbstractItemView::ScrollPerItem</enum>
194+
</property>
195+
<property name="horizontalScrollMode">
196+
<enum>QAbstractItemView::ScrollPerPixel</enum>
197+
</property>
198+
<property name="rowCount">
199+
<number>0</number>
200+
</property>
201+
<attribute name="horizontalHeaderVisible">
202+
<bool>true</bool>
203+
</attribute>
204+
<attribute name="verticalHeaderVisible">
205+
<bool>false</bool>
206+
</attribute>
207+
</widget>
208+
</item>
209+
</layout>
210+
</item>
211+
<item row="2" column="0">
212+
<layout class="QHBoxLayout" name="horizontalLayout_2">
213+
<item>
214+
<widget class="QLabel" name="label_2">
215+
<property name="text">
216+
<string>API file</string>
217+
</property>
218+
</widget>
219+
</item>
220+
<item>
221+
<widget class="QLineEdit" name="lineEdit"/>
222+
</item>
223+
<item>
224+
<widget class="QPushButton" name="browseButton">
225+
<property name="text">
226+
<string>Browse</string>
227+
</property>
228+
</widget>
229+
</item>
230+
</layout>
231+
</item>
232+
</layout>
233+
</widget>
234+
<widget class="QWidget" name="tabAbout">
235+
<attribute name="title">
236+
<string>Tab 2</string>
237+
</attribute>
238+
<layout class="QGridLayout" name="gridLayout_6">
239+
<item row="0" column="0">
240+
<widget class="QTextEdit" name="textEdit">
241+
<property name="readOnly">
242+
<bool>true</bool>
243+
</property>
244+
<property name="html">
245+
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
246+
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
247+
p, li { white-space: pre-wrap; }
248+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Aurulent Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
249+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:14pt; font-weight:600;&quot;&gt;Python Console for QGIS&lt;/span&gt;&lt;/p&gt;
250+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;Developed by Salvatore Larosa&lt;/span&gt;&lt;/p&gt;
251+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;---------------------------&lt;/span&gt;&lt;/p&gt;
252+
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt;&quot;&gt;This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
253+
</property>
254+
</widget>
255+
</item>
256+
</layout>
257+
</widget>
258+
</widget>
259+
</item>
260+
</layout>
261+
</widget>
262+
<resources/>
263+
<connections>
264+
<connection>
265+
<sender>buttonBox</sender>
266+
<signal>accepted()</signal>
267+
<receiver>SettingsDialog</receiver>
268+
<slot>accept()</slot>
269+
<hints>
270+
<hint type="sourcelabel">
271+
<x>248</x>
272+
<y>254</y>
273+
</hint>
274+
<hint type="destinationlabel">
275+
<x>157</x>
276+
<y>274</y>
277+
</hint>
278+
</hints>
279+
</connection>
280+
<connection>
281+
<sender>buttonBox</sender>
282+
<signal>rejected()</signal>
283+
<receiver>SettingsDialog</receiver>
284+
<slot>reject()</slot>
285+
<hints>
286+
<hint type="sourcelabel">
287+
<x>316</x>
288+
<y>260</y>
289+
</hint>
290+
<hint type="destinationlabel">
291+
<x>286</x>
292+
<y>274</y>
293+
</hint>
294+
</hints>
295+
</connection>
296+
</connections>
297+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.