-
Notifications
You must be signed in to change notification settings - Fork 17
/
uclliu.pyw
3811 lines (3519 loc) · 144 KB
/
uclliu.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
VERSION = "1.61"
import os
#os.environ['PYTHONIOENCODING'] = 'utf-8'
#os.environ['PYTHONUTF8'] = '1'
import portalocker
# Force 950 fix utf8-beta cp65001
# should fix before import configparser
#chcp_cmd = "C:\\Windows\\System32\\chcp.com"
#if my.is_file(chcp_cmd) == True:
# my.system(chcp_cmd + " 950");
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import gtk
from gtk import gdk
import gobject
import hashlib
import php
my = php.kit()
# trad to simp or simp to trad
import stts
import re
import win32api
# 2022-08-09 參考 https://stackoverflow.com/questions/4357258/how-to-get-the-height-of-windows-taskbar-using-python-pyqt-win32
# 可以取得工作列高度
from win32api import GetMonitorInfo, MonitorFromPoint
import configparser
#,,,z ,,,x 用thread去輸出字
import thread
import base64
import random
# 播放打字音用
import pyaudio
import audioop
import wave
#2021-08-08 新版右下角 traybar
from traybar import SysTrayIcon
paudio_player = None
#2021-10-28 同時間只能一個執行緒播放
is_sound_playing = False
sound_playing_s = ""
PWD = os.path.dirname(os.path.realpath(sys.argv[0]))
import clip
#if "a" in []:
# #print("TEST")
#sys.exit(0)
#paudio_player = pyaudio.PyAudio()
# 播放打字音用
#from pydub import AudioSegment
#from pydub.playback import play
# 2022-12-02
# 強制使用 CP950 CHCP CP950
# From : https://stackoverflow.com/questions/55899664/is-there-a-way-to-change-the-console-code-page-from-within-python
# 似乎沒啥用
#os.system("chcp 950");
#import locale
#LOCALE_ENCODING = locale.getpreferredencoding()
#print("LOCALE_ENCODING: %s" % (LOCALE_ENCODING))
# 改用 i18n
import myi18n
my18 = myi18n.kit()
#print my18.auto('test')
#sys.exit()
# Fix exit crash problem
# 改用
# https://stackoverflow.com/questions/23727539/runtime-error-in-python/24035224#24035224
# 用來取反白字
# https://stackoverflow.com/questions/1007185/how-to-retrieve-the-selected-text-from-the-active-window
# import win32ui
# https://superuser.com/questions/1120624/run-script-on-any-selected-text
# 額外出字處理的 app
f_arr = [ "putty","pietty","pcman","xyplorer","kinza.exe","oxygennotincluded.exe","iedit.exe","iedit_.exe","rimworldwin64.exe" ]
f_big5_arr = [ "zip32w","daqkingcon.exe","EWinner.exe" ]
# 不使用肥米的 app
# 2021-03-19 2077 也不能使用肥米
# 2021-07-03 vncviewer.exe 不需要肥米
f_pass_app = [ "mstsc.exe","cyberpunk2077.exe","vncviewer.exe" ]
# 2019-10-20 增加出字模式
# 這是右下角 肥 的 icon
UCL_PIC_BASE64 = "AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAACUWAAAlFgAAAAAAAAAAAAD/////+Pf4//n6+//8+/n/4ebh/+3y8f////////////n69v/u9Ov/6u7o/+ru6P/q7+n/8vjy//7+////////+vTu/5W0e/+w1cv/1Na0/1mxPP9mvWL/0+bm/+fk0/+BwmD/YsVI/16+Rv9evkb/X8BG/2jGWP+01cX///////bu5v9wq0D/cbmQ/9jhyf+h1oP/Rq4t/5LAuv+xtIf/Qagu/4fMg/+d3I7/m9uO/5zXif9juzf/Vatp/+ny+f///f3/nbFt/1OoZP/t9v3/7O3Y/1StOf+LvbT/pKd5/06sU//i7ff/////////////////p7Z7/0WnSP/U5e3//////7/MkP9NqE7/2+Tv/+vt2P9Trjn/jL21/6Wnef9OrFP/4+73/////////////////8bCnv9kqmD/0uPo///////MyKr/Q4k1/22cbf+uza7/VK47/4y9tf+lp3n/TqxT/+Pu9//////////////////18e3/7fDv//7+////////zsKu/0WbKP9HqTD/TLM7/0CqMP+NvbX/pad5/06sVP/j7vf//////////////////////////////////////87Crf9IoTX/m76j/2auOv81sCT/jb22/6Wne/9FrzT/iNKC/5faiP+X2of/ldmG/5TWiv/G3NT////////////Owq3/R6Az/7zh2v/H0Kj/Ragr/4y9tf+mp3z/QK8l/1y6Rf9IsCT/QrUw/165Qv9AriH/jbap////////////zsKt/0miNv+St5X/erBj/0iqM/+MvbX/pad6/02rUP/S1tn/cZRC/1yydv/g2tH/Zacx/4u4qf///////////87Crv9InS7/VZtD/0edPf9EpjT/jL21/6Wnef9PrVT/3uDo/3SVRf9guHz/7+ff/2mqM/+Lt6n////////////Owq7/R50o/1WkTf+Gsoz/VK48/4y9tf+lp3n/T61U/97g6P90lUX/YLd8/+/n3/9pqjP/i7ep////////////zsKt/0egM/+z1tD/4uHR/1StOf+MvbX/pad6/06tUv/X3eD/cpZE/122ef/n49f/Z6oy/4u3qf///////////87Crf9CnSP/Yaha/3SlVf89pCf/jLy0/6Sne/8/sCb/ZMVQ/0qyKP9EujX/aMVN/0SxIv+Mtqn////////////b0MX/dppZ/2+mVv9uplb/bJ9d/67Jyf/LyrX/icJ2/4jId/+KyXn/ish5/4jId/+Hw3v/vtDO/////////////f39//n1+P/59Pf/+fT3//n1+P/8/P3///7///77/v/++/7//vv+//77/v/++/7//vv+///+////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
ICON_PATH = PWD + "\\icon.ico"
DEFAULT_OUTPUT_TYPE = "DEFAULT"
#BIG5
#PASTE
#import pywinauto
#pwa = pywinauto.keyboard
# 2021-08-08 將簡、繁轉換抽離成獨立 class
mystts = stts.kit()
#2022-09-02 改用 opencc 簡繁轉換
# 嘗試修正 ,,,z 在轉 簡字回字碼,有些語句如 「小当家->小當傢,天后->天後」這種問題
from opencc import OpenCC
myopencc = OpenCC('s2t')
# Debug 模式
is_DEBUG_mode = False
message = ("\nUCLLIU 肥米輸入法\nBy 羽山秋人(https://3wa.tw)\nBy Benson9954029 (https://github.com/Benson9954029)\nVersion: %s\n\n若要使用 Debug 模式:uclliu.exe -d\n" % (VERSION));
def about_uclliu():
_msg_text = ("肥米輸入法\n\n作者:羽山秋人 (https://3wa.tw)\n作者:Benson9954029 (https://github.com/Benson9954029)\n版本:%s" % VERSION)
_msg_text += "\n\n熱鍵提示:\n\n"
_msg_text += "「,,,VERSION」目前版本\n"
_msg_text += "「'ucl」同音字查詢\n"
_msg_text += "「';zo6」注音查詢\n"
_msg_text += "「,,,UNLOCK」回到正常模式\n"
_msg_text += "「,,,LOCK」進入遊戲模式\n"
_msg_text += "「,,,C」簡體模式\n"
_msg_text += "「,,,T」繁體模式\n"
_msg_text += "「,,,S」UI變窄\n"
_msg_text += "「,,,L」UI變寬\n"
_msg_text += "「,,,+」UI變大\n"
_msg_text += "「,,,-」UI變小\n"
_msg_text += "「,,,X」框字的字根轉回文字\n"
_msg_text += "「,,,Z」框字的文字變成字根\n"
return _msg_text
if len(sys.argv)!=2:
print( my.utf8tobig5(message) );
elif sys.argv[1]=="-d":
is_DEBUG_mode = True
def debug_print(data):
global is_DEBUG_mode
if is_DEBUG_mode == True:
try:
print(data)
except:
pass
#debug_print("sys.argv[1]: ")
#debug_print(sys.argv[1])
#my.exit()
def md5_file(fileName):
"""Compute md5 hash of the specified file"""
m = hashlib.md5()
try:
fd = open(fileName,"rb")
except IOError:
debug_print("Reading file has problem:", filename)
return
x = fd.read()
fd.close()
m.update(x)
return m.hexdigest()
#PWD=my.pwd()
#my.file_put_contents("c:\\temp\\aaa.txt",PWD);
#debug_print(PWD)
#sys.exit(0)
#此是防止重覆執行
#if os.path.isdir("C:\\temp") == False:
# os.mkdir("C:\\temp")
check_file_run = open(PWD + '\\UCLLIU.lock', "a+")
try:
portalocker.lock(check_file_run, portalocker.LOCK_EX | portalocker.LOCK_NB)
except:
md = gtk.MessageDialog(None,
gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_OK, "【肥米輸入法】已執行...")
md.set_position(gtk.WIN_POS_CENTER)
response = md.run()
if response == gtk.RESPONSE_OK or response == gtk.RESPONSE_DELETE_EVENT:
md.destroy()
ctypes.windll.user32.PostQuitMessage(0)
#atexit.register(cleanup)
#os.killpg(0, signal.SIGKILL)
sys.exit(0)
import ctypes
import pythoncom, pyHook
from pyHook import HookManager
from pyHook.HookManager import HookConstants
import win32clipboard
import pango
import SendKeysCtypes
import time
#http://wiki.alarmchang.com/index.php?title=Python_%E5%AD%98%E5%8F%96_Windows_%E7%9A%84%E5%89%AA%E8%B2%BC%E7%B0%BF_ClipBoard_%E7%AF%84%E4%BE%8B
import win32gui
import win32process
import psutil
#import win32com
import win32con
#import win32com.client
#2023-03-29 判斷作業系統版本
# Issue 177、Win11 裡的 notepad 如果不改字型為 MingLiu 無法正常出字,改成強制複製貼上修正
#debug_print(platform.version());
#sys.exit(0)
import platform
os_version = platform.release()
def isWin11():
# From : https://stackoverflow.com/questions/68899983/get-current-windows-11-release-in-python
# From : https://www.digitalocean.com/community/tutorials/python-system-command-os-subprocess-call
# From : https://stackoverflow.com/questions/68899983/get-current-windows-11-release-in-python 這個可以
#if sys.getwindowsversion().build > 20000:
# 失敗
data = ""
wmic_cmd = "C:\\Windows\\System32\\wbem\\WMIC.exe"
if my.is_file(wmic_cmd) == False:
# windows 11 沙箱,沒有 WMIC 這個指令
# issue 184、windows 沙箱在 1.55 版以後無法使用,發現是沙箱缺少 wmic.exe 指令
version = platform.version()
if 'Windows 7' in version:
return False
elif 'Windows 8' in version:
return False
elif 'Windows 10' in version:
return False
elif 'Windows 8.1' in version:
return False
else:
# python 2.7 platform 讀不到版號!?
return True
try:
data = my.system("%s os get name" % (wmic_cmd));
except e:
debug_print(e)
#debug_print("GGG %s" % (data))
if my.is_string_like(data,"Windows 11"):
return True
else:
return False
if isWin11():
os_version = "11"
#sys.exit()
# 在此可以確定使用者是 win7 win10 win11
# os_version 7 8 10 11
debug_print("os_version: %s" % (os_version))
#debug_print("sys.getwindowsversion().build: %s" % (sys.getwindowsversion().build))
#2023-03-10 在肥米啟動後,將優先性「priority」設為高,避免有些暫用cpu高的程式啟動後,肥米打字會卡
#參考:https://stackoverflow.com/questions/1023038/change-process-priority-in-python-cross-platform
p = psutil.Process(os.getpid())
#print("nice: %s" % (p.nice())) # default 32
#p.nice(psutil.HIGH_PRIORITY_CLASS) # 這樣會變 128
p.nice(256)
#print("nice: %s" % (p.nice()))
#2018-07-13 1.12版增加
#檢查 C:\temp\UCLLIU.ini 初始化設定檔
#取螢幕大小
#2019-03-02 調整,將 UCLLIU.ini 跟隨在 UCLLIU.exe 旁
INI_CONFIG_FILE = 'C:\\temp\\UCLLIU.ini'
if my.is_file(INI_CONFIG_FILE):
my.copy(INI_CONFIG_FILE,PWD+"\\UCLLIU.ini")
my.unlink(INI_CONFIG_FILE)
INI_CONFIG_FILE = PWD + "\\UCLLIU.ini"
#user32 = ctypes.windll.user32
#user32.SetProcessDPIAware()
#screen_width=user32.GetSystemMetrics(0)
#screen_height=user32.GetSystemMetrics(1)
#debug_print("screen width, height : %s , %s" % (screen_width,screen_height))
#window = gtk.Window()
#From : https://www.familylifemag.com/question/701406/how-do-i-get-monitor-resolution-in-python
myScreensObj = gtk.gdk.Screen()
myScreenStatus = {
"main_monitor" : 0, # 面積大的當作 main
"first_time_x": 0, # 系統初始位置,使用下面主螢幕中心點位置移至右下150x150
"first_time_y": 0,
"screens": [
# x,y,w,h,area, c_x,c_y
]
}
debug_print("get_n_monitors(): %d\n" % (myScreensObj.get_n_monitors()));
#print(my.json_encode(myopencc.convert(u"所以我说那个酱汁呢,小当家你是在...")))
#debug_print(myScreensObj.get_monitor_geometry(0)); #gtk.gdk.Rectangle(1280, 0, 2560, 1080)
#debug_print(myScreensObj.get_monitor_geometry(1)); #gtk.gdk.Rectangle(0, 59, 1280, 1024)
for i in range(0,myScreensObj.get_n_monitors()):
d = {
"x": myScreensObj.get_monitor_geometry(i)[0],
"y": myScreensObj.get_monitor_geometry(i)[1],
"w": myScreensObj.get_monitor_geometry(i)[2],
"h": myScreensObj.get_monitor_geometry(i)[3],
"area": (myScreensObj.get_monitor_geometry(i)[2] * myScreensObj.get_monitor_geometry(i)[3]),
"c_x": (myScreensObj.get_monitor_geometry(i)[0] + (myScreensObj.get_monitor_geometry(i)[2] / 2)),
"c_y": (myScreensObj.get_monitor_geometry(i)[1] + (myScreensObj.get_monitor_geometry(i)[3] / 2)),
}
myScreenStatus["screens"].append(d);
if i == 0:
myScreenStatus["main_monitor"] = i;
#調整第一次執行的中心位置
myScreenStatus["first_time_x"] = d["c_x"]+150
myScreenStatus["first_time_y"] = d["c_y"]+150
else:
_is_bigger = True
for j in range(0,len(myScreenStatus["screens"])-1):
if myScreenStatus["screens"][j] > d["area"]:
_is_bigger = False;
break;
if _is_bigger == True:
myScreenStatus["main_monitor"]=i; # 最大螢幕易主
myScreenStatus["first_time_x"] = d["c_x"]+150
myScreenStatus["first_time_y"] = d["c_y"]+150
debug_print(my.json_encode(myScreenStatus));
screen_width = gtk.gdk.screen_width()
screen_height = gtk.gdk.screen_height()
debug_print("screen_width: %d\n" % (screen_width));
debug_print("screen_height: %d\n" % (screen_height));
config = configparser.ConfigParser()
config['DEFAULT'] = {
"X": myScreenStatus["first_time_x"],
"Y": myScreenStatus["first_time_y"],
"ALPHA": "1", #嘸蝦米全顯示時時的初值
"NON_UCL_ALPHA": "0.2", #英數時的透明度
"SHORT_MODE": "0", #0:簡短畫面,或1:長畫面
"ZOOM": "1", #整體比例大小
"SEND_KIND_1_PASTE": "", #出字模式1
"SEND_KIND_2_BIG5": "", #出字模式2
"SEND_KIND_3_NOUCL":"", #Force no UCL
"KEYBOARD_VOLUME": "30", #打字聲音量,0~100
"SP": "0", #短根
"SHOW_PHONE_CODE": "0", #顯示注音讀音
"CTRL_SP": "0", #使用CTRL+SPACE換肥米
"PLAY_SOUND_ENABLE": "0", #打字音
"STARTUP_DEFAULT_UCL": "1", #啟動時,預設為 肥,改為 0 則為 英
"ENABLE_HALF_FULL": "1" #允許切換 全形半形
};
if my.is_file(INI_CONFIG_FILE):
_config = configparser.ConfigParser()
_config.read(INI_CONFIG_FILE, encoding='utf-8')
for k in _config['DEFAULT'].keys(): # ['X','Y','ALPHA','ZOOM','SHORT_MODE','SEND_KIND_1_PASTE','SEND_KIND_2_BIG5']
if k in config['DEFAULT'].keys():
config['DEFAULT'][k]=_config['DEFAULT'][k]
config['DEFAULT']['X'] = str(int(config['DEFAULT']['X']));
config['DEFAULT']['Y'] = str(int(config['DEFAULT']['Y']));
config['DEFAULT']['ALPHA'] = "%.1f" % ( float(config['DEFAULT']['ALPHA'] ));
config['DEFAULT']['NON_UCL_ALPHA'] = "%.1f" % ( float(config['DEFAULT']['NON_UCL_ALPHA'] ));
config['DEFAULT']['SHORT_MODE'] = str(int(config['DEFAULT']['SHORT_MODE']));
config['DEFAULT']['ZOOM'] = "%.2f" % ( float(config['DEFAULT']['ZOOM'] ));
config['DEFAULT']['SEND_KIND_1_PASTE'] = str(config['DEFAULT']['SEND_KIND_1_PASTE']);
config['DEFAULT']['SEND_KIND_2_BIG5'] = str(config['DEFAULT']['SEND_KIND_2_BIG5']);
config['DEFAULT']['KEYBOARD_VOLUME'] = str(int(config['DEFAULT']['KEYBOARD_VOLUME']));
config['DEFAULT']['SP'] = str(int(config['DEFAULT']['SP']));
config['DEFAULT']['SHOW_PHONE_CODE'] = str(int(config['DEFAULT']['SHOW_PHONE_CODE']));
config['DEFAULT']['CTRL_SP'] = str(int(config['DEFAULT']['CTRL_SP']));
config['DEFAULT']['PLAY_SOUND_ENABLE'] = str(int(config['DEFAULT']['PLAY_SOUND_ENABLE']));
config['DEFAULT']['STARTUP_DEFAULT_UCL'] = str(int(config['DEFAULT']['STARTUP_DEFAULT_UCL']));
config['DEFAULT']['ENABLE_HALF_FULL'] = str(int(config['DEFAULT']['ENABLE_HALF_FULL']));
# merge f_arr and f_big5_arr
config['DEFAULT']['SEND_KIND_1_PASTE'] = my.trim(config['DEFAULT']['SEND_KIND_1_PASTE'])
config['DEFAULT']['SEND_KIND_1_PASTE'] = my.str_replace("\"","",config['DEFAULT']['SEND_KIND_1_PASTE'])
config['DEFAULT']['SEND_KIND_2_BIG5'] = my.trim(config['DEFAULT']['SEND_KIND_2_BIG5'])
config['DEFAULT']['SEND_KIND_2_BIG5'] = my.str_replace("\"","",config['DEFAULT']['SEND_KIND_2_BIG5'])
config['DEFAULT']['SEND_KIND_3_NOUCL'] = my.str_replace("\"","",config['DEFAULT']['SEND_KIND_3_NOUCL'])
if config['DEFAULT']['SEND_KIND_1_PASTE'] != "":
f_arr = f_arr + my.explode(",",config['DEFAULT']['SEND_KIND_1_PASTE'])
if config['DEFAULT']['SEND_KIND_2_BIG5'] != "":
f_big5_arr = f_big5_arr + my.explode(",",config['DEFAULT']['SEND_KIND_2_BIG5'])
if config['DEFAULT']['SEND_KIND_3_NOUCL'] != "":
f_pass_app = f_pass_app + my.explode(",",config['DEFAULT']['SEND_KIND_3_NOUCL'])
if int(config['DEFAULT']['KEYBOARD_VOLUME']) < 0:
config['DEFAULT']['KEYBOARD_VOLUME'] = "0"
if int(config['DEFAULT']['KEYBOARD_VOLUME']) > 100:
config['DEFAULT']['KEYBOARD_VOLUME'] = "100"
#debug_print(f_arr)
#debug_print(f_big5_arr)
# array_unique
# 2021-07-22 防止使用者在 f_arr 這些打多的逗號、空白
f_arr = my.array_remove_empty_and_trim(list(set(f_arr)))
f_big5_arr = my.array_remove_empty_and_trim(list(set(f_big5_arr)))
f_pass_app = my.array_remove_empty_and_trim(list(set(f_pass_app)))
#debug_print(f_arr)
#debug_print(f_big5_arr)
if float(config['DEFAULT']['ALPHA'])>=1:
config['DEFAULT']['ALPHA']="1"
if float(config['DEFAULT']['ALPHA'])<=0.1:
config['DEFAULT']['ALPHA']="0.1"
if float(config['DEFAULT']['NON_UCL_ALPHA'])>=1:
config['DEFAULT']['NON_UCL_ALPHA']="1"
if float(config['DEFAULT']['NON_UCL_ALPHA'])<=0:
config['DEFAULT']['NON_UCL_ALPHA']="0"
if int(config['DEFAULT']['SHORT_MODE'])>=1:
config['DEFAULT']['SHORT_MODE']="1"
if int(config['DEFAULT']['SHORT_MODE'])<=0:
config['DEFAULT']['SHORT_MODE']="0"
if float(config['DEFAULT']['ZOOM'])>=3:
config['DEFAULT']['ZOOM']="3"
if float(config['DEFAULT']['ZOOM'])<=0.1:
config['DEFAULT']['ZOOM']="0.1"
if int(config['DEFAULT']['SP'])<=0:
config['DEFAULT']['SP']="0"
else:
config['DEFAULT']['SP']="1"
if int(config['DEFAULT']['SHOW_PHONE_CODE'])<=0:
config['DEFAULT']['SHOW_PHONE_CODE']="0"
else:
config['DEFAULT']['SHOW_PHONE_CODE']="1"
if int(config['DEFAULT']['CTRL_SP'])<=0:
config['DEFAULT']['CTRL_SP']="0"
else:
config['DEFAULT']['CTRL_SP']="1"
if int(config['DEFAULT']['PLAY_SOUND_ENABLE'])<=0:
config['DEFAULT']['PLAY_SOUND_ENABLE']="0"
else:
config['DEFAULT']['PLAY_SOUND_ENABLE']="1"
if int(config['DEFAULT']['STARTUP_DEFAULT_UCL'])<=0:
config['DEFAULT']['STARTUP_DEFAULT_UCL']="0"
else:
config['DEFAULT']['STARTUP_DEFAULT_UCL']="1"
if int(config['DEFAULT']['ENABLE_HALF_FULL'])<=0:
config['DEFAULT']['ENABLE_HALF_FULL']="0"
else:
config['DEFAULT']['ENABLE_HALF_FULL']="1"
# GUI Font
GLOBAL_FONT_FAMILY = "Mingliu,Serif,Malgun Gothic,roman" #roman
GUI_FONT_12 = my.utf8tobig5("%s %d" % (GLOBAL_FONT_FAMILY,int( float(config['DEFAULT']['ZOOM'])*12) ));
GUI_FONT_14 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*14) ));
GUI_FONT_16 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*16) ));
GUI_FONT_18 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*18) ));
GUI_FONT_20 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*20) ));
GUI_FONT_22 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*22) ));
GUI_FONT_26 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*26) ));
# print config setting
debug_print("UCLLIU.ini SETTING:")
debug_print("X:%s" % (config["DEFAULT"]["X"]))
debug_print("Y:%s" % (config["DEFAULT"]["Y"]))
debug_print("ALPHA:%s" % (config["DEFAULT"]["ALPHA"]))
debug_print("NON_UCL_ALPHA:%s" % (config["DEFAULT"]["NON_UCL_ALPHA"]))
debug_print("SHORT_MODE:%s" % (config["DEFAULT"]["SHORT_MODE"]))
debug_print("ZOOM:%s" % (config["DEFAULT"]["ZOOM"]))
debug_print("SEND_KIND_1_PASTE:%s" % (config["DEFAULT"]["SEND_KIND_1_PASTE"]))
debug_print("SEND_KIND_2_BIG5:%s" % (config["DEFAULT"]["SEND_KIND_2_BIG5"]))
debug_print("SP:%s" % (config["DEFAULT"]["SP"]))
debug_print("SHOW_PHONE_CODE:%s" % (config["DEFAULT"]["SHOW_PHONE_CODE"]))
def saveConfig():
global config
global INI_CONFIG_FILE
with open(INI_CONFIG_FILE, 'w') as configfile:
config.write(configfile)
def run_big_small(kind):
global config
global GLOBAL_FONT_FAMILY
global GUI_FONT_12
global GUI_FONT_14
global GUI_FONT_16
global GUI_FONT_18
global GUI_FONT_20
global GUI_FONT_22
global GUI_FONT_26
global simple_btn
global x_btn
global gamemode_btn
global uclen_btn
global hf_btn
global type_label
global word_label
global play_ucl_label
global ucl_find_data
play_ucl_label=""
ucl_find_data=[]
type_label_set_text()
toAlphaOrNonAlpha()
kind = float(kind)
if kind > 0:
if float(config['DEFAULT']['ZOOM']) < 3:
config['DEFAULT']['ZOOM'] = str(float(config['DEFAULT']['ZOOM'])+kind)
else:
if float(config['DEFAULT']['ZOOM']) > 0.3:
config['DEFAULT']['ZOOM'] = str(float(config['DEFAULT']['ZOOM'])+kind)
GUI_FONT_12 = my.utf8tobig5("%s %d" % (GLOBAL_FONT_FAMILY,int( float(config['DEFAULT']['ZOOM'])*12) ));
GUI_FONT_14 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*14) ));
GUI_FONT_16 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*16) ));
GUI_FONT_18 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*18) ));
GUI_FONT_20 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*20) ));
GUI_FONT_22 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*22) ));
GUI_FONT_26 = my.utf8tobig5("%s bold %d" % (GLOBAL_FONT_FAMILY,int(float(config['DEFAULT']['ZOOM'])*26) ));
if is_simple():
simple_btn.set_size_request(0,int( float(config['DEFAULT']['ZOOM'])*40))
simple_label=simple_btn.get_child()
simple_label.modify_font(pango.FontDescription(GUI_FONT_16))
x_label=x_btn.get_child()
x_label.modify_font(pango.FontDescription(GUI_FONT_14))
x_btn.set_size_request(int( float(config['DEFAULT']['ZOOM'])*40),int( float(config['DEFAULT']['ZOOM'])*40))
gamemode_label=gamemode_btn.get_child()
gamemode_label.modify_font(pango.FontDescription(GUI_FONT_12))
gamemode_btn.set_size_request(int( float(config['DEFAULT']['ZOOM'])*80),int( float(config['DEFAULT']['ZOOM'])*40))
uclen_label=uclen_btn.get_child()
uclen_label.modify_font(pango.FontDescription(GUI_FONT_22))
uclen_btn.set_size_request(int(float(config['DEFAULT']['ZOOM'])*40) ,int(float(config['DEFAULT']['ZOOM'])*40 ))
hf_label=hf_btn.get_child()
hf_label.modify_font(pango.FontDescription(GUI_FONT_22))
hf_btn.set_size_request(int( float(config['DEFAULT']['ZOOM'])*40) ,int(float(config['DEFAULT']['ZOOM'])*40) )
type_label.modify_font(pango.FontDescription(GUI_FONT_22))
type_label.set_size_request(int( float(config['DEFAULT']['ZOOM'])*100) ,int( float(config['DEFAULT']['ZOOM'])*40) )
word_label.modify_font(pango.FontDescription(GUI_FONT_20))
word_label.set_size_request(int( float(config['DEFAULT']['ZOOM'])*350),int( float(config['DEFAULT']['ZOOM'])*40))
saveConfig()
def play_sound():
global m_play_song
global max_thread___playMusic_counts
global step_thread___playMusic_counts
#global NOW_VOLUME
global o_song
global PWD
global paudio_player
if paudio_player == None:
paudio_player = pyaudio.PyAudio()
m_play_song.extend( [ random.choice(o_song.keys()) ])
if len(o_song.keys())!=0 and step_thread___playMusic_counts < max_thread___playMusic_counts:
step_thread___playMusic_counts = step_thread___playMusic_counts + 1
NOW_VOLUME = (int(config['DEFAULT']['KEYBOARD_VOLUME'])) #音量
thread.start_new_thread( thread___playMusic,(NOW_VOLUME,))
def run_short():
global config
global word_label
global type_label
global gamemode_btn
global play_ucl_label
global ucl_find_data
play_ucl_label=""
ucl_find_data=[]
type_label_set_text()
toAlphaOrNonAlpha()
word_label.set_visible(False)
type_label.set_visible(False)
gamemode_btn.set_visible(False)
config["DEFAULT"]["SHORT_MODE"]="1"
saveConfig()
def run_long():
global config
global word_label
global type_label
global gamemode_btn
global play_ucl_label
global ucl_find_data
play_ucl_label=""
ucl_find_data=[]
type_label_set_text()
toAlphaOrNonAlpha()
word_label.set_visible(True)
type_label.set_visible(True)
gamemode_btn.set_visible(True)
type_label.set_size_request(int( float(config['DEFAULT']['ZOOM'])*100),int( float(config['DEFAULT']['ZOOM'])*40))
word_label.set_size_request(int( float(config['DEFAULT']['ZOOM'])*385),int( float(config['DEFAULT']['ZOOM'])*40))
config["DEFAULT"]["SHORT_MODE"]="0"
saveConfig()
saveConfig()
#check if exists tab cin json
is_need_trans_tab = False
is_need_trans_cin = False
is_all_fault = False
#my.unlink("liu.json")
#my.unlink("liu.cin")
if my.is_file(PWD + "\\liu.json") == False:
if my.is_file(PWD + "\\liu.cin") == False:
if my.is_file(PWD + "\\liu-uni.tab") == False:
is_all_fault=True
else:
is_need_trans_tab=True
is_need_trans_cin=True
else:
is_need_trans_cin=True
if is_all_fault==True and my.is_file("C:\\windows\\SysWOW64\\liu-uni.tab")==True:
my.copy("C:\\windows\\SysWOW64\\liu-uni.tab",PWD+"\\liu-uni.tab")
is_all_fault=False
is_need_trans_tab=True
is_need_trans_cin=True
if is_all_fault==True and my.is_file("C:\\Program Files\\BoshiamyTIP\\liu-uni.tab")==True:
my.copy("C:\\Program Files\\BoshiamyTIP\\liu-uni.tab",PWD+"\\liu-uni.tab")
is_all_fault=False
is_need_trans_tab=True
is_need_trans_cin=True
# 2019-04-13 加入 小小輸入法臺灣包2018年版wuxiami.txt,http://fygul.blogspot.com/2018/05/yong-tw2018.html 裡linux包中的/tw/wuxiami.txt
if is_all_fault==True and my.is_file(PWD + "\\wuxiami.txt")==True:
debug_print("Run wuxiami.txt ...");
my.copy(PWD+"\\wuxiami.txt",PWD+"\\liu.cin");
data = my.file_get_contents(PWD+"\\liu.cin");
m = my.explode("#修正錯誤:2018-4-15,17",data);
data = my.trim(m[1])
data = my.str_replace("\t"," ",data);
data = my.implode("\n",m);
# 修正 cin 用的表頭
data = '''%gen_inp
%ename liu
%cname 肥米
%encoding UTF-8
%selkey 0123456789
%keyname begin
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z
, ,
. .
' ’
[ 〔
] 〔
%keyname end
%chardef begin
''' + data +"\n%chardef end\n";
my.file_put_contents(PWD+"\\liu.cin",data);
is_need_trans_tab = False;
is_need_trans_cin = True;
is_all_fault = False;
# 2018-06-25 加入 RIME liur_trad.dict.yaml 表格支援
if is_all_fault==True and my.is_file(PWD + "\\liur_trad.dict.yaml")==True:
debug_print("Run Rime liur_trad.dict.yaml ...");
my.copy(PWD+"\\liur_trad.dict.yaml",PWD+"\\liu.cin");
data = my.file_get_contents(PWD+"\\liu.cin");
# 2021-03-21
# 不知道為啥 rime 要把好字的打改成 ~ 開頭@_@?
data = my.str_replace("~","",data);
# 2021-03-21
# 修正 ... 因為字根裡也有 ... 笑死 XD
m = my.explode("#字碼格式: 字 + Tab + 字碼",data);
data = my.trim(m[1])
data = my.str_replace("\t"," ",data);
# swap field
m = my.explode("\n",data);
for i in range(1,len(m)):
d = my.explode(" ",m[i]);
m[i] = "%s %s" % (d[1],d[0]);
data = my.implode("\n",m);
# 修正 cin 用的表頭
data = '''%gen_inp
%ename liu
%cname 肥米
%encoding UTF-8
%selkey 0123456789
%keyname begin
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z
, ,
. .
' ’
[ 〔
] 〔
%keyname end
%chardef begin
''' + data +"\n%chardef end\n";
my.file_put_contents(PWD+"\\liu.cin",data);
is_need_trans_tab = False;
is_need_trans_cin = True;
is_all_fault = False;
# 2018-04-08 加入 terry 表格支援
if is_all_fault==True and my.is_file(PWD + "\\terry_boshiamy.txt")==True:
#將 terry_boshiamy.txt 轉成 正常的 liu.cin、然後轉成 liu.json
debug_print("Run terry ...")
my.copy(PWD+"\\terry_boshiamy.txt",PWD+"\\liu.cin");
data = my.file_get_contents(PWD+"\\liu.cin");
m = my.explode("## 無蝦米-大五碼-常用漢字:",data);
data = my.trim(m[1])
# 修正 cin 用的表頭
data = '''%gen_inp
%ename liu
%cname 肥米
%encoding UTF-8
%selkey 0123456789
%keyname begin
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z
, ,
. .
' ’
[ 〔
] 〔
%keyname end
%chardef begin
''' + data +"\n%chardef end\n";
my.file_put_contents(PWD+"\\liu.cin",data);
is_need_trans_tab = False;
is_need_trans_cin = True;
is_all_fault = False;
# 2018-03-22 加入 fcitx 輸入法支援
if is_all_fault==True and my.is_file(PWD + "\\fcitx_boshiamy.txt")==True:
#將 fcitx_boshiamy.txt 轉成 正常的 liu.cin、然後轉成 liu.json
debug_print("Run fcitx ...")
my.copy(PWD+"\\fcitx_boshiamy.txt",PWD+"\\liu.cin");
data = my.file_get_contents(PWD+"\\liu.cin");
data = my.str_replace("键码=,.'abcdefghijklmnopqrstuvwxyz[]\n","",data);
data = my.str_replace("码长=5\n","",data);
data = my.str_replace("[数据]",'''%gen_inp
%ename liu
%cname 肥米
%encoding UTF-8
%selkey 0123456789
%keyname begin
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z
, ,
. .
' ’
[ 〔
] 〔
%keyname end
%chardef begin
''',data);
#這版的日文很怪,正常的 a, 、 s, 都有怪字,我看全拿掉,用 j開頭的版本
bad_words = [];
res = re.findall('^(?!j)(\w+[,\.]\w*) (.*)\n',data,re.M);
for k in res:
d=" ".join(k);
bad_words.append(d);
#然後修正看不到的奇怪字
#bad_words = ['','','','']
mdata = my.explode("\n",data);
new_mdata = [];
for line in mdata:
if not any(bad_word in line for bad_word in bad_words):
new_mdata.append(line);
data = my.implode("\n",new_mdata);
#然後修正日文 ja, = あ 也相容 a, = あ
res = re.findall('j(\w*[,\.]) (.*)\n',data,re.M);
#debug_print(res)
for k in res:
d=" ".join(k);
data = data + d +"\n";
data = data + "%chardef end";
my.file_put_contents(PWD+"\\liu.cin",data);
is_need_trans_tab = False;
is_need_trans_cin = True;
is_all_fault = False;
if is_all_fault == True:
message = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
message.set_markup("無字根檔,請購買正版嘸蝦米,將「C:\\windows\\SysWOW64\\liu-uni.tab」或「C:\\Program Files\\BoshiamyTIP\\liu-uni.tab」與uclliu.exe放在一起執行")
response = message.run()
#debug_print(gtk.ResponseType.BUTTONS_OK)
if response == -5 or response == -4:
ctypes.windll.user32.PostQuitMessage(0)
#atexit.register(cleanup)
#os.killpg(0, signal.SIGKILL)
my.exit()
#message.show()
gtk.main()
if is_need_trans_tab==True:
#需要轉tab檔
#Check liu-uni.tab md5 is fuck up
if md5_file( ("%s\\liu-uni.tab" % (PWD)) )== "4e89501681ba0405b4c0e03fae740d8c":
message = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
message.set_markup("請不要使用義守大學的字根檔,這組 liu-uni.tab 太舊不支援...");
response = message.run()
#debug_print(gtk.ResponseType.BUTTONS_OK)
if response == -5 or response == -4:
ctypes.windll.user32.PostQuitMessage(0)
#atexit.register(cleanup)
#os.killpg(0, signal.SIGKILL)
my.exit()
#message.show()
gtk.main()
# 2021-08-20 135、https://www.csie.ntu.edu.tw/~b92025/liu/ 裡的 liu-uni.tab 異常,利用 MD5 排除
if md5_file( ("%s\\liu-uni.tab" % (PWD)) )== "41c458e859524613ca5e958f3d809b86":
message = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
message.set_markup("此組字根檔 (b92025) 並非主字根檔 liu-uni.tab,不支援...");
response = message.run()
#debug_print(gtk.ResponseType.BUTTONS_OK)
if response == -5 or response == -4:
ctypes.windll.user32.PostQuitMessage(0)
#atexit.register(cleanup)
#os.killpg(0, signal.SIGKILL)
my.exit()
#message.show()
gtk.main()
if md5_file( ("%s\\liu-uni.tab" % (PWD)) )== "260312958775300438497e366b277cb4":
message = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK)
message.set_markup("此組字根檔並非正常的 liu-uni.tab,這個不支援...");
response = message.run()
#debug_print(gtk.ResponseType.BUTTONS_OK)
if response == -5 or response == -4:
ctypes.windll.user32.PostQuitMessage(0)
#atexit.register(cleanup)
#os.killpg(0, signal.SIGKILL)
my.exit()
#message.show()
gtk.main()
import liu_unitab2cin
#debug_print(PWD)
liu_unitab2cin.convert_liu_unitab( ("%s\\liu-uni.tab" % (PWD)), ("%s\\liu.cin" % (PWD) ))
if is_need_trans_cin==True:
import cintojson
cinapp = cintojson.CinToJson()
cinapp.run( "liu" , "liu.cin",False)
last_key = "" #to save last 7 word for game mode
flag_is_capslock_down=False
flag_is_play_capslock_otherkey=False
flag_is_win_down=False
flag_is_shift_down=False
flag_is_ctrl_down=False
flag_is_alt_down=False
flag_is_play_otherkey=False
flag_shift_down_microtime=0
flag_isCTRLSPACE=False
play_ucl_label=""
ucl_find_data=[]
pinyi_version="0" #初版
uclcode_phone = {} #注音文字儲這 "-3": ["爾","耳","洱","餌","邇","珥","駬","薾","鉺","峏","尒","栮"]
re_uclcode_phone = {} #注音文字儲這 "爾": ["ㄦˇ"]
is_need_use_phone=False
phone_INDEX = ", - . / 0 1 2 3 4 5 6 7 8 9 ; a b c d e f g h i j k l m n o p q r s t u v w x y z"
phone_DATA = "ㄝ ㄦ ㄡ ㄥ ㄢ ㄅ ㄉ ˇ ˋ ㄓ ˊ ˙ ㄚ ㄞ ㄤ ㄇ ㄖ ㄏ ㄎ ㄍ ㄑ ㄕ ㄘ ㄛ ㄨ ㄜ ㄠ ㄩ ㄙ ㄟ ㄣ ㄆ ㄐ ㄋ ㄔ ㄧ ㄒ ㄊ ㄌ ㄗ ㄈ"
phone_INDEX = my.explode(" ",phone_INDEX)
phone_DATA = my.explode(" ",phone_DATA)
same_sound_data=[] #同音字表
same_sound_index=0 #預設第零頁
same_sound_max_word=6 #一頁最多五字
is_has_more_page=False #是否還有下頁
same_sound_last_word="" #lastword
wavs = my.glob(PWD + "\\*.wav")
#debug_print("PWD : %s" % (PWD))
#debug_print(wavs)
o_song = {}
m_play_song = []
max_thread___playMusic_counts = 3 #最多同時五個執行緒在作動
step_thread___playMusic_counts = 0 #目前0個執行緒
for i in range(0,len(wavs)):
#from : https://pythonbasics.org/python-play-sound/
#m_song.extend([ AudioSegment.from_wav(wavs[i]) ])