mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
kivy: allow user-defined text colors in data/client.kv (#1429)
This commit is contained in:
20
kvui.py
20
kvui.py
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import logging
|
||||
import typing
|
||||
import asyncio
|
||||
|
||||
os.environ["KIVY_NO_CONSOLELOG"] = "1"
|
||||
os.environ["KIVY_NO_FILELOG"] = "1"
|
||||
@@ -26,6 +25,7 @@ from kivy.base import ExceptionHandler, ExceptionManager
|
||||
from kivy.clock import Clock
|
||||
from kivy.factory import Factory
|
||||
from kivy.properties import BooleanProperty, ObjectProperty
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.layout import Layout
|
||||
@@ -538,6 +538,19 @@ class E(ExceptionHandler):
|
||||
|
||||
|
||||
class KivyJSONtoTextParser(JSONtoTextParser):
|
||||
# dummy class to absorb kvlang definitions
|
||||
class TextColors(Widget):
|
||||
pass
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# we grab the color definitions from the .kv file, then overwrite the JSONtoTextParser default entries
|
||||
colors = self.TextColors()
|
||||
color_codes = self.color_codes.copy()
|
||||
for name, code in color_codes.items():
|
||||
color_codes[name] = getattr(colors, name, code)
|
||||
self.color_codes = color_codes
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.ref_count = 0
|
||||
return super(KivyJSONtoTextParser, self).__call__(*args, **kwargs)
|
||||
@@ -587,3 +600,8 @@ class KivyJSONtoTextParser(JSONtoTextParser):
|
||||
ExceptionManager.add_handler(E())
|
||||
|
||||
Builder.load_file(Utils.local_path("data", "client.kv"))
|
||||
user_file = Utils.local_path("data", "user.kv")
|
||||
if os.path.exists(user_file):
|
||||
logging.info("Loading user.kv into builder.")
|
||||
Builder.load_file(user_file)
|
||||
|
||||
|
Reference in New Issue
Block a user