Skip to content

Commit

Permalink
Ctrl A selects all, Ctrl b automatically plays what is on keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadlyApps committed Feb 8, 2016
1 parent 96296e8 commit 12b7dc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Controllers/SpeedReaderController.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SpeedReaderController(Tk):
def __init__(self):
Tk.__init__(self)
self.title("Speed Reader")
main_frame = MainFrame()
main_frame = MainFrame(master=self)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
main_frame.grid(padx=50, pady=50, sticky=(N, S, E, W))
19 changes: 15 additions & 4 deletions Frames/MainFrame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import thread
import ttk
from Tkconstants import END, N, S, E, W, NORMAL, DISABLED, RIGHT, CENTER
from Tkconstants import END, N, S, E, W, NORMAL, DISABLED, RIGHT, CENTER, SEL, INSERT
from Tkinter import Text

import pyttsx
Expand Down Expand Up @@ -65,6 +65,20 @@ def build_frame_content(self, kw):
self.stop_button['state'] = DISABLED
self.stop_button.bind("<Button-1>", self.stop)

self.text_area.bind("<Control-Key-a>", self.select_all_text)
self.text_area.bind("<Control-Key-A>", self.select_all_text)

self.master.bind("<Control-Key-b>", self.paste_and_speak)
self.master.bind("<Control-Key-B>", self.paste_and_speak)

def paste_and_speak(self, event):
self.text_area.delete("1.0", END)
self.text_area.insert(END, self.master.clipboard_get())
self.speak(event)

def select_all_text(self, event):
self.text_area.tag_add(SEL, "1.0", END)

def stop(self, event):
if self.stop_button['state'].__str__() == NORMAL:
self.engine.stop()
Expand Down Expand Up @@ -104,7 +118,6 @@ def speak(self, event):
self.text_area.insert(END, self.spoken_text)

speech_speed = int(self.speed_entry.get())
print("starting thread")
thread.start_new_thread(self.speak_on_thread, (speech_speed, self.spoken_text))

def speak_on_thread(self, speech_speed, spoken_text):
Expand All @@ -121,7 +134,5 @@ def speak_on_thread(self, speech_speed, spoken_text):
self.engine.setProperty('rate', speech_speed)
self.engine.say(spoken_text)

print("thread finished")


TAG_CURRENT_WORD = "current word"

0 comments on commit 12b7dc8

Please sign in to comment.