-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 2D-Data-Processing-for-Pr
- Loading branch information
Showing
69 changed files
with
4,933 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ pytest_qt | |
pytest-mock | ||
unittest-xml-reporting | ||
tinycc | ||
h5py | ||
h5py | ||
sphinx | ||
pyparsing | ||
html5lib | ||
|
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
121 changes: 121 additions & 0 deletions
121
src/sas/qtgui/Perspectives/ParticleEditor/AngularSamplingMethodSelector.py
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,121 @@ | ||
from typing import List, Tuple | ||
|
||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QFormLayout, QComboBox, QDoubleSpinBox | ||
|
||
from sas.qtgui.Perspectives.ParticleEditor.datamodel.calculation import AngularDistribution | ||
from sas.qtgui.Perspectives.ParticleEditor.sampling.geodesic import GeodesicDivisions | ||
from sas.qtgui.Perspectives.ParticleEditor.sampling.angles import angular_sampling_methods | ||
from sas.qtgui.Perspectives.ParticleEditor.GeodesicSampleSelector import GeodesicSamplingSpinBox | ||
|
||
class ParametersForm(QWidget): | ||
""" Form that displays the parameters associated with the class (also responsible for generating the sampler)""" | ||
def __init__(self, sampling_class: type, parent=None): | ||
super().__init__(parent=parent) | ||
|
||
self.sampling_class = sampling_class | ||
|
||
self.layout = QFormLayout() | ||
self.parameter_callbacks = [] | ||
|
||
for parameter_name, text, cls in sampling_class.parameters(): | ||
if cls == GeodesicDivisions: | ||
widget = GeodesicSamplingSpinBox() | ||
|
||
def callback(): | ||
return widget.getNDivisions() | ||
|
||
elif cls == float: | ||
widget = QDoubleSpinBox() | ||
|
||
def callback(): | ||
return widget.value() | ||
|
||
|
||
else: | ||
raise TypeError(f"Cannot create appropriate widget for parameter of type '{cls}'") | ||
|
||
self.layout.addRow(text, widget) | ||
self.parameter_callbacks.append((parameter_name, callback)) | ||
|
||
self.setLayout(self.layout) | ||
|
||
def generate_sampler(self) -> AngularDistribution: | ||
""" Generate a sampler based on the selected parameters """ | ||
|
||
parameter_dict = {name: callback() for name, callback in self.parameter_callbacks} | ||
|
||
return self.sampling_class(**parameter_dict) | ||
|
||
|
||
|
||
class AngularSamplingMethodSelector(QWidget): | ||
""" Selects the method for doing angular sampling, and provides access to the parameters """ | ||
|
||
def __init__(self, parent=None): | ||
super().__init__(parent) | ||
|
||
layout = QVBoxLayout() | ||
|
||
self.combo = QComboBox() | ||
self.combo.addItems([cls.name() for cls in angular_sampling_methods]) | ||
|
||
subwidget = QWidget() | ||
self.subwidget_layout = QVBoxLayout() | ||
subwidget.setLayout(self.subwidget_layout) | ||
|
||
layout.addWidget(self.combo) | ||
layout.addWidget(subwidget) | ||
|
||
self.setLayout(layout) | ||
|
||
self.entry_widgets = [ParametersForm(cls) for cls in angular_sampling_methods] | ||
|
||
for widget in self.entry_widgets: | ||
self.subwidget_layout.addWidget(widget) | ||
widget.hide() | ||
|
||
self.entry_widgets[0].show() | ||
|
||
self.combo.currentIndexChanged.connect(self.on_update) | ||
|
||
def on_update(self): | ||
for i in range(self.subwidget_layout.count()): | ||
self.subwidget_layout.itemAt(i).widget().hide() | ||
|
||
self.subwidget_layout.itemAt(self.combo.currentIndex()).widget().show() | ||
|
||
def generate_sampler(self) -> AngularDistribution: | ||
""" Create the angular distribution sampler spectified by the current settings""" | ||
return self.subwidget_layout.itemAt(self.combo.currentIndex()).widget().generate_sampler() | ||
|
||
def main(): | ||
""" Show a demo """ | ||
|
||
from PySide6 import QtWidgets | ||
|
||
|
||
app = QtWidgets.QApplication([]) | ||
|
||
|
||
widget = QWidget() | ||
layout = QVBoxLayout() | ||
|
||
sampling = AngularSamplingMethodSelector() | ||
|
||
def callback(): | ||
print(sampling.generate_sampler()) | ||
|
||
button = QtWidgets.QPushButton("Check") | ||
button.clicked.connect(callback) | ||
|
||
layout.addWidget(sampling) | ||
layout.addWidget(button) | ||
|
||
widget.setLayout(layout) | ||
|
||
widget.show() | ||
app.exec_() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,27 @@ | ||
from PySide6 import QtWidgets, QtGui | ||
|
||
from sas.qtgui.Perspectives.ParticleEditor.UI.CodeToolBarUI import Ui_CodeToolBar | ||
|
||
import sas.qtgui.Perspectives.ParticleEditor.UI.icons_rc | ||
class CodeToolBar(QtWidgets.QWidget, Ui_CodeToolBar): | ||
def __init__(self, parent=None): | ||
super().__init__() | ||
|
||
self.setupUi(self) | ||
|
||
|
||
load_icon = QtGui.QIcon() | ||
load_icon.addPixmap(QtGui.QPixmap(":/particle_editor/upload-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) | ||
self.loadButton.setIcon(load_icon) | ||
|
||
save_icon = QtGui.QIcon() | ||
save_icon.addPixmap(QtGui.QPixmap(":/particle_editor/download-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) | ||
self.saveButton.setIcon(save_icon) | ||
|
||
build_icon = QtGui.QIcon() | ||
build_icon.addPixmap(QtGui.QPixmap(":/particle_editor/hammer-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) | ||
self.buildButton.setIcon(build_icon) | ||
|
||
scatter_icon = QtGui.QIcon() | ||
scatter_icon.addPixmap(QtGui.QPixmap(":/particle_editor/scatter-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) | ||
self.scatterButton.setIcon(scatter_icon) |
Oops, something went wrong.