-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappEdit.py
More file actions
220 lines (191 loc) · 6.74 KB
/
appEdit.py
File metadata and controls
220 lines (191 loc) · 6.74 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import dash
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from Tools import unit_function, Buf, Chemical, extract_unit, Col_Buffer, Col_Chem, Data_empty_recipe, Data_empty, Col_recipe, Col
from LayoutEdit import layout
#print(Chem)
Password = "Gilli"
external_stylesheets = [dbc.themes.LUMEN]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.title = "Buffer Update"
app.config.suppress_callback_exceptions = True
app.layout = layout
@app.callback(
[
Output("check_ok", "children"),
Output("table", "editable"),
Output("editing-rows-button", "disabled"),
Output("Button", "disabled"),
Output("NameNewBuffer", "children"),
],
Input("check", "n_clicks"),
State("BufferName", "value")
)
def Buffer_Check(n_clicks, BufferName):
if not n_clicks:
return "", False, True, True, ""
Buffer = Buf.load()
if BufferName in [d.name for d in Buffer]:
return "Buffer already in the library!", False, True, True, ""
elif BufferName == "":
return "Your Buffer needs a name!", False, True, True, ""
else:
return "Buffer not found", True, False, False, BufferName
@app.callback(
Output('table', 'data'),
Input('editing-rows-button', 'n_clicks'),
State('table', 'data'),
State('table', 'columns'))
def add_row(n_clicks, rows, columns):
if n_clicks > 0:
rows.append({c['id']: '' for c in columns})
return rows
@app.callback(
[
Output("table_recipe", "data"),
Output("table_recipe", "columns"),
Output("Recipe_Header", "children"),
Output("Recipe_check", "children"),
Output("Output", "children"),
Output("NameCheck_recipe", "children"),
Output("UseCheck_recipe", "children"),
Output("info_show", "value"),
],
Input("Button", "n_clicks"),
State("table", "data"),
State("NameNewBuffer", "children"),
State("subfolder", "value"),
State("info_in","value"),
)
def control(n_clicks, data, NameNewBuffer, subfolder, info_in):
global Col_recipe
if not n_clicks:
return [], Col_recipe, "", "", "", "", "", ""
if n_clicks > 0:
EmptyField = "No"
for i in data:
if i["name"] == "" or i["amount"] == "" or i['unit'] == "" or i['mass'] == "" or i['aggregation'] == "" or i['density'] == "" or subfolder == "":
EmptyField = "Yes"
if EmptyField == "Yes":
return [], Col_recipe, "", "", "Please fill in all empty fields", "", "", ""
if EmptyField == "No":
return data, Col_recipe, "Recipe", "Please check if the Recipe is correct!", "Successful", f"Name: {NameNewBuffer}", f"Usage: {subfolder} Buffer", info_in
@app.callback(
Output("success","children"),
Input("confirm", "n_clicks"),
State("table_recipe", "data"),
State("subfolder", "value"),
State("NameNewBuffer", "children"),
State("password_1", "value"),
State("info_show", "value"),
)
def data(n_clicks, data, subfolder, NameNewBuffer, password, info):
global Password
ListNewIngredients = []
ListNewMolarity = []
ListNewUnit = []
Buffer = Buf.load()
Chem = Chemical.load()
if not n_clicks:
return ""
if n_clicks > 0:
if password == Password:
if NameNewBuffer in [d.name for d in Buffer]:
return "Buffer already added"
for i, j in enumerate(data):
Amount, unit_data = extract_unit(data[i]["unit"], data[i]["amount"])
ListNewIngredients.append(data[i]["name"])
ListNewMolarity.append(float(Amount))
ListNewUnit.append(unit_data)
if not data[i]["name"] in [d.name for d in Chem]:
data[i]["name"] = Chemical(data[i]["name"],data[i]["mass"], data[i]["aggregation"], data[i]["density"])
Chem.append(data[i]["name"])
NameNewBuffer = Buf(NameNewBuffer, subfolder, ListNewIngredients, ListNewMolarity, ListNewUnit, info)
Buffer.append(NameNewBuffer)
Buf.save(Buffer)
Chemical.save(Chem)
return "Buffer Added!"
else:
return html.H2(style={"color":"red"}, id="success", children = "Wrong Password")
@app.callback(
Output("confirm", "disabled"),
Input("swear", "value"),
State("Button", "n_clicks")
)
def swear_switch(swear, n_clicks):
if not n_clicks:
return True
if swear == "yes":
return False
if swear == "no":
return True
@app.callback(
[
Output("table_edit", "data"),
Output("table_edit", "columns"),
],
Input("show_list", "n_clicks"),
State("show_buf_chem", "value"),
)
def show_content(n_clicks, chose):
global Col_Buffer, Col_Chem
if not n_clicks:
return [], Col_Buffer
if chose == "":
return [], Col_Buffer
if chose == "buffer":
Buffer = Buf.load()
Buffer = Buf.list_to_dic(Buffer)
return Buffer, Col_Buffer
if chose == "chem":
Chem = Chemical.load()
Chem = Chemical.list_to_dic(Chem)
return Chem, Col_Chem
@app.callback(
Output("confirm_2", "disabled"),
Input("swear_2", "value"),
State("show_list", "n_clicks")
)
def switch_delete(swear, n_clicks):
if not n_clicks:
return True
if swear == "yes":
return False
if swear == "no":
return True
@app.callback(
Output("saved_2", "children"),
Input("confirm_2", "n_clicks"),
State("table_edit", "data"),
State("table_edit", "columns"),
State("password_2", "value"),
)
def save_changes(n_clicks, data, columns, password):
global Col_Buffer, Col_Chem, Password
if not n_clicks:
return ""
if password == Password:
if columns == Col_Chem:
data = Chemical.dic_to_list(data)
Chemical.save(data)
if columns == Col_Buffer:
new_data = []
for buffer in data:
_buffer = {}
for k, v in buffer.items():
if k in ["ingredients", "molarity", "unit"]:
if isinstance(v, str):
_buffer[k] = v.split(", ")
else:
_buffer[k] = v
else:
_buffer[k] = v
new_data.append(_buffer)
new_data = Buf.dic_to_list(new_data)
Buf.save(new_data)
return "Update successful"
else:
return html.H2(style={"color":"red"}, id="save_2", children = "Wrong Password")
if __name__ == '__main__':
app.run_server(debug=True)