Skip to content

Commit af4fd5d

Browse files
committed
Enhance grab_save_window to conditionally add timestamps based on name patterns for improved screenshot management
1 parent f5e6628 commit af4fd5d

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

datalab/utils/qthelpers.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import traceback
1919
from collections.abc import Callable, Generator
2020
from contextlib import contextmanager
21-
from datetime import datetime
2221
from typing import Any
2322

2423
import guidata
@@ -422,12 +421,23 @@ def grab_save_window(
422421
"""Grab window screenshot and save it"""
423422
if name is None:
424423
name = widget.objectName()
425-
widget.activateWindow()
426-
widget.raise_()
427-
QW.QApplication.processEvents()
428-
pixmap = widget.grab()
429-
suffix = datetime.now().strftime("%Y-%m-%d-%H%M%S") if name.endswith("_") else ""
430-
pixmap.save(osp.join(SHOTPATH, f"{name}{suffix}.png"))
424+
425+
# DataLab-specific logic: determine if timestamp should be added
426+
# based on name patterns and DataLab conventions
427+
add_timestamp = True
428+
if name.endswith("_"):
429+
# Name ending with underscore always gets timestamp
430+
add_timestamp = True
431+
elif name[-1].isdigit() or name.startswith(("s_", "i_")):
432+
# DataLab screenshot names or numbered items don't get timestamp
433+
add_timestamp = False
434+
435+
# Use guidata's grab_save_window with DataLab-specific configuration
436+
from guidata.qthelpers import grab_save_window as guidata_grab_save_window
437+
438+
guidata_grab_save_window(
439+
widget=widget, name=name, save_dir=SHOTPATH, add_timestamp=add_timestamp
440+
)
431441

432442

433443
@contextmanager

0 commit comments

Comments
 (0)