Added a color cache

This commit is contained in:
Salvador E. Tropea 2022-04-10 15:32:42 -03:00
parent bfdc024a33
commit a5c848c752
1 changed files with 6 additions and 0 deletions

View File

@ -26,6 +26,7 @@ KI6_KI5 = {'b_adhesive': 'b_adhes',
'user_eco2': 'eco2_user', 'user_eco2': 'eco2_user',
'b_courtyard': 'b_crtyd', 'b_courtyard': 'b_crtyd',
'f_courtyard': 'f_crtyd'} 'f_courtyard': 'f_crtyd'}
CACHE = {}
class KiCadColors(object): class KiCadColors(object):
@ -59,6 +60,10 @@ def load_color_theme(name):
else: else:
KiConf.init(GS.pcb_file) KiConf.init(GS.pcb_file)
fn = os.path.join(KiConf.config_dir, 'colors', name+'.json') fn = os.path.join(KiConf.config_dir, 'colors', name+'.json')
fn = os.path.abspath(fn)
global CACHE
if fn in CACHE:
return CACHE[fn]
if not os.path.isfile(fn): if not os.path.isfile(fn):
logger.warning(W_COLORTHEME, "Missing color theme: {}".format(fn)) logger.warning(W_COLORTHEME, "Missing color theme: {}".format(fn))
return None return None
@ -93,4 +98,5 @@ def load_color_theme(name):
# Title block and frame color # Title block and frame color
if 'worksheet' in board: if 'worksheet' in board:
c.pcb_frame = parse_color(board['worksheet']) c.pcb_frame = parse_color(board['worksheet'])
CACHE[fn] = c
return c return c