Skip to content
Permalink
Browse files

Remove QgsPythonConsoleBase so that we have a single definitive Pytho…

…n editor class (QgsCodeEditorPython)
  • Loading branch information
nyalldawson committed Oct 5, 2020
1 parent ac6ee22 commit 8ec7f0e69c674635169ea12a743f668af964fb0e
@@ -3,7 +3,6 @@ SET (PYTHON_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/python)

SET(PY_CONSOLE_FILES
console.py
console_base.py
console_sci.py
console_settings.py
console_output.py

This file was deleted.

@@ -24,9 +24,8 @@
from qgis.PyQt.QtWidgets import QShortcut, QMenu, QApplication, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
from qgis.PyQt.Qsci import QsciScintilla, QsciAPIs, QsciStyle
from qgis.core import Qgis, QgsApplication, QgsSettings, QgsBlockingNetworkRequest
from qgis.gui import QgsMessageBar, QgsCodeEditor
from qgis.gui import QgsMessageBar, QgsCodeEditorPython
from qgis.utils import OverrideCursor
from .console_base import QgsPythonConsoleBase
import sys
import os
import subprocess
@@ -79,12 +78,12 @@ def eventFilter(self, obj, event):
return QObject.eventFilter(self, obj, event)


class Editor(QgsPythonConsoleBase):
class Editor(QgsCodeEditorPython):

MARKER_NUM = 6

def __init__(self, parent=None):
super(Editor, self).__init__(parent)
super().__init__(parent)
self.parent = parent
# recent modification time
self.lastModified = 0
@@ -143,7 +142,7 @@ def __init__(self, parent=None):

def settingsEditor(self):
# Set Python lexer
self.setLexers()
self.initializeLexer()
threshold = self.settings.value("pythonConsole/autoCompThreshold", 2, type=int)
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource", 'fromAPI')
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabled", True, type=bool)
@@ -24,8 +24,7 @@
from qgis.PyQt.QtWidgets import QGridLayout, QSpacerItem, QSizePolicy, QShortcut, QMenu, QApplication
from qgis.PyQt.Qsci import QsciScintilla
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.gui import QgsMessageBar, QgsCodeEditor
from .console_base import QgsPythonConsoleBase
from qgis.gui import QgsMessageBar, QgsCodeEditorPython
import sys


@@ -94,10 +93,10 @@ def isatty(self):
return False


class ShellOutputScintilla(QgsPythonConsoleBase):
class ShellOutputScintilla(QgsCodeEditorPython):

def __init__(self, parent=None):
super(ShellOutputScintilla, self).__init__(parent)
super().__init__(parent)
self.parent = parent
self.shell = self.parent.shell

@@ -119,6 +118,9 @@ def __init__(self, parent=None):

self.insertInitText()
self.refreshSettingsOutput()
self.setReadOnly(True)

self.setCaretWidth(0) # NO (blinking) caret in the output

self.setMinimumHeight(120)

@@ -152,7 +154,7 @@ def insertInitText(self):

def refreshSettingsOutput(self):
# Set Python lexer
self.setLexers()
self.initializeLexer()
self.setReadOnly(True)

self.setCaretWidth(0) # NO (blinking) caret in the output
@@ -21,10 +21,9 @@

from qgis.PyQt.QtCore import Qt, QByteArray, QCoreApplication, QFile, QSize
from qgis.PyQt.QtWidgets import QDialog, QMenu, QShortcut, QApplication
from qgis.PyQt.QtGui import QColor, QKeySequence, QFont, QFontMetrics, QStandardItemModel, QStandardItem, QClipboard, \
QFontDatabase
from qgis.PyQt.QtGui import QKeySequence, QFontMetrics, QStandardItemModel, QStandardItem, QClipboard
from qgis.PyQt.Qsci import QsciScintilla
from qgis.gui import QgsCodeEditor
from qgis.gui import QgsCodeEditorPython, QgsCodeEditor

import sys
import os
@@ -35,7 +34,6 @@

from qgis.core import QgsApplication, QgsSettings, Qgis
from .ui_console_history_dlg import Ui_HistoryDialogPythonConsole
from .console_base import QgsPythonConsoleBase

_init_commands = ["import sys", "import os", "import re", "import math", "from qgis.core import *",
"from qgis.gui import *", "from qgis.analysis import *", "from qgis._3d import *",
@@ -46,10 +44,10 @@
_historyFile = os.path.join(QgsApplication.qgisSettingsDirPath(), "console_history.txt")


class ShellScintilla(QgsPythonConsoleBase, code.InteractiveInterpreter):
class ShellScintilla(QgsCodeEditorPython, code.InteractiveInterpreter):

def __init__(self, parent=None):
super(ShellScintilla, self).__init__(parent)
super(QgsCodeEditorPython, self).__init__(parent)
code.InteractiveInterpreter.__init__(self, locals=None)

self.parent = parent
@@ -115,7 +113,7 @@ def _setMinimumHeight(self):

def refreshSettingsShell(self):
# Set Python lexer
self.setLexers()
self.initializeLexer()
threshold = self.settings.value("pythonConsole/autoCompThreshold", 2, type=int)
self.setAutoCompletionThreshold(threshold)
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource", 'fromAPI')
@@ -17,6 +17,8 @@
#include "qgscodeeditorpython.h"
#include "qgslogger.h"
#include "qgssymbollayerutils.h"
#include "qgssettings.h"
#include "qgis.h"

#include <QWidget>
#include <QString>
@@ -90,15 +92,36 @@ void QgsCodeEditorPython::initializeLexer()

QsciAPIs *apis = new QsciAPIs( pyLexer );

// check if the file is a prepared apis file.
//QString mPapFileName = QFileInfo( mAPISFilesList[0] ).fileName();
//QString isPapFile = mPapFileName.right( 3 );
//QgsDebugMsg( QStringLiteral( "file extension: %1" ).arg( isPapFile ) );
QgsSettings settings;

if ( mAPISFilesList.isEmpty() )
{
mPapFile = QgsApplication::pkgDataPath() + QStringLiteral( "/python/qsci_apis/pyqgis.pap" );
apis->loadPrepared( mPapFile );
if ( settings.value( QStringLiteral( "pythonConsole/preloadAPI" ), true ).toBool() )
{
mPapFile = QgsApplication::pkgDataPath() + QStringLiteral( "/python/qsci_apis/pyqgis.pap" );
apis->loadPrepared( mPapFile );
}
else if ( settings.value( QStringLiteral( "pythonConsole/usePreparedAPIFile" ), false ).toBool() )
{
apis->loadPrepared( settings.value( QStringLiteral( "pythonConsole/preparedAPIFile" ) ).toString() );
}
else
{
const QStringList apiPaths = settings.value( QStringLiteral( "pythonConsole/userAPI" ) ).toStringList();
for ( const QString &path : apiPaths )
{
if ( !QFileInfo::exists( path ) )
{
QgsDebugMsg( QStringLiteral( "The apis file %1 was not found" ).arg( path ) );
}
else
{
apis->load( path );
}
}
apis->prepare();
pyLexer->setAPIs( apis );
}
}
else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == QLatin1String( "pap" ) )
{
@@ -112,16 +135,15 @@ void QgsCodeEditorPython::initializeLexer()
}
else
{
for ( int i = 0; i < mAPISFilesList.size(); i++ )
for ( const QString &path : mAPISFilesList )
{
if ( !QFileInfo::exists( mAPISFilesList[i] ) )
if ( !QFileInfo::exists( path ) )
{
QgsDebugMsg( QStringLiteral( "The apis file %1 was not found" ).arg( mAPISFilesList.at( i ) ) );
return;
QgsDebugMsg( QStringLiteral( "The apis file %1 was not found" ).arg( path ) );
}
else
{
apis->load( mAPISFilesList[i] );
apis->load( path );
}
}
apis->prepare();

0 comments on commit 8ec7f0e

Please sign in to comment.
You can’t perform that action at this time.