Add probably final version
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
b5ffd0d716
commit
1f5cf0260c
@ -1,15 +1,23 @@
|
||||
"""
|
||||
LICENSE:
|
||||
SPDX-FileCopyrightText: 2020 Juraj Oravec <jurajoravec@mailo.com>
|
||||
SPDX-License-Identifier: MIT
|
||||
"""
|
||||
|
||||
from configparser import ConfigParser
|
||||
from pprint import pprint
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
settings = {
|
||||
"prefferStandAloneData": True,
|
||||
"IncludeCustoms": True
|
||||
}
|
||||
|
||||
|
||||
jsonConfig = {
|
||||
"_comments": "Created by theme_converter script",
|
||||
"metadata": {
|
||||
"name": "MyCuteTheme",
|
||||
"revision": 1
|
||||
}
|
||||
"_comments": "Created by theme_converter script"
|
||||
}
|
||||
|
||||
editorColors = {
|
||||
"Color Background": "BackgroundColor",
|
||||
"Color Code Folding": "CodeFolding",
|
||||
@ -40,7 +48,6 @@ editorColors = {
|
||||
"Color Template Not Editable Placeholder": "TemplateReadOnlyPlaceholder",
|
||||
"Color Word Wrap Marker": "WordWrapMarker"
|
||||
}
|
||||
|
||||
textStyles = {
|
||||
"Alert": "Alert",
|
||||
"Annotation": "Annotation",
|
||||
@ -74,8 +81,41 @@ textStyles = {
|
||||
"Verbatim String": "VerbatimString",
|
||||
"Warning": "Warning"
|
||||
}
|
||||
|
||||
indexToStyle = {
|
||||
"0": "Normal",
|
||||
"1": "Keyword",
|
||||
"2": "Function",
|
||||
"3": "Variable",
|
||||
"4": "ControlFlow",
|
||||
"5": "Operator",
|
||||
"6": "BuiltIn",
|
||||
"7": "Extension",
|
||||
"8": "Preprocessor",
|
||||
"9": "Attribute",
|
||||
"10": "Char",
|
||||
"11": "SpecialChar",
|
||||
"12": "String",
|
||||
"13": "VerbatimString",
|
||||
"14": "SpecialString",
|
||||
"15": "Import",
|
||||
"16": "DataType",
|
||||
"17": "DecVal",
|
||||
"18": "BaseN",
|
||||
"19": "Float",
|
||||
"20": "Constant",
|
||||
"21": "Comment",
|
||||
"22": "Documentation",
|
||||
"23": "Annotation",
|
||||
"24": "CommentVar",
|
||||
"25": "RegionMarker",
|
||||
"26": "Information",
|
||||
"27": "Warning",
|
||||
"28": "Alert",
|
||||
"29": "Others",
|
||||
"30": "Error"
|
||||
}
|
||||
normalizedSections = {}
|
||||
custom_styles = {}
|
||||
|
||||
|
||||
def normalizeSections(sections: list):
|
||||
@ -106,6 +146,10 @@ def decodeTextStyle(text: str) -> dict:
|
||||
|
||||
field = text.split(",")
|
||||
|
||||
if len(field) == 11:
|
||||
styleIndex = field.pop(0)
|
||||
style = jsonConfig["text-styles"][indexToStyle[styleIndex]].copy()
|
||||
|
||||
if len(field) != 10:
|
||||
return dict()
|
||||
|
||||
@ -113,13 +157,13 @@ def decodeTextStyle(text: str) -> dict:
|
||||
style["text-color"] = reEcodeColors(field[0])
|
||||
if field[1] and len(field[1]) == 8:
|
||||
style["selected-text-color"] = reEcodeColors(field[1])
|
||||
if field[2]:
|
||||
if field[2] and len(field[2]) == 1:
|
||||
style["bold"] = reEncodeBool(field[2])
|
||||
if field[3]:
|
||||
if field[3] and len(field[3]) == 1:
|
||||
style["italic"] = reEncodeBool(field[3])
|
||||
if field[4]:
|
||||
if field[4] and len(field[4]) == 1:
|
||||
style["strike-through"] = reEncodeBool(field[4])
|
||||
if field[5]:
|
||||
if field[5] and len(field[5]) == 1:
|
||||
style["underline"] = reEncodeBool(field[5])
|
||||
if field[6] and len(field[6]) == 8:
|
||||
style["background-color"] = reEcodeColors(field[6])
|
||||
@ -162,8 +206,28 @@ def extractTextStyles(section: dict) -> dict:
|
||||
return text_styles
|
||||
|
||||
|
||||
def extractCustomStyles() -> dict:
|
||||
custom_styles = {}
|
||||
def extractCustomStyle(style: dict, realKey: str):
|
||||
global custom_styles
|
||||
|
||||
key: str
|
||||
value: str
|
||||
for key, value in style.items():
|
||||
style = decodeTextStyle(value)
|
||||
|
||||
primaryKey, SeondaryKey = key.split(":")[-2:]
|
||||
|
||||
if primaryKey not in custom_styles:
|
||||
custom_styles[primaryKey] = dict()
|
||||
|
||||
if style and SeondaryKey not in custom_styles[primaryKey]:
|
||||
custom_styles[primaryKey][SeondaryKey] = style
|
||||
|
||||
if settings["prefferStandAloneData"] and style and realKey == primaryKey:
|
||||
custom_styles[primaryKey][SeondaryKey] = style
|
||||
|
||||
|
||||
def extractCustomStyles(config: ConfigParser) -> dict:
|
||||
global custom_styles
|
||||
|
||||
key: str
|
||||
value: str
|
||||
@ -173,24 +237,37 @@ def extractCustomStyles() -> dict:
|
||||
|
||||
realKey = key[len("Highlighting "):]
|
||||
|
||||
|
||||
extractCustomStyle(config[value], realKey)
|
||||
|
||||
return custom_styles
|
||||
|
||||
|
||||
config = ConfigParser(delimiters="=")
|
||||
config.optionxform = str
|
||||
config.read('DarkOxygen.kateschema')
|
||||
def main(inputFile: str):
|
||||
config = ConfigParser(delimiters="=")
|
||||
config.optionxform = str
|
||||
config.read(inputFile)
|
||||
|
||||
normalizeSections(config.sections())
|
||||
normalizeSections(config.sections())
|
||||
|
||||
if "Editor Colors" in normalizedSections:
|
||||
jsonConfig["editor-colors"] = extractEditorColors(config[normalizedSections["Editor Colors"]])
|
||||
if "Default Item Styles" in normalizedSections:
|
||||
jsonConfig["text-styles"] = extractTextStyles(config[normalizedSections["Default Item Styles"]])
|
||||
if "Editor Colors" in normalizedSections:
|
||||
jsonConfig["editor-colors"] = extractEditorColors(config[normalizedSections["Editor Colors"]])
|
||||
if "Default Item Styles" in normalizedSections:
|
||||
jsonConfig["text-styles"] = extractTextStyles(config[normalizedSections["Default Item Styles"]])
|
||||
|
||||
jsonConfig["custom-styles"] = extractCustomStyles()
|
||||
if settings["IncludeCustoms"]:
|
||||
jsonConfig["custom-styles"] = extractCustomStyles(config)
|
||||
|
||||
print(json.dumps(jsonConfig, indent=4, sort_keys=True))
|
||||
|
||||
|
||||
pprint(jsonConfig)
|
||||
# pprint(config.sections())
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: " + sys.argv[0] + " Name Filepath")
|
||||
exit()
|
||||
|
||||
jsonConfig["metadata"] = {
|
||||
"name": str(sys.argv[1]),
|
||||
"revision": 1
|
||||
}
|
||||
|
||||
main(str(sys.argv[2]))
|
||||
|
Loading…
Reference in New Issue
Block a user