Skip to content
Permalink
Browse files

Move code editor color scheme tracking to dedicated registry,

QgsCodeEditorColorSchemeRegistry

This cleans up the code, and makes it possible for creation of plugins
which add new code editor color schemes!
  • Loading branch information
nyalldawson committed Oct 6, 2020
1 parent 1bafa2f commit 3098fa59062af6702d995ef5f3cd0967c0b275a2
@@ -23,7 +23,7 @@
from qgis.PyQt.QtWidgets import QDialog, QMenu, QShortcut, QApplication
from qgis.PyQt.QtGui import QKeySequence, QFontMetrics, QStandardItemModel, QStandardItem, QClipboard
from qgis.PyQt.Qsci import QsciScintilla
from qgis.gui import QgsCodeEditorPython, QgsCodeEditor
from qgis.gui import QgsCodeEditorPython, QgsCodeEditorColorScheme

import sys
import os
@@ -127,7 +127,7 @@ def refreshSettingsShell(self):
self.setMarginLineNumbers(1, True)
self.setMarginWidth(1, "00000")
self.setMarginType(1, 5) # TextMarginRightJustified=5
self.setMarginsBackgroundColor(self.color(QgsCodeEditor.ColorRole.Background))
self.setMarginsBackgroundColor(self.color(QgsCodeEditorColorScheme.ColorRole.Background))
self.setFoldingVisible(False)
self.setEdgeMode(QsciScintilla.EdgeNone)

@@ -73,58 +73,20 @@ made a selection.
:param text: The text to be inserted
%End

enum class ColorRole
{
Default,
Keyword,
Class,
Method,
Decoration,
Number,
Comment,
CommentLine,
CommentBlock,
Background,
Cursor,
CaretLine,
SingleQuote,
DoubleQuote,
TripleSingleQuote,
TripleDoubleQuote,
Operator,
QuotedOperator,
Identifier,
QuotedIdentifier,
Tag,
UnknownTag,
MarginBackground,
MarginForeground,
SelectionBackground,
SelectionForeground,
MatchedBraceBackground,
MatchedBraceForeground,
Edge,
Fold,
Error,
};

static QColor defaultColor( ColorRole role, const QString &theme = QString() );
static QColor defaultColor( QgsCodeEditorColorScheme::ColorRole role, const QString &theme = QString() );
%Docstring
Returns the default color for the specified ``role``.

The optional ``theme`` argument can be used to specify a color ``theme``. A blank
``theme`` indicates the default color scheme.

Possible ``theme`` values are:

- (empty string) follow application default colors
- solarized
- solarized_dark
Available themes are stored in QgsCodeEditorColorSchemeRegistry, and can be retrieved
via :py:func:`QgsGui.codeEditorColorSchemeRegistry()`.

.. versionadded:: 3.16
%End

static QColor color( ColorRole role );
static QColor color( QgsCodeEditorColorScheme::ColorRole role );
%Docstring
Returns the color to use in the editor for the specified ``role``.

@@ -136,7 +98,7 @@ selected a custom color scheme for the editor.
.. versionadded:: 3.16
%End

static void setColor( ColorRole role, const QColor &color );
static void setColor( QgsCodeEditorColorScheme::ColorRole role, const QColor &color );
%Docstring
Sets the ``color`` to use in the editor for the specified ``role``.

@@ -176,7 +138,7 @@ The default implementation does nothing.
.. versionadded:: 3.16
%End

QColor lexerColor( ColorRole role ) const;
QColor lexerColor( QgsCodeEditorColorScheme::ColorRole role ) const;
%Docstring
Returns the color to use in the lexer for the specified ``role``.

