2020-06-14 08:59:23 +08:00
|
|
|
|
#!/usr/bin/python
|
2019-12-19 16:11:17 +08:00
|
|
|
|
|
|
|
|
|
import os
|
2020-06-14 08:59:23 +08:00
|
|
|
|
import sys
|
2020-08-14 16:43:12 +08:00
|
|
|
|
import json
|
|
|
|
|
import collections
|
2020-06-14 08:59:23 +08:00
|
|
|
|
|
|
|
|
|
# AWTK_ROOT/scripts/update_res_common.py
|
2019-12-19 16:11:17 +08:00
|
|
|
|
import update_res_common as common
|
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
def use_theme_config_from_project_json():
|
|
|
|
|
global DPI
|
|
|
|
|
global THEMES
|
|
|
|
|
global OUTPUT_ROOT
|
|
|
|
|
global IS_GENERATE_INC_RES
|
|
|
|
|
global IS_GENERATE_INC_BITMAP
|
|
|
|
|
global APP_THEME
|
|
|
|
|
global APP_ROOT
|
|
|
|
|
|
|
|
|
|
project_json = common.join_path(APP_ROOT, 'project.json')
|
|
|
|
|
if not os.path.exists(project_json):
|
|
|
|
|
print('project.json is not exists.')
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
content = common.read_file(project_json)
|
|
|
|
|
content = json.loads(content, object_pairs_hook=collections.OrderedDict)
|
|
|
|
|
|
|
|
|
|
if not isinstance(content, dict):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if 'assets' not in content:
|
|
|
|
|
return
|
|
|
|
|
assets = content['assets']
|
|
|
|
|
|
|
|
|
|
if 'outputDir' in assets:
|
|
|
|
|
OUTPUT_ROOT = common.to_file_system_coding(assets['outputDir'])
|
|
|
|
|
OUTPUT_ROOT = common.join_path(APP_ROOT, OUTPUT_ROOT+'/assets')
|
|
|
|
|
|
|
|
|
|
if 'activedTheme' in assets:
|
|
|
|
|
APP_THEME = assets['activedTheme']
|
|
|
|
|
|
|
|
|
|
if 'themes' not in assets:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if len(assets['themes']) == 0:
|
|
|
|
|
return
|
|
|
|
|
|
2020-10-30 07:11:48 +08:00
|
|
|
|
if 'loadFrom' in assets and assets['loadFrom'] == 'fs':
|
|
|
|
|
IS_GENERATE_INC_BITMAP = False
|
|
|
|
|
IS_GENERATE_INC_RES = False
|
|
|
|
|
elif 'const' in assets and assets['const'] != 'all_data':
|
2020-10-15 13:56:59 +08:00
|
|
|
|
if assets['const'] == 'resource_data':
|
|
|
|
|
IS_GENERATE_INC_BITMAP = False
|
|
|
|
|
else:
|
|
|
|
|
IS_GENERATE_INC_RES = False
|
2020-08-14 16:43:12 +08:00
|
|
|
|
|
|
|
|
|
if 'screenDPR' in assets:
|
|
|
|
|
DPI = assets['screenDPR']
|
|
|
|
|
|
|
|
|
|
for theme_name, theme_setting in assets['themes'].items():
|
|
|
|
|
theme_name = common.to_file_system_coding(theme_name)
|
|
|
|
|
color_format = theme_setting['lcd']['colorFormat']
|
|
|
|
|
color_depth = theme_setting['lcd']['colorDepth']
|
|
|
|
|
|
|
|
|
|
if color_format == 'MONO':
|
|
|
|
|
imagegen_options = 'mono'
|
|
|
|
|
elif color_format == 'BGR(A)':
|
|
|
|
|
if color_depth == '16bit':
|
|
|
|
|
imagegen_options = 'bgr565'
|
|
|
|
|
else:
|
|
|
|
|
imagegen_options = 'bgra'
|
|
|
|
|
else:
|
|
|
|
|
if color_depth == '16bit':
|
|
|
|
|
imagegen_options = 'rgb565'
|
|
|
|
|
else:
|
|
|
|
|
imagegen_options = 'rgba'
|
|
|
|
|
|
|
|
|
|
if IS_GENERATE_INC_BITMAP:
|
|
|
|
|
font = theme_setting['fonts']
|
|
|
|
|
config_dir = common.join_path(ASSETS_ROOT, theme_name+'/fonts/config')
|
|
|
|
|
common.remove_dir(config_dir)
|
|
|
|
|
common.make_dirs(config_dir)
|
|
|
|
|
for font_name, font_setting in theme_setting['fonts'].items():
|
|
|
|
|
for font_size, text in font_setting.items():
|
|
|
|
|
if font_size.isdigit():
|
|
|
|
|
font_name = common.to_file_system_coding(font_name)
|
|
|
|
|
font_size = common.to_file_system_coding(font_size)
|
|
|
|
|
filename = common.join_path(config_dir, font_name+'_'+font_size+'.txt')
|
|
|
|
|
common.write_file(filename, text)
|
|
|
|
|
|
|
|
|
|
theme = {'name': theme_name, 'imagegen_options': imagegen_options, 'packaged': theme_setting['packaged']}
|
|
|
|
|
if theme_name == 'default':
|
|
|
|
|
THEMES.insert(0, theme)
|
|
|
|
|
else:
|
|
|
|
|
THEMES.append(theme)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def use_default_theme_config():
|
|
|
|
|
global THEMES
|
|
|
|
|
|
|
|
|
|
use_theme_config_from_project_json()
|
|
|
|
|
|
|
|
|
|
if len(THEMES) == 0:
|
|
|
|
|
if os.path.isdir(ASSETS_ROOT):
|
|
|
|
|
for file in os.listdir(ASSETS_ROOT):
|
|
|
|
|
if os.path.isdir(common.join_path(ASSETS_ROOT, file)):
|
|
|
|
|
if file == 'default':
|
|
|
|
|
THEMES.insert(0, file)
|
|
|
|
|
else:
|
|
|
|
|
THEMES.append(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_dependencies_ok():
|
|
|
|
|
dependencies = ['bsvggen', 'fontgen', 'imagegen', 'resgen', 'strgen', 'themegen', 'xml_to_ui']
|
|
|
|
|
for d in dependencies:
|
|
|
|
|
if not os.path.exists(common.join_path(TOOLS_ROOT, common.to_exe(d))):
|
|
|
|
|
print('Can\'t find ' + common.to_exe(d) + ', please build AWTK.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if IS_GENERATE_INC_BITMAP:
|
|
|
|
|
for t in THEMES:
|
|
|
|
|
if isinstance(t, dict):
|
|
|
|
|
print(t['imagegen_options'])
|
|
|
|
|
if 'imagegen_options' in t and t['imagegen_options'] == 'mono':
|
|
|
|
|
if not os.path.exists(common.join_path(TOOLS_ROOT, common.to_exe('fontgen_ft'))):
|
|
|
|
|
print('If you need to generate fonts those display on MONO LCD, please generate fontgen_ft.')
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_generate_res_event():
|
|
|
|
|
if os.path.exists(common.join_path(APP_ROOT, 'scripts/update_res_generate_res_handler.py')):
|
|
|
|
|
import update_res_generate_res_handler as generate_res
|
|
|
|
|
if hasattr(generate_res, 'on_generate_res_before'):
|
|
|
|
|
common.on_generate_res_before(generate_res.on_generate_res_before)
|
|
|
|
|
if hasattr(generate_res, 'on_generate_res_after'):
|
|
|
|
|
common.on_generate_res_after(generate_res.on_generate_res_after)
|
|
|
|
|
|
2021-02-20 15:03:40 +08:00
|
|
|
|
def getopt(args):
|
|
|
|
|
return common.get_args(args);
|
2020-08-14 16:43:12 +08:00
|
|
|
|
|
2020-09-18 11:31:59 +08:00
|
|
|
|
def run(awtk_root, is_excluded_file_handler = None):
|
2020-10-30 07:11:48 +08:00
|
|
|
|
global DPI
|
2020-08-14 16:43:12 +08:00
|
|
|
|
global AWTK_ROOT
|
|
|
|
|
global TOOLS_ROOT
|
|
|
|
|
global THEMES
|
2020-10-30 07:11:48 +08:00
|
|
|
|
global APP_THEME
|
2020-08-14 16:43:12 +08:00
|
|
|
|
global APP_ROOT
|
|
|
|
|
global ASSETS_ROOT
|
2020-10-30 07:11:48 +08:00
|
|
|
|
global OUTPUT_ROOT
|
2020-10-15 13:56:59 +08:00
|
|
|
|
global IS_GENERATE_INC_RES
|
2020-08-14 16:43:12 +08:00
|
|
|
|
global IS_GENERATE_INC_BITMAP
|
|
|
|
|
|
2021-02-20 15:03:40 +08:00
|
|
|
|
GDPI=''
|
|
|
|
|
IMAGEGEN_OPTIONS=''
|
|
|
|
|
sys_args = common.get_args(sys.argv[1:])
|
|
|
|
|
if len(sys_args) > 0 :
|
|
|
|
|
common.set_action(sys_args[0])
|
|
|
|
|
if len(sys_args) > 1:
|
|
|
|
|
GDPI = sys_args[1]
|
|
|
|
|
if len(sys_args) > 2:
|
|
|
|
|
IMAGEGEN_OPTIONS = sys_args[2]
|
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
AWTK_ROOT = awtk_root
|
|
|
|
|
APP_ROOT = common.getcwd()
|
2020-08-17 08:43:23 +08:00
|
|
|
|
action = common.get_action()
|
2020-08-14 16:43:12 +08:00
|
|
|
|
if APP_ROOT.endswith('scripts'):
|
|
|
|
|
APP_ROOT = os.path.dirname(APP_ROOT)
|
2020-06-14 08:59:23 +08:00
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
os.chdir(APP_ROOT)
|
2020-06-14 08:59:23 +08:00
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
DPI = 'x1'
|
|
|
|
|
THEMES = []
|
|
|
|
|
APP_THEME = 'default'
|
|
|
|
|
IS_GENERATE_INC_RES = True
|
|
|
|
|
IS_GENERATE_INC_BITMAP = True
|
|
|
|
|
TOOLS_ROOT = common.join_path(AWTK_ROOT, 'bin')
|
|
|
|
|
AWTK_ROOT = common.join_path(APP_ROOT, AWTK_ROOT)
|
|
|
|
|
ASSETS_ROOT = common.join_path(APP_ROOT, 'design')
|
|
|
|
|
OUTPUT_ROOT = common.join_path(APP_ROOT, 'res/assets')
|
2020-06-14 08:59:23 +08:00
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
use_default_theme_config()
|
2020-10-15 13:56:59 +08:00
|
|
|
|
|
2020-10-30 07:11:48 +08:00
|
|
|
|
ASSET_C = common.join_path(OUTPUT_ROOT, '../assets.inc')
|
|
|
|
|
if action == 'json':
|
|
|
|
|
ASSET_C = common.join_path(APP_ROOT, 'assets_web.js')
|
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
if not is_dependencies_ok():
|
|
|
|
|
print('For details, please read scripts/README.md.')
|
|
|
|
|
elif len(THEMES) == 0:
|
|
|
|
|
print('Not found theme.')
|
|
|
|
|
print('For details, please read scripts/README.md.')
|
|
|
|
|
else:
|
2021-02-20 15:03:40 +08:00
|
|
|
|
if GDPI != '':
|
|
|
|
|
DPI = GDPI
|
|
|
|
|
if IMAGEGEN_OPTIONS != '':
|
|
|
|
|
for theme in THEMES :
|
|
|
|
|
theme["imagegen_options"] = IMAGEGEN_OPTIONS
|
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
common.init(AWTK_ROOT, ASSETS_ROOT, THEMES, ASSET_C, OUTPUT_ROOT)
|
|
|
|
|
common.set_tools_dir(TOOLS_ROOT)
|
|
|
|
|
common.set_dpi(DPI)
|
|
|
|
|
common.set_app_theme(APP_THEME)
|
|
|
|
|
common.set_enable_generate_inc_res(IS_GENERATE_INC_RES)
|
|
|
|
|
common.set_enable_generate_inc_bitmap(IS_GENERATE_INC_BITMAP)
|
2020-09-18 11:31:59 +08:00
|
|
|
|
common.set_is_excluded_file_handler(is_excluded_file_handler)
|
2020-08-14 16:43:12 +08:00
|
|
|
|
on_generate_res_event()
|
|
|
|
|
common.update_res()
|
2020-06-14 08:59:23 +08:00
|
|
|
|
|
2020-08-14 16:43:12 +08:00
|
|
|
|
if isinstance(THEMES[0], dict):
|
|
|
|
|
if action != 'clean' and action != 'web' and action != 'json' and action != 'pinyin':
|
|
|
|
|
common.gen_res_c(False)
|