Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
#379 slider with dict labels
Browse files Browse the repository at this point in the history
  • Loading branch information
FredLL-Avaiga committed Aug 26, 2022
1 parent 45795da commit f56752c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/taipy/gui/renderers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,8 @@ def set_labels(self, var_name: str = "labels"):
if value := self.__attributes.get(var_name):
if _is_boolean_true(value):
return self.__set_react_attribute(_to_camel_case(var_name), True)
return self.__set_dict_attribute(var_name)
elif isinstance(value, (dict, _MapDict)):
return self.__set_dict_attribute(var_name)
return self

def set_partial(self):
Expand Down
2 changes: 1 addition & 1 deletion src/taipy/gui/utils/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def _is_boolean_true(s: t.Union[bool, str]) -> bool:
return s if isinstance(s, bool) else s.lower() in ["true", "1", "t", "y", "yes", "yeah", "sure"]
return s if isinstance(s, bool) else s.lower() in ["true", "1", "t", "y", "yes", "yeah", "sure"] if isinstance(s, str) else False


def _is_boolean(s: t.Any) -> bool:
Expand Down
17 changes: 17 additions & 0 deletions tests/taipy/gui/control/test_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import inspect
from taipy.gui import Gui


Expand All @@ -31,6 +32,22 @@ def test_slider_with_min_max(gui: Gui, test_client, helpers):
helpers.test_control_md(gui, md_string, expected_list)


def test_slider_with_dict_labels_md(gui: Gui, helpers):
sel = "Item 1"
labels = {"Item 1": "Label Start", "Item 3": "Label End"}
gui._set_frame(inspect.currentframe())
md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels={labels}|>"
expected_list = ["<Slider", 'labels="{&quot;Item 1&quot;: &quot;Label Start&quot;, &quot;Item 3&quot;: &quot;Label End&quot;}"']
helpers.test_control_md(gui, md_string, expected_list)

def test_slider_with_boolean_labels_md(gui: Gui, helpers):
sel = "Item 1"
gui._set_frame(inspect.currentframe())
md_string = "<|{sel}|slider|lov=Item 1;Item 2;Item 3|labels|>"
expected_list = ["<Slider", "labels={true}"]
helpers.test_control_md(gui, md_string, expected_list)


def test_slider_items_md(gui: Gui, test_client, helpers):
gui._bind_var_val("x", "Item 1")
md_string = "<|{x}|slider|lov=Item 1;Item 2;Item 3|text_anchor=left|>"
Expand Down

0 comments on commit f56752c

Please sign in to comment.