2024-01-26 15:20:30 +00:00
|
|
|
from db import *
|
|
|
|
# Загружаем элементы БД
|
|
|
|
db = read_db()
|
|
|
|
els = list(db.keys())
|
|
|
|
|
|
|
|
|
|
|
|
###### ОФОРМЛЕНИЕ #######
|
|
|
|
|
2024-01-25 21:48:18 +00:00
|
|
|
from dash import Dash, dcc, html, Input, Output,callback
|
2024-01-28 19:50:30 +00:00
|
|
|
app = Dash(__name__, title="SS14 Tools", update_title=None)
|
2024-01-24 09:39:30 +00:00
|
|
|
|
2024-01-28 09:10:17 +00:00
|
|
|
|
|
|
|
# Форматируем список для красоты
|
|
|
|
def list_form(ll):
|
|
|
|
global db
|
|
|
|
|
|
|
|
formatted = []
|
|
|
|
imgs = {'medicine': '💊',
|
2024-01-29 21:03:15 +00:00
|
|
|
'chemicals': '🧪',
|
|
|
|
'botany': '🪴'}
|
2024-01-28 09:10:17 +00:00
|
|
|
|
|
|
|
for i in ll:
|
2024-01-28 22:39:57 +00:00
|
|
|
if type(i) == int:
|
|
|
|
formatted.append(i)
|
|
|
|
elif db[i][1] in imgs:
|
2024-01-28 09:10:17 +00:00
|
|
|
formatted.append(imgs[db[i][1]] + ' ' + i)
|
|
|
|
else:
|
|
|
|
formatted.append(i)
|
|
|
|
|
|
|
|
return formatted
|
|
|
|
|
2024-01-28 22:39:57 +00:00
|
|
|
# 'background-color': 'rgb(27, 29, 30)', 'color': 'rgb(255,255,255)'
|
2024-01-28 09:10:17 +00:00
|
|
|
|
2024-01-25 21:48:18 +00:00
|
|
|
app.layout = html.Div([
|
2024-01-26 15:20:30 +00:00
|
|
|
|
|
|
|
# Название + объём
|
|
|
|
html.Div([
|
|
|
|
# Реакция
|
|
|
|
html.Div([
|
2024-01-28 22:39:57 +00:00
|
|
|
dcc.Dropdown(list_form(els), id='reaction', placeholder="Реакция", maxHeight=500,
|
|
|
|
style={'font-size': '120%'}) #, 'background-color': 'rgb(27, 29, 30)'})
|
2024-01-26 15:20:30 +00:00
|
|
|
], style={'flex': 4}),
|
|
|
|
|
|
|
|
# Объём
|
|
|
|
html.Div([
|
2024-01-28 22:39:57 +00:00
|
|
|
dcc.Dropdown(list_form([30, 50, 100, 300, 1000]), 100, id='amount', clearable=False, searchable=False
|
|
|
|
, style={'font-family': '"Source Sans Pro", sans-serif', 'font-size': '120%'}) #, 'background-color': 'rgb(27, 29, 30)'})
|
|
|
|
], style={'flex': 1, 'padding-left': 25}) #, 'background-color': 'rgb(27, 29, 30)'})
|
2024-01-26 15:20:30 +00:00
|
|
|
|
|
|
|
], style={'display': 'flex', 'flexDirection': 'row'}),
|
|
|
|
|
|
|
|
# Вывод
|
2024-01-26 18:11:43 +00:00
|
|
|
html.Div(id='output', style={'text-align': 'center', 'padding-left': '15%', 'padding-right': '15%'})
|
2024-01-26 15:20:30 +00:00
|
|
|
|
2024-01-26 18:11:43 +00:00
|
|
|
], style={'padding': '5%', 'margin-left': '30%', 'margin-right': '30%'})
|
2024-01-26 15:20:30 +00:00
|
|
|
|
2024-01-28 22:39:57 +00:00
|
|
|
# vh - высота окна, vw - ширина окна
|
|
|
|
#
|
|
|
|
# 'background-color': '#242829',
|
2024-01-26 15:20:30 +00:00
|
|
|
# padding - отступ
|
|
|
|
# [#####]
|
|
|
|
# margin - сужение
|
|
|
|
# [###]
|
|
|
|
#########################
|
|
|
|
|
|
|
|
|
2024-01-24 09:39:30 +00:00
|
|
|
|
2024-01-24 12:20:02 +00:00
|
|
|
|
2024-01-26 15:20:30 +00:00
|
|
|
|
|
|
|
####### ЛОГИКА ##########
|
|
|
|
|
2024-01-27 17:39:01 +00:00
|
|
|
from calc import *
|
|
|
|
|
2024-01-25 21:48:18 +00:00
|
|
|
@callback(
|
2024-01-26 15:20:30 +00:00
|
|
|
Output('output', 'children'),
|
|
|
|
Input('reaction', 'value'),
|
|
|
|
Input('amount', 'value')
|
2024-01-25 21:48:18 +00:00
|
|
|
)
|
2024-01-26 15:20:30 +00:00
|
|
|
def update_output(reaction, amount):
|
|
|
|
if reaction:
|
2024-01-28 09:10:17 +00:00
|
|
|
reaction = reaction[2:]
|
2024-01-27 17:39:01 +00:00
|
|
|
comps, res = calc(reaction, amount, main = True)
|
|
|
|
|
2024-01-26 15:20:30 +00:00
|
|
|
# Форматирование для HTML
|
|
|
|
result = []
|
|
|
|
for i in comps:
|
2024-01-26 18:11:43 +00:00
|
|
|
result.append( html.Div(i + ': ' + str(comps[i])
|
2024-01-28 22:39:57 +00:00
|
|
|
, 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%'}) )
|
2024-01-26 18:11:43 +00:00
|
|
|
|
2024-01-26 15:20:30 +00:00
|
|
|
# Выходное вещество
|
2024-01-27 17:39:01 +00:00
|
|
|
result.append( html.Div(f'{reaction}: {res}'
|
2024-01-28 22:39:57 +00:00
|
|
|
, 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%'}) )
|
2024-01-26 18:11:43 +00:00
|
|
|
|
2024-01-27 17:39:01 +00:00
|
|
|
|
2024-01-26 15:20:30 +00:00
|
|
|
return result
|
|
|
|
|
2024-01-27 17:39:01 +00:00
|
|
|
|
2024-01-26 15:20:30 +00:00
|
|
|
#########################
|
|
|
|
|
2024-01-24 12:20:02 +00:00
|
|
|
|
2024-01-24 09:39:30 +00:00
|
|
|
|
2024-01-25 21:48:18 +00:00
|
|
|
if __name__ == '__main__':
|
2024-01-28 19:44:14 +00:00
|
|
|
# app.run(debug=True)
|
|
|
|
app.run(debug=False)
|