From 9bce90ac781becb7f5d6a5d1236681d8b6178656 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Tue, 23 Apr 2024 10:57:18 -0700 Subject: [PATCH 1/4] PERF: set text size on resize event, not on paint event, to avoid 100% cpu --- typhos/dynamic_font.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/typhos/dynamic_font.py b/typhos/dynamic_font.py index aea7be5f..91352722 100644 --- a/typhos/dynamic_font.py +++ b/typhos/dynamic_font.py @@ -119,7 +119,7 @@ def patch_widget( maximum font size. Content margin settings determine the content rectangle, and this padding is applied as a percentage on top of that. """ - def paintEvent(event: QtGui.QPaintEvent) -> None: + def resizeEvent(event: QtGui.QResizeEvent) -> None: font = widget.font() font_size = get_widget_maximum_font_size( widget, widget.text(), @@ -129,27 +129,27 @@ def paintEvent(event: QtGui.QPaintEvent) -> None: if abs(font.pointSizeF() - font_size) > 0.1: font.setPointSizeF(font_size) widget.setFont(font) - return orig_paint_event(event) + return orig_resize_event(event) def minimumSizeHint() -> QtCore.QSize: - # Do not give any size hint as it it changes during paintEvent + # Do not give any size hint as it it changes during resizeEvent return QtWidgets.QWidget.minimumSizeHint(widget) def sizeHint() -> QtCore.QSize: - # Do not give any size hint as it it changes during paintEvent + # Do not give any size hint as it it changes during resizeEvent return QtWidgets.QWidget.sizeHint(widget) - if hasattr(widget.paintEvent, "_patched_methods_"): + if hasattr(widget.resizeEvent, "_patched_methods_"): return - orig_paint_event = widget.paintEvent + orig_resize_event = widget.resizeEvent - paintEvent._patched_methods_ = ( - widget.paintEvent, + resizeEvent._patched_methods_ = ( + widget.resizeEvent, widget.sizeHint, widget.minimumSizeHint, ) - widget.paintEvent = paintEvent + widget.resizeEvent = resizeEvent widget.sizeHint = sizeHint widget.minimumSizeHint = minimumSizeHint @@ -163,14 +163,14 @@ def unpatch_widget(widget: QtWidgets.QWidget) -> None: widget : QtWidgets.QWidget The widget to unpatch. """ - if not hasattr(widget.paintEvent, "_patched_methods_"): + if not hasattr(widget.resizeEvent, "_patched_methods_"): return ( - widget.paintEvent, + widget.resizeEvent, widget.sizeHint, widget.minimumSizeHint, - ) = widget.paintEvent._patched_methods_ + ) = widget.resizeEvent._patched_methods_ def is_patched(widget: QtWidgets.QWidget) -> bool: @@ -187,4 +187,4 @@ def is_patched(widget: QtWidgets.QWidget) -> bool: bool True if the widget has been patched. """ - return hasattr(widget.paintEvent, "_patched_methods_") + return hasattr(widget.resizeEvent, "_patched_methods_") From 6dc86e034c0f3ef7837f0c92b8e617a00ef586b4 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Fri, 31 May 2024 17:25:07 +0000 Subject: [PATCH 2/4] TST: adjust test to match behavior --- typhos/tests/test_dynamic_font.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/typhos/tests/test_dynamic_font.py b/typhos/tests/test_dynamic_font.py index c4c04321..3b1e07e6 100644 --- a/typhos/tests/test_dynamic_font.py +++ b/typhos/tests/test_dynamic_font.py @@ -33,13 +33,17 @@ def test_patching( ) print("Starting font size", original_font_size) - event = QtGui.QPaintEvent(QtCore.QRect(0, 0, widget.width(), widget.height())) + old_size = widget.size() + event = QtGui.QResizeEvent( + QtCore.QSize(old_size.width() * 2, old_size.height() * 2), + old_size, + ) assert not is_patched(widget) patch_widget(widget) assert is_patched(widget) - widget.paintEvent(event) + widget.resizeEvent(event) new_font_size = widget.font().pointSizeF() print("Patched font size", new_font_size) assert original_font_size != new_font_size From 1b4c1d56f3f70dfe5aac4120acb4ded53e1b8910 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Fri, 31 May 2024 17:25:39 +0000 Subject: [PATCH 3/4] MAINT: ignore user-specific vscode config --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c68433f4..f3620fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,4 @@ ENV/ # Editors *.swp *~ +.vscode From 80d317c6a59dd343160445e2699187be08fad499 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Fri, 31 May 2024 17:26:54 +0000 Subject: [PATCH 4/4] DOC: add pre-release notes --- .../604-perf_resize_text.rst | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/source/upcoming_release_notes/604-perf_resize_text.rst diff --git a/docs/source/upcoming_release_notes/604-perf_resize_text.rst b/docs/source/upcoming_release_notes/604-perf_resize_text.rst new file mode 100644 index 00000000..3ef37787 --- /dev/null +++ b/docs/source/upcoming_release_notes/604-perf_resize_text.rst @@ -0,0 +1,22 @@ +604 perf_resize_text +################# + +API Breaks +---------- +- N/A + +Features +-------- +- N/A + +Bugfixes +-------- +- Fix an issue where the row positioner widget's resizing would peg the cpu to 100% + +Maintenance +----------- +- N/A + +Contributors +------------ +- zllentz