Skip to content

Commit

Permalink
refactor files
Browse files Browse the repository at this point in the history
  • Loading branch information
pomme-abricot committed May 27, 2021
1 parent 510729f commit fe2e653
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 251 deletions.
37 changes: 32 additions & 5 deletions src/openalea/strawberry/application/Strawberry Application.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "375bc513299e4bd1861d4d6d1307b795",
"model_id": "8f2ccc39f65e4789b6bbb53251ff3d44",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -170,7 +170,7 @@
"# Navigation (menubar)\n",
"components_map = {\n",
" 'Import MTG': p1.p1_container_main,\n",
" 'Visualization': p2.p2_container_main,\n",
" 'Visualization': p2.container_main,\n",
" 'Plant Scale': p3.p3_container_main,\n",
" 'Module Scale': p4.p4_container_main,\n",
" 'Node Scale': p5.p5_container_main,\n",
Expand Down Expand Up @@ -221,13 +221,40 @@
" navigation\n",
" ]\n",
")\n",
"# container_nav"
"container_nav"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "e884deaf",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "202742710fe54cc3a06b75dc8c6246e5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Container(children=[Container(children=[Tabs(children=[Tab(children=['Import Files']), Tab(children=['Files De…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"container_main"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4b27f75f",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -254,4 +281,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
197 changes: 75 additions & 122 deletions src/openalea/strawberry/application/app_import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@
# # ----------------------------------------------------------------

def print_preview(mtg, genotype="", p_nb=1, width="800px", height="600px"):
with p1_wgt_graphMTG:
p1_wgt_graphMTG.clear_output()
with graphMTG:
graphMTG.clear_output()
vid = get_vid_from_nbplant(misc.all_mtg, genotype, p_nb)
p = oawidgets.mtg.plot(mtg.sub_mtg(vid), scale=p1_wgt_parameters.v_model, height=height, width=width)
p = oawidgets.mtg.plot(mtg.sub_mtg(vid), scale=parameter_scale.v_model, height=height, width=width)
display(p)


def print_files_description():
with p1_wgt_files_description:
p1_wgt_files_description.clear_output()
with files_description:
files_description.clear_output()
# nb of files selected
nb_files = len(p1_wgt_files_selection.v_model)
nb_files = len(files_selection.v_model)

# experiments names:
exp_names = set(misc.all_mtg.property('Experiment_name').values())
Expand Down Expand Up @@ -96,14 +96,14 @@ def on_change_get_files(widget, event, data):
if misc.all_mtg:
df = get_table_mtg(misc.all_mtg)
df_fixed = fix_inferior_character_for_qgrid(df)
p1_wgt_tableMTG.df = df_fixed
tableMTG.df = df_fixed
else:
p1_wgt_tableMTG.df= pd.DataFrame()
tableMTG.df= pd.DataFrame()

# update genotype selection
p1_wgt_genotypes_selection.items=get_genotypes(misc.all_mtg)
p2.p2_wgt_genotype_selection_3D.items=get_genotypes(misc.all_mtg)
p2.p2_wgt_genotype_selection_2D.items=get_genotypes(misc.all_mtg)
genotypes_selection.items=get_genotypes(misc.all_mtg)
p2.genotype_selection_3d.items=get_genotypes(misc.all_mtg)
p2.genotype_selection_2d.items=get_genotypes(misc.all_mtg)
p3.p3_wgt_genotypes_selection_t1.items=get_genotypes(misc.all_mtg)
p3.p3_wgt_genotypes_selection_t2.items=get_genotypes(misc.all_mtg)
p4.p4_wgt_genotypes_selection_t1.items=get_genotypes(misc.all_mtg)
Expand All @@ -117,212 +117,165 @@ def on_change_get_files(widget, event, data):

def on_click_allp(widget, event, data):
if data:
p1_wgt_plants_slider.disabled = True
p1_wgt_plants_nb.disabled = True
slider_n_plant.disabled = True
box_n_plant.disabled = True
else:
p1_wgt_plants_slider.disabled = False
p1_wgt_plants_nb.disabled = False
slider_n_plant.disabled = False
box_n_plant.disabled = False

