def load_finished(self, ok, data): open_at, self.pending_open_at = self.pending_open_at, None if not ok: self.setWindowTitle(self.base_window_title) error_dialog( self, _('Loading book failed'), _('Failed to open the book at {0}. Click "Show details" for more info.' ).format(data['pathtoebook']), det_msg=data['tb'], show=True) self.web_view.show_home_page() return set_book_path(data['base'], data['pathtoebook']) self.current_book_data = 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() self.update_window_title() initial_cfi = self.initial_cfi_for_current_book() initial_toc_node = None if open_at: if open_at.startswith('toc:'): initial_toc_node = self.toc_model.node_id_for_text( open_at[len('toc:'):]) elif open_at.startswith('epubcfi(/'): initial_cfi = open_at self.web_view.start_book_load(initial_cfi=initial_cfi, initial_toc_node=initial_toc_node)
def load_finished(self, ok, data): open_at, self.pending_open_at = self.pending_open_at, None if not ok: self.setWindowTitle(self.base_window_title) tb = data['tb'].strip() 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 set_book_path(data['base'], data['pathtoebook']) self.current_book_data = 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() self.update_window_title() initial_cfi = self.initial_cfi_for_current_book() initial_toc_node = initial_bookpos = None if open_at: if open_at.startswith('toc:'): initial_toc_node = self.toc_model.node_id_for_text(open_at[len('toc:'):]) elif open_at.startswith('epubcfi(/'): initial_cfi = open_at elif is_float(open_at): initial_bookpos = float(open_at) self.web_view.start_book_load(initial_cfi=initial_cfi, initial_toc_node=initial_toc_node, initial_bookpos=initial_bookpos)
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')