2020-09-20 14:20:52 +02:00
|
|
|
from configparser import ConfigParser
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
|
|
|
|
jsonConfig = {
|
|
|
|
"_comments": "Created by theme_converter script",
|
|
|
|
"metadata": {
|
|
|
|
"name": "MyCuteTheme",
|
|
|
|
"revision": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
editorColors = {
|
|
|
|
"Color Background": "BackgroundColor",
|
|
|
|
"Color Code Folding": "CodeFolding",
|
|
|
|
"Color Current Line Number": "CurrentLineNumber",
|
|
|
|
"Color Highlighted Bracket": "BracketMatching",
|
|
|
|
"Color Highlighted Line": "CurrentLine",
|
|
|
|
"Color Icon Bar": "IconBorder",
|
|
|
|
"Color Indentation Line": "IndentationLine",
|
|
|
|
"Color Line Number": "LineNumbers",
|
|
|
|
"Color MarkType 1": "MarkBookmark",
|
|
|
|
"Color MarkType 2": "MarkBreakpointActive",
|
|
|
|
"Color MarkType 3": "MarkBreakpointReached",
|
|
|
|
"Color MarkType 4": "MarkBreakpointDisabled",
|
|
|
|
"Color MarkType 5": "MarkExecution",
|
|
|
|
"Color MarkType 6": "MarkWarning",
|
|
|
|
"Color MarkType 7": "MarkError",
|
|
|
|
"Color Modified Lines": "ModifiedLines",
|
|
|
|
"Color Replace Highlight": "ReplaceHighlight",
|
|
|
|
"Color Saved Lines": "SavedLines",
|
|
|
|
"Color Search Highlight": "SearchHighlight",
|
|
|
|
"Color Selection": "TextSelection",
|
|
|
|
"Color Separator": "Separator",
|
|
|
|
"Color Spelling Mistake Line": "SpellChecking",
|
|
|
|
"Color Tab Marker": "TabMarker",
|
|
|
|
"Color Template Background": "TemplateBackground",
|
|
|
|
"Color Template Editable Placeholder": "TemplatePlaceholder",
|
|
|
|
"Color Template Focused Editable Placeholder": "TemplateFocusedPlaceholder",
|
|
|
|
"Color Template Not Editable Placeholder": "TemplateReadOnlyPlaceholder",
|
|
|
|
"Color Word Wrap Marker": "WordWrapMarker"
|
|
|
|
}
|
|
|
|
|
|
|
|
textStyles = {
|
|
|
|
"Alert": "Alert",
|
|
|
|
"Annotation": "Annotation",
|
|
|
|
"Attribute": "Attribute",
|
|
|
|
"Base-N Integer": "BaseN",
|
|
|
|
"Built-in": "BuiltIn",
|
|
|
|
"Character": "Char",
|
|
|
|
"Comment": "Comment",
|
|
|
|
"Comment Variable": "CommentVar",
|
|
|
|
"Constant": "Constant",
|
|
|
|
"Control Flow": "ControlFlow",
|
|
|
|
"Data Type": "DataType",
|
|
|
|
"Decimal/Value": "DecVal",
|
|
|
|
"Documentation": "Documentation",
|
|
|
|
"Error": "Error",
|
|
|
|
"Extension": "Extension",
|
|
|
|
"Floating Point": "Float",
|
|
|
|
"Function": "Function",
|
|
|
|
"Import": "Import",
|
|
|
|
"Information": "Information",
|
|
|
|
"Keyword": "Keyword",
|
|
|
|
"Normal": "Normal",
|
|
|
|
"Operator": "Operator",
|
|
|
|
"Others": "Others",
|
|
|
|
"Preprocessor": "Preprocessor",
|
|
|
|
"Region Marker": "RegionMarker",
|
|
|
|
"Special Character": "SpecialChar",
|
|
|
|
"Special String": "SpecialString",
|
|
|
|
"String": "String",
|
|
|
|
"Variable": "Variable",
|
|
|
|
"Verbatim String": "VerbatimString",
|
|
|
|
"Warning": "Warning"
|
|
|
|
}
|
|
|
|
|
|
|
|
normalizedSections = {}
|
|
|
|
|
|
|
|
|
|
|
|
def normalizeSections(sections: list):
|
|
|
|
value: str
|
|
|
|
for value in sections:
|
|
|
|
normal = value
|
|
|
|
|
|
|
|
if " - " in value:
|
|
|
|
normal = normal.split(" - ")[0]
|
|
|
|
|
|
|
|
normalizedSections[normal] = value
|
|
|
|
|
|
|
|
|
|
|
|
def reEcodeColors(text: str) -> str:
|
|
|
|
return "#" + text[2:]
|
|
|
|
|
|
|
|
|
|
|
|
def reEncodeBool(text: str) -> bool:
|
|
|
|
return True if text == "1" else False
|
|
|
|
|
|
|
|
|
|
|
|
def rgb_to_hex(rgb: tuple) -> str:
|
|
|
|
return '#%02x%02x%02x' % rgb
|
|
|
|
|
|
|
|
|
|
|
|
def decodeTextStyle(text: str) -> dict:
|
|
|
|
style = {}
|
|
|
|
|
|
|
|
field = text.split(",")
|
|
|
|
|
|
|
|
if len(field) != 10:
|
|
|
|
return dict()
|
|
|
|
|
|
|
|
if field[0]:
|
|
|
|
style["text-color"] = reEcodeColors(field[0])
|
|
|
|
if field[1]:
|
|
|
|
style["selected-text-color"] = reEcodeColors(field[1])
|
|
|
|
if field[2]:
|
|
|
|
style["bold"] = reEncodeBool(field[2])
|
|
|
|
if field[3]:
|
|
|
|
style["italic"] = reEncodeBool(field[3])
|
|
|
|
if field[4]:
|
|
|
|
style["strike-through"] = reEncodeBool(field[4])
|
|
|
|
if field[5]:
|
|
|
|
style["underline"] = reEncodeBool(field[5])
|
|
|
|
if field[6]:
|
|
|
|
style["background-color"] = reEcodeColors(field[6])
|
|
|
|
if field[7]:
|
|
|
|
style["selected-text-color"] = reEcodeColors(field[7])
|
|
|
|
# 8: font family > ignored
|
|
|
|
# 9: --- > ignored
|
|
|
|
|
|
|
|
return style
|
|
|
|
|
|
|
|
|
|
|
|
def decodeColorSettings(text: str) -> str:
|
|
|
|
fieldds = tuple(map(int, text.split(",")))
|
|
|
|
|
|
|
|
if len(fieldds) != 3:
|
|
|
|
return
|
|
|
|
|
|
|
|
return rgb_to_hex(fieldds)
|
|
|
|
|
|
|
|
|
|
|
|
def extractEditorColors(section: dict) -> dict:
|
|
|
|
editor_colors = {}
|
|
|
|
|
|
|
|
key: str
|
|
|
|
value: str
|
|
|
|
for key, value in section.items():
|
|
|
|
editor_colors[editorColors[key]] = decodeColorSettings(value)
|
|
|
|
|
|
|
|
return editor_colors
|
|
|
|
|
|
|
|
|
|
|
|
def extractTextStyles(section: dict) -> dict:
|
|
|
|
text_styles = {}
|
|
|
|
|
|
|
|
key: str
|
|
|
|
value: str
|
|
|
|
for key, value in section.items():
|
|
|
|
text_styles[textStyles[key]] = decodeTextStyle(value)
|
|
|
|
|
|
|
|
return text_styles
|
|
|
|
|
|
|
|
|
|
|
|
config = ConfigParser(delimiters="=")
|
|
|
|
config.optionxform = str
|
|
|
|
config.read('DarkOxygen.kateschema')
|
|
|
|
|
|
|
|
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"]])
|
|
|
|
|
|
|
|
pprint(jsonConfig)
|
|
|
|
# pprint(config.sections())
|