-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocations.py
69 lines (56 loc) · 2.3 KB
/
locations.py
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
# -*- coding: utf-8 -*-
import ipywidgets as widgets
from widgets import add_location
from utils import utils
from pathlib import Path
import yaml
style = {"description_width": "initial"}
layout = widgets.Layout(grid_template_columns="repeat(4, 25%)")
locations_yaml_path = Path.cwd() / "config" / "locations.yaml"
locations_groups_yaml_path = Path.cwd() / "config" / "location_groups.yaml"
class Locations(widgets.VBox):
def __init__(self):
# Creates the locations group and stores the default locations
utils.initialize_group(locations_yaml_path, group_name="locations")
with open(locations_groups_yaml_path) as finp:
self.group_dict = yaml.safe_load(finp)
self.locations_g_w = [
widgets.Checkbox(description=g) for g in self.group_dict.keys()
]
for group in self.locations_g_w:
group.observe(self.enable_locations_in_group, names="value")
self.locations_widget = widgets.GridBox(
utils.generate_locations(), layout=layout
)
# Adds accordion for adding new location
add_locations = add_location.AddLocation()
add_locations.update_button.on_click(self.update_locations)
acc = widgets.Accordion(
children=[
add_locations,
],
)
acc.set_title(0, "Add a new location")
acc.selected_index = None
self.children = [
widgets.HTML(value="<b>ALL LOCATIONS</b>"),
self.locations_widget,
widgets.HTML(value="<hr><b>GROUPS</b>"),
widgets.GridBox(self.locations_g_w, layout=layout),
widgets.HTML(value="<hr>"),
acc,
]
super().__init__(children=self.children)
def enable_locations_in_group(self, change=None):
value = change["new"]
group_name = change["owner"].description
list_of_locations = set(self.group_dict[group_name])
for location in self.locations_widget.children:
if location.description in list_of_locations:
location.value = value
def update_locations(self, change=None):
self.locations_widget.children = utils.generate_locations()
def fill(self):
return [
x.description for x in self.locations_widget.children if x.value == True
]