def on_bridge_ready(self): f = QApplication.instance().font() fi = QFontInfo(f) family = f.family() if family in ('.AppleSystemUIFont', 'MS Shell Dlg 2'): family = 'system-ui' ui_data = { 'all_font_families': QFontDatabase().families(), 'ui_font_family': family, 'ui_font_sz': '{}px'.format(fi.pixelSize()), 'show_home_page_on_ready': self.show_home_page_on_ready, 'system_colors': system_colors(), 'QT_VERSION': QT_VERSION, 'short_time_fmt': QLocale.system().timeFormat(QLocale.FormatType.ShortFormat), } self.bridge.create_view(vprefs['session_data'], vprefs['local_storage'], field_metadata.all_metadata(), ui_data) performance_monitor('bridge ready') for func, args in iteritems(self.pending_bridge_ready_actions): getattr(self.bridge, func)(*args)
def _load_ebook_worker(self, pathtoebook, open_at, reload_book): try: ans = prepare_book(pathtoebook, force=reload_book, prepare_notify=self.prepare_notify) except WorkerError as e: self.book_prepared.emit(False, { 'exception': e, 'tb': e.orig_tb, 'pathtoebook': pathtoebook }) except Exception as e: import traceback self.book_prepared.emit( False, { 'exception': e, 'tb': traceback.format_exc(), 'pathtoebook': pathtoebook }) else: performance_monitor('prepared emitted') self.book_prepared.emit( True, { 'base': ans, 'pathtoebook': pathtoebook, 'open_at': open_at, 'reloaded': reload_book })
def show_loading_message(self, msg): if msg: self.loading_overlay(msg) else: if not hasattr(self, 'initial_loading_performace_reported'): performance_monitor('loading finished') self.initial_loading_performace_reported = True self.loading_overlay.hide()
def load_finished(self, ok, data): cbd = self.calibre_book_data_for_first_book self.calibre_book_data_for_first_book = None if self.shutting_down: return open_at, self.pending_open_at = self.pending_open_at, None self.web_view.clear_caches() if not ok: self.actions_toolbar.update_action_state(False) self.setWindowTitle(self.base_window_title) tb = as_unicode(data['tb'].strip(), errors='replace') tb = re.split(r'^calibre\.gui2\.viewer\.convert_book\.ConversionFailure:\s*', tb, maxsplit=1, flags=re.M)[-1] last_line = tuple(tb.strip().splitlines())[-1] if last_line.startswith('calibre.ebooks.DRMError'): DRMErrorMessage(self).exec_() else: error_dialog(self, _('Loading book failed'), _( 'Failed to open the book at {0}. Click "Show details" for more info.').format(data['pathtoebook']), det_msg=tb, show=True) self.loading_overlay.hide() self.web_view.show_home_page() return try: set_book_path(data['base'], data['pathtoebook']) except Exception: if data['reloaded']: raise self.load_ebook(data['pathtoebook'], open_at=data['open_at'], reload_book=True) return self.current_book_data = data get_current_book_data(self.current_book_data) self.current_book_data['annotations_map'] = defaultdict(list) self.current_book_data['annotations_path_key'] = path_key(data['pathtoebook']) + '.json' self.load_book_data(cbd) self.update_window_title() initial_cfi = self.initial_cfi_for_current_book() initial_position = {'type': 'cfi', 'data': initial_cfi} if initial_cfi else None if open_at: if open_at.startswith('toc:'): initial_toc_node = self.toc_model.node_id_for_text(open_at[len('toc:'):]) initial_position = {'type': 'toc', 'data': initial_toc_node} elif open_at.startswith('toc-href:'): initial_toc_node = self.toc_model.node_id_for_href(open_at[len('toc-href:'):], exact=True) initial_position = {'type': 'toc', 'data': initial_toc_node} elif open_at.startswith('toc-href-contains:'): initial_toc_node = self.toc_model.node_id_for_href(open_at[len('toc-href-contains:'):], exact=False) initial_position = {'type': 'toc', 'data': initial_toc_node} elif open_at.startswith('epubcfi(/'): initial_position = {'type': 'cfi', 'data': open_at} elif open_at.startswith('ref:'): initial_position = {'type': 'ref', 'data': open_at[len('ref:'):]} elif is_float(open_at): initial_position = {'type': 'bookpos', 'data': float(open_at)} highlights = self.current_book_data['annotations_map']['highlight'] self.highlights_widget.load(highlights) self.web_view.start_book_load(initial_position=initial_position, highlights=highlights, current_book_data=self.current_book_data) performance_monitor('webview loading requested')
def show_loading_message(self, msg): if msg: self.loading_overlay(msg) self.actions_toolbar.update_action_state(False) else: if not hasattr(self, 'initial_loading_performace_reported'): performance_monitor('loading finished') self.initial_loading_performace_reported = True self.loading_overlay.hide() self.actions_toolbar.update_action_state(True)
def load_ebook(self, pathtoebook, open_at=None, reload_book=False): performance_monitor('Load of book started', reset=True) self.web_view.show_home_page_on_ready = False if open_at: self.pending_open_at = open_at self.setWindowTitle(_('Loading book') + '… — {}'.format(self.base_window_title)) self.loading_overlay(_('Loading book, please wait')) self.save_annotations() self.current_book_data = {} get_current_book_data(self.current_book_data) self.search_widget.clear_searches() t = Thread(name='LoadBook', target=self._load_ebook_worker, args=(pathtoebook, open_at, reload_book or self.force_reload)) t.daemon = True t.start()
def load_ebook(self, pathtoebook, open_at=None, reload_book=False): if '.' not in os.path.basename(pathtoebook): pathtoebook = os.path.abspath(os.path.realpath(pathtoebook)) performance_monitor('Load of book started', reset=True) self.actions_toolbar.update_action_state(False) self.web_view.show_home_page_on_ready = False if open_at: self.pending_open_at = open_at self.setWindowTitle(_('Loading book') + f'… — {self.base_window_title}') self.loading_overlay(_('Loading book, please wait')) self.save_annotations() self.current_book_data = {} get_current_book_data(self.current_book_data) self.search_widget.clear_searches() t = Thread(name='LoadBook', target=self._load_ebook_worker, args=(pathtoebook, open_at, reload_book or self.force_reload)) t.daemon = True t.start()
def show_loading_message(self, msg): if msg: self.loading_overlay(msg) else: performance_monitor('loading finished') self.loading_overlay.hide()
def on_iframe_ready(self): performance_monitor('iframe ready')