Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e975185
first reworked commit simply changing window type
ggoneiESS Oct 26, 2023
0862d49
working size switcher
ggoneiESS Oct 26, 2023
cc274b5
ensured window only appears once
ggoneiESS Oct 26, 2023
a259f58
fixed initial height being different
ggoneiESS Oct 27, 2023
01cf3d1
removed field title
ggoneiESS Oct 27, 2023
ece0608
cleaned heigh_reset method
ggoneiESS Oct 27, 2023
b5632be
working commit for new component not edit
ggoneiESS Oct 27, 2023
39c918b
fixed additional blank line
ggoneiESS Oct 30, 2023
a5365a1
GO FORMAT YOURSELF (black)
cow-bot Oct 30, 2023
215f701
Update NeXus HTML documentation
cow-bot Oct 30, 2023
16f1823
Update ui/add_component.py
ggoneiESS Oct 30, 2023
e068a98
fixed multiple widgets appearing (again)
ggoneiESS Oct 30, 2023
d878bdd
remove cancel confirmation call
ggoneiESS Oct 30, 2023
a7051ec
removed unused module
ggoneiESS Oct 30, 2023
ffad0e1
defined empty add_component_window
ggoneiESS Oct 30, 2023
54ab059
still no working window without reinitialising
ggoneiESS Oct 30, 2023
b342183
bug hunting for component filling
ggoneiESS Oct 31, 2023
a39eb16
half-fixed size correciton for add component
ggoneiESS Oct 31, 2023
2a71316
dynamic height based on selection
ggoneiESS Nov 2, 2023
7df4f76
commit so I can see what changed in Github easier
ggoneiESS Nov 2, 2023
1e73ff0
GO FORMAT YOURSELF (black)
cow-bot Nov 2, 2023
3838bd1
Update NeXus HTML documentation
cow-bot Nov 2, 2023
9642185
few changes to fix widgets back to 'normal'
ggoneiESS Nov 3, 2023
020911b
intermediate working-out-paint firing commit
ggoneiESS Nov 21, 2023
ea19a6b
understanding get_frame and paint events
ggoneiESS Nov 21, 2023
5f8dd6c
GO FORMAT YOURSELF (black)
cow-bot Nov 21, 2023
974e97c
Update NeXus HTML documentation
cow-bot Nov 21, 2023
1a0f223
small changes from 21.11
ggoneiESS Nov 22, 2023
807c905
Merge remote-tracking branch 'refs/remotes/origin/ECDC-3633-add_compo…
ggoneiESS Nov 22, 2023
2583684
GO FORMAT YOURSELF (black)
cow-bot Nov 22, 2023
f53c388
Update NeXus HTML documentation
cow-bot Nov 22, 2023
ad225d1
add expand call for add_component
ggoneiESS Nov 23, 2023
d8959a0
appending dummy component
ggoneiESS Nov 23, 2023
d43e477
fake component
ggoneiESS Nov 23, 2023
cb40c25
incremental edits to add component method
ggoneiESS Nov 27, 2023
f2542a5
FINALLY dialog appearing in the tree, badly
ggoneiESS Nov 27, 2023
9e9a1d1
prior to re-edits of addcomponentdialog
ggoneiESS Nov 27, 2023
65612a3
working on dialog features
ggoneiESS Nov 27, 2023
6079116
final edit for now with comments on widget
ggoneiESS Nov 27, 2023
7596565
pausing development on this branch for now
ggoneiESS Nov 27, 2023
e07635e
Merge remote-tracking branch 'refs/remotes/origin/ECDC-3633-add_compo…
ggoneiESS Nov 27, 2023
492572e
fixing merge errror
ggoneiESS Nov 27, 2023
6042098
wrong treeview_utils in previous commit
ggoneiESS Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nexus-constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def closeEvent(self, event: QCloseEvent) -> None:
surfaceFormat.setSwapBehavior(QSurfaceFormat.DoubleBuffer)
QSurfaceFormat.setDefaultFormat(surfaceFormat)
app = QApplication(sys.argv)
app.setStyleSheet(
"QWidget{padding:0px;margin:0px;}QLayout{padding:0;margin:0;border:0;}"
)
app.setWindowIcon(QIcon(os.path.join("ui", "icon.png")))
window = NexusConstructorMainWindow()
definitions_dir = os.path.abspath(os.path.join(root_dir, "definitions"))
Expand Down
179 changes: 103 additions & 76 deletions nexus_constructor/add_component_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from copy import deepcopy
from functools import partial
from os import path
from typing import Callable, List
from typing import Callable, List, Optional

from PySide6.QtCore import Qt, QUrl, Signal
from PySide6.QtGui import QKeyEvent, QVector3D
from PySide6.QtWidgets import QListWidget, QListWidgetItem, QMessageBox, QWidget
from PySide6.QtWidgets import QListWidget, QListWidgetItem, QWidget, QSizePolicy

from nexus_constructor.common_attrs import NX_CLASSES_WITH_PLACEHOLDERS, CommonAttrs
from nexus_constructor.component_tree_model import NexusTreeModel
Expand Down Expand Up @@ -55,98 +55,111 @@ class AddComponentDialog(Ui_AddComponentDialog):
nx_class_changed = Signal("QVariant")
suggest_group_name_from_parent_fields = Signal("QVariant")

def __init__(
def __init__(self, parent):
fakegroup = Group("", parent_node=None)
self._group_to_edit_backup: Group = deepcopy(fakegroup)
self._group_parent = None
super().__init__(parent, GroupContainer(fakegroup))
self.initial_edit = True
nx_classes = {}
self.nx_component_classes = OrderedDict(sorted(nx_classes.items()))
file_dir = path.dirname(__file__)
self.local_url_root = path.join(
file_dir,
"..",
"nx-class-documentation",
"html",
"classes",
"base_classes",
)
super().setupUi()
self.setWindowModality(Qt.WindowModal)

# self.setHidden(True)

def refresh_widget_values(
self,
parent: QWidget,
model: Model,
component_model: NexusTreeModel,
group_to_edit: Group,
scene_widget: QWidget,
# scene_widget: QWidget,
initial_edit: bool,
nx_classes=None,
tree_view_updater: Callable = None,
):
self._tree_view_updater = tree_view_updater
self._scene_widget = scene_widget
# self._scene_widget = scene_widget
self._group_to_edit_backup: Group = deepcopy(group_to_edit)
self._group_container = GroupContainer(group_to_edit)
self._group_parent = group_to_edit.parent_node
file_dir = path.dirname(__file__)
self.local_url_root = path.join(
file_dir,
"..",
"nx-class-documentation",
"html",
"classes",
"base_classes",
)
super().__init__(parent, self._group_container)
super().setupUi()
self.initial_edit = initial_edit
super().setGroupContainer(self._group_container)
if nx_classes is None:
nx_classes = {}
self.nx_component_classes = OrderedDict(sorted(nx_classes.items()))
self.signals = model.signals
self.model = model
self.component_model = component_model
self.nx_component_classes = OrderedDict(sorted(nx_classes.items()))
c_group = self._group_container.group

self.cad_file_name = None
self.possible_fields: List[str] = []
self.initial_edit = initial_edit
self.valid_file_given = False
self.pixel_options: PixelOptions = None
self.setupUi()
self.setModal(True)
self.setWindowModality(Qt.WindowModal)

if self.initial_edit:
self.ok_button.setText("Add group")
self.ok_validator.set_nx_class_valid(False)
self.cancel_button.setVisible(True)
self.componentTypeComboBox.currentIndexChanged.connect(
self._handle_class_change
)
self.cancel_button.clicked.connect(self._cancel_new_group)
self.rejected.connect(self._rejected)
else:
self.setWindowTitle(f"Edit group: {c_group.name}")
self.placeholder_checkbox.setChecked(c_group.group_placeholder)

self._fill_existing_entries()
if (
self.get_pixel_visibility_condition()
and self.pixel_options
and isinstance(c_group, Component)
):
self.pixel_options.fill_existing_entries(c_group)
if c_group.nx_class in NX_CLASSES_WITH_PLACEHOLDERS:
self.placeholder_checkbox.setVisible(True)
self.cancel_button.setVisible(True)
self.cancel_button.clicked.connect(self._cancel_edit_group)

self._set_html_docs_and_possible_fields(self._group_to_edit_backup.nx_class)

def _rejected(self):
if self.initial_edit:
self._group_parent.children.remove(self._group_container.group)

def _confirm_cancel(self) -> bool:
quit_msg = "Do you want to close the group editor?"
reply = QMessageBox.question(
self,
"Really quit?",
quit_msg,
QMessageBox.Close | QMessageBox.Ignore,
QMessageBox.Close,
)
if reply == QMessageBox.Close:
return True
return False

def _cancel_new_group(self):
if self._confirm_cancel():
group, _ = self.component_model.current_nxs_obj
if isinstance(group, Group):
self._refresh_tree(group)
else:
self._refresh_tree(self._group_to_edit_backup)
self.close()
# self._rejected()
group, _ = self.component_model.current_nxs_obj
if isinstance(group, Group):
self._refresh_tree(group)
else:
self._refresh_tree(self._group_to_edit_backup)
self.setHidden(True)

def _cancel_edit_group(self):
if self._confirm_cancel():
if self._group_parent:
self._group_parent.children.remove(self._group_container.group)
self._group_parent[
self._group_to_edit_backup.name
] = self._group_to_edit_backup
else:
self.model.entry = self._group_to_edit_backup # type: ignore
self.component_model.tree_root = self.model.entry
self._refresh_tree(self._group_to_edit_backup)
self.close()
self._rejected()
if self._group_parent:
self._group_parent.children.remove(self._group_container.group)
self._group_parent[
self._group_to_edit_backup.name
] = self._group_to_edit_backup
else:
self.model.entry = self._group_to_edit_backup # type: ignore
self.component_model.tree_root = self.model.entry
self._refresh_tree(self._group_to_edit_backup)
self.setHidden(True)

def _refresh_tree(self, group: Group):
if self._tree_view_updater:
Expand Down Expand Up @@ -178,9 +191,12 @@ def _handle_class_change(self):
self._group_container.group.nx_class = c_nx_class
self._group_parent.children.append(self._group_container.group)

def setupUi(self, pixel_options: PixelOptions = PixelOptions()):
def setupUi(self, pixel_options: Optional[PixelOptions] = None):
"""Sets up push buttons and validators for the add component window."""

if not pixel_options:
pixel_options = PixelOptions(self.pixelOptionsWidget)

# Connect the button calls with functions
self.ok_button.clicked.connect(self.on_ok)

Expand Down Expand Up @@ -229,7 +245,7 @@ def setupUi(self, pixel_options: PixelOptions = PixelOptions()):

self.pixel_options = pixel_options
if self.pixel_options:
self.pixel_options.setupUi(self.pixelOptionsWidget)
self.pixel_options.setupUi()
self.pixelOptionsWidget.ui = self.pixel_options

self.ok_validator = OkValidator(
Expand All @@ -245,22 +261,6 @@ def setupUi(self, pixel_options: PixelOptions = PixelOptions()):

c_group = self._group_container.group

if not self.initial_edit:
self.setWindowTitle(f"Edit group: {c_group.name}")
self.placeholder_checkbox.setChecked(c_group.group_placeholder)

self._fill_existing_entries()
if (
self.get_pixel_visibility_condition()
and self.pixel_options
and isinstance(c_group, Component)
):
self.pixel_options.fill_existing_entries(c_group)
if c_group.nx_class in NX_CLASSES_WITH_PLACEHOLDERS:
self.placeholder_checkbox.setVisible(True)
else:
self.ok_validator.set_nx_class_valid(False)

self.componentTypeComboBox.validator().is_valid.connect(
self.ok_validator.set_nx_class_valid
)
Expand Down Expand Up @@ -326,8 +326,6 @@ def setupUi(self, pixel_options: PixelOptions = PixelOptions()):
self.setAttribute(Qt.WA_DeleteOnClose)
self.ok_validator.validate_field_widget_list()

self._set_html_docs_and_possible_fields(self._group_to_edit_backup.nx_class)

def set_pixel_related_changes(self):
"""
Manages the pixel-related changes that are induced by changing the shape type. This entails changing the
Expand Down Expand Up @@ -465,7 +463,11 @@ def on_nx_class_changed(self):
self.placeholder_checkbox.setVisible(c_nx_class in NX_CLASSES_WITH_PLACEHOLDERS)
if c_nx_class not in NX_CLASSES_WITH_PLACEHOLDERS:
self.placeholder_checkbox.setChecked(False)
if not c_nx_class or c_nx_class not in self.nx_component_classes:
if (
not c_nx_class
or c_nx_class not in self.nx_component_classes
or self._group_container == 0
):
return
self._set_html_docs_and_possible_fields(c_nx_class)

Expand All @@ -479,7 +481,10 @@ def on_nx_class_changed(self):
def _set_html_docs_and_possible_fields(self, c_nx_class):
nx_class_docs_to_display = c_nx_class
if c_nx_class in STREAM_MODULE_GROUPS or not c_nx_class:
nx_class_docs_to_display = self._group_parent.nx_class
try:
nx_class_docs_to_display = self._group_parent.nx_class
except AttributeError:
nx_class_docs_to_display = "NXentry"
if self._group_parent:
possible_fields = self.nx_component_classes[self._group_parent.nx_class]
possible_field_names, _, _ = zip(*possible_fields)
Expand All @@ -503,19 +508,40 @@ def mesh_file_picker(self):
self.cad_file_name = filename
self.fileLineEdit.setText(filename)

def height_reset(self, height):
pass

# print(self.pixelOptionsWidget.isVisible())
# print(self.shapeOptionsBox.sizeHint().height()
# + (self.pixelOptionsWidget.sizeHint().height() if self.pixelOptionsWidget.isVisible() else 0)
# + self.fieldsBox.sizeHint().height()
# + self.unitsbox.sizeHint().height()
# + height)
# self.setFixedHeight(
# self.shapeOptionsBox.sizeHint().height()
# + (self.cylinderOptionsBox.sizeHint().height() if self.cylinderOptionsBox.isVisible() else 0)
# + (self.pixelOptionsWidget.sizeHint().height() if self.pixelOptionsWidget.isVisible() else 0)
# + self.fieldsBox.sizeHint().height()
# + self.unitsbox.sizeHint().height()
# + height
# )

def show_cylinder_fields(self):
self.shapeOptionsBox.setVisible(True)
self.geometryFileBox.setVisible(False)
self.cylinderOptionsBox.setVisible(True)
self.boxOptionsBox.setVisible(False)
self.height_reset(self.cylinderOptionsBox.sizeHint().height())

def show_box_fields(self):
self.shapeOptionsBox.setVisible(True)
self.geometryFileBox.setVisible(False)
self.cylinderOptionsBox.setVisible(False)
self.boxOptionsBox.setVisible(True)
self.height_reset(self.boxOptionsBox.sizeHint().height())

def show_no_geometry_fields(self):
self.height_reset(-self.shapeOptionsBox.sizeHint().height())
self.shapeOptionsBox.setVisible(False)
if self.nameLineEdit.text():
self.ok_button.setEnabled(True)
Expand All @@ -525,6 +551,7 @@ def show_mesh_fields(self):
self.geometryFileBox.setVisible(True)
self.cylinderOptionsBox.setVisible(False)
self.boxOptionsBox.setVisible(False)
self.height_reset(self.geometryFileBox.sizeHint().height())

def _disable_fields_and_buttons(self, placeholder_state: bool):
self.noShapeRadioButton.setEnabled(not placeholder_state)
Expand Down Expand Up @@ -615,7 +642,7 @@ def on_ok(self):
if not self.initial_edit:
self.signals.transformation_changed.emit()
self.model.signals.group_edited.emit(index, True)
self.hide()
self.setHidden(True)

def keyPressEvent(self, arg__1: QKeyEvent) -> None:
if arg__1.key() == Qt.Key_Escape:
Expand Down Expand Up @@ -645,7 +672,7 @@ def finalise_group(
add_fields_to_component(c_group, self.fieldsListWidget, self.component_model)
if isinstance(c_group, Component):
# remove the previous object from the qt3d view
self._scene_widget.delete_component(old_group_name)
# self._scene_widget.delete_component(old_group_name)
self.component_model.model.append_component(c_group)
self.generate_geometry_model(c_group, pixel_data)
self.write_pixel_data_to_component(c_group, pixel_data)
Expand Down
13 changes: 12 additions & 1 deletion nexus_constructor/component_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import PySide6.QtGui
from PySide6.QtCore import QAbstractItemModel, QByteArray, QMimeData, QModelIndex, Qt
from PySide6.QtGui import QVector3D
from PySide6.QtWidgets import QMessageBox
from PySide6.QtWidgets import QMessageBox, QTreeView

from nexus_constructor.common_attrs import (
NX_TRANSFORMATIONS,
Expand Down Expand Up @@ -430,6 +430,17 @@ def add_link(self, node: QModelIndex):
transformation_list.has_link = True
self.endInsertRows()

def add_component(self, index: QModelIndex, component_tree_view: QTreeView):
self.model.signals.group_edited.emit(index, False)
something = index.internalPointer()
c_group = Group("New Component", parent_node=something)
something.children.append(c_group)
# ok so let's do something instead of appending a nothing group!
self.model.append_component(c_group)
self.model.signals.component_added.emit(c_group)
self.model.signals.group_edited.emit(component_tree_view, True)
return c_group

def add_transformation(self, parent_index: QModelIndex, transformation_type: str):
parent_item = parent_index.internalPointer()
transformation_list = None
Expand Down
12 changes: 12 additions & 0 deletions nexus_constructor/component_tree_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
QWidget,
)

from nexus_constructor.add_component_window import AddComponentDialog
from nexus_constructor.component_tree_model import ComponentInfo, LinkTransformation
from nexus_constructor.model.component import Component
from nexus_constructor.model.group import Group
Expand All @@ -28,6 +29,7 @@
from nexus_constructor.transformations_list import TransformationsList
from nexus_constructor.treeview_utils import (
fill_selection,
get_component_frame,
get_group_frame,
get_group_info_frame,
get_link_transformation_frame,
Expand Down Expand Up @@ -62,6 +64,7 @@ def get_frame(
LinkTransformation,
TransformationsList,
FileWriterModule,
None,
],
):
frame = NexusQFrame()
Expand All @@ -85,6 +88,15 @@ def get_frame(
get_link_transformation_frame(frame, self.model, value)
elif isinstance(value, FileWriterModule):
get_module_frame(frame, self.model, value, self._use_simple_tree_view)
else:
get_component_frame(
frame,
self.model, value
# self.parent().parent().component_model,
# self.model.entry,
# self.parent().parent().sceneWidget,
# True,
)
return frame

def paint(
Expand Down
Loading