From 7892c04948894110f9b199487ce348a79f8bf499 Mon Sep 17 00:00:00 2001 From: Dusten Hubbard Date: Tue, 6 Oct 2026 17:36:28 -0500 Subject: [PATCH] feat(sections): show progress on bulk section edits Brightness/contrast and thickness edits over many sections load and save each one with nothing on screen. They now share the progress bar that locking already had; a single section still shows no dialog. Also fixes the thickness accumulator, which built a set and discarded it. Issue #139. --- PyReconstruct/modules/gui/table/section.py | 71 ++++++++++++++-------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/PyReconstruct/modules/gui/table/section.py b/PyReconstruct/modules/gui/table/section.py index 05ce78021..9b91a49d9 100644 --- a/PyReconstruct/modules/gui/table/section.py +++ b/PyReconstruct/modules/gui/table/section.py @@ -196,38 +196,29 @@ def mouseDoubleClickEvent(self, event=None): # RIGHT CLICK FUNCTIONS - def lockSections(self, lock=True, section_numbers=None, log_event=True): - """Lock or unlock a set of sections. - + def loadSectionsWithProgress(self, section_numbers : list, text : str): + """Load each section in turn, with a progress bar for more than one. + + Every operation here that edits a set of sections loads, changes and + saves each one, so a whole series takes a while with nothing on + screen. A single section (a lock checkbox toggle) shows no dialog. + Params: - lock (bool): True if section should be locked - section_numbers (list): the list of sections to modify + section_numbers (list): the sections to load + text (str): the text for the progress bar + Returns: + (generator): yields (section number, section) pairs """ - if section_numbers is None: - section_numbers = self.getSelected() - if not section_numbers: - return - - self.mainwindow.saveAllData() - - # set up progress (skip for single sections, e.g. a lock checkbox toggle) progress = 0 final_value = len(section_numbers) if final_value > 1: - progbar = getProgbar( - text=f"{'Locking' if lock else 'Unlocking'} sections...", - cancel=False - ) + progbar = getProgbar(text=text, cancel=False) else: progbar = None try: for snum in section_numbers: - section = self.series.loadSection(snum) - section.align_locked = lock - section.save() - if log_event: - self.series.addLog(None, snum, f"{'Lock' if lock else 'Unlock'} section") + yield snum, self.series.loadSection(snum) progress += 1 if progbar is not None: progbar.setValue(progress/final_value * 100) @@ -236,6 +227,29 @@ def lockSections(self, lock=True, section_numbers=None, log_event=True): if progbar is not None and progress < final_value: progbar.close() + def lockSections(self, lock=True, section_numbers=None, log_event=True): + """Lock or unlock a set of sections. + + Params: + lock (bool): True if section should be locked + section_numbers (list): the list of sections to modify + """ + if section_numbers is None: + section_numbers = self.getSelected() + if not section_numbers: + return + + self.mainwindow.saveAllData() + + for snum, section in self.loadSectionsWithProgress( + section_numbers, + f"{'Locking' if lock else 'Unlocking'} sections..." + ): + section.align_locked = lock + section.save() + if log_event: + self.series.addLog(None, snum, f"{'Lock' if lock else 'Unlock'} section") + self.manager.updateSections(section_numbers) # update the field @@ -269,8 +283,9 @@ def setBC(self, section_numbers=None, b=None, c=None, inc=False, log_event=True) self.mainwindow.saveAllData() - for snum in section_numbers: - section = self.series.loadSection(snum) + for snum, section in self.loadSectionsWithProgress( + section_numbers, "Adjusting brightness/contrast..." + ): if b is not None: if inc: section.brightness += b @@ -365,12 +380,14 @@ def editThickness(self, log_event=True): modified_contours = set() # iterate through selected sections - for snum in section_numbers: - section = self.series.loadSection(snum) + for snum, section in self.loadSectionsWithProgress( + section_numbers, "Setting section thickness..." + ): section.thickness = thickness # flag all traces as modified because the thickness of the section has been changed section.modified_contours = set(section.contours.keys()) - modified_contours.union(section.modified_contours) + # union() returns a new set, so the accumulator stayed empty + modified_contours |= section.modified_contours section.save() self.manager.updateObjects(section.modified_contours) if log_event: