Updated display_text so that it will hopefully skip blank lines when reading with arrow keys.
This commit is contained in:
parent
1cb57391d8
commit
da17b71c28
42
__init__.py
42
__init__.py
@ -677,9 +677,9 @@ def display_text(text):
|
||||
"""Display and speak text with navigation controls.
|
||||
|
||||
Allows users to:
|
||||
- Navigate text line by line with arrow keys
|
||||
- Navigate text line by line with arrow keys (skipping blank lines)
|
||||
- Listen to full text with space
|
||||
- Copy current line or full text
|
||||
- Copy current line or full text (preserving blank lines)
|
||||
- Exit with enter/escape
|
||||
- Volume controls (with Alt modifier):
|
||||
- Alt+PageUp/PageDown: Master volume up/down
|
||||
@ -689,12 +689,23 @@ def display_text(text):
|
||||
Args:
|
||||
text (list): List of text lines to display
|
||||
"""
|
||||
# Store original text with blank lines for copying
|
||||
originalText = text.copy()
|
||||
|
||||
# Create navigation text by filtering out blank lines
|
||||
navText = [line for line in text if line.strip()]
|
||||
|
||||
# Add instructions at the start
|
||||
instructions = ("Press space to read the whole text. Use up and down arrows to navigate "
|
||||
"the text line by line. Press c to copy the current line to the clipboard "
|
||||
"or t to copy the entire text. Press enter or escape when you are done reading.")
|
||||
navText.insert(0, instructions)
|
||||
|
||||
# Add end marker
|
||||
navText.append("End of text.")
|
||||
|
||||
currentIndex = 0
|
||||
text.insert(0, "Press space to read the whole text. Use up and down arrows to navigate "
|
||||
"the text line by line. Press c to copy the current line to the clipboard "
|
||||
"or t to copy the entire text. Press enter or escape when you are done reading.")
|
||||
text.append("End of text.")
|
||||
speak(text[currentIndex])
|
||||
speak(navText[currentIndex])
|
||||
|
||||
while True:
|
||||
event = pygame.event.wait()
|
||||
@ -717,32 +728,33 @@ def display_text(text):
|
||||
adjust_sfx_volume(0.1)
|
||||
elif event.key == pygame.K_DELETE:
|
||||
adjust_sfx_volume(-0.1)
|
||||
# Regular text navigation (no Alt required)
|
||||
else:
|
||||
if event.key in (pygame.K_ESCAPE, pygame.K_RETURN):
|
||||
return
|
||||
|
||||
if event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(text) - 1:
|
||||
if event.key in [pygame.K_DOWN, pygame.K_s] and currentIndex < len(navText) - 1:
|
||||
currentIndex += 1
|
||||
speak(text[currentIndex])
|
||||
speak(navText[currentIndex])
|
||||
|
||||
if event.key in [pygame.K_UP, pygame.K_w] and currentIndex > 0:
|
||||
currentIndex -= 1
|
||||
speak(text[currentIndex])
|
||||
speak(navText[currentIndex])
|
||||
|
||||
if event.key == pygame.K_SPACE:
|
||||
speak(' '.join(text[1:]))
|
||||
# Join with newlines to preserve spacing in speech
|
||||
speak('\n'.join(originalText[1:-1]))
|
||||
|
||||
if event.key == pygame.K_c:
|
||||
try:
|
||||
pyperclip.copy(text[currentIndex])
|
||||
speak("Copied " + text[currentIndex] + " to the clipboard.")
|
||||
pyperclip.copy(navText[currentIndex])
|
||||
speak("Copied " + navText[currentIndex] + " to the clipboard.")
|
||||
except:
|
||||
speak("Failed to copy the text to the clipboard.")
|
||||
|
||||
if event.key == pygame.K_t:
|
||||
try:
|
||||
pyperclip.copy(' '.join(text[1:-1]))
|
||||
# Join with newlines to preserve blank lines in full text
|
||||
pyperclip.copy('\n'.join(originalText[1:-1]))
|
||||
speak("Copied entire message to the clipboard.")
|
||||
except:
|
||||
speak("Failed to copy the text to the clipboard.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user