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,150 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtGui import QCursor, QRegExpValidator
|
|
4
|
+
from PyQt5.QtWidgets import QMenu, QWidgetAction, QLineEdit
|
|
5
|
+
from PyQt5.QtCore import QRegExp
|
|
6
|
+
|
|
7
|
+
from ...app.app import App
|
|
8
|
+
from ...app.rois.roi import Roi, RoiTypes
|
|
9
|
+
from .confidence_level_widget import SetConfidenceLevelWidget
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AbstractRoiContextMenu(QMenu):
|
|
13
|
+
|
|
14
|
+
def __init__(self, roi: Roi):
|
|
15
|
+
QMenu.__init__(self)
|
|
16
|
+
self.roi = roi
|
|
17
|
+
self.key = roi.key
|
|
18
|
+
self.roi_dict = App().roi_dict
|
|
19
|
+
self._init_menu()
|
|
20
|
+
|
|
21
|
+
if App().debug_tracker:
|
|
22
|
+
App().debug_tracker.add_object(self)
|
|
23
|
+
|
|
24
|
+
self.exec_(QCursor.pos())
|
|
25
|
+
# self.exec_(ev.globalPos())
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class RoiContextMenu(AbstractRoiContextMenu):
|
|
29
|
+
def _init_menu(self):
|
|
30
|
+
self._init_rename_menu()
|
|
31
|
+
self._init_conf_level_menu()
|
|
32
|
+
self._init_cif_file_menu()
|
|
33
|
+
self.addSeparator()
|
|
34
|
+
self._init_type_menu()
|
|
35
|
+
self.addSeparator()
|
|
36
|
+
self._init_fix_menu()
|
|
37
|
+
self.addSeparator()
|
|
38
|
+
self._init_copy_menu()
|
|
39
|
+
self.addSeparator()
|
|
40
|
+
self._init_select_menu()
|
|
41
|
+
self.addSeparator()
|
|
42
|
+
self._init_fit_menu()
|
|
43
|
+
self.addSeparator()
|
|
44
|
+
self._init_delete_menu()
|
|
45
|
+
|
|
46
|
+
def _init_fix_menu(self):
|
|
47
|
+
fix_menu = self.addMenu('Fix/Unfix')
|
|
48
|
+
if self.roi.movable:
|
|
49
|
+
fix_action = fix_menu.addAction('Fix roi')
|
|
50
|
+
fix_action.triggered.connect(lambda: self.roi_dict.fix_roi(self.key))
|
|
51
|
+
else:
|
|
52
|
+
fix_action = fix_menu.addAction('Unfix roi')
|
|
53
|
+
fix_action.triggered.connect(lambda: self.roi_dict.unfix_roi(self.key))
|
|
54
|
+
|
|
55
|
+
fix_selected = fix_menu.addAction('Fix selected roi')
|
|
56
|
+
fix_selected.triggered.connect(self.roi_dict.fix_selected)
|
|
57
|
+
unfix_selected = fix_menu.addAction('Unfix selected roi')
|
|
58
|
+
unfix_selected.triggered.connect(self.roi_dict.unfix_selected)
|
|
59
|
+
|
|
60
|
+
fix_all = fix_menu.addAction('Fix all roi')
|
|
61
|
+
fix_all.triggered.connect(self.roi_dict.fix_all)
|
|
62
|
+
|
|
63
|
+
unfix_all = fix_menu.addAction('Unix all roi')
|
|
64
|
+
unfix_all.triggered.connect(self.roi_dict.unfix_all)
|
|
65
|
+
|
|
66
|
+
def _init_delete_menu(self):
|
|
67
|
+
delete_menu = self.addMenu('Delete')
|
|
68
|
+
delete_self = delete_menu.addAction('Delete this roi')
|
|
69
|
+
delete_self.triggered.connect(lambda: self.roi_dict.delete_roi(self.key))
|
|
70
|
+
delete_selected = delete_menu.addAction('Delete selected')
|
|
71
|
+
delete_selected.triggered.connect(self.roi_dict.delete_selected_roi)
|
|
72
|
+
|
|
73
|
+
def _init_select_menu(self):
|
|
74
|
+
select_menu = self.addMenu('Select')
|
|
75
|
+
select_all = select_menu.addAction('Select all')
|
|
76
|
+
select_all.triggered.connect(self.roi_dict.select_all)
|
|
77
|
+
unselect_all = select_menu.addAction('Unselect all')
|
|
78
|
+
unselect_all.triggered.connect(self.roi_dict.unselect_all)
|
|
79
|
+
|
|
80
|
+
def _init_rename_menu(self):
|
|
81
|
+
rename = self.addMenu('Rename')
|
|
82
|
+
rename_action = QWidgetAction(self)
|
|
83
|
+
line_edit = QLineEdit(self.roi.name)
|
|
84
|
+
line_edit.editingFinished.connect(
|
|
85
|
+
lambda: self.roi_dict.change_name(self.key, line_edit.text())
|
|
86
|
+
)
|
|
87
|
+
rename_action.setDefaultWidget(line_edit)
|
|
88
|
+
rename.addAction(rename_action)
|
|
89
|
+
|
|
90
|
+
def _init_conf_level_menu(self):
|
|
91
|
+
conf_level = self.addAction(f'Change confidence ({self.roi.confidence_level_name})')
|
|
92
|
+
conf_level.triggered.connect(self._change_confidence_widget)
|
|
93
|
+
|
|
94
|
+
def _init_cif_file_menu(self):
|
|
95
|
+
cif_file = self.addMenu('Change cif_file')
|
|
96
|
+
rename_action = QWidgetAction(self)
|
|
97
|
+
line_edit = QLineEdit(str(self.roi.cif_file))
|
|
98
|
+
rx = QRegExp("^[A-Za-z0-9]*$")
|
|
99
|
+
validator = QRegExpValidator(rx, line_edit)
|
|
100
|
+
line_edit.setValidator(validator)
|
|
101
|
+
line_edit.editingFinished.connect(
|
|
102
|
+
lambda: self.roi_dict.change_cif_file(self.key, line_edit.text())
|
|
103
|
+
)
|
|
104
|
+
rename_action.setDefaultWidget(line_edit)
|
|
105
|
+
cif_file.addAction(rename_action)
|
|
106
|
+
|
|
107
|
+
def _change_confidence_widget(self, *args):
|
|
108
|
+
widget = SetConfidenceLevelWidget(self.roi.confidence_level_name)
|
|
109
|
+
widget.sigSetConfidenceLevel.connect(self._conf_level_changed)
|
|
110
|
+
widget.move(QCursor.pos())
|
|
111
|
+
widget.show()
|
|
112
|
+
self._conf_widget = widget
|
|
113
|
+
|
|
114
|
+
def _conf_level_changed(self, level: float):
|
|
115
|
+
self.roi_dict.change_conf_level(self.roi.key, level)
|
|
116
|
+
|
|
117
|
+
def _init_type_menu(self):
|
|
118
|
+
available_types = []
|
|
119
|
+
roi = self.roi
|
|
120
|
+
|
|
121
|
+
if not roi.type == RoiTypes.segment:
|
|
122
|
+
available_types.append(('segment', RoiTypes.segment))
|
|
123
|
+
if not roi.type == RoiTypes.ring:
|
|
124
|
+
available_types.append(('ring', RoiTypes.ring))
|
|
125
|
+
if not roi.type == RoiTypes.background:
|
|
126
|
+
available_types.append(('background', RoiTypes.background))
|
|
127
|
+
|
|
128
|
+
for name, new_type in available_types:
|
|
129
|
+
change_type_action = self.addAction(f'Change type to {name}')
|
|
130
|
+
change_type_action.triggered.connect(
|
|
131
|
+
lambda *x, t=new_type: self._change_roi_type(t))
|
|
132
|
+
|
|
133
|
+
def _change_roi_type(self, new_type: RoiTypes):
|
|
134
|
+
self.roi.type = new_type
|
|
135
|
+
self.roi_dict.change_roi_type(self.key)
|
|
136
|
+
|
|
137
|
+
def _init_fit_menu(self):
|
|
138
|
+
fit_menu = self.addMenu('Fit')
|
|
139
|
+
fit_selected = fit_menu.addAction('Fit selected rois')
|
|
140
|
+
fit_selected.triggered.connect(lambda: self.roi_dict.open_fit_rois(True))
|
|
141
|
+
fit_selected = fit_menu.addAction('Fit all rois')
|
|
142
|
+
fit_selected.triggered.connect(lambda: self.roi_dict.open_fit_rois(False))
|
|
143
|
+
|
|
144
|
+
def _init_copy_menu(self):
|
|
145
|
+
copy_menu = self.addMenu('Copy/Paste')
|
|
146
|
+
copy_menu.addAction('Copy roi', lambda: self.roi_dict.copy_rois(self.roi.key))
|
|
147
|
+
copy_menu.addAction('Copy selected rois', lambda: self.roi_dict.copy_rois('selected'))
|
|
148
|
+
copy_menu.addAction('Copy all rois', lambda: self.roi_dict.copy_rois('all'))
|
|
149
|
+
if self.roi_dict.is_copied:
|
|
150
|
+
copy_menu.addAction('Paste rois', lambda: self.roi_dict.paste_rois())
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Dict, Tuple
|
|
2
|
+
from itertools import product
|
|
3
|
+
|
|
4
|
+
from PyQt5.QtWidgets import QWidget, QGridLayout
|
|
5
|
+
from PyQt5.QtCore import pyqtSignal, QObject
|
|
6
|
+
from PyQt5.QtGui import QColor
|
|
7
|
+
|
|
8
|
+
from pyqtgraph import ColorButton
|
|
9
|
+
|
|
10
|
+
from ...app.rois import RoiTypes
|
|
11
|
+
from ..basic_widgets import Label
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SelectRoiColorWidget(QWidget):
|
|
16
|
+
sigColorChanged = pyqtSignal(tuple, QColor)
|
|
17
|
+
sigColorChanging = pyqtSignal(tuple, QColor)
|
|
18
|
+
|
|
19
|
+
def __init__(self, colors_dict: RoiColorsDict, parent=None, font_size: int = 12):
|
|
20
|
+
super().__init__(parent)
|
|
21
|
+
self.setFixedSize(450, 500)
|
|
22
|
+
self.setWindowTitle('Select roi colors')
|
|
23
|
+
self._color_dict: RoiColorsDict = colors_dict
|
|
24
|
+
self._label_props: dict = {'font_size': font_size}
|
|
25
|
+
self._color_buttons: dict = {}
|
|
26
|
+
|
|
27
|
+
self._init_ui()
|
|
28
|
+
|
|
29
|
+
def _init_ui(self):
|
|
30
|
+
layout = self._layout = QGridLayout(self)
|
|
31
|
+
layout.addWidget(Label('Type', self, bold=True, **self._label_props), 0, 0)
|
|
32
|
+
layout.addWidget(Label('Selected', self, bold=True, **self._label_props), 0, 1)
|
|
33
|
+
layout.addWidget(Label('Fixed', self, bold=True, **self._label_props), 0, 2)
|
|
34
|
+
layout.addWidget(Label('Color', self, bold=True, **self._label_props), 0, 3)
|
|
35
|
+
|
|
36
|
+
for row, (roi_type, selected, fixed) in enumerate(
|
|
37
|
+
product((RoiTypes.ring, RoiTypes.segment, RoiTypes.background),
|
|
38
|
+
(True, False),
|
|
39
|
+
(True, False)
|
|
40
|
+
), 1
|
|
41
|
+
):
|
|
42
|
+
self._add_row(row, roi_type, selected, fixed)
|
|
43
|
+
|
|
44
|
+
def _add_row(self, row: int, roi_type: RoiTypes, selected: bool, fixed: bool):
|
|
45
|
+
color_button = self._create_color_button((roi_type, selected, fixed))
|
|
46
|
+
layout = self._layout
|
|
47
|
+
|
|
48
|
+
layout.addWidget(Label(roi_type.name, self, **self._label_props), row, 0)
|
|
49
|
+
layout.addWidget(Label('Yes' if selected else 'No', self, **self._label_props), row, 1)
|
|
50
|
+
layout.addWidget(Label('Yes' if fixed else 'No', self, **self._label_props), row, 2)
|
|
51
|
+
layout.addWidget(color_button, row, 3)
|
|
52
|
+
|
|
53
|
+
def _create_color_button(self, key: tuple) -> ColorButton:
|
|
54
|
+
color: QColor = self._color_dict.get(key, QColor(0, 0, 255))
|
|
55
|
+
self._color_buttons[key] = color_button = ColorButton(self, color)
|
|
56
|
+
color_button.sigColorChanged.connect(lambda btn: self.sigColorChanged.emit(key, btn.color()))
|
|
57
|
+
color_button.sigColorChanging.connect(lambda btn: self.sigColorChanging.emit(key, btn.color()))
|
|
58
|
+
return color_button
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
from typing import List, Dict
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
|
|
5
|
+
from PyQt5.QtWidgets import QWidget, QGridLayout, QPushButton
|
|
6
|
+
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal
|
|
7
|
+
|
|
8
|
+
from ...app.app import App
|
|
9
|
+
from ...app.file_manager import ImageKey, FolderKey
|
|
10
|
+
from ...app.data_manager import SaveFormats, SaveMode, SavingParameters
|
|
11
|
+
from ..tools import Icon, show_info
|
|
12
|
+
|
|
13
|
+
from .select_images import SelectImagesWindow
|
|
14
|
+
from .options_widgets import OptionsWidget
|
|
15
|
+
from .format_box import FormatBox
|
|
16
|
+
from .save_mode_box import SaveModeBox
|
|
17
|
+
from .num_selected_widget import NumSelectedWidget
|
|
18
|
+
from ..basic_widgets.path_line import PathLineModes, H5PathLine
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class SaveWindow(QWidget):
|
|
22
|
+
sigSaveClicked = pyqtSignal(SavingParameters)
|
|
23
|
+
|
|
24
|
+
def __init__(self, parent=None, saving_params: SavingParameters = None):
|
|
25
|
+
super().__init__(parent)
|
|
26
|
+
self.setWindowTitle('Save Project')
|
|
27
|
+
self.setWindowIcon(Icon('window_icon'))
|
|
28
|
+
self.setWindowFlag(Qt.Window, True)
|
|
29
|
+
self.setWindowModality(Qt.WindowModal)
|
|
30
|
+
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
|
31
|
+
self.app = App()
|
|
32
|
+
self._all_images = self.app.data_manager.get_paths_dict(skip_empty_images=False)
|
|
33
|
+
self._all_labeled_images = self.app.data_manager.get_paths_dict(skip_empty_images=True)
|
|
34
|
+
|
|
35
|
+
self._params: SavingParameters = saving_params or SavingParameters(
|
|
36
|
+
deepcopy(self._all_labeled_images), Path('~').expanduser()
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
self._init_ui()
|
|
40
|
+
self._init_layout()
|
|
41
|
+
self._init_connections()
|
|
42
|
+
|
|
43
|
+
if self.app.debug_tracker:
|
|
44
|
+
self.app.debug_tracker.add_object(self, 'SaveWindow')
|
|
45
|
+
|
|
46
|
+
def _init_ui(self):
|
|
47
|
+
self._select_images_window = None
|
|
48
|
+
self.save_mode_box = SaveModeBox(self)
|
|
49
|
+
self.path_line = H5PathLine(parent=self)
|
|
50
|
+
|
|
51
|
+
self.format_box = FormatBox(self)
|
|
52
|
+
self.options_widget = OptionsWidget(self._params, self)
|
|
53
|
+
self.num_select_widget = NumSelectedWidget(self._params, self)
|
|
54
|
+
|
|
55
|
+
self.save_button = QPushButton('Save', self)
|
|
56
|
+
self.cancel_button = QPushButton('Cancel', self)
|
|
57
|
+
|
|
58
|
+
def _init_layout(self):
|
|
59
|
+
layout = QGridLayout(self)
|
|
60
|
+
layout.addWidget(self.save_mode_box, 0, 0)
|
|
61
|
+
layout.addWidget(self.path_line, 0, 1, 1, 2)
|
|
62
|
+
|
|
63
|
+
layout.addWidget(self.format_box, 1, 0)
|
|
64
|
+
layout.addWidget(self.options_widget.bool_options, 2, 0)
|
|
65
|
+
layout.addWidget(self.options_widget.text_options, 2, 1)
|
|
66
|
+
layout.addWidget(self.num_select_widget, 2, 2)
|
|
67
|
+
layout.addWidget(self.save_button, 3, 0)
|
|
68
|
+
layout.addWidget(self.cancel_button, 3, 1)
|
|
69
|
+
|
|
70
|
+
self.setMinimumWidth(600)
|
|
71
|
+
|
|
72
|
+
def _init_connections(self):
|
|
73
|
+
self.num_select_widget.sigSelectManuallyClicked.connect(self._select_images_clicked)
|
|
74
|
+
self.num_select_widget.sigSkipUnlabelledClicked.connect(self._select_images_auto)
|
|
75
|
+
self.format_box.sigFormatChanged.connect(self._format_changed)
|
|
76
|
+
self.save_mode_box.sigSaveModeChanged.connect(self._save_mode_changed)
|
|
77
|
+
self.save_button.clicked.connect(self._save_clicked)
|
|
78
|
+
self.cancel_button.clicked.connect(self.close)
|
|
79
|
+
|
|
80
|
+
@pyqtSlot(int)
|
|
81
|
+
def _select_images_auto(self, skip_unlabelled_imgs):
|
|
82
|
+
if skip_unlabelled_imgs:
|
|
83
|
+
self._params.selected_images = deepcopy(self._all_labeled_images)
|
|
84
|
+
else:
|
|
85
|
+
self._params.selected_images = deepcopy(self._all_images)
|
|
86
|
+
self.num_select_widget.update_params()
|
|
87
|
+
|
|
88
|
+
@pyqtSlot(name='selectImagesClicked')
|
|
89
|
+
def _select_images_clicked(self):
|
|
90
|
+
select_images_window = SelectImagesWindow(deepcopy(self._all_images), self)
|
|
91
|
+
select_images_window.show()
|
|
92
|
+
select_images_window.sigApplyClicked.connect(self._set_selected_images)
|
|
93
|
+
|
|
94
|
+
def update_params(self):
|
|
95
|
+
self.path_line.update_params(self._params)
|
|
96
|
+
self.format_box.update_params(self._params)
|
|
97
|
+
self.options_widget.update_params(self._params)
|
|
98
|
+
|
|
99
|
+
def is_valid(self) -> bool:
|
|
100
|
+
return self.path_line.is_valid
|
|
101
|
+
|
|
102
|
+
def not_valid_action(self):
|
|
103
|
+
self.path_line.not_valid_action()
|
|
104
|
+
|
|
105
|
+
@pyqtSlot(name='saveClicked')
|
|
106
|
+
def _save_clicked(self):
|
|
107
|
+
self.update_params()
|
|
108
|
+
#check provided path
|
|
109
|
+
if self.is_valid():
|
|
110
|
+
self.sigSaveClicked.emit(self._params)
|
|
111
|
+
#check if save was successful, otherwise keep the window open
|
|
112
|
+
if self.app.data_manager.last_save_successfull:
|
|
113
|
+
show_info(
|
|
114
|
+
title='Data is saved',
|
|
115
|
+
txt=f'{self._params.num_images} images saved to {str(self._params.path)}'
|
|
116
|
+
)
|
|
117
|
+
self.close()
|
|
118
|
+
else:
|
|
119
|
+
self.not_valid_action()
|
|
120
|
+
else:
|
|
121
|
+
self.not_valid_action()
|
|
122
|
+
|
|
123
|
+
@pyqtSlot(dict, name='setSelectedImages')
|
|
124
|
+
def _set_selected_images(self, path_dict: Dict[FolderKey, List[ImageKey]]):
|
|
125
|
+
self._params.selected_images = dict(path_dict)
|
|
126
|
+
self.num_select_widget.update_params()
|
|
127
|
+
|
|
128
|
+
@pyqtSlot(SaveFormats, name='formatChanged')
|
|
129
|
+
def _format_changed(self, save_format: SaveFormats):
|
|
130
|
+
self.options_widget.set_format(save_format, self._params)
|
|
131
|
+
self.update_params()
|
|
132
|
+
self.path_line.set_mode(_get_path_line_mode(save_format, self.save_mode_box.mode))
|
|
133
|
+
self.path_line.set_path(_get_path_line_mode(self.format_box.save_format, self.save_mode_box.mode))
|
|
134
|
+
|
|
135
|
+
@pyqtSlot(SaveMode, name='saveModeChanged')
|
|
136
|
+
def _save_mode_changed(self, save_mode: SaveMode):
|
|
137
|
+
self.path_line.set_mode(_get_path_line_mode(self.format_box.save_format, save_mode))
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
_PATH_MODE_DICT: Dict[tuple, PathLineModes] = {
|
|
141
|
+
(SaveFormats.entire_h5.name, SaveMode.create.name): PathLineModes.new_file,
|
|
142
|
+
(SaveFormats.entire_h5.name, SaveMode.add.name): PathLineModes.existing_file,
|
|
143
|
+
(SaveFormats.object_detection.name, SaveMode.create.name): PathLineModes.new_dir,
|
|
144
|
+
(SaveFormats.text.name, SaveMode.create.name): PathLineModes.new_dir,
|
|
145
|
+
(SaveFormats.text.name, SaveMode.add.name): PathLineModes.existing_dir,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
def _get_path_line_mode(save_format: SaveFormats, save_mode: SaveMode):
|
|
149
|
+
try:
|
|
150
|
+
return _PATH_MODE_DICT[(save_format.name, save_mode.name)]
|
|
151
|
+
except:
|
|
152
|
+
return _PATH_MODE_DICT[(SaveFormats.entire_h5.name, save_mode.name)]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from PyQt5.QtWidgets import QComboBox
|
|
2
|
+
from PyQt5.QtCore import pyqtSlot, pyqtSignal
|
|
3
|
+
|
|
4
|
+
from ...app.data_manager import SaveFormats, SavingParameters
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FormatBox(QComboBox):
|
|
8
|
+
sigFormatChanged = pyqtSignal(SaveFormats)
|
|
9
|
+
|
|
10
|
+
def __init__(self, parent):
|
|
11
|
+
super().__init__(parent)
|
|
12
|
+
self._current_format: SaveFormats = SaveFormats.entire_h5
|
|
13
|
+
self.addItems([save_format.value for save_format in SaveFormats])
|
|
14
|
+
self.currentTextChanged.connect(self._format_changed)
|
|
15
|
+
self.setCurrentText(self._current_format.value)
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def save_format(self) -> SaveFormats:
|
|
19
|
+
return self._current_format
|
|
20
|
+
|
|
21
|
+
@pyqtSlot(SaveFormats, name='setFormat')
|
|
22
|
+
def set_format(self, save_format: SaveFormats):
|
|
23
|
+
if self._current_format.value != save_format.value:
|
|
24
|
+
self._current_format = save_format
|
|
25
|
+
self.setCurrentText(save_format.value)
|
|
26
|
+
|
|
27
|
+
def update_params(self, saving_params: SavingParameters):
|
|
28
|
+
saving_params.format = self.save_format
|
|
29
|
+
|
|
30
|
+
@pyqtSlot(name='selectedFormatChanged')
|
|
31
|
+
def _format_changed(self):
|
|
32
|
+
self._current_format = SaveFormats(self.currentText())
|
|
33
|
+
self.sigFormatChanged.emit(self._current_format)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from PyQt5.QtWidgets import (
|
|
2
|
+
QWidget,
|
|
3
|
+
QGridLayout,
|
|
4
|
+
QCheckBox,
|
|
5
|
+
QPushButton,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
from PyQt5.QtCore import pyqtSignal
|
|
9
|
+
|
|
10
|
+
from ...app.data_manager import SavingParameters
|
|
11
|
+
from ...gui.basic_widgets import Label
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class NumSelectedWidget(QWidget):
|
|
15
|
+
sigSkipUnlabelledClicked = pyqtSignal(int)
|
|
16
|
+
sigSelectManuallyClicked = pyqtSignal()
|
|
17
|
+
|
|
18
|
+
def __init__(self, saving_params: SavingParameters, parent=None):
|
|
19
|
+
super().__init__(parent)
|
|
20
|
+
self.params = saving_params
|
|
21
|
+
self._init_ui()
|
|
22
|
+
self._init_layout()
|
|
23
|
+
self._init_connect()
|
|
24
|
+
|
|
25
|
+
def update_params(self):
|
|
26
|
+
self.num_label.setText(self._get_label())
|
|
27
|
+
|
|
28
|
+
def _get_label(self):
|
|
29
|
+
return f'{self.params.num_images} images selected'
|
|
30
|
+
|
|
31
|
+
def _init_ui(self):
|
|
32
|
+
self.num_label = Label(self._get_label(), self)
|
|
33
|
+
self.skip_unlabelled_btn = QCheckBox('Skip unlabelled', self)
|
|
34
|
+
self.skip_unlabelled_btn.setChecked(True)
|
|
35
|
+
self.select_manually_btn = QPushButton('Select manually', self)
|
|
36
|
+
|
|
37
|
+
def _init_layout(self):
|
|
38
|
+
layout = QGridLayout(self)
|
|
39
|
+
layout.addWidget(self.num_label, 0, 0)
|
|
40
|
+
layout.addWidget(self.skip_unlabelled_btn, 1, 0)
|
|
41
|
+
layout.addWidget(self.select_manually_btn, 2, 0)
|
|
42
|
+
|
|
43
|
+
def _init_connect(self):
|
|
44
|
+
self.skip_unlabelled_btn.stateChanged.connect(self.sigSkipUnlabelledClicked)
|
|
45
|
+
self.select_manually_btn.clicked.connect(self.sigSelectManuallyClicked)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import QWidget, QGridLayout, QCheckBox, QComboBox
|
|
4
|
+
|
|
5
|
+
from ...app.data_manager import (
|
|
6
|
+
SavingParameters,
|
|
7
|
+
SaveFormats,
|
|
8
|
+
TextFormats,
|
|
9
|
+
MetaTextFormats,
|
|
10
|
+
)
|
|
11
|
+
from ...gui.basic_widgets import Label
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OptionsWidget(QWidget):
|
|
15
|
+
def __init__(self, saving_parameters: SavingParameters, parent=None):
|
|
16
|
+
super().__init__(parent)
|
|
17
|
+
self.saving_parameters = saving_parameters
|
|
18
|
+
self._current_format = None
|
|
19
|
+
self._init_ui(saving_parameters)
|
|
20
|
+
self.set_format(saving_parameters.format, saving_parameters)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _init_ui(self, saving_parameters: SavingParameters):
|
|
24
|
+
self.bool_options = BoolOptionsWidget(saving_parameters, self)
|
|
25
|
+
self.text_options = TextFormatOptions(saving_parameters, self)
|
|
26
|
+
self.text_options.setHidden(True)
|
|
27
|
+
|
|
28
|
+
def set_format(self, save_format: SaveFormats, saving_parameters: SavingParameters):
|
|
29
|
+
if self._current_format != save_format:
|
|
30
|
+
self._current_format = save_format
|
|
31
|
+
if save_format.value == SaveFormats.entire_h5.value:
|
|
32
|
+
saving_parameters.set_entire_h5_params()
|
|
33
|
+
self.bool_options.setDisabled(True)
|
|
34
|
+
self.text_options.setHidden(True)
|
|
35
|
+
elif save_format.value == SaveFormats.partial_h5.value:
|
|
36
|
+
saving_parameters.set_partial_h5_params()
|
|
37
|
+
self.bool_options.setDisabled(False)
|
|
38
|
+
self.text_options.setHidden(True)
|
|
39
|
+
elif save_format.value == SaveFormats.text.value:
|
|
40
|
+
self.bool_options.setDisabled(False)
|
|
41
|
+
self.text_options.setHidden(False)
|
|
42
|
+
elif save_format.value in (
|
|
43
|
+
SaveFormats.object_detection.value,
|
|
44
|
+
SaveFormats.partial_h5.value,
|
|
45
|
+
):
|
|
46
|
+
self.bool_options.setDisabled(True)
|
|
47
|
+
self.text_options.setHidden(True)
|
|
48
|
+
else:
|
|
49
|
+
raise ValueError(f'Unknown save format {save_format}.')
|
|
50
|
+
|
|
51
|
+
def update_params(self, params: SavingParameters):
|
|
52
|
+
self.bool_options.update_params(params)
|
|
53
|
+
self.text_options.update_params(params)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class BoolOptionsWidget(QWidget):
|
|
57
|
+
def __init__(self, saving_parameters: SavingParameters, parent=None):
|
|
58
|
+
super().__init__(parent)
|
|
59
|
+
self._check_boxes: Dict[SavingParameters, QCheckBox] = {}
|
|
60
|
+
self._init_ui(saving_parameters)
|
|
61
|
+
|
|
62
|
+
def _init_ui(self, saving_parameters: SavingParameters):
|
|
63
|
+
layout = QGridLayout(self)
|
|
64
|
+
|
|
65
|
+
for i, (attr, name) in enumerate(SavingParameters.BOOL_FLAGS.items()):
|
|
66
|
+
label = Label(name, self)
|
|
67
|
+
check_box = QCheckBox(self)
|
|
68
|
+
value = getattr(saving_parameters, attr, SavingParameters.__dataclass_fields__[attr].default)
|
|
69
|
+
check_box.setChecked(value)
|
|
70
|
+
self._check_boxes[attr] = check_box
|
|
71
|
+
layout.addWidget(label, i, 0)
|
|
72
|
+
layout.addWidget(check_box, i, 1)
|
|
73
|
+
|
|
74
|
+
def update_params(self, params: SavingParameters):
|
|
75
|
+
|
|
76
|
+
for attr in SavingParameters.BOOL_FLAGS.keys():
|
|
77
|
+
value = getattr(params, attr, SavingParameters.__dataclass_fields__[attr].default)
|
|
78
|
+
self._check_boxes[attr].setChecked(value)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class TextFormatOptions(QWidget):
|
|
82
|
+
def __init__(self, saving_parameters: SavingParameters, parent=None):
|
|
83
|
+
super().__init__(parent)
|
|
84
|
+
|
|
85
|
+
self._init_ui(saving_parameters)
|
|
86
|
+
|
|
87
|
+
def _init_ui(self, saving_parameters: SavingParameters):
|
|
88
|
+
layout = QGridLayout(self)
|
|
89
|
+
self.text_format = QComboBox(self)
|
|
90
|
+
self.text_format.addItems([value.value for value in TextFormats])
|
|
91
|
+
|
|
92
|
+
self.meta_text_format = QComboBox(self)
|
|
93
|
+
self.meta_text_format.addItems([value.value for value in MetaTextFormats])
|
|
94
|
+
|
|
95
|
+
self.text_format.setCurrentText(saving_parameters.text_format.value)
|
|
96
|
+
self.meta_text_format.setCurrentText(saving_parameters.meta_text_format.value)
|
|
97
|
+
|
|
98
|
+
layout.addWidget(Label('Table format'), 0, 0)
|
|
99
|
+
layout.addWidget(self.text_format, 1, 0)
|
|
100
|
+
layout.addWidget(Label('Configuration format'), 2, 0)
|
|
101
|
+
layout.addWidget(self.meta_text_format, 3, 0)
|
|
102
|
+
|
|
103
|
+
def update_params(self, params: SavingParameters):
|
|
104
|
+
params.text_format = TextFormats(self.text_format.currentText())
|
|
105
|
+
params.meta_text_format = MetaTextFormats(self.meta_text_format.currentText())
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from PyQt5.QtWidgets import QComboBox
|
|
2
|
+
from PyQt5.QtCore import pyqtSlot, pyqtSignal
|
|
3
|
+
|
|
4
|
+
from ...app.data_manager import SaveMode
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SaveModeBox(QComboBox):
|
|
8
|
+
sigSaveModeChanged = pyqtSignal(SaveMode)
|
|
9
|
+
|
|
10
|
+
def __init__(self, parent):
|
|
11
|
+
super().__init__(parent)
|
|
12
|
+
self._mode: SaveMode = SaveMode.create
|
|
13
|
+
self.addItems([mode.value for mode in SaveMode])
|
|
14
|
+
self.currentTextChanged.connect(self._mode_changed)
|
|
15
|
+
self.setCurrentText(self._mode.value)
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def mode(self) -> SaveMode:
|
|
19
|
+
return self._mode
|
|
20
|
+
|
|
21
|
+
@pyqtSlot(SaveMode, name='setMode')
|
|
22
|
+
def set_mode(self, mode: SaveMode):
|
|
23
|
+
if self._mode.value != mode.value:
|
|
24
|
+
self._mode = mode
|
|
25
|
+
self.setCurrentText(mode.value)
|
|
26
|
+
|
|
27
|
+
@pyqtSlot(name='selectedModeChanged')
|
|
28
|
+
def _mode_changed(self):
|
|
29
|
+
self._mode = SaveMode(self.currentText())
|
|
30
|
+
self.sigSaveModeChanged.emit(self._mode)
|