(click_function = None)
Creates a button and an int form to connect to timesketch.
Creates a button and an int form to connect to timesketch.
Creates a button and an int form to connect to timesketch .
def generate_connect_button(click_function = None):
    """Creates a button and an int form to connect to timesketch."""
    button = widgets.Button(description='Connect to sketch')
    output = widgets.Output()

    sketch_field = widgets.IntText(
        value=1,
        description='Sketch ID:',
        disabled=False
    )

    display(Markdown('## Connect to a sketch'))
    display(Markdown('Select a sketch to connect to.'))
    display(sketch_field, button, output)

    def _click_function(_):
        with output:
            timesketch_set_active_sketch_func(str(sketch_field.value))
            sketch = timesketch_get_sketch_func()
            try:
                display(Markdown(
                    f'Connected to sketch: {sketch.id}: **{sketch.name}**'))
                valid = widgets.Valid(value=True, description='Connected')
                display(valid)
                utils.ipython_bind_global('sketch', sketch)
                display(Markdown('Sketch object saved to **sketch**'))
            except KeyError:
                display(Markdown('**Unable to connect to sketch.**'))
                invalid = widgets.Valid(value=False, description='Connected')
                display(invalid)

    if click_function:
        button.on_click(click_function)
    else:
        button.on_click(_click_function)
def generate_connect_button ( click_function = None ) : button = widgets . Button ( description = 'Connect to sketch' ) output = widgets . Output ( ) sketch_field = widgets . IntText ( value = 1 , description = 'Sketch ID:' , disabled = False ) display ( Markdown ( '## Connect to a sketch' ) ) display ( Markdown ( 'Select a sketch to connect to.' ) ) display ( sketch_field , button , output ) def _click_function ( _ ) : with output : timesketch_set_active_sketch_func ( str ( sketch_field . value ) ) sketch = timesketch_get_sketch_func ( ) try : display ( Markdown ( f'Connected to sketch: {sketch.id}: **{sketch.name}**' ) ) valid = widgets . Valid ( value = True , description = 'Connected' ) display ( valid ) utils . ipython_bind_global ( 'sketch' , sketch ) display ( Markdown ( 'Sketch object saved to **sketch**' ) ) except KeyError : display ( Markdown ( '**Unable to connect to sketch.**' ) ) invalid = widgets . Valid ( value = False , description = 'Connected' ) display ( invalid ) if click_function : button . on_click ( click_function ) else : button . on_click ( _click_function )