def on_change_genotype(widget, event, data):
# update plant selection
p1_wgt_plants_slider.disabled=False
p1_wgt_plants_nb.disabled=False
p1_wgt_cb_allplants.disabled=False
p1_wgt_plants_slider.max = len(get_vid_of_genotype(misc.all_mtg, [data]))
p1_wgt_plants_slider.v_model=1
slider_n_plant.disabled=False
box_n_plant.disabled=False
cb_allplants.disabled=False
slider_n_plant.max = len(get_vid_of_genotype(misc.all_mtg, [data]))
slider_n_plant.v_model=1

# update mtg preview
print_preview(misc.all_mtg, genotype=data, p_nb= p1_wgt_plants_slider.v_model ,width="500px", height="800px")
print_preview(misc.all_mtg, genotype=data, p_nb= slider_n_plant.v_model ,width="500px", height="800px")


def on_change_nbplant(widget, event, data):
# update mtg preview
print_preview(misc.all_mtg, genotype=p1_wgt_genotypes_selection.v_model, p_nb= data ,width="500px", height="800px")
print_preview(misc.all_mtg, genotype=genotypes_selection.v_model, p_nb= data ,width="500px", height="800px")

def on_change_parameters(widget, event, data):
# update mtg preview
if misc.all_mtg:
print_preview(misc.all_mtg, genotype=p1_wgt_genotypes_selection.v_model, p_nb= p1_wgt_plants_slider.v_model ,width="1000px", height="1000px")
print_preview(misc.all_mtg, genotype=genotypes_selection.v_model, p_nb= slider_n_plant.v_model ,width="1000px", height="1000px")



# # ----------------------------------------------------------------
# # Widgets
# # ----------------------------------------------------------------

