-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroiTableWidget.py
More file actions
90 lines (70 loc) · 2.89 KB
/
Copy pathroiTableWidget.py
File metadata and controls
90 lines (70 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import sys
from silx.gui import qt
from silx.gui.plot.tools.roi import RegionOfInterestManager
from silx.gui.plot.tools.roi import RegionOfInterestTableWidget
from silx.gui.plot.items import SymbolMixIn
from silx.gui import icons
from silx.gui.utils.concurrent import submitToQtMainThread as _submit
roiClasses = ('PointROI', 'RectangleROI', 'CircleROI', 'PolygonROI')
class RegionOfInterestManagerCustom(RegionOfInterestManager):
sigUpdatedRoi = qt.Signal(object)
def __init__(self, parent=None):
super().__init__(parent=parent)
plot = self.parent()
plot.sigPlotSignal.connect(self.updateInteraction)
def updateInteraction(self, event):
"""emit update roi signal when markerMoved event is triggered."""
if event['event'] == 'markerMoved':
currentRoi = self.getCurrentRoi()
self.sigUpdatedRoi.emit(currentRoi)
def updateAddedRegionOfInterest(roi):
rois = roi.parent().getRois()
roiIndexes = []
for roi in rois:
name = roi.getName()
if name.startswith('ROI'):
roiIndexes.append(int(name[4:]))
index = 1
for i in range(1, len(rois)+1):
if i not in roiIndexes:
index = i
break
if roi.getName() == '':
roi.setName(f'ROI {index}')
if isinstance(roi, SymbolMixIn):
roi.setSymbolSize(4)
roi.setSelectable(True)
roi.setEditable(True)
class RoiTableWidget(qt.QWidget):
sigClearRoiCurves = qt.Signal()
def __init__(self, parent=None, plot=None):
super(RoiTableWidget, self).__init__(parent)
self.roiManager = RegionOfInterestManagerCustom(parent=plot)
self.roiManager.setColor('pink')
self.roiManager.sigRoiAdded.connect(updateAddedRegionOfInterest)
self.roiTable = RegionOfInterestTableWidget()
self.roiTable.setRegionOfInterestManager(self.roiManager)
self.roiToolbar = qt.QToolBar()
self.roiToolbar.setIconSize(qt.QSize(16, 16))
for roiClass in self.roiManager.getSupportedRoiClasses():
if roiClass.__name__ in roiClasses:
action = self.roiManager.getInteractionModeAction(roiClass)
self.roiToolbar.addAction(action)
# Need to delete all rois action
icon = icons.getQIcon("remove")
action = qt.QAction(icon, "Delete all ROIs", self)
action.triggered.connect(self.roiManager.clear)
action.triggered.connect(lambda: self.roiTable.setRowCount(0))
action.triggered.connect(self.sigClearRoiCurves.emit)
self.roiToolbar.addAction(action)
layout = qt.QVBoxLayout()
layout.addWidget(self.roiToolbar)
layout.addWidget(self.roiTable)
self.setLayout(layout)
if __name__ == '__main__':
from silx.gui.plot import Plot2D
app = qt.QApplication(sys.argv)
plot = Plot2D()
main = RoiTableWidget(plot=plot)
main.show()
sys.exit(app.exec_())