-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from scipp/multi-file-widget
Add multi-file and multi-string widgets
- Loading branch information
Showing
5 changed files
with
80 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
|
||
from ._string_widget import MultiStringWidget, StringWidget | ||
|
||
|
||
class FilenameWidget(StringWidget): ... | ||
|
||
|
||
class MultiFilenameWidget(MultiStringWidget): ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
from ipywidgets import HBox, Text, ValueWidget | ||
|
||
from ._config import default_layout | ||
|
||
|
||
class StringWidget(HBox, ValueWidget): | ||
def __init__(self, description: str, value: str | None = None, **kwargs): | ||
super().__init__(layout=default_layout) | ||
self.text_widget = Text(description=description, value=value, **kwargs) | ||
self.children = [self.text_widget] | ||
|
||
@property | ||
def value(self) -> str | None: | ||
v = self.text_widget.value.strip() | ||
if not v: | ||
return None | ||
return v | ||
|
||
@value.setter | ||
def value(self, value: str | None): | ||
if value is None: | ||
self.text_widget.value = '' | ||
else: | ||
self.text_widget.value = value | ||
|
||
|
||
class MultiStringWidget(StringWidget): | ||
@property | ||
def value(self) -> tuple[str, ...]: | ||
v = super().value | ||
if v is None: | ||
return () | ||
return tuple(s.strip() for s in v.split(',')) | ||
|
||
@value.setter | ||
def value(self, value: tuple[str, ...]): | ||
self.text_widget.value = ', '.join(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters