# """ # slider Layout # """ # # Needed for the fall-back radio layout # from potato.ai.ai_help_wrapper import get_ai_wrapper, get_dynamic_ai_help # from .radio import generate_radio_layout # from .identifier_utils import ( # safe_generate_layout, # generate_element_identifier, # escape_html_content # ) # def test_and_get(key, d): # val = d[key] # try: # return int(val) # except: # raise Exception( # 'Slider scale %s\'s value for "%s" is not an int' % (d["name"], key) # ) # def generate_slider_layout(annotation_scheme): # """ # Generate HTML for a slider input interface. # Args: # annotation_scheme (dict): Configuration including: # - name: Schema identifier # - description: Display description # - starting_value: Initial slider value # - min_value: Minimum allowed value # - max_value: Maximum allowed value # - show_labels: Whether to show min/max labels # - labels: If present, fall back to radio layout # Returns: # tuple: (html_string, key_bindings) # html_string: Complete HTML for the slider interface # key_bindings: Empty list (no keyboard shortcuts) # """ # return safe_generate_layout(annotation_scheme, generate_slider_layout_internal) # def generate_slider_layout_internal(annotation_scheme): # from .identifier_utils import escape_html_content, generate_element_identifier # if "labels" in annotation_scheme: # return generate_radio_layout(annotation_scheme, horizontal=False) # for required in ["starting_value", "min_value", "max_value"]: # if required not in annotation_scheme: # raise Exception( # f'Slider scale for "{annotation_scheme["name"]}" did not include {required}' # ) # min_value = test_and_get("min_value", annotation_scheme) # max_value = test_and_get("max_value", annotation_scheme) # starting_value = test_and_get("starting_value", annotation_scheme) # if min_value >= max_value: # raise Exception( # f'Slider scale for "{annotation_scheme["name"]}" must have minimum value < max value ({min_value} >= {max_value})' # ) # show_labels = annotation_scheme.get("show_labels", True) # min_label = str(min_value) if show_labels else '' # max_label = str(max_value) if show_labels else '' # identifiers = generate_element_identifier(annotation_scheme["name"], "slider", "range") # # Get step from annotation_scheme or default to 5 # step_value = annotation_scheme.get("step", 1) # print(step_value) # max_tick = annotation_scheme.get("maxTick", 8) # print("max_tick") # print(max_tick) # schematic = f""" #
# {get_ai_wrapper()} #
# {annotation_scheme['description']} #
# # # #
#
#
#
#
#
#
#
# # """ # key_bindings = [] # return schematic, key_bindings """ slider Layout """ import logging # Needed for the fall-back radio layout from potato.ai.ai_help_wrapper import get_ai_wrapper, get_dynamic_ai_help from .radio import generate_radio_layout from .identifier_utils import ( safe_generate_layout, generate_element_identifier, escape_html_content ) logger = logging.getLogger(__name__) def test_and_get(key, d): val = d[key] try: return int(val) except: raise Exception( 'Slider scale %s\'s value for "%s" is not an int' % (d["name"], key) ) def generate_slider_layout(annotation_scheme): """ Generate HTML for a slider input interface. Args: annotation_scheme (dict): Configuration including: - name: Schema identifier - description: Display description - starting_value: Initial slider value - min_value: Minimum allowed value - max_value: Maximum allowed value - show_labels: Whether to show min/max labels - labels: If present, fall back to radio layout Returns: tuple: (html_string, key_bindings) html_string: Complete HTML for the slider interface key_bindings: Empty list (no keyboard shortcuts) """ return safe_generate_layout(annotation_scheme, generate_slider_layout_internal) def generate_slider_layout_internal(annotation_scheme): from .identifier_utils import escape_html_content, generate_element_identifier, generate_validation_attribute if "labels" in annotation_scheme: return generate_radio_layout(annotation_scheme, horizontal=False) for required in ["starting_value", "min_value", "max_value"]: if required not in annotation_scheme: raise Exception( f'Slider scale for "{annotation_scheme["name"]}" did not include {required}' ) min_value = test_and_get("min_value", annotation_scheme) max_value = test_and_get("max_value", annotation_scheme) starting_value = test_and_get("starting_value", annotation_scheme) if min_value >= max_value: raise Exception( f'Slider scale for "{annotation_scheme["name"]}" must have minimum value < max value ({min_value} >= {max_value})' ) show_labels = annotation_scheme.get("show_labels", True) min_label = str(min_value) if show_labels else '' max_label = str(max_value) if show_labels else '' identifiers = generate_element_identifier(annotation_scheme["name"], "slider", "range") validation = generate_validation_attribute(annotation_scheme) # Get step from annotation_scheme or default to 1 step_value = annotation_scheme.get("step", 1) max_tick = annotation_scheme.get("maxTick", 8) schematic = f"""
{get_ai_wrapper()}
{annotation_scheme['description']}
{starting_value}
""" key_bindings = [] return schematic, key_bindings