@@ -0,0 +1,102 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/codeeditors/qgscodeeditorcolorscheme.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsCodeEditorColorScheme
{
%Docstring
Defines a color scheme for use in QgsCodeEditor widgets.

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgscodeeditorcolorscheme.h"
%End
public:

enum class ColorRole
{
Default,
Keyword,
Class,
Method,
Decoration,
Number,
Comment,
CommentLine,
CommentBlock,
Background,
Cursor,
CaretLine,
SingleQuote,
DoubleQuote,
TripleSingleQuote,
TripleDoubleQuote,
Operator,
QuotedOperator,
Identifier,
QuotedIdentifier,
Tag,
UnknownTag,
MarginBackground,
MarginForeground,
SelectionBackground,
SelectionForeground,
MatchedBraceBackground,
MatchedBraceForeground,
Edge,
Fold,
Error,
};

QgsCodeEditorColorScheme( const QString &id = QString(), const QString &name = QString() );
%Docstring
Constructor for QgsCodeEditorColorScheme.

The ``id`` argument must be set to a unique, non-translated identifier for the color scheme.

The ``name`` argument must be set to a translated, user-visible descriptive name of the scheme.
%End


QString id() const;
%Docstring
Returns the ID of the color scheme, which is a unique, non-translated identifier for the scheme.
%End

QString name() const;
%Docstring
Returns the name of the color scheme, which is the translated, user-visible name of the scheme.
%End

QColor color( ColorRole role ) const;
%Docstring
Returns the color to use in the editor for the specified ``role``.

.. seealso:: :py:func:`setColor`
%End

void setColor( ColorRole role, const QColor &color );
%Docstring
Sets the ``color`` to use in the editor for the specified ``role``.

.. seealso:: :py:func:`color`
%End


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/codeeditors/qgscodeeditorcolorscheme.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,67 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/codeeditors/qgscodeeditorcolorschemeregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsCodeEditorColorSchemeRegistry
{
%Docstring
A registry of color schemes for use in QgsCodeEditor widgets.

QgsCodeEditorColorSchemeRegistry is not usually directly created, but rather accessed through
:py:func:`QgsGui.codeEditorColorSchemeRegistry()`.

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgscodeeditorcolorschemeregistry.h"
%End
public:

QgsCodeEditorColorSchemeRegistry();
%Docstring
Constructor for a color scheme registry.
%End

bool addColorScheme( const QgsCodeEditorColorScheme &scheme );
%Docstring
Adds a color ``scheme`` to the registry.

Returns ``True`` if the scheme was successfully added.
%End

bool removeColorScheme( const QString &id );
%Docstring
Removes the color scheme with matching ``id`` from the registry.

Returns ``True`` if scheme was found and removed.
%End

QStringList schemes() const;
%Docstring
Returns a list of the :py:func:`QgsCodeEditorColorScheme.id()` values for all registered color schemes.
%End

QgsCodeEditorColorScheme scheme( const QString &id ) const;
%Docstring
Returns the color scheme with matching ``id``.

If the specified scheme \id does not exist then the default scheme will be returned instead.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/codeeditors/qgscodeeditorcolorschemeregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -80,6 +80,13 @@ Returns the global processing gui registry, used for registering the GUI behavio
Returns the global numeric format gui registry, used for registering the GUI widgets associated with :py:class:`QgsNumericFormats`.

.. versionadded:: 3.12
%End

static QgsCodeEditorColorSchemeRegistry *codeEditorColorSchemeRegistry() /KeepReference/;
%Docstring
Returns the global code editor color scheme registry, used for registering the color schemes for QgsCodeEditor widgets.

.. versionadded:: 3.16
%End

static QgsProcessingRecentAlgorithmLog *processingRecentAlgorithmLog();
@@ -241,6 +241,8 @@
%If ( HAVE_QSCI_SIP )
%Include auto_generated/codeeditors/qgscodeeditor.sip
%End
%Include auto_generated/codeeditors/qgscodeeditorcolorscheme.sip
%Include auto_generated/codeeditors/qgscodeeditorcolorschemeregistry.sip
%If ( HAVE_QSCI_SIP )
%Include auto_generated/codeeditors/qgscodeeditorcss.sip
%End

0 comments on commit 3098fa5

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