Refactor the theme setting meta fields and requirements
This commit is contained in:
@@ -55,8 +55,6 @@ A colour theme ``.conf`` file consists of the following settings:
|
||||
author = Veronica Berglyd Olsen
|
||||
credit = Veronica Berglyd Olsen
|
||||
url = https://github.com/vkbo/novelWriter
|
||||
license = CC BY-SA 4.0
|
||||
licenseurl = https://creativecommons.org/licenses/by-sa/4.0/
|
||||
|
||||
[Base]
|
||||
base = #fcfcfc
|
||||
@@ -140,7 +138,7 @@ affects.
|
||||
:header: "Section", "Description"
|
||||
:class: "tight-table"
|
||||
|
||||
"``[Main]``", "Meta data about the theme, You must at least set ``name`` and ``mode``, and ``mode`` must be either ``light`` or ``dark``."
|
||||
"``[Main]``", "Meta data about the theme, You must at least set ``name``, ``mode`` and ``author``, and ``mode`` must be either ``light`` or ``dark``."
|
||||
"``[Base]``", "The base colours of the theme. These are also selectable colours in various places inside the app, like for icon colours in **Preferences**."
|
||||
"``[Project]``", "The colours used for icons and markers for the different project item types."
|
||||
"``[Palette]``", "The colours used for styling the user interface. The values correspond to the ColorRole_ values in the Qt library."
|
||||
@@ -177,6 +175,8 @@ There are several ways to enter colour values:
|
||||
.. versionadded:: 2.8
|
||||
The ``[Syntax]`` section was moved into the main theme file. Previously, these settings were in
|
||||
their own file. The ``[Icons]`` section was renamed to ``[Base]``. Added the ``line`` setting.
|
||||
Dropped the ``license`` and ``licenseurl`` settings. The ``description`` and ``author`` fields
|
||||
are now required if the theme is included in the app, but not for user themes.
|
||||
|
||||
|
||||
Icon Themes
|
||||
|
||||
+15
-12
@@ -72,8 +72,13 @@ class ThemeMeta:
|
||||
author: str = ""
|
||||
credit: str = ""
|
||||
url: str = ""
|
||||
license: str = ""
|
||||
licenseUrl: str = ""
|
||||
|
||||
|
||||
class IconsMeta:
|
||||
|
||||
name: str = ""
|
||||
author: str = ""
|
||||
license: str = ""
|
||||
|
||||
|
||||
class SyntaxColors:
|
||||
@@ -296,12 +301,10 @@ class GuiTheme:
|
||||
if parser.has_section(sec):
|
||||
meta.name = parser.get(sec, "name", fallback="")
|
||||
meta.mode = parser.get(sec, "mode", fallback="light")
|
||||
meta.description = parser.get(sec, "description", fallback="N/A")
|
||||
meta.author = parser.get(sec, "author", fallback="N/A")
|
||||
meta.credit = parser.get(sec, "credit", fallback="N/A")
|
||||
meta.description = parser.get(sec, "description", fallback="")
|
||||
meta.author = parser.get(sec, "author", fallback="")
|
||||
meta.credit = parser.get(sec, "credit", fallback="")
|
||||
meta.url = parser.get(sec, "url", fallback="")
|
||||
meta.license = parser.get(sec, "license", fallback="N/A")
|
||||
meta.licenseUrl = parser.get(sec, "licenseurl", fallback="")
|
||||
|
||||
self._meta = meta
|
||||
|
||||
@@ -613,13 +616,13 @@ class GuiTheme:
|
||||
parser.clear()
|
||||
parser.read(file, encoding="utf-8")
|
||||
name = parser.get("Main", "name", fallback="")
|
||||
dark = parser.get("Main", "mode", fallback="light").lower() == "dark"
|
||||
if name:
|
||||
mode = parser.get("Main", "mode", fallback="").lower()
|
||||
if name and mode in ("light", "dark"):
|
||||
key = file.stem
|
||||
prefix = "*" if key.startswith("default") else ""
|
||||
lookup = f"{prefix}{name} {key}"
|
||||
keys.append(lookup)
|
||||
data[lookup] = (file.stem, name, dark, file)
|
||||
data[lookup] = (file.stem, name, mode == "dark", file)
|
||||
except Exception: # noqa: PERF203
|
||||
logger.error("Could not read file: %s", file)
|
||||
logException()
|
||||
@@ -659,7 +662,7 @@ class GuiIcons:
|
||||
def __init__(self, mainTheme: GuiTheme) -> None:
|
||||
|
||||
self._theme = mainTheme
|
||||
self._meta = ThemeMeta()
|
||||
self._meta = IconsMeta()
|
||||
|
||||
# Storage
|
||||
self._allThemes: dict[str, ThemeEntry] = {}
|
||||
@@ -722,7 +725,7 @@ class GuiIcons:
|
||||
CONFIG.splashMessage(f"Loading icon theme: {entry.name}")
|
||||
logger.info("Loading icon theme '%s'", theme)
|
||||
try:
|
||||
meta = ThemeMeta()
|
||||
meta = IconsMeta()
|
||||
with open(entry.path, mode="r", encoding="utf-8") as icons:
|
||||
for icon in icons:
|
||||
bits = icon.partition("=")
|
||||
|
||||
@@ -613,7 +613,7 @@ def testGuiTheme_CheckTheme(theme):
|
||||
|
||||
structure = {
|
||||
"Main": [
|
||||
"name", "mode", # The rest are not required
|
||||
"name", "mode", "description", "author", # The rest are not required
|
||||
],
|
||||
"Base": [
|
||||
"base", "default", "faded", "red", "orange", "yellow", "green",
|
||||
@@ -638,7 +638,7 @@ def testGuiTheme_CheckTheme(theme):
|
||||
"errorline", "replacetag", "modifier", "texthighlight",
|
||||
],
|
||||
}
|
||||
optional = ["description", "author", "credit", "url", "license", "licenseurl"]
|
||||
optional = ["credit", "url"]
|
||||
missing = []
|
||||
for section, options in structure.items():
|
||||
missing.extend(opt for opt in options if opt not in parser[section])
|
||||
|
||||
Reference in New Issue
Block a user