-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusefull.py
More file actions
78 lines (65 loc) · 2.19 KB
/
usefull.py
File metadata and controls
78 lines (65 loc) · 2.19 KB
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
from unicodedata import east_asian_width
import colorama
from colorama import Fore
from colorama import Style
colorama.init()
def printWarning(warningMessage):
print(Fore.YELLOW + Style.BRIGHT + '\n[Warning] ' + Style.RESET_ALL + warningMessage)
def bindAllChildren(widget, sequence, func):
widget.bind(sequence, func)
for child in widget.winfo_children():
bindAllChildren(child, sequence, func)
def getEastAsianWidthCount(eastAsianText):
'''
文字列の長さを測る
len()と違い全角文字は2文字としてカウントされる
Parameters
----------
eastAsianText : str
長さを測る文字列
Returns
-------
count : int
文字列の長さ
'''
count = 0
for char in eastAsianText:
if east_asian_width(char) in 'FWA':
count += 2
else:
count += 1
return count
def cloneWidget(widget, master=None):
"""
Create a cloned version o a widget
Parameters
----------
widget : tkinter widget
tkinter widget that shall be cloned.
master : tkinter widget, optional
Master widget onto which cloned widget shall be placed. If None, same master of input widget will be used. The
default is None.
Returns
-------
cloned : tkinter widget
Clone of input widget onto master widget.
"""
# Get main info
parent = master if master else widget.master
cls = widget.__class__
# Clone the widget configuration
cfg = {key: widget.cget(key) for key in widget.configure()}
cloned = cls(parent, **cfg)
# Clone the widget's children
for child in widget.winfo_children():
child_cloned = cloneWidget(child, master=cloned)
if child.grid_info():
grid_info = {k: v for k, v in child.grid_info().items() if k not in {'in'}}
child_cloned.grid(**grid_info)
elif child.place_info():
place_info = {k: v for k, v in child.place_info().items() if k not in {'in'}}
child_cloned.place(**place_info)
else:
pack_info = {k: v for k, v in child.pack_info().items() if k not in {'in'}}
child_cloned.pack(**pack_info)
return cloned