Skip to content

Commit

Permalink
Merge pull request #7 from gammaboard/tabs
Browse files Browse the repository at this point in the history
Tabs
  • Loading branch information
mikael10j authored Jan 8, 2019
2 parents 21ce6cd + 99d56fe commit 5f611a6
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions gammaboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import pandas as pd
from ipywidgets import HBox
from ipywidgets import HBox, Tab, Output


def load_data(experiment, experiments_directory):
Expand Down Expand Up @@ -427,7 +427,7 @@ def update_legend(visible_experiments, ax_imp_res):
ax_imp_res.legend(handles=legend_elements, loc='best', bbox_to_anchor=(1, -0.3), ncol=4)


def create_plot_on_click(experiments_dict, experiment_info_box,
def create_plot_on_click(experiments_dict, experiment_info_box, tabs,
fig_resolution, visible_experiments, ax_imp_res):

def plot_on_click(sender):
Expand All @@ -448,20 +448,26 @@ def plot_on_click(sender):
visible = True
if not exp.get_loaded():
exp.load_data()
if exp_name not in tabs.keys():
tabs[exp_name] = Output()

experiment_info_box.clear_output()
with experiment_info_box:
experiment_info_box.children = [value for _, value in tabs.items()]
for i, key, in enumerate(tabs.keys()):
experiment_info_box.set_title(i, key)
if key == exp_name:
experiment_info_box.selected_index = i

with tabs[exp_name]:
try:
# exp_info = experiments_info[experiments_info.experiment == exp_name]
# for col in exp_info:
# print(col, exp_info[col].values)
print_dict(exp.info)
except:
print("Sorry, I have no info on the experiment {}".format(exp_name))
visible_experiments.add(exp)
else:
sender.button_style = 'warning'
visible = False
tabs[exp_name].close()
tabs.pop(exp_name)
visible_experiments.remove(exp)

if not exp.get_plotted() and visible:
Expand All @@ -473,13 +479,18 @@ def plot_on_click(sender):
return plot_on_click


def make_experiments_carousel(experiments_dic, experiment_info_box, fig_resolution,
def make_experiments_carousel(experiments_dic, experiment_info_box, tabs, fig_resolution,
visible_experiments, ax_imp_res):
"""
Make an ipywidget carousel holding a series of `ipywidget.Button` corresponding to
the list of experiments in experiments_dic
Args
experiments_dic (dict): dictionary of experiment class
experiment_info_box (Tab): the tab container
tabs (dict): dictionary of active tabs
fig_resolution
visible_experiments
ax_imp_res
Returns
`ipywidgets.VBox()`
Expand All @@ -491,28 +502,19 @@ def make_experiments_carousel(experiments_dic, experiment_info_box, fig_resoluti
for exp_name in np.sort(list(experiments_dic))[::-1]]

for b in items:
b.on_click(create_plot_on_click(experiments_dic, experiment_info_box,
b.on_click(create_plot_on_click(experiments_dic, experiment_info_box, tabs,
fig_resolution, visible_experiments, ax_imp_res))

box_layout = Layout(overflow_y='scroll',
border='3px solid black',
width='300px',
height='300px',
height='600px',
flex_flow='columns',
display='flex')

return VBox(children=items, layout=box_layout)


def make_exp_info_box():
from ipywidgets import Layout, Output
layout = Layout(border='1px solid black')

out = Output(layout=layout, description="Experiment info")

return out


class GammaBoard(object):

def __init__(self, experiments_directory):
Expand All @@ -536,16 +538,10 @@ def __init__(self, experiments_directory):

visible_experiments = set()

# try:
# experiments_info = pd.read_csv(experiments_directory + '/experiments.csv')
# except:
# experiments_info = None
# print("The file 'experiments.csv' cannot be found in the experiments directory")
experiment_info_box = Tab()
tabs = {}

experiment_info_box = make_exp_info_box()
# carousel = make_experiments_carousel(self.experiments_dict, experiment_info_box,
# experiments_info, fig_resolution, visible_experiments, ax_imp_res)
carousel = make_experiments_carousel(self.experiments_dict, experiment_info_box,
carousel = make_experiments_carousel(self.experiments_dict, experiment_info_box, tabs,
fig_resolution, visible_experiments, ax_imp_res)

self.exp_box = HBox([carousel, experiment_info_box])
Expand Down

0 comments on commit 5f611a6

Please sign in to comment.