Skip to content

Commit

Permalink
Update v4.2p
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatDamon committed Jul 15, 2023
1 parent 239bdc3 commit bb875d7
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 34 deletions.
17 changes: 8 additions & 9 deletions lib/basic_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
print("\033[0;34m[INFO] Basic Information ready...\033[0m")

# 基本信息
ver = "v4.1.1p"
ver = "v4.2p"
author = "Suntrise (STR)"
auth_abbr = "STR"
title = "伪本地化演示程序 " + ver + " by " + auth_abbr
updmd = """
# 更新日志 (详见GitHub Releases)
## v4.2p - 2023.7.15
1. 修复了一些BUG;
2. 界面更新;
3. 仓库置顶;
3. 细节优化.
## v4.1.1p - 2023.7.14
1. 新增保存历史记录;
Expand All @@ -28,14 +35,6 @@
# v4.0.1p - 2023.7.4
1. 细节优化.
## v4.0p - 2023.7.4
1. [开发者]功能函数已拆分;
2. 引入Mini模式;
3. 新增文本文件导入&保存;
4. 新增窗口透明度设置;
5. 检查更新优化.
"""

# 定义内容
Expand Down
18 changes: 12 additions & 6 deletions lib/pslo_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,23 @@ def pslo(pstype, xab, num_pslo, vowel_cs, suf_way, cus_pre, cus_suf,cus_re, cus_
print("\033[0;34m[INFO] Pseudo-localization initialization completed\033[0m")
pstr = pstype
res = ''
control_txt = False
if str != "" and str != "null":
if xab != "enxb":
xab = "enxa"
for l in pstr:
i += 1
if control_txt == True:
control_txt = False
continue
# 隐藏控制符
if vis_con_cb == True:
if l == "%" and pstr[i] == "s":
break
control_txt = True
continue
if l == "\\" and pstr[i] == "n":
break
control_txt = True
continue
# 数字伪本地化判断
if num_pslo == "2":
al = l.replace('a',random.choice(arra)).replace('A',random.choice(arraa)).replace('b',random.choice(arrb)).replace('B',random.choice(arrbb)).replace('c',random.choice(arrc)).replace('C',random.choice(arrcc)).replace('d',random.choice(arrd)).replace('D',random.choice(arrdd)).replace('e',random.choice(arre)).replace('E',random.choice(arree)).replace('f',random.choice(arrf)).replace('F',random.choice(arrff)).replace('g',random.choice(arrg)).replace('G',random.choice(arrgg)).replace('h',random.choice(arrh)).replace('H',random.choice(arrhh)).replace('i',random.choice(arri)).replace('I',random.choice(arrii)).replace('j',random.choice(arrj)).replace('J',random.choice(arrjj)).replace('k',random.choice(arrk)).replace('K',random.choice(arrkk)).replace('l',random.choice(arrl)).replace('L',random.choice(arrll)).replace('m',random.choice(arrm)).replace('M',random.choice(arrmm)).replace('n',random.choice(arrn)).replace('N',random.choice(arrnn)).replace('o',random.choice(arro)).replace('O',random.choice(arroo)).replace('p',random.choice(arrp)).replace('P',random.choice(arrpp)).replace('q',random.choice(arrq)).replace('Q',random.choice(arrqq)).replace('r',random.choice(arrr)).replace('R',random.choice(arrrr)).replace('s',random.choice(arrs)).replace('S',random.choice(arrss)).replace('t',random.choice(arrt)).replace('T',random.choice(arrtt)).replace('u',random.choice(arru)).replace('U',random.choice(arruu)).replace('v',random.choice(arrv)).replace('V',random.choice(arrvv)).replace('w',random.choice(arrw)).replace('W',random.choice(arrww)).replace('x',random.choice(arrx)).replace('X',random.choice(arrxx)).replace('y',random.choice(arry)).replace('Y',random.choice(arryy)).replace('z',random.choice(arrz)).replace('Z',random.choice(arrzz)).replace('1',random.choice(arr1)).replace('2',random.choice(arr2)).replace('3',random.choice(arr3)).replace('4',random.choice(arr4)).replace('5',random.choice(arr5)).replace('6',random.choice(arr6)).replace('7',random.choice(arr7)).replace('8',random.choice(arr8)).replace('9',random.choice(arr9)).replace('0',random.choice(arr0))
Expand Down Expand Up @@ -145,12 +151,12 @@ def pslo(pstype, xab, num_pslo, vowel_cs, suf_way, cus_pre, cus_suf,cus_re, cus_
hash_id = hash_id + random.choice(arral)
m += 1
print("\033[0;34m[INFO] Number of Hash ID bits: " + str(hash_ws) + "\033[0m")
res = "[" + hash_id + "]" +res
res = "[" + hash_id + "]" + res
hash_id = ""
m = 0
else:
print("\033[0;34m[INFO] Add Hash ID: False\033[0m")

print("\033[0;34m[INFO] Result: " + res + "\033[0m")
return res
output = res
print("\033[0;34m[INFO] Result: " + output + "\033[0m")
return output
print("\033[0;32m[DONE] Pseudo-localization completed\033[0m")
113 changes: 97 additions & 16 deletions pslo.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main(page: ft.Page):
def pslo(e):
global pshis
page.result.value = pslo_work.pslo(page.pstype.value, xab.value, num_pslo.value, vowel_cs.value, suf_way.value, cus_pre.value, cus_suf.value, cus_re.value, cus_cs.value, hash_cb.value, hash_ws.value, vis_con_cb.value)
pshis += page.pstype.value + " → " + page.result.value +" | " + datetime.datetime.now().strftime('%H:%M:%S') + "\n" # 添加到历史记录
pshis += page.pstype.value + " → " + page.result.value +" | " + datetime.datetime.now().strftime('%H:%M:%S') + "\n——————————————————————————————\n" # 添加到历史记录
history.value = pshis
print("\033[0;32m[DONE] Added content to history\033[0m")
page.update()
Expand Down Expand Up @@ -303,6 +303,23 @@ def main(page: ft.Page):
page.update()
print("\033[0;32m[DONE] Dialog open(UPD)\033[0m")

# 置顶
def always_on_top(e):
if page.window_always_on_top == False:
page.window_always_on_top = True
print("\033[0;32m[DONE] Set always on top\033[0m")
page.snack_bar = ft.SnackBar(ft.Text(f"已置顶")) # 提示栏
page.snack_bar.open = True
print("\033[0;32m[DONE] Snack Bar pop-up(AOT)\033[0m")
page.update()
elif page.window_always_on_top == True:
page.window_always_on_top = False
print("\033[0;32m[DONE] Cancel always on top\033[0m")
page.snack_bar = ft.SnackBar(ft.Text(f"已取消置顶")) # 提示栏
page.snack_bar.open = True
print("\033[0;32m[DONE] Snack Bar pop-up(ATX)\033[0m")
page.update()

# “什么是伪本地化”窗口定义
what_dlg = ft.AlertDialog(
title = ft.Text("什么是伪本地化?"), on_dismiss = lambda e: print("\033[0;34m[INFO] Dialog dismissed(WHT)\033[0m"),
Expand Down Expand Up @@ -346,9 +363,8 @@ def main(page: ft.Page):
page.window_height = 600
page.window_width = 800
page.window_min_height = 400
page.window_min_width = 760
#page.window_title_bar_hidden = True
#page.window_title_bar_buttons_hidden = True
page.window_min_width = 797
page.window_always_on_top = False
page.theme = ft.Theme(
font_family = "Microsoft Yahei",
color_scheme_seed = ft.colors.BLUE
Expand All @@ -360,6 +376,7 @@ def main(page: ft.Page):
title = ft.Text(basic_info.title),
center_title = False,
actions = [
ft.IconButton(icon = ft.icons.VERTICAL_ALIGN_TOP_OUTLINED, tooltip = "置顶", on_click = always_on_top),
ft.PopupMenuButton(
tooltip = "展开",
items = [
Expand Down Expand Up @@ -412,7 +429,6 @@ def main(page: ft.Page):
tooltip = "将您所填写的内容伪本地化, 每次生成结果都会不一样哦",
on_click = pslo
)

copy_btn = ft.FilledTonalButton(
"复制",
icon = ft.icons.COPY,
Expand Down Expand Up @@ -448,6 +464,19 @@ def main(page: ft.Page):
]
)
row_pslo = ft.Row(spacing = 10, controls = [pslo_btn, copy_btn, lsfile])
pslo_card = ft.Card(
content = ft.Container(
content = ft.Column(
[
page.pstype,
page.result,
row_pslo
]
),
width = 1000000000,
padding = 15
)
)

# 历史记录
history = ft.Text("无记录", size = 18, selectable = True)
Expand All @@ -458,11 +487,19 @@ def main(page: ft.Page):
history
]
),
width = page.window_width,
width = 1000000000,
padding = 15
)
)
save_his_dialog = ft.FilePicker(on_result = sv_his)
his_title = ft.Row(controls = [
ft.Icon(
ft.icons.LIST_ALT_OUTLINED
),
ft.Text(
"历史记录:",
size = 20
)])
his_opts = ft.Row(controls=[
save_his_dialog,
ft.TextButton(
Expand All @@ -471,7 +508,7 @@ def main(page: ft.Page):
on_click = copy_history
),
ft.TextButton(
"保存到本地",
"导出记录",
icon = ft.icons.SAVE_OUTLINED,
on_click = lambda _: save_his_dialog.save_file(allowed_extensions = ["txt"])
),
Expand All @@ -482,10 +519,7 @@ def main(page: ft.Page):
)
])
his_bar = ft.Row(alignment = ft.MainAxisAlignment.SPACE_BETWEEN,controls = [
ft.Text(
"历史记录:",
size = 20
),
his_title,
his_opts
])

