Skip to content

Commit

Permalink
Merge pull request #378 from favreau/master
Browse files Browse the repository at this point in the history
Fixed notebooks widgets
  • Loading branch information
favreau authored Jun 24, 2024
2 parents c6fbb22 + 8713cb5 commit 45b2e62
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions bioexplorer/pythonsdk/bioexplorer/notebook_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import seaborn as sns
from stringcase import pascalcase
from PIL import ImageDraw
from .bio_explorer import Vector3
from .bio_explorer import BioExplorer, Vector3

# pylint: disable=unused-argument
# pylint: disable=too-many-locals
Expand Down Expand Up @@ -228,20 +228,22 @@ class Widgets:
"winter_r",
]

SHADING_MODES = [
"none",
"basic",
"diffuse",
"electron",
"cartoon",
"electron_transparency",
"perlin",
"diffuse_transparency",
"checker",
"goodsell",
]

CHAMELEON_MODES = ["none", "emitter", "receiver"]
SHADING_MODES = dict()
SHADING_MODES["none"] = BioExplorer.shading_mode.NONE
SHADING_MODES["basic"] = BioExplorer.shading_mode.BASIC
SHADING_MODES["diffuse"] = BioExplorer.shading_mode.DIFFUSE
SHADING_MODES["electron"] = BioExplorer.shading_mode.ELECTRON
SHADING_MODES["cartoon"] = BioExplorer.shading_mode.CARTOON
SHADING_MODES["electron_transparency"] = BioExplorer.shading_mode.ELECTRON_TRANSPARENCY
SHADING_MODES["perlin"] = BioExplorer.shading_mode.PERLIN
SHADING_MODES["diffuse_transparency"] = BioExplorer.shading_mode.DIFFUSE_TRANSPARENCY
SHADING_MODES["checker"] = BioExplorer.shading_mode.CHECKER
SHADING_MODES["goodsell"] = BioExplorer.shading_mode.GOODSELL

CHAMELEON_MODES = dict()
CHAMELEON_MODES["none"] = BioExplorer.shading_chameleon_mode.NONE
CHAMELEON_MODES["emitter"] = BioExplorer.shading_chameleon_mode.EMITTER
CHAMELEON_MODES["receiver"] = BioExplorer.shading_chameleon_mode.RECEIVER

DEFAULT_GRID_LAYOUT = Layout(border="1px solid black", margin="5px", padding="5px")
DEFAULT_LAYOUT = Layout(width="50%", height="24px", display="flex", flex_flow="row")
Expand Down Expand Up @@ -442,7 +444,7 @@ def set_colormap(model_id, colormap_name, shading_mode):
glossiness=glossiness_slider.value,
user_parameter=user_param_slider.value,
emission=emission_slider.value,
chameleon_mode=chameleon_combobox.index,
chameleon_mode=self.CHAMELEON_MODES[chameleon_combobox.value],
)
self._client.set_renderer(accumulation=True)

Expand All @@ -456,7 +458,7 @@ def set_colormap(model_id, colormap_name, shading_mode):

# Shading modes
shading_combobox = Select(
options=Widgets.SHADING_MODES, description="Shading:", disabled=False
options=self.SHADING_MODES.keys(), description="Shading:", disabled=False
)

# Colors
Expand All @@ -466,7 +468,7 @@ def set_colormap(model_id, colormap_name, shading_mode):

# Chameleon modes
chameleon_combobox = Select(
options=Widgets.CHAMELEON_MODES, description="Chameleon:", disabled=False
options=self.CHAMELEON_MODES.keys(), description="Chameleon:", disabled=False
)

# Events
Expand All @@ -475,23 +477,23 @@ def update_materials_from_palette(value):
set_colormap(
self._client.scene.models[model_combobox.index]["id"],
value["new"],
shading_combobox.index,
self.SHADING_MODES[shading_combobox.value]
)

def update_materials_from_shading_modes(_):
"""Update materials when shading is modified"""
set_colormap(
self._client.scene.models[model_combobox.index]["id"],
palette_combobox.value,
shading_combobox.index,
self.SHADING_MODES[shading_combobox.value]
)

def update_materials_from_chameleon_modes(_):
"""Update materials when chameleon mode is modified"""
set_colormap(
self._client.scene.models[model_combobox.index]["id"],
palette_combobox.value,
shading_combobox.index,
self.SHADING_MODES[shading_combobox.value]
)

shading_combobox.observe(update_materials_from_shading_modes, "value")
Expand Down

0 comments on commit 45b2e62

Please sign in to comment.