Skip to content

Commit

Permalink
Merge pull request #557 from 12rambau/fullscreen
Browse files Browse the repository at this point in the history
fix small fries issues
  • Loading branch information
12rambau authored Jul 25, 2022
2 parents 07f0ce0 + a9cf76c commit 6b9a54b
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 14 deletions.
13 changes: 9 additions & 4 deletions docs/source/_static/switcher.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
[
{
"name": "dev",
"name": "main",
"version": "latest",
"url": "https://sepal-ui.readthedocs.io/en/latest/"
},
{
"name": "2.9.0 (stable)",
"version": "v_2.9.0",
"url": "https://sepal-ui.readthedocs.io/en/v_2.9.0"
"name": "2.10.0 (stable)",
"version": "v_2.10.0",
"url": "https://sepal-ui.readthedocs.io/en/v_2.10.0"
}
{
"name": "2.9.4",
"version": "v_2.9.4",
"url": "https://sepal-ui.readthedocs.io/en/v_2.9.4"
}
]
3 changes: 2 additions & 1 deletion sepal_ui/frontend/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.leaflet-widgetcontrol {box-shadow: none;}
main.v-content {padding-top: 0px !important;}
.leaflet-control-container .vuetify-styles .v-application {background: rgb(0,0,0,0);}
.v-alert__wrapper .progress {background-color: transparent;}
.v-alert__wrapper .progress {background-color: transparent;}
header.v-app-bar {z-index: 800 !important}
6 changes: 2 additions & 4 deletions sepal_ui/mapping/aoi_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ class AoiControl(MenuControl):

def __init__(self, m, **kwargs):

# load the map
self.m = m

# init the aoi data list
self.aoi_bounds = {}

# set some default parameters
kwargs["position"] = kwargs.pop("position", "topright")
kwargs["m"] = m

# create a list
self.aoi_list = sw.ListItemGroup(children=[], v_model="")

# create the widget
super().__init__("fas fa-search-location", self.aoi_list)
super().__init__("fas fa-search-location", self.aoi_list, **kwargs)

# change a bit the behavior of the control
self.menu.open_on_hover = True
Expand Down
30 changes: 28 additions & 2 deletions sepal_ui/mapping/menu_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class MenuControl(WidgetControl):
"""
Widget control displaying a btn on the map. When clicked the menu expand to show the content set by the user.
Widget control displaying a btn on the map. When clicked the menu expand to show the content set by the user and all the others are closed.
It's used to display interactive tiles directly in the map. If the card_content is a Tile it will be automatically nested.
Args:
Expand All @@ -18,7 +18,13 @@ class MenuControl(WidgetControl):
menu = None
"sw.Menu: the menu displayed on the map as a widget"

def __init__(self, icon_content, card_content, card_title=None, **kwargs):
m = None
"sm.SepalMap: the map used to display the control"

def __init__(self, icon_content, card_content, card_title=None, m=None, **kwargs):

# save the map in the members
self.m = m

# create a clickable btn
btn = MapBtn(content=icon_content, v_on="menu.on")
Expand Down Expand Up @@ -68,6 +74,7 @@ def __init__(self, icon_content, card_content, card_title=None, **kwargs):

# add some interaction
self.observe(self.update_position, "position")
self.menu.observe(self.close_others, "v_model")

def update_position(self, change):
"""
Expand Down Expand Up @@ -103,3 +110,22 @@ def set_size(self, **kwargs):
card.max_height = kwargs.pop("max_height", "40vh")

return self

def close_others(self, change):
"""Close all the other menus associated to the map to avoid overlapping"""

# don't do anything if no map was set to avoid deprecation
# remove when jumping to sepal-ui 3.0
if self.m is None:
return

# avoid infinite loop by exiting the method when it's closed
if self.menu.v_model is True:

[
setattr(c.menu, "v_model", False)
for c in self.m.controls
if isinstance(c, MenuControl) and c != self
]

return
4 changes: 1 addition & 3 deletions sepal_ui/mapping/value_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ class ValueInspector(MenuControl):

def __init__(self, m, **kwargs):

# load the map
self.m = m

# set some default parameters
kwargs["position"] = kwargs.pop("position", "topleft")
kwargs["m"] = m

# create a loading to place it on top of the card. It will always be visible
# even when the card is scrolled
Expand Down
3 changes: 3 additions & 0 deletions sepal_ui/sepalwidgets/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def update_progress(self, progress, msg="Progress", **tqdm_args):
self
"""

# show the alert
self.show()

# cast the progress to float
progress = float(progress)
if not (0 <= progress <= 1):
Expand Down
1 change: 1 addition & 0 deletions tests/test_Alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def test_update_progress(self):
# test a random update
alert.update_progress(0.5)
assert alert.progress_bar.n == 50
assert alert.viz is True

# show that a value > 1 raise an error
with pytest.raises(ValueError):
Expand Down
30 changes: 30 additions & 0 deletions tests/test_MenuControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,33 @@ def test_update_position(self):
assert menu_control.menu.right is True

return

def test_close_others(self):

# add controls on the map
m = sm.SepalMap()
control_1 = sm.MenuControl("fas fa-folder", sw.Card(), m=m)
control_2 = sm.MenuControl("fas fa-folder", sw.Card(), m=m)
control_3 = sm.MenuControl("fas fa-folder", sw.Card())
m.add_control(control_1)
m.add_control(control_2)
m.add_control(control_3)

# open the first one and then the second one
control_1.menu.v_model = True
control_2.menu.v_model = True
control_3.menu.v_model = False

# check the values
assert control_1.menu.v_model is False
assert control_2.menu.v_model is True
assert control_3.menu.v_model is False

# use the control that is not wired
control_3.menu.v_model = True

assert control_1.menu.v_model is False
assert control_2.menu.v_model is True
assert control_3.menu.v_model is True

return

0 comments on commit 6b9a54b

Please # to comment.