-
Notifications
You must be signed in to change notification settings - Fork 1
/
status_manager.py
36 lines (30 loc) · 1.06 KB
/
status_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
import numpy as np
from PIL import ImageGrab
from typing import Optional
import threading
# from capture_bbox_manager import CaptureBBoxManager
class StatusManager:
def __init__(self):
self.capture_img: Optional[np.ndarray] = None
self.result_img: Optional[np.ndarray] = None
self._capture_thread = None
self.bbox = None
self.is_capturing = False
def run_capture(self) -> None:
if (
self._capture_thread is not None
and self._capture_thread.is_alive()
):
return
self._capture_thread = threading.Thread(target=self._capture_screen)
self._capture_thread.daemon = True
self._capture_thread.start()
def _capture_screen(self) -> None:
while self.is_capturing and self.bbox is not None:
self.capture_img = np.array(ImageGrab.grab(bbox=self.bbox))
time.sleep(0.1)
def stop_capture(self):
self.is_capturing = False
if self._capture_thread is not None:
self._capture_thread.join()