diff --git a/src/calibre/gui2/main_window.py b/src/calibre/gui2/main_window.py index fae1b3f9d3..aa8a50aed9 100644 --- a/src/calibre/gui2/main_window.py +++ b/src/calibre/gui2/main_window.py @@ -118,7 +118,7 @@ class MainWindow(QMainWindow): def native_menubar(self): return self.___menu_bar - def __init__(self, opts, parent=None, disable_automatic_gc=False): + def __init__(self, opts=None, parent=None, disable_automatic_gc=False): QMainWindow.__init__(self, parent) self.display_unhandled_exception.connect(self.unhandled_exception, type=Qt.ConnectionType.QueuedConnection) if disable_automatic_gc: diff --git a/src/calibre/gui2/tts2/develop.py b/src/calibre/gui2/tts2/develop.py new file mode 100644 index 0000000000..c3198b0006 --- /dev/null +++ b/src/calibre/gui2/tts2/develop.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# License: GPLv3 Copyright: 2024, Kovid Goyal + + +from qt.core import QAction, QPlainTextEdit, QToolBar + +from calibre.gui2 import Application +from calibre.gui2.main_window import MainWindow + +TEXT = '''\ +Demonstration of DOCX support in calibre + +This document demonstrates the ability of the calibre DOCX Input plugin to convert the various typographic features in a Microsoft Word +(2007 and newer) document. Convert this document to a modern ebook format, such as AZW3 for Kindles or EPUB for other ebook readers, +to see it in action. + +There is support for images, tables, lists, footnotes, endnotes, links, dropcaps and various types of text and paragraph level formatting. + +To see the DOCX conversion in action, simply add this file to calibre using the “Add Books” button and then click “Convert”. +Set the output format in the top right corner of the conversion dialog to EPUB or AZW3 and click “OK”. +''' + + +def to_marked_text(text=TEXT): + pos = 0 + for word in text.split(): + yield pos + yield word + yield ' ' + pos += 1 + len(word) + + +class MainWindow(MainWindow): + + def __init__(self, text): + super().__init__() + self.display = d = QPlainTextEdit(self) + self.toolbar = tb = QToolBar(self) + self.addToolBar(tb) + self.setCentralWidget(d) + d.setPlainText(text) + d.setReadOnly(True) + self.marked_text = to_marked_text(text) + self.resize(self.sizeHint()) + self.play_action = pa = QAction('Play') + pa.setCheckable(True) + self.toolbar.addAction(pa) + self.faster_action = fa = QAction('Faster') + self.toolbar.addAction(fa) + self.slower_action = sa = QAction('Slower') + self.toolbar.addAction(sa) + self.configure_action = ca = QAction('Configure') + self.toolbar.addAction(ca) + + +def main(): + app = Application([]) + mw = MainWindow(TEXT) + mw.set_exception_handler() + mw.show() + app.exec() + + +if __name__ == '__main__': + main() diff --git a/src/calibre/gui2/tts2/manager.py b/src/calibre/gui2/tts2/manager.py new file mode 100644 index 0000000000..231fbf4a91 --- /dev/null +++ b/src/calibre/gui2/tts2/manager.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# License: GPLv3 Copyright: 2024, Kovid Goyal + + +from qt.core import QObject + + +class TTSManager(QObject): + + def __init__(self, parent=None): + super().__init__(parent) + self._tts = None + + @property + def tts(self): + if self._tts is None: + from calibre.gui2.tts.types import create_tts_backend + self._tts = create_tts_backend(parent=self) + return self._tts + + def speak_marked_text(self, marked_text): + pass