feat(ui): 添加深色模式支持

- 新增深色/浅色模式切换按钮,位于主窗口底部
- 在配置文件中定义主题颜色(浅色/深色背景、列表背景、前景色)
- 更新 UI 工具函数以支持动态主题切换,包括列表斑马纹适配
- 添加翻译条目(Dark Mode/Light Mode)并更新编译脚本
- 修改主窗口创建逻辑,集成主题切换回调
- 调整列表背景色属性从 BACKCOLOR 改为 BGCOLOR 以保持一致性
This commit is contained in:
2026-05-02 01:32:56 +08:00
parent 3df2988915
commit 720ebb535d
14 changed files with 233 additions and 27 deletions
+67
View File
@@ -0,0 +1,67 @@
import struct, re, os
def compile_po_to_mo(po_path, mo_path):
with open(po_path, 'r', encoding='utf-8') as f:
content = f.read()
entries = []
for match in re.finditer(
r'msgid "(.+?)"\s*\nmsgstr "(.*?)"',
content, re.DOTALL
):
msgid = match.group(1)
msgstr = match.group(2)
if msgid:
entries.append((msgid, msgstr))
if not entries:
print(f'No entries in {po_path}')
return
N = len(entries)
header_sz = 28
table_sz = N * 8 * 2
orig_off = header_sz + table_sz
orig_data = b''
orig_offsets = []
for eid, estr in entries:
orig_offsets.append(len(orig_data))
orig_data += eid.encode('utf-8') + b'\x00'
trans_off = orig_off + len(orig_data)
trans_data = b''
trans_offsets = []
for eid, estr in entries:
trans_offsets.append(len(trans_data))
trans_data += estr.encode('utf-8') + b'\x00'
buf = bytearray()
buf += struct.pack('<I', 0x950412de)
buf += struct.pack('<I', 0)
buf += struct.pack('<I', N)
buf += struct.pack('<I', orig_off)
buf += struct.pack('<I', trans_off)
buf += struct.pack('<I', 0)
buf += struct.pack('<I', 0)
for i in range(N):
buf += struct.pack('<II', len(entries[i][0].encode('utf-8')), orig_offsets[i])
for i in range(N):
buf += struct.pack('<II', len(entries[i][1].encode('utf-8')), trans_offsets[i])
buf += orig_data
buf += trans_data
os.makedirs(os.path.dirname(mo_path), exist_ok=True)
with open(mo_path, 'wb') as f:
f.write(buf)
print(f'{po_path} -> {mo_path} ({N} strings)')
base = os.path.dirname(os.path.abspath(__file__))
root = os.path.dirname(base)
compile_po_to_mo(os.path.join(root, 'po', 'zh_CN.po'), os.path.join(root, 'locale', 'zh_CN', 'LC_MESSAGES', 'zh_CN.mo'))
compile_po_to_mo(os.path.join(root, 'po', 'en_US.po'), os.path.join(root, 'locale', 'en_US', 'LC_MESSAGES', 'en_US.mo'))
compile_po_to_mo(os.path.join(root, 'po', 'zh_CN.po'), os.path.join(root, 'build', 'locale', 'zh_CN', 'LC_MESSAGES', 'zh_CN.mo'))
compile_po_to_mo(os.path.join(root, 'po', 'en_US.po'), os.path.join(root, 'build', 'locale', 'en_US', 'LC_MESSAGES', 'en_US.mo'))
+9 -1
View File
@@ -406,4 +406,12 @@ msgstr "Please select an item to delete first"
#: src/controller/callbacks_basic.c
msgid "This path already exists and will not be added again."
msgstr "This path already exists and will not be added again."
msgstr "This path already exists and will not be added again."
#: src/ui/main_window.c
msgid "Dark Mode"
msgstr "Dark Mode"
#: src/ui/main_window.c
msgid "Light Mode"
msgstr "Light Mode"
+8
View File
@@ -124,3 +124,11 @@ msgstr ""
#: src/controller/callbacks_nav.c
msgid "Redo completed"
msgstr ""
#: src/ui/main_window.c
msgid "Dark Mode"
msgstr ""
#: src/ui/main_window.c
msgid "Light Mode"
msgstr ""
+9 -1
View File
@@ -406,4 +406,12 @@ msgstr "请先选择要删除的项"
#: src/controller/callbacks_basic.c
msgid "This path already exists and will not be added again."
msgstr "该路径已存在,不会重复添加。"
msgstr "该路径已存在,不会重复添加。"
#: src/ui/main_window.c
msgid "Dark Mode"
msgstr "深色模式"
#: src/ui/main_window.c
msgid "Light Mode"
msgstr "浅色模式"