def restore_state(self): state = vprefs['main_window_state'] geom = vprefs['main_window_geometry'] if geom and get_session_pref('remember_window_geometry', default=False): self.restoreGeometry(geom) if state: self.restoreState(state, self.MAIN_WINDOW_STATE_VERSION) self.inspector_dock.setVisible(False)
def update_mode_action(self): mode = get_session_pref('read_mode', default='paged', group=None) a = self.mode_action if mode == 'paged': a.setChecked(False) a.setToolTip(_('Switch to flow mode -- where the text is not broken into pages')) else: a.setChecked(True) a.setToolTip(_('Switch to paged mode -- where the text is broken into pages'))
def populate_color_scheme_menu(self): m = self.color_scheme_menu m.clear() ccs = get_session_pref('current_color_scheme', group=None) or '' ucs = get_session_pref('user_color_schemes', group=None) or {} def add_action(key, defns): a = m.addAction(defns[key]['name']) a.setCheckable(True) a.setObjectName('color-switch-action:{}'.format(key)) a.triggered.connect(self.color_switch_triggerred) if key == ccs: a.setChecked(True) for key in sorted(ucs, key=lambda x: primary_sort_key(ucs[x]['name'])): add_action(key, ucs) m.addSeparator() for key in sorted(self.default_color_schemes, key=lambda x: primary_sort_key(self.default_color_schemes[x]['name'])): add_action(key, self.default_color_schemes)
def restore_state(self): state = vprefs['main_window_state'] geom = vprefs['main_window_geometry'] if geom and get_session_pref('remember_window_geometry', default=False): QApplication.instance().safe_restore_geometry(self, geom) else: QApplication.instance().ensure_window_on_screen(self) if state: self.restoreState(state, self.MAIN_WINDOW_STATE_VERSION) self.inspector_dock.setVisible(False)
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 save_annotations(self): if not self.current_book_data: return amap = self.current_book_data['annotations_map'] annots = as_bytes(serialize_annotations(amap)) with open(os.path.join(annotations_dir, self.current_book_data['annotations_path_key']), 'wb') as f: f.write(annots) if self.current_book_data.get('pathtoebook', '').lower().endswith( '.epub') and get_session_pref('save_annotations_in_ebook', default=True): path = self.current_book_data['pathtoebook'] if os.access(path, os.W_OK): before_stat = os.stat(path) save_annots_to_epub(path, annots) update_book(path, before_stat, {'calibre-book-annotations.json': annots})
def populate_open_menu(self): m = self.open_menu m.clear() recent = get_session_pref('standalone_recently_opened', group=None, default=()) if recent: for entry in recent: try: path = os.path.abspath(entry['pathtoebook']) except Exception: continue if path == os.path.abspath(set_book_path.pathtoebook): continue m.addAction('{}\t {}'.format( elided_text(entry['title'], pos='right', width=250), elided_text(os.path.basename(path), width=250))).triggered.connect(partial( self.open_book_at_path.emit, path))
def initial_cfi_for_current_book(self): lrp = self.current_book_data['annotations_map']['last-read'] if lrp and get_session_pref('remember_last_read', default=True): lrp = lrp[0] if lrp['pos_type'] == 'epubcfi': return lrp['pos']
def update_visibility(self): self.setVisible( bool(get_session_pref('show_actions_toolbar', default=False)))
def visible_in_fullscreen(self): return bool(get_session_pref('show_actions_toolbar_in_fullscreen', default=False))