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
|
author = Veronica Berglyd Olsen
|
||||||
credit = Veronica Berglyd Olsen
|
credit = Veronica Berglyd Olsen
|
||||||
url = https://github.com/vkbo/novelWriter
|
url = https://github.com/vkbo/novelWriter
|
||||||
license = CC BY-SA 4.0
|
|
||||||
licenseurl = https://creativecommons.org/licenses/by-sa/4.0/
|
|
||||||
|
|
||||||
[Base]
|
[Base]
|
||||||
base = #fcfcfc
|
base = #fcfcfc
|
||||||
@@ -140,7 +138,7 @@ affects.
|
|||||||
:header: "Section", "Description"
|
:header: "Section", "Description"
|
||||||
:class: "tight-table"
|
: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**."
|
"``[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."
|
"``[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."
|
"``[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
|
.. versionadded:: 2.8
|
||||||
The ``[Syntax]`` section was moved into the main theme file. Previously, these settings were in
|
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.
|
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
|
Icon Themes
|
||||||
|
|||||||
+15
-12
@@ -72,8 +72,13 @@ class ThemeMeta:
|
|||||||
author: str = ""
|
author: str = ""
|
||||||
credit: str = ""
|
credit: str = ""
|
||||||
url: str = ""
|
url: str = ""
|
||||||
license: str = ""
|
|
||||||
licenseUrl: str = ""
|
|
||||||
|
class IconsMeta:
|
||||||
|
|
||||||
|
name: str = ""
|
||||||
|
author: str = ""
|
||||||
|
license: str = ""
|
||||||
|
|
||||||
|
|
||||||
class SyntaxColors:
|
class SyntaxColors:
|
||||||
@@ -296,12 +301,10 @@ class GuiTheme:
|
|||||||
if parser.has_section(sec):
|
if parser.has_section(sec):
|
||||||
meta.name = parser.get(sec, "name", fallback="")
|
meta.name = parser.get(sec, "name", fallback="")
|
||||||
meta.mode = parser.get(sec, "mode", fallback="light")
|
meta.mode = parser.get(sec, "mode", fallback="light")
|
||||||
meta.description = parser.get(sec, "description", fallback="N/A")
|
meta.description = parser.get(sec, "description", fallback="")
|
||||||
meta.author = parser.get(sec, "author", fallback="N/A")
|
meta.author = parser.get(sec, "author", fallback="")
|
||||||
meta.credit = parser.get(sec, "credit", fallback="N/A")
|
meta.credit = parser.get(sec, "credit", fallback="")
|
||||||
meta.url = parser.get(sec, "url", 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
|
self._meta = meta
|
||||||
|
|
||||||
@@ -613,13 +616,13 @@ class GuiTheme:
|
|||||||
parser.clear()
|
parser.clear()
|
||||||
parser.read(file, encoding="utf-8")
|
parser.read(file, encoding="utf-8")
|
||||||
name = parser.get("Main", "name", fallback="")
|
name = parser.get("Main", "name", fallback="")
|
||||||
dark = parser.get("Main", "mode", fallback="light").lower() == "dark"
|
mode = parser.get("Main", "mode", fallback="").lower()
|
||||||
if name:
|
if name and mode in ("light", "dark"):
|
||||||
key = file.stem
|
key = file.stem
|
||||||
prefix = "*" if key.startswith("default") else ""
|
prefix = "*" if key.startswith("default") else ""
|
||||||
lookup = f"{prefix}{name} {key}"
|
lookup = f"{prefix}{name} {key}"
|
||||||
keys.append(lookup)
|
keys.append(lookup)
|
||||||
data[lookup] = (file.stem, name, dark, file)
|
data[lookup] = (file.stem, name, mode == "dark", file)
|
||||||
except Exception: # noqa: PERF203
|
except Exception: # noqa: PERF203
|
||||||
logger.error("Could not read file: %s", file)
|
logger.error("Could not read file: %s", file)
|
||||||
logException()
|
logException()
|
||||||
@@ -659,7 +662,7 @@ class GuiIcons:
|
|||||||
def __init__(self, mainTheme: GuiTheme) -> None:
|
def __init__(self, mainTheme: GuiTheme) -> None:
|
||||||
|
|
||||||
self._theme = mainTheme
|
self._theme = mainTheme
|
||||||
self._meta = ThemeMeta()
|
self._meta = IconsMeta()
|
||||||
|
|
||||||
# Storage
|
# Storage
|
||||||
self._allThemes: dict[str, ThemeEntry] = {}
|
self._allThemes: dict[str, ThemeEntry] = {}
|
||||||
@@ -722,7 +725,7 @@ class GuiIcons:
|
|||||||
CONFIG.splashMessage(f"Loading icon theme: {entry.name}")
|
CONFIG.splashMessage(f"Loading icon theme: {entry.name}")
|
||||||
logger.info("Loading icon theme '%s'", theme)
|
logger.info("Loading icon theme '%s'", theme)
|
||||||
try:
|
try:
|
||||||
meta = ThemeMeta()
|
meta = IconsMeta()
|
||||||
with open(entry.path, mode="r", encoding="utf-8") as icons:
|
with open(entry.path, mode="r", encoding="utf-8") as icons:
|
||||||
for icon in icons:
|
for icon in icons:
|
||||||
bits = icon.partition("=")
|
bits = icon.partition("=")
|
||||||
|
|||||||
@@ -613,7 +613,7 @@ def testGuiTheme_CheckTheme(theme):
|
|||||||
|
|
||||||
structure = {
|
structure = {
|
||||||
"Main": [
|
"Main": [
|
||||||
"name", "mode", # The rest are not required
|
"name", "mode", "description", "author", # The rest are not required
|
||||||
],
|
],
|
||||||
"Base": [
|
"Base": [
|
||||||
"base", "default", "faded", "red", "orange", "yellow", "green",
|
"base", "default", "faded", "red", "orange", "yellow", "green",
|
||||||
@@ -638,7 +638,7 @@ def testGuiTheme_CheckTheme(theme):
|
|||||||
"errorline", "replacetag", "modifier", "texthighlight",
|
"errorline", "replacetag", "modifier", "texthighlight",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
optional = ["description", "author", "credit", "url", "license", "licenseurl"]
|
optional = ["credit", "url"]
|
||||||
missing = []
|
missing = []
|
||||||
for section, options in structure.items():
|
for section, options in structure.items():
|
||||||
missing.extend(opt for opt in options if opt not in parser[section])
|
missing.extend(opt for opt in options if opt not in parser[section])
|
||||||
|
|||||||
Reference in New Issue
Block a user