-
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.
reduce code duplication between stringwidget and filenamewidget
- Loading branch information
Showing
3 changed files
with
4 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,10 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
# import scipp as sc | ||
from ipywidgets import HBox, Text, ValueWidget | ||
|
||
from ._config import default_layout | ||
from ._string_widget import MultiStringWidget, StringWidget | ||
|
||
|
||
class FilenameWidget(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] | ||
class FilenameWidget(StringWidget): ... | ||
|
||
@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 MultiFilenameWidget(FilenameWidget): | ||
@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) | ||
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