Skip to content

Commit

Permalink
Merge branch 'main' into 2D-Data-Processing-for-Pr
Browse files Browse the repository at this point in the history
  • Loading branch information
dehoni authored Sep 16, 2023
2 parents e4ab4b7 + f8f52af commit bac0a4f
Show file tree
Hide file tree
Showing 69 changed files with 4,933 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build_tools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pytest_qt
pytest-mock
unittest-xml-reporting
tinycc
h5py
h5py
sphinx
pyparsing
html5lib
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from setuptools import setup, Command, find_packages


# Manage version number
version_file = os.path.join("src", "sas", "system", "version.py")
with open(version_file) as fid:
Expand Down Expand Up @@ -80,6 +81,9 @@ def run(self):
'install', 'build', 'build_py', 'bdist', 'bdist_egg', 'bdist_rpm',
'bdist_wheel', 'develop', 'test'
]

print(sys.argv)

# determine if this run requires building of Qt GUI ui->py
build_qt = any(c in sys.argv for c in build_commands)
force_rebuild = "-f" if 'rebuild_ui' in sys.argv or 'clean' in sys.argv else ""
Expand All @@ -93,7 +97,7 @@ def run(self):
# Required packages
required = [
'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0',
'lxml', 'h5py',
'lxml',
]

if os.name == 'nt':
Expand Down
9 changes: 1 addition & 8 deletions src/sas/qtgui/Calculators/DataOperationUtilityPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,7 @@ def _findId(self, name):
def _extractData(self, key_id):
""" Extract data from file with id contained in list of filenames """
data_complete = self.filenames[key_id]
dimension = data_complete.data.__class__.__name__

if dimension in ('Data1D', 'Data2D'):
return copy.deepcopy(data_complete.data)

else:
logging.error('Error with data format')
return
return copy.deepcopy(data_complete)

# ########
# PLOTS
Expand Down
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()
27 changes: 27 additions & 0 deletions src/sas/qtgui/Perspectives/ParticleEditor/CodeToolBar.py
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)
Loading

0 comments on commit bac0a4f

Please sign in to comment.