Drop the custom data class decorator for now, since it is not performance relevant
This commit is contained in:
@@ -29,8 +29,6 @@ from enum import Flag, IntEnum
|
|||||||
|
|
||||||
from PyQt6.QtGui import QColor
|
from PyQt6.QtGui import QColor
|
||||||
|
|
||||||
from novelwriter.types import nwDataClass
|
|
||||||
|
|
||||||
ESCAPES = {r"\*": "*", r"\~": "~", r"\_": "_", r"\[": "[", r"\]": "]", r"\ ": ""}
|
ESCAPES = {r"\*": "*", r"\~": "~", r"\_": "_", r"\[": "[", r"\]": "]", r"\ ": ""}
|
||||||
RX_ESC = re.compile("|".join([re.escape(k) for k in ESCAPES.keys()]), flags=re.DOTALL)
|
RX_ESC = re.compile("|".join([re.escape(k) for k in ESCAPES.keys()]), flags=re.DOTALL)
|
||||||
|
|
||||||
@@ -42,7 +40,6 @@ def stripEscape(text: str) -> str:
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
@nwDataClass
|
|
||||||
class TextDocumentTheme:
|
class TextDocumentTheme:
|
||||||
"""Default document theme."""
|
"""Default document theme."""
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ from novelwriter.common import NWConfigParser, cssCol, minmax
|
|||||||
from novelwriter.constants import nwLabels
|
from novelwriter.constants import nwLabels
|
||||||
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
|
||||||
from novelwriter.error import logException
|
from novelwriter.error import logException
|
||||||
from novelwriter.types import QtPaintAntiAlias, QtTransparent, nwDataClass
|
from novelwriter.types import QtPaintAntiAlias, QtTransparent
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -50,7 +50,6 @@ STYLES_MIN_TOOLBUTTON = "minimalToolButton"
|
|||||||
STYLES_BIG_TOOLBUTTON = "bigToolButton"
|
STYLES_BIG_TOOLBUTTON = "bigToolButton"
|
||||||
|
|
||||||
|
|
||||||
@nwDataClass
|
|
||||||
class ThemeMeta:
|
class ThemeMeta:
|
||||||
|
|
||||||
name: str = ""
|
name: str = ""
|
||||||
@@ -62,7 +61,6 @@ class ThemeMeta:
|
|||||||
licenseUrl: str = ""
|
licenseUrl: str = ""
|
||||||
|
|
||||||
|
|
||||||
@nwDataClass
|
|
||||||
class SyntaxColors:
|
class SyntaxColors:
|
||||||
|
|
||||||
back: QColor = QColor(255, 255, 255)
|
back: QColor = QColor(255, 255, 255)
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, TypeVar
|
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt
|
from PyQt6.QtCore import Qt
|
||||||
from PyQt6.QtGui import QColor, QFont, QPainter, QTextCharFormat, QTextCursor, QTextFormat
|
from PyQt6.QtGui import QColor, QFont, QPainter, QTextCharFormat, QTextCursor, QTextFormat
|
||||||
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QSizePolicy, QStyle
|
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QSizePolicy, QStyle
|
||||||
@@ -148,30 +146,3 @@ FONT_STYLE: dict[QFont.Style, str] = {
|
|||||||
QFont.Style.StyleItalic: "italic",
|
QFont.Style.StyleItalic: "italic",
|
||||||
QFont.Style.StyleOblique: "oblique",
|
QFont.Style.StyleOblique: "oblique",
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
|
||||||
# Decorators and MetaClasses
|
|
||||||
##
|
|
||||||
|
|
||||||
T_ = TypeVar("T_", bound=object)
|
|
||||||
|
|
||||||
|
|
||||||
def nwDataClass(cls: T_) -> T_:
|
|
||||||
"""A simple data class decorator that generates slots automatically
|
|
||||||
and creates an init function to match.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def wrap(cls: T_) -> T_:
|
|
||||||
fields = tuple(a for a in dir(cls) if not a.startswith("__"))
|
|
||||||
values = {a: getattr(cls, a) for a in fields}
|
|
||||||
|
|
||||||
def init(self: Any) -> None:
|
|
||||||
nonlocal values
|
|
||||||
for a, v in values.items():
|
|
||||||
self.__setattr__(a, v)
|
|
||||||
|
|
||||||
return type(cls.__class__.__name__, (object,), { # type: ignore
|
|
||||||
"__slots__": fields, "__init__": init
|
|
||||||
})
|
|
||||||
|
|
||||||
return wrap(cls)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user