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,146 @@
|
|
|
1
|
+
from collections import OrderedDict
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import (QWidget,
|
|
4
|
+
QGridLayout, QTreeView, QPushButton)
|
|
5
|
+
from PyQt5.QtCore import Qt, QObject, QItemSelection
|
|
6
|
+
from PyQt5.QtGui import QColor, QStandardItem, QStandardItemModel
|
|
7
|
+
|
|
8
|
+
from mlgidGUI.app.cif_rois.cif_peaks_calculation import cif_results
|
|
9
|
+
from mlgidGUI.app.rois import Roi
|
|
10
|
+
from mlgidGUI.app.rois.roi import CIFPeakRoi
|
|
11
|
+
from mlgidGUI.gui.roi_widgets import AbstractRoiHolder, AbstractRoiWidget
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class StandardItem(QStandardItem):
|
|
15
|
+
def __init__(self, text: str, key: int, is_numeric: bool = True):
|
|
16
|
+
super().__init__(text)
|
|
17
|
+
self.key = key
|
|
18
|
+
self.is_numeric = is_numeric
|
|
19
|
+
|
|
20
|
+
def __lt__(self, other):
|
|
21
|
+
if self.is_numeric:
|
|
22
|
+
try:
|
|
23
|
+
return float(self.text()) < float(other.text())
|
|
24
|
+
except ValueError:
|
|
25
|
+
pass
|
|
26
|
+
return super().__lt__(other)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CIFRingWidget(AbstractRoiWidget, QObject):
|
|
30
|
+
COLOR_DICT = dict(
|
|
31
|
+
default=QColor(0, 0, 0, 0),
|
|
32
|
+
active=QColor(0, 128, 255, 100),
|
|
33
|
+
fixed=QColor(0, 255, 0, 100),
|
|
34
|
+
fixed_active=QColor(255, 0, 255, 100)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
PARAM_DICT = OrderedDict([('cif_file', 'CIF File'),
|
|
38
|
+
('q_z', 'Qz'),
|
|
39
|
+
('q_xy', 'Qxy'),
|
|
40
|
+
('miller_id', 'Miller indices'),
|
|
41
|
+
('intensity', 'Intensity'),
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
def __init__(self, roi: Roi, parent):
|
|
45
|
+
AbstractRoiWidget.__init__(self, roi, enable_context=True)
|
|
46
|
+
QObject.__init__(self, parent)
|
|
47
|
+
|
|
48
|
+
self.__items = self._init_items()
|
|
49
|
+
self.update_color()
|
|
50
|
+
#self.move_roi()
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def row(self):
|
|
54
|
+
return self.__items['name'].row()
|
|
55
|
+
|
|
56
|
+
def _init_items(self) -> dict:
|
|
57
|
+
roi_key = self.roi.key
|
|
58
|
+
items = dict(name = StandardItem(self.roi.name, roi_key),
|
|
59
|
+
key = StandardItem(str(self.roi.key), roi_key),
|
|
60
|
+
type = StandardItem(str(self.roi.type.name), roi_key, False),
|
|
61
|
+
q_z = StandardItem(f'{self.roi.q_z:.2f}', roi_key, False),
|
|
62
|
+
q_xy=StandardItem(f'{self.roi.q_xy:.2f}', roi_key, False),
|
|
63
|
+
confidence_level_name = StandardItem(str(self.roi.confidence_level_name), roi_key),
|
|
64
|
+
cif_file = StandardItem(str(self.roi.cif_file), roi_key),
|
|
65
|
+
intensity = StandardItem(f'{self.roi.intensity_raw:.0f}', roi_key),
|
|
66
|
+
miller_id=StandardItem(str(self.roi.miller_id), roi_key),
|
|
67
|
+
)
|
|
68
|
+
return items
|
|
69
|
+
|
|
70
|
+
def items(self):
|
|
71
|
+
return [self.__items[key] for key in self.PARAM_DICT.keys()]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class CIFRingsWidget(AbstractRoiHolder, QWidget):
|
|
75
|
+
def __init__(self, parent=None):
|
|
76
|
+
AbstractRoiHolder.__init__(self, 'RoiMetaWidget')
|
|
77
|
+
QWidget.__init__(self, parent)
|
|
78
|
+
|
|
79
|
+
self._model = QStandardItemModel(0, len(CIFRingWidget.PARAM_DICT), self)
|
|
80
|
+
self._model.setHorizontalHeaderLabels(list(CIFRingWidget.PARAM_DICT.values()))
|
|
81
|
+
# self._model.setRowCount(0)
|
|
82
|
+
|
|
83
|
+
self.tree_view = QTreeView(self)
|
|
84
|
+
self.tree_view.setModel(self._model)
|
|
85
|
+
|
|
86
|
+
self.tree_view.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
87
|
+
self.tree_view.customContextMenuRequested.connect(self._custom_menu)
|
|
88
|
+
self.tree_view.selectionModel().selectionChanged.connect(self._selection_changed)
|
|
89
|
+
self.tree_view.header().setSectionsClickable(True)
|
|
90
|
+
self.tree_view.header().setSortIndicatorShown(True)
|
|
91
|
+
self.tree_view.header().sortIndicatorChanged.connect(self._model.sort)
|
|
92
|
+
|
|
93
|
+
self._init_ui()
|
|
94
|
+
|
|
95
|
+
def _init_connect(self):
|
|
96
|
+
pass
|
|
97
|
+
|
|
98
|
+
def _init_ui(self):
|
|
99
|
+
layout = QGridLayout(self)
|
|
100
|
+
layout.addWidget(self.tree_view)
|
|
101
|
+
layout.addWidget(QPushButton('Add ROI by holding `Ctrl + Alt` and click and hold on the image'))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def delete_all(self) -> None:
|
|
105
|
+
self._model.removeRows(0, self._model.rowCount())
|
|
106
|
+
|
|
107
|
+
def empty_simulation(self) -> None:
|
|
108
|
+
roi_widget = CIFRingWidget(CIFPeakRoi(
|
|
109
|
+
radius = 0,
|
|
110
|
+
width = 0,
|
|
111
|
+
cif_file='Please add a CIF-file to start the simulation.',
|
|
112
|
+
), self.tree_view)
|
|
113
|
+
self._model.appendRow(roi_widget.items())
|
|
114
|
+
|
|
115
|
+
def resizeColumns(self):
|
|
116
|
+
for col in range(self._model.columnCount()):
|
|
117
|
+
self.tree_view.resizeColumnToContents(col)
|
|
118
|
+
|
|
119
|
+
def _delete_roi_widget(self, roi_widget) -> None:
|
|
120
|
+
self.tree_view.selectionModel().blockSignals(True)
|
|
121
|
+
self._model.removeRow(roi_widget.row)
|
|
122
|
+
self.tree_view.selectionModel().blockSignals(False)
|
|
123
|
+
|
|
124
|
+
def _make_roi_widget(self, roi: Roi) -> AbstractRoiWidget:
|
|
125
|
+
try:
|
|
126
|
+
roi_widget = CIFRingWidget(roi, self.tree_view)
|
|
127
|
+
self._model.appendRow(roi_widget.items())
|
|
128
|
+
return roi_widget
|
|
129
|
+
except:
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
def _custom_menu(self, pos):
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
def _selection_changed(self, item: QItemSelection):
|
|
136
|
+
try:
|
|
137
|
+
cif_results[self.selected_key].roi_widget.set_unselected()
|
|
138
|
+
except:
|
|
139
|
+
pass
|
|
140
|
+
try:
|
|
141
|
+
keys = set(self._model.itemFromIndex(index).key for index in item.indexes())
|
|
142
|
+
if len(keys) == 1:
|
|
143
|
+
cif_results[next(iter(keys))].roi_widget.set_selected()
|
|
144
|
+
self.selected_key = next(iter(keys))
|
|
145
|
+
except:
|
|
146
|
+
pass
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from collections import OrderedDict
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import (QWidget,
|
|
4
|
+
QGridLayout, QTreeView)
|
|
5
|
+
from PyQt5.QtCore import Qt, QObject, QItemSelection
|
|
6
|
+
from PyQt5.QtGui import QColor, QStandardItem, QStandardItemModel
|
|
7
|
+
|
|
8
|
+
from mlgidGUI.app.rois import Roi
|
|
9
|
+
from mlgidGUI.gui.roi_widgets import AbstractRoiHolder, AbstractRoiWidget
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MetaWidget(AbstractRoiHolder, QWidget):
|
|
14
|
+
def __init__(self, parent=None):
|
|
15
|
+
pass
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import (QTreeView, QMenu,
|
|
4
|
+
QWidget, QHBoxLayout, QLabel)
|
|
5
|
+
from PyQt5.QtGui import QStandardItem, QStandardItemModel
|
|
6
|
+
from PyQt5.QtCore import Qt
|
|
7
|
+
|
|
8
|
+
from ..basic_widgets import RoundedPushButton
|
|
9
|
+
from ..tools import Icon, get_folder_filepath, get_filepath_dialog
|
|
10
|
+
from ...app.file_manager import FileManager, ImageKey, FolderKey
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FileModel(QStandardItemModel):
|
|
14
|
+
def __init__(self):
|
|
15
|
+
super(FileModel, self).__init__()
|
|
16
|
+
self.setHorizontalHeaderLabels([''])
|
|
17
|
+
self.setRowCount(0)
|
|
18
|
+
|
|
19
|
+
def new_project(self):
|
|
20
|
+
self.removeRows(1, self.rowCount() - 1)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ImageItem(QStandardItem):
|
|
24
|
+
|
|
25
|
+
def __init__(self, key: ImageKey):
|
|
26
|
+
super().__init__(key.name)
|
|
27
|
+
self.key: ImageKey = key
|
|
28
|
+
self.setIcon(Icon('data'))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class FolderItem(QStandardItem):
|
|
32
|
+
|
|
33
|
+
def __init__(self, key: FolderKey):
|
|
34
|
+
super().__init__(key.name)
|
|
35
|
+
self.key = key
|
|
36
|
+
self.setIcon(Icon('folder'))
|
|
37
|
+
self._updated: bool = False
|
|
38
|
+
|
|
39
|
+
def on_clicked(self):
|
|
40
|
+
if not self._updated:
|
|
41
|
+
self.update()
|
|
42
|
+
self._updated = True
|
|
43
|
+
|
|
44
|
+
def _fill(self):
|
|
45
|
+
for folder in self.key.folder_children:
|
|
46
|
+
self.appendRow(FolderItem(folder))
|
|
47
|
+
for image in self.key.image_children:
|
|
48
|
+
self.appendRow(ImageItem(image))
|
|
49
|
+
|
|
50
|
+
def update(self):
|
|
51
|
+
self.clear()
|
|
52
|
+
self.key.update()
|
|
53
|
+
self._fill()
|
|
54
|
+
|
|
55
|
+
def clear(self):
|
|
56
|
+
self.removeRows(0, self.rowCount())
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class FileViewer(QTreeView):
|
|
60
|
+
|
|
61
|
+
def __init__(self, fm: FileManager, parent=None):
|
|
62
|
+
super().__init__(parent)
|
|
63
|
+
self._model = FileModel()
|
|
64
|
+
self.setModel(self._model)
|
|
65
|
+
self.setEditTriggers(QTreeView.NoEditTriggers)
|
|
66
|
+
self._fm = fm
|
|
67
|
+
self._fm.sigNewFile.connect(self._add_new_file)
|
|
68
|
+
self._fm.sigNewFolder.connect(self._add_new_folder)
|
|
69
|
+
self._fm.sigProjectClosed.connect(self._model.new_project)
|
|
70
|
+
|
|
71
|
+
self.selectionModel().currentChanged.connect(self._on_clicked)
|
|
72
|
+
self.customContextMenuRequested.connect(self._context_menu)
|
|
73
|
+
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
74
|
+
self._init_ui()
|
|
75
|
+
self.show()
|
|
76
|
+
|
|
77
|
+
def _init_ui(self):
|
|
78
|
+
add_file_button = RoundedPushButton(icon=Icon('data'), radius=30,
|
|
79
|
+
background_color='transparent')
|
|
80
|
+
add_file_button.clicked.connect(self._open_add_file_menu)
|
|
81
|
+
add_folder_button = RoundedPushButton(icon=Icon('folder'), radius=30,
|
|
82
|
+
background_color='transparent')
|
|
83
|
+
add_folder_button.clicked.connect(self._open_add_folder_menu)
|
|
84
|
+
layout = self._get_header_layout(QStandardItem(), 'Files')
|
|
85
|
+
layout.addWidget(add_file_button)
|
|
86
|
+
layout.addWidget(add_folder_button)
|
|
87
|
+
|
|
88
|
+
def _get_header_layout(self, item: QStandardItem, label: str):
|
|
89
|
+
header_widget = QWidget(self)
|
|
90
|
+
layout = QHBoxLayout()
|
|
91
|
+
header_widget.setLayout(layout)
|
|
92
|
+
label_widget = QLabel(label)
|
|
93
|
+
layout.addWidget(label_widget, alignment=Qt.AlignLeft)
|
|
94
|
+
layout.addStretch(1)
|
|
95
|
+
self._model.appendRow(item)
|
|
96
|
+
self.setIndexWidget(item.index(), header_widget)
|
|
97
|
+
return layout
|
|
98
|
+
|
|
99
|
+
def clear(self):
|
|
100
|
+
self._model.removeRows(0, self._model.rowCount())
|
|
101
|
+
self._init_ui()
|
|
102
|
+
|
|
103
|
+
def _add_new_file(self, key: ImageKey):
|
|
104
|
+
self._model.appendRow(ImageItem(key))
|
|
105
|
+
|
|
106
|
+
def _add_new_cif_file(self, key):
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
def _add_new_folder(self, key: FolderKey):
|
|
110
|
+
self._model.appendRow(FolderItem(key))
|
|
111
|
+
|
|
112
|
+
def _on_clicked(self, index):
|
|
113
|
+
item = self._model.itemFromIndex(index)
|
|
114
|
+
if isinstance(item, ImageItem):
|
|
115
|
+
self._fm.change_image(item.key)
|
|
116
|
+
elif isinstance(item, FolderItem):
|
|
117
|
+
item.on_clicked()
|
|
118
|
+
self.setExpanded(item.index(), True)
|
|
119
|
+
|
|
120
|
+
def _open_add_file_menu(self):
|
|
121
|
+
path = get_filepath_dialog(self)
|
|
122
|
+
if path:
|
|
123
|
+
self._fm.add_root_path_to_project(path)
|
|
124
|
+
|
|
125
|
+
def _open_add_folder_menu(self):
|
|
126
|
+
path = get_folder_filepath(self, message='Choose directory containing images or h5 files')
|
|
127
|
+
if path:
|
|
128
|
+
self._fm.add_root_path_to_project(path)
|
|
129
|
+
|
|
130
|
+
def _context_menu(self, position):
|
|
131
|
+
item = self._model.itemFromIndex(self.indexAt(position))
|
|
132
|
+
menu = QMenu()
|
|
133
|
+
if isinstance(item, FolderItem):
|
|
134
|
+
update_folder = menu.addAction('Update folder')
|
|
135
|
+
update_folder.triggered.connect(item.update)
|
|
136
|
+
close_folder = menu.addAction('Remove from project')
|
|
137
|
+
close_folder.triggered.connect(
|
|
138
|
+
lambda *x, it=item: self._remove_item(it))
|
|
139
|
+
|
|
140
|
+
elif isinstance(item, ImageItem):
|
|
141
|
+
close_image = menu.addAction('Remove from project')
|
|
142
|
+
close_image.triggered.connect(
|
|
143
|
+
lambda *x, it=item: self._remove_item(it))
|
|
144
|
+
else:
|
|
145
|
+
return
|
|
146
|
+
menu.exec_(self.viewport().mapToGlobal(position))
|
|
147
|
+
|
|
148
|
+
def _remove_item(self, item: FolderItem or ImageItem):
|
|
149
|
+
self._fm.remove_key(item.key)
|
|
150
|
+
self.clear()
|
|
151
|
+
self._fm.init_file_viewer()
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
from collections import OrderedDict
|
|
2
|
+
|
|
3
|
+
from PyQt5.QtWidgets import (QWidget,
|
|
4
|
+
QGridLayout, QTreeView, QPushButton)
|
|
5
|
+
from PyQt5.QtCore import Qt, QObject, QItemSelection
|
|
6
|
+
from PyQt5.QtGui import QColor, QStandardItem, QStandardItemModel
|
|
7
|
+
|
|
8
|
+
from mlgidGUI.app.rois import Roi
|
|
9
|
+
from mlgidGUI.gui.roi_widgets import AbstractRoiHolder, AbstractRoiWidget
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StandardItem(QStandardItem):
|
|
13
|
+
def __init__(self, text: str, key: int, is_numeric: bool = True):
|
|
14
|
+
super().__init__(text)
|
|
15
|
+
self.key = key
|
|
16
|
+
self.is_numeric = is_numeric
|
|
17
|
+
|
|
18
|
+
def __lt__(self, other):
|
|
19
|
+
if self.is_numeric:
|
|
20
|
+
try:
|
|
21
|
+
return float(self.text()) < float(other.text())
|
|
22
|
+
except ValueError:
|
|
23
|
+
pass
|
|
24
|
+
return super().__lt__(other)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RoiWidgetItem(AbstractRoiWidget, QObject):
|
|
28
|
+
COLOR_DICT = dict(
|
|
29
|
+
default=QColor(0, 0, 0, 0),
|
|
30
|
+
active=QColor(0, 128, 255, 100),
|
|
31
|
+
fixed=QColor(0, 255, 0, 100),
|
|
32
|
+
fixed_active=QColor(255, 0, 255, 100)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
PARAM_DICT = OrderedDict([('name', 'Name'),
|
|
36
|
+
('type', 'ROI type'),
|
|
37
|
+
('radius', 'Radius'),
|
|
38
|
+
('width', 'Width'),
|
|
39
|
+
('angle', 'Angle'),
|
|
40
|
+
('angle_std', 'Angle Width'),
|
|
41
|
+
('confidence_level_name', 'Confidence level'),
|
|
42
|
+
('key', 'Key'),
|
|
43
|
+
('cif_file', 'CIF File')
|
|
44
|
+
])
|
|
45
|
+
|
|
46
|
+
def __init__(self, roi: Roi, parent):
|
|
47
|
+
AbstractRoiWidget.__init__(self, roi, enable_context=True)
|
|
48
|
+
QObject.__init__(self, parent)
|
|
49
|
+
|
|
50
|
+
self.__items = self._init_items()
|
|
51
|
+
self.update_color()
|
|
52
|
+
self.move_roi()
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def row(self):
|
|
56
|
+
return self.__items['name'].row()
|
|
57
|
+
|
|
58
|
+
def _init_items(self) -> dict:
|
|
59
|
+
roi_key = self.roi.key
|
|
60
|
+
items = dict(name=StandardItem(self.roi.name, roi_key),
|
|
61
|
+
key=StandardItem(str(self.roi.key), roi_key),
|
|
62
|
+
type=StandardItem(str(self.roi.type.name), roi_key, False),
|
|
63
|
+
confidence_level_name=StandardItem(str(self.roi.confidence_level_name), roi_key),
|
|
64
|
+
cif_file = StandardItem(str(self.roi.cif_file), roi_key)
|
|
65
|
+
)
|
|
66
|
+
for key in 'radius width angle angle_std'.split():
|
|
67
|
+
items[key] = StandardItem('', roi_key)
|
|
68
|
+
|
|
69
|
+
return items
|
|
70
|
+
|
|
71
|
+
def move_roi(self):
|
|
72
|
+
for key in 'radius width angle angle_std'.split():
|
|
73
|
+
self.__items[key].setText(f'{getattr(self.roi, key):.2f}')
|
|
74
|
+
|
|
75
|
+
def items(self):
|
|
76
|
+
return [self.__items[key] for key in self.PARAM_DICT.keys()]
|
|
77
|
+
|
|
78
|
+
def send_move(self):
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
def change_conf_level(self):
|
|
82
|
+
self.__items['confidence_level_name'].setText(str(self.roi.confidence_level_name))
|
|
83
|
+
|
|
84
|
+
def change_cif_file(self):
|
|
85
|
+
self.__items['cif_file'].setText(str(self.roi.cif_file))
|
|
86
|
+
|
|
87
|
+
def rename(self):
|
|
88
|
+
self.__items['name'].setText(self.roi.name)
|
|
89
|
+
|
|
90
|
+
def change_type(self):
|
|
91
|
+
self.__items['type'].setText(str(self.roi.type.name))
|
|
92
|
+
|
|
93
|
+
def set_color(self, color):
|
|
94
|
+
for item in self.__items.values():
|
|
95
|
+
item.setBackground(color)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class RoiMetaWidget(AbstractRoiHolder, QWidget):
|
|
99
|
+
def __init__(self, parent=None):
|
|
100
|
+
AbstractRoiHolder.__init__(self, 'ROIMetaWidget')
|
|
101
|
+
QWidget.__init__(self, parent)
|
|
102
|
+
|
|
103
|
+
self._model = QStandardItemModel(0, len(RoiWidgetItem.PARAM_DICT), self)
|
|
104
|
+
self._model.setHorizontalHeaderLabels(list(RoiWidgetItem.PARAM_DICT.values()))
|
|
105
|
+
|
|
106
|
+
self.tree_view = QTreeView(self)
|
|
107
|
+
self.tree_view.setModel(self._model)
|
|
108
|
+
|
|
109
|
+
self.tree_view.setContextMenuPolicy(Qt.CustomContextMenu)
|
|
110
|
+
self.tree_view.customContextMenuRequested.connect(self._custom_menu)
|
|
111
|
+
self.tree_view.selectionModel().selectionChanged.connect(self._selection_changed)
|
|
112
|
+
self.tree_view.header().setSectionsClickable(True)
|
|
113
|
+
self.tree_view.header().setSortIndicatorShown(True)
|
|
114
|
+
self.tree_view.header().sortIndicatorChanged.connect(self._model.sort)
|
|
115
|
+
self._roi_dict.sig_roi_renamed.connect(self._rename)
|
|
116
|
+
self._roi_dict.sig_cif_renamed.connect(self._change_cif_file)
|
|
117
|
+
self._roi_dict.sigConfLevelChanged.connect(self._change_conf_level)
|
|
118
|
+
|
|
119
|
+
self._init_ui()
|
|
120
|
+
|
|
121
|
+
def _init_connect(self):
|
|
122
|
+
super()._init_connect()
|
|
123
|
+
self._roi_dict.sig_type_changed.connect(self._type_changed)
|
|
124
|
+
|
|
125
|
+
def _init_ui(self):
|
|
126
|
+
layout = QGridLayout(self)
|
|
127
|
+
layout.addWidget(self.tree_view)
|
|
128
|
+
layout.addWidget(QPushButton('Add ROI by holding `Ctrl + Alt` and click and hold on the image'))
|
|
129
|
+
|
|
130
|
+
def _type_changed(self, key: int):
|
|
131
|
+
self._roi_widgets[key].change_type()
|
|
132
|
+
|
|
133
|
+
def _delete_roi_widget(self, roi_widget) -> None:
|
|
134
|
+
self.tree_view.selectionModel().blockSignals(True)
|
|
135
|
+
self._model.removeRow(roi_widget.row)
|
|
136
|
+
self.tree_view.selectionModel().blockSignals(False)
|
|
137
|
+
|
|
138
|
+
def _make_roi_widget(self, roi: Roi) -> AbstractRoiWidget:
|
|
139
|
+
roi_widget = RoiWidgetItem(roi, self.tree_view)
|
|
140
|
+
self._model.appendRow(roi_widget.items())
|
|
141
|
+
for col in range(self._model.columnCount()):
|
|
142
|
+
self.tree_view.resizeColumnToContents(col)
|
|
143
|
+
return roi_widget
|
|
144
|
+
|
|
145
|
+
def _custom_menu(self, pos):
|
|
146
|
+
item = self._model.itemFromIndex(self.tree_view.indexAt(pos))
|
|
147
|
+
if item:
|
|
148
|
+
self._roi_widgets[item.key].show_context_menu()
|
|
149
|
+
|
|
150
|
+
def _selection_changed(self, item: QItemSelection):
|
|
151
|
+
keys = set(self._model.itemFromIndex(index).key for index in item.indexes())
|
|
152
|
+
if len(keys) == 1:
|
|
153
|
+
self._roi_dict.select(next(iter(keys)))
|
|
154
|
+
|
|
155
|
+
def _rename(self, key: int):
|
|
156
|
+
try:
|
|
157
|
+
self._roi_widgets[key].rename()
|
|
158
|
+
except KeyError:
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
def _change_conf_level(self, key: int):
|
|
162
|
+
try:
|
|
163
|
+
self._roi_widgets[key].change_conf_level()
|
|
164
|
+
except KeyError:
|
|
165
|
+
pass
|
|
166
|
+
|
|
167
|
+
def _change_cif_file(self, key: int):
|
|
168
|
+
try:
|
|
169
|
+
self._roi_widgets[key].change_cif_file()
|
|
170
|
+
except KeyError:
|
|
171
|
+
pass
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from .rois_context_menu import RoiContextMenu
|
|
2
|
+
from .roi_2d_rect_widget import Roi2DRect
|
|
3
|
+
from .roi_1d_widget import Roi1D, Roi1DAngular
|
|
4
|
+
from .roi_2d_ring_widget import Roi2DRing, BasicRoiRing
|
|
5
|
+
from .abstract_roi_widget import AbstractRoiWidget
|
|
6
|
+
from .abstract_roi_holder import AbstractRoiHolder
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Dict
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from PyQt5.QtCore import Qt
|
|
6
|
+
|
|
7
|
+
from .abstract_roi_widget import AbstractRoiWidget
|
|
8
|
+
from ...app.app import App
|
|
9
|
+
from ...app.rois.roi import Roi
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AbstractRoiHolder(object):
|
|
13
|
+
log = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
def __init__(self, name: str):
|
|
16
|
+
self._name = name
|
|
17
|
+
self._roi_dict = App().roi_dict
|
|
18
|
+
self._roi_widgets: Dict[int, AbstractRoiWidget] = {}
|
|
19
|
+
self._init_connect()
|
|
20
|
+
self._segments_hidden: bool = False
|
|
21
|
+
self._key_patch = _KeyEventsPatch(Qt.Key_H)
|
|
22
|
+
|
|
23
|
+
def _init_connect(self):
|
|
24
|
+
self._roi_dict.sig_roi_created.connect(self._create_roi)
|
|
25
|
+
self._roi_dict.sig_roi_deleted.connect(self._delete_roi)
|
|
26
|
+
self._roi_dict.sig_roi_moved.connect(self._move_rois)
|
|
27
|
+
self._roi_dict.sig_selected.connect(self._update_select)
|
|
28
|
+
self._roi_dict.sig_fixed.connect(self._fix_rois)
|
|
29
|
+
self._roi_dict.sig_unfixed.connect(self._unfix_rois)
|
|
30
|
+
|
|
31
|
+
def register_key_patch(self, widget=None):
|
|
32
|
+
widget = widget or self
|
|
33
|
+
self._key_patch.attach_to_widget(widget)
|
|
34
|
+
self._key_patch.set_press_func(self.hide_segments)
|
|
35
|
+
self._key_patch.set_release_func(self.show_segments)
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def segments_hidden(self):
|
|
39
|
+
return self._segments_hidden
|
|
40
|
+
|
|
41
|
+
def hide_show_segments(self, hide: bool = None):
|
|
42
|
+
if hide is None:
|
|
43
|
+
hide = not self._segments_hidden
|
|
44
|
+
if hide:
|
|
45
|
+
self.hide_segments()
|
|
46
|
+
else:
|
|
47
|
+
self.show_segments()
|
|
48
|
+
|
|
49
|
+
def hide_segments(self, *args):
|
|
50
|
+
for widget in self._roi_widgets.values():
|
|
51
|
+
widget.hide()
|
|
52
|
+
self._segments_hidden = True
|
|
53
|
+
|
|
54
|
+
def show_segments(self, *args):
|
|
55
|
+
for widget in self._roi_widgets.values():
|
|
56
|
+
widget.show()
|
|
57
|
+
self._segments_hidden = False
|
|
58
|
+
|
|
59
|
+
def _create_roi(self, keys: tuple):
|
|
60
|
+
for key in keys:
|
|
61
|
+
try:
|
|
62
|
+
self._roi_widgets[key] = self._make_roi_widget(self._roi_dict[key])
|
|
63
|
+
self._connect_roi_widget(self._roi_widgets[key])
|
|
64
|
+
except:
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
def _move_rois(self, keys: tuple, name: str):
|
|
68
|
+
if name != self._name:
|
|
69
|
+
for key in keys:
|
|
70
|
+
try:
|
|
71
|
+
self._roi_widgets[key].move_roi()
|
|
72
|
+
except KeyError as err:
|
|
73
|
+
self.log.error(f'Key error in {self.__class__.__name__}')
|
|
74
|
+
self.log.exception(err)
|
|
75
|
+
|
|
76
|
+
def _connect_roi_widget(self, roi_widget: AbstractRoiWidget):
|
|
77
|
+
roi_widget.sigRoiMoved.connect(
|
|
78
|
+
lambda k: self._roi_dict.move_roi(k, self._name))
|
|
79
|
+
roi_widget.sigSelected.connect(self._roi_dict.select)
|
|
80
|
+
roi_widget.sigShiftSelected.connect(self._roi_dict.shift_select)
|
|
81
|
+
|
|
82
|
+
def _update_select(self, keys: tuple):
|
|
83
|
+
for key in keys:
|
|
84
|
+
try:
|
|
85
|
+
self._roi_widgets[key].update_select()
|
|
86
|
+
except KeyError as err:
|
|
87
|
+
self.log.error(f'Key error in {self.__class__.__name__}')
|
|
88
|
+
self.log.exception(err)
|
|
89
|
+
|
|
90
|
+
def _delete_roi(self, keys: tuple):
|
|
91
|
+
for key in keys:
|
|
92
|
+
try:
|
|
93
|
+
self._delete_roi_widget(self._roi_widgets.pop(key))
|
|
94
|
+
except KeyError as err:
|
|
95
|
+
self.log.error(f'Key error in {self.__class__.__name__}')
|
|
96
|
+
self.log.exception(err)
|
|
97
|
+
|
|
98
|
+
def _fix_rois(self, keys: tuple):
|
|
99
|
+
for key in keys:
|
|
100
|
+
try:
|
|
101
|
+
self._roi_widgets[key].fix()
|
|
102
|
+
except KeyError as err:
|
|
103
|
+
self.log.error(f'Key error in {self.__class__.__name__}')
|
|
104
|
+
self.log.exception(err)
|
|
105
|
+
|
|
106
|
+
def _unfix_rois(self, keys: tuple):
|
|
107
|
+
for key in keys:
|
|
108
|
+
try:
|
|
109
|
+
self._roi_widgets[key].unfix()
|
|
110
|
+
except KeyError as err:
|
|
111
|
+
self.log.error(f'Key error in {self.__class__.__name__}')
|
|
112
|
+
self.log.exception(err)
|
|
113
|
+
|
|
114
|
+
@abstractmethod
|
|
115
|
+
def _delete_roi_widget(self, roi_widget) -> None:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
@abstractmethod
|
|
119
|
+
def _make_roi_widget(self, roi: Roi) -> AbstractRoiWidget:
|
|
120
|
+
pass
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class _KeyEventsPatch(object):
|
|
124
|
+
def __init__(self, key: int):
|
|
125
|
+
self._key_listened: int = key
|
|
126
|
+
|
|
127
|
+
self._super_key_pressed_func = None
|
|
128
|
+
self._super_key_released_func = None
|
|
129
|
+
self._patched_key_pressed_func = None
|
|
130
|
+
self._patched_key_released_func = None
|
|
131
|
+
self._widget = None
|
|
132
|
+
|
|
133
|
+
self._ctrl_pressed: bool = False
|
|
134
|
+
self._key_pressed: bool = False
|
|
135
|
+
self._pressed: bool = False
|
|
136
|
+
|
|
137
|
+
def attach_to_widget(self, widget):
|
|
138
|
+
if self._widget:
|
|
139
|
+
self.detach_from_widget()
|
|
140
|
+
self._widget = widget
|
|
141
|
+
|
|
142
|
+
self._super_key_pressed_func = widget.keyPressEvent
|
|
143
|
+
self._super_key_released_func = widget.keyReleaseEvent
|
|
144
|
+
widget.keyPressEvent = self._keyPressEvent
|
|
145
|
+
widget.keyReleaseEvent = self._keyReleaseEvent
|
|
146
|
+
|
|
147
|
+
def detach_from_widget(self):
|
|
148
|
+
if self._widget:
|
|
149
|
+
self._widget.keyPressEvent = self._super_key_pressed_func
|
|
150
|
+
self._widget.keyReleaseEvent = self._super_key_released_func
|
|
151
|
+
|
|
152
|
+
self._widget = None
|
|
153
|
+
self._super_key_pressed_func = None
|
|
154
|
+
self._super_key_released_func = None
|
|
155
|
+
self._ctrl_pressed: bool = False
|
|
156
|
+
self._key_pressed: bool = False
|
|
157
|
+
self._pressed: bool = False
|
|
158
|
+
|
|
159
|
+
def set_press_func(self, func):
|
|
160
|
+
self._patched_key_pressed_func = func
|
|
161
|
+
|
|
162
|
+
def set_release_func(self, func):
|
|
163
|
+
self._patched_key_released_func = func
|
|
164
|
+
|
|
165
|
+
def _keyPressEvent(self, ev):
|
|
166
|
+
if not self._widget:
|
|
167
|
+
return
|
|
168
|
+
if ev.key() == self._key_listened:
|
|
169
|
+
self._key_pressed = True
|
|
170
|
+
if ev.key() == Qt.Key_Control:
|
|
171
|
+
self._ctrl_pressed = True
|
|
172
|
+
if self._patched_key_pressed_func:
|
|
173
|
+
if not self._pressed and (self._key_pressed and self._ctrl_pressed):
|
|
174
|
+
self._patched_key_pressed_func(self._widget, ev)
|
|
175
|
+
self._pressed = True
|
|
176
|
+
self._super_key_pressed_func(ev)
|
|
177
|
+
|
|
178
|
+
def _keyReleaseEvent(self, ev):
|
|
179
|
+
if not self._widget:
|
|
180
|
+
return
|
|
181
|
+
if ev.key() == self._key_listened:
|
|
182
|
+
self._key_pressed = False
|
|
183
|
+
if ev.key() == Qt.Key_Control:
|
|
184
|
+
self._ctrl_pressed = False
|
|
185
|
+
if self._patched_key_released_func:
|
|
186
|
+
if self._pressed and not (self._key_pressed and self._ctrl_pressed):
|
|
187
|
+
self._patched_key_released_func(self._widget, ev)
|
|
188
|
+
self._pressed = False
|
|
189
|
+
self._super_key_released_func(ev)
|