Expand Down Expand Up @@ -542,7 +576,25 @@ def main(page: ft.Page):
vowel_cs = ft.TextField(width = 150, label = "次数 (0-10)", value = 0, on_blur = vcs_check)
row_vow = ft.Row(spacing = 10, controls = [vowel_tx,vowel_cs])
#----------#
vis_con_cb = ft.Switch(label = "翻译后隐藏%s, \\n等控制字符", value = False)
vis_con_cb = ft.Switch(label = r"翻译后隐藏%s, \n等控制字符", value = False)

pslo_opt_card = ft.Card(
content = ft.Container(
content = ft.Column(
[
suf_way,
cus_ps,
row_hash,
num_pslo,
row_vow,
vis_con_cb
]
),
width = 1000000000,
padding = 15
)
)

# 外观设置
opt_look = ft.Row(
[
Expand All @@ -563,7 +615,7 @@ def main(page: ft.Page):
theme.value = 2
#----------#
sch_text = ft.Text("配色", size = 20)
scheme = ft.RadioGroup(value = 0,content=ft.Row([
scheme = ft.RadioGroup(value = 0, content = ft.Row([
ft.Radio(
value = 0,
label = "蓝色",
Expand Down Expand Up @@ -593,6 +645,22 @@ def main(page: ft.Page):
#----------#
opacity_text = ft.Text("窗口透明度", size = 20)
page.opacity_slider = ft.Slider(min = 50, max = 100, divisions = 50, label = "{value}%", on_change = opacity_slider_changed, value = 100)
opacity_bar = ft.Row(controls = [opacity_text, ft.Icon(ft.icons.OPACITY), page.opacity_slider, ft.Icon(ft.icons.WATER_DROP)])

look_opt_card = ft.Card(
content = ft.Container(
content = ft.Column(
[
theme,
sch_text,
scheme,
opacity_bar
]
),
width = 1000000000,
padding = 15
)
)

# 关于内容
abt = ft.Row(
Expand All @@ -603,12 +671,25 @@ def main(page: ft.Page):
)
about = ft.Text(basic_info.about_text, size = 15, selectable = True)
upd_bar = ft.Row(
controls=[
controls = [
ft.TextButton("更新日志", icon = ft.icons.UPDATE, on_click = open_upd),
ft.TextButton("检查更新", icon = ft.icons.UPLOAD_OUTLINED, on_click = check_for_update)
]
)

abt_card = ft.Card(
content = ft.Container(
content = ft.Column(
[
about,
upd_bar
]
),
width = 1000000000,
padding = 15
)
)

# 标签
tab = ft.Tabs(
selected_index = 0,
Expand All @@ -618,7 +699,7 @@ def main(page: ft.Page):
text = "主界面",
icon = ft.icons.HOME_OUTLINED,
content = ft.Container(
ft.Column(spacing = 5, controls = [edge, XABrow, page.pstype, page.result, row_pslo])
ft.Column(spacing = 5, controls = [edge, XABrow, pslo_card])
),
),
ft.Tab(
Expand All @@ -629,7 +710,7 @@ def main(page: ft.Page):
ft.Tab(
text = "设置",
icon = ft.icons.SETTINGS_OUTLINED,
content = ft.Column(spacing = 10, controls = [edge, opt_pslo, opt_pslo_detail, suf_way, cus_ps, row_hash, num_pslo, row_vow, vis_con_cb, divider, opt_look, theme, sch_text, scheme, opacity_text, page.opacity_slider, divider, abt, about, upd_bar]),
content = ft.Column(spacing = 10, controls = [edge, opt_pslo, opt_pslo_detail, pslo_opt_card, divider, opt_look, look_opt_card, divider, abt, abt_card]),
),
]
)
Expand Down
25 changes: 22 additions & 3 deletions pslo_mini.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main(page: ft.Page):
# 伪本地化
def pslo(e):
global pshis
page.result.value = pslo_work.pslo(page.pstype.value, "enxa", 0, 0, 0, "", "", "", 0, False, 0)
page.result.value = pslo_work.pslo(page.pstype.value, "enxa", 0, 0, 0, "", "", "", 0, False, 0, False)
page.update()

# 复制文本
Expand All @@ -31,6 +31,23 @@ def main(page: ft.Page):
page.update()
print("\033[0;34m[INFO] Snack bar pop-up(CP)\033[0m")

# 置顶
def always_on_top(e):
if page.window_always_on_top == False:
page.window_always_on_top = True
print("\033[0;32m[DONE] Set always on top\033[0m")
page.snack_bar = ft.SnackBar(ft.Text(f"已置顶")) # 提示栏
page.snack_bar.open = True
print("\033[0;32m[DONE] Snack Bar pop-up(AOT)\033[0m")
page.update()
elif page.window_always_on_top == True:
page.window_always_on_top = False
print("\033[0;32m[DONE] Cancel always on top\033[0m")
page.snack_bar = ft.SnackBar(ft.Text(f"已取消置顶")) # 提示栏
page.snack_bar.open = True
print("\033[0;32m[DONE] Snack Bar pop-up(ATX)\033[0m")
page.update()

# 用户界面
# 基本内容定义
page.window_left = 200
Expand All @@ -45,8 +62,9 @@ def main(page: ft.Page):
)

# 主页区
titlebar = fleter.HeaderBar(page, title = "₽šļö ❤️ " + basic_info.ver, title_align = "left")
titlebar = fleter.HeaderBar(page, title = "₽šļö & ❤️", title_align = "left")
titlebar.controls.insert(1, fleter.SwitchThemeButton(page, light_icon = ft.icons.LIGHT_MODE, dark_icon = ft.icons.DARK_MODE, has_system = False))
titlebar.controls.insert(2, ft.IconButton(icon = ft.icons.VERTICAL_ALIGN_TOP_OUTLINED, on_click = always_on_top))
page.pstype = ft.TextField(hint_text = "在这里输入要翻译的内容~", text_size = 15, multiline = False, max_lines = 5)
page.result = ft.TextField(hint_text = "结果会显示在这里~", text_size = 15, multiline = False, max_lines = 5, read_only = True)
pslo_btn = ft.FilledButton(
Expand All @@ -58,7 +76,8 @@ def main(page: ft.Page):
icon = ft.icons.COPY_OUTLINED,
on_click = copy_text
)
row = ft.Row(controls=[pslo_btn, copy_btn])
btns = ft.Row(controls=[pslo_btn, copy_btn])
row = ft.Row(controls=[btns, ft.Text(basic_info.ver, size = 11, color = ft.colors.GREY)], alignment = ft.MainAxisAlignment.SPACE_BETWEEN)
page.add(titlebar, page.pstype, page.result, row)
print("\033[0;34m[INFO] Window initialization completed\033[0m")

Expand Down

0 comments on commit bb875d7

Please sign in to comment.