More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-08 20:01:09 +05:30
parent dc10461cba
commit 235b22bb69
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
11 changed files with 24 additions and 24 deletions

View file

@ -18,7 +18,7 @@
QDesktopServices, QDialog, QEvent, QFileDialog, QFileIconProvider, QFileInfo, QPalette,
QFont, QFontDatabase, QFontInfo, QFontMetrics, QIcon, QLocale, QColor,
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
@ -709,7 +709,7 @@ def pixmap_to_data(pixmap, format='JPEG', quality=None):
quality = 90
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
pixmap.save(buf, format, quality=quality)
return ba.data()

View file

@ -9,7 +9,7 @@
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
@ -127,7 +127,7 @@ def icon_to_dbus_menu_icon(icon, size=32):
return None
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
icon.pixmap(32).save(buf, 'PNG')
return dbus.ByteArray(ba)

View file

@ -16,7 +16,7 @@
QItemSelectionModel, QListView, QMimeData, QModelIndex, QPainter, QPixmap,
QPoint, QPropertyAnimation, QRect, QSize, QStyledItemDelegate,
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 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): # {{{
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
if not image.save(buf, CACHE_FORMAT):
raise EncodeError('Failed to encode thumbnail')
ret = ba.data()

View file

@ -12,7 +12,7 @@
from PyQt5.Qt import (
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)
from calibre.constants import islinux
@ -213,7 +213,7 @@ class BooksView(QTableView): # {{{
is_library_view = True
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
try:
ret = self.gesture_manager.handle_event(event)

View file

@ -12,7 +12,7 @@
from PyQt5.Qt import (
QAction, QBuffer, QByteArray, QIcon, QInputDialog, QKeySequence, QLabel,
QListWidget, QListWidgetItem, QPixmap, QSize, QStackedLayout, Qt, QVBoxLayout,
QWidget, pyqtSignal
QWidget, pyqtSignal, QIODevice
)
from threading import Thread
@ -34,7 +34,7 @@
def pixmap_to_data(pixmap):
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
pixmap.save(buf, 'PNG')
return bytearray(ba.data())

View file

@ -14,7 +14,7 @@
QPainter, QStaticText, pyqtSignal, QTextOption, QAbstractListModel,
QModelIndex, QStyledItemDelegate, QStyle, QCheckBox, QListView,
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.constants import iswindows
@ -1236,7 +1236,7 @@ def windows_ignore_altgr_shortcut(self, ev):
def event(self, ev):
et = ev.type()
if et == ev.ToolTip:
if et == QEvent.Type.ToolTip:
self.show_tooltip(ev)
return True
if et == ev.ShortcutOverride:

View file

@ -9,7 +9,7 @@
from PyQt5.Qt import (
QApplication, QFont, QHBoxLayout, QIcon, QMenu, QModelIndex, QStandardItem,
QStandardItemModel, QStyledItemDelegate, Qt, QToolButton, QToolTip, QTreeView,
QWidget, pyqtSignal
QWidget, pyqtSignal, QEvent
)
from calibre.gui2 import error_dialog
@ -23,7 +23,7 @@ def helpEvent(self, ev, view, option, index):
# Show a tooltip only if the item is truncated
if not ev or not view:
return False
if ev.type() == ev.ToolTip:
if ev.type() == QEvent.Type.ToolTip:
rect = view.visualRect(index)
size = self.sizeHint(option, index)
if rect.width() < size.width():

View file

@ -9,7 +9,7 @@
from itertools import count
from PyQt5.Qt import (
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.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
# rq is deleted
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
# collected by python
buf.write(data)

View file

@ -13,7 +13,7 @@
# We use explicit module imports so tracebacks when importing are more useful
from PyQt5.QtCore import QBuffer, QByteArray, Qt
from PyQt5.QtGui import (
QColor, QImage, QImageReader, QImageWriter, QPixmap, QTransform
QColor, QImage, QImageReader, QImageWriter, QPixmap, QTransform, QIODevice
)
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 '
ba = QByteArray(data)
buf = QBuffer(ba)
buf.open(QBuffer.ReadOnly)
buf.open(QIODevice.OpenModeFlag.ReadOnly)
r = QImageReader(buf)
fmt = bytes(r.format()).decode('utf-8')
return r.read(), fmt
@ -172,7 +172,7 @@ def image_to_data(img, compression_quality=95, fmt='JPEG', png_compression_level
fmt = fmt.upper()
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
if fmt == 'GIF':
w = QImageWriter(buf, b'PNG')
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)
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
if not img.save(buf, 'PPM'):
raise ValueError('Failed to export image to PPM')
return run_optimizer(file_path, cmd, as_filter=True, input_data=ReadOnlyFileBuffer(ba.data()))

View file

@ -7,7 +7,7 @@
import re
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.utils.winreg.default_programs import split_commandline
@ -24,7 +24,7 @@ def hicon_to_pixmap(hicon):
def pixmap_to_data(pixmap):
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
pixmap.save(buf, 'PNG')
return bytes(bytearray(ba.data()))

View file

@ -61,12 +61,12 @@ def create_bmp_from_dib(raw):
def to_png(bmp):
from PyQt5.Qt import QImage, QByteArray, QBuffer
from PyQt5.Qt import QImage, QByteArray, QBuffer, QIODevice
i = QImage()
if not i.loadFromData(bmp):
raise ValueError('Invalid image data')
ba = QByteArray()
buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly)
buf.open(QIODevice.OpenModeFlag.WriteOnly)
i.save(buf, 'png')
return ba.data()