p1_wgt_files_upload = v.FileInput(row=True, wrap=True, align_center=True,
files_upload = v.FileInput(row=True, wrap=True, align_center=True,
chips=True,
multiple=True,
counter=True,
v_model=None,
label="Import Files",
truncate_length=22)

p1_wgt_files_selection = v.Select(v_model=None, items=files,
files_selection = v.Select(v_model=None, items=files,
label="Select Files",
multiple=True, chips=True, counter=True)

p1_wgt_files_selection.on_event('change', on_change_get_files)

p1_wgt_export = v.Btn(children=['Export Analyses'])
export_all = v.Btn(children=['Export Analyses'])

p1_wgt_genotypes_selection = v.Select(items=[],
genotypes_selection = v.Select(items=[],
chips=True,
multiple=False,
counter=True,
v_model="",
label="Select Genotypes",
truncate_length=22)

p1_wgt_parameters = v.Select(items=[{"text":"scale 1",
parameter_scale = v.Select(items=[{"text":"scale 1",
"value":1},
{"text":"scale 2",
"value":2}],
label="Select Parameters",
multiple=False, chips=True,
v_model=2)

p1_wgt_plants_slider = v.Slider(max=100,
slider_n_plant = v.Slider(max=100,
min=1,
label="#p",
thumb_label=True,
v_model="",
disabled=True)

p1_wgt_plants_nb = v.TextField(type_="number",
box_n_plant = v.TextField(type_="number",
class_="mt-0 pt-0",
v_model='',
disabled=True)


p1_wgt_plants_selection=v.Row(children=[v.Col(cols=12, sm=7, md=7,
children=[p1_wgt_plants_slider]),
v.Col(cols=12, sm=1, md=1,
children=[p1_wgt_plants_nb])
plant_selection=v.Row(children=[v.Col(cols=12, sm=7, md=7, children=[slider_n_plant]),
v.Col(cols=12, sm=1, md=1, children=[box_n_plant])
])

p1_wgt_cb_allplants = v.Checkbox(v_model=False,label="Select all plants", disabled=True)

cb_allplants = v.Checkbox(v_model=False,label="Select all plants", disabled=True)


p1_col1 = v.Col(cols=12, sm=3, md=3,
menu_plant = v.Col(cols=12, sm=3, md=3,
children=[
p1_wgt_files_selection,
files_selection,
v.Divider(),
p1_wgt_files_upload,
files_upload,
v.Divider(),
p1_wgt_genotypes_selection,
genotypes_selection,
v.Divider(),
p1_wgt_plants_selection,
plant_selection,
v.Divider(),
p1_wgt_cb_allplants,
cb_allplants,
v.Divider(),
p1_wgt_parameters,
parameter_scale,
v.Divider(),
p1_wgt_export
export_all
])

p1_wgt_tableMTG = qgrid.show_grid(pd.DataFrame(), show_toolbar=False,
grid_options={'forceFitColumns': False, 'editable':True, 'defaultColumnWidth':50})
tableMTG = qgrid.show_grid(pd.DataFrame(), show_toolbar=False, grid_options={'forceFitColumns': False, 'editable':True, 'defaultColumnWidth':50})

p1_panel_table_mtg = v.Container(
# style_='width: 600px; height: 300px',
panel_tableMTG = v.Container(
label="The MTG as a table",
fluid=True,
children=[
p1_wgt_tableMTG
])
children=[tableMTG])

p1_wgt_graphMTG = widgets.Output(layout=layout_output_wgt)
graphMTG=widgets.Output(layout=layout_output_wgt)

p1_panel_graph_mtg = v.Container(
panel_graphMTG = v.Container(
label="The MTG as a graph",
fluid=True,
children=[
p1_wgt_graphMTG
])
children=[graphMTG])


p1_col2 = v.Col(cols=12, sm=8, md=8,
panel_MTG = v.Col(cols=12, sm=8, md=8,
children=[
p1_panel_table_mtg,
panel_tableMTG,
v.Divider(),
p1_panel_graph_mtg,
panel_graphMTG,
])


p1_content1 = v.Row(children=[
p1_col1,
p1_col2,
tab_MTG_content = v.Row(children=[
menu_plant,
panel_MTG,
])

# p1_log_content = v.Textarea(background_color="black",
# dark=True,
# auto_grow=True,
# value= "ICI s'afficheront les messages d'erreurs et les infos sur les imports"
# )

# p1_log = v.Row(children=[
# p1_log_content
# ])

p1_tab1 = v.Row(children=[
v.Col(col=12, sm=11, md=11,
children=[p1_content1,
# p1_log,
])
])



p1_wgt_files_description = widgets.Output(layout=layout_output_wgt)
files_description = widgets.Output(layout=layout_output_wgt)

p1_panel_files_description = v.Container(
panel_files_description = v.Container(
fluid=False,
children=[
p1_wgt_files_description
])
children=[files_description])


p1_tab2 = v.Row(children=[v.Col(cols=12, sm=3, md=3,
children=[p1_wgt_files_selection]),
tab_description_content = v.Row(children=[v.Col(cols=12, sm=3, md=3,
children=[files_selection]),
v.Col(cols=12, sm=7, md=9,
children=[p1_panel_files_description])
children=[panel_files_description])
])


p1 = v.Tabs(
children=[
v.Tab(children=['Import Files']),
v.Tab(children=['Files Description']),
v.TabItem(children=[
p1_tab1
]),
v.TabItem(children=[
p1_tab2
])
])

p1_container_main = v.Container(fluid=True,
class_='grid-list-md box',
children=[
p1
])
container_main = v.Container(fluid=True,
class_='grid-list-md box',
children=[v.Tabs( children=[
v.Tab(children=['Import Files']),
v.Tab(children=['Files Description']),
v.TabItem(children=[tab_MTG_content]),
v.TabItem(children=[tab_description_content])
])
])


# # ----------------------------------------------------------------
# # Link widgets - event
# # ----------------------------------------------------------------

widgets.jslink((p1_wgt_plants_slider,'v_model'), (p1_wgt_plants_nb,'v_model'))

p1_wgt_cb_allplants.on_event('change', on_click_allp)
p1_wgt_genotypes_selection.on_event('change', on_change_genotype)
p1_wgt_plants_slider.on_event('change', on_change_nbplant)
p1_wgt_plants_nb.on_event('change', on_change_nbplant)
p1_wgt_parameters.on_event('change', on_change_parameters)




widgets.jslink((slider_n_plant,'v_model'), (box_n_plant,'v_model'))

files_selection.on_event('change', on_change_get_files)
cb_allplants.on_event('change', on_click_allp)
genotypes_selection.on_event('change', on_change_genotype)
slider_n_plant.on_event('change', on_change_nbplant)
box_n_plant.on_event('change', on_change_nbplant)
parameter_scale.on_event('change', on_change_parameters)
Loading

0 comments on commit fe2e653

Please sign in to comment.