Merge pull request #5250 from PySimpleGUI/Dev-latest

Dev latest
This commit is contained in:
PySimpleGUI 2022-03-05 06:18:27 -05:00 committed by GitHub
commit 4c8abeeb40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -17,7 +17,7 @@
import PySimpleGUI as sg import PySimpleGUI as sg
# Settings for you to modify are the size of the element, the circle width & color and the foht for the % complete # Settings for you to modify are the size of the element, the circle width & color and the font for the % complete
GRAPH_SIZE = (300 , 300) # this one setting drives the other settings GRAPH_SIZE = (300 , 300) # this one setting drives the other settings
CIRCLE_LINE_WIDTH, LINE_COLOR = 20, 'yellow' CIRCLE_LINE_WIDTH, LINE_COLOR = 20, 'yellow'
TEXT_FONT = 'Courier' TEXT_FONT = 'Courier'

View File

@ -1,8 +1,6 @@
import PySimpleGUI as sg import PySimpleGUI as sg
import win32gui import win32gui
import cv2
from PIL import ImageGrab from PIL import ImageGrab
import numpy as np
""" """
Demo - Save Window screenshot Demo - Save Window screenshot
@ -10,7 +8,7 @@ import numpy as np
Saves a window as an image file. Tested saving as PNG and JPG. Input the title of the Window and it will be Saves a window as an image file. Tested saving as PNG and JPG. Input the title of the Window and it will be
saved in the format indicated by the filename. saved in the format indicated by the filename.
Copyright 2020 PySimpleGUI.org Copyright 2020, 2022 PySimpleGUI.org
""" """
# --------------------------------- Function to Save Window as JPG --------------------------------- # --------------------------------- Function to Save Window as JPG ---------------------------------
@ -41,9 +39,8 @@ def save_win(filename=None, title=None):
fceuxHWND = win32gui.FindWindow(None, title) fceuxHWND = win32gui.FindWindow(None, title)
rect = win32gui.GetWindowRect(fceuxHWND) rect = win32gui.GetWindowRect(fceuxHWND)
rect_cropped = (rect[0]+C, rect[1], rect[2]-C, rect[3]-C) rect_cropped = (rect[0]+C, rect[1], rect[2]-C, rect[3]-C)
frame = np.array(ImageGrab.grab(bbox=rect_cropped), dtype=np.uint8) grab = ImageGrab.grab(bbox=rect_cropped)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) grab.save(filename)
cv2.imwrite(filename, frame)
sg.popup('Wrote image to file:',filename) sg.popup('Wrote image to file:',filename)
except Exception as e: except Exception as e:
sg.popup('Error trying to save screenshot file', e) sg.popup('Error trying to save screenshot file', e)

View File

@ -6,10 +6,19 @@ import win32api
import win32con import win32con
import win32gui import win32gui
import win32process import win32process
import cv2
from PIL import ImageGrab from PIL import ImageGrab
import numpy as np
"""
Demo - Save Windows as Images
Works on WINDOWS only.
Saves a window as an image file. Tested saving as PNG and JPG.
saved in the format indicated by the filename.
The window needs to be on the primary display.
2022 update was to remove OpenCV requirement.
Copyright 2020, 2022 PySimpleGUI.org
"""
def convert_string_to_tuple(string): def convert_string_to_tuple(string):
""" """
@ -67,7 +76,6 @@ def get_window_list():
titles = sorted(titles, key=lambda x: x[0].lower()) titles = sorted(titles, key=lambda x: x[0].lower())
return titles return titles
def save_win(filename=None, title=None, crop=True): def save_win(filename=None, title=None, crop=True):
""" """
Saves a window with the title provided as a file using the provided filename. Saves a window with the title provided as a file using the provided filename.
@ -82,9 +90,8 @@ def save_win(filename=None, title=None, crop=True):
fceuxHWND = win32gui.FindWindow(None, title) fceuxHWND = win32gui.FindWindow(None, title)
rect = win32gui.GetWindowRect(fceuxHWND) rect = win32gui.GetWindowRect(fceuxHWND)
rect_cropped = (rect[0] + C, rect[1], rect[2] - C, rect[3] - C) rect_cropped = (rect[0] + C, rect[1], rect[2] - C, rect[3] - C)
frame = np.array(ImageGrab.grab(bbox=rect_cropped), dtype=np.uint8) grab = ImageGrab.grab(bbox=rect_cropped)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) grab.save(filename)
cv2.imwrite(filename, frame)
sg.cprint('Wrote image to file:') sg.cprint('Wrote image to file:')
sg.cprint(filename, c='white on purple') sg.cprint(filename, c='white on purple')
except Exception as e: except Exception as e: