24 #include <QMessageBox> 25 #include <QTextStream> 26 #include <Qsci/qscilexerpython.h> 30 , mAPISFilesList( filenames )
39 void QgsCodeEditorPython::setSciLexerPython()
44 setEdgeMode( QsciScintilla::EdgeLine );
46 setEdgeColor( QColor( 255, 0, 0 ) );
48 setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent );
52 QsciLexerPython *pyLexer =
new QsciLexerPython(
this );
53 pyLexer->setDefaultFont( font );
54 pyLexer->setFont( font, -1 );
55 pyLexer->setColor( Qt::red, QsciLexerPython::Comment );
56 pyLexer->setColor( Qt::darkGreen, QsciLexerPython::Keyword );
57 pyLexer->setColor( Qt::darkBlue, QsciLexerPython::Decorator );
59 QsciAPIs *apis =
new QsciAPIs( pyLexer );
66 if ( mAPISFilesList.isEmpty() )
69 apis->loadPrepared( mPapFile );
71 else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == QLatin1String(
"pap" ) )
73 if ( !QFileInfo::exists( mAPISFilesList[0] ) )
75 QgsDebugMsg( QStringLiteral(
"The apis file %1 not found" ).arg( mAPISFilesList.at( 0 ) ) );
78 mPapFile = mAPISFilesList[0];
79 apis->loadPrepared( mPapFile );
83 for (
int i = 0; i < mAPISFilesList.size(); i++ )
85 if ( !QFileInfo::exists( mAPISFilesList[i] ) )
87 QgsDebugMsg( QString(
"The apis file %1 was not found" ).arg( mAPISFilesList.at( i ) ) );
92 apis->load( mAPISFilesList[i] );
96 pyLexer->setAPIs( apis );
107 mAPISFilesList = filenames;
114 QgsDebugMsg( QString(
"The script file: %1" ).arg( script ) );
115 QFile file( script );
116 if ( !file.open( QIODevice::ReadOnly ) )
121 QTextStream in( &file );
123 setText( in.readAll().trimmed() );
bool loadScript(const QString &script)
Load a script file.
A text editor based on QScintilla2.
void setFoldingVisible(bool folding)
Set folding visible state.
QgsCodeEditorPython(QWidget *parent=nullptr, const QList< QString > &filenames=QList< QString >())
Construct a new Python editor.
static QString pkgDataPath()
Returns the common root path of all application data directories.
void setMarginVisible(bool margin)
Set margin visible state.
void setTitle(const QString &title)
Set the widget title.
void loadAPIs(const QList< QString > &filenames)
Load APIs from one or more files.