Esempio n. 1
0
    def build_ui(self, input_widgets, of_widgets, go):
        """Create the form."""
        iw = list(input_widgets.values())
        ofw = list(of_widgets.values())

        header = widgets.Button(
            description=self.process.abstract or self.process.identifier,
            layout=widgets.Layout(width="100%"),
        )
        header = widgets.HTML(
            value=f"<h3>{self.process.abstract or self.process.identifier}</h3>"
        )
        input_header = widgets.HTML(value="<h4>Input parameters</h4>")
        widgets.Label("Input parameters")
        inputs = widgets.VBox([input_header, widgets.VBox(iw)])

        if len(ofw) > 0:
            widgets.Label("Complex outputs format")
            outputs_header = widgets.HTML(
                value="<h4>Complex outputs format</h4>")
            outputs = widgets.VBox([outputs_header, widgets.VBox(ofw)])
        else:
            outputs = None

        ui = widgets.AppLayout(header=header,
                               left_sidebar=inputs,
                               right_sidebar=outputs,
                               footer=go)

        return ui
Esempio n. 2
0
def monitor(execution, sleep=3):
    """Monitor the execution of a process using a notebook progress bar widget.

    Parameters
    ----------
    execution : WPSExecution instance
      The execute response to monitor.
    sleep: float
      Number of seconds to wait before each status check.
    """
    progress = widgets.IntProgress(
        value=0,
        min=0,
        max=100,
        step=1,
        description="Processing:",
        bar_style="info",
        orientation="horizontal",
    )

    cancel = widgets.Button(
        description="Cancel",
        button_style="danger",
        disabled=False,
        tooltip="Send `dismiss` request to WPS server.",
    )

    def cancel_handler(b):
        b.value = True
        b.disabled = True
        progress.description = "Interrupted"
        # TODO: Send dismiss signal to server

    cancel.value = False
    cancel.on_click(cancel_handler)

    box = widgets.HBox([progress, cancel],
                       layout=widgets.Layout(justify_content="space-between"))
    IPython.display.display(box)

    def check(execution, progress, cancel):
        while not execution.isComplete() and not cancel.value:
            execution.checkStatus(sleepSecs=sleep)
            progress.value = execution.percentCompleted

        if execution.isSucceded():
            progress.value = 100
            cancel.disabled = True
            progress.bar_style = "success"
            progress.description = "Complete"

        else:
            progress.bar_style = "danger"

    thread = threading.Thread(target=check, args=(execution, progress, cancel))
    thread.start()
Esempio n. 3
0
File: base.py Progetto: f-PLT/birdy
    def _create_refresh_widget(self):
        if ipyw is None:
            print(ipyw_not_installed)
            return

        if self._refresh_widget is None:
            button = ipyw.Button(description="Refresh WFS layer")
            button.on_click(self._refresh_layer)
            self._refresh_widget = ipyl.WidgetControl(widget=button,
                                                      position='topright')
            self._source_map.add_control(self._refresh_widget)
Esempio n. 4
0
    def __init__(self, func):
        self.result = None
        wps = func.__self__
        pid = self.pid = [
            k for k in wps._processes.keys() if sanitize(k) == func.__name__
        ][0]

        self.process = wps._processes[pid]
        inputs = list(wps._inputs[pid].items())
        outputs = list(wps._outputs[pid].items())

        # Create widgets
        iw = self.input_widgets(inputs)
        ofw = self.output_formats_widgets(outputs)
        go = widgets.Button(
            description="Launch process",
            layout=widgets.Layout(width="100%"),
            button_style="success",
        )
        out = widgets.Output()

        # Interaction logic
        def execute(change):
            """Execute callback when "Launch process" button is clicked."""
            go.disabled = True
            of = self.output_format_widget_values(ofw)
            if of:
                of = {"output_formats": of}
            kwargs = {**self.input_widget_values(iw), **of}

            with out:
                self.result = func(**kwargs)

        # Connect callback to button
        go.on_click(execute)

        # Create GUI
        ui = self.build_ui(iw, ofw, go)
        IPython.display(ui, out)