-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicode_table.py
83 lines (74 loc) · 1.94 KB
/
unicode_table.py
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
import dash
from dash import dcc, html, Input, Output, State
from htexpr import compile
import unicodedata
app = dash.Dash(__name__, external_stylesheets=['https://codepen.io/jkseppan/pen/qwBNGp.css'])
app.layout = compile("""
<div>
<h1>Unicode table</h1>
<div id="inputs">
<label for="from">From</label>
<Input id="from" value="128500" type="number" />
<label for="to">to</label>
<Input id="to" value="129000" type="number" />
<label for="step">by steps of</label>
<Input id="step" value="3" type="number" />
</div>
<table>
<thead>
<tr>
<th rowspan="2">Char</th>
<th >Number</th>
<th rowspan="2">Name</th>
<th rowspan="2">Category</th>
<th rowspan="2">Bidirectional</th>
</tr>
<tr>
<th class="rt">(Hexadecimal)</th>
</tr>
</thead>
<tbody id="body">
</tbody>
</table>
</div>
""").run()
row1 = compile("""
<tr>
<td rowspan="2">{ chr(i) }</td>
<td>{ i }</td>
<td rowspan="2">{ unicodedata.name(chr(i), '???') }</td>
<td rowspan="2">{ unicodedata.category(chr(i)) }</td>
<td rowspan="2">{ unicodedata.bidirectional(chr(i)) }</td>
</tr>
""")
row2 = compile("""
<tr>
<td class="rt fw">U+{ f'{i:04x}' }</td>
</tr>
""")
def parseint(x):
try:
return max(0, int(x))
except ValueError:
return 0
@app.callback(
Output("body", "children"),
[Input("from", "value"), Input("to", "value"), Input("step", "value")]
)
def update_table(from_, to, step):
from_ = parseint(from_)
to = parseint(to)
step = max(1, parseint(step))
return [row
for pair in [(row1.run(), row2.run()) for i in range(from_, to+1, step)]
for row in pair]
@app.callback(
Output("to", "value"),
[Input("from", "value")],
[State("to", "value")]
)
def update_to(from_, to):
return max(parseint(from_), int(to))
# Run the server
if __name__ == '__main__':
app.run_server(debug=True)