Merge branch 'main' of https://git.coopcloud.tech/knoflook/bbbbbs
This commit is contained in:
commit
496450325e
38
main.py
38
main.py
|
@ -7,14 +7,20 @@ from datetime import datetime
|
|||
from time import sleep
|
||||
from random import choice
|
||||
from string import ascii_lowercase, digits
|
||||
from playsound import playsound
|
||||
import pyttsx3
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
import db
|
||||
|
||||
ttsEngine = pyttsx3.init('espeak')
|
||||
ttsEngine.setProperty('voice', 'female3')
|
||||
ttsEngine.setProperty('speed', 75)
|
||||
log = logging.getLogger("main")
|
||||
|
||||
|
||||
db.create_transmissions_table()
|
||||
|
||||
class MainWindow(Gtk.Window):
|
||||
|
@ -59,9 +65,9 @@ class MainWindow(Gtk.Window):
|
|||
self.play_box.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
self.play_box.set_spacing(pad)
|
||||
|
||||
self.synthesize_listen_box = Gtk.Box()
|
||||
self.synthesize_listen_box.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
self.synthesize_listen_box.set_spacing(pad)
|
||||
self.clear_play_box = Gtk.Box()
|
||||
self.clear_play_box.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
self.clear_play_box.set_spacing(pad)
|
||||
|
||||
self.clear_save_box = Gtk.Box()
|
||||
self.clear_save_box.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
|
@ -96,6 +102,7 @@ class MainWindow(Gtk.Window):
|
|||
self.message_scroll_window = Gtk.ScrolledWindow()
|
||||
self.message = Gtk.TextView()
|
||||
self.message.get_buffer().connect("changed", self.update_save_button)
|
||||
self.message.set_wrap_mode(Gtk.WrapMode.WORD)
|
||||
|
||||
self.calendar = Gtk.Calendar()
|
||||
self.calendar.connect("day-selected", self.on_date_picked)
|
||||
|
@ -123,8 +130,8 @@ class MainWindow(Gtk.Window):
|
|||
self.play_label = Gtk.Label(label="enable this message?")
|
||||
self.play_switch = Gtk.Switch()
|
||||
|
||||
self.synthesize_button = Gtk.Button(label="synthesize")
|
||||
self.listen_button = Gtk.Button(label="listen")
|
||||
self.play_button = Gtk.Button(label="play")
|
||||
self.play_button.connect("clicked", self.on_play_clicked)
|
||||
self.clear_button = Gtk.Button(label="clear")
|
||||
self.clear_button.connect("clicked", self.clear_transmission)
|
||||
self.save_button = Gtk.Button(label="save")
|
||||
|
@ -133,8 +140,7 @@ class MainWindow(Gtk.Window):
|
|||
|
||||
# we need to put the buttons in a sizegroup to make the synthesize button the same length as the rest
|
||||
self.right_sizegroup = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL)
|
||||
self.right_sizegroup.add_widget(self.synthesize_button)
|
||||
self.right_sizegroup.add_widget(self.listen_button)
|
||||
self.right_sizegroup.add_widget(self.play_button)
|
||||
self.right_sizegroup.add_widget(self.clear_button)
|
||||
self.right_sizegroup.add_widget(self.save_button)
|
||||
|
||||
|
@ -166,12 +172,11 @@ class MainWindow(Gtk.Window):
|
|||
self.play_box.pack_start(self.play_label, True, True, 0)
|
||||
self.play_box.pack_start(self.play_switch, False, False, 0)
|
||||
|
||||
self.right_box.pack_start(self.synthesize_listen_box, False, True, 0)
|
||||
self.synthesize_listen_box.pack_start(self.synthesize_button, True, True, 0)
|
||||
self.synthesize_listen_box.pack_start(self.listen_button, True, True, 0)
|
||||
self.right_box.pack_start(self.clear_play_box, False, True, 0)
|
||||
self.clear_play_box.pack_start(self.clear_button, True, True, 0)
|
||||
self.clear_play_box.pack_start(self.play_button, True, True, 0)
|
||||
|
||||
self.right_box.pack_start(self.clear_save_box, False, True, pad)
|
||||
self.clear_save_box.pack_start(self.clear_button, True, True, 0)
|
||||
self.clear_save_box.pack_start(self.save_button, True, True, 0)
|
||||
|
||||
############################## Helper functions #############################
|
||||
|
@ -266,6 +271,17 @@ class MainWindow(Gtk.Window):
|
|||
except TypeError:
|
||||
self.clear_transmission()
|
||||
|
||||
def on_play_clicked(self, user_data):
|
||||
messageBuffer = self.message.get_buffer()
|
||||
startIter, endIter = messageBuffer.get_bounds()
|
||||
message = messageBuffer.get_text(startIter, endIter, False)
|
||||
text = "Author: %s, Title: %s. Message: %s" % (
|
||||
self.author.get_buffer().get_text(),\
|
||||
self.title.get_buffer().get_text(),\
|
||||
message)
|
||||
ttsEngine.say(text)
|
||||
ttsEngine.runAndWait()
|
||||
|
||||
def on_transmission_saved(self, user_data):
|
||||
uid = self.transmissions[self.transmission_list.get_selected_row().get_index()][0]
|
||||
log.info("saving transmission %s" % uid)
|
||||
|
|
Loading…
Reference in New Issue