def show_splash_screen(self): self.splash_pixmap = QPixmap() self.splash_pixmap.load(I("library.png")) self.splash_screen = QSplashScreen(self.splash_pixmap) self.splash_screen.showMessage(_("Starting %s: Loading books...") % __appname__) self.splash_screen.show() QApplication.instance().processEvents()
def __init__(self, view): QObject.__init__(self, view) self.state = State() self.state.swiped.connect(self.handle_swipe) self.evmap = {QEvent.TouchBegin: 'start', QEvent.TouchUpdate: 'update', QEvent.TouchEnd: 'end'} # Ignore fake mouse events generated by the window system from touch # events. At least on windows, we know how to identify these fake # events. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx self.is_fake_mouse_event = lambda : False if touch_supported and iswindows: MI_WP_SIGNATURE = 0xFF515700 SIGNATURE_MASK = 0xFFFFFF00 try: f = ctypes.windll.user32.GetMessageExtraInfo f.restype = wintypes.LPARAM def is_fake_mouse_event(): val = f() ans = (val & SIGNATURE_MASK) == MI_WP_SIGNATURE return ans self.is_fake_mouse_event = is_fake_mouse_event QApplication.instance().focusChanged.connect(self.register_for_wm_touch) except Exception: import traceback traceback.print_exc()
def show_splash_screen(self): self.splash_pixmap = QPixmap() self.splash_pixmap.load(I('library.png')) self.splash_screen = QSplashScreen(self.splash_pixmap) self.splash_screen.showMessage( _('Starting %s: Loading books...') % __appname__) self.splash_screen.show() QApplication.instance().processEvents()
def run_wizard(self, *args): if self.confirm_quit(): self.run_wizard_b4_shutdown = True self.restart_after_quit = True try: self.shutdown(write_settings=False) except: pass QApplication.instance().quit()
def quit(self, checked=True, restart=False, debug_on_restart=False, confirm_quit=True): if confirm_quit and not self.confirm_quit(): return try: self.shutdown() except: pass self.restart_after_quit = restart self.debug_on_restart = debug_on_restart QApplication.instance().quit()
def __init__(self, view): QObject.__init__(self, view) self.state = State() self.last_swipe_hold_update = None self.state.swiped.connect(self.handle_swipe) self.state.tapped.connect(self.handle_tap) self.state.swiping.connect(self.handle_swiping) self.state.tap_hold_started.connect( partial(self.handle_tap_hold, 'start')) self.state.tap_hold_updated.connect( partial(self.handle_tap_hold, 'update')) self.state.tap_hold_finished.connect( partial(self.handle_tap_hold, 'end')) self.state.swipe_hold_started.connect( partial(self.handle_swipe_hold, 'start')) self.state.swipe_hold_updated.connect( partial(self.handle_swipe_hold, 'update')) self.state.swipe_hold_finished.connect( partial(self.handle_swipe_hold, 'end')) self.state.pinched.connect(self.handle_pinch) self.evmap = { QEvent.TouchBegin: 'start', QEvent.TouchUpdate: 'update', QEvent.TouchEnd: 'end' } # Ignore fake mouse events generated by the window system from touch # events. At least on windows, we know how to identify these fake # events. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx self.is_fake_mouse_event = lambda: False if touch_supported and iswindows: MI_WP_SIGNATURE = 0xFF515700 SIGNATURE_MASK = 0xFFFFFF00 try: f = ctypes.windll.user32.GetMessageExtraInfo f.restype = wintypes.LPARAM def is_fake_mouse_event(): val = f() ans = (val & SIGNATURE_MASK) == MI_WP_SIGNATURE return ans self.is_fake_mouse_event = is_fake_mouse_event QApplication.instance().focusChanged.connect( self.register_for_wm_touch) except Exception: import traceback traceback.print_exc()
def __init__(self, parent, current_img, current_url): QDialog.__init__(self) dw = QApplication.instance().desktop() self.avail_geom = dw.availableGeometry(parent) self.current_img = current_img self.current_url = current_url self.factor = 1.0 self.label = l = QLabel() l.setBackgroundRole(QPalette.Base); l.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) l.setScaledContents(True) self.scrollarea = sa = QScrollArea() sa.setBackgroundRole(QPalette.Dark) sa.setWidget(l) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.zi_button = zi = bb.addButton(_('Zoom &in'), bb.ActionRole) self.zo_button = zo = bb.addButton(_('Zoom &out'), bb.ActionRole) self.save_button = so = bb.addButton(_('&Save as'), bb.ActionRole) zi.setIcon(QIcon(I('plus.png'))) zo.setIcon(QIcon(I('minus.png'))) so.setIcon(QIcon(I('save.png'))) zi.clicked.connect(self.zoom_in) zo.clicked.connect(self.zoom_out) so.clicked.connect(self.save_image) self.l = l = QVBoxLayout() self.setLayout(l) l.addWidget(sa) l.addWidget(bb)
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 set_dimensions(self): width = self.original_width = gprefs['cover_grid_width'] height = self.original_height = gprefs['cover_grid_height'] self.original_show_title = show_title = gprefs['cover_grid_show_title'] if height < 0.1: height = max(185, QApplication.instance().desktop().availableGeometry(self.parent()).height() / 5.0) else: height *= self.parent().logicalDpiY() * CM_TO_INCH if width < 0.1: width = 0.75 * height else: width *= self.parent().logicalDpiX() * CM_TO_INCH self.cover_size = QSize(width, height) self.title_height = 0 if show_title: f = self.parent().font() sz = f.pixelSize() if sz < 5: sz = f.pointSize() * self.parent().logicalDpiY() / 72.0 self.title_height = max(25, sz + 10) self.item_size = self.cover_size + QSize(2 * self.MARGIN, (2 * self.MARGIN) + self.title_height) self.calculate_spacing() self.animation.setStartValue(1.0) self.animation.setKeyValueAt(0.5, 0.5) self.animation.setEndValue(1.0)
def default_theme(): global _default_theme if _default_theme is None: isdark = QApplication.instance().palette().color( QPalette.WindowText).lightness() > 128 _default_theme = 'wombat-dark' if isdark else 'pyte-light' return _default_theme
def paste(self, *args): app = QApplication.instance() c = app.clipboard() txt = unicode(c.text()).strip() if txt: old = unicode(self.isbn_box.toPlainText()).strip() new = old + '\n' + txt self.isbn_box.setPlainText(new)
def paste_from_clipboard(self): cb = QApplication.instance().clipboard() pmap = cb.pixmap() if pmap.isNull() and cb.supportsSelection(): pmap = cb.pixmap(cb.Selection) if not pmap.isNull(): self.set_pixmap(pmap) self.cover_changed.emit(pixmap_to_data(pmap))
def contextMenuEvent(self, ev): cm = QMenu(self) paste = cm.addAction(_("Paste Cover")) copy = cm.addAction(_("Copy Cover")) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) cm.exec_(ev.globalPos())
def __init__(self, parent=None): QWebView.__init__(self, parent) self.inspector = QWebInspector(self) w = QApplication.instance().desktop().availableGeometry(self).width() self._size_hint = QSize(int(w/3), int(w/2)) self._page = WebPage(self) self.setPage(self._page) self.inspector.setPage(self._page) self.clear()
def contextMenuEvent(self, ev): cm = QMenu(self) paste = cm.addAction(_('Paste Cover')) copy = cm.addAction(_('Copy Cover')) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) cm.exec_(ev.globalPos())
def build_context_menu(self): cm = QMenu(self) paste = cm.addAction(_('Paste Cover')) copy = cm.addAction(_('Copy Cover')) if not QApplication.instance().clipboard().mimeData().hasImage(): paste.setEnabled(False) copy.triggered.connect(self.copy_to_clipboard) paste.triggered.connect(self.paste_from_clipboard) return cm
def data(self, index, role=Qt.DisplayRole): if role == Qt.DisplayRole: return QVariant(self.label_for_row(index.row())) if role == Qt.FontRole and index.row() == self.pos: f = QApplication.instance().font() f.setBold(True) return QVariant(f) if role == Qt.UserRole: return QVariant(self.states[index.row()]) return NONE
def must_use_qt(): global gui_thread, _store_app if (islinux or isbsd) and ":" not in os.environ.get("DISPLAY", ""): raise RuntimeError("X server required. If you are running on a" " headless machine, use xvfb") if _store_app is None and QApplication.instance() is None: _store_app = QApplication([]) if gui_thread is None: gui_thread = QThread.currentThread() if gui_thread is not QThread.currentThread(): raise RuntimeError("Cannot use Qt in non GUI thread")
def must_use_qt(): global gui_thread, _store_app if (islinux or isbsd) and ':' not in os.environ.get('DISPLAY', ''): raise RuntimeError('X server required. If you are running on a' ' headless machine, use xvfb') if _store_app is None and QApplication.instance() is None: _store_app = QApplication([]) if gui_thread is None: gui_thread = QThread.currentThread() if gui_thread is not QThread.currentThread(): raise RuntimeError('Cannot use Qt in non GUI thread')
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.spell_check = SpellCheck(parent=self) self.toc_view = TOCViewer(self) self.saved_searches = SavedSearches(self) self.image_browser = InsertImage(self, for_browsing=True) self.insert_char = CharSelect(self) self.manage_fonts = ManageFonts(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 paste_from_clipboard(self, pmap=None): if not isinstance(pmap, QPixmap): cb = QApplication.instance().clipboard() pmap = cb.pixmap() if pmap.isNull() and cb.supportsSelection(): pmap = cb.pixmap(cb.Selection) if not pmap.isNull(): self.pixmap = pmap self.do_layout() self.update() self.update_tooltip(getattr(self.parent(), "current_path", "")) if not config["disable_animations"]: self.animation.start() id_ = self.data.get("id", None) if id_ is not None: self.cover_changed.emit(id_, pixmap_to_data(pmap))
def paste_from_clipboard(self, pmap=None): if not isinstance(pmap, QPixmap): cb = QApplication.instance().clipboard() pmap = cb.pixmap() if pmap.isNull() and cb.supportsSelection(): pmap = cb.pixmap(cb.Selection) if not pmap.isNull(): self.pixmap = pmap self.do_layout() self.update() self.update_tooltip(getattr(self.parent(), 'current_path', '')) if not config['disable_animations']: self.animation.start() id_ = self.data.get('id', None) if id_ is not None: self.cover_changed.emit(id_, pixmap_to_data(pmap))
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.spell_check = SpellCheck(parent=self) self.toc_view = TOCViewer(self) self.saved_searches = SavedSearches(self) self.image_browser = InsertImage(self, for_browsing=True) self.insert_char = CharSelect(self) self.manage_fonts = ManageFonts(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, 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, parent, current_img, current_url, geom_name='viewer_image_popup_geometry'): QDialog.__init__(self) dw = QApplication.instance().desktop() self.avail_geom = dw.availableGeometry(parent) self.current_img = current_img self.current_url = current_url self.factor = 1.0 self.geom_name = geom_name self.label = l = QLabel() l.setBackgroundRole(QPalette.Base) l.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored) l.setScaledContents(True) self.scrollarea = sa = QScrollArea() sa.setBackgroundRole(QPalette.Dark) sa.setWidget(l) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.zi_button = zi = bb.addButton(_('Zoom &in'), bb.ActionRole) self.zo_button = zo = bb.addButton(_('Zoom &out'), bb.ActionRole) self.save_button = so = bb.addButton(_('&Save as'), bb.ActionRole) self.rotate_button = ro = bb.addButton(_('&Rotate'), bb.ActionRole) zi.setIcon(QIcon(I('plus.png'))) zo.setIcon(QIcon(I('minus.png'))) so.setIcon(QIcon(I('save.png'))) ro.setIcon(QIcon(I('rotate-right.png'))) zi.clicked.connect(self.zoom_in) zo.clicked.connect(self.zoom_out) so.clicked.connect(self.save_image) ro.clicked.connect(self.rotate_image) self.l = l = QVBoxLayout() self.setLayout(l) l.addWidget(sa) l.addWidget(bb)
def __init__(self, parent, font_magnification_step): QDialog.__init__(self, parent) self.font_magnification_step = font_magnification_step dw = QApplication.instance().desktop() self.avail_geom = dw.availableGeometry(parent) self.view = QWebView(self) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.zi_button = zi = bb.addButton(_('Zoom &in'), bb.ActionRole) self.zo_button = zo = bb.addButton(_('Zoom &out'), bb.ActionRole) zi.setIcon(QIcon(I('plus.png'))) zo.setIcon(QIcon(I('minus.png'))) zi.clicked.connect(self.zoom_in) zo.clicked.connect(self.zoom_out) self.l = l = QVBoxLayout() self.setLayout(l) l.addWidget(self.view) l.addWidget(bb)
def __init__(self, parent=None): QWebView.__init__(self, parent) self.inspector = QWebInspector(self) w = QApplication.instance().desktop().availableGeometry(self).width() self._size_hint = QSize(int(w/3), int(w/2)) settings = self.page().settings() apply_settings(settings, config().parse()) settings.setMaximumPagesInCache(0) settings.setAttribute(settings.JavaEnabled, False) settings.setAttribute(settings.PluginsEnabled, False) settings.setAttribute(settings.PrivateBrowsingEnabled, True) settings.setAttribute(settings.JavascriptCanOpenWindows, False) settings.setAttribute(settings.JavascriptCanAccessClipboard, False) settings.setAttribute(settings.LinksIncludedInFocusChain, False) settings.setAttribute(settings.DeveloperExtrasEnabled, True) settings.setDefaultTextEncoding('utf-8') self.page().setNetworkAccessManager(NetworkAccessManager(self)) self.page().setLinkDelegationPolicy(self.page().DelegateAllLinks) self.clear()
def contextMenuEvent(self, event): popup_menu = self.createStandardContextMenu() pal = QApplication.instance().palette() # This fixes Issue 20 menu_style = """ * { background-color: %s; color: %s;} """ % ( unicode(pal.color(QPalette.Button).name()), unicode(pal.color(QPalette.WindowText).name())) popup_menu.setStyleSheet(menu_style) # Select the word under the cursor. cursor = self.textCursor() cursor.select(QTextCursor.WordUnderCursor) self.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. if enchant and self.dict: if self.textCursor().hasSelection(): text = unicode(self.textCursor().selectedText()) if not self.dict.check(text): spell_menu = QMenu( QtCore.QCoreApplication.translate( 'app', 'Spelling Suggestions'), self) spell_menu.setStyleSheet(menu_style) for word in self.dict.suggest(text): action = SpellAction(word, spell_menu) action.correct.connect(self.correctWord) spell_menu.addAction(action) # Only add the spelling suggests to the menu if there are # suggestions. if len(spell_menu.actions()) != 0: popup_menu.insertSeparator(popup_menu.actions()[0]) popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) # FIXME: add change dict and disable spellcheck options popup_menu.exec_(event.globalPos())
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.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 contextMenuEvent(self, event): popup_menu = self.createStandardContextMenu() pal=QApplication.instance().palette() # This fixes Issue 20 menu_style=""" * { background-color: %s; color: %s;} """%(unicode(pal.color(QPalette.Button).name()), unicode(pal.color(QPalette.WindowText).name())) popup_menu.setStyleSheet(menu_style) # Select the word under the cursor. cursor = self.textCursor() cursor.select(QTextCursor.WordUnderCursor) self.setTextCursor(cursor) # Check if the selected word is misspelled and offer spelling # suggestions if it is. if enchant and self.dict: if self.textCursor().hasSelection(): text = unicode(self.textCursor().selectedText()) if not self.dict.check(text): spell_menu = QMenu(QtCore.QCoreApplication.translate('app','Spelling Suggestions'), self) spell_menu.setStyleSheet(menu_style) for word in self.dict.suggest(text): action = SpellAction(word, spell_menu) action.correct.connect(self.correctWord) spell_menu.addAction(action) # Only add the spelling suggests to the menu if there are # suggestions. if len(spell_menu.actions()) != 0: popup_menu.insertSeparator(popup_menu.actions()[0]) popup_menu.insertMenu(popup_menu.actions()[0], spell_menu) # FIXME: add change dict and disable spellcheck options popup_menu.exec_(event.globalPos())
def icon_to_clipboard(self): app = QApplication.instance() c = app.clipboard() c.setText(unicode(self.icon_files.currentText()))
def auto_height(widget): return max( 185, QApplication.instance().desktop().availableGeometry(widget).height() / 5.0)
def color_to_clipboard(self): app = QApplication.instance() c = app.clipboard() c.setText(unicode(self.color_name.color))
def sizeHint(self): geom = QApplication.instance().desktop().availableGeometry(self) return QSize(int(0.9 * geom.width()), int(0.8 * geom.height()))
def copy_to_clipboard(self): QApplication.instance().clipboard().setPixmap(self.pixmap)
def auto_height(widget): return max(185, QApplication.instance().desktop().availableGeometry(widget).height() / 5.0)
def load_ebook(self, pathtoebook, open_at=None): if self.iterator is not None: self.save_current_position() self.iterator.__exit__() self.iterator = EbookIterator(pathtoebook) self.open_progress_indicator(_('Loading ebook...')) worker = Worker(target=partial(self.iterator.__enter__, extract_embedded_fonts_for_qt=True)) worker.start() while worker.isAlive(): worker.join(0.1) QApplication.processEvents() if worker.exception is not None: if isinstance(worker.exception, DRMError): from calibre.gui2.dialogs.drm_error import DRMErrorMessage DRMErrorMessage(self).exec_() else: r = getattr(worker.exception, 'reason', worker.exception) error_dialog(self, _('Could not open ebook'), as_unicode(r) or _('Unknown error'), det_msg=worker.traceback, show=True) self.close_progress_indicator() else: self.metadata.show_opf(self.iterator.opf, self.iterator.book_format) self.view.current_language = self.iterator.language title = self.iterator.opf.title if not title: title = os.path.splitext(os.path.basename(pathtoebook))[0] if self.iterator.toc: self.toc_model = TOC(self.iterator.spine, self.iterator.toc) self.toc.setModel(self.toc_model) if self.show_toc_on_open: self.action_table_of_contents.setChecked(True) else: self.toc_model = TOC(self.iterator.spine) self.toc.setModel(self.toc_model) self.action_table_of_contents.setChecked(False) if isbytestring(pathtoebook): pathtoebook = force_unicode(pathtoebook, filesystem_encoding) vh = vprefs.get('viewer_open_history', []) try: vh.remove(pathtoebook) except: pass vh.insert(0, pathtoebook) vprefs.set('viewer_open_history', vh[:50]) self.build_recent_menu() self.action_table_of_contents.setDisabled(not self.iterator.toc) self.current_book_has_toc = bool(self.iterator.toc) self.current_title = title self.setWindowTitle(self.base_window_title+' - '+title + ' [%s]'%self.iterator.book_format) self.pos.setMaximum(sum(self.iterator.pages)) self.pos.setSuffix(' / %d'%sum(self.iterator.pages)) self.vertical_scrollbar.setMinimum(100) self.vertical_scrollbar.setMaximum(100*sum(self.iterator.pages)) self.vertical_scrollbar.setSingleStep(10) self.vertical_scrollbar.setPageStep(100) self.set_vscrollbar_value(1) self.current_index = -1 QApplication.instance().alert(self, 5000) previous = self.set_bookmarks(self.iterator.bookmarks) if open_at is None and previous is not None: self.goto_bookmark(previous) else: if open_at is None: self.next_document() else: if open_at > self.pos.maximum(): open_at = self.pos.maximum() if open_at < self.pos.minimum(): open_at = self.pos.minimum() self.goto_page(open_at, loaded_check=False)
class ShortcutConfig(QWidget): def __init__(self, model, parent=None): QWidget.__init__(self, parent) self._layout = QHBoxLayout() self.setLayout(self._layout) self.view = QListView(self) self._layout.addWidget(self.view) self.view.setModel(model) self.delegate = Delegate() self.view.setItemDelegate(self.delegate) self.delegate.sizeHintChanged.connect(self.scrollTo, type=Qt.QueuedConnection) def scrollTo(self, index): self.view.scrollTo(index, self.view.EnsureVisible) @property def is_editing(self): return self.view.state() == self.view.EditingState if __name__ == '__main__': from calibre.gui2 import is_ok_to_use_qt from calibre.gui2.viewer.keys import SHORTCUTS is_ok_to_use_qt() model = Shortcuts(SHORTCUTS, 'shortcuts/viewer') conf = ShortcutConfig(model) conf.resize(400, 500) conf.show() QApplication.instance().exec_()
def __init__(self, ids, get_metadata, field_metadata, parent=None, window_title=None, reject_button_tooltip=None, accept_all_tooltip=None, reject_all_tooltip=None, revert_tooltip=None, intro_msg=None, action_button=None, **kwargs): QDialog.__init__(self, parent) self.l = l = QVBoxLayout() self.setLayout(l) self.setWindowIcon(QIcon(I('auto_author_sort.png'))) self.get_metadata = get_metadata self.ids = list(ids) self.total = len(self.ids) self.accepted = OrderedDict() self.window_title = window_title or _('Compare metadata') if intro_msg: self.la = la = QLabel(intro_msg) la.setWordWrap(True) l.addWidget(la) self.compare_widget = CompareSingle(field_metadata, parent=parent, revert_tooltip=revert_tooltip, **kwargs) self.sa = sa = QScrollArea() l.addWidget(sa) sa.setWidget(self.compare_widget) sa.setWidgetResizable(True) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Cancel) bb.rejected.connect(self.reject) if self.total > 1: self.aarb = b = bb.addButton(_('&Accept all remaining'), bb.YesRole) b.setIcon(QIcon(I('ok.png'))) if accept_all_tooltip: b.setToolTip(accept_all_tooltip) b.clicked.connect(self.accept_all_remaining) self.rarb = b = bb.addButton(_('Re&ject all remaining'), bb.NoRole) b.setIcon(QIcon(I('minus.png'))) if reject_all_tooltip: b.setToolTip(reject_all_tooltip) b.clicked.connect(self.reject_all_remaining) self.sb = b = bb.addButton(_('&Reject'), bb.ActionRole) b.clicked.connect(partial(self.next_item, False)) b.setIcon(QIcon(I('minus.png'))) if reject_button_tooltip: b.setToolTip(reject_button_tooltip) if action_button is not None: self.acb = b = bb.addButton(action_button[0], bb.ActionRole) b.setIcon(QIcon(action_button[1])) self.action_button_action = action_button[2] b.clicked.connect(self.action_button_clicked) self.nb = b = bb.addButton( _('&Next') if self.total > 1 else _('&OK'), bb.ActionRole) b.setIcon(QIcon(I('forward.png' if self.total > 1 else 'ok.png'))) b.clicked.connect(partial(self.next_item, True)) b.setDefault(True) l.addWidget(bb) self.next_item(True) desktop = QApplication.instance().desktop() geom = desktop.availableGeometry(parent or self) width = max(700, min(950, geom.width() - 50)) height = max(650, min(1000, geom.height() - 100)) self.resize(QSize(width, height)) geom = gprefs.get('diff_dialog_geom', None) if geom is not None: self.restoreGeometry(geom) b.setFocus(Qt.OtherFocusReason)
def sizeHint(self): g = QApplication.instance().desktop().availableGeometry(self.parent() or self) return QSize(min(1500, g.width() - 25), 650)
def default_theme(): global _default_theme if _default_theme is None: isdark = QApplication.instance().palette().color(QPalette.WindowText).lightness() > 128 _default_theme = 'wombat-dark' if isdark else 'pyte-light' return _default_theme
def check_terminal_save(self): if self.save_manager.has_tasks: return QTimer.singleShot(50, self.check_terminal_save) self.shutdown() QApplication.instance().quit()
def copy_to_clipboard(self): QApplication.instance().clipboard().setPixmap(self.get_pixmap())
def quit(self): if not self.confirm_quit(): return self.save_state() QApplication.instance().quit()
def quit(self): if self.shutdown(): QApplication.instance().quit()