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.
Files changed (202) hide show
  1. mlgidGUI/__init__.py +52 -0
  2. mlgidGUI/__main__.py +7 -0
  3. mlgidGUI/__version.py +1 -0
  4. mlgidGUI/app/__init__.py +8 -0
  5. mlgidGUI/app/actions_stack.py +1 -0
  6. mlgidGUI/app/app.py +67 -0
  7. mlgidGUI/app/cif_rois/__init__.py +0 -0
  8. mlgidGUI/app/cif_rois/cif_peaks_calculation.py +57 -0
  9. mlgidGUI/app/cif_rois/cif_simulation/__init__.py +0 -0
  10. mlgidGUI/app/cif_rois/cif_simulation/data/__init__.py +0 -0
  11. mlgidGUI/app/cif_rois/cif_simulation/data/atoms.py +15 -0
  12. mlgidGUI/app/cif_rois/cif_simulation/data/export_database.py +28 -0
  13. mlgidGUI/app/cif_rois/cif_simulation/experiment.py +57 -0
  14. mlgidGUI/app/cif_rois/cif_simulation/giwaxs_sim.py +286 -0
  15. mlgidGUI/app/cif_rois/cif_simulation/int_sim.py +105 -0
  16. mlgidGUI/app/cif_rois/cif_simulation/possible_directions.py +20 -0
  17. mlgidGUI/app/cif_rois/cif_simulation/q_sim.py +159 -0
  18. mlgidGUI/app/data_manager/__init__.py +4 -0
  19. mlgidGUI/app/data_manager/data_manager.py +164 -0
  20. mlgidGUI/app/data_manager/import_from_h5.py +68 -0
  21. mlgidGUI/app/data_manager/load_data.py +78 -0
  22. mlgidGUI/app/data_manager/pascal/__init__.py +2 -0
  23. mlgidGUI/app/data_manager/pascal/annotation_fabric.py +59 -0
  24. mlgidGUI/app/data_manager/pascal/draw_objects.py +119 -0
  25. mlgidGUI/app/data_manager/pascal/exceptions.py +6 -0
  26. mlgidGUI/app/data_manager/pascal/format_convertor.py +127 -0
  27. mlgidGUI/app/data_manager/pascal/pascal_annotation.py +85 -0
  28. mlgidGUI/app/data_manager/pascal/protocol_implementations.py +28 -0
  29. mlgidGUI/app/data_manager/pascal/protocols.py +47 -0
  30. mlgidGUI/app/data_manager/pascal/utils.py +64 -0
  31. mlgidGUI/app/data_manager/save_dataset.py +57 -0
  32. mlgidGUI/app/data_manager/save_h5.py +178 -0
  33. mlgidGUI/app/data_manager/saving_parameters.py +88 -0
  34. mlgidGUI/app/debug_tracker.py +129 -0
  35. mlgidGUI/app/edf_reader.py +135 -0
  36. mlgidGUI/app/file_manager/__init__.py +201 -0
  37. mlgidGUI/app/file_manager/config_manager.py +76 -0
  38. mlgidGUI/app/file_manager/keys.py +542 -0
  39. mlgidGUI/app/file_manager/npy_file_manager.py +17 -0
  40. mlgidGUI/app/file_manager/object_file_manager.py +77 -0
  41. mlgidGUI/app/file_manager/project_structure.py +169 -0
  42. mlgidGUI/app/file_manager/read_fits.py +76 -0
  43. mlgidGUI/app/file_manager/read_geometry.py +54 -0
  44. mlgidGUI/app/file_manager/read_images.py +31 -0
  45. mlgidGUI/app/file_manager/read_meta_roi.py +40 -0
  46. mlgidGUI/app/file_manager/read_polar_images.py +22 -0
  47. mlgidGUI/app/file_manager/read_radial_profile.py +6 -0
  48. mlgidGUI/app/file_manager/read_roi_data.py +39 -0
  49. mlgidGUI/app/fitting/__init__.py +5 -0
  50. mlgidGUI/app/fitting/background.py +92 -0
  51. mlgidGUI/app/fitting/fit.py +128 -0
  52. mlgidGUI/app/fitting/fit_holder.py +273 -0
  53. mlgidGUI/app/fitting/fit_object.py +247 -0
  54. mlgidGUI/app/fitting/functions.py +107 -0
  55. mlgidGUI/app/fitting/range_strategy.py +14 -0
  56. mlgidGUI/app/fitting/utils.py +17 -0
  57. mlgidGUI/app/geometry.py +236 -0
  58. mlgidGUI/app/geometry_holder.py +131 -0
  59. mlgidGUI/app/image_holder.py +200 -0
  60. mlgidGUI/app/image_processing.py +23 -0
  61. mlgidGUI/app/polar_image.py +96 -0
  62. mlgidGUI/app/profiles/__init__.py +5 -0
  63. mlgidGUI/app/profiles/angular_profile.py +20 -0
  64. mlgidGUI/app/profiles/basic_profile.py +169 -0
  65. mlgidGUI/app/profiles/radial_profile.py +38 -0
  66. mlgidGUI/app/read_image.py +21 -0
  67. mlgidGUI/app/rois/__init__.py +4 -0
  68. mlgidGUI/app/rois/new_roi_dict.py +670 -0
  69. mlgidGUI/app/rois/roi.py +194 -0
  70. mlgidGUI/app/rois/roi_colors.py +76 -0
  71. mlgidGUI/app/rois/roi_data.py +177 -0
  72. mlgidGUI/app/rois/roi_dict.py +466 -0
  73. mlgidGUI/app/rois/roi_meta_data.py +149 -0
  74. mlgidGUI/app/structures/__init__.py +6 -0
  75. mlgidGUI/app/structures/crystal_ring.py +19 -0
  76. mlgidGUI/app/structures/crystals_holders.py +144 -0
  77. mlgidGUI/app/structures/custom_crystal.py +45 -0
  78. mlgidGUI/app/structures/get_ring_list.py +89 -0
  79. mlgidGUI/app/transformations.py +82 -0
  80. mlgidGUI/app/update/__init__.py +3 -0
  81. mlgidGUI/app/update/check_version.py +51 -0
  82. mlgidGUI/app/update/launch_program.py +15 -0
  83. mlgidGUI/app/update/script_update.py +64 -0
  84. mlgidGUI/app/utils.py +124 -0
  85. mlgidGUI/gui/__init__.py +3 -0
  86. mlgidGUI/gui/background_tasks.py +41 -0
  87. mlgidGUI/gui/background_update.py +87 -0
  88. mlgidGUI/gui/basic_widgets/__init__.py +12 -0
  89. mlgidGUI/gui/basic_widgets/buttons.py +144 -0
  90. mlgidGUI/gui/basic_widgets/labels.py +51 -0
  91. mlgidGUI/gui/basic_widgets/mouse_events.py +119 -0
  92. mlgidGUI/gui/basic_widgets/path_line.py +162 -0
  93. mlgidGUI/gui/basic_widgets/plots_1d.py +365 -0
  94. mlgidGUI/gui/basic_widgets/plots_2d.py +224 -0
  95. mlgidGUI/gui/basic_widgets/popups.py +164 -0
  96. mlgidGUI/gui/basic_widgets/progress_bar.py +127 -0
  97. mlgidGUI/gui/basic_widgets/setup_widgets.py +138 -0
  98. mlgidGUI/gui/basic_widgets/sliders.py +616 -0
  99. mlgidGUI/gui/basic_widgets/spinner.py +65 -0
  100. mlgidGUI/gui/basic_widgets/toolbars.py +19 -0
  101. mlgidGUI/gui/debug_widgets.py +388 -0
  102. mlgidGUI/gui/dock_area.py +115 -0
  103. mlgidGUI/gui/exception_message.py +42 -0
  104. mlgidGUI/gui/fitting/__init__.py +2 -0
  105. mlgidGUI/gui/fitting/fit_widget.py +966 -0
  106. mlgidGUI/gui/fitting/inplace_fit.py +536 -0
  107. mlgidGUI/gui/fitting/selected_fit_widget.py +286 -0
  108. mlgidGUI/gui/gui_main.py +349 -0
  109. mlgidGUI/gui/image_viewer.py +323 -0
  110. mlgidGUI/gui/init_window.py +170 -0
  111. mlgidGUI/gui/load_window/__init__.py +2 -0
  112. mlgidGUI/gui/load_window/load_folder.py +61 -0
  113. mlgidGUI/gui/load_window/load_h5.py +73 -0
  114. mlgidGUI/gui/notifications.py +68 -0
  115. mlgidGUI/gui/polar_image_viewer.py +153 -0
  116. mlgidGUI/gui/profiles/__init__.py +1 -0
  117. mlgidGUI/gui/profiles/angular_profile_widget.py +62 -0
  118. mlgidGUI/gui/profiles/radial_profile_widget.py +164 -0
  119. mlgidGUI/gui/project_manager/__init__.py +17 -0
  120. mlgidGUI/gui/project_manager/cif_files_widget.py +196 -0
  121. mlgidGUI/gui/project_manager/cif_results.py +146 -0
  122. mlgidGUI/gui/project_manager/metadata_widget.py +15 -0
  123. mlgidGUI/gui/project_manager/project_viewer.py +151 -0
  124. mlgidGUI/gui/project_manager/roi_widget.py +171 -0
  125. mlgidGUI/gui/roi_widgets/__init__.py +6 -0
  126. mlgidGUI/gui/roi_widgets/abstract_roi_holder.py +189 -0
  127. mlgidGUI/gui/roi_widgets/abstract_roi_widget.py +111 -0
  128. mlgidGUI/gui/roi_widgets/cif_file_widget.py +16 -0
  129. mlgidGUI/gui/roi_widgets/cif_peak_widget.py +43 -0
  130. mlgidGUI/gui/roi_widgets/confidence_level_widget.py +105 -0
  131. mlgidGUI/gui/roi_widgets/roi_1d_widget.py +136 -0
  132. mlgidGUI/gui/roi_widgets/roi_2d_rect_widget.py +98 -0
  133. mlgidGUI/gui/roi_widgets/roi_2d_ring_widget.py +203 -0
  134. mlgidGUI/gui/roi_widgets/rois_context_menu.py +150 -0
  135. mlgidGUI/gui/roi_widgets/select_roi_color_widget.py +58 -0
  136. mlgidGUI/gui/save_window/__init__.py +152 -0
  137. mlgidGUI/gui/save_window/format_box.py +33 -0
  138. mlgidGUI/gui/save_window/num_selected_widget.py +45 -0
  139. mlgidGUI/gui/save_window/options_widgets.py +105 -0
  140. mlgidGUI/gui/save_window/save_mode_box.py +30 -0
  141. mlgidGUI/gui/save_window/select_images.py +198 -0
  142. mlgidGUI/gui/tools.py +179 -0
  143. mlgidGUI/static/__init__.py +0 -0
  144. mlgidGUI/static/icons/__init__.py +0 -0
  145. mlgidGUI/static/icons/add.png +0 -0
  146. mlgidGUI/static/icons/add_yellow.png +0 -0
  147. mlgidGUI/static/icons/angular_profile.png +0 -0
  148. mlgidGUI/static/icons/arrow.png +0 -0
  149. mlgidGUI/static/icons/baseline.png +0 -0
  150. mlgidGUI/static/icons/center.png +0 -0
  151. mlgidGUI/static/icons/confirm.png +0 -0
  152. mlgidGUI/static/icons/control_widget.png +0 -0
  153. mlgidGUI/static/icons/data.png +0 -0
  154. mlgidGUI/static/icons/delete.png +0 -0
  155. mlgidGUI/static/icons/delete_yellow.png +0 -0
  156. mlgidGUI/static/icons/error.png +0 -0
  157. mlgidGUI/static/icons/find.png +0 -0
  158. mlgidGUI/static/icons/fit.png +0 -0
  159. mlgidGUI/static/icons/fix_all.png +0 -0
  160. mlgidGUI/static/icons/flip_horizontal.png +0 -0
  161. mlgidGUI/static/icons/flip_vertical.png +0 -0
  162. mlgidGUI/static/icons/folder.png +0 -0
  163. mlgidGUI/static/icons/fromfullscreen.png +0 -0
  164. mlgidGUI/static/icons/h5_folder.png +0 -0
  165. mlgidGUI/static/icons/h5_group_folder.png +0 -0
  166. mlgidGUI/static/icons/info.png +0 -0
  167. mlgidGUI/static/icons/interpolate.png +0 -0
  168. mlgidGUI/static/icons/item.png +0 -0
  169. mlgidGUI/static/icons/properties.png +0 -0
  170. mlgidGUI/static/icons/radial_profile.png +0 -0
  171. mlgidGUI/static/icons/roi_item.png +0 -0
  172. mlgidGUI/static/icons/rotate.png +0 -0
  173. mlgidGUI/static/icons/rotate_image.png +0 -0
  174. mlgidGUI/static/icons/rotate_right.png +0 -0
  175. mlgidGUI/static/icons/setup.png +0 -0
  176. mlgidGUI/static/icons/setup_white.png +0 -0
  177. mlgidGUI/static/icons/tofullscreen.png +0 -0
  178. mlgidGUI/static/icons/unfix_all.png +0 -0
  179. mlgidGUI/static/icons/update.png +0 -0
  180. mlgidGUI/static/icons/update_suggested.png +0 -0
  181. mlgidGUI/static/icons/window_icon.png +0 -0
  182. mlgidGUI/static/icons/window_icon_256.png +0 -0
  183. mlgidGUI/utils/__init__.py +1 -0
  184. mlgidGUI/utils/project2h5.py +11 -0
  185. mlgidgui-0.4.1.dist-info/METADATA +119 -0
  186. mlgidgui-0.4.1.dist-info/RECORD +202 -0
  187. mlgidgui-0.4.1.dist-info/WHEEL +5 -0
  188. mlgidgui-0.4.1.dist-info/entry_points.txt +5 -0
  189. mlgidgui-0.4.1.dist-info/licenses/LICENSE +674 -0
  190. mlgidgui-0.4.1.dist-info/top_level.txt +4 -0
  191. tests/__init__.py +0 -0
  192. tests/conftest.py +1 -0
  193. tests/fixures/__init__.py +2 -0
  194. tests/fixures/projects.py +102 -0
  195. tests/func/__init__.py +1 -0
  196. tests/func/test_loading_state.py +21 -0
  197. tests/func/test_parse_project_data.py +23 -0
  198. tests/func/test_save.py +62 -0
  199. tests/unit/__init__.py +0 -0
  200. tests/unit/rois/__init__.py +0 -0
  201. tests/unit/rois/test_basic_operations.py +18 -0
  202. tests/unit/test_add_data.py +33 -0
@@ -0,0 +1,164 @@
1
+ from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel, QFrame, QMessageBox
2
+ from PyQt5.QtCore import Qt, QObject, QPoint, pyqtSignal, pyqtSlot
3
+ from .spinner import Spinner
4
+ from .labels import Label, LabelButton
5
+
6
+ NOTIFICATION_BACKGROUND_COLOR = 'rgb(80, 80, 80)'
7
+
8
+
9
+ class PopUpWrapper(QObject):
10
+ WIDTH = 400
11
+ HEIGHT = 90
12
+ PADDING = 10
13
+
14
+ def __init__(self, widget: QWidget):
15
+ super().__init__(widget)
16
+ self.parent = widget
17
+ self.__popups = []
18
+ self.__popups_dict = {}
19
+ self.__monkeypatch_parent_methods(widget)
20
+
21
+ @pyqtSlot(name='movePopup')
22
+ def _move_popups(self):
23
+ win_width, win_height = self.parent.size().width(), self.parent.size().height()
24
+ win_point = self.parent.mapToGlobal(QPoint(win_width, win_height))
25
+ for i, popup in enumerate(self.__popups):
26
+ popup_w, popup_h = self.WIDTH + self.PADDING, (self.HEIGHT + self.PADDING) * (i + 1)
27
+ p = win_point - QPoint(popup_w, popup_h)
28
+ popup.move(p)
29
+ if win_width - popup_w < 0 or win_height - popup_h < 0:
30
+ popup.hide()
31
+ else:
32
+ popup.show()
33
+
34
+ def add_notification(self, context: str or QWidget, name=None):
35
+ if not context:
36
+ return
37
+ notification = Notification(self.parent, context)
38
+ notification.sigCloseClicked.connect(self.remove_notification)
39
+
40
+ if name is not None:
41
+ self.__popups_dict[name] = notification
42
+
43
+ self.__popups.append(notification)
44
+ self._move_popups()
45
+
46
+ @pyqtSlot(QWidget, name='removeWidget')
47
+ def remove_notification(self, widget: QWidget):
48
+ try:
49
+ self.__popups.remove(widget)
50
+ widget.deleteLater()
51
+ self._move_popups()
52
+ except ValueError:
53
+ pass
54
+ self.__popups_dict = {k: v for k, v in self.__popups_dict.items() if v is not widget}
55
+
56
+ def remove_by_name(self, name):
57
+ if name in self.__popups_dict:
58
+ self.remove_notification(self.__popups_dict.pop(name))
59
+
60
+ def clear(self):
61
+ for widget in self.__popups:
62
+ try:
63
+ widget.deleteLater()
64
+ except RuntimeError:
65
+ pass
66
+ self.__popups = []
67
+ self.__popups_dict = {}
68
+
69
+ def __monkeypatch_parent_methods(self, parent: QWidget):
70
+ old_resize = parent.resizeEvent
71
+ old_move = parent.moveEvent
72
+
73
+ def new_resize(event):
74
+ self._move_popups()
75
+ old_resize(event)
76
+
77
+ def new_move(event):
78
+ self._move_popups()
79
+ old_move(event)
80
+
81
+ parent.resizeEvent = new_resize
82
+ parent.moveEvent = new_move
83
+
84
+
85
+ class CloseButton(LabelButton):
86
+ def __init__(self, *args, **kwargs):
87
+ super().__init__(*args, **kwargs)
88
+ font = self.font()
89
+ font.setBold(True)
90
+ font.setPointSize(10)
91
+ self.setFont(font)
92
+
93
+ def set_visible(self, enable: bool = True):
94
+ if enable:
95
+ self.setStyleSheet('QLabel {color: #808080}')
96
+ else:
97
+ self.setStyleSheet('QLabel {color: %s}' % NOTIFICATION_BACKGROUND_COLOR)
98
+
99
+
100
+ class Notification(QFrame):
101
+ sigCloseClicked = pyqtSignal(QWidget)
102
+
103
+ def __init__(self, parent, context: str or QWidget):
104
+ super().__init__(parent, Qt.Window | Qt.FramelessWindowHint)
105
+ self._init_ui(context)
106
+ self.show()
107
+
108
+ def enterEvent(self, a0) -> None:
109
+ self.button.set_visible(True)
110
+ super().enterEvent(a0)
111
+
112
+ def leaveEvent(self, a0) -> None:
113
+ self.button.set_visible(False)
114
+ super().leaveEvent(a0)
115
+
116
+ def _init_ui(self, context: str or QWidget):
117
+ if isinstance(context, str):
118
+ context = QLabel(context, self)
119
+ else:
120
+ context.setParent(self)
121
+
122
+ self.setFixedSize(PopUpWrapper.WIDTH, PopUpWrapper.HEIGHT)
123
+ self.setStyleSheet(f"background-color: {NOTIFICATION_BACKGROUND_COLOR}")
124
+ self.setContentsMargins(5, 5, 5, 0)
125
+
126
+ layout = QGridLayout(self)
127
+ layout.setContentsMargins(0, 0, 0, 0)
128
+ layout.setSpacing(0)
129
+ layout.addWidget(self._get_close_button(), 0, 1, alignment=Qt.AlignRight | Qt.AlignTop)
130
+ layout.addWidget(context, 0, 0, 3, 1)
131
+
132
+ def _get_close_button(self):
133
+ close_button = CloseButton('x', self)
134
+ close_button.sigClicked.connect(lambda: self.sigCloseClicked.emit(self))
135
+ close_button.set_visible(False)
136
+ self.button = close_button
137
+ return close_button
138
+
139
+ def confirmation_box(window_title: str = '', text: str = '', informative_text: str = ','):
140
+ msg_box = QMessageBox()
141
+ msg_box.setWindowTitle(window_title)
142
+ msg_box.setText(text)
143
+ msg_box.setInformativeText(informative_text)
144
+ msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
145
+ msg_box.setDefaultButton(QMessageBox.Yes)
146
+ ret = msg_box.exec()
147
+ if ret == QMessageBox.Yes:
148
+ return True
149
+ else:
150
+ return False
151
+
152
+ class TextNotification(QWidget):
153
+ def __init__(self, title: str, text: str, spinner: bool = False, parent=None):
154
+ super().__init__(parent)
155
+ layout = QGridLayout(self)
156
+ layout.setSpacing(5)
157
+
158
+ if spinner:
159
+ layout.addWidget(Spinner(self, 20), 0, 0)
160
+ layout.addWidget(Label(title, self, 8.5, True), 0, 1)
161
+ layout.addWidget(Label(text, self, 8.5), 1, 0, 1, 2)
162
+ else:
163
+ layout.addWidget(Label(title, self, 8.5, True), 0, 0)
164
+ layout.addWidget(Label(text, self, 8.5), 1, 0)
@@ -0,0 +1,127 @@
1
+ # -*- coding: utf-8 -*-
2
+ import logging
3
+
4
+ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QLabel, QPushButton
5
+ from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal
6
+
7
+ from ..tools import center_widget, DummySignal
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ class ProgressBar(QWidget):
13
+ sigCancelClicked = pyqtSignal()
14
+
15
+ def __init__(self,
16
+ num: int,
17
+ progress_label: str,
18
+ finish_label: str,
19
+ parent=None,
20
+ auto_close: bool = False,
21
+ cancel_btn: bool = False,
22
+ block_window: bool = True,
23
+ show: bool = True):
24
+ super().__init__(parent)
25
+ self._progress_label: str = progress_label
26
+ self._finish_label: str = finish_label
27
+ self._auto_close: bool = auto_close
28
+ self._cancel_btn: bool = cancel_btn
29
+
30
+ self.setWindowFlag(Qt.Window)
31
+ self.setWindowFlag(Qt.FramelessWindowHint)
32
+
33
+ if block_window:
34
+ self.setWindowModality(Qt.ApplicationModal)
35
+ self.setAttribute(Qt.WA_DeleteOnClose, True)
36
+
37
+ self._init_ui(num)
38
+ center_widget(self)
39
+ if show:
40
+ self.show()
41
+
42
+ def _init_ui(self, num: int):
43
+ layout = QVBoxLayout(self)
44
+ self.progress = QProgressBar()
45
+ self.progress.setMaximum(num)
46
+ self.label = QLabel(self._progress_label)
47
+
48
+ layout.addWidget(self.label)
49
+ layout.addWidget(self.progress)
50
+
51
+ if not self._auto_close:
52
+ self.close_button = self._init_close_button()
53
+ layout.addWidget(self.close_button)
54
+
55
+ if self._cancel_btn:
56
+ self.cancel_btn = self._init_cancel_btn()
57
+ layout.addWidget(self.cancel_btn)
58
+
59
+ if not num:
60
+ self.progress.setMaximum(1)
61
+ self.progress.setValue(1)
62
+ self.finished()
63
+
64
+ def _init_cancel_btn(self):
65
+ cancel_button = QPushButton('Cancel')
66
+ cancel_button.clicked.connect(self.sigCancelClicked.emit)
67
+ cancel_button.hide()
68
+ return cancel_button
69
+
70
+ def _init_close_button(self):
71
+ close_button = QPushButton('Close')
72
+ close_button.clicked.connect(self.close)
73
+ close_button.hide()
74
+ return close_button
75
+
76
+ @pyqtSlot(int, name='setMax')
77
+ def set_max(self, num: int):
78
+ self.progress.setMaximum(num)
79
+ self.show()
80
+ logger.debug(f'set max called {num}')
81
+
82
+ @pyqtSlot(int, name='setProgress')
83
+ def set_progress(self, value: int):
84
+ self.progress.setValue(value)
85
+ logger.debug(f'set_progress {value} ')
86
+
87
+ @pyqtSlot(name='finished')
88
+ def finished(self):
89
+ logger.debug('Finished!')
90
+ if self._auto_close:
91
+ self.close()
92
+ else:
93
+ if self._cancel_btn:
94
+ self.cancel_btn.hide()
95
+ self.label.setText(self._finish_label)
96
+ self.progress.setValue(self.progress.maximum())
97
+ self.close_button.show()
98
+
99
+
100
+ def progress_bar_factory(num: int,
101
+ progress_label: str,
102
+ finish_label: str,
103
+ auto_close: bool = False,
104
+ cancel_btn: bool = False,
105
+ block_window: bool = True,
106
+ set_process_sig: DummySignal = None,
107
+ set_finished_sig: DummySignal = None,
108
+ set_max_sig: DummySignal = None,
109
+ cancel_callback=None
110
+ ):
111
+ def func(parent):
112
+ progress_bar = ProgressBar(parent=parent,
113
+ num=num, progress_label=progress_label,
114
+ finish_label=finish_label,
115
+ auto_close=auto_close,
116
+ cancel_btn=cancel_btn,
117
+ block_window=block_window)
118
+ if set_process_sig:
119
+ set_process_sig.connect(progress_bar.set_progress)
120
+ if set_finished_sig:
121
+ set_finished_sig.connect(progress_bar.finished)
122
+ if set_max_sig:
123
+ set_max_sig.connect(progress_bar.set_max)
124
+ if cancel_callback:
125
+ progress_bar.sigCancelClicked.connect(cancel_callback)
126
+
127
+ return func
@@ -0,0 +1,138 @@
1
+ # -*- coding: utf-8 -*-
2
+ import logging
3
+ from copy import deepcopy
4
+ from abc import abstractmethod
5
+ from typing import NamedTuple
6
+
7
+ from PyQt5.QtWidgets import (QWidget, QLineEdit, QHBoxLayout,
8
+ QLabel, QFormLayout,
9
+ QPushButton, QRadioButton)
10
+ from PyQt5.QtGui import QIntValidator
11
+ from PyQt5.QtCore import Qt, pyqtSignal
12
+
13
+ from ...app.app import App
14
+ from .buttons import InfoButton
15
+ from ..tools import Icon, center_widget, validate_scientific_value
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ class AbstractInputParametersWidget(QWidget):
21
+ class InputParameters(NamedTuple):
22
+ name: str
23
+ label: str
24
+ type: type
25
+ info: str = None
26
+ none: str = False
27
+
28
+ @property
29
+ @abstractmethod
30
+ def PARAMETER_TYPES(self):
31
+ pass
32
+
33
+ @property
34
+ @abstractmethod
35
+ def NAME(self):
36
+ pass
37
+
38
+ @property
39
+ @abstractmethod
40
+ def DEFAULT_DICT(self):
41
+ return {}
42
+
43
+ @classmethod
44
+ def get_config(cls):
45
+ d = deepcopy(cls.DEFAULT_DICT)
46
+ config_d = App().fm.config[cls.NAME] or {}
47
+ d.update(config_d)
48
+ return d
49
+
50
+ def __init__(self, parent=None, params_dict: dict = None):
51
+ super().__init__(parent)
52
+ self.setWindowIcon(Icon('setup'))
53
+ self.setWindowTitle(self.NAME)
54
+ self.default_dict = params_dict or self.get_config()
55
+
56
+ def get_parameters_dict(self):
57
+ parameters_dict = dict()
58
+ for p in self.PARAMETER_TYPES:
59
+ value = getattr(self, p.name)
60
+ if not p.none and value is None:
61
+ return
62
+ parameters_dict[p.name] = value
63
+ return parameters_dict
64
+
65
+ def save_to_config(self, parameters_dict: dict):
66
+ App().fm.config[self.NAME] = parameters_dict
67
+
68
+ def _get_layout(self,
69
+ input_parameter: 'InputParameters'):
70
+ current_value = self.default_dict.get(input_parameter.name, '')
71
+ if current_value is None:
72
+ current_value = ''
73
+ label_widget = QLabel(input_parameter.label)
74
+ input_widget = QLineEdit(str(current_value))
75
+ if input_parameter.type is int:
76
+ input_widget.setValidator(QIntValidator())
77
+ layout = QHBoxLayout()
78
+ layout.addWidget(label_widget, Qt.AlignHCenter)
79
+ layout.addWidget(input_widget, Qt.AlignHCenter)
80
+ if input_parameter.info:
81
+ info_button = InfoButton(input_parameter.info)
82
+ layout.addWidget(info_button, Qt.AlignLeft)
83
+
84
+ def get_input(s):
85
+ return validate_scientific_value(input_widget, input_parameter.type, input_parameter.none)
86
+
87
+ setattr(AbstractInputParametersWidget, input_parameter.name,
88
+ property(get_input))
89
+ return layout
90
+
91
+
92
+ class BasicInputParametersWidget(AbstractInputParametersWidget):
93
+ apply_signal = pyqtSignal(dict)
94
+ close_signal = pyqtSignal()
95
+
96
+ def __init__(self, parent=None, params_dict: dict = None):
97
+ super().__init__(parent, params_dict)
98
+ self.form = QFormLayout()
99
+ for p in self.PARAMETER_TYPES:
100
+ self.form.addRow(self._get_layout(p))
101
+ self.save_button = self._init_save_button()
102
+ self.apply_button = self._init_apply_button()
103
+ self.cancel_button = self._init_cancel_button()
104
+ self.form.addWidget(self.save_button)
105
+ self.form.addWidget(self.apply_button)
106
+ self.form.addWidget(self.cancel_button)
107
+ self.setLayout(self.form)
108
+ center_widget(self)
109
+
110
+ def _init_apply_button(self):
111
+ apply_button = QPushButton('Apply')
112
+
113
+ apply_button.clicked.connect(self.on_apply)
114
+ return apply_button
115
+
116
+ def _init_cancel_button(self):
117
+ cancel_button = QPushButton('Cancel')
118
+ cancel_button.clicked.connect(self.close)
119
+ return cancel_button
120
+
121
+ def on_apply(self, *args):
122
+ parameters_dict = self.get_parameters_dict()
123
+ if parameters_dict is not None:
124
+ self.apply_signal.emit(parameters_dict)
125
+ logger.debug(parameters_dict)
126
+ if self.save_button.isChecked():
127
+ self.save_to_config(parameters_dict)
128
+ self.close()
129
+
130
+ def close(self):
131
+ self.close_signal.emit()
132
+ AbstractInputParametersWidget.close(self)
133
+
134
+ @staticmethod
135
+ def _init_save_button():
136
+ save_button = QRadioButton('Save parameters')
137
+ save_button.setChecked(True)
138
+ return save_button