25 #include <QMessageBox>    26 #include <QTextStream>    27 #include <Qsci/qscilexerpython.h>    31   , mAPISFilesList( filenames )
    40 void QgsCodeEditorPython::setSciLexerPython()
    42   QHash< QString, QColor > colors;
    46     for ( 
const auto &key : ini.allKeys() )
    55   setEdgeMode( QsciScintilla::EdgeLine );
    57   setEdgeColor( colors.value( QStringLiteral( 
"edgeColor" ), QColor( 255, 0, 0 ) ) );
    59   setWhitespaceVisibility( QsciScintilla::WsVisibleAfterIndent );
    62   QColor defaultColor = colors.value( QStringLiteral( 
"python/defaultFontColor" ), Qt::black );
    64   QsciLexerPython *pyLexer = 
new QsciLexerPython( 
this );
    65   pyLexer->setDefaultFont( font );
    66   pyLexer->setDefaultColor( defaultColor );
    67   pyLexer->setDefaultPaper( colors.value( QStringLiteral( 
"python/paperBackgroundColor" ), Qt::white ) );
    68   pyLexer->setFont( font, -1 );
    69   pyLexer->setColor( defaultColor, QsciLexerPython::Default );
    70   pyLexer->setColor( colors.value( QStringLiteral( 
"python/classFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerPython::ClassName );
    71   pyLexer->setColor( colors.value( QStringLiteral( 
"python/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerPython::Number );
    72   pyLexer->setColor( colors.value( QStringLiteral( 
"python/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerPython::Comment );
    73   pyLexer->setColor( colors.value( QStringLiteral( 
"python/commentBlockFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerPython::CommentBlock );
    74   pyLexer->setColor( colors.value( QStringLiteral( 
"python/keywordFontColor" ), QColor( 137, 89, 168 ) ), QsciLexerPython::Keyword );
    75   pyLexer->setColor( colors.value( QStringLiteral( 
"python/decoratorFontColor" ), QColor( 62, 153, 159 ) ), QsciLexerPython::Decorator );
    76   pyLexer->setColor( colors.value( QStringLiteral( 
"python/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerPython::SingleQuotedString );
    77   pyLexer->setColor( colors.value( QStringLiteral( 
"python/doubleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerPython::DoubleQuotedString );
    78   pyLexer->setColor( colors.value( QStringLiteral( 
"python/tripleSingleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerPython::TripleSingleQuotedString );
    79   pyLexer->setColor( colors.value( QStringLiteral( 
"python/tripleDoubleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerPython::TripleDoubleQuotedString );
    81   QsciAPIs *apis = 
new QsciAPIs( pyLexer );
    88   if ( mAPISFilesList.isEmpty() )
    91     apis->loadPrepared( mPapFile );
    93   else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == QLatin1String( 
"pap" ) )
    95     if ( !QFileInfo::exists( mAPISFilesList[0] ) )
    97       QgsDebugMsg( QStringLiteral( 
"The apis file %1 not found" ).arg( mAPISFilesList.at( 0 ) ) );
   100     mPapFile = mAPISFilesList[0];
   101     apis->loadPrepared( mPapFile );
   105     for ( 
int i = 0; i < mAPISFilesList.size(); i++ )
   107       if ( !QFileInfo::exists( mAPISFilesList[i] ) )
   109         QgsDebugMsg( QStringLiteral( 
"The apis file %1 was not found" ).arg( mAPISFilesList.at( i ) ) );
   114         apis->load( mAPISFilesList[i] );
   118     pyLexer->setAPIs( apis );
   124   setIndentationsUseTabs( 
false );
   130   mAPISFilesList = filenames;
   137   QgsDebugMsg( QStringLiteral( 
"The script file: %1" ).arg( script ) );
   138   QFile file( script );
   139   if ( !file.open( QIODevice::ReadOnly ) )
   144   QTextStream in( &file );
   146   setText( in.readAll().trimmed() );
 bool loadScript(const QString &script)
Load a script file. 
 
A text editor based on QScintilla2. 
 
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication. 
 
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. 
 
static QColor decodeColor(const QString &str)