-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.py
166 lines (126 loc) · 4.01 KB
/
site.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
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
from db import *
# Загружаем элементы БД
db = read_db()
els = list(db.keys())
## Сайт
from dash import Dash, dcc, html, Input, Output,callback
app = Dash(__name__, title="SS14 Tools", update_title=None)
#### ФОРМАТ СТРАНИЦЫ ####
app.index_string = '''
<!DOCTYPE html>
<html>
<head>
{%metas%}
<title>{%title%}</title>
{%favicon%}
{%css%}
</head>
<body>
<div class="panel">
<div class=img_text_panel>
<img height="auto" src="assets/favicon.ico" class="logo">
<div style="color: rgb(255, 255, 255); font-weight: bold; font-size: 2vh;">SS14 Tools</div>
</div>
<div class=soc_buttons>
<a href="https://discord.gg/VxHbM3cedQ" target="_blank" class="socials">
<img src="assets/discord.svg" class="soc_logo">
<p class="soc_text">Discord</p>
</a>
<a href="https://github.com/Justuser3310/ss14_chemistry_site" target="_blank">
<img src="assets/github-mark-white.svg" class="git_logo">
</a>
<a href="https://t.me/ss14tools" target="_blank" class="socials">
<img src="assets/telegram.svg" class="soc_logo">
<p class="soc_text">Telegram</p>
</a>
</div>
<div class="empty_box"></div>
</div>
{%app_entry%}
<footer>
{%config%}
{%scripts%}
{%renderer%}
</footer>
</body>
</html>
'''
###### ОФОРМЛЕНИЕ #######
# Форматируем список для красоты
def list_form(ll):
global db
formatted = []
imgs = {'medicine': '💊',
'chemicals': '🧪',
'botany': '🪴',
'drinks': '🍸'}
for i in ll:
if type(i) == int:
formatted.append(i)
elif db[i][1] in imgs:
formatted.append(imgs[db[i][1]] + ' ' + i)
else:
formatted.append(i)
return formatted
# Типо контейнер для всего
# [
# Div,
# Div
# ]
app.layout = html.Div([
# Название + объём + вывод
html.Div([
# Название + объём
html.Div([
# Реакция
html.Div([
dcc.Dropdown(list_form(els), id='reaction', placeholder="Реакция", maxHeight=500,
style={'font-size': '120%', 'font-family': 'NotaSans'})
], style={'flex': 4, 'min-width': '200px'}),
# Объём
html.Div([
dcc.Dropdown(list_form([30, 50, 100, 300, 1000]), 100, id='amount', clearable=False, searchable=False
, style={'font-family': '"Mulish", sans-serif', 'font-size': '120%'})
], className="vol")
], className="react_vol"),
# Вывод
html.Div(id='output', style={'text-align': 'center', 'padding-left': '15%', 'padding-right': '15%'})
], className="react_vol_out")
#], style={'padding': '5%', 'margin-left': '25vw', 'margin-right': '25vw'})
], style={'justify-content': 'center', 'display': 'flex'})
# vh - высота окна, vw - ширина окна
#
# 'background-color': '#242829',
# padding - отступ
# [#####]
# margin - сужение
# [###]
#########################
####### ЛОГИКА ##########
from calc import *
@callback(
Output('output', 'children'),
Input('reaction', 'value'),
Input('amount', 'value')
)
def update_output(reaction, amount):
if reaction:
reaction = reaction[2:]
comps, res = calc(reaction, amount, main = True)
# Форматирование для HTML
result = []
for i in comps:
if i[0] == 'heat':
result.append( html.Div('Нагреть!'
, style={'background-color': 'rgb(115, 62, 157)', 'color': '#ffffff', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
else:
result.append( html.Div(i[0] + ': ' + str(i[1])
, style={'background-color': 'rgb(213, 193, 86)', 'color': '#ffffff', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
# Выходное вещество
result.append( html.Div(f'{reaction}: {res}'
, style={'background-color': 'rgb(61, 164, 113)', 'color': '#ffffff', 'margin-top': 10, 'border-radius': 10, 'padding': 15, 'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) )
return result
#########################
if __name__ == '__main__':
# app.run(debug=True)
app.run(debug=False, port = 9000)