Commit c07ce3c6 authored by Valentin Valls's avatar Valentin Valls
Browse files

Rework the name picker for new ROIs

parent 98576d22
......@@ -16,6 +16,7 @@ from import RegionOfInterestManager
from import RegionOfInterestTableWidget
from silx.gui.plot.items.roi import RectangleROI
from silx.gui.plot.items.roi import RegionOfInterest
from .utils import rois as rois_mdl
class RoiSelectionWidget(qt.QMainWindow):
......@@ -34,7 +35,7 @@ class RoiSelectionWidget(qt.QMainWindow):
self.roi_manager = RegionOfInterestManager(plot)
self.table = RegionOfInterestTableWidget()
......@@ -76,10 +77,29 @@ class RoiSelectionWidget(qt.QMainWindow):
# In case the mode is not supported
def on_added(self, roi):
def searchForFreeName(self, roi):
"""Returns a new name for a ROI.
The name is picked in order to match roi_counters and
roi2spectrum_counters. It was decided to allow to have the same sub
names for both Lima devices.
As this module is generic, it would be better to move this code in more
specific place.
rois = self.roi_manager.getRois()
roiNames = set([r.getName() for r in rois])
for i in range(1, 1000):
name = f"roi{i}"
if name not in roiNames:
return name
return "roi666.666"
def __roiAdded(self, roi):
if not roi.getName():
nb_rois = len(self.roi_manager.getRois())
name = self.searchForFreeName(roi)
def add_roi(self, roi):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment