Skip to content

Commit bc3acb2

Browse files
committed
Refactor: simplify block_signals function to default enable parameter to True
1 parent dbdfb5e commit bc3acb2

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cdl/core/gui/objectview.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def __update_item(
215215
def populate_tree(self) -> None:
216216
"""Populate tree with objects"""
217217
uuid = self.get_current_item_id()
218-
with block_signals(widget=self, enable=True):
218+
with block_signals(widget=self):
219219
self.clear()
220220
for group in self.objmodel.get_groups():
221221
self.add_group_item(group)

cdl/core/gui/plothandler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def add_shapes(self, oid: str, do_autoscale: bool = False) -> None:
176176
# Performance optimization: block `plotpy.plot.BasePlot` signals, add
177177
# all items except the last one, unblock signals, then add the last one
178178
# (this avoids some unnecessary refresh process by PlotPy)
179-
with block_signals(self.plot, True):
179+
with block_signals(self.plot):
180180
with create_progress_bar(
181181
self.panel, _("Creating geometric shapes"), max_=len(items) - 1
182182
) as progress:

cdl/utils/qthelpers.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,21 @@ def save_restore_stds() -> Generator[None, None, None]:
415415

416416

417417
@contextmanager
418-
def block_signals(widget: QW.QWidget, enable: bool) -> Generator[None, None, None]:
418+
def block_signals(
419+
widget: QW.QWidget, enable: bool = True
420+
) -> Generator[None, None, None]:
419421
"""Eventually block/unblock widget Qt signals before/after doing some things
420-
(enable: True if feature is enabled)"""
422+
423+
Args:
424+
widget: Widget to block/unblock signals
425+
enable: Whether to block/unblock signals (default: True). This is useful
426+
to avoid blocking signals when not needed without having to handle it by
427+
adding an `if` statement which would require to duplicate the code that is
428+
inside the `with` statement in the `else` branch.
429+
430+
Returns:
431+
Context manager
432+
"""
421433
if enable:
422434
widget.blockSignals(True)
423435
try:

0 commit comments

Comments
 (0)