def __init__(self, opts, parent=None, gui_debug=None): global _gui MainWindow.__init__(self, opts, parent=parent, disable_automatic_gc=True) self.jobs_pointer = Pointer(self) self.proceed_requested.connect(self.do_proceed, type=Qt.QueuedConnection) self.proceed_question = ProceedQuestion(self) self.job_error_dialog = JobError(self) self.keyboard = Manager(self) _gui = self self.opts = opts self.device_connected = None self.gui_debug = gui_debug self.iactions = OrderedDict() # Actions for action in interface_actions(): if opts.ignore_plugins and action.plugin_path is not None: continue try: ac = self.init_iaction(action) except: # Ignore errors in loading user supplied plugins import traceback traceback.print_exc() if action.plugin_path is None: raise continue ac.plugin_path = action.plugin_path ac.interface_action_base_plugin = action self.add_iaction(ac) self.load_store_plugins()
def __init__(self, opts): MainWindow.__init__(self, opts, disable_automatic_gc=True) self.boss = Boss(self) self.setWindowTitle(self.APP_NAME) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.path_to_ebook = None self.container = None self.current_metadata = None self.blocking_job = BlockingJob(self) self.keyboard = KeyboardManager() self.central = Central(self) self.setCentralWidget(self.central) self.create_actions() self.create_toolbars() self.create_docks() self.create_menubar() self.status_bar = self.statusBar() self.status_bar.addPermanentWidget(self.boss.save_manager.status_widget) self.status_bar.addWidget(QLabel(_('{0} {1} created by {2}').format(__appname__, get_version(), 'Kovid Goyal'))) f = self.status_bar.font() f.setBold(True) self.status_bar.setFont(f) self.boss(self) g = QApplication.instance().desktop().availableGeometry(self) self.resize(g.width()-50, g.height()-50) self.restore_state() self.keyboard.finalize() self.keyboard.set_mode('other')
def __init__(self, opts, notify=None): MainWindow.__init__(self, opts, disable_automatic_gc=True) try: install_new_plugins() except Exception: import traceback traceback.print_exc() self.setWindowTitle(self.APP_NAME) self.boss = Boss(self, notify=notify) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.path_to_ebook = None self.container = None self.current_metadata = None self.blocking_job = BlockingJob(self) self.keyboard = KeyboardManager(self, config_name='shortcuts/tweak_book') self.central = Central(self) self.setCentralWidget(self.central) self.check_book = Check(self) self.spell_check = SpellCheck(parent=self) self.toc_view = TOCViewer(self) self.text_search = TextSearch(self) self.saved_searches = SavedSearches(self) self.image_browser = InsertImage(self, for_browsing=True) self.reports = Reports(self) self.check_external_links = CheckExternalLinks(self) self.insert_char = CharSelect(self) self.manage_fonts = ManageFonts(self) self.sr_debug_output = DebugOutput(self) self.create_actions() self.create_toolbars() self.create_docks() self.create_menubar() self.status_bar = self.statusBar() self.status_bar.addPermanentWidget( self.boss.save_manager.status_widget) self.cursor_position_widget = CursorPositionWidget(self) self.status_bar.addPermanentWidget(self.cursor_position_widget) self.status_bar_default_msg = la = QLabel( ' ' + _('{0} {1} created by {2}').format( __appname__, get_version(), 'Kovid Goyal')) la.base_template = unicode_type(la.text()) self.status_bar.addWidget(la) f = self.status_bar.font() f.setBold(True) self.status_bar.setFont(f) self.boss(self) g = QApplication.instance().desktop().availableGeometry(self) self.resize(g.width() - 50, g.height() - 50) self.restore_state() self.apply_settings()
def __init__(self, logger, opts, parent=None): MainWindow.__init__(self, opts, parent) Ui_MainWindow.__init__(self) self.setupUi(self) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(__appname__ + _(' - LRF Viewer')) self.logger = logger self.opts = opts self.create_document() self.spin_box_action = self.spin_box = QSpinBox() self.tool_bar.addWidget(self.spin_box) self.tool_bar.addSeparator() self.slider_action = self.slider = QSlider(Qt.Horizontal) self.tool_bar.addWidget(self.slider) self.tool_bar.addSeparator() self.search = SearchBox2(self) self.search.initialize('lrf_viewer_search_history') self.search_action = self.tool_bar.addWidget(self.search) self.search.search.connect(self.find) self.action_next_page.setShortcuts( [QKeySequence.MoveToNextPage, QKeySequence(Qt.Key_Space)]) self.action_previous_page.setShortcuts( [QKeySequence.MoveToPreviousPage, QKeySequence(Qt.Key_Backspace)]) self.action_next_match.setShortcuts(QKeySequence.FindNext) self.addAction(self.action_next_match) QObject.connect(self.action_next_page, SIGNAL('triggered(bool)'), self.next) QObject.connect(self.action_previous_page, SIGNAL('triggered(bool)'), self.previous) QObject.connect(self.action_back, SIGNAL('triggered(bool)'), self.back) QObject.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward) QObject.connect(self.action_next_match, SIGNAL('triggered(bool)'), self.next_match) QObject.connect(self.action_open_ebook, SIGNAL('triggered(bool)'), self.open_ebook) QObject.connect(self.action_configure, SIGNAL('triggered(bool)'), self.configure) QObject.connect(self.spin_box, SIGNAL('valueChanged(int)'), self.go_to_page) QObject.connect(self.slider, SIGNAL('valueChanged(int)'), self.go_to_page) self.graphics_view.setRenderHint(QPainter.Antialiasing, True) self.graphics_view.setRenderHint(QPainter.TextAntialiasing, True) self.graphics_view.setRenderHint(QPainter.SmoothPixmapTransform, True) self.closed = False
def __init__(self, opts, notify=None): MainWindow.__init__(self, opts, disable_automatic_gc=True) self.setWindowTitle(self.APP_NAME) self.boss = Boss(self, notify=notify) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.path_to_ebook = None self.container = None self.current_metadata = None self.blocking_job = BlockingJob(self) self.keyboard = KeyboardManager(self, config_name='shortcuts/tweak_book') self.central = Central(self) self.setCentralWidget(self.central) self.check_book = Check(self) self.spell_check = SpellCheck(parent=self) self.toc_view = TOCViewer(self) self.text_search = TextSearch(self) self.saved_searches = SavedSearches(self) self.image_browser = InsertImage(self, for_browsing=True) self.reports = Reports(self) self.check_external_links = CheckExternalLinks(self) self.insert_char = CharSelect(self) self.manage_fonts = ManageFonts(self) self.sr_debug_output = DebugOutput(self) self.create_actions() self.create_toolbars() self.create_docks() self.create_menubar() self.status_bar = self.statusBar() self.status_bar.addPermanentWidget(self.boss.save_manager.status_widget) self.cursor_position_widget = CursorPositionWidget(self) self.status_bar.addPermanentWidget(self.cursor_position_widget) self.status_bar_default_msg = la = QLabel(' ' + _('{0} {1} created by {2}').format(__appname__, get_version(), 'Kovid Goyal')) la.base_template = unicode(la.text()) self.status_bar.addWidget(la) f = self.status_bar.font() f.setBold(True) self.status_bar.setFont(f) self.boss(self) g = QApplication.instance().desktop().availableGeometry(self) self.resize(g.width()-50, g.height()-50) self.restore_state() self.apply_settings()
def __init__(self, data): MainWindow.__init__(self, None) self.setWindowIcon(QIcon(I('store.png'))) self.setWindowTitle(data['window_title']) self.download_data = {} profile = QWebEngineProfile.defaultProfile() profile.setCachePath(os.path.join(cache_dir(), 'web_store', 'hc')) profile.setPersistentStoragePath(os.path.join(cache_dir(), 'web_store', 'ps')) profile.setHttpUserAgent(random_user_agent(allow_ie=False)) profile.downloadRequested.connect(self.download_requested) self.data = data self.central = c = Central(self) c.home.connect(self.go_home) self.setCentralWidget(c) geometry = gprefs.get('store_dialog_main_window_geometry') if geometry is not None: self.restoreGeometry(geometry) self.go_to(data['detail_url'] or None)
def __init__(self, opts, notify=None): MainWindow.__init__(self, opts, disable_automatic_gc=True) self.boss = Boss(self, notify=notify) self.setWindowTitle(self.APP_NAME) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.path_to_ebook = None self.container = None self.current_metadata = None self.blocking_job = BlockingJob(self) self.keyboard = KeyboardManager(self, config_name='shortcuts/tweak_book') self.central = Central(self) self.setCentralWidget(self.central) self.check_book = Check(self) self.toc_view = TOCViewer(self) self.create_actions() self.create_toolbars() self.create_docks() self.create_menubar() self.status_bar = self.statusBar() self.status_bar.addPermanentWidget( self.boss.save_manager.status_widget) self.cursor_position_widget = CursorPositionWidget(self) self.status_bar.addPermanentWidget(self.cursor_position_widget) self.status_bar.addWidget( QLabel( _('{0} {1} created by {2}').format(__appname__, get_version(), 'Kovid Goyal'))) f = self.status_bar.font() f.setBold(True) self.status_bar.setFont(f) self.boss(self) g = QApplication.instance().desktop().availableGeometry(self) self.resize(g.width() - 50, g.height() - 50) self.restore_state() self.keyboard.finalize()
def __init__(self, logger, opts, parent=None): MainWindow.__init__(self, opts, parent) Ui_MainWindow.__init__(self) self.setupUi(self) self.setAttribute(Qt.WA_DeleteOnClose) self.setWindowTitle(__appname__ + _(' - LRF Viewer')) self.logger = logger self.opts = opts self.create_document() self.spin_box_action = self.spin_box = QSpinBox() self.tool_bar.addWidget(self.spin_box) self.tool_bar.addSeparator() self.slider_action = self.slider = QSlider(Qt.Horizontal) self.tool_bar.addWidget(self.slider) self.tool_bar.addSeparator() self.search = SearchBox2(self) self.search.initialize('lrf_viewer_search_history') self.search_action = self.tool_bar.addWidget(self.search) self.search.search.connect(self.find) self.action_next_page.setShortcuts([QKeySequence.MoveToNextPage, QKeySequence(Qt.Key_Space)]) self.action_previous_page.setShortcuts([QKeySequence.MoveToPreviousPage, QKeySequence(Qt.Key_Backspace)]) self.action_next_match.setShortcuts(QKeySequence.FindNext) self.addAction(self.action_next_match) QObject.connect(self.action_next_page, SIGNAL('triggered(bool)'), self.next) QObject.connect(self.action_previous_page, SIGNAL('triggered(bool)'), self.previous) QObject.connect(self.action_back, SIGNAL('triggered(bool)'), self.back) QObject.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward) QObject.connect(self.action_next_match, SIGNAL('triggered(bool)'), self.next_match) QObject.connect(self.action_open_ebook, SIGNAL('triggered(bool)'), self.open_ebook) QObject.connect(self.action_configure, SIGNAL('triggered(bool)'), self.configure) QObject.connect(self.spin_box, SIGNAL('valueChanged(int)'), self.go_to_page) QObject.connect(self.slider, SIGNAL('valueChanged(int)'), self.go_to_page) self.graphics_view.setRenderHint(QPainter.Antialiasing, True) self.graphics_view.setRenderHint(QPainter.TextAntialiasing, True) self.graphics_view.setRenderHint(QPainter.SmoothPixmapTransform, True) self.closed = False
def __init__(self, opts): MainWindow.__init__(self, opts, disable_automatic_gc=True) self.setWindowTitle(self.APP_NAME) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.tdir = None self.path_to_ebook = None self.container = None self.global_undo = GlobalUndoHistory() self.blocking_job = BlockingJob(self) self.file_list_dock = d = QDockWidget(_('&Files Browser'), self) d.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) self.file_list = FileListWidget(d) d.setWidget(self.file_list) self.addDockWidget(Qt.LeftDockWidgetArea, d) self.status_bar = self.statusBar() self.l = QLabel('Placeholder') self.setCentralWidget(self.l)
def __init__(self, opts, notify=None): MainWindow.__init__(self, opts, disable_automatic_gc=True) self.boss = Boss(self, notify=notify) self.setWindowTitle(self.APP_NAME) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.path_to_ebook = None self.container = None self.current_metadata = None self.blocking_job = BlockingJob(self) self.keyboard = KeyboardManager(self, config_name='shortcuts/tweak_book') self.central = Central(self) self.setCentralWidget(self.central) self.check_book = Check(self) self.toc_view = TOCViewer(self) self.image_browser = InsertImage(self, for_browsing=True) self.insert_char = CharSelect(self) self.create_actions() self.create_toolbars() self.create_docks() self.create_menubar() self.status_bar = self.statusBar() self.status_bar.addPermanentWidget(self.boss.save_manager.status_widget) self.cursor_position_widget = CursorPositionWidget(self) self.status_bar.addPermanentWidget(self.cursor_position_widget) self.status_bar.addWidget(QLabel(_('{0} {1} created by {2}').format(__appname__, get_version(), 'Kovid Goyal'))) f = self.status_bar.font() f.setBold(True) self.status_bar.setFont(f) self.boss(self) g = QApplication.instance().desktop().availableGeometry(self) self.resize(g.width()-50, g.height()-50) self.restore_state() self.apply_settings()
def __init__(self, opts): MainWindow.__init__(self, opts, disable_automatic_gc=True) self.boss = Boss(self) self.setWindowTitle(self.APP_NAME) self.setWindowIcon(QIcon(I('tweak.png'))) self.opts = opts self.path_to_ebook = None self.container = None self.current_metadata = None self.blocking_job = BlockingJob(self) self.keyboard = KeyboardManager(parent=self, config_name='shortcuts/tweak') self.create_actions() self.create_menubar() self.create_toolbar() self.create_docks() self.status_bar = self.statusBar() self.l = QLabel('Placeholder') self.setCentralWidget(self.l) self.boss(self) self.keyboard.finalize()
def __init__(self, open_at=None, continue_reading=None, force_reload=False, calibre_book_data=None): MainWindow.__init__(self, None) self.annotations_saver = None self.calibre_book_data_for_first_book = calibre_book_data self.shutting_down = self.close_forced = self.shutdown_done = False self.force_reload = force_reload connect_lambda(self.book_preparation_started, self, lambda self: self.loading_overlay(_( 'Preparing book for first read, please wait')), type=Qt.ConnectionType.QueuedConnection) self.maximized_at_last_fullscreen = False self.save_pos_timer = t = QTimer(self) t.setSingleShot(True), t.setInterval(3000), t.setTimerType(Qt.TimerType.VeryCoarseTimer) connect_lambda(t.timeout, self, lambda self: self.save_annotations(in_book_file=False)) self.pending_open_at = open_at self.base_window_title = _('E-book viewer') self.setDockOptions(QMainWindow.DockOption.AnimatedDocks | QMainWindow.DockOption.AllowTabbedDocks | QMainWindow.DockOption.AllowNestedDocks) self.setWindowTitle(self.base_window_title) self.in_full_screen_mode = None self.image_popup = ImagePopup(self) self.actions_toolbar = at = ActionsToolBar(self) at.open_book_at_path.connect(self.ask_for_open) self.addToolBar(Qt.ToolBarArea.LeftToolBarArea, at) try: os.makedirs(annotations_dir) except EnvironmentError: pass self.current_book_data = {} get_current_book_data(self.current_book_data) self.book_prepared.connect(self.load_finished, type=Qt.ConnectionType.QueuedConnection) self.dock_defs = dock_defs() def create_dock(title, name, area, areas=Qt.DockWidgetArea.LeftDockWidgetArea | Qt.DockWidgetArea.RightDockWidgetArea): ans = QDockWidget(title, self) ans.setObjectName(name) self.addDockWidget(area, ans) ans.setVisible(False) ans.visibilityChanged.connect(self.dock_visibility_changed) return ans for dock_def in itervalues(self.dock_defs): setattr(self, '{}_dock'.format(dock_def.name.partition('-')[0]), create_dock( dock_def.title, dock_def.name, dock_def.initial_area, dock_def.allowed_areas)) self.toc_container = w = QWidget(self) w.l = QVBoxLayout(w) self.toc = TOCView(w) self.toc.clicked[QModelIndex].connect(self.toc_clicked) self.toc.searched.connect(self.toc_searched) self.toc_search = TOCSearch(self.toc, parent=w) w.l.addWidget(self.toc), w.l.addWidget(self.toc_search), w.l.setContentsMargins(0, 0, 0, 0) self.toc_dock.setWidget(w) self.search_widget = w = SearchPanel(self) w.search_requested.connect(self.start_search) w.hide_search_panel.connect(self.search_dock.close) w.count_changed.connect(self.search_results_count_changed) w.goto_cfi.connect(self.goto_cfi) self.search_dock.setWidget(w) self.search_dock.visibilityChanged.connect(self.search_widget.visibility_changed) self.lookup_widget = w = Lookup(self) self.lookup_dock.visibilityChanged.connect(self.lookup_widget.visibility_changed) self.lookup_dock.setWidget(w) self.bookmarks_widget = w = BookmarkManager(self) connect_lambda( w.create_requested, self, lambda self: self.web_view.trigger_shortcut('new_bookmark')) w.edited.connect(self.bookmarks_edited) w.activated.connect(self.bookmark_activated) w.toggle_requested.connect(self.toggle_bookmarks) self.bookmarks_dock.setWidget(w) self.highlights_widget = w = HighlightsPanel(self) self.highlights_dock.setWidget(w) w.toggle_requested.connect(self.toggle_highlights) self.web_view = WebView(self) self.web_view.cfi_changed.connect(self.cfi_changed) self.web_view.reload_book.connect(self.reload_book) self.web_view.toggle_toc.connect(self.toggle_toc) self.web_view.show_search.connect(self.show_search) self.web_view.find_next.connect(self.search_widget.find_next_requested) self.search_widget.show_search_result.connect(self.web_view.show_search_result) self.web_view.search_result_not_found.connect(self.search_widget.search_result_not_found) self.web_view.search_result_discovered.connect(self.search_widget.search_result_discovered) self.web_view.toggle_bookmarks.connect(self.toggle_bookmarks) self.web_view.toggle_highlights.connect(self.toggle_highlights) self.web_view.new_bookmark.connect(self.bookmarks_widget.create_new_bookmark) self.web_view.toggle_inspector.connect(self.toggle_inspector) self.web_view.toggle_lookup.connect(self.toggle_lookup) self.web_view.quit.connect(self.quit) self.web_view.update_current_toc_nodes.connect(self.toc.update_current_toc_nodes) self.web_view.toggle_full_screen.connect(self.toggle_full_screen) self.web_view.ask_for_open.connect(self.ask_for_open, type=Qt.ConnectionType.QueuedConnection) self.web_view.selection_changed.connect(self.lookup_widget.selected_text_changed, type=Qt.ConnectionType.QueuedConnection) self.web_view.selection_changed.connect(self.highlights_widget.selected_text_changed, type=Qt.ConnectionType.QueuedConnection) self.web_view.view_image.connect(self.view_image, type=Qt.ConnectionType.QueuedConnection) self.web_view.copy_image.connect(self.copy_image, type=Qt.ConnectionType.QueuedConnection) self.web_view.show_loading_message.connect(self.show_loading_message) self.web_view.show_error.connect(self.show_error) self.web_view.print_book.connect(self.print_book, type=Qt.ConnectionType.QueuedConnection) self.web_view.reset_interface.connect(self.reset_interface, type=Qt.ConnectionType.QueuedConnection) self.web_view.quit.connect(self.quit, type=Qt.ConnectionType.QueuedConnection) self.web_view.shortcuts_changed.connect(self.shortcuts_changed) self.web_view.scrollbar_context_menu.connect(self.scrollbar_context_menu) self.web_view.close_prep_finished.connect(self.close_prep_finished) self.web_view.highlights_changed.connect(self.highlights_changed) self.web_view.edit_book.connect(self.edit_book) self.actions_toolbar.initialize(self.web_view, self.search_dock.toggleViewAction()) at.update_action_state(False) self.setCentralWidget(self.web_view) self.loading_overlay = LoadingOverlay(self) self.restore_state() self.actions_toolbar.update_visibility() self.dock_visibility_changed() self.highlights_widget.request_highlight_action.connect(self.web_view.highlight_action) self.highlights_widget.web_action.connect(self.web_view.generic_action) if continue_reading: self.continue_reading() self.setup_mouse_auto_hide()
def __init__(self, debug_javascript): MainWindow.__init__(self, None) self.setWindowTitle(_('E-book viewer')) self.base_window_title = unicode(self.windowTitle()) self.setObjectName('EbookViewer') self.setWindowIcon(QIcon(I('viewer.png'))) self.setDockOptions(self.AnimatedDocks | self.AllowTabbedDocks) self.centralwidget = c = QWidget(self) c.setObjectName('centralwidget') self.setCentralWidget(c) self.central_layout = cl = QGridLayout(c) cl.setSpacing(0) c.setLayout(cl), cl.setContentsMargins(0, 0, 0, 0) self.view = v = DocumentView(self) v.setMinimumSize(100, 100) self.view.initialize_view(debug_javascript) v.setObjectName('view') cl.addWidget(v) self.vertical_scrollbar = vs = QScrollBar(c) vs.setOrientation(Qt.Vertical), vs.setObjectName("vertical_scrollbar") cl.addWidget(vs, 0, 1, 2, 1) self.horizontal_scrollbar = hs = QScrollBar(c) hs.setOrientation(Qt.Vertical), hs.setObjectName("horizontal_scrollbar") cl.addWidget(hs, 1, 0, 1, 1) self.tool_bar = tb = QToolBar(self) tb.setObjectName('tool_bar'), tb.setIconSize(QSize(32, 32)) self.addToolBar(Qt.LeftToolBarArea, tb) self.tool_bar2 = tb2 = QToolBar(self) tb2.setObjectName('tool_bar2') self.addToolBar(Qt.TopToolBarArea, tb2) self.tool_bar.setContextMenuPolicy(Qt.PreventContextMenu) self.tool_bar2.setContextMenuPolicy(Qt.PreventContextMenu) self.pos = DoubleSpinBox() self.pos.setDecimals(1) self.pos.setSuffix('/'+_('Unknown')+' ') self.pos.setMinimum(1.) self.tool_bar2.addWidget(self.pos) self.tool_bar2.addSeparator() self.reference = Reference() self.tool_bar2.addWidget(self.reference) self.tool_bar2.addSeparator() self.search = SearchBox2(self) self.search.setMinimumContentsLength(20) self.search.initialize('viewer_search_history') self.search.setToolTip(_('Search for text in book')) self.search.setMinimumWidth(200) self.tool_bar2.addWidget(self.search) self.toc_dock = d = QDockWidget(_('Table of Contents'), self) self.toc = TOCView(self) d.setObjectName('toc-dock') d.setWidget(self.toc) d.close() # starts out hidden self.addDockWidget(Qt.LeftDockWidgetArea, d) d.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) self.bookmarks_dock = d = QDockWidget(_('Bookmarks'), self) self.bookmarks = BookmarkManager(self) d.setObjectName('bookmarks-dock') d.setWidget(self.bookmarks) d.close() # starts out hidden self.addDockWidget(Qt.RightDockWidgetArea, d) d.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) self.create_actions() self.metadata = Metadata(self.centralwidget) self.history = History(self.action_back, self.action_forward) self.full_screen_label = QLabel(''' <center> <h1>%s</h1> <h3>%s</h3> <h3>%s</h3> <h3>%s</h3> </center> '''%(_('Full screen mode'), _('Right click to show controls'), _('Tap in the left or right page margin to turn pages'), _('Press Esc to quit')), self.centralWidget()) self.full_screen_label.setVisible(False) self.full_screen_label.final_height = 200 self.full_screen_label.setFocusPolicy(Qt.NoFocus) self.full_screen_label.setStyleSheet(''' QLabel { text-align: center; background-color: white; color: black; border-width: 1px; border-style: solid; border-radius: 20px; } ''') self.clock_label = QLabel('99:99', self.centralWidget()) self.clock_label.setVisible(False) self.clock_label.setFocusPolicy(Qt.NoFocus) self.info_label_style = ''' QLabel { text-align: center; border-width: 1px; border-style: solid; border-radius: 8px; background-color: %s; color: %s; font-family: monospace; font-size: larger; padding: 5px; }''' self.pos_label = QLabel('2000/4000', self.centralWidget()) self.pos_label.setVisible(False) self.pos_label.setFocusPolicy(Qt.NoFocus) self.resize(653, 746) if workaround_broken_under_mouse is not None: for bar in (self.tool_bar, self.tool_bar2): for ac in bar.actions(): m = ac.menu() if m is not None: m.aboutToHide.connect(partial(workaround_broken_under_mouse, bar.widgetForAction(ac)))
def __init__(self, pathtoebook=None, debug_javascript=False, open_at=None, start_in_fullscreen=False): MainWindow.__init__(self, None) self.setupUi(self) self.view.initialize_view(debug_javascript) self.view.magnification_changed.connect(self.magnification_changed) self.show_toc_on_open = False self.current_book_has_toc = False self.base_window_title = unicode(self.windowTitle()) self.iterator = None self.current_page = None self.pending_search = None self.pending_search_dir= None self.pending_anchor = None self.pending_reference = None self.pending_bookmark = None self.pending_restore = False self.existing_bookmarks= [] self.selected_text = None self.was_maximized = False self.read_settings() self.dictionary_box.hide() self.close_dictionary_view.clicked.connect(lambda x:self.dictionary_box.hide()) self.history = History(self.action_back, self.action_forward) self.metadata = Metadata(self) self.pos = DoubleSpinBox() self.pos.setDecimals(1) self.pos.setSuffix('/'+_('Unknown')+' ') self.pos.setMinimum(1.) self.pos.value_changed.connect(self.update_pos_label) self.splitter.setCollapsible(0, False) self.splitter.setCollapsible(1, False) self.pos.setMinimumWidth(150) self.tool_bar2.insertWidget(self.action_find_next, self.pos) self.reference = Reference() self.tool_bar2.insertSeparator(self.action_find_next) self.tool_bar2.insertWidget(self.action_find_next, self.reference) self.tool_bar2.insertSeparator(self.action_find_next) self.setFocusPolicy(Qt.StrongFocus) self.search = SearchBox2(self) self.search.setMinimumContentsLength(20) self.search.initialize('viewer_search_history') self.search.setToolTip(_('Search for text in book')) self.search.setMinimumWidth(200) self.tool_bar2.insertWidget(self.action_find_next, self.search) self.view.set_manager(self) self.pi = ProgressIndicator(self) self.toc.setVisible(False) self.action_quit = QAction(_('&Quit'), self) self.addAction(self.action_quit) self.view_resized_timer = QTimer(self) self.view_resized_timer.timeout.connect(self.viewport_resize_finished) self.view_resized_timer.setSingleShot(True) self.resize_in_progress = False self.action_quit.triggered.connect(self.quit) self.action_copy.setDisabled(True) self.action_metadata.setCheckable(True) self.action_table_of_contents.setCheckable(True) self.toc.setMinimumWidth(80) self.action_reference_mode.setCheckable(True) self.action_reference_mode.triggered[bool].connect(self.view.reference_mode) self.action_metadata.triggered[bool].connect(self.metadata.setVisible) self.action_table_of_contents.toggled[bool].connect(self.set_toc_visible) self.action_copy.triggered[bool].connect(self.copy) self.action_font_size_larger.triggered.connect(self.font_size_larger) self.action_font_size_smaller.triggered.connect(self.font_size_smaller) self.action_open_ebook.triggered[bool].connect(self.open_ebook) self.action_next_page.triggered.connect(self.view.next_page) self.action_previous_page.triggered.connect(self.view.previous_page) self.action_find_next.triggered.connect(self.find_next) self.action_find_previous.triggered.connect(self.find_previous) self.action_full_screen.triggered[bool].connect(self.toggle_fullscreen) self.action_full_screen.setToolTip(_('Toggle full screen [%s]') % _(' or ').join([x for x in self.view.shortcuts.get_shortcuts('Fullscreen')])) self.action_back.triggered[bool].connect(self.back) self.action_forward.triggered[bool].connect(self.forward) self.action_preferences.triggered.connect(self.do_config) self.pos.editingFinished.connect(self.goto_page_num) self.vertical_scrollbar.valueChanged[int].connect(lambda x:self.goto_page(x/100.)) self.search.search.connect(self.find) self.search.focus_to_library.connect(lambda: self.view.setFocus(Qt.OtherFocusReason)) self.toc.pressed[QModelIndex].connect(self.toc_clicked) self.reference.goto.connect(self.goto) self.bookmarks_menu = QMenu() self.action_bookmark.setMenu(self.bookmarks_menu) self.set_bookmarks([]) self.themes_menu = QMenu() self.action_load_theme.setMenu(self.themes_menu) self.tool_bar.widgetForAction(self.action_load_theme).setPopupMode(QToolButton.InstantPopup) self.load_theme_menu() if pathtoebook is not None: f = functools.partial(self.load_ebook, pathtoebook, open_at=open_at) QTimer.singleShot(50, f) self.view.setMinimumSize(100, 100) self.toc.setCursor(Qt.PointingHandCursor) self.tool_bar.setContextMenuPolicy(Qt.PreventContextMenu) self.tool_bar2.setContextMenuPolicy(Qt.PreventContextMenu) self.tool_bar.widgetForAction(self.action_bookmark).setPopupMode(QToolButton.InstantPopup) self.action_full_screen.setCheckable(True) self.full_screen_label = QLabel(''' <center> <h1>%s</h1> <h3>%s</h3> <h3>%s</h3> <h3>%s</h3> </center> '''%(_('Full screen mode'), _('Right click to show controls'), _('Tap in the left or right page margin to turn pages'), _('Press Esc to quit')), self) self.full_screen_label.setVisible(False) self.full_screen_label.setStyleSheet(''' QLabel { text-align: center; background-color: white; color: black; border-width: 1px; border-style: solid; border-radius: 20px; } ''') self.window_mode_changed = None self.toggle_toolbar_action = QAction(_('Show/hide controls'), self) self.toggle_toolbar_action.setCheckable(True) self.toggle_toolbar_action.triggered.connect(self.toggle_toolbars) self.toolbar_hidden = None self.addAction(self.toggle_toolbar_action) self.full_screen_label_anim = QPropertyAnimation( self.full_screen_label, 'size') self.clock_label = QLabel('99:99', self) self.clock_label.setVisible(False) self.clock_label.setFocusPolicy(Qt.NoFocus) self.info_label_style = ''' QLabel { text-align: center; border-width: 1px; border-style: solid; border-radius: 8px; background-color: %s; color: %s; font-family: monospace; font-size: larger; padding: 5px; }''' self.original_frame_style = self.frame.frameStyle() self.pos_label = QLabel('2000/4000', self) self.pos_label.setVisible(False) self.pos_label.setFocusPolicy(Qt.NoFocus) self.clock_timer = QTimer(self) self.clock_timer.timeout.connect(self.update_clock) self.print_menu = QMenu() self.print_menu.addAction(QIcon(I('print-preview.png')), _('Print Preview')) self.action_print.setMenu(self.print_menu) self.tool_bar.widgetForAction(self.action_print).setPopupMode(QToolButton.MenuButtonPopup) self.action_print.triggered.connect(self.print_book) self.print_menu.actions()[0].triggered.connect(self.print_preview) self.open_history_menu = QMenu() self.clear_recent_history_action = QAction( _('Clear list of recently opened books'), self) self.clear_recent_history_action.triggered.connect(self.clear_recent_history) self.build_recent_menu() self.action_open_ebook.setMenu(self.open_history_menu) self.open_history_menu.triggered[QAction].connect(self.open_recent) w = self.tool_bar.widgetForAction(self.action_open_ebook) w.setPopupMode(QToolButton.MenuButtonPopup) for x in ('tool_bar', 'tool_bar2'): x = getattr(self, x) for action in x.actions(): # So that the keyboard shortcuts for these actions will # continue to function even when the toolbars are hidden self.addAction(action) for plugin in self.view.document.all_viewer_plugins: plugin.customize_ui(self) self.view.document.settings_changed.connect(self.settings_changed) self.restore_state() self.settings_changed() self.action_toggle_paged_mode.toggled[bool].connect(self.toggle_paged_mode) if (start_in_fullscreen or self.view.document.start_in_fullscreen): self.action_full_screen.trigger()
def __init__(self, open_at=None, continue_reading=None, force_reload=False): MainWindow.__init__(self, None) self.shutting_down = False self.force_reload = force_reload connect_lambda(self.book_preparation_started, self, lambda self: self.loading_overlay( _('Preparing book for first read, please wait')), type=Qt.QueuedConnection) self.maximized_at_last_fullscreen = False self.pending_open_at = open_at self.base_window_title = _('E-book viewer') self.setWindowTitle(self.base_window_title) self.in_full_screen_mode = None self.image_popup = ImagePopup(self) self.actions_toolbar = at = ActionsToolBar(self) at.open_book_at_path.connect(self.ask_for_open) self.addToolBar(Qt.LeftToolBarArea, at) try: os.makedirs(annotations_dir) except EnvironmentError: pass self.current_book_data = {} self.book_prepared.connect(self.load_finished, type=Qt.QueuedConnection) self.dock_defs = dock_defs() def create_dock(title, name, area, areas=Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea): ans = QDockWidget(title, self) ans.setObjectName(name) self.addDockWidget(area, ans) ans.setVisible(False) ans.visibilityChanged.connect(self.dock_visibility_changed) return ans for dock_def in itervalues(self.dock_defs): setattr( self, '{}_dock'.format(dock_def.name.partition('-')[0]), create_dock(dock_def.title, dock_def.name, dock_def.initial_area, dock_def.allowed_areas)) self.toc_container = w = QWidget(self) w.l = QVBoxLayout(w) self.toc = TOCView(w) self.toc.clicked[QModelIndex].connect(self.toc_clicked) self.toc.searched.connect(self.toc_searched) self.toc_search = TOCSearch(self.toc, parent=w) w.l.addWidget(self.toc), w.l.addWidget( self.toc_search), w.l.setContentsMargins(0, 0, 0, 0) self.toc_dock.setWidget(w) self.lookup_widget = w = Lookup(self) self.lookup_dock.visibilityChanged.connect( self.lookup_widget.visibility_changed) self.lookup_dock.setWidget(w) self.bookmarks_widget = w = BookmarkManager(self) connect_lambda( w.create_requested, self, lambda self: self.web_view. get_current_cfi(self.bookmarks_widget.create_new_bookmark)) w.edited.connect(self.bookmarks_edited) w.activated.connect(self.bookmark_activated) w.toggle_requested.connect(self.toggle_bookmarks) self.bookmarks_dock.setWidget(w) self.web_view = WebView(self) self.web_view.cfi_changed.connect(self.cfi_changed) self.web_view.reload_book.connect(self.reload_book) self.web_view.toggle_toc.connect(self.toggle_toc) self.web_view.toggle_bookmarks.connect(self.toggle_bookmarks) self.web_view.toggle_inspector.connect(self.toggle_inspector) self.web_view.toggle_lookup.connect(self.toggle_lookup) self.web_view.quit.connect(self.quit) self.web_view.update_current_toc_nodes.connect( self.toc.update_current_toc_nodes) self.web_view.toggle_full_screen.connect(self.toggle_full_screen) self.web_view.ask_for_open.connect(self.ask_for_open, type=Qt.QueuedConnection) self.web_view.selection_changed.connect( self.lookup_widget.selected_text_changed, type=Qt.QueuedConnection) self.web_view.view_image.connect(self.view_image, type=Qt.QueuedConnection) self.web_view.copy_image.connect(self.copy_image, type=Qt.QueuedConnection) self.web_view.show_loading_message.connect(self.show_loading_message) self.web_view.show_error.connect(self.show_error) self.web_view.print_book.connect(self.print_book, type=Qt.QueuedConnection) self.web_view.reset_interface.connect(self.reset_interface, type=Qt.QueuedConnection) self.web_view.shortcuts_changed.connect(self.shortcuts_changed) self.actions_toolbar.initialize(self.web_view) self.setCentralWidget(self.web_view) self.loading_overlay = LoadingOverlay(self) self.restore_state() self.actions_toolbar.update_visibility() self.dock_visibility_changed() if continue_reading: self.continue_reading()
def __init__(self, debug_javascript): MainWindow.__init__(self, None) self.setWindowTitle(_("E-book viewer")) self.base_window_title = unicode(self.windowTitle()) self.setObjectName("EbookViewer") self.setWindowIcon(QIcon(I("viewer.png"))) self.setDockOptions(self.AnimatedDocks | self.AllowTabbedDocks) self.centralwidget = c = QWidget(self) c.setObjectName("centralwidget") self.setCentralWidget(c) self.central_layout = cl = QGridLayout(c) cl.setSpacing(0) c.setLayout(cl), cl.setContentsMargins(0, 0, 0, 0) self.view = v = DocumentView(self) v.setMinimumSize(100, 100) self.view.initialize_view(debug_javascript) v.setObjectName("view") cl.addWidget(v) self.vertical_scrollbar = vs = QScrollBar(c) vs.setOrientation(Qt.Vertical), vs.setObjectName("vertical_scrollbar") cl.addWidget(vs, 0, 1, 2, 1) self.horizontal_scrollbar = hs = QScrollBar(c) hs.setOrientation(Qt.Horizontal), hs.setObjectName("horizontal_scrollbar") cl.addWidget(hs, 1, 0, 1, 1) self.tool_bar = tb = ToolBar(self) tb.setObjectName("tool_bar"), tb.setIconSize(QSize(32, 32)) self.addToolBar(Qt.LeftToolBarArea, tb) self.tool_bar2 = tb2 = QToolBar(self) tb2.setObjectName("tool_bar2") self.addToolBar(Qt.TopToolBarArea, tb2) self.tool_bar.setContextMenuPolicy(Qt.DefaultContextMenu) self.tool_bar2.setContextMenuPolicy(Qt.PreventContextMenu) self.pos = DoubleSpinBox() self.pos.setDecimals(1) self.pos.setSuffix("/" + _("Unknown") + " ") self.pos.setMinimum(1.0) self.tool_bar2.addWidget(self.pos) self.tool_bar2.addSeparator() self.reference = Reference() self.tool_bar2.addWidget(self.reference) self.tool_bar2.addSeparator() self.search = SearchBox2(self) self.search.setMinimumContentsLength(20) self.search.initialize("viewer_search_history") self.search.setToolTip(_("Search for text in book")) self.search.setMinimumWidth(200) self.tool_bar2.addWidget(self.search) self.toc_dock = d = QDockWidget(_("Table of Contents"), self) d.setContextMenuPolicy(Qt.CustomContextMenu) self.toc_container = w = QWidget(self) w.l = QVBoxLayout(w) self.toc = TOCView(w) self.toc_search = TOCSearch(self.toc, parent=w) w.l.addWidget(self.toc), w.l.addWidget(self.toc_search), w.l.setContentsMargins(0, 0, 0, 0) d.setObjectName("toc-dock") d.setWidget(w) d.close() # starts out hidden self.addDockWidget(Qt.LeftDockWidgetArea, d) d.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) self.bookmarks_dock = d = QDockWidget(_("Bookmarks"), self) d.setContextMenuPolicy(Qt.CustomContextMenu) self.bookmarks = BookmarkManager(self) d.setObjectName("bookmarks-dock") d.setWidget(self.bookmarks) d.close() # starts out hidden self.addDockWidget(Qt.RightDockWidgetArea, d) d.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) self.footnotes_dock = d = QDockWidget(_("Footnotes"), self) d.visibilityChanged.connect(self.footnote_visibility_changed) d.setContextMenuPolicy(Qt.CustomContextMenu) self.footnotes_view = FootnotesView(self) self.footnotes_view.follow_link.connect(self.view.follow_footnote_link) self.footnotes_view.close_view.connect(d.close) self.view.footnotes.set_footnotes_view(self.footnotes_view) d.setObjectName("footnotes-dock") d.setWidget(self.footnotes_view) d.close() # starts out hidden self.addDockWidget(Qt.BottomDockWidgetArea, d) d.setAllowedAreas( Qt.BottomDockWidgetArea | Qt.TopDockWidgetArea | Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea ) self.create_actions() self.themes_menu.aboutToShow.connect(self.themes_menu_shown, type=Qt.QueuedConnection) self.metadata = Metadata(self.centralwidget) self.history = History(self.action_back, self.action_forward) self.full_screen_label = QLabel( """ <center> <h1>%s</h1> <h3>%s</h3> <h3>%s</h3> <h3>%s</h3> </center> """ % ( _("Full screen mode"), _("Right click to show controls"), _("Tap in the left or right page margin to turn pages"), _("Press Esc to quit"), ), self.centralWidget(), ) self.full_screen_label.setVisible(False) self.full_screen_label.final_height = 200 self.full_screen_label.setFocusPolicy(Qt.NoFocus) self.full_screen_label.setStyleSheet( """ QLabel { text-align: center; background-color: white; color: black; border-width: 1px; border-style: solid; border-radius: 20px; } """ ) self.clock_label = QLabel("99:99", self.centralWidget()) self.clock_label.setVisible(False) self.clock_label.setFocusPolicy(Qt.NoFocus) self.info_label_style = """ QLabel { text-align: center; border-width: 1px; border-style: solid; border-radius: 8px; background-color: %s; color: %s; font-family: monospace; font-size: larger; padding: 5px; }""" self.pos_label = QLabel("2000/4000", self.centralWidget()) self.pos_label.setVisible(False) self.pos_label.setFocusPolicy(Qt.NoFocus) self.resize(653, 746)