mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More stupid PyQt enums
This commit is contained in:
parent
dc10461cba
commit
235b22bb69
@ -18,7 +18,7 @@ from PyQt5.Qt import (
|
|||||||
QDesktopServices, QDialog, QEvent, QFileDialog, QFileIconProvider, QFileInfo, QPalette,
|
QDesktopServices, QDialog, QEvent, QFileDialog, QFileIconProvider, QFileInfo, QPalette,
|
||||||
QFont, QFontDatabase, QFontInfo, QFontMetrics, QIcon, QLocale, QColor,
|
QFont, QFontDatabase, QFontInfo, QFontMetrics, QIcon, QLocale, QColor,
|
||||||
QNetworkProxyFactory, QObject, QSettings, QSocketNotifier, QStringListModel, Qt,
|
QNetworkProxyFactory, QObject, QSettings, QSocketNotifier, QStringListModel, Qt,
|
||||||
QThread, QTimer, QTranslator, QUrl, pyqtSignal
|
QThread, QTimer, QTranslator, QUrl, pyqtSignal, QIODevice
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import QStyle # Gives a nicer error message than import from Qt
|
from PyQt5.QtWidgets import QStyle # Gives a nicer error message than import from Qt
|
||||||
|
|
||||||
@ -709,7 +709,7 @@ def pixmap_to_data(pixmap, format='JPEG', quality=None):
|
|||||||
quality = 90
|
quality = 90
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
pixmap.save(buf, format, quality=quality)
|
pixmap.save(buf, format, quality=quality)
|
||||||
return ba.data()
|
return ba.data()
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import sys, array, re, os, errno
|
|||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
|
|
||||||
from PyQt5.Qt import QSize, QImage, Qt, QKeySequence, QBuffer, QByteArray
|
from PyQt5.Qt import QSize, QImage, Qt, QKeySequence, QBuffer, QByteArray, QIODevice
|
||||||
|
|
||||||
from polyglot.builtins import unicode_type, iteritems
|
from polyglot.builtins import unicode_type, iteritems
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ def icon_to_dbus_menu_icon(icon, size=32):
|
|||||||
return None
|
return None
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
icon.pixmap(32).save(buf, 'PNG')
|
icon.pixmap(32).save(buf, 'PNG')
|
||||||
return dbus.ByteArray(ba)
|
return dbus.ByteArray(ba)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from PyQt5.Qt import (
|
|||||||
QItemSelectionModel, QListView, QMimeData, QModelIndex, QPainter, QPixmap,
|
QItemSelectionModel, QListView, QMimeData, QModelIndex, QPainter, QPixmap,
|
||||||
QPoint, QPropertyAnimation, QRect, QSize, QStyledItemDelegate,
|
QPoint, QPropertyAnimation, QRect, QSize, QStyledItemDelegate,
|
||||||
QStyleOptionViewItem, Qt, QTableView, QTimer, QToolTip, QTreeView, QUrl,
|
QStyleOptionViewItem, Qt, QTableView, QTimer, QToolTip, QTreeView, QUrl,
|
||||||
pyqtProperty, pyqtSignal, pyqtSlot, qBlue, qGreen, qRed
|
pyqtProperty, pyqtSignal, pyqtSlot, qBlue, qGreen, qRed, QIODevice
|
||||||
)
|
)
|
||||||
from textwrap import wrap
|
from textwrap import wrap
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
@ -77,7 +77,7 @@ def handle_enter_press(self, ev, special_action=None, has_edit_cell=True):
|
|||||||
def image_to_data(image): # {{{
|
def image_to_data(image): # {{{
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
if not image.save(buf, CACHE_FORMAT):
|
if not image.save(buf, CACHE_FORMAT):
|
||||||
raise EncodeError('Failed to encode thumbnail')
|
raise EncodeError('Failed to encode thumbnail')
|
||||||
ret = ba.data()
|
ret = ba.data()
|
||||||
|
@ -12,7 +12,7 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, QFont, QModelIndex,
|
QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, QFont, QModelIndex,
|
||||||
QIcon, QItemSelection, QMimeData, QDrag, QStyle, QPoint, QUrl, QHeaderView,
|
QIcon, QItemSelection, QMimeData, QDrag, QStyle, QPoint, QUrl, QHeaderView, QEvent,
|
||||||
QStyleOptionHeader, QItemSelectionModel, QSize, QFontMetrics, QApplication)
|
QStyleOptionHeader, QItemSelectionModel, QSize, QFontMetrics, QApplication)
|
||||||
|
|
||||||
from calibre.constants import islinux
|
from calibre.constants import islinux
|
||||||
@ -213,7 +213,7 @@ class BooksView(QTableView): # {{{
|
|||||||
is_library_view = True
|
is_library_view = True
|
||||||
|
|
||||||
def viewportEvent(self, event):
|
def viewportEvent(self, event):
|
||||||
if (event.type() == event.ToolTip and not gprefs['book_list_tooltips']):
|
if (event.type() == QEvent.Type.ToolTip and not gprefs['book_list_tooltips']):
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
ret = self.gesture_manager.handle_event(event)
|
ret = self.gesture_manager.handle_event(event)
|
||||||
|
@ -12,7 +12,7 @@ from functools import partial
|
|||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QAction, QBuffer, QByteArray, QIcon, QInputDialog, QKeySequence, QLabel,
|
QAction, QBuffer, QByteArray, QIcon, QInputDialog, QKeySequence, QLabel,
|
||||||
QListWidget, QListWidgetItem, QPixmap, QSize, QStackedLayout, Qt, QVBoxLayout,
|
QListWidget, QListWidgetItem, QPixmap, QSize, QStackedLayout, Qt, QVBoxLayout,
|
||||||
QWidget, pyqtSignal
|
QWidget, pyqtSignal, QIODevice
|
||||||
)
|
)
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ ENTRY_ROLE = Qt.ItemDataRole.UserRole
|
|||||||
def pixmap_to_data(pixmap):
|
def pixmap_to_data(pixmap):
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
pixmap.save(buf, 'PNG')
|
pixmap.save(buf, 'PNG')
|
||||||
return bytearray(ba.data())
|
return bytearray(ba.data())
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from PyQt5.Qt import (
|
|||||||
QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel,
|
QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel,
|
||||||
QModelIndex, QStyledItemDelegate, QStyle, QCheckBox, QListView,
|
QModelIndex, QStyledItemDelegate, QStyle, QCheckBox, QListView,
|
||||||
QTextDocument, QSize, QComboBox, QFrame, QCursor, QGroupBox, QSplitter,
|
QTextDocument, QSize, QComboBox, QFrame, QCursor, QGroupBox, QSplitter,
|
||||||
QPixmap, QRect, QPlainTextEdit, QMimeData, QDialog)
|
QPixmap, QRect, QPlainTextEdit, QMimeData, QDialog, QEvent)
|
||||||
|
|
||||||
from calibre import prepare_string_for_xml, human_readable
|
from calibre import prepare_string_for_xml, human_readable
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
@ -1236,7 +1236,7 @@ class PlainTextEdit(QPlainTextEdit): # {{{
|
|||||||
|
|
||||||
def event(self, ev):
|
def event(self, ev):
|
||||||
et = ev.type()
|
et = ev.type()
|
||||||
if et == ev.ToolTip:
|
if et == QEvent.Type.ToolTip:
|
||||||
self.show_tooltip(ev)
|
self.show_tooltip(ev)
|
||||||
return True
|
return True
|
||||||
if et == ev.ShortcutOverride:
|
if et == ev.ShortcutOverride:
|
||||||
|
@ -9,7 +9,7 @@ from functools import partial
|
|||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QApplication, QFont, QHBoxLayout, QIcon, QMenu, QModelIndex, QStandardItem,
|
QApplication, QFont, QHBoxLayout, QIcon, QMenu, QModelIndex, QStandardItem,
|
||||||
QStandardItemModel, QStyledItemDelegate, Qt, QToolButton, QToolTip, QTreeView,
|
QStandardItemModel, QStyledItemDelegate, Qt, QToolButton, QToolTip, QTreeView,
|
||||||
QWidget, pyqtSignal
|
QWidget, pyqtSignal, QEvent
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
@ -23,7 +23,7 @@ class Delegate(QStyledItemDelegate):
|
|||||||
# Show a tooltip only if the item is truncated
|
# Show a tooltip only if the item is truncated
|
||||||
if not ev or not view:
|
if not ev or not view:
|
||||||
return False
|
return False
|
||||||
if ev.type() == ev.ToolTip:
|
if ev.type() == QEvent.Type.ToolTip:
|
||||||
rect = view.visualRect(index)
|
rect = view.visualRect(index)
|
||||||
size = self.sizeHint(option, index)
|
size = self.sizeHint(option, index)
|
||||||
if rect.width() < size.width():
|
if rect.width() < size.width():
|
||||||
|
@ -9,7 +9,7 @@ import sys
|
|||||||
from itertools import count
|
from itertools import count
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QT_VERSION, QApplication, QBuffer, QByteArray, QFontDatabase, QFontInfo,
|
QT_VERSION, QApplication, QBuffer, QByteArray, QFontDatabase, QFontInfo,
|
||||||
QHBoxLayout, QMimeData, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal
|
QHBoxLayout, QMimeData, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal, QIODevice
|
||||||
)
|
)
|
||||||
from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
|
from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
|
||||||
from PyQt5.QtWebEngineWidgets import (
|
from PyQt5.QtWebEngineWidgets import (
|
||||||
@ -100,7 +100,7 @@ def send_reply(rq, mime_type, data):
|
|||||||
# make the buf a child of rq so that it is automatically deleted when
|
# make the buf a child of rq so that it is automatically deleted when
|
||||||
# rq is deleted
|
# rq is deleted
|
||||||
buf = QBuffer(parent=rq)
|
buf = QBuffer(parent=rq)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
# we have to copy data into buf as it will be garbage
|
# we have to copy data into buf as it will be garbage
|
||||||
# collected by python
|
# collected by python
|
||||||
buf.write(data)
|
buf.write(data)
|
||||||
|
@ -13,7 +13,7 @@ from io import BytesIO
|
|||||||
# We use explicit module imports so tracebacks when importing are more useful
|
# We use explicit module imports so tracebacks when importing are more useful
|
||||||
from PyQt5.QtCore import QBuffer, QByteArray, Qt
|
from PyQt5.QtCore import QBuffer, QByteArray, Qt
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QColor, QImage, QImageReader, QImageWriter, QPixmap, QTransform
|
QColor, QImage, QImageReader, QImageWriter, QPixmap, QTransform, QIODevice
|
||||||
)
|
)
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ def image_and_format_from_data(data):
|
|||||||
' Create an image object from the specified data which should be a bytestring and also return the format of the image '
|
' Create an image object from the specified data which should be a bytestring and also return the format of the image '
|
||||||
ba = QByteArray(data)
|
ba = QByteArray(data)
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.ReadOnly)
|
buf.open(QIODevice.OpenModeFlag.ReadOnly)
|
||||||
r = QImageReader(buf)
|
r = QImageReader(buf)
|
||||||
fmt = bytes(r.format()).decode('utf-8')
|
fmt = bytes(r.format()).decode('utf-8')
|
||||||
return r.read(), fmt
|
return r.read(), fmt
|
||||||
@ -172,7 +172,7 @@ def image_to_data(img, compression_quality=95, fmt='JPEG', png_compression_level
|
|||||||
fmt = fmt.upper()
|
fmt = fmt.upper()
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
if fmt == 'GIF':
|
if fmt == 'GIF':
|
||||||
w = QImageWriter(buf, b'PNG')
|
w = QImageWriter(buf, b'PNG')
|
||||||
w.setQuality(90)
|
w.setQuality(90)
|
||||||
@ -609,7 +609,7 @@ def encode_jpeg(file_path, quality=80):
|
|||||||
raise ValueError('%s is not a valid image file' % file_path)
|
raise ValueError('%s is not a valid image file' % file_path)
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
if not img.save(buf, 'PPM'):
|
if not img.save(buf, 'PPM'):
|
||||||
raise ValueError('Failed to export image to PPM')
|
raise ValueError('Failed to export image to PPM')
|
||||||
return run_optimizer(file_path, cmd, as_filter=True, input_data=ReadOnlyFileBuffer(ba.data()))
|
return run_optimizer(file_path, cmd, as_filter=True, input_data=ReadOnlyFileBuffer(ba.data()))
|
||||||
|
@ -7,7 +7,7 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from PyQt5.Qt import QBuffer, QByteArray, QPixmap, Qt, QtWin
|
from PyQt5.Qt import QBuffer, QByteArray, QPixmap, Qt, QtWin, QIODevice
|
||||||
|
|
||||||
from calibre.gui2 import must_use_qt
|
from calibre.gui2 import must_use_qt
|
||||||
from calibre.utils.winreg.default_programs import split_commandline
|
from calibre.utils.winreg.default_programs import split_commandline
|
||||||
@ -24,7 +24,7 @@ def hicon_to_pixmap(hicon):
|
|||||||
def pixmap_to_data(pixmap):
|
def pixmap_to_data(pixmap):
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
pixmap.save(buf, 'PNG')
|
pixmap.save(buf, 'PNG')
|
||||||
return bytes(bytearray(ba.data()))
|
return bytes(bytearray(ba.data()))
|
||||||
|
|
||||||
|
@ -61,12 +61,12 @@ def create_bmp_from_dib(raw):
|
|||||||
|
|
||||||
|
|
||||||
def to_png(bmp):
|
def to_png(bmp):
|
||||||
from PyQt5.Qt import QImage, QByteArray, QBuffer
|
from PyQt5.Qt import QImage, QByteArray, QBuffer, QIODevice
|
||||||
i = QImage()
|
i = QImage()
|
||||||
if not i.loadFromData(bmp):
|
if not i.loadFromData(bmp):
|
||||||
raise ValueError('Invalid image data')
|
raise ValueError('Invalid image data')
|
||||||
ba = QByteArray()
|
ba = QByteArray()
|
||||||
buf = QBuffer(ba)
|
buf = QBuffer(ba)
|
||||||
buf.open(QBuffer.WriteOnly)
|
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||||
i.save(buf, 'png')
|
i.save(buf, 'png')
|
||||||
return ba.data()
|
return ba.data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user