diff --git a/ui_programm_fragmente/input_to_checklist.py b/ui_programm_fragmente/input_to_checklist.py new file mode 100644 index 0000000000000000000000000000000000000000..0f0ec61cd9177bc77564fd1d636f8d9fe8741dbf --- /dev/null +++ b/ui_programm_fragmente/input_to_checklist.py @@ -0,0 +1,63 @@ +import dash +from dash import dcc +from dash import html +from dash import callback_context +from dash.dependencies import Input, Output, State +from dash.exceptions import PreventUpdate + +app = dash.Dash(__name__) + +list_of_inputs = dict() + +app.layout = html.Div([ + html.H4("Progressively add input strings to a list"), + html.Div([ + html.Button(id='show-info',children='Show Info',n_clicks=0), + html.Div(id='info-box') + ]), + html.Div([ + "Input: ", + dcc.Input(id='my-input', value='', type='text',debounce=True), + dcc.Checklist(id='list-of-inputs',labelStyle = dict(display='block')), + html.Button(id='clear-all-button',children='Clear All'), + html.Button(id='clear-selected-button',children='Clear Selected') + ]), +]) +@app.callback( + Output('list-of-inputs','options'), + Output('my-input','value'), + Input('my-input','value'), + Input('clear-all-button','n_clicks'), + Input('clear-selected-button','n_clicks'), + State('list-of-inputs','value') +) +def update_input_list(input_value,btn1,btn2,all_inputs): + changed_id = [p['prop_id'] for p in callback_context.triggered][0] + if 'clear-all-button' in changed_id: + list_of_inputs.clear() + return list(),'' + if 'clear-selected-button' in changed_id: + for key in range(len(all_inputs)): + if all_inputs[key]: + del list_of_inputs[all_inputs[key]] + return [{'label': i, 'value': i} for i in list_of_inputs], '' + if input_value == '': + return list(),'' + if input_value not in list_of_inputs: + list_of_inputs[input_value] = input_value + return [{'label': i, 'value': i} for i in list_of_inputs], '' + +@app.callback( + Output('info-box','children'), + Input('show-info','n_clicks') +) +def show_hide_info_box(n_clicks): + if n_clicks % 2 == 0: + return '' + else: + return "Hier koennte Ihre Werbung stehen" + + + +if __name__ == '__main__': + app.run_server(debug=True) diff --git a/ui_programm_fragmente/upload_to_checklist.py b/ui_programm_fragmente/upload_to_checklist.py new file mode 100644 index 0000000000000000000000000000000000000000..dba9f698c47250b58ceb006095b763b437cee640 --- /dev/null +++ b/ui_programm_fragmente/upload_to_checklist.py @@ -0,0 +1,51 @@ +import dash +from dash import dcc +from dash import html +from dash.dependencies import Input, Output + +app = dash.Dash(__name__) + +list_of_inputs = dict() + +app.layout = html.Div([ + html.H4("Add all lines in a file to a list"), + html.Div([ + dcc.Upload( + id="upload-data", + children=html.Div( + ["Drag and drop or click to select a file to upload."] + ), + style={ + "width": "30%", + "height": "60px", + "lineHeight": "60px", + "borderWidth": "1px", + "borderStyle": "dashed", + "borderRadius": "5px", + "textAlign": "center", + "margin": "10px", + }), + dcc.Checklist(id='list-of-inputs',labelStyle = dict(display='block')) + ]), +]) + +@app.callback( + Output('list-of-inputs','options'), + Input('upload-data','filenames'), + Input('upload-data','contents') +) +def update_input_list(uploaded_filenames,uploaded_file_contents): + for line in uploaded_file_contents: + line = line.rstrip() + list_of_inputs[line] = line + try: + stream = open(uploaded_filenames,'r') # this statement may throw an exception + except IOError as err: # exception stores error message in err + # now comes the code reacting on the exception + sys.stderr.write('{}: {}\n'.format(sys.argv[0], err)) + exit(1) + return [{'label': i, 'value': i} for i in list_of_inputs], '' + +if __name__ == '__main__': + app.run_server(debug=True) +