Add an option to capture non active (but maximized) windows
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
has_config = False
|
has_config = False
|
||||||
__general_config = {}
|
__general_config = {}
|
||||||
@@ -20,7 +21,8 @@ class Config:
|
|||||||
'notifications': False,
|
'notifications': False,
|
||||||
'screen_capture_monitor': 1,
|
'screen_capture_monitor': 1,
|
||||||
'screen_capture_coords': '',
|
'screen_capture_coords': '',
|
||||||
'screen_capture_delay_secs': 3
|
'screen_capture_delay_secs': 3,
|
||||||
|
'screen_capture_only_active_windows': True
|
||||||
}
|
}
|
||||||
|
|
||||||
def __parse(self, value):
|
def __parse(self, value):
|
||||||
|
|||||||
14
owocr/run.py
14
owocr/run.py
@@ -201,6 +201,11 @@ def on_window_activated(active):
|
|||||||
screencapture_window_active = active
|
screencapture_window_active = active
|
||||||
|
|
||||||
|
|
||||||
|
def on_window_minimized(minimized):
|
||||||
|
global screencapture_window_visible
|
||||||
|
screencapture_window_visible = not minimized
|
||||||
|
|
||||||
|
|
||||||
def on_window_resized(size):
|
def on_window_resized(size):
|
||||||
global sct_params
|
global sct_params
|
||||||
sct_params['width'] = size[0]
|
sct_params['width'] = size[0]
|
||||||
@@ -376,8 +381,10 @@ def run(read_from=None,
|
|||||||
screen_capture_delay_secs = config.get_general('screen_capture_delay_secs')
|
screen_capture_delay_secs = config.get_general('screen_capture_delay_secs')
|
||||||
screen_capture_coords = config.get_general('screen_capture_coords')
|
screen_capture_coords = config.get_general('screen_capture_coords')
|
||||||
global screencapture_window_active
|
global screencapture_window_active
|
||||||
|
global screencapture_window_visible
|
||||||
screencapture_window_mode = False
|
screencapture_window_mode = False
|
||||||
screencapture_window_active = True
|
screencapture_window_active = True
|
||||||
|
screencapture_window_visible = True
|
||||||
sct = mss.mss()
|
sct = mss.mss()
|
||||||
mon = sct.monitors
|
mon = sct.monitors
|
||||||
if len(mon) <= screen_capture_monitor:
|
if len(mon) <= screen_capture_monitor:
|
||||||
@@ -393,6 +400,7 @@ def run(read_from=None,
|
|||||||
coord_left = mon[screen_capture_monitor]["left"] + x
|
coord_left = mon[screen_capture_monitor]["left"] + x
|
||||||
coord_top = mon[screen_capture_monitor]["top"] + y
|
coord_top = mon[screen_capture_monitor]["top"] + y
|
||||||
else:
|
else:
|
||||||
|
screen_capture_only_active_windows = config.get_general('screen_capture_only_active_windows')
|
||||||
window_title = None
|
window_title = None
|
||||||
window_titles = pywinctl.getAllTitles()
|
window_titles = pywinctl.getAllTitles()
|
||||||
if screen_capture_coords in window_titles:
|
if screen_capture_coords in window_titles:
|
||||||
@@ -413,8 +421,12 @@ def run(read_from=None,
|
|||||||
coord_left = target_window.left
|
coord_left = target_window.left
|
||||||
coord_width = target_window.width
|
coord_width = target_window.width
|
||||||
coord_height = target_window.height
|
coord_height = target_window.height
|
||||||
|
if screen_capture_only_active_windows:
|
||||||
screencapture_window_active = target_window.isActive
|
screencapture_window_active = target_window.isActive
|
||||||
target_window.watchdog.start(isActiveCB=on_window_activated, resizedCB=on_window_resized, movedCB=on_window_moved)
|
target_window.watchdog.start(isActiveCB=on_window_activated, resizedCB=on_window_resized, movedCB=on_window_moved)
|
||||||
|
else:
|
||||||
|
screencapture_window_visible = not target_window.isMinimized
|
||||||
|
target_window.watchdog.start(isMinimizedCB=on_window_minimized, resizedCB=on_window_resized, movedCB=on_window_moved)
|
||||||
target_window.watchdog.setTryToFind(True)
|
target_window.watchdog.setTryToFind(True)
|
||||||
|
|
||||||
global sct_params
|
global sct_params
|
||||||
@@ -478,7 +490,7 @@ def run(read_from=None,
|
|||||||
if not windows_clipboard_polling:
|
if not windows_clipboard_polling:
|
||||||
time.sleep(delay_secs)
|
time.sleep(delay_secs)
|
||||||
elif read_from == 'screencapture':
|
elif read_from == 'screencapture':
|
||||||
if screencapture_window_active and not paused and not tmp_paused:
|
if screencapture_window_active and screencapture_window_visible and not paused and not tmp_paused:
|
||||||
sct_img = sct.grab(sct_params)
|
sct_img = sct.grab(sct_params)
|
||||||
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
|
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
|
||||||
process_and_write_results(engine_instances[engine_index], img, write_to)
|
process_and_write_results(engine_instances[engine_index], img, write_to)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
;screen_capture_coords =
|
;screen_capture_coords =
|
||||||
;screen_capture_coords = 400,200,1500,600
|
;screen_capture_coords = 400,200,1500,600
|
||||||
;screen_capture_coords = OBS
|
;screen_capture_coords = OBS
|
||||||
|
;note: if screen_capture_coords is a window name, this can be changed to capture inactive windows too
|
||||||
|
;screen_capture_only_active_windows = True
|
||||||
;screen_capture_delay_secs = 3
|
;screen_capture_delay_secs = 3
|
||||||
[winrtocr]
|
[winrtocr]
|
||||||
;url = http://aaa.xxx.yyy.zzz:8000
|
;url = http://aaa.xxx.yyy.zzz:8000
|
||||||
|
|||||||
Reference in New Issue
Block a user