Skip to content
Permalink
Browse files

Ensure True/False are treated as Python keywords in Python code editor

  • Loading branch information
nyalldawson committed Oct 6, 2020
1 parent ea6ad85 commit 5f661045c078b7938550c2c9d0798664c6f65f5a
@@ -172,7 +172,7 @@ QgsCodeEditorOptionsWidget::QgsCodeEditorOptionsWidget( QWidget *parent )
"""
Function docstring
"""
return [1, 1.2, "val", 'a string', {'a': 1, 'b': 2}]
return [1, 1.2, "val", 'a string', {'a': True, 'b': False}]
@my_decorator
def somefunc(param1: str='', param2=0):
@@ -55,7 +55,7 @@ void QgsCodeEditorPython::initializeLexer()
QFont font = lexerFont();
QColor defaultColor = lexerColor( QgsCodeEditorColorScheme::ColorRole::Default );

QsciLexerPython *pyLexer = new QsciLexerPython( this );
QsciLexerPython *pyLexer = new QgsQsciLexerPython( this );

pyLexer->setIndentationWarning( QsciLexerPython::Inconsistent );
pyLexer->setFoldComments( true );
@@ -236,3 +236,24 @@ void QgsCodeEditorPython::searchSelectedTextInPyQGISDocs()
const QString version = QString( Qgis::version() ).split( '.' ).mid( 0, 2 ).join( '.' );
QDesktopServices::openUrl( QUrl( QStringLiteral( "https://qgis.org/pyqgis/%1/search.html?q=%2" ).arg( version, text ) ) );
}

//
// QgsQsciLexerPython
//
QgsQsciLexerPython::QgsQsciLexerPython( QObject *parent )
: QsciLexerPython( parent )
{

}

const char *QgsQsciLexerPython::keywords( int set ) const
{
if ( set == 1 )
{
return "True False and as assert break class continue def del elif else except exec "
"finally for from global if import in is lambda None not or pass "
"print raise return try while with yield";
}

return QsciLexerPython::keywords( set );
}
@@ -19,9 +19,24 @@
#include "qgscodeeditor.h"
#include "qgis_sip.h"
#include "qgis_gui.h"
#include <Qsci/qscilexerpython.h>

SIP_IF_MODULE( HAVE_QSCI_SIP )

#ifndef SIP_RUN
///@cond PRIVATE
class QgsQsciLexerPython : public QsciLexerPython
{
Q_OBJECT
public:

QgsQsciLexerPython( QObject *parent = nullptr );

const char *keywords( int set ) const override;

};
///@endcond
#endif

/**
* \ingroup gui

0 comments on commit 5f66104

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