diff --git a/gnarrator/reading_engine.py b/gnarrator/reading_engine.py index e270779..33c2eb6 100644 --- a/gnarrator/reading_engine.py +++ b/gnarrator/reading_engine.py @@ -1,4 +1,5 @@ from PyQt5.QtCore import QTimer +from deprecated import deprecated from gnarrator.utils.utils import get_mouse_pos, create_arb_reg, get_detection_coords from gnarrator.ocr import OCR from gnarrator.TTS import Narrator @@ -15,6 +16,9 @@ class ReadingEngine: voice_speed: speed of the TTS voice OCR: OCR engine TTS: TTS engine + screen_region: (x,y,w,h) coordinates of the region to be captured + if None, the whole screen will be captured + window: Window where the buttons will be displayed `Methods:` get_detection_coords(): Returns the coordinates of the bounding box @@ -46,7 +50,7 @@ def __init__(self, settings=None): self.OCR = OCR(lang=self.settings["LANGUAGE"], gpu=True) self.settings["VOICE"] = VOICE self.TTS = Narrator(self.settings) - + self.window = None def say_content(self, content : str): """ @@ -56,6 +60,7 @@ def say_content(self, content : str): self.TTS.say(content) + @deprecated(reason="No longer used") def read_full_screen(self): # Take full screen shot self.OCR.take_screenshot() @@ -77,9 +82,8 @@ def read_screen(self, mode, window, screen_region=None): if None, the whole screen will be captured """ - if mode == "full": - self.screen_region = None - self.read_full_screen() + self.window = window + if mode == "regional": self.screen_region = screen_region self.read_regional_screen(self.screen_region) @@ -93,24 +97,20 @@ def read_screen(self, mode, window, screen_region=None): det_text_content = det[1] det_coords = get_detection_coords(det) # x, y, w, h # draw button on bounding boxes coords - button = window.create_button(coords=det_coords) + button = self.window.create_button(coords=det_coords) # Associate button with bbox text button.clicked.connect(lambda _, text=det_text_content: self.say_content(text)) # Give buttons style - window.style_buttons() + self.window.style_buttons() # Launch window if self.screen_region: # NOTE: This can be changed to be all screen if needed (using map_coordinates function) - window.set_to_regional(screen_region=self.screen_region) - window.reset_opacity() - - # if only 1 detection was found, read it directly - #if len(self.OCR.get_detections) == 1: - #QTimer.singleShot(5, lambda: self.say_content(det_text_content)) + self.window.set_to_regional(screen_region=self.screen_region) + self.window.reset_opacity() - return window + return self.window def read_snq_screen(self): """ @@ -134,5 +134,8 @@ def read_snq_screen(self): return screen_region def say_content_immediatly(self): - QTimer.singleShot(5, lambda: self.say_content(self.det_text_content)) + # Call the TTS engine to read the content out loud + QTimer.singleShot(10, lambda: self.say_content(self.det_text_content)) + # When this the previous statement finishes then the window will be closed + QTimer.singleShot(12, lambda: self.window.close()) \ No newline at end of file diff --git a/gnarrator/windows.py b/gnarrator/windows.py index a07613a..d6b903c 100644 --- a/gnarrator/windows.py +++ b/gnarrator/windows.py @@ -184,6 +184,10 @@ def create_button(self, coords : list): def style_buttons(self): + # if theres only one button (small_n_quick mode): + if len(self.buttons) == 1: + self.bbox_color = self.hover_color + for button in self.buttons: button.setStyleSheet( f"QPushButton {{" diff --git a/setup.py b/setup.py index 4902340..20b2f3c 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setuptools.setup( name='gnarrator', - version='1.1.203', + version='1.1.210', python_requires='>=3.9.0', author='Arnau Castelalno', author_email='arcascb2001@gmail.com',