def main(): from calibre.gui2 import Application from PyQt5.Qt import QMainWindow, QStatusBar, QTimer app = Application([]) w = QMainWindow() s = QStatusBar(w) w.setStatusBar(s) s.showMessage("Testing ProceedQuestion") w.show() p = ProceedQuestion(w) def doit(): p.dummy_question() p.dummy_question(action_label="A very long button for testing relayout (indeed)") p( lambda p: None, None, "ass2", "ass2", "testing2", "testing2", det_msg="details shown first, with a long line to test wrapping of text and width layout", show_det=True, show_ok=True, ) QTimer.singleShot(10, doit) app.exec_()
def main(args=sys.argv): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() # The following two lines are needed to prevent circular imports causing # errors during initialization of plugins that use the polish container # infrastructure. importlib.import_module('calibre.customize.ui') from calibre.gui2.tweak_book.ui import Main parser = option_parser() opts, args = parser.parse_args(args) if getattr(opts, 'detach', False): detach_gui() override = 'calibre-tweak-book' if islinux else None app = Application(args, override_program_name=override) app.load_builtin_fonts() app.setWindowIcon(QIcon(I('tweak.png'))) Application.setOrganizationName(ORG_NAME) Application.setApplicationName(APP_UID) main = Main(opts) sys.excepthook = main.unhandled_exception main.show() if len(args) > 1: main.boss.open_book(args[1]) app.exec_()
def main(): from calibre.gui2 import Application app = Application([]) spl = SplashScreen(develop=True) spl.show() spl.show_message('Testing the splash screen message...') app.exec_()
def _run(args, notify=None): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() # The following two lines are needed to prevent circular imports causing # errors during initialization of plugins that use the polish container # infrastructure. importlib.import_module('calibre.customize.ui') from calibre.gui2.tweak_book.ui import Main parser = option_parser() opts, args = parser.parse_args(args) if getattr(opts, 'detach', False): detach_gui() override = 'calibre-edit-book' if islinux else None app = Application(args, override_program_name=override) app.load_builtin_fonts() app.setWindowIcon(QIcon(I('tweak.png'))) Application.setOrganizationName(ORG_NAME) Application.setApplicationName(APP_UID) main = Main(opts, notify=notify) sys.excepthook = main.unhandled_exception main.show() if len(args) > 1: main.boss.open_book(args[1], edit_file=opts.edit_file, clear_notify_data=False) app.exec_()
def main(): from calibre.gui2 import Application from qt.core import QMainWindow, QStatusBar, QTimer app = Application([]) w = QMainWindow() s = QStatusBar(w) w.setStatusBar(s) s.showMessage('Testing ProceedQuestion') w.show() p = ProceedQuestion(w) def doit(): p.dummy_question() p.dummy_question( action_label='A very long button for testing relayout (indeed)') p(lambda p: None, None, 'ass2', 'ass2', 'testing2', 'testing2', det_msg= 'details shown first, with a long line to test wrapping of text and width layout', show_det=True, show_ok=True) QTimer.singleShot(10, doit) app.exec_()
def test(scale=0.25): from PyQt5.Qt import QLabel, QPixmap, QMainWindow, QWidget, QScrollArea, QGridLayout from calibre.gui2 import Application app = Application([]) mi = Metadata('Unknown', ['Kovid Goyal', 'John & Doe', 'Author']) mi.series = 'A series & styles' m = QMainWindow() sa = QScrollArea(m) w = QWidget(m) sa.setWidget(w) l = QGridLayout(w) w.setLayout(l), l.setSpacing(30) scale *= w.devicePixelRatioF() labels = [] for r, color in enumerate(sorted(default_color_themes)): for c, style in enumerate(sorted(all_styles())): mi.series_index = c + 1 mi.title = 'An algorithmic cover [%s]' % color prefs = override_prefs(cprefs, override_color_theme=color, override_style=style) scale_cover(prefs, scale) img = generate_cover(mi, prefs=prefs, as_qimage=True) img.setDevicePixelRatio(w.devicePixelRatioF()) la = QLabel() la.setPixmap(QPixmap.fromImage(img)) l.addWidget(la, r, c) labels.append(la) m.setCentralWidget(sa) w.resize(w.sizeHint()) m.show() app.exec_()
def launch_editor(path_to_edit, path_is_raw=False, syntax='html', callback=None): from calibre.gui2 import Application from calibre.gui2.tweak_book import dictionaries from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status from calibre.gui2.tweak_book.main import option_parser from calibre.gui2.tweak_book.ui import Main dictionaries.initialize() refresh_spell_check_status() opts = option_parser().parse_args([]) app = Application([]) # Create the actions that are placed into the editors toolbars main = Main(opts) # noqa if path_is_raw: raw = path_to_edit else: with open(path_to_edit, 'rb') as f: raw = f.read().decode('utf-8') ext = path_to_edit.rpartition('.')[-1].lower() if ext in ('html', 'htm', 'xhtml', 'xhtm'): syntax = 'html' elif ext in ('css', ): syntax = 'css' t = Editor(syntax) t.data = raw if callback is not None: callback(t) t.show() app.exec_()
def main(): from calibre.gui2 import Application from PyQt5.Qt import QMainWindow app = Application([]) w = QMainWindow() w.show() p = ProceedQuestion(None) p(lambda p, q: None, None, 'ass', 'ass', 'testing', 'testing', checkbox_msg='testing the ruddy checkbox', det_msg='details') p(lambda p: None, None, 'ass2', 'ass2', 'testing2', 'testing2', det_msg='details shown first', show_det=True, show_ok=True, geom_pref='ProceedQuestion-unit-test') app.exec_()
def develop(): from calibre.gui2 import Application from calibre.gui2.tts.implementation import Client app = Application([]) c = Client() w = Widget(c, {}) w.show() app.exec_() print(w.backend_settings)
def main(): app = Application([]) w = QMainWindow() tts = TTSWidget(w) w.setCentralWidget(tts) w.show() app.exec_() tts.events_available.disconnect() tts.mark_changed.disconnect() tts.tts.shutdown()
def main(): os.closerange(3, 256) from calibre.gui2 import Application app = Application([]) s = CalibreSplashScreen() s.show_message.connect(s.showMessage, type=Qt.QueuedConnection) s.shutdown.connect(app.quit, type=Qt.QueuedConnection) s.show() Thread(target=run_loop, args=(s,)).start() app.exec_()
def main(): from calibre.gui2 import Application from calibre.gui2.tweak_book.boss import get_container app = Application([]) # noqa path = sys.argv[-1] container = get_container(path) d = Check() d.run_checks(container) d.show() app.exec_()
def main(): app = Application([]) w = QMainWindow() tts = TTSWidget(w) w.setCentralWidget(tts) w.show() app.exec_() tts.dispatch_on_main_thread_signal.disconnect() tts.mark_changed.disconnect() tts.tts.shutdown()
def main(url): # This function is run in a separate process and can do anything it likes, # including use QWebEngine. Here it simply opens the passed in URL # in a QWebEngineView app = Application([]) w = QWebEngineView() w.setUrl(QUrl(url)) w.show() w.raise_() app.exec_()
def _run(args, notify=None): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() if iswindows: # Ensure that all ebook editor instances are grouped together in the task # bar. This prevents them from being grouped with viewer process when # launched from within calibre, as both use calibre-parallel.exe import ctypes try: ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( 'com.calibre-ebook.edit-book') except: pass # Only available on windows 7 and newer # The following two lines are needed to prevent circular imports causing # errors during initialization of plugins that use the polish container # infrastructure. importlib.import_module('calibre.customize.ui') from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book.ui import Main parser = option_parser() opts, args = parser.parse_args(args) decouple('edit-book-'), set_gui_prefs(tprefs) override = 'calibre-edit-book' if islinux else None app = Application(args, override_program_name=override, color_prefs=tprefs) app.file_event_hook = EventAccumulator() app.load_builtin_fonts() app.setWindowIcon(QIcon(I('tweak.png'))) Application.setOrganizationName(ORG_NAME) Application.setApplicationName(APP_UID) main = Main(opts, notify=notify) main.set_exception_handler() main.show() app.shutdown_signal_received.connect(main.boss.quit) if len(args) > 1: main.boss.open_book(args[1], edit_file=args[2:], clear_notify_data=False) else: for path in reversed(app.file_event_hook.events): main.boss.open_book(path) break app.file_event_hook = main.boss.open_book app.exec_() # Ensure that the parse worker has quit so that temp files can be deleted # on windows st = time.time() from calibre.gui2.tweak_book.preview import parse_worker while parse_worker.is_alive() and time.time() - st < 120: time.sleep(0.1)
def main(args=sys.argv): # Ensure viewer can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() scheme = QWebEngineUrlScheme(FAKE_PROTOCOL.encode('ascii')) scheme.setSyntax(QWebEngineUrlScheme.Syntax.Host) scheme.setFlags(QWebEngineUrlScheme.SecureScheme) QWebEngineUrlScheme.registerScheme(scheme) override = 'calibre-ebook-viewer' if islinux else None app = Application(args, override_program_name=override, windows_app_uid=VIEWER_APP_UID) parser = option_parser() opts, args = parser.parse_args(args) oat = opts.open_at if oat and not ( oat.startswith('toc:') or oat.startswith('toc-href:') or oat.startswith('toc-href-contains:') or oat.startswith('epubcfi(/') or is_float(oat)): raise SystemExit('Not a valid --open-at value: {}'.format(opts.open_at)) listener = None if get_session_pref('singleinstance', False): try: listener = ensure_single_instance(args, opts.open_at) except Exception as e: import traceback error_dialog(None, _('Failed to start viewer'), as_unicode(e), det_msg=traceback.format_exc(), show=True) raise SystemExit(1) acc = EventAccumulator(app) app.file_event_hook = acc app.load_builtin_fonts() app.setWindowIcon(QIcon(I('viewer.png'))) migrate_previous_viewer_prefs() main = EbookViewer(open_at=opts.open_at, continue_reading=opts.continue_reading, force_reload=opts.force_reload) main.set_exception_handler() if len(args) > 1: acc.events.append(os.path.abspath(args[-1])) acc.got_file.connect(main.handle_commandline_arg) main.show() main.msg_from_anotherinstance.connect(main.another_instance_wants_to_talk, type=Qt.QueuedConnection) if listener is not None: t = Thread(name='ConnListener', target=listen, args=(listener, main.msg_from_anotherinstance)) t.daemon = True t.start() QTimer.singleShot(0, acc.flush) if opts.raise_window: main.raise_() if opts.full_screen: main.set_full_screen(True) app.exec_() if listener is not None: listener.close()
def _run(args, notify=None): # Ensure we can continue to function if GUI is closed os.environ.pop("CALIBRE_WORKER_TEMP_DIR", None) reset_base_dir() if iswindows: # Ensure that all ebook editor instances are grouped together in the task # bar. This prevents them from being grouped with viewer process when # launched from within calibre, as both use calibre-parallel.exe import ctypes try: ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("com.calibre-ebook.edit-book") except: pass # Only available on windows 7 and newer # The following two lines are needed to prevent circular imports causing # errors during initialization of plugins that use the polish container # infrastructure. importlib.import_module("calibre.customize.ui") from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book.ui import Main parser = option_parser() opts, args = parser.parse_args(args) decouple("edit-book-"), set_gui_prefs(tprefs) override = "calibre-edit-book" if islinux else None app = Application(args, override_program_name=override, color_prefs=tprefs) app.file_event_hook = EventAccumulator() app.load_builtin_fonts() app.setWindowIcon(QIcon(I("tweak.png"))) Application.setOrganizationName(ORG_NAME) Application.setApplicationName(APP_UID) main = Main(opts, notify=notify) main.set_exception_handler() main.show() app.shutdown_signal_received.connect(main.boss.quit) if len(args) > 1: main.boss.open_book(args[1], edit_file=args[2:], clear_notify_data=False) else: for path in reversed(app.file_event_hook.events): main.boss.open_book(path) break app.file_event_hook = main.boss.open_book app.exec_() # Ensure that the parse worker has quit so that temp files can be deleted # on windows st = time.time() from calibre.gui2.tweak_book.preview import parse_worker while parse_worker.is_alive() and time.time() - st < 120: time.sleep(0.1)
def main(): from calibre.gui2 import Application from PyQt5.Qt import QMainWindow app = Application([]) w = QMainWindow() w.show() p = ProceedQuestion(None) p(lambda p,q:None, None, 'ass', 'ass', 'testing', 'testing', checkbox_msg='testing the ruddy checkbox', det_msg='details') p(lambda p:None, None, 'ass2', 'ass2', 'testing2', 'testing2', det_msg='details shown first', show_det=True, show_ok=True, geom_pref='ProceedQuestion-unit-test') app.exec_()
def main(): app = Application([]) w = QMainWindow() sb = w.statusBar() la = QLabel(sb) sb.addPermanentWidget(la) tts = TTSWidget(w) tts.show_message.connect(sb.showMessage) tts.show_status.connect(la.setText) w.setCentralWidget(tts) w.show() app.exec_() tts.dispatch_on_main_thread_signal.disconnect() tts.mark_changed.disconnect() tts.tts.shutdown()
def _run(args, notify=None): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() scheme = QWebEngineUrlScheme(FAKE_PROTOCOL.encode('ascii')) scheme.setSyntax(QWebEngineUrlScheme.Syntax.Host) scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme) QWebEngineUrlScheme.registerScheme(scheme) # The following two lines are needed to prevent circular imports causing # errors during initialization of plugins that use the polish container # infrastructure. importlib.import_module('calibre.customize.ui') from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book.ui import Main parser = option_parser() opts, args = parser.parse_args(args) decouple('edit-book-'), set_gui_prefs(tprefs) override = 'calibre-edit-book' if islinux else None app = Application(args, override_program_name=override, color_prefs=tprefs, windows_app_uid=EDITOR_APP_UID) app.file_event_hook = EventAccumulator() app.load_builtin_fonts() app.setWindowIcon(QIcon(I('tweak.png'))) main = Main(opts, notify=notify) main.set_exception_handler() main.show() app.shutdown_signal_received.connect(main.boss.quit) if len(args) > 1: main.boss.open_book(args[1], edit_file=args[2:], clear_notify_data=False, search_text=opts.select_text) else: for path in reversed(app.file_event_hook.events): main.boss.open_book(path) break app.file_event_hook = main.boss.open_book app.exec_() # Ensure that the parse worker has quit so that temp files can be deleted # on windows st = time.time() from calibre.gui2.tweak_book.preview import parse_worker while parse_worker.is_alive() and time.time() - st < 120: time.sleep(0.1)
def main(args=sys.argv): # Ensure viewer can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() parser = option_parser() opts, args = parser.parse_args(args) if getattr(opts, 'detach', False): detach_gui() try: open_at = float(opts.open_at) except: open_at = None override = 'calibre-ebook-viewer' if islinux else None app = Application(args, override_program_name=override) app.load_builtin_fonts() app.setWindowIcon(QIcon(I('viewer.png'))) QApplication.setOrganizationName(ORG_NAME) QApplication.setApplicationName(APP_UID) main = EbookViewer(args[1] if len(args) > 1 else None, debug_javascript=opts.debug_javascript, open_at=open_at, start_in_fullscreen=opts.full_screen) # This is needed for paged mode. Without it, the first document that is # loaded will have extra blank space at the bottom, as # turn_off_internal_scrollbars does not take effect for the first # rendered document main.view.load_path(P('viewer/blank.html', allow_user_override=False)) sys.excepthook = main.unhandled_exception main.show() if opts.raise_window: main.raise_() with main: return app.exec_() return 0
def headless(): app = Application([]) c = Client() text = '[[sync 0x123456]]very [[sync 0x80]]good [[sync 0x81]]indeed' def callback(): for ev in c.get_events(): if ev.type is EventType.mark: print('mark:', hex(ev.data)) if ev.type in (EventType.end, EventType.cancel): print(ev.type) app.quit() def run(): c.speak_marked_text(text, callback) QTimer.singleShot(10, run) QTimer.singleShot(5000, app.quit) app.exec_()
def _run(args, notify=None): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() if iswindows: # Ensure that all ebook editor instances are grouped together in the task # bar. This prevents them from being grouped with viewer process when # launched from within calibre, as both use calibre-parallel.exe import ctypes try: ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('com.calibre-ebook.edit-book') except: pass # Only available on windows 7 and newer # The following two lines are needed to prevent circular imports causing # errors during initialization of plugins that use the polish container # infrastructure. importlib.import_module('calibre.customize.ui') from calibre.gui2.tweak_book.ui import Main parser = option_parser() opts, args = parser.parse_args(args) if getattr(opts, 'detach', False): detach_gui() decouple('edit-book-') override = 'calibre-edit-book' if islinux else None app = Application(args, override_program_name=override) app.load_builtin_fonts() app.setWindowIcon(QIcon(I('tweak.png'))) Application.setOrganizationName(ORG_NAME) Application.setApplicationName(APP_UID) main = Main(opts, notify=notify) sys.excepthook = main.unhandled_exception main.show() if len(args) > 1: main.boss.open_book(args[1], edit_file=opts.edit_file, clear_notify_data=False) app.exec_() # Ensure that the parse worker has quit so that temp files can be deleted # on windows st = time.time() from calibre.gui2.tweak_book.preview import parse_worker while parse_worker.is_alive() and time.time() - st < 120: time.sleep(0.1)
def main(args=sys.argv): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() parser = option_parser() opts, args = parser.parse_args(args) override = 'calibre-tweak-book' if islinux else None app = Application(args, override_program_name=override) app.load_builtin_fonts() app.setWindowIcon(QIcon(I('tweak.png'))) Application.setOrganizationName(ORG_NAME) Application.setApplicationName(APP_UID) main = Main(opts) sys.excepthook = main.unhandled_exception main.show() if len(args) > 1: main.boss.open_book(args[1]) app.exec_()
def main(args): # Ensure we can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() if iswindows: # Ensure that all instances are grouped together in the task bar. This # prevents them from being grouped with viewer/editor process when # launched from within calibre, as both use calibre-parallel.exe set_app_uid(STORE_DIALOG_APP_UID) data = args[-1] data = json.loads(from_base64_bytes(data)) override = 'calibre-gui' if islinux else None app = Application(args, override_program_name=override) m = Main(data) m.show(), m.raise_() app.exec_() del m del app
def main(path_to_ebook, book_id, from_calibre, calibre_libpaths): # This function is run in a separate process and can do anything # it likes, including use QWebEngine. # See uiaction.py show_dialog() for the call which launches this function # via self.gui.job_manager.launch_gui_app() # This import must happen before creating the Application() object from PyQt5.QtWebEngineWidgets import QWebEngineView from calibre.gui2 import Application from calibre_plugins.scrambleebook_plugin.scrambleebook import EbookScramble app = Application([]) w = EbookScramble(path_to_ebook, book_id=book_id, from_calibre=from_calibre, calibre_libpaths=calibre_libpaths) w.show() w.raise_() app.exec_()
def main(args=sys.argv): from calibre.gui2 import Application left, right = args[-2:] ext1, ext2 = left.rpartition('.')[-1].lower(), right.rpartition('.')[-1].lower() if ext1.startswith('original_'): ext1 = ext1.partition('_')[-1] if ext2.startswith('original_'): ext2 = ext2.partition('_')[-2] if os.path.isdir(left): attr = 'dir_diff' elif (ext1, ext2) in {('epub', 'epub'), ('azw3', 'azw3')}: attr = 'ebook_diff' else: attr = 'file_diff' app = Application([]) # noqa d = Diff(show_as_window=True) func = getattr(d, attr) QTimer.singleShot(0, lambda : func(left, right)) d.show() app.exec_() return 0
def main(args=sys.argv): # Ensure viewer can continue to function if GUI is closed os.environ.pop("CALIBRE_WORKER_TEMP_DIR", None) reset_base_dir() parser = option_parser() opts, args = parser.parse_args(args) open_at = float(opts.open_at.replace(",", ".")) if opts.open_at else None listener = None override = "calibre-ebook-viewer" if islinux else None app = Application(args, override_program_name=override, color_prefs=vprefs) app.load_builtin_fonts() app.setWindowIcon(QIcon(I("viewer.png"))) QApplication.setOrganizationName(ORG_NAME) QApplication.setApplicationName(APP_UID) if vprefs["singleinstance"]: try: listener = ensure_single_instance(args, open_at) except Exception as e: import traceback error_dialog(None, _("Failed to start viewer"), as_unicode(e), det_msg=traceback.format_exc(), show=True) raise SystemExit(1) main = EbookViewer( args[1] if len(args) > 1 else None, debug_javascript=opts.debug_javascript, open_at=open_at, continue_reading=opts.continue_reading, start_in_fullscreen=opts.full_screen, listener=listener, ) app.installEventFilter(main) # This is needed for paged mode. Without it, the first document that is # loaded will have extra blank space at the bottom, as # turn_off_internal_scrollbars does not take effect for the first # rendered document main.view.load_path(P("viewer/blank.html", allow_user_override=False)) sys.excepthook = main.unhandled_exception main.show() if opts.raise_window: main.raise_() with main: return app.exec_() return 0
def main(args=sys.argv): # Ensure viewer can continue to function if GUI is closed os.environ.pop('CALIBRE_WORKER_TEMP_DIR', None) reset_base_dir() parser = option_parser() opts, args = parser.parse_args(args) open_at = float(opts.open_at.replace(',', '.')) if opts.open_at else None listener = None override = 'calibre-ebook-viewer' if islinux else None app = Application(args, override_program_name=override, color_prefs=vprefs) app.load_builtin_fonts() app.setWindowIcon(QIcon(I('viewer.png'))) QApplication.setOrganizationName(ORG_NAME) QApplication.setApplicationName(APP_UID) if vprefs['singleinstance']: try: listener = ensure_single_instance(args, open_at) except Exception as e: import traceback error_dialog(None, _('Failed to start viewer'), as_unicode(e), det_msg=traceback.format_exc(), show=True) raise SystemExit(1) main = EbookViewer(args[1] if len(args) > 1 else None, debug_javascript=opts.debug_javascript, open_at=open_at, continue_reading=opts.continue_reading, start_in_fullscreen=opts.full_screen, listener=listener) app.installEventFilter(main) # This is needed for paged mode. Without it, the first document that is # loaded will have extra blank space at the bottom, as # turn_off_internal_scrollbars does not take effect for the first # rendered document main.view.load_path(P('viewer/blank.html', allow_user_override=False)) sys.excepthook = main.unhandled_exception main.show() if opts.raise_window: main.raise_() with main: return app.exec_() return 0
def main(args=sys.argv, logger=None): parser = option_parser() opts, args = parser.parse_args(args) if hasattr(opts, 'help'): parser.print_help() return 1 pid = os.fork() if (islinux or isbsd) else -1 if pid <= 0: override = 'calibre-lrf-viewer' if islinux else None app = Application(args, override_program_name=override) app.setWindowIcon(QIcon(I('viewer.png'))) opts = normalize_settings(parser, opts) stream = open(args[1], 'rb') if len(args) > 1 else None main = file_renderer(stream, opts, logger=logger) main.set_exception_handler() main.show() main.render() main.activateWindow() main.raise_() return app.exec_() return 0
def palette_changed(self): app = QApplication.instance() if app.is_dark_theme: pal = app.palette() col = pal.color(pal.Link) self.default_css = 'a { color: %s }\n\n' % col.name(col.HexRgb) else: self.default_css = '' self.document().setDefaultStyleSheet(self.default_css + self.external_css) self.setHtml(self.last_set_html) def on_anchor_clicked(self, qurl): if not qurl.scheme() and qurl.hasFragment() and qurl.toString( ).startswith('#'): frag = qurl.fragment(qurl.FullyDecoded) if frag: self.scrollToAnchor(frag) return self.anchor_clicked.emit(qurl) if __name__ == '__main__': from calibre.gui2 import Application app = Application([]) app.load_builtin_fonts() w = FlowLayout.test() w.show() app.exec_()
def initialize(self, library_path, db, listener, actions, show_gui=True): from calibre.gui2 import Application app = Application([]) app.load_builtin_fonts() w = QtWidgets.QWidget() w.show() app.exec_() #time.sleep(1000) opts = self.opts self.preferences_action, self.quit_action = actions self.library_path = library_path self.library_broker = GuiLibraryBroker(db) self.content_server = None self.server_change_notification_timer = t = QTimer(self) self.server_changes = Queue() t.setInterval(1000), t.timeout.connect( self.handle_changes_from_server_debounced), t.setSingleShot(True) self._spare_pool = None self.must_restart_before_config = False self.listener = Listener(listener) self.check_messages_timer = QTimer() self.check_messages_timer.timeout.connect( self.another_instance_wants_to_talk) self.check_messages_timer.start(1000) for ac in self.iactions.values(): try: ac.do_genesis() except Exception: # Ignore errors in third party plugins import traceback traceback.print_exc() if getattr(ac, 'plugin_path', None) is None: raise self.donate_action = QAction(QIcon(I('donate.png')), _('&Donate to support calibre'), self) for st in self.istores.values(): st.do_genesis() MainWindowMixin.init_main_window_mixin(self, db) # Jobs Button {{{ self.job_manager = JobManager() self.jobs_dialog = JobsDialog(self, self.job_manager) self.jobs_button = JobsButton(parent=self) self.jobs_button.initialize(self.jobs_dialog, self.job_manager) # }}} LayoutMixin.init_layout_mixin(self) DeviceMixin.init_device_mixin(self) self.progress_indicator = ProgressIndicator(self) self.progress_indicator.pos = (0, 20) self.verbose = opts.verbose self.get_metadata = GetMetadata() self.upload_memory = {} self.metadata_dialogs = [] self.default_thumbnail = None self.tb_wrapper = textwrap.TextWrapper(width=40) self.viewers = collections.deque() self.system_tray_icon = None do_systray = config['systray_icon'] or opts.start_in_tray if do_systray: self.system_tray_icon = factory( app_id='com.calibre-ebook.gui').create_system_tray_icon( parent=self, title='calibre') if self.system_tray_icon is not None: self.system_tray_icon.setIcon( QIcon(I('lt.png', allow_user_override=False))) if not (iswindows or isosx): self.system_tray_icon.setIcon( QIcon.fromTheme('calibre-tray', self.system_tray_icon.icon())) self.system_tray_icon.setToolTip(self.jobs_button.tray_tooltip()) self.system_tray_icon.setVisible(True) self.jobs_button.tray_tooltip_updated.connect( self.system_tray_icon.setToolTip) elif do_systray: prints( 'Failed to create system tray icon, your desktop environment probably' ' does not support the StatusNotifier spec https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/' ) self.system_tray_menu = QMenu(self) self.toggle_to_tray_action = self.system_tray_menu.addAction( QIcon(I('page.png')), '') self.toggle_to_tray_action.triggered.connect( self.system_tray_icon_activated) self.system_tray_menu.addAction(self.donate_action) self.eject_action = self.system_tray_menu.addAction( QIcon(I('eject.png')), _('&Eject connected device')) self.eject_action.setEnabled(False) self.addAction(self.quit_action) self.system_tray_menu.addAction(self.quit_action) self.keyboard.register_shortcut('quit calibre', _('Quit calibre'), default_keys=('Ctrl+Q', ), action=self.quit_action) if self.system_tray_icon is not None: self.system_tray_icon.setContextMenu(self.system_tray_menu) self.system_tray_icon.activated.connect( self.system_tray_icon_activated) self.quit_action.triggered[bool].connect(self.quit) self.donate_action.triggered[bool].connect(self.donate) self.minimize_action = QAction(_('Minimize the calibre window'), self) self.addAction(self.minimize_action) self.keyboard.register_shortcut('minimize calibre', self.minimize_action.text(), default_keys=(), action=self.minimize_action) self.minimize_action.triggered.connect(self.showMinimized) self.esc_action = QAction(self) self.addAction(self.esc_action) self.keyboard.register_shortcut('clear current search', _('Clear the current search'), default_keys=('Esc', ), action=self.esc_action) self.esc_action.triggered.connect(self.esc) self.shift_esc_action = QAction(self) self.addAction(self.shift_esc_action) self.keyboard.register_shortcut('focus book list', _('Focus the book list'), default_keys=('Shift+Esc', ), action=self.shift_esc_action) self.shift_esc_action.triggered.connect(self.shift_esc) self.ctrl_esc_action = QAction(self) self.addAction(self.ctrl_esc_action) self.keyboard.register_shortcut('clear virtual library', _('Clear the virtual library'), default_keys=('Ctrl+Esc', ), action=self.ctrl_esc_action) self.ctrl_esc_action.triggered.connect(self.ctrl_esc) self.alt_esc_action = QAction(self) self.addAction(self.alt_esc_action) self.keyboard.register_shortcut('clear additional restriction', _('Clear the additional restriction'), default_keys=('Alt+Esc', ), action=self.alt_esc_action) self.alt_esc_action.triggered.connect( self.clear_additional_restriction) # ###################### Start spare job server ######################## QTimer.singleShot(1000, self.create_spare_pool) # ###################### Location Manager ######################## self.location_manager.location_selected.connect(self.location_selected) self.location_manager.unmount_device.connect( self.device_manager.umount_device) self.location_manager.configure_device.connect( self.configure_connected_device) self.location_manager.update_device_metadata.connect( self.update_metadata_on_device) self.eject_action.triggered.connect(self.device_manager.umount_device) # ################### Update notification ################### UpdateMixin.init_update_mixin(self, opts) # ###################### Search boxes ######################## SearchRestrictionMixin.init_search_restriction_mixin(self) SavedSearchBoxMixin.init_saved_seach_box_mixin(self) # ###################### Library view ######################## LibraryViewMixin.init_library_view_mixin(self, db) SearchBoxMixin.init_search_box_mixin(self) # Requires current_db self.library_view.model().count_changed_signal.connect( self.iactions['Choose Library'].count_changed) if not gprefs.get('quick_start_guide_added', False): try: add_quick_start_guide(self.library_view) except: import traceback traceback.print_exc() for view in ('library', 'memory', 'card_a', 'card_b'): v = getattr(self, '%s_view' % view) v.selectionModel().selectionChanged.connect(self.update_status_bar) v.model().count_changed_signal.connect(self.update_status_bar) self.library_view.model().count_changed() self.bars_manager.database_changed(self.library_view.model().db) self.library_view.model().database_changed.connect( self.bars_manager.database_changed, type=Qt.QueuedConnection) # ########################## Tags Browser ############################## TagBrowserMixin.init_tag_browser_mixin(self, db) self.library_view.model().database_changed.connect( self.populate_tb_manage_menu, type=Qt.QueuedConnection) # ######################## Search Restriction ########################## if db.prefs['virtual_lib_on_startup']: self.apply_virtual_library(db.prefs['virtual_lib_on_startup']) self.rebuild_vl_tabs() # ########################## Cover Flow ################################ CoverFlowMixin.init_cover_flow_mixin(self) self._calculated_available_height = min(max_available_height() - 15, self.height()) self.resize(self.width(), self._calculated_available_height) self.build_context_menus() for ac in self.iactions.values(): try: ac.gui_layout_complete() except: import traceback traceback.print_exc() if ac.plugin_path is None: raise if config['autolaunch_server']: self.start_content_server() self.read_settings() self.finalize_layout() self.bars_manager.start_animation() self.set_window_title() for ac in self.iactions.values(): try: ac.initialization_complete() except: import traceback traceback.print_exc() if ac.plugin_path is None: raise self.set_current_library_information(current_library_name(), db.library_id, db.field_metadata) register_keyboard_shortcuts() self.keyboard.finalize() if show_gui: # Note this has to come after restoreGeometry() because of # https://bugreports.qt.io/browse/QTBUG-56831 self.show() if self.system_tray_icon is not None and self.system_tray_icon.isVisible( ) and opts.start_in_tray: self.hide_windows() self.auto_adder = AutoAdder(gprefs['auto_add_path'], self) # Now that the gui is initialized we can restore the quickview state # The same thing will be true for any action-based operation with a # layout button from calibre.gui2.actions.show_quickview import get_quickview_action_plugin qv = get_quickview_action_plugin() if qv: qv.qv_button.restore_state() self.save_layout_state() # Collect cycles now gc.collect() QApplication.instance().shutdown_signal_received.connect(self.quit) if show_gui and self.gui_debug is not None: QTimer.singleShot(10, self.show_gui_debug_msg) self.iactions['Connect Share'].check_smartdevice_menus() QTimer.singleShot(1, self.start_smartdevice) QTimer.singleShot(100, self.update_toggle_to_tray_action)
self.model.import_rules(rules) self.changed.emit() # }}} if __name__ == '__main__': from calibre.gui2 import Application app = Application([]) from calibre.library import db db = db() if False: d = RuleEditor(db.field_metadata, 'column_icon_rules') d.add_blank_condition() d.exec_() kind, col, r = d.rule print ('Column to be colored:', col) print ('Template:') print (r.template) else: d = EditRules() d.resize(QSize(800, 600)) d.initialize(db.field_metadata, db.prefs, None, 'column_color_rules') d.show() app.exec_() d.commit(db.prefs)