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,388 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Dict, Tuple, List, DefaultDict, Set
|
|
3
|
+
from collections import defaultdict
|
|
4
|
+
import gc
|
|
5
|
+
|
|
6
|
+
from PyQt5.QtCore import QObject, pyqtSignal, Qt, pyqtSlot
|
|
7
|
+
|
|
8
|
+
from PyQt5.QtWidgets import (QPlainTextEdit, QTreeWidget,
|
|
9
|
+
QTreeWidgetItem, QWidget, QPushButton,
|
|
10
|
+
QVBoxLayout, QApplication, QLabel, QSplitter,
|
|
11
|
+
QListWidget, QListWidgetItem, QLineEdit, QMenu,
|
|
12
|
+
QCheckBox, QGridLayout, QComboBox)
|
|
13
|
+
|
|
14
|
+
from PyQt5.QtGui import QColor, QTextCursor
|
|
15
|
+
|
|
16
|
+
from ..app import App
|
|
17
|
+
from ..app.debug_tracker import ObjectTracker, ObjectStatus
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _set_html_color(message, level):
|
|
21
|
+
return f'<font color="{_COLOR_DICT.get(level, "white")}"> {message}'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
_COLOR_DICT = dict(DEBUG='green', INFO='white', WARNING='yellow', ERROR='red')
|
|
25
|
+
_LEVEL_DICT = dict(DEBUG=logging.DEBUG, INFO=logging.INFO,
|
|
26
|
+
WARNING=logging.WARNING, ERROR=logging.ERROR)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class QTextEditLogger(logging.Handler, QObject):
|
|
30
|
+
sigAppendLog = pyqtSignal(str)
|
|
31
|
+
MAX_LENGTH = 300
|
|
32
|
+
|
|
33
|
+
def __init__(self, parent):
|
|
34
|
+
super().__init__()
|
|
35
|
+
QObject.__init__(self)
|
|
36
|
+
|
|
37
|
+
self._init_ui(parent)
|
|
38
|
+
|
|
39
|
+
# self.cursor = QTextCursor(self.text_widget.document())
|
|
40
|
+
self.sigAppendLog.connect(self.append_log)
|
|
41
|
+
self.setFormatter(
|
|
42
|
+
logging.Formatter(
|
|
43
|
+
'%(levelname)s %(module)s:%(funcName)s %(message)s'))
|
|
44
|
+
logging.getLogger().addHandler(self)
|
|
45
|
+
self.setLevel(logging.DEBUG)
|
|
46
|
+
|
|
47
|
+
def _init_ui(self, parent):
|
|
48
|
+
self.widget = QWidget(parent)
|
|
49
|
+
self.level_box = QComboBox(self.widget)
|
|
50
|
+
self.level_box.addItems('DEBUG INFO WARNING ERROR'.split())
|
|
51
|
+
self.level_box.currentIndexChanged.connect(self.level_changed)
|
|
52
|
+
self.text_widget = QPlainTextEdit(self.widget)
|
|
53
|
+
self.text_widget.setReadOnly(True)
|
|
54
|
+
layout = QGridLayout(self.widget)
|
|
55
|
+
|
|
56
|
+
layout.addWidget(self.level_box, 0, 0)
|
|
57
|
+
layout.addWidget(self.text_widget, 1, 0)
|
|
58
|
+
|
|
59
|
+
@pyqtSlot(int, name='levelBoxIndexChanged')
|
|
60
|
+
def level_changed(self, idx):
|
|
61
|
+
text = self.level_box.currentText()
|
|
62
|
+
self.setLevel(_LEVEL_DICT[text])
|
|
63
|
+
|
|
64
|
+
@pyqtSlot(str, name='appendLog')
|
|
65
|
+
def append_log(self, log: str):
|
|
66
|
+
level, *message = log.split()
|
|
67
|
+
message = _set_html_color(' '.join(message), level)
|
|
68
|
+
if len(message) > self.MAX_LENGTH:
|
|
69
|
+
self.text_widget.appendPlainText('')
|
|
70
|
+
self.text_widget.appendHtml(message)
|
|
71
|
+
if len(message) > self.MAX_LENGTH:
|
|
72
|
+
self.text_widget.appendPlainText('')
|
|
73
|
+
|
|
74
|
+
def emit(self, record):
|
|
75
|
+
msg = self.format(record)
|
|
76
|
+
try:
|
|
77
|
+
self.sigAppendLog.emit(msg)
|
|
78
|
+
except RuntimeError:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class TrackerItem(QListWidgetItem):
|
|
83
|
+
def __init__(self, parent: QListWidget, obj: ObjectTracker):
|
|
84
|
+
super().__init__(obj.name, parent)
|
|
85
|
+
self.id = obj.id
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class TrackerWidget(QWidget):
|
|
89
|
+
log = logging.getLogger(__name__)
|
|
90
|
+
|
|
91
|
+
def __init__(self, parent):
|
|
92
|
+
super().__init__(parent=parent)
|
|
93
|
+
self.tracker = App().debug_tracker
|
|
94
|
+
self.tracker.signals.sigObjectAdded.connect(self._add_object)
|
|
95
|
+
self.tracker.signals.sigStatusUpdated.connect(self._status_updated)
|
|
96
|
+
self.item_dict: Dict[str, TrackerItem] = {}
|
|
97
|
+
self._init_ui()
|
|
98
|
+
|
|
99
|
+
def _init_ui(self):
|
|
100
|
+
layout = QGridLayout(self)
|
|
101
|
+
|
|
102
|
+
self.update_button = QPushButton('Update', self)
|
|
103
|
+
self.clear_button = QPushButton('Clear', self)
|
|
104
|
+
self.collect_checkbox = QCheckBox('GC collect', self)
|
|
105
|
+
self.search_line = QLineEdit(parent=self)
|
|
106
|
+
self.splitter = QSplitter(orientation=Qt.Horizontal, parent=self)
|
|
107
|
+
|
|
108
|
+
self.list_exists, w1 = self._get_list('Exist')
|
|
109
|
+
self.list_deleted_by_c, w2 = self._get_list('Deleted by c')
|
|
110
|
+
self.list_deleted_by_python, w3 = self._get_list('Deleted by python')
|
|
111
|
+
self.list_safely_deleted, w4 = self._get_list('Safely deleted')
|
|
112
|
+
|
|
113
|
+
self.splitter.addWidget(w1)
|
|
114
|
+
self.splitter.addWidget(w2)
|
|
115
|
+
self.splitter.addWidget(w3)
|
|
116
|
+
self.splitter.addWidget(w4)
|
|
117
|
+
|
|
118
|
+
num = 3
|
|
119
|
+
|
|
120
|
+
layout.addWidget(self.update_button, 0, 0, 1, num)
|
|
121
|
+
layout.addWidget(self.clear_button, 1, 0, 1, num)
|
|
122
|
+
layout.addWidget(self.collect_checkbox, 2, 0)
|
|
123
|
+
layout.addWidget(QLabel('Search: '), 2, 1)
|
|
124
|
+
layout.addWidget(self.search_line, 2, 2)
|
|
125
|
+
layout.addWidget(self.splitter, 3, 0, 1, num)
|
|
126
|
+
|
|
127
|
+
self.update_button.clicked.connect(self._update)
|
|
128
|
+
self.clear_button.clicked.connect(self._clear)
|
|
129
|
+
self.search_line.editingFinished.connect(self._search)
|
|
130
|
+
|
|
131
|
+
self.list_exists.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
132
|
+
self.list_exists.customContextMenuRequested.connect(self._custom_menu(self.list_exists))
|
|
133
|
+
|
|
134
|
+
self.list_deleted_by_c.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
135
|
+
self.list_deleted_by_c.customContextMenuRequested.connect(self._custom_menu(self.list_deleted_by_c))
|
|
136
|
+
|
|
137
|
+
def _custom_menu(self, widget):
|
|
138
|
+
def menu(pos):
|
|
139
|
+
item = widget.itemAt(pos)
|
|
140
|
+
if not item:
|
|
141
|
+
return
|
|
142
|
+
|
|
143
|
+
q_menu = QMenu()
|
|
144
|
+
q_menu.addAction('Referrers', lambda *args, key=item.id: self._log_referrers(key))
|
|
145
|
+
q_menu.addAction('Is tracked', lambda *args, key=item.id: self._is_tracked(key))
|
|
146
|
+
q_menu.addAction('Remove', lambda *args, key=item.id: self._remove(key))
|
|
147
|
+
self.tracker.add_object(q_menu)
|
|
148
|
+
q_menu.exec(widget.mapToGlobal(pos))
|
|
149
|
+
|
|
150
|
+
return menu
|
|
151
|
+
|
|
152
|
+
@pyqtSlot(name='searchItems')
|
|
153
|
+
def _search(self):
|
|
154
|
+
text = self.search_line.text()
|
|
155
|
+
for item in self.item_dict.values():
|
|
156
|
+
if text in item.text():
|
|
157
|
+
item.setHidden(False)
|
|
158
|
+
else:
|
|
159
|
+
item.setHidden(True)
|
|
160
|
+
|
|
161
|
+
@pyqtSlot(name='updateLists')
|
|
162
|
+
def _update(self):
|
|
163
|
+
if self.collect_checkbox.isChecked():
|
|
164
|
+
gc.collect()
|
|
165
|
+
self.tracker.update()
|
|
166
|
+
|
|
167
|
+
def _log_referrers(self, key: str):
|
|
168
|
+
try:
|
|
169
|
+
obj = self.tracker.objects[key]
|
|
170
|
+
except KeyError as err:
|
|
171
|
+
self.log.exception(err)
|
|
172
|
+
self._remove(key)
|
|
173
|
+
return
|
|
174
|
+
|
|
175
|
+
referrers = obj.get_referrers()
|
|
176
|
+
if not referrers:
|
|
177
|
+
self.log.error('No referrers found!')
|
|
178
|
+
else:
|
|
179
|
+
self.log.debug(f'Referrers to {obj.name}:')
|
|
180
|
+
for r in referrers:
|
|
181
|
+
self.log.debug(f'{r.__class__.__name__}: {r}')
|
|
182
|
+
self.log.debug(f'--------------------')
|
|
183
|
+
|
|
184
|
+
def _is_tracked(self, key: str):
|
|
185
|
+
try:
|
|
186
|
+
obj = self.tracker.objects[key]
|
|
187
|
+
except KeyError as err:
|
|
188
|
+
self.log.exception(err)
|
|
189
|
+
return
|
|
190
|
+
if obj.is_tracked():
|
|
191
|
+
self.log.debug(f'{obj.name} is tracked by gc.')
|
|
192
|
+
else:
|
|
193
|
+
self.log.error(f'{obj.name} is NOT tracked by gc!')
|
|
194
|
+
|
|
195
|
+
def _remove(self, key: str):
|
|
196
|
+
try:
|
|
197
|
+
self.tracker.objects.pop(key)
|
|
198
|
+
except KeyError:
|
|
199
|
+
self.log.debug(f'{key} not in tracker')
|
|
200
|
+
try:
|
|
201
|
+
item = self.item_dict.pop(key)
|
|
202
|
+
parent = item.listWidget()
|
|
203
|
+
parent.takeItem(parent.row(item))
|
|
204
|
+
except KeyError:
|
|
205
|
+
self.log.debug(f'{key} not in item_dict')
|
|
206
|
+
return
|
|
207
|
+
|
|
208
|
+
@pyqtSlot(list, name='statusUpdated')
|
|
209
|
+
def _status_updated(self, key_list: list):
|
|
210
|
+
for key in key_list:
|
|
211
|
+
status = self.tracker.objects[key].status
|
|
212
|
+
item = self.item_dict[key]
|
|
213
|
+
parent = item.listWidget()
|
|
214
|
+
new_parent = self._get_list_by_status(status)
|
|
215
|
+
new_parent.insertItem(new_parent.count(), parent.takeItem(parent.row(item)))
|
|
216
|
+
|
|
217
|
+
def _clear(self):
|
|
218
|
+
to_delete = self.tracker.clear_deleted()
|
|
219
|
+
for key in to_delete:
|
|
220
|
+
item = self.item_dict.pop(key)
|
|
221
|
+
item.listWidget().removeItemWidget(item)
|
|
222
|
+
|
|
223
|
+
self.list_safely_deleted.clear()
|
|
224
|
+
|
|
225
|
+
def _get_list_by_status(self, status: ObjectStatus):
|
|
226
|
+
if status == ObjectStatus.EXISTS:
|
|
227
|
+
return self.list_exists
|
|
228
|
+
if status == ObjectStatus.SAFELY_DELETED:
|
|
229
|
+
return self.list_safely_deleted
|
|
230
|
+
if status == ObjectStatus.DELETED_BY_C:
|
|
231
|
+
return self.list_deleted_by_c
|
|
232
|
+
if status == ObjectStatus.DELETED_BY_PYTHON:
|
|
233
|
+
return self.list_deleted_by_python
|
|
234
|
+
raise ValueError('Unknown status')
|
|
235
|
+
|
|
236
|
+
@pyqtSlot(str, name='objectAdded')
|
|
237
|
+
def _add_object(self, key: str):
|
|
238
|
+
self.item_dict[key] = TrackerItem(self.list_exists, self.tracker.objects[key])
|
|
239
|
+
|
|
240
|
+
def _get_list(self, name):
|
|
241
|
+
widget = QWidget(self)
|
|
242
|
+
label = QLabel(name, widget)
|
|
243
|
+
list_widget = QListWidget(widget)
|
|
244
|
+
|
|
245
|
+
layout = QVBoxLayout(widget)
|
|
246
|
+
layout.addWidget(label)
|
|
247
|
+
layout.addWidget(list_widget)
|
|
248
|
+
|
|
249
|
+
return list_widget, widget
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class TreeWidgetItem(QTreeWidgetItem):
|
|
253
|
+
def __lt__(self, other):
|
|
254
|
+
return int(self.text(2)) < int(other.text(2))
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def get_color(fr: float):
|
|
258
|
+
return QColor(0, 255, 0, int(fr * 255))
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class WidgetList(QWidget):
|
|
262
|
+
def __init__(self, parent=None):
|
|
263
|
+
super().__init__(parent)
|
|
264
|
+
self.id_dict: Dict[int, Tuple[List[str], int]] = {}
|
|
265
|
+
self.item_dict: DefaultDict[str, Set[tuple]] = defaultdict(set)
|
|
266
|
+
self._init_ui()
|
|
267
|
+
|
|
268
|
+
def _init_ui(self):
|
|
269
|
+
layout = QVBoxLayout(self)
|
|
270
|
+
self.splitter = QSplitter(orientation=Qt.Vertical, parent=self)
|
|
271
|
+
|
|
272
|
+
self.label = QLabel('Number of widgets (not calculated)')
|
|
273
|
+
self.update_button = QPushButton('Update')
|
|
274
|
+
self.widget_list = QTreeWidget(self)
|
|
275
|
+
self.differ_list = QListWidget(self)
|
|
276
|
+
|
|
277
|
+
self.search_widget = QWidget(self)
|
|
278
|
+
self.search_line = QLineEdit(self.search_widget)
|
|
279
|
+
self.search_tree = QTreeWidget(self.search_widget)
|
|
280
|
+
|
|
281
|
+
self.widget_list.setHeaderLabels(['Class name', 'Object name', 'Number of children', 'id'])
|
|
282
|
+
self.search_tree.setHeaderLabels(['Class name', 'Object name', 'Number of children', 'id'])
|
|
283
|
+
|
|
284
|
+
s_layout = QVBoxLayout(self.search_widget)
|
|
285
|
+
s_layout.addWidget(self.search_line)
|
|
286
|
+
s_layout.addWidget(self.search_tree)
|
|
287
|
+
|
|
288
|
+
layout.addWidget(self.label)
|
|
289
|
+
layout.addWidget(self.update_button)
|
|
290
|
+
layout.addWidget(self.splitter)
|
|
291
|
+
|
|
292
|
+
self.splitter.addWidget(self.widget_list)
|
|
293
|
+
self.splitter.addWidget(self.differ_list)
|
|
294
|
+
self.splitter.addWidget(self.search_widget)
|
|
295
|
+
|
|
296
|
+
self.update_button.clicked.connect(self.update_widget_list)
|
|
297
|
+
self.search_line.editingFinished.connect(self._update_search_list)
|
|
298
|
+
|
|
299
|
+
self.differ_list.hide()
|
|
300
|
+
|
|
301
|
+
@pyqtSlot(name='updateSearchList')
|
|
302
|
+
def _update_search_list(self):
|
|
303
|
+
search: str = self.search_line.text().lower()
|
|
304
|
+
self.search_tree.clear()
|
|
305
|
+
for key, value in self.item_dict.items():
|
|
306
|
+
if key.lower().startswith(search):
|
|
307
|
+
for name_list in value:
|
|
308
|
+
TreeWidgetItem(self.search_tree, name_list)
|
|
309
|
+
|
|
310
|
+
def update_widget_list(self):
|
|
311
|
+
self.widget_list.clear()
|
|
312
|
+
self.differ_list.clear()
|
|
313
|
+
self.item_dict.clear()
|
|
314
|
+
|
|
315
|
+
count = 0
|
|
316
|
+
new_id_dict: Dict[int, Tuple[list, int]] = {}
|
|
317
|
+
|
|
318
|
+
for obj in QApplication.topLevelWidgets():
|
|
319
|
+
count += self._update_list(obj, self.widget_list, new_id_dict)
|
|
320
|
+
|
|
321
|
+
self.widget_list.update()
|
|
322
|
+
self.label.setText(f'Number of widgets = {count}')
|
|
323
|
+
self.widget_list.sortByColumn(2, Qt.DescendingOrder)
|
|
324
|
+
|
|
325
|
+
for value in self.id_dict.values():
|
|
326
|
+
QListWidgetItem(' '.join(value[0]), self.differ_list)
|
|
327
|
+
|
|
328
|
+
self.id_dict = new_id_dict
|
|
329
|
+
|
|
330
|
+
def _update_list(self, parent_obj: QObject,
|
|
331
|
+
parent_node: QTreeWidget or QTreeWidgetItem, new_id_dict: Dict[int, Tuple[List[str], int]]):
|
|
332
|
+
count = 0
|
|
333
|
+
|
|
334
|
+
for obj in parent_obj.children():
|
|
335
|
+
name_list = self._get_name_list(obj)
|
|
336
|
+
item = TreeWidgetItem(parent_node, name_list)
|
|
337
|
+
|
|
338
|
+
obj_count = 0
|
|
339
|
+
|
|
340
|
+
for o in obj.children():
|
|
341
|
+
obj_count += self._update_list(o, item, new_id_dict)
|
|
342
|
+
|
|
343
|
+
item.setText(2, str(obj_count))
|
|
344
|
+
|
|
345
|
+
name_list[2] = str(obj_count)
|
|
346
|
+
self.item_dict[str(obj.__class__.__name__)].add(tuple(name_list))
|
|
347
|
+
|
|
348
|
+
id_ = id(obj)
|
|
349
|
+
new_id_dict[id_] = [item.text(i) for i in range(4)], obj_count
|
|
350
|
+
|
|
351
|
+
_, prev_count = self.id_dict.pop(id_, (None, None))
|
|
352
|
+
|
|
353
|
+
if prev_count is None:
|
|
354
|
+
fr = 1
|
|
355
|
+
elif prev_count + obj_count == 0:
|
|
356
|
+
fr = 0
|
|
357
|
+
else:
|
|
358
|
+
fr = abs(prev_count - obj_count) / (prev_count + obj_count)
|
|
359
|
+
item.setBackground(3, get_color(fr))
|
|
360
|
+
|
|
361
|
+
count += 1 + obj_count
|
|
362
|
+
|
|
363
|
+
return count
|
|
364
|
+
|
|
365
|
+
@staticmethod
|
|
366
|
+
def _get_name_list(obj: QObject):
|
|
367
|
+
return [str(obj.__class__.__name__), obj.objectName(), '', str(id(obj))]
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
class DebugWindow(QWidget):
|
|
371
|
+
def __init__(self, parent=None):
|
|
372
|
+
super().__init__(parent)
|
|
373
|
+
self._init_ui()
|
|
374
|
+
self.show()
|
|
375
|
+
|
|
376
|
+
def _init_ui(self):
|
|
377
|
+
layout = QVBoxLayout(self)
|
|
378
|
+
self.setWindowFlag(Qt.Window)
|
|
379
|
+
self.setWindowTitle('Debugging Window')
|
|
380
|
+
|
|
381
|
+
self.logging_widget = QTextEditLogger(self)
|
|
382
|
+
# self.widget_list = WidgetList(self)
|
|
383
|
+
self.widget_list = TrackerWidget(self)
|
|
384
|
+
self.splitter = QSplitter(orientation=Qt.Vertical, parent=self)
|
|
385
|
+
self.splitter.addWidget(self.logging_widget.widget)
|
|
386
|
+
self.splitter.addWidget(self.widget_list)
|
|
387
|
+
|
|
388
|
+
layout.addWidget(self.splitter)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from pyqtgraph.dockarea import DockArea, Dock
|
|
4
|
+
|
|
5
|
+
from ..app import App
|
|
6
|
+
from .image_viewer import Basic2DImageWidget
|
|
7
|
+
from .polar_image_viewer import PolarImageViewer
|
|
8
|
+
from .project_manager import MainFileWidget
|
|
9
|
+
from .profiles.radial_profile_widget import RadialProfileWidget
|
|
10
|
+
from .profiles.angular_profile_widget import AngularProfileWidget
|
|
11
|
+
from .fitting import FitWidget, RoiFitWidget
|
|
12
|
+
from .save_window import SaveWindow
|
|
13
|
+
from .load_window import LoadFromH5Widget
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AppDockArea(DockArea):
|
|
19
|
+
def __init__(self, parent=None):
|
|
20
|
+
DockArea.__init__(self, parent=parent)
|
|
21
|
+
self._status_dict = defaultdict(lambda: True)
|
|
22
|
+
self.app = App()
|
|
23
|
+
|
|
24
|
+
self.__init_image_viewer()
|
|
25
|
+
self.__init_polar_viewer()
|
|
26
|
+
self.__init_radial_widget()
|
|
27
|
+
self.__init_file_widget()
|
|
28
|
+
self.__init_fit_viewer()
|
|
29
|
+
self.__init_angular_widget()
|
|
30
|
+
|
|
31
|
+
self._DOCK_DICT = {
|
|
32
|
+
'image_view': self.image_viewer_dock,
|
|
33
|
+
'polar': self.polar_viewer_dock,
|
|
34
|
+
'radial_profile': self.radial_profile_dock,
|
|
35
|
+
'file_widget': self.file_dock,
|
|
36
|
+
'angular_profile': self.angular_profile_dock,
|
|
37
|
+
'fit_view': self.fit_view_dock,
|
|
38
|
+
}
|
|
39
|
+
self._apply_default_view()
|
|
40
|
+
self._fit_widget = None
|
|
41
|
+
|
|
42
|
+
self.app.image_holder.sigFitOpen.connect(self._open_fit_widget)
|
|
43
|
+
|
|
44
|
+
def open_load_from_h5_window(self):
|
|
45
|
+
self.app.save_state()
|
|
46
|
+
load_window = LoadFromH5Widget(self.app.data_manager.load_project_from_h5, self)
|
|
47
|
+
load_window.exec()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def open_save_window(self):
|
|
51
|
+
self.app.save_state()
|
|
52
|
+
save_window = SaveWindow(self)
|
|
53
|
+
save_window.sigSaveClicked.connect(self.app.data_manager.save)
|
|
54
|
+
save_window.show()
|
|
55
|
+
|
|
56
|
+
def _open_fit_widget(self, fit_object):
|
|
57
|
+
fit_widget = FitWidget(fit_object, parent=self.parent())
|
|
58
|
+
fit_widget.sigFitApplyActiveImage.connect(self.app.image_holder.apply_fit)
|
|
59
|
+
|
|
60
|
+
def _apply_default_view(self):
|
|
61
|
+
self.show_hide_docks('polar')
|
|
62
|
+
self.show_hide_docks('radial_profile')
|
|
63
|
+
self.show_hide_docks('angular_profile')
|
|
64
|
+
self.show_hide_docks('fit_view')
|
|
65
|
+
|
|
66
|
+
def __init_image_viewer(self):
|
|
67
|
+
self.image_view = Basic2DImageWidget(self)
|
|
68
|
+
dock = Dock('Image Viewer')
|
|
69
|
+
dock.addWidget(self.image_view)
|
|
70
|
+
self.addDock(dock, size=(1000, 1000))
|
|
71
|
+
self.image_viewer_dock = dock
|
|
72
|
+
|
|
73
|
+
def __init_fit_viewer(self):
|
|
74
|
+
self.fit_view = RoiFitWidget(self)
|
|
75
|
+
dock = Dock('Radial Fit')
|
|
76
|
+
dock.addWidget(self.fit_view)
|
|
77
|
+
self.addDock(dock, size=(1000, 1000), position='right', relativeTo=self.image_viewer_dock)
|
|
78
|
+
self.fit_view_dock = dock
|
|
79
|
+
|
|
80
|
+
def __init_polar_viewer(self):
|
|
81
|
+
self.polar_view = PolarImageViewer(self)
|
|
82
|
+
dock = Dock('Polar ImageViewer')
|
|
83
|
+
dock.addWidget(self.polar_view)
|
|
84
|
+
self.addDock(dock, position='right')
|
|
85
|
+
self.polar_viewer_dock = dock
|
|
86
|
+
|
|
87
|
+
def __init_radial_widget(self):
|
|
88
|
+
self.radial_profile = RadialProfileWidget(self)
|
|
89
|
+
dock = Dock('Radial Profile')
|
|
90
|
+
dock.addWidget(self.radial_profile)
|
|
91
|
+
self.addDock(dock, position='bottom')
|
|
92
|
+
self.radial_profile_dock = dock
|
|
93
|
+
|
|
94
|
+
def __init_angular_widget(self):
|
|
95
|
+
self.angular_profile = AngularProfileWidget(self)
|
|
96
|
+
dock = Dock('Angular Profile')
|
|
97
|
+
dock.addWidget(self.angular_profile)
|
|
98
|
+
self.addDock(dock, position='bottom')
|
|
99
|
+
self.angular_profile_dock = dock
|
|
100
|
+
|
|
101
|
+
def __init_file_widget(self):
|
|
102
|
+
self.file_widget = MainFileWidget(self.app, self)
|
|
103
|
+
self.file_dock = Dock('Project Manager')
|
|
104
|
+
self.file_dock.addWidget(self.file_widget)
|
|
105
|
+
self.addDock(self.file_dock, position='left')
|
|
106
|
+
|
|
107
|
+
def show_hide_docks(self, dock_name: str):
|
|
108
|
+
assert dock_name in self._DOCK_DICT.keys()
|
|
109
|
+
dock = self._DOCK_DICT[dock_name]
|
|
110
|
+
status = self._status_dict[dock_name]
|
|
111
|
+
if status:
|
|
112
|
+
dock.hide()
|
|
113
|
+
else:
|
|
114
|
+
dock.show()
|
|
115
|
+
self._status_dict[dock_name] = not status
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import sys
|
|
3
|
+
import traceback
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from .tools import show_error
|
|
7
|
+
|
|
8
|
+
from PyQt5.QtCore import QObject, pyqtSignal
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class UncaughtHook(QObject):
|
|
12
|
+
|
|
13
|
+
_exception_caught = pyqtSignal(object)
|
|
14
|
+
log = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
def __init__(self, *args, **kwargs):
|
|
17
|
+
super(UncaughtHook, self).__init__(*args, **kwargs)
|
|
18
|
+
|
|
19
|
+
# this registers the exception_hook() function as hook with the Python interpreter
|
|
20
|
+
sys.excepthook = self.exception_hook
|
|
21
|
+
|
|
22
|
+
# connect signal to execute the message box function always on main thread
|
|
23
|
+
self._exception_caught.connect(show_error)
|
|
24
|
+
|
|
25
|
+
def exception_hook(self, exc_type, exc_value, exc_traceback):
|
|
26
|
+
"""
|
|
27
|
+
Function handling uncaught exceptions.
|
|
28
|
+
It is triggered each time an uncaught exception occurs.
|
|
29
|
+
"""
|
|
30
|
+
if issubclass(exc_type, KeyboardInterrupt):
|
|
31
|
+
# ignore keyboard interrupt to support console applications
|
|
32
|
+
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
|
33
|
+
else:
|
|
34
|
+
exc_info = (exc_type, exc_value, exc_traceback)
|
|
35
|
+
log_msg = '\n'.join([''.join(traceback.format_tb(exc_traceback)),
|
|
36
|
+
'{0}: {1}'.format(exc_type.__name__, exc_value)])
|
|
37
|
+
|
|
38
|
+
self.log.critical("Uncaught exception:\n {0}".format(log_msg), exc_info=exc_info)
|
|
39
|
+
|
|
40
|
+
# trigger message box show
|
|
41
|
+
self._exception_caught.emit(log_msg)
|
|
42
|
+
|