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:44:14 +00:00
app = Dash ( __name__ , title = " SS14 Tools " )
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 ' : ' 💊 ' ,
' chemicals ' : ' 🧪 ' }
for i in ll :
2024-01-28 19:44:14 +00:00
#print(db[i][1])
2024-01-28 09:10:17 +00:00
if db [ i ] [ 1 ] in imgs :
formatted . append ( imgs [ db [ i ] [ 1 ] ] + ' ' + i )
else :
formatted . append ( i )
return formatted
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 09:10:17 +00:00
dcc . Dropdown ( list_form ( els ) , id = ' reaction ' , placeholder = " Реакция " , maxHeight = 500 , style = { ' font-size ' : ' 120 % ' } )
2024-01-26 15:20:30 +00:00
] , style = { ' flex ' : 4 } ) ,
# Объём
html . Div ( [
2024-01-26 18:11:43 +00:00
dcc . Dropdown ( [ 30 , 50 , 100 , 300 , 1000 ] , 100 , id = ' amount ' , clearable = False , searchable = False
, style = { ' font-family ' : ' " Source Sans Pro " , sans-serif ' , ' font-size ' : ' 120 % ' } )
2024-01-26 15:20:30 +00:00
] , style = { ' flex ' : 1 , ' padding-left ' : 25 } )
] , 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
# 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 ] )
, style = { ' background-color ' : ' #3f3b17 ' , ' margin-top ' : 10 , ' border-radius ' : 10 , ' padding ' : 15 , ' font-family ' : ' " Source Sans Pro " , sans-serif ' , ' font-size ' : ' 120 % ' } ) )
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-26 18:11:43 +00:00
, style = { ' background-color ' : ' #183929 ' , ' margin-top ' : 10 , ' border-radius ' : 10 , ' padding ' : 15 , ' font-family ' : ' " Source Sans Pro " , sans-serif ' , ' font-size ' : ' 120 % ' } ) )
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 )