[Do...] Posted October 23 Share Posted October 23 (edited) Hallo zusammen, in meinem Skript möchte ich eine Funktion einbauen, die beim Ausführen automatisch einen Screenshot des aktuellen Bildschirms erstellt. Dieser Screenshot soll direkt im Dialog angezeigt werden. Aktuell verwende ich als Platzhalter ein statisches Beispielbild, das über einen separaten Dialog (screenshot_container.gdlg) eingebunden wird. Ziel ist es, dass der Screenshot ähnlich wie im Dialog „Hilfe → Systemanalyse → Supportdatei“ automatisch erzeugt und angezeigt wird. Zusätzlich soll der Screenshot durch einen Klick auf den Button „Screenshot“ im Dialog aktualisiert werden können. Leider finde ich keine entsprechende Funktion in der gom.script API, um einen Screenshot zu erzeugen oder zu aktualisieren. Da die Funktionalität im Dialog „Supportdaten zusammenstellen“ offensichtlich vorhanden ist, gehe ich davon aus, dass es eine interne Möglichkeit gibt. Meine Frage: Wie kann ich diese Screenshot-Funktion programmatisch aufrufen und in meinen Dialog integrieren? Gibt es eine dokumentierte oder empfohlene Methode, um dies umzusetzen? Ich bedanke mich vorab für Ihre Unterstützung. Edited October 23 Link to comment Share on other sites More sharing options...
[Ma...] Posted October 23 Share Posted October 23 For screenshots i've found usage of "Pillow" ( it's in our almost stock machine ) Python Screen Capture: Tools, Libraries, and Step-by-Step Guide 2025 1 Link to comment Share on other sites More sharing options...
[Do...] Posted October 23 Author Share Posted October 23 (edited) Thank you very much for the quick response. Creating screenshots via a dialog now works wonderfully with Pillow. However, there are still some issues when reading the .png files. In the screenshot_container.gdlg file, I set a placeholder under data. I then define this in the code, but no matter how I do it, I keep getting an error message. I have marked line 19 in bold and red. Error in line 19 RequestError: GScriptErr-0006 - Die Daten können nicht als Bild interpretiert werden. Code: import gom import base64 # Screenshot-Datei als Base64 laden with open("C:/Temp/ZEISS-Inspect/screenshots/fullscreen.png", "rb") as image_file: image_bytes = image_file.read() # Base64-kodieren image_data = base64.b64encode(image_bytes).decode("utf-8") print(image_data[:100]) DUMMY=gom.script.sys.create_user_defined_dialog(file='screenshot_container.gdlg') DUMMY.image.data = image_data TEST=gom.script.sys.show_user_defined_dialog(dialog=DUMMY) screenshot_container.gdlg: { "content": [ [ { "columns": 1, "data": "AAAAAA==", "file_name": "C:/Temp/ZEISS-Inspect/screenshots/fullscreen.png", "height": 500, "keep_aspect": true, "keep_original_size": false, "name": "image", "rows": 1, "system_image": "system_message_warning", "tooltip": { "id": "", "text": "", "translatable": true }, "type": "image", "use_system_image": false, "width": 500 } ] ], "control": { "id": "OkCancel" }, "embedding": "always_toplevel", "position": "center", "size": { "height": 92, "width": 215 }, "sizemode": "automatic", "style": "", "title": { "id": "", "text": "Screenshot Container", "translatable": true } } Edited October 23 Link to comment Share on other sites More sharing options...
[Ma...] Posted October 23 Share Posted October 23 I would reffer to example app with using numpy It seems for data it's not base64 zeiss-inspect-app-examples/AppExamples/misc/DisplayImage/scripts/display_image.py at main · ZEISS/zeiss-inspect-app-examples · GitHub 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in