Skip to content

Commit

Permalink
Merge pull request #84 from scipp/ui-readability
Browse files Browse the repository at this point in the history
Minor readability improvements in the widgets
  • Loading branch information
SimonHeybrock authored Sep 5, 2024
2 parents dd2d9d8 + 154b1ee commit a0358da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ess/reduce/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Generic, TypeVar

import scipp as sc
from sciline._utils import key_name
from sciline.typing import Key

T = TypeVar('T')
Expand Down Expand Up @@ -56,7 +57,7 @@ def from_type(
# TODO __doc__ not correct when using Generic
# use sciline type->string helper
return cls(
name=str(t),
name=key_name(t),
description=t.__doc__,
default=default,
optional=optional,
Expand Down
2 changes: 1 addition & 1 deletion src/ess/reduce/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OutputSelectionWidget(widgets.VBox):
def __init__(self, workflow: sl.Pipeline, **kwargs):
self.typical_outputs_widget = widgets.SelectMultiple(
options=get_typical_outputs(workflow),
layout=Layout(width='90%', height='auto'),
layout=Layout(width='90%', height='250px'),
)
self.possible_outputs_widget = widgets.SelectMultiple(
options=get_possible_outputs(workflow),
Expand Down
14 changes: 10 additions & 4 deletions src/ess/reduce/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
from __future__ import annotations

from collections.abc import Callable, MutableSet
from collections.abc import Callable, MutableSet, Sequence
from typing import Any, TypeVar

import networkx as nx
from sciline import Pipeline
from sciline._utils import key_name
from sciline.typing import Key

from .parameter import Parameter, keep_default, parameter_mappers, parameter_registry
Expand Down Expand Up @@ -52,12 +53,17 @@ def get_typical_outputs(pipeline: Pipeline) -> tuple[Key, ...]:
if (typical_outputs := getattr(pipeline, "typical_outputs", None)) is None:
graph = pipeline.underlying_graph
sink_nodes = [node for node, degree in graph.out_degree if degree == 0]
return tuple(sink_nodes)
return tuple(typical_outputs)
return sorted(_with_pretty_names(sink_nodes))
return _with_pretty_names(typical_outputs)


def get_possible_outputs(pipeline: Pipeline) -> tuple[Key, ...]:
return tuple(pipeline.underlying_graph.nodes)
return sorted(_with_pretty_names(tuple(pipeline.underlying_graph.nodes)))


def _with_pretty_names(outputs: Sequence[Key]) -> tuple[tuple[str, Key], ...]:
"""Add a more readable string representation without full module path."""
return tuple((key_name(output), output) for output in outputs)


def get_parameters(
Expand Down
2 changes: 1 addition & 1 deletion tests/widget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_workflow_selection() -> None:
first_widget = widget.children[1].children[0]
assert isinstance(first_widget, WorkflowWidget)
assert first_widget.output_selection_box.typical_outputs_widget.options == (
str,
('str', str),
)
_refresh_widget_parameter(widget=first_widget, output_selections=[str])
assert first_widget.parameter_box._input_widgets.keys() == {int, float}
Expand Down

0 comments on commit a0358da

Please sign in to comment.