geemap/toolbar.py
def tool_gui(tool_dict, max_width="420px", max_height="600px"):
    """Create a GUI for a tool based on the tool dictionary.

    Args:
        tool_dict (dict): The dictionary containing the tool info.
        max_width (str, optional): The max width of the tool dialog.
        max_height (str, optional): The max height of the tool dialog.

    Returns:
        object: An ipywidget object representing the tool interface.
    """
    tool_widget = widgets.VBox(
        layout=widgets.Layout(max_width=max_width, max_height=max_height)
    )
    children = []
    args = {}
    required_inputs = []
    style = {"description_width": "initial"}
    max_width = str(int(max_width.replace("px", "")) - 10) + "px"

    header_width = str(int(max_width.replace("px", "")) - 104) + "px"
    header = widgets.Label(
        value=f'Current Tool: {tool_dict["label"]}',
        style=style,
        layout=widgets.Layout(width=header_width),
    )
    code_btn = widgets.Button(
        description="View Code", layout=widgets.Layout(width="100px")
    )

    children.append(widgets.HBox([header, code_btn]))

    desc = widgets.Textarea(
        value=f'Description: {tool_dict["description"]}',
        layout=widgets.Layout(width="410px", max_width=max_width),
        disabled=True,
    )
    children.append(desc)

    run_btn = widgets.Button(description="Run", layout=widgets.Layout(width="100px"))
    cancel_btn = widgets.Button(
        description="Cancel", layout=widgets.Layout(width="100px")
    )
    help_btn = widgets.Button(description="Help", layout=widgets.Layout(width="100px"))
    import_btn = widgets.Button(
        description="Import",
        tooltip="Import the script to a new cell",
        layout=widgets.Layout(width="98px"),
    )
    tool_output = widgets.Output(layout=widgets.Layout(max_height="200px"))
    children.append(widgets.HBox([run_btn, cancel_btn, help_btn, import_btn]))
    children.append(tool_output)
    tool_widget.children = children

    def run_button_clicked(b):
        tool_output.clear_output()

        required_params = required_inputs.copy()
        args2 = []
        for arg in args:

            line = ""
            if isinstance(args[arg], FileChooser):
                if arg in required_params and args[arg].selected is None:
                    with tool_output:
                        print(f"Please provide inputs for required parameters.")
                        break
                elif arg in required_params:
                    required_params.remove(arg)
                if arg == "i":
                    line = f"-{arg}={args[arg].selected}"
                else:
                    line = f"--{arg}={args[arg].selected}"
            elif isinstance(args[arg], widgets.Text):
                if arg in required_params and len(args[arg].value) == 0:
                    with tool_output:
                        print(f"Please provide inputs for required parameters.")
                        break
                elif arg in required_params:
                    required_params.remove(arg)
                if args[arg].value is not None and len(args[arg].value) > 0:
                    line = f"--{arg}={args[arg].value}"
            elif isinstance(args[arg], widgets.Checkbox):
                line = f"--{arg}={args[arg].value}"
            args2.append(line)

        if len(required_params) == 0:
            with tool_output:
                # wbt.run_tool(tool_dict["name"], args2)
                pass

    def help_button_clicked(b):
        import webbrowser

        tool_output.clear_output()
        with tool_output:
            html = widgets.HTML(
                value=f'<a href={tool_dict["link"]} target="_blank">{tool_dict["link"]}</a>'
            )
            display(html)
        webbrowser.open_new_tab(tool_dict["link"])

    def code_button_clicked(b):
        import webbrowser

        with tool_output:
            html = widgets.HTML(
                value=f'<a href={tool_dict["link"]} target="_blank">{tool_dict["link"]}</a>'
            )
            display(html)
        webbrowser.open_new_tab(tool_dict["link"])

    def cancel_btn_clicked(b):
        tool_output.clear_output()

    def import_button_clicked(b):
        tool_output.clear_output()

        content = []

        create_code_cell("\n".join(content))

    import_btn.on_click(import_button_clicked)
    run_btn.on_click(run_button_clicked)
    help_btn.on_click(help_button_clicked)
    code_btn.on_click(code_button_clicked)
    cancel_btn.on_click(cancel_btn_clicked)

    return tool_widget
Create a GUI for a tool based on the tool dictionary.

    Args:
        tool_dict (dict): The dictionary containing the tool info.
        max_width (str, optional): The max width of the tool dialog.
        max_height (str, optional): The max height of the tool dialog.

    Returns:
        object: An ipywidget object representing the tool interface.
    
Create a GUI for a tool based on the tool dictionary.
Create a GUI for a tool based on the tool dictionary .
def tool_gui(tool_dict, max_width="420px", max_height="600px"):
    tool_widget = widgets.VBox(
        layout=widgets.Layout(max_width=max_width, max_height=max_height)
    )
    children = []
    args = {}
    required_inputs = []
    style = {"description_width": "initial"}
    max_width = str(int(max_width.replace("px", "")) - 10) + "px"
    header_width = str(int(max_width.replace("px", "")) - 104) + "px"
    header = widgets.Label(
        value=f'Current Tool: {tool_dict["label"]}',
        style=style,
        layout=widgets.Layout(width=header_width),
    )
    code_btn = widgets.Button(
        description="View Code", layout=widgets.Layout(width="100px")
    )
    children.append(widgets.HBox([header, code_btn]))
    desc = widgets.Textarea(
        value=f'Description: {tool_dict["description"]}',
        layout=widgets.Layout(width="410px", max_width=max_width),
        disabled=True,
    )
    children.append(desc)
    run_btn = widgets.Button(description="Run", layout=widgets.Layout(width="100px"))
    cancel_btn = widgets.Button(
        description="Cancel", layout=widgets.Layout(width="100px")
    )
    help_btn = widgets.Button(description="Help", layout=widgets.Layout(width="100px"))
    import_btn = widgets.Button(
        description="Import",
        tooltip="Import the script to a new cell",
        layout=widgets.Layout(width="98px"),
    )
    tool_output = widgets.Output(layout=widgets.Layout(max_height="200px"))
    children.append(widgets.HBox([run_btn, cancel_btn, help_btn, import_btn]))
    children.append(tool_output)
    tool_widget.children = children
    def run_button_clicked(b):
        tool_output.clear_output()
        required_params = required_inputs.copy()
        args2 = []
        for arg in args:
            line = ""
            if isinstance(args[arg], FileChooser):
                if arg in required_params and args[arg].selected is None:
                    with tool_output:
                        print(f"Please provide inputs for required parameters.")
                        break
                elif arg in required_params:
                    required_params.remove(arg)
                if arg == "i":
                    line = f"-{arg}={args[arg].selected}"
                else:
                    line = f"--{arg}={args[arg].selected}"
            elif isinstance(args[arg], widgets.Text):
                if arg in required_params and len(args[arg].value) == 0:
                    with tool_output:
                        print(f"Please provide inputs for required parameters.")
                        break
                elif arg in required_params:
                    required_params.remove(arg)
                if args[arg].value is not None and len(args[arg].value) > 0:
                    line = f"--{arg}={args[arg].value}"
            elif isinstance(args[arg], widgets.Checkbox):
                line = f"--{arg}={args[arg].value}"
            args2.append(line)
        if len(required_params) == 0:
            with tool_output:
                pass
    def help_button_clicked(b):
        import webbrowser
        tool_output.clear_output()
        with tool_output:
            html = widgets.HTML(
                value=f'<a href={tool_dict["link"]} target="_blank">{tool_dict["link"]}</a>'
            )
            display(html)
        webbrowser.open_new_tab(tool_dict["link"])
    def code_button_clicked(b):
        import webbrowser
        with tool_output:
            html = widgets.HTML(
                value=f'<a href={tool_dict["link"]} target="_blank">{tool_dict["link"]}</a>'
            )
            display(html)
        webbrowser.open_new_tab(tool_dict["link"])
    def cancel_btn_clicked(b):
        tool_output.clear_output()
    def import_button_clicked(b):
        tool_output.clear_output()
        content = []
        create_code_cell("\n".join(content))
    import_btn.on_click(import_button_clicked)
    run_btn.on_click(run_button_clicked)
    help_btn.on_click(help_button_clicked)
    code_btn.on_click(code_button_clicked)
    cancel_btn.on_click(cancel_btn_clicked)
    return tool_widget
def tool_gui ( tool_dict , max_width = "420px" , max_height = "600px" ) : tool_widget = widgets . VBox ( layout = widgets . Layout ( max_width = max_width , max_height = max_height ) ) children = [ ] args = { } required_inputs = [ ] style = { "description_width" : "initial" } max_width = str ( int ( max_width . replace ( "px" , "" ) ) - 10 ) + "px" header_width = str ( int ( max_width . replace ( "px" , "" ) ) - 104 ) + "px" header = widgets . Label ( value = f'Current Tool: {tool_dict["label"]}' , style = style , layout = widgets . Layout ( width = header_width ) , ) code_btn = widgets . Button ( description = "View Code" , layout = widgets . Layout ( width = "100px" ) ) children . append ( widgets . HBox ( [ header , code_btn ] ) ) desc = widgets . Textarea ( value = f'Description: {tool_dict["description"]}' , layout = widgets . Layout ( width = "410px" , max_width = max_width ) , disabled = True , ) children . append ( desc ) run_btn = widgets . Button ( description = "Run" , layout = widgets . Layout ( width = "100px" ) ) cancel_btn = widgets . Button ( description = "Cancel" , layout = widgets . Layout ( width = "100px" ) ) help_btn = widgets . Button ( description = "Help" , layout = widgets . Layout ( width = "100px" ) ) import_btn = widgets . Button ( description = "Import" , tooltip = "Import the script to a new cell" , layout = widgets . Layout ( width = "98px" ) , ) tool_output = widgets . Output ( layout = widgets . Layout ( max_height = "200px" ) ) children . append ( widgets . HBox ( [ run_btn , cancel_btn , help_btn , import_btn ] ) ) children . append ( tool_output ) tool_widget . children = children def run_button_clicked ( b ) : tool_output . clear_output ( ) required_params = required_inputs . copy ( ) args2 = [ ] for arg in args : line = "" if isinstance ( args [ arg ] , FileChooser ) : if arg in required_params and args [ arg ] . selected is None : with tool_output : print ( f"Please provide inputs for required parameters." ) break elif arg in required_params : required_params . remove ( arg ) if arg == "i" : line = f"-{arg}={args[arg].selected}" else : line = f"--{arg}={args[arg].selected}" elif isinstance ( args [ arg ] , widgets . Text ) : if arg in required_params and len ( args [ arg ] . value ) == 0 : with tool_output : print ( f"Please provide inputs for required parameters." ) break elif arg in required_params : required_params . remove ( arg ) if args [ arg ] . value is not None and len ( args [ arg ] . value ) > 0 : line = f"--{arg}={args[arg].value}" elif isinstance ( args [ arg ] , widgets . Checkbox ) : line = f"--{arg}={args[arg].value}" args2 . append ( line ) if len ( required_params ) == 0 : with tool_output : pass def help_button_clicked ( b ) : import webbrowser tool_output . clear_output ( ) with tool_output : html = widgets . HTML ( value = f'<a href={tool_dict["link"]} target="_blank">{tool_dict["link"]}</a>' ) display ( html ) webbrowser . open_new_tab ( tool_dict [ "link" ] ) def code_button_clicked ( b ) : import webbrowser with tool_output : html = widgets . HTML ( value = f'<a href={tool_dict["link"]} target="_blank">{tool_dict["link"]}</a>' ) display ( html ) webbrowser . open_new_tab ( tool_dict [ "link" ] ) def cancel_btn_clicked ( b ) : tool_output . clear_output ( ) def import_button_clicked ( b ) : tool_output . clear_output ( ) content = [ ] create_code_cell ( "\n" . join ( content ) ) import_btn . on_click ( import_button_clicked ) run_btn . on_click ( run_button_clicked ) help_btn . on_click ( help_button_clicked ) code_btn . on_click ( code_button_clicked ) cancel_btn . on_click ( cancel_btn_clicked ) return tool_widget
Create a GUI for a tool based on the tool dictionary.
Create a GUI for a tool based on the tool dictionary .
"""Create a GUI for a tool based on the tool dictionary.

    Args:
        tool_dict (dict): The dictionary containing the tool info.
        max_width (str, optional): The max width of the tool dialog.
        max_height (str, optional): The max height of the tool dialog.

    Returns:
        object: An ipywidget object representing the tool interface.
    """ # wbt.run_tool(tool_dict["name"], args2)
An ipywidget object representing the tool interface.
An ipywidget object representing the tool interface .
object
tool_dict
The dictionary containing the tool info.
The dictionary containing the tool info .
max_width
The max width of the tool dialog.
The max width of the tool dialog .
max_height
The max height of the tool dialog.
The max height of the tool dialog .