mlgidGUI 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlgidGUI/__init__.py +52 -0
- mlgidGUI/__main__.py +7 -0
- mlgidGUI/__version.py +1 -0
- mlgidGUI/app/__init__.py +8 -0
- mlgidGUI/app/actions_stack.py +1 -0
- mlgidGUI/app/app.py +67 -0
- mlgidGUI/app/cif_rois/__init__.py +0 -0
- mlgidGUI/app/cif_rois/cif_peaks_calculation.py +57 -0
- mlgidGUI/app/cif_rois/cif_simulation/__init__.py +0 -0
- mlgidGUI/app/cif_rois/cif_simulation/data/__init__.py +0 -0
- mlgidGUI/app/cif_rois/cif_simulation/data/atoms.py +15 -0
- mlgidGUI/app/cif_rois/cif_simulation/data/export_database.py +28 -0
- mlgidGUI/app/cif_rois/cif_simulation/experiment.py +57 -0
- mlgidGUI/app/cif_rois/cif_simulation/giwaxs_sim.py +286 -0
- mlgidGUI/app/cif_rois/cif_simulation/int_sim.py +105 -0
- mlgidGUI/app/cif_rois/cif_simulation/possible_directions.py +20 -0
- mlgidGUI/app/cif_rois/cif_simulation/q_sim.py +159 -0
- mlgidGUI/app/data_manager/__init__.py +4 -0
- mlgidGUI/app/data_manager/data_manager.py +164 -0
- mlgidGUI/app/data_manager/import_from_h5.py +68 -0
- mlgidGUI/app/data_manager/load_data.py +78 -0
- mlgidGUI/app/data_manager/pascal/__init__.py +2 -0
- mlgidGUI/app/data_manager/pascal/annotation_fabric.py +59 -0
- mlgidGUI/app/data_manager/pascal/draw_objects.py +119 -0
- mlgidGUI/app/data_manager/pascal/exceptions.py +6 -0
- mlgidGUI/app/data_manager/pascal/format_convertor.py +127 -0
- mlgidGUI/app/data_manager/pascal/pascal_annotation.py +85 -0
- mlgidGUI/app/data_manager/pascal/protocol_implementations.py +28 -0
- mlgidGUI/app/data_manager/pascal/protocols.py +47 -0
- mlgidGUI/app/data_manager/pascal/utils.py +64 -0
- mlgidGUI/app/data_manager/save_dataset.py +57 -0
- mlgidGUI/app/data_manager/save_h5.py +178 -0
- mlgidGUI/app/data_manager/saving_parameters.py +88 -0
- mlgidGUI/app/debug_tracker.py +129 -0
- mlgidGUI/app/edf_reader.py +135 -0
- mlgidGUI/app/file_manager/__init__.py +201 -0
- mlgidGUI/app/file_manager/config_manager.py +76 -0
- mlgidGUI/app/file_manager/keys.py +542 -0
- mlgidGUI/app/file_manager/npy_file_manager.py +17 -0
- mlgidGUI/app/file_manager/object_file_manager.py +77 -0
- mlgidGUI/app/file_manager/project_structure.py +169 -0
- mlgidGUI/app/file_manager/read_fits.py +76 -0
- mlgidGUI/app/file_manager/read_geometry.py +54 -0
- mlgidGUI/app/file_manager/read_images.py +31 -0
- mlgidGUI/app/file_manager/read_meta_roi.py +40 -0
- mlgidGUI/app/file_manager/read_polar_images.py +22 -0
- mlgidGUI/app/file_manager/read_radial_profile.py +6 -0
- mlgidGUI/app/file_manager/read_roi_data.py +39 -0
- mlgidGUI/app/fitting/__init__.py +5 -0
- mlgidGUI/app/fitting/background.py +92 -0
- mlgidGUI/app/fitting/fit.py +128 -0
- mlgidGUI/app/fitting/fit_holder.py +273 -0
- mlgidGUI/app/fitting/fit_object.py +247 -0
- mlgidGUI/app/fitting/functions.py +107 -0
- mlgidGUI/app/fitting/range_strategy.py +14 -0
- mlgidGUI/app/fitting/utils.py +17 -0
- mlgidGUI/app/geometry.py +236 -0
- mlgidGUI/app/geometry_holder.py +131 -0
- mlgidGUI/app/image_holder.py +200 -0
- mlgidGUI/app/image_processing.py +23 -0
- mlgidGUI/app/polar_image.py +96 -0
- mlgidGUI/app/profiles/__init__.py +5 -0
- mlgidGUI/app/profiles/angular_profile.py +20 -0
- mlgidGUI/app/profiles/basic_profile.py +169 -0
- mlgidGUI/app/profiles/radial_profile.py +38 -0
- mlgidGUI/app/read_image.py +21 -0
- mlgidGUI/app/rois/__init__.py +4 -0
- mlgidGUI/app/rois/new_roi_dict.py +670 -0
- mlgidGUI/app/rois/roi.py +194 -0
- mlgidGUI/app/rois/roi_colors.py +76 -0
- mlgidGUI/app/rois/roi_data.py +177 -0
- mlgidGUI/app/rois/roi_dict.py +466 -0
- mlgidGUI/app/rois/roi_meta_data.py +149 -0
- mlgidGUI/app/structures/__init__.py +6 -0
- mlgidGUI/app/structures/crystal_ring.py +19 -0
- mlgidGUI/app/structures/crystals_holders.py +144 -0
- mlgidGUI/app/structures/custom_crystal.py +45 -0
- mlgidGUI/app/structures/get_ring_list.py +89 -0
- mlgidGUI/app/transformations.py +82 -0
- mlgidGUI/app/update/__init__.py +3 -0
- mlgidGUI/app/update/check_version.py +51 -0
- mlgidGUI/app/update/launch_program.py +15 -0
- mlgidGUI/app/update/script_update.py +64 -0
- mlgidGUI/app/utils.py +124 -0
- mlgidGUI/gui/__init__.py +3 -0
- mlgidGUI/gui/background_tasks.py +41 -0
- mlgidGUI/gui/background_update.py +87 -0
- mlgidGUI/gui/basic_widgets/__init__.py +12 -0
- mlgidGUI/gui/basic_widgets/buttons.py +144 -0
- mlgidGUI/gui/basic_widgets/labels.py +51 -0
- mlgidGUI/gui/basic_widgets/mouse_events.py +119 -0
- mlgidGUI/gui/basic_widgets/path_line.py +162 -0
- mlgidGUI/gui/basic_widgets/plots_1d.py +365 -0
- mlgidGUI/gui/basic_widgets/plots_2d.py +224 -0
- mlgidGUI/gui/basic_widgets/popups.py +164 -0
- mlgidGUI/gui/basic_widgets/progress_bar.py +127 -0
- mlgidGUI/gui/basic_widgets/setup_widgets.py +138 -0
- mlgidGUI/gui/basic_widgets/sliders.py +616 -0
- mlgidGUI/gui/basic_widgets/spinner.py +65 -0
- mlgidGUI/gui/basic_widgets/toolbars.py +19 -0
- mlgidGUI/gui/debug_widgets.py +388 -0
- mlgidGUI/gui/dock_area.py +115 -0
- mlgidGUI/gui/exception_message.py +42 -0
- mlgidGUI/gui/fitting/__init__.py +2 -0
- mlgidGUI/gui/fitting/fit_widget.py +966 -0
- mlgidGUI/gui/fitting/inplace_fit.py +536 -0
- mlgidGUI/gui/fitting/selected_fit_widget.py +286 -0
- mlgidGUI/gui/gui_main.py +349 -0
- mlgidGUI/gui/image_viewer.py +323 -0
- mlgidGUI/gui/init_window.py +170 -0
- mlgidGUI/gui/load_window/__init__.py +2 -0
- mlgidGUI/gui/load_window/load_folder.py +61 -0
- mlgidGUI/gui/load_window/load_h5.py +73 -0
- mlgidGUI/gui/notifications.py +68 -0
- mlgidGUI/gui/polar_image_viewer.py +153 -0
- mlgidGUI/gui/profiles/__init__.py +1 -0
- mlgidGUI/gui/profiles/angular_profile_widget.py +62 -0
- mlgidGUI/gui/profiles/radial_profile_widget.py +164 -0
- mlgidGUI/gui/project_manager/__init__.py +17 -0
- mlgidGUI/gui/project_manager/cif_files_widget.py +196 -0
- mlgidGUI/gui/project_manager/cif_results.py +146 -0
- mlgidGUI/gui/project_manager/metadata_widget.py +15 -0
- mlgidGUI/gui/project_manager/project_viewer.py +151 -0
- mlgidGUI/gui/project_manager/roi_widget.py +171 -0
- mlgidGUI/gui/roi_widgets/__init__.py +6 -0
- mlgidGUI/gui/roi_widgets/abstract_roi_holder.py +189 -0
- mlgidGUI/gui/roi_widgets/abstract_roi_widget.py +111 -0
- mlgidGUI/gui/roi_widgets/cif_file_widget.py +16 -0
- mlgidGUI/gui/roi_widgets/cif_peak_widget.py +43 -0
- mlgidGUI/gui/roi_widgets/confidence_level_widget.py +105 -0
- mlgidGUI/gui/roi_widgets/roi_1d_widget.py +136 -0
- mlgidGUI/gui/roi_widgets/roi_2d_rect_widget.py +98 -0
- mlgidGUI/gui/roi_widgets/roi_2d_ring_widget.py +203 -0
- mlgidGUI/gui/roi_widgets/rois_context_menu.py +150 -0
- mlgidGUI/gui/roi_widgets/select_roi_color_widget.py +58 -0
- mlgidGUI/gui/save_window/__init__.py +152 -0
- mlgidGUI/gui/save_window/format_box.py +33 -0
- mlgidGUI/gui/save_window/num_selected_widget.py +45 -0
- mlgidGUI/gui/save_window/options_widgets.py +105 -0
- mlgidGUI/gui/save_window/save_mode_box.py +30 -0
- mlgidGUI/gui/save_window/select_images.py +198 -0
- mlgidGUI/gui/tools.py +179 -0
- mlgidGUI/static/__init__.py +0 -0
- mlgidGUI/static/icons/__init__.py +0 -0
- mlgidGUI/static/icons/add.png +0 -0
- mlgidGUI/static/icons/add_yellow.png +0 -0
- mlgidGUI/static/icons/angular_profile.png +0 -0
- mlgidGUI/static/icons/arrow.png +0 -0
- mlgidGUI/static/icons/baseline.png +0 -0
- mlgidGUI/static/icons/center.png +0 -0
- mlgidGUI/static/icons/confirm.png +0 -0
- mlgidGUI/static/icons/control_widget.png +0 -0
- mlgidGUI/static/icons/data.png +0 -0
- mlgidGUI/static/icons/delete.png +0 -0
- mlgidGUI/static/icons/delete_yellow.png +0 -0
- mlgidGUI/static/icons/error.png +0 -0
- mlgidGUI/static/icons/find.png +0 -0
- mlgidGUI/static/icons/fit.png +0 -0
- mlgidGUI/static/icons/fix_all.png +0 -0
- mlgidGUI/static/icons/flip_horizontal.png +0 -0
- mlgidGUI/static/icons/flip_vertical.png +0 -0
- mlgidGUI/static/icons/folder.png +0 -0
- mlgidGUI/static/icons/fromfullscreen.png +0 -0
- mlgidGUI/static/icons/h5_folder.png +0 -0
- mlgidGUI/static/icons/h5_group_folder.png +0 -0
- mlgidGUI/static/icons/info.png +0 -0
- mlgidGUI/static/icons/interpolate.png +0 -0
- mlgidGUI/static/icons/item.png +0 -0
- mlgidGUI/static/icons/properties.png +0 -0
- mlgidGUI/static/icons/radial_profile.png +0 -0
- mlgidGUI/static/icons/roi_item.png +0 -0
- mlgidGUI/static/icons/rotate.png +0 -0
- mlgidGUI/static/icons/rotate_image.png +0 -0
- mlgidGUI/static/icons/rotate_right.png +0 -0
- mlgidGUI/static/icons/setup.png +0 -0
- mlgidGUI/static/icons/setup_white.png +0 -0
- mlgidGUI/static/icons/tofullscreen.png +0 -0
- mlgidGUI/static/icons/unfix_all.png +0 -0
- mlgidGUI/static/icons/update.png +0 -0
- mlgidGUI/static/icons/update_suggested.png +0 -0
- mlgidGUI/static/icons/window_icon.png +0 -0
- mlgidGUI/static/icons/window_icon_256.png +0 -0
- mlgidGUI/utils/__init__.py +1 -0
- mlgidGUI/utils/project2h5.py +11 -0
- mlgidgui-0.4.1.dist-info/METADATA +119 -0
- mlgidgui-0.4.1.dist-info/RECORD +202 -0
- mlgidgui-0.4.1.dist-info/WHEEL +5 -0
- mlgidgui-0.4.1.dist-info/entry_points.txt +5 -0
- mlgidgui-0.4.1.dist-info/licenses/LICENSE +674 -0
- mlgidgui-0.4.1.dist-info/top_level.txt +4 -0
- tests/__init__.py +0 -0
- tests/conftest.py +1 -0
- tests/fixures/__init__.py +2 -0
- tests/fixures/projects.py +102 -0
- tests/func/__init__.py +1 -0
- tests/func/test_loading_state.py +21 -0
- tests/func/test_parse_project_data.py +23 -0
- tests/func/test_save.py +62 -0
- tests/unit/__init__.py +0 -0
- tests/unit/rois/__init__.py +0 -0
- tests/unit/rois/test_basic_operations.py +18 -0
- tests/unit/test_add_data.py +33 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from enum import Enum, auto
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import QWidget, QGridLayout
|
|
4
|
+
from PyQt5.QtCore import pyqtSignal
|
|
5
|
+
|
|
6
|
+
from ..app.update import CheckVersionMessage
|
|
7
|
+
from .basic_widgets import PopUpWrapper, TextNotification, Label, HyperlinkLabel
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class NotificationTypes(Enum):
|
|
11
|
+
checking_version = auto()
|
|
12
|
+
updating_program = auto()
|
|
13
|
+
check_result = auto()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_check_result_notification(res: CheckVersionMessage) -> TextNotification or None:
|
|
17
|
+
if res.value == CheckVersionMessage.new_version_available.value:
|
|
18
|
+
try:
|
|
19
|
+
version = f'{res.version} '
|
|
20
|
+
except AttributeError:
|
|
21
|
+
return
|
|
22
|
+
# version = ''
|
|
23
|
+
return TextNotification('New version available',
|
|
24
|
+
f'The new version {version}will be installed')
|
|
25
|
+
if res.value == CheckVersionMessage.latest_version_installed.value:
|
|
26
|
+
return TextNotification('Latest version installed',
|
|
27
|
+
'You use the latest version of the program!')
|
|
28
|
+
if res.value == CheckVersionMessage.error.value or res.value == CheckVersionMessage.no_internet.value:
|
|
29
|
+
return TextNotification('Check version failed',
|
|
30
|
+
'Please, check your internet connection')
|
|
31
|
+
if res.value == CheckVersionMessage.failed_updating.value:
|
|
32
|
+
return TextNotification('Install failed', 'Please, check your internet connection or update manually')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CheckingVersion(TextNotification):
|
|
36
|
+
def __init__(self, parent=None):
|
|
37
|
+
super().__init__('Check version', 'The program is looking for updates', spinner=True, parent=parent)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class UpdatingProgram(TextNotification):
|
|
41
|
+
def __init__(self, version: str, parent=None):
|
|
42
|
+
super().__init__('Install', f'Updating the program to version {version}', spinner=True, parent=parent)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class UpdateFailed(TextNotification):
|
|
46
|
+
def __init__(self, parent=None):
|
|
47
|
+
super().__init__('Install failed', 'Please, check your internet connection or use\n'
|
|
48
|
+
'pip install --upgrade mlgidGUI',
|
|
49
|
+
spinner=False, parent=parent)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class AskRestart(QWidget):
|
|
53
|
+
sigRestart = pyqtSignal()
|
|
54
|
+
|
|
55
|
+
def __init__(self, parent=None):
|
|
56
|
+
super().__init__(parent)
|
|
57
|
+
layout = QGridLayout(self)
|
|
58
|
+
layout.setSpacing(5)
|
|
59
|
+
title = Label('The program was updated', self, 8.5, True)
|
|
60
|
+
title_font = title.font()
|
|
61
|
+
title_font.setPointSizeF(8.5)
|
|
62
|
+
title_font.setBold(True)
|
|
63
|
+
title.setFont(title_font)
|
|
64
|
+
layout.addWidget(title, 0, 0, 1, 2)
|
|
65
|
+
layout.addWidget(Label('Please, restart the program to launch the new version.', self, 8.5), 1, 0, 1, 2)
|
|
66
|
+
restart_label = HyperlinkLabel('Restart', self, 8.5)
|
|
67
|
+
layout.addWidget(restart_label, 2, 0)
|
|
68
|
+
restart_label.sigClicked.connect(self.sigRestart)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import QMainWindow, QLabel, QComboBox, QHBoxLayout
|
|
4
|
+
from PyQt5.QtCore import pyqtSlot, Qt, QPointF
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from .basic_widgets import (CustomImageViewer, BlackToolBar, BasicInputParametersWidget,
|
|
8
|
+
InfoButton, AbstractInputParametersWidget,
|
|
9
|
+
DrawRoiController)
|
|
10
|
+
from .roi_widgets.roi_2d_rect_widget import Roi2DRect
|
|
11
|
+
from .roi_widgets.abstract_roi_holder import AbstractRoiHolder
|
|
12
|
+
|
|
13
|
+
from ..app.app import App
|
|
14
|
+
from ..app.rois.roi import Roi, RoiTypes
|
|
15
|
+
from ..app.polar_image import INTERPOLATION_ALGORITHMS
|
|
16
|
+
from .tools import Icon
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class _PolarCustomImageViewer(CustomImageViewer):
|
|
20
|
+
def set_default_range(self):
|
|
21
|
+
return self.set_auto_range()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PolarImageViewer(AbstractRoiHolder, QMainWindow):
|
|
25
|
+
|
|
26
|
+
def __init__(self, parent=None):
|
|
27
|
+
AbstractRoiHolder.__init__(self, 'PolarImageViewer')
|
|
28
|
+
QMainWindow.__init__(self, parent)
|
|
29
|
+
self.app = parent.app
|
|
30
|
+
self._setup_window = None
|
|
31
|
+
self._interpolation_params_dict: dict = InterpolateSetupWindow.get_config()
|
|
32
|
+
self._image_viewer = _PolarCustomImageViewer(self)
|
|
33
|
+
|
|
34
|
+
self.register_key_patch()
|
|
35
|
+
|
|
36
|
+
self._draw_roi = PolarDrawRoi(self._image_viewer.view_box, self)
|
|
37
|
+
self._draw_roi.sigCreateRoi.connect(self.app.roi_dict.add_roi)
|
|
38
|
+
self._draw_roi.sigMoveRoi.connect(self.app.roi_dict.move_roi)
|
|
39
|
+
|
|
40
|
+
self._image_viewer.image_plot.getAxis('bottom').setLabel(
|
|
41
|
+
text='|Q|', color='white', font_size='large')
|
|
42
|
+
self._image_viewer.image_plot.getAxis('left').setLabel(
|
|
43
|
+
text='Φ', color='white', font_size='large')
|
|
44
|
+
self.setCentralWidget(self._image_viewer)
|
|
45
|
+
self.app.image_holder.sigPolarImageChanged.connect(self._update_image)
|
|
46
|
+
self.app.geometry_holder.sigScaleChanged.connect(self._on_scale_changed)
|
|
47
|
+
self.app.image_holder.sigEmptyImage.connect(self._image_viewer.clear_image)
|
|
48
|
+
# self.app.roi_dict.sig_roi_moved.connect(self._image_viewer.set_auto_range)
|
|
49
|
+
|
|
50
|
+
self.__init_toolbar()
|
|
51
|
+
|
|
52
|
+
def _on_scale_changed(self):
|
|
53
|
+
self.set_axes()
|
|
54
|
+
|
|
55
|
+
def _make_roi_widget(self, roi):
|
|
56
|
+
roi_widget = Roi2DRect(roi)
|
|
57
|
+
self._image_viewer.image_plot.addItem(roi_widget)
|
|
58
|
+
return roi_widget
|
|
59
|
+
|
|
60
|
+
def _delete_roi_widget(self, roi_widget):
|
|
61
|
+
self._image_viewer.image_plot.removeItem(roi_widget)
|
|
62
|
+
self._image_viewer.set_auto_range()
|
|
63
|
+
|
|
64
|
+
def __init_toolbar(self):
|
|
65
|
+
setup_toolbar = BlackToolBar('Setup', self)
|
|
66
|
+
self.addToolBar(setup_toolbar)
|
|
67
|
+
|
|
68
|
+
setup_action = setup_toolbar.addAction(Icon('setup'), 'Setup')
|
|
69
|
+
setup_action.triggered.connect(self.open_setup_window)
|
|
70
|
+
|
|
71
|
+
@pyqtSlot(name='updateImage')
|
|
72
|
+
def _update_image(self):
|
|
73
|
+
img = self.app.polar_image
|
|
74
|
+
if img is not None:
|
|
75
|
+
self._image_viewer.set_data(img)
|
|
76
|
+
self.set_axes()
|
|
77
|
+
|
|
78
|
+
def set_axes(self):
|
|
79
|
+
if self._image_viewer.image_item.image is None:
|
|
80
|
+
return
|
|
81
|
+
p1, p2 = self.app.geometry.phi_range
|
|
82
|
+
r1, r2 = np.nanmin(self.app.geometry.r_axis), self.app.geometry.r_axis.max()
|
|
83
|
+
self._image_viewer.set_x_axis(r1, r2)
|
|
84
|
+
self._image_viewer.set_y_axis(p1 * 180 / np.pi, p2 * 180 / np.pi)
|
|
85
|
+
self._image_viewer.view_box.setAspectLocked(
|
|
86
|
+
True, self.app.geometry.polar_aspect_ratio)
|
|
87
|
+
self._image_viewer.set_auto_range()
|
|
88
|
+
|
|
89
|
+
def open_setup_window(self):
|
|
90
|
+
self._setup_window = InterpolateSetupWindow(params_dict=self.app.image_holder.polar_image_params_dict())
|
|
91
|
+
self._setup_window.apply_signal.connect(self.set_fit_parameters)
|
|
92
|
+
self._setup_window.close_signal.connect(self.close_peaks_setup)
|
|
93
|
+
self._setup_window.show()
|
|
94
|
+
|
|
95
|
+
def set_fit_parameters(self, params: dict):
|
|
96
|
+
self._interpolation_params_dict = params
|
|
97
|
+
self.app.image_holder.set_polar_image_params(params)
|
|
98
|
+
|
|
99
|
+
def close_peaks_setup(self):
|
|
100
|
+
self._setup_window = None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class PolarDrawRoi(DrawRoiController):
|
|
104
|
+
|
|
105
|
+
def _update_roi(self, point: QPointF):
|
|
106
|
+
r1, r2 = self._init_point.x(), point.x()
|
|
107
|
+
p1, p2 = self._init_point.y(), point.y()
|
|
108
|
+
self._roi.radius, self._roi.width = (r1 + r2) / 2, abs(r2 - r1)
|
|
109
|
+
self._roi.angle, self._roi.angle_std = (p1 + p2) / 2, abs(p2 - p1)
|
|
110
|
+
|
|
111
|
+
def _init_roi(self) -> Roi:
|
|
112
|
+
return Roi(0, 0, 0, 0, type=RoiTypes.segment)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class InterpolateSetupWindow(BasicInputParametersWidget):
|
|
116
|
+
P = BasicInputParametersWidget.InputParameters
|
|
117
|
+
PARAMETER_TYPES = (P('r_size', 'Radius axis size', int),
|
|
118
|
+
P('phi_size', 'Angle axis size', int),
|
|
119
|
+
P('mode', 'Interpolation algorithm', str))
|
|
120
|
+
|
|
121
|
+
NAME = 'Interpolation parameters'
|
|
122
|
+
|
|
123
|
+
DEFAULT_DICT = dict(r_size=1024, phi_size=1024, mode='Bilinear')
|
|
124
|
+
|
|
125
|
+
def _get_layout(self,
|
|
126
|
+
input_parameter: BasicInputParametersWidget.InputParameters):
|
|
127
|
+
if input_parameter.name == 'mode':
|
|
128
|
+
return self._get_mode_layout(input_parameter)
|
|
129
|
+
else:
|
|
130
|
+
return super()._get_layout(input_parameter)
|
|
131
|
+
|
|
132
|
+
def _get_mode_layout(self, input_parameter: BasicInputParametersWidget.InputParameters):
|
|
133
|
+
|
|
134
|
+
current_value = self.default_dict.get(input_parameter.name, None)
|
|
135
|
+
if current_value is None:
|
|
136
|
+
current_value = next(iter(INTERPOLATION_ALGORITHMS.keys()))
|
|
137
|
+
label_widget = QLabel(input_parameter.label)
|
|
138
|
+
input_widget = QComboBox()
|
|
139
|
+
input_widget.setEditable(False)
|
|
140
|
+
input_widget.addItems(list(INTERPOLATION_ALGORITHMS.keys()))
|
|
141
|
+
input_widget.setCurrentText(current_value)
|
|
142
|
+
layout = QHBoxLayout()
|
|
143
|
+
layout.addWidget(label_widget, Qt.AlignHCenter)
|
|
144
|
+
layout.addWidget(input_widget, Qt.AlignHCenter)
|
|
145
|
+
if input_parameter.info:
|
|
146
|
+
info_button = InfoButton(input_parameter.info)
|
|
147
|
+
layout.addWidget(info_button, Qt.AlignLeft)
|
|
148
|
+
|
|
149
|
+
def get_input(*args):
|
|
150
|
+
return input_widget.currentText()
|
|
151
|
+
|
|
152
|
+
setattr(AbstractInputParametersWidget, input_parameter.name, property(get_input))
|
|
153
|
+
return layout
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from ..basic_widgets import PlotBC
|
|
4
|
+
from ...app.app import App
|
|
5
|
+
from ..roi_widgets.abstract_roi_holder import AbstractRoiHolder
|
|
6
|
+
from ..roi_widgets.roi_1d_widget import Roi1DAngular
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AngularProfileWidget(AbstractRoiHolder, PlotBC):
|
|
10
|
+
def __init__(self, parent=None):
|
|
11
|
+
AbstractRoiHolder.__init__(self, 'AngularProfile')
|
|
12
|
+
PlotBC.__init__(self, App().angular_profile, parent)
|
|
13
|
+
self._selected_key = None
|
|
14
|
+
|
|
15
|
+
# self.image_view.plot_item.setTitle('Angular Profile')
|
|
16
|
+
self.image_view.plot_item.getAxis('bottom').setLabel('Φ', color='white', font_size='large')
|
|
17
|
+
self.image_view.plot_item.getAxis('left').setLabel('Intensity', color='white', font_size='large')
|
|
18
|
+
|
|
19
|
+
def _init_connect(self):
|
|
20
|
+
App().image_holder.sigPolarImageChanged.connect(self._update)
|
|
21
|
+
App().image_holder.sigEmptyImage.connect(self.clear_plot)
|
|
22
|
+
self._roi_dict.sig_roi_created.connect(self._update)
|
|
23
|
+
self._roi_dict.sig_roi_deleted.connect(self._update)
|
|
24
|
+
self._roi_dict.sig_roi_moved.connect(self._update)
|
|
25
|
+
self._roi_dict.sig_roi_moved.connect(self._move_rois)
|
|
26
|
+
self._roi_dict.sig_selected.connect(self._update)
|
|
27
|
+
self._roi_dict.sig_one_selected.connect(self._update)
|
|
28
|
+
self._roi_dict.sig_fixed.connect(self._fix_rois)
|
|
29
|
+
self._roi_dict.sig_unfixed.connect(self._unfix_rois)
|
|
30
|
+
|
|
31
|
+
def _update(self):
|
|
32
|
+
selected_rois = self._roi_dict.selected_rois
|
|
33
|
+
|
|
34
|
+
if len(selected_rois) == 1:
|
|
35
|
+
selected_roi = selected_rois[0]
|
|
36
|
+
key = selected_roi.key
|
|
37
|
+
if key == self._selected_key:
|
|
38
|
+
self.profile.update()
|
|
39
|
+
else:
|
|
40
|
+
self._clear()
|
|
41
|
+
self._selected_key = key
|
|
42
|
+
self._create_roi((key, ))
|
|
43
|
+
self.profile.update()
|
|
44
|
+
else:
|
|
45
|
+
self._clear()
|
|
46
|
+
|
|
47
|
+
def _clear(self):
|
|
48
|
+
if self._selected_key is not None:
|
|
49
|
+
try:
|
|
50
|
+
self._delete_roi_widget(self._roi_widgets.pop(self._selected_key))
|
|
51
|
+
except KeyError:
|
|
52
|
+
pass
|
|
53
|
+
self._selected_key = None
|
|
54
|
+
self.clear_plot()
|
|
55
|
+
|
|
56
|
+
def _make_roi_widget(self, roi):
|
|
57
|
+
roi_widget = Roi1DAngular(roi)
|
|
58
|
+
self.image_view.plot_item.addItem(roi_widget)
|
|
59
|
+
return roi_widget
|
|
60
|
+
|
|
61
|
+
def _delete_roi_widget(self, roi_widget):
|
|
62
|
+
self.image_view.plot_item.removeItem(roi_widget)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from scipy.signal import find_peaks
|
|
6
|
+
|
|
7
|
+
from PyQt5.QtGui import QColor
|
|
8
|
+
from PyQt5.QtCore import QPointF
|
|
9
|
+
|
|
10
|
+
from ..basic_widgets import (ConfirmButton, DrawRoiController,
|
|
11
|
+
RoundedPushButton, PlotBC,
|
|
12
|
+
BlackToolBar, BasicInputParametersWidget)
|
|
13
|
+
from ...app.app import App
|
|
14
|
+
from ..tools import Icon
|
|
15
|
+
from ..roi_widgets.abstract_roi_holder import AbstractRoiHolder
|
|
16
|
+
from ..roi_widgets.roi_1d_widget import Roi1D
|
|
17
|
+
from ..tools import show_error
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RadialProfileWidget(AbstractRoiHolder, PlotBC):
|
|
23
|
+
|
|
24
|
+
def __init__(self, parent=None):
|
|
25
|
+
AbstractRoiHolder.__init__(self, 'RadialProfile')
|
|
26
|
+
PlotBC.__init__(self, profile=App().radial_profile, parent=parent)
|
|
27
|
+
self.app = App()
|
|
28
|
+
self.app.geometry_holder.sigScaleChanged.connect(self._update_axis)
|
|
29
|
+
self.app.image_holder.sigEmptyImage.connect(self.clear_plot)
|
|
30
|
+
self._init_radial_toolbars()
|
|
31
|
+
self._fit_params_dict: dict = PeaksSetupWindow.get_config()
|
|
32
|
+
self._peaks_setup = None
|
|
33
|
+
self._draw_roi = RadialDrawRoi(self.view_box, self)
|
|
34
|
+
self._draw_roi.sigCreateRoi.connect(self.app.roi_dict.add_roi)
|
|
35
|
+
self._draw_roi.sigMoveRoi.connect(self.app.roi_dict.move_roi)
|
|
36
|
+
|
|
37
|
+
self.register_key_patch()
|
|
38
|
+
|
|
39
|
+
# self.image_view.plot_item.setTitle('Radial Profile')
|
|
40
|
+
self.image_view.plot_item.getAxis('bottom').setLabel('|Q|', color='white', font_size='large')
|
|
41
|
+
self.image_view.plot_item.getAxis('left').setLabel('Intensity', color='white', font_size='large')
|
|
42
|
+
|
|
43
|
+
self.sigBackgroundChanged.connect(self.profile.save_state)
|
|
44
|
+
|
|
45
|
+
def _init_radial_toolbars(self):
|
|
46
|
+
|
|
47
|
+
fit_toolbar = BlackToolBar('Fitting', self)
|
|
48
|
+
self.addToolBar(fit_toolbar)
|
|
49
|
+
|
|
50
|
+
find_peaks_widget = ConfirmButton(Icon('find'), text='Find peaks?')
|
|
51
|
+
find_peaks_widget.label_widget.setStyleSheet(
|
|
52
|
+
'QLabel { color : white ; }')
|
|
53
|
+
find_peaks_widget.clicked.connect(self.find_peaks)
|
|
54
|
+
fit_toolbar.addWidget(find_peaks_widget)
|
|
55
|
+
#
|
|
56
|
+
# fit_peaks_widget = ConfirmButton(Icon('fit'), text='Fit selected peaks?')
|
|
57
|
+
# fit_peaks_widget.label_widget.setStyleSheet(
|
|
58
|
+
# 'QLabel { color : white ; }')
|
|
59
|
+
# fit_peaks_widget.clicked.connect(self.fit_selected)
|
|
60
|
+
# fit_toolbar.addWidget(fit_peaks_widget)
|
|
61
|
+
#
|
|
62
|
+
setup_action = fit_toolbar.addAction(Icon('setup'), 'Fit setup')
|
|
63
|
+
setup_action.triggered.connect(self.open_peaks_setup)
|
|
64
|
+
|
|
65
|
+
segments_toolbar = BlackToolBar('Segments', self)
|
|
66
|
+
self.addToolBar(segments_toolbar)
|
|
67
|
+
|
|
68
|
+
create_roi_widget = RoundedPushButton(
|
|
69
|
+
icon=Icon('add'), radius=30)
|
|
70
|
+
create_roi_widget.clicked.connect(lambda: self.app.roi_dict.create_roi())
|
|
71
|
+
segments_toolbar.addWidget(create_roi_widget)
|
|
72
|
+
|
|
73
|
+
delete_selected_widget = ConfirmButton(
|
|
74
|
+
Icon('delete'), text='Delete selected roi?')
|
|
75
|
+
delete_selected_widget.clicked.connect(self.app.roi_dict.delete_selected_roi)
|
|
76
|
+
delete_selected_widget.label_widget.setStyleSheet(
|
|
77
|
+
'QLabel { color : white ; }')
|
|
78
|
+
|
|
79
|
+
segments_toolbar.addWidget(delete_selected_widget)
|
|
80
|
+
fix_all = RoundedPushButton(icon=Icon('fix_all'), radius=120, background_color=QColor(0, 0, 0, 0))
|
|
81
|
+
fix_all.setFixedWidth(60)
|
|
82
|
+
fix_all.setFixedHeight(30)
|
|
83
|
+
fix_all.clicked.connect(self.app.roi_dict.fix_all)
|
|
84
|
+
segments_toolbar.addWidget(fix_all)
|
|
85
|
+
unfix_all = RoundedPushButton(icon=Icon('unfix_all'), radius=120, background_color=QColor(0, 0, 0, 0))
|
|
86
|
+
unfix_all.setFixedWidth(60)
|
|
87
|
+
unfix_all.setFixedHeight(30)
|
|
88
|
+
unfix_all.clicked.connect(self.app.roi_dict.unfix_all)
|
|
89
|
+
segments_toolbar.addWidget(unfix_all)
|
|
90
|
+
|
|
91
|
+
# def _on_scale_changed(self):
|
|
92
|
+
# self.update_x_axis()
|
|
93
|
+
#
|
|
94
|
+
#
|
|
95
|
+
def _update_axis(self):
|
|
96
|
+
self.x = App().geometry.r_axis
|
|
97
|
+
|
|
98
|
+
def find_peaks(self):
|
|
99
|
+
if self.y is None or self.x is None:
|
|
100
|
+
return
|
|
101
|
+
if self._fit_params_dict.get('sigma_find', None) is not None:
|
|
102
|
+
self.set_sigma(self._fit_params_dict['sigma_find'])
|
|
103
|
+
peaks = find_peaks(self.y)[0]
|
|
104
|
+
max_num = self._fit_params_dict.get('max_peaks_number', 40)
|
|
105
|
+
if len(peaks) > max_num:
|
|
106
|
+
show_error(
|
|
107
|
+
'Maximum number of peaks exceeded.',
|
|
108
|
+
error_title='Error',
|
|
109
|
+
info_text=f'Number of found peaks ({len(peaks)}) exceeds the maximum number {max_num}. '
|
|
110
|
+
f'Consider increasing sigma for smoothing the radial profile.')
|
|
111
|
+
return
|
|
112
|
+
w = self._fit_params_dict.get('init_width', 30) * App().geometry.scale
|
|
113
|
+
for r in peaks:
|
|
114
|
+
self._roi_dict.create_roi(radius=self.x[r], width=w)
|
|
115
|
+
|
|
116
|
+
def _make_roi_widget(self, roi):
|
|
117
|
+
roi_widget = Roi1D(roi)
|
|
118
|
+
self.image_view.plot_item.addItem(roi_widget)
|
|
119
|
+
return roi_widget
|
|
120
|
+
|
|
121
|
+
def _delete_roi_widget(self, roi_widget):
|
|
122
|
+
self.image_view.plot_item.removeItem(roi_widget)
|
|
123
|
+
|
|
124
|
+
def open_peaks_setup(self):
|
|
125
|
+
self._peaks_setup = PeaksSetupWindow()
|
|
126
|
+
self._peaks_setup.apply_signal.connect(self.set_fit_parameters)
|
|
127
|
+
self._peaks_setup.close_signal.connect(self.close_peaks_setup)
|
|
128
|
+
self._peaks_setup.show()
|
|
129
|
+
|
|
130
|
+
def set_fit_parameters(self, params: dict):
|
|
131
|
+
self._fit_params_dict = params
|
|
132
|
+
|
|
133
|
+
def close_peaks_setup(self):
|
|
134
|
+
self._peaks_setup = None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class RadialDrawRoi(DrawRoiController):
|
|
138
|
+
def _update_roi(self, point: QPointF):
|
|
139
|
+
r1, r2 = self._init_point.x(), point.x()
|
|
140
|
+
self._roi.radius, self._roi.width = (r1 + r2) / 2, abs(r2 - r1)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class PeaksSetupWindow(BasicInputParametersWidget):
|
|
144
|
+
P = BasicInputParametersWidget.InputParameters
|
|
145
|
+
|
|
146
|
+
PARAMETER_TYPES = (P('max_peaks_number',
|
|
147
|
+
'Maximum number of peaks', int, 'Do not recommended to put high numbers'),
|
|
148
|
+
P('init_width', 'Peaks width', float,
|
|
149
|
+
'Gaussian fitting will start with this number'),
|
|
150
|
+
P('sigma_find', 'Sigma to find peaks', float,
|
|
151
|
+
'Default sigma value for gaussian smooth\n'
|
|
152
|
+
'applied before initial peaks finding to\n'
|
|
153
|
+
'avoid noise peaks. To use current lambda, \n'
|
|
154
|
+
'leave empty.', True),
|
|
155
|
+
P('sigma_fit', 'Sigma to find peaks', float,
|
|
156
|
+
'Default sigma value for gaussian smooth\n'
|
|
157
|
+
'applied before gaussian fitting of \n'
|
|
158
|
+
'found peaks. To use current lambda, \n'
|
|
159
|
+
'leave empty.', True)
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
NAME = 'Fitting parameters'
|
|
163
|
+
|
|
164
|
+
DEFAULT_DICT = dict(max_peaks_number=20, init_width=30, sigma_find=8)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from PyQt5.QtWidgets import QTabWidget
|
|
2
|
+
|
|
3
|
+
from .cif_results import CIFRingsWidget
|
|
4
|
+
from .project_viewer import FileViewer
|
|
5
|
+
from .roi_widget import RoiMetaWidget
|
|
6
|
+
from .cif_files_widget import CIFFileWidget
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MainFileWidget(QTabWidget):
|
|
10
|
+
def __init__(self, app , parent=None):
|
|
11
|
+
super().__init__(parent)
|
|
12
|
+
self.cif_rois_widget = CIFRingsWidget(self)
|
|
13
|
+
self.setTabPosition(QTabWidget.West)
|
|
14
|
+
self.addTab(FileViewer(app.fm, self), 'Files')
|
|
15
|
+
self.addTab(RoiMetaWidget(self), 'Labeled ROIs')
|
|
16
|
+
self.addTab(CIFFileWidget(app, self), 'CIF-Files')
|
|
17
|
+
self.addTab(self.cif_rois_widget, 'CIF ROIs')
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from PyQt5.QtWidgets import (QGridLayout, QTableWidget, QTableWidgetItem,
|
|
3
|
+
QLineEdit, QPushButton, QVBoxLayout, QWidget, QCheckBox, QMenu, QSlider)
|
|
4
|
+
from PyQt5.QtGui import QIntValidator, QDoubleValidator, QCursor
|
|
5
|
+
from PyQt5 import QtCore
|
|
6
|
+
from mlgidGUI.app.cif_rois.cif_peaks_calculation import calculate_cif_peaks, cif_results
|
|
7
|
+
from mlgidGUI.gui.tools import show_info
|
|
8
|
+
PARAM_LIST = [' ','Name','Powder\ndiffraction','\nh','contact plane\nk','\nl','energy [eV]','show_only the ..%\nhighest intensities']
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class CIFFileRow():
|
|
12
|
+
cif_key: None
|
|
13
|
+
row_num: int
|
|
14
|
+
filename: str
|
|
15
|
+
show_button: QPushButton
|
|
16
|
+
random_button: QCheckBox
|
|
17
|
+
orientation1: QTableWidgetItem
|
|
18
|
+
orientation2: QTableWidgetItem
|
|
19
|
+
orientation3: QTableWidgetItem
|
|
20
|
+
en: QTableWidgetItem
|
|
21
|
+
|
|
22
|
+
class CIFFileWidget(QWidget):
|
|
23
|
+
|
|
24
|
+
def __init__(self, app, parent=None):
|
|
25
|
+
QWidget.__init__(self, parent)
|
|
26
|
+
self._app = app
|
|
27
|
+
self._fm = app.fm
|
|
28
|
+
self.parent = parent
|
|
29
|
+
self._fm.sigNewCIFFile.connect(self.update_view)
|
|
30
|
+
self.input_content_dict = None
|
|
31
|
+
# Create the table widget
|
|
32
|
+
self.tableWidget = QTableWidget(self)
|
|
33
|
+
self.tableWidget.setRowCount(0) # Set initial row count
|
|
34
|
+
self.tableWidget.setColumnCount(len(PARAM_LIST)) # Set two columns
|
|
35
|
+
self.tableWidget.setHorizontalHeaderLabels(PARAM_LIST)
|
|
36
|
+
|
|
37
|
+
# Create the "Add Entry" button
|
|
38
|
+
self.add_button = QPushButton("Add CIF File", self)
|
|
39
|
+
self.add_button.clicked.connect(lambda: self._app.parent.main_window._add_file_dialog(cif=True))
|
|
40
|
+
|
|
41
|
+
# Set up layout
|
|
42
|
+
layout = QVBoxLayout()
|
|
43
|
+
layout.addWidget(self.tableWidget)
|
|
44
|
+
layout.addWidget(self.add_button)
|
|
45
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
46
|
+
|
|
47
|
+
central_widget = QWidget()
|
|
48
|
+
central_widget.setLayout(layout)
|
|
49
|
+
layout = QGridLayout(self)
|
|
50
|
+
layout.addWidget(central_widget)
|
|
51
|
+
|
|
52
|
+
self.tableWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
|
|
53
|
+
self.tableWidget.customContextMenuRequested.connect(self.mouseMenu)
|
|
54
|
+
|
|
55
|
+
self.cif_files = {}
|
|
56
|
+
|
|
57
|
+
def update_view(self):
|
|
58
|
+
self.tableWidget.setRowCount(0)
|
|
59
|
+
self.cif_files = {}
|
|
60
|
+
for cif_path_key in self._fm._project_structure.root._cif_files:
|
|
61
|
+
self._add_new_cif_to_view(cif_path_key)
|
|
62
|
+
self._display_cif_peaks()
|
|
63
|
+
|
|
64
|
+
def _add_new_cif_to_view(self, cif_key: str):
|
|
65
|
+
|
|
66
|
+
show_button = QPushButton("")
|
|
67
|
+
random_button = QPushButton("")
|
|
68
|
+
row_num = self.tableWidget.rowCount()
|
|
69
|
+
int_val = QIntValidator(0,100)
|
|
70
|
+
float_val = QDoubleValidator(0, 90, 4)
|
|
71
|
+
orientation1 = QLineEdit('0')
|
|
72
|
+
orientation1.setValidator(int_val)
|
|
73
|
+
orientation1.setMaxLength(3)
|
|
74
|
+
orientation1.setMaximumWidth(40)
|
|
75
|
+
orientation1.setAlignment(QtCore.Qt.AlignHCenter)
|
|
76
|
+
orientation2 = QLineEdit('0')
|
|
77
|
+
orientation2.setValidator(int_val)
|
|
78
|
+
orientation2.setMaxLength(3)
|
|
79
|
+
orientation2.setMaximumWidth(40)
|
|
80
|
+
orientation2.setAlignment(QtCore.Qt.AlignHCenter)
|
|
81
|
+
orientation3 = QLineEdit('1')
|
|
82
|
+
orientation3.setValidator(int_val)
|
|
83
|
+
orientation3.setMaxLength(3)
|
|
84
|
+
orientation3.setMaximumWidth(40)
|
|
85
|
+
orientation3.setAlignment(QtCore.Qt.AlignHCenter)
|
|
86
|
+
slider = QSlider(QtCore.Qt.Horizontal)
|
|
87
|
+
slider.setMinimum(0)
|
|
88
|
+
slider.setMaximum(100)
|
|
89
|
+
slider.setValue(0)
|
|
90
|
+
slider.sliderReleased.connect(lambda: self.slider_released(slider))
|
|
91
|
+
|
|
92
|
+
en = QLineEdit('18000')
|
|
93
|
+
en.setValidator(float_val)
|
|
94
|
+
en.setAlignment(QtCore.Qt.AlignHCenter)
|
|
95
|
+
|
|
96
|
+
self.cif_files[cif_key.name] = CIFFileRow(
|
|
97
|
+
cif_key = cif_key,
|
|
98
|
+
row_num=row_num,
|
|
99
|
+
filename=cif_key.name,
|
|
100
|
+
show_button = show_button,
|
|
101
|
+
random_button = random_button,
|
|
102
|
+
orientation1 = orientation1,
|
|
103
|
+
orientation2 = orientation2,
|
|
104
|
+
orientation3 = orientation3,
|
|
105
|
+
en = en
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
self.tableWidget.insertRow(row_num)
|
|
109
|
+
self._set_show_button_text(show_button, cif_key)
|
|
110
|
+
show_button.clicked.connect(lambda: self._show_button_clicked(show_button, cif_key))
|
|
111
|
+
|
|
112
|
+
self.tableWidget.setCellWidget(row_num, 0, show_button)
|
|
113
|
+
self.tableWidget.setItem(row_num, 1, QTableWidgetItem(cif_key.name))
|
|
114
|
+
|
|
115
|
+
self.tableWidget.setCellWidget(row_num, 2, random_button)
|
|
116
|
+
self._set_random_button(random_button, cif_key)
|
|
117
|
+
random_button.clicked.connect(lambda: self._random_button_clicked(random_button, cif_key))
|
|
118
|
+
|
|
119
|
+
self.tableWidget.setCellWidget(row_num, 7, slider)
|
|
120
|
+
self.tableWidget.setCellWidget(row_num, 3, orientation1)
|
|
121
|
+
self.tableWidget.setCellWidget(row_num, 4, orientation2)
|
|
122
|
+
orientation2.setMaximumWidth(self.tableWidget.columnWidth(4))
|
|
123
|
+
self.tableWidget.setCellWidget(row_num, 5, orientation3)
|
|
124
|
+
self.tableWidget.setCellWidget(row_num, 6, en)
|
|
125
|
+
en.setMaximumWidth(self.tableWidget.columnWidth(6))
|
|
126
|
+
|
|
127
|
+
self.tableWidget.resizeColumnsToContents()
|
|
128
|
+
self.tableWidget.resizeRowsToContents()
|
|
129
|
+
|
|
130
|
+
def slider_released(self, slider):
|
|
131
|
+
self._app.image_holder.sigCIFPeaksChanged.emit(slider.value()/100)
|
|
132
|
+
|
|
133
|
+
def _set_show_button_text(self, button, cif_key):
|
|
134
|
+
if cif_key.is_visible():
|
|
135
|
+
button.setText("Hide")
|
|
136
|
+
else:
|
|
137
|
+
button.setText("Show")
|
|
138
|
+
|
|
139
|
+
def _set_random_button(self, button, cif_key):
|
|
140
|
+
if cif_key.powder_diffraction:
|
|
141
|
+
button.setText("Deactivate")
|
|
142
|
+
else:
|
|
143
|
+
button.setText("Activate")
|
|
144
|
+
|
|
145
|
+
def _random_button_clicked(self, button, cif_key):
|
|
146
|
+
cif_key.change_powder_diffraction()
|
|
147
|
+
self._display_cif_peaks()
|
|
148
|
+
self._set_random_button(button, cif_key)
|
|
149
|
+
|
|
150
|
+
def _show_button_clicked(self, button, cif_key):
|
|
151
|
+
orientation = [int(self.cif_files[cif_key.name].orientation1.text()),
|
|
152
|
+
int(self.cif_files[cif_key.name].orientation2.text()),
|
|
153
|
+
int(self.cif_files[cif_key.name].orientation3.text())]
|
|
154
|
+
if all(v == 0 for v in orientation):
|
|
155
|
+
raise Exception('all orientations 0 is not allowed')
|
|
156
|
+
cif_key.orientation = orientation
|
|
157
|
+
cif_key.en = float(self.cif_files[cif_key.name].en.text())
|
|
158
|
+
cif_key.change_show_hide()
|
|
159
|
+
|
|
160
|
+
self._display_cif_peaks()
|
|
161
|
+
self._set_show_button_text(button, cif_key)
|
|
162
|
+
|
|
163
|
+
def _display_cif_peaks(self):
|
|
164
|
+
error_key = calculate_cif_peaks(self._fm._project_structure.root, self._fm.current_key)
|
|
165
|
+
if error_key is not None:
|
|
166
|
+
show_info('Error with CIF File', 'CIF File ' + error_key.name + ' could not be calculated, check content!')
|
|
167
|
+
self._fm._project_structure.root._cif_files.remove(error_key)
|
|
168
|
+
self.update_view()
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
self.parent.cif_rois_widget.delete_all()
|
|
172
|
+
if bool(cif_results):
|
|
173
|
+
for key, cif_result in cif_results.items():
|
|
174
|
+
self.parent.cif_rois_widget._make_roi_widget(cif_result)
|
|
175
|
+
else:
|
|
176
|
+
self.parent.cif_rois_widget.empty_simulation()
|
|
177
|
+
self.parent.cif_rois_widget.resizeColumns()
|
|
178
|
+
self._app.image_holder.sigCIFPeaksChanged.emit(0)
|
|
179
|
+
|
|
180
|
+
def mouseMenu(self, pos):
|
|
181
|
+
selected = self.tableWidget.selectedIndexes()
|
|
182
|
+
if not selected:
|
|
183
|
+
return
|
|
184
|
+
menu = QMenu()
|
|
185
|
+
deleteAction = menu.addAction('Delete CIF-File')
|
|
186
|
+
deleteAction.triggered.connect(lambda: self.removeRows(selected))
|
|
187
|
+
menu.exec_(QCursor.pos())
|
|
188
|
+
|
|
189
|
+
def removeRows(self, indexes):
|
|
190
|
+
rows = set(index.row() for index in indexes)
|
|
191
|
+
for row in sorted(rows, reverse=True):
|
|
192
|
+
self.tableWidget.removeRow(row)
|
|
193
|
+
for cif_file_row in self.cif_files:
|
|
194
|
+
if self.cif_files[cif_file_row].row_num == row:
|
|
195
|
+
self._fm._project_structure.root._cif_files.remove(self.cif_files[cif_file_row].cif_key)
|
|
196
|
+
self.update_view()
|