Commit 160b3afd authored by Martin Schorb's avatar Martin Schorb
Browse files

propagate store to next module

parent b0fb56d4
......@@ -39,16 +39,34 @@ def init_update_store(thismodule,prevmodule,comp_in='store_render_launch',comp_o
def update_store(prevstore,thisstore):
if not dash.callback_context.triggered:
raise PreventUpdate
if None in (prevstore,thisstore):
raise PreventUpdate
# print(thisstore,prevstore)
# for key in thisstore.keys():
# if not (not key in prevstore.keys() or prevstore[key] == '' or prevstore[key] == None):
# thisstore[key] = prevstore[key]
thisstore.update(prevstore)
return thisstore
def subpage_launch(module, subpages):
# subpages can be list of strings or list of dicts (dcc.Dropdown)
if type(subpages) is not list: raise TypeError('subpages need to be list')
c_in = list()
c_out = Output({'component': 'store_render_launch', 'module': module}, 'data')
sbstrings = list()
if type(subpages[0]) is dict:
for item in subpages: sbstrings.append(item['value'])
elif type(subpages[0]) is str:
sbstrings = subpages
for subpage in sbstrings:
sublabel = module + '_' + subpage
c_in.append(Input({'component': 'store_render_launch', 'module': sublabel}, 'data'))
return c_in,c_out
# Update owner dropdown:
......@@ -61,7 +79,7 @@ def update_store(prevstore,thisstore):
State({'component': 'owner_dd', 'module': MATCH},'options')
,prevent_initial_call=True)
def update_owner_dd(init_in,thispage,dd_options_in):
if not dash.callback_context.triggered:
raise PreventUpdate
......@@ -71,7 +89,7 @@ def update_owner_dd(init_in,thispage,dd_options_in):
if thispage in (None,'') or not thispage in hf.trigger(key='module') and not dd_options_in is None:
raise PreventUpdate
dd_options = list(dict())
allowners = params.render_owners
......@@ -83,6 +101,7 @@ def update_owner_dd(init_in,thispage,dd_options_in):
if init_owner == '':
init_owner = allowners[0]
return dd_options, init_owner
......@@ -137,7 +156,7 @@ def update_proj_dd(owner_sel,init_store,newproj_in,thispage,store_proj,dd_option
store = {}
store['allprojects'] = projects
if 'store_init_render' in trigger:
if 'store_init_render' in trigger or init_store['owner'] == owner_sel:
if 'project' in init_store.keys() and init_store['project'] not in (None,''):
out_project=init_store['project']
......
......@@ -8,7 +8,7 @@ Created on Tue Nov 3 13:30:16 2020
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input,Output,State
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
import importlib
......@@ -18,68 +18,63 @@ from app import app
from utils import pages
from utils import helper_functions as hf
# from callbacks import runstate
from callbacks import render_selector
from inputtypes import sbem_conv, serialem_conv
module='convert'
module = 'convert'
inputtypes = [
{'label': 'SBEMImage', 'value': 'SBEM'},
{'label': 'SerialEM Montage', 'value': 'SerialEM'},
]
{'label': 'SBEMImage', 'value': 'SBEM'},
{'label': 'SerialEM Montage', 'value': 'SerialEM'},
]
inputmodules = [
'inputtypes.sbem_conv',
'inputtypes.serialem_conv'
]
main = html.Div(children=[html.H3("Import volume EM datasets - Choose type:",id='conv_head'),dcc.Dropdown(
id={'component': 'import_type_dd', 'module': module},persistence=True,
options=inputtypes
)
])
'inputtypes.sbem_conv',
'inputtypes.serialem_conv'
]
store = dcc.Store(id={'component':'store_render_init','module':module}, storage_type='session',data='')#pages.init_store({}, module)
main = html.Div(children=[html.H3("Import volume EM datasets - Choose type:", id='conv_head'),
dcc.Dropdown(id={'component': 'import_type_dd', 'module': module}, persistence=True,
options=inputtypes, value='...')
])
stores = [dcc.Store(id={'component': 'store_render_init', 'module': module}, storage_type='session',data=''),
dcc.Store(id={'component': 'store_render_launch', 'module': module}, storage_type='session',data='')]
# pages.init_store({}, module)
page = [main,store]
page = [main]
page.extend(stores)
page1 = []
# # =============================================
# # # Page content
page1.append(html.Div([html.Br(),'No data type selected.'],
page1.append(html.Div([html.Br(), 'No data type selected.'],
id='nullpage'))
switch_outputs = [Output('nullpage','style')]
switch_outputs = [Output('nullpage', 'style')]
status_inputs = []
page2 = []
page2=[]
for inputsel,impmod in zip(inputtypes,inputmodules):
for inputsel, impmod in zip(inputtypes, inputmodules):
thismodule = importlib.import_module(impmod)
page1.append(html.Div(getattr(thismodule,'page1'),
id={'component':'page1','module':inputsel['value']},
style = {'display':'none'}))
switch_outputs.append(Output({'component':'page1','module':inputsel['value']},'style'))
page2.append(html.Div(getattr(thismodule,'page2'),
id={'component':'page2','module':inputsel['value']},
style = {'display':'none'}))
switch_outputs.append(Output({'component':'page2','module':inputsel['value']},'style'))
status_inputs.append(Input({'component':'status','module':inputsel['value']},'data'))
page1.append(html.Div(getattr(thismodule, 'page1'),
id={'component': 'page1', 'module': inputsel['value']},
style={'display': 'none'}))
switch_outputs.append(Output({'component': 'page1', 'module': inputsel['value']}, 'style'))
page2.append(html.Div(getattr(thismodule, 'page2'),
id={'component': 'page2', 'module': inputsel['value']},
style={'display': 'none'}))
switch_outputs.append(Output({'component': 'page2', 'module': inputsel['value']}, 'style'))
status_inputs.append(Input({'component': 'status', 'module': inputsel['value']}, 'data'))
switch_outputs.append(Output({'component': 'store_render_init', 'module': module}, 'data'))
......@@ -88,41 +83,43 @@ switch_outputs.append(Output({'component': 'store_render_init', 'module': module
@app.callback(switch_outputs,
Input({'component': 'import_type_dd', 'module': module}, 'value'),
State('url','pathname'))
def convert_output(dd_value,thispage):
State('url', 'pathname'))
def convert_output(dd_value, thispage):
thispage = thispage.lstrip('/')
if thispage=='' or not thispage in hf.trigger(key='module'):
if thispage == '' or not thispage in hf.trigger(key='module'):
raise PreventUpdate
outputs = dash.callback_context.outputs_list
outstyles = [{'display':'none'}]*(len(outputs)-1)
outstyles = [{'display': 'none'}] * (len(outputs) - 1)
modules = [m['id']['module'] for m in outputs[1:]]
for ix, mod in enumerate(modules):
if mod == dd_value:
outstyles[ix+1]={}
if dd_value not in modules:
outstyles[0]={}
if dd_value in (None,''):
dd_value = 'SBEM'
outstore=dict()
outstyles[ix + 1] = {}
if dd_value not in modules:
outstyles[0] = {}
# if dd_value in (None,''):
# dd_value = 'SBEM'
outstore = dict()
outstore['owner'] = dd_value
out=outstyles
out = outstyles
out.append(outstore)
return out
# collect Render selections from sub pages and make them available to following pages
c_in, c_out = render_selector.subpage_launch(module, inputtypes)
@app.callback(c_out,c_in)
def convert_merge_launch_stores(*inputs):
return hf.trigger_value()
page.append(html.Div(page1))
page.append(html.Div(page2))
......@@ -248,9 +248,6 @@ def sbem_conv_gobutton(stack_sel, in_dir, click, proj_dd_sel, compute_sel, run_s
# params.processes[parent.strip('_')] = []
popup = 'Directory not accessible.'
# pop_display = True
out['logfile'] = log_file
out['status'] = run_state['status']
return but_disabled, popup, out, outstore
......
......@@ -187,7 +187,7 @@ im_width = 900
default_tile_scale = 0.5
# controls refresh rate and length of console output
refresh_interval = 1000 # ms
refresh_interval = 3000 # ms
disp_lines = 50 # output lines to display
......
......@@ -51,6 +51,7 @@ us_out,us_in,us_state = render_selector.init_update_store(module,'convert')
@app.callback(us_out,us_in,us_state,
prevent_initial_call=True)
def tilepairs_update_store(*args):
thispage = args[-1]
args = args[:-1]
thispage = thispage.lstrip('/')
......
......@@ -48,6 +48,11 @@ def trigger(key=None,debug=False):
return trigger
def trigger_value():
ctx = dash.callback_context
return ctx.triggered[0]['value']
# def trigger_module():
# ctx = dash.callback_context
......@@ -83,7 +88,6 @@ def input_components():
return incomp, inval
def output_components():
ol = dash.callback_context.outputs_list
......@@ -94,7 +98,6 @@ def output_components():
return outcomp, outprop
def compset_radiobutton(c_options):
outopt = list()
......@@ -104,8 +107,6 @@ def compset_radiobutton(c_options):
return outopt
def tilepair_numfromlog(tilepairdir,stack):
tp_log = params.render_log_dir+'/'+''.join(os.path.basename(tilepairdir).partition(stack+'_')[slice(0,3,2)])+'.log'
......@@ -128,6 +129,7 @@ def tilepair_numfromlog(tilepairdir,stack):
else:
return int(tpairs)
def neighbours_from_json(infiles,target_id):
if type(infiles) is str:
......@@ -161,6 +163,7 @@ def neighbours_from_json(infiles,target_id):
return neighbours,slices,positions
def jsonfiles(dirname):
tp_dir = os.path.join(params.json_run_dir, dirname)
tp_json = os.listdir(tp_dir)
......@@ -173,4 +176,9 @@ def spark_nodes(n_cpu):
nodes_out = nodes + (cores1>0)
return nodes_out
\ No newline at end of file
return nodes_out
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment