Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1031 from ess-dmsc/ECDC-3446-new-Filewriter-Attri…
Browse files Browse the repository at this point in the history
…bute

Ecdc 3446 new filewriter attribute
  • Loading branch information
ggoneiESS authored Jun 15, 2023
2 parents 23fdafb + b63623f commit 6d17ca4
Show file tree
Hide file tree
Showing 177 changed files with 522 additions and 600 deletions.
1 change: 1 addition & 0 deletions definitions/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lxml
pyRestTable==2020.0.3
urllib3<2.0
Sphinx
1 change: 1 addition & 0 deletions nexus-constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def closeEvent(self, event: QCloseEvent) -> None:
if "help" in parser.parse_args():
exit(0)
logging.basicConfig(level=logging.INFO)
QApplication.setStyle("Fusion")
QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
surfaceFormat = QSurfaceFormat()
surfaceFormat.setSwapInterval(1)
Expand Down
4 changes: 2 additions & 2 deletions nexus_constructor/add_component_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
OFFGeometryNoNexus,
)
from nexus_constructor.model.model import Model
from nexus_constructor.model.module import Dataset, Link
from nexus_constructor.model.module import Dataset, Link, FileWriter
from nexus_constructor.pixel_options import PixelOptions
from nexus_constructor.ui_utils import (
file_dialog,
Expand Down Expand Up @@ -763,7 +763,7 @@ def add_fields_to_component(
for i in range(fields_widget.count()):
widget = fields_widget.itemWidget(fields_widget.item(i))
try:
if not isinstance(widget.value, (Link, Dataset)):
if not isinstance(widget.value, (Link, Dataset, FileWriter)):
stream_module = deepcopy(widget.value)
stream_module.parent_node = component
component.children.append(stream_module)
Expand Down
1 change: 1 addition & 0 deletions nexus_constructor/common_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TransformationType:
SAMPLE_NAME = "sample"
ARRAY = "Array"
SCALAR = "Scalar"
FILEWRITER = "Filewriter"
SHAPE_GROUP_NAME = "shape"
PIXEL_SHAPE_GROUP_NAME = "pixel_shape"
GEOMETRY_GROUP_NAME = "geometry"
Expand Down
24 changes: 21 additions & 3 deletions nexus_constructor/field_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from nexus_constructor.field_widget import FieldWidget
from nexus_constructor.invalid_field_names import INVALID_FIELD_NAMES
from nexus_constructor.model.group import Group
from nexus_constructor.model.module import Dataset, FileWriterModule, Link, StreamModule
from nexus_constructor.model.module import (
Dataset,
FileWriterModule,
Link,
StreamModule,
FileWriter,
)
from nexus_constructor.model.value_type import ValueTypes
from nexus_constructor.utils.required_component_fields import required_component_fields
from nexus_constructor.validators import FieldType
Expand Down Expand Up @@ -47,7 +53,17 @@ def __update_existing_dataset_field(field: Dataset, new_ui_field: FieldWidget):
new_ui_field.value = field.values # type: ignore
new_ui_field.attrs = field
units = field.attributes.get_attribute_value(CommonAttrs.UNITS)
new_ui_field.units = units
new_ui_field.units = units or ""


def update_existing_filewriter_field(field: Dataset, new_ui_field: FieldWidget):
"""
Fill in a UI filewriter field for an existing filewriter field in the component group
:param field: The dataset to copy into the ???value line edit
:param new_ui_field: The new UI field to fill in with existing data
"""
new_ui_field.field_type = FieldType(FieldType.filewriter.value)
__update_existing_dataset_field(field, new_ui_field)


def update_existing_scalar_field(field: Dataset, new_ui_field: FieldWidget):
Expand All @@ -69,7 +85,7 @@ def update_existing_stream_field(
:param new_ui_field: The new UI field to fill in with existing data
"""
new_ui_field.field_type = FieldType.kafka_stream
new_ui_field._old_schema = field.writer_module # type: ignore
new_ui_field._old_schema = field.writer_module
new_ui_field.streams_widget.update_existing_stream_info(field)
new_ui_field.attrs = field
units = field.attributes.get_attribute_value(CommonAttrs.UNITS)
Expand Down Expand Up @@ -115,6 +131,8 @@ def find_field_type(item: "ValueType", ignore_names=INVALID_FIELD_NAMES) -> Call
return update_existing_stream_field
elif isinstance(item, Link):
return update_existing_link_field
elif isinstance(item, FileWriter):
return update_existing_filewriter_field
else:
try:
logging.debug(
Expand Down
21 changes: 17 additions & 4 deletions nexus_constructor/field_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
from nexus_constructor.field_attrs import FieldAttrsDialog
from nexus_constructor.invalid_field_names import INVALID_FIELD_NAMES
from nexus_constructor.model.group import Group
from nexus_constructor.model.module import Dataset, FileWriterModule, Link, StreamModule
from nexus_constructor.model.module import (
Dataset,
FileWriter,
FileWriterModule,
Link,
StreamModule,
)
from nexus_constructor.model.value_type import VALUE_TYPE_TO_NP, ValueTypes
from nexus_constructor.stream_fields_widget import StreamFieldsWidget
from nexus_constructor.ui_utils import validate_line_edit
Expand Down Expand Up @@ -367,6 +373,12 @@ def value(self) -> Union[FileWriterModule, None]:
name=self.name,
source=self.value_line_edit.text(),
)
elif self.field_type == FieldType.filewriter:
return_object = FileWriter(
parent_node=self._node_parent,
name=self.name,
type=dtype,
)
else:
logging.error(f"unknown field type: {self.name}")
return None
Expand Down Expand Up @@ -459,6 +471,9 @@ def field_type_changed(self):
show_attrs_edit=False,
)
self._set_up_value_validator(False)
elif self.field_type == FieldType.filewriter:
self.set_visibility(False, False, False, False, True, False, False)
self._set_up_value_validator(False)

def reset_field_type(self):
self.streams_widget.parentWidget().close()
Expand Down Expand Up @@ -486,9 +501,7 @@ def _set_up_value_validator(self, is_link: bool):
else:
self.value_line_edit.setValidator(
FieldValueValidator(
self.field_type_combo,
self.value_type_combo,
FieldType.scalar_dataset.value,
self.field_type_combo, self.value_type_combo, self.field_type.value
)
)
tooltip_on_accept = "Value is cast-able to numpy type."
Expand Down
10 changes: 6 additions & 4 deletions nexus_constructor/json/load_from_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from nexus_constructor.model.model import Model
from nexus_constructor.model.module import (
Dataset,
FileWriter,
FileWriterModule,
Link,
StreamModule,
Expand Down Expand Up @@ -201,7 +202,7 @@ def _load_from_json_dict(self, json_dict: Dict) -> bool:
self.entry_node = self._read_json_object(json_dict[CommonKeys.CHILDREN][0])
self.model.entry.attributes = self.entry_node.attributes
for child in self.entry_node.children:
if isinstance(child, (Dataset, Link, Group)):
if isinstance(child, (Dataset, Link, FileWriter, Group)):
self.model.entry[child.name] = child
else:
self.model.entry.children.append(child)
Expand Down Expand Up @@ -277,9 +278,10 @@ def _read_json_object(self, json_object: Dict, parent_node: Group = None):
module_type = json_object[CommonKeys.MODULE]
if (
module_type == WriterModules.DATASET.value
and json_object[NodeType.CONFIG][CommonKeys.NAME]
== CommonAttrs.DEPENDS_ON
):
or module_type == WriterModules.FILEWRITER.value
) and json_object[NodeType.CONFIG][
CommonKeys.NAME
] == CommonAttrs.DEPENDS_ON:
nexus_object = None
elif module_type in [x.value for x in WriterModules]:
nexus_object = create_fw_module_object(
Expand Down
26 changes: 26 additions & 0 deletions nexus_constructor/model/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WriterModules(Enum):
LINK = "link"
DATASET = "dataset"
ADAR = "ADAr"
FILEWRITER = "filewriter"


class StreamModules(Enum):
Expand Down Expand Up @@ -167,6 +168,26 @@ class F144Stream(F142Stream):
writer_module = attr.ib(type=str, default=WriterModules.F144.value, init=False)


@attr.s
class FileWriter(FileWriterModule):
name = attr.ib(type=str)
type = attr.ib(type=str, default="string")
values = attr.ib(type=str, default=None)
writer_module = attr.ib(
type=str, default=WriterModules.FILEWRITER.value, init=False
)

def as_dict(self, error_collector: List[str]):
return {
CommonKeys.MODULE: self.writer_module,
NodeType.CONFIG: {CommonKeys.NAME: self.name},
}

def as_nexus(self, nexus_node, error_collector: List[str]):
nexus_dataset = nexus_node.create_dataset(self.name, data=self.name)
nexus_dataset.attrs[self.name] = self.name


@attr.s
class Link(FileWriterModule):
name = attr.ib(type=str)
Expand Down Expand Up @@ -305,6 +326,7 @@ class WriterModuleClasses(Enum):
LINK = Link
DATASET = Dataset
ADAR = ADARStream
FILEWRITER = FileWriter


module_class_dict = dict(
Expand Down Expand Up @@ -373,6 +395,10 @@ def create_fw_module_object(mod_type, configuration, parent_node):
source=configuration[SOURCE],
parent_node=parent_node,
)
elif mod_type == WriterModules.FILEWRITER.value:
fw_mod_obj = fw_mod_class(
name=configuration[CommonKeys.NAME], parent_node=parent_node, type="string"
)
elif mod_type == WriterModules.DATASET.value:
if CommonKeys.DATA_TYPE in configuration:
dtype = configuration[CommonKeys.DATA_TYPE]
Expand Down
6 changes: 5 additions & 1 deletion nexus_constructor/module_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def _setup_frame(self, module):
source = module.source if module.source else "not specified"
self.layout.addWidget(self._get_label(f"link name: {name} | "))
self.layout.addWidget(self._get_label(f"source: {source}"))
elif module.writer_module == WriterModules.DATASET.value:
elif (
module.writer_module == WriterModules.DATASET.value
or module.writer_module == WriterModules.FILEWRITER.value
):
name = module.name if module.name else "not specified"
dtype = module.type if module.type else "not specified"
self.layout.addWidget(self._get_label(f"dataset name: {name} | "))
Expand Down Expand Up @@ -76,6 +79,7 @@ def _set_existing_items(self):
or self.module.writer_module == WriterModules.LINK.value
or self.module.writer_module
in [StreamMode.value for StreamMode in StreamModules]
or self.module.writer_module == WriterModules.FILEWRITER.value
):
update_function = find_field_type(module, [])
if update_function is not None:
Expand Down
4 changes: 2 additions & 2 deletions nexus_constructor/ui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def validate_combobox_edit(
:param tooltip_on_reject: Tooltip to display combobox edit is invalid.
:return: None.
"""
colour = "#FFFFFF" if is_valid else "#f6989d"
colour = "#333333" if is_valid else "#f6989d"
combobox_edit.setStyleSheet(f"QComboBox {{ background-color: {colour} }}")
if "Suggestion" in tooltip_on_reject and callable(suggestion_callable):
tooltip_on_reject += suggestion_callable()
Expand All @@ -86,7 +86,7 @@ def validate_line_edit(
:param tooltip_on_reject: Tooltip to display if line edit is invalid.
:return: None.
"""
colour = "#FFFFFF" if is_valid else "#f6989d"
colour = "#333333" if is_valid else "#f6989d"
line_edit.setStyleSheet(f"QLineEdit {{ background-color: {colour} }}")
if "Suggestion" in tooltip_on_reject and callable(suggestion_callable):
tooltip_on_reject += suggestion_callable()
Expand Down
5 changes: 3 additions & 2 deletions nexus_constructor/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PySide6.QtWidgets import QComboBox, QListWidget, QRadioButton, QWidget
from stl import mesh

from nexus_constructor.common_attrs import SCALAR
from nexus_constructor.common_attrs import SCALAR, FILEWRITER
from nexus_constructor.model.value_type import VALUE_TYPE_TO_NP
from nexus_constructor.unit_utils import (
units_are_expected_dimensionality,
Expand Down Expand Up @@ -392,6 +392,7 @@ class FieldType(Enum):
array_dataset = "Array dataset"
kafka_stream = "Kafka stream"
link = "Link"
filewriter = "Filewriter"


class FieldValueValidator(QValidator):
Expand All @@ -417,7 +418,7 @@ def validate(self, input: str, pos: int) -> QValidator.State:
:param pos: mouse position cursor(ignored, just here to satisfy overriding function)
:return: QValidator state (Acceptable, Intermediate, Invalid) - returning intermediate because invalid stops the user from typing.
"""
if not input: # More criteria here
if not input and not self.scalar == FILEWRITER: # More criteria here
return self._emit_and_return(False)
if self.field_type_combo.currentText() == self.scalar:
try:
Expand Down
5 changes: 2 additions & 3 deletions nx-class-documentation/html/applying-nexus.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@




<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>1.3. Constructing NeXus Files and Application Definitions &#8212; nexus v2020.10 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
Expand Down Expand Up @@ -790,7 +789,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="copyright.html">Copyright</a> 1996-2023, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 6.1.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.0.1.
</div>
</body>
</html>
5 changes: 2 additions & 3 deletions nx-class-documentation/html/authorgroup.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@




<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>9.1. Authors &#8212; nexus v2020.10 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
Expand Down Expand Up @@ -152,7 +151,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="copyright.html">Copyright</a> 1996-2023, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 6.1.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.0.1.
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@




<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>3.3.2.1. NXarchive &#8212; nexus v2020.10 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
Expand Down Expand Up @@ -451,7 +450,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2023, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 6.1.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.0.1.
</div>
</body>
</html>
5 changes: 2 additions & 3 deletions nx-class-documentation/html/classes/applications/NXarpes.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@




<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>3.3.2.2. NXarpes &#8212; nexus v2020.10 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
Expand Down Expand Up @@ -370,7 +369,7 @@ <h3>Navigation</h3>
</div>
<div class="footer" role="contentinfo">
&#169; <a href="../../copyright.html">Copyright</a> 1996-2023, NIAC, https://www.nexusformat.org.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 6.1.3.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.0.1.
</div>
</body>
</html>
Loading

0 comments on commit 6d17ca4

Please sign in to comment.