Skip to content

Commit

Permalink
Added feature in SnQ mode (#16)
Browse files Browse the repository at this point in the history
* more full screen mode removal

* snq fix
  • Loading branch information
arcb01 authored Jan 6, 2024
1 parent 1808df8 commit 035c212
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
31 changes: 17 additions & 14 deletions gnarrator/reading_engine.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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):
"""
Expand All @@ -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())

4 changes: 4 additions & 0 deletions gnarrator/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down

0 comments on commit 035c212

Please sign in to comment.