File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818import traceback
1919from collections .abc import Callable , Generator
2020from contextlib import contextmanager
21- from datetime import datetime
2221from typing import Any
2322
2423import 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
You can’t perform that action at this time.
0 commit comments