From 88a1c1a618062db0ad49ba3b98d6e47e9e80d5d9 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 9 Nov 2021 01:02:57 +0100 Subject: [PATCH] python 3.10: fix some deprecation warnings and compat with 3.10 --- electrum/daemon.py | 2 +- .../qt/qrreader/qtmultimedia/camera_dialog.py | 4 ++-- .../qt/qrreader/qtmultimedia/video_overlay.py | 2 +- .../qt/qrreader/qtmultimedia/video_surface.py | 2 +- electrum/gui/qt/util.py | 16 ++++++++-------- electrum/plugin.py | 2 +- electrum/sql_db.py | 2 +- electrum/util.py | 4 ++-- electrum/wallet_db.py | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/electrum/daemon.py b/electrum/daemon.py index 6611b20e3..6d3ac7cd5 100644 --- a/electrum/daemon.py +++ b/electrum/daemon.py @@ -607,7 +607,7 @@ class Daemon(Logger): self._stopped_event.set() def run_gui(self, config, plugins): - threading.current_thread().setName('GUI') + threading.current_thread().name = 'GUI' gui_name = config.get('gui', 'qt') if gui_name in ['lite', 'classic']: gui_name = 'qt' diff --git a/electrum/gui/qt/qrreader/qtmultimedia/camera_dialog.py b/electrum/gui/qt/qrreader/qtmultimedia/camera_dialog.py index d5bee7111..ae01cc982 100644 --- a/electrum/gui/qt/qrreader/qtmultimedia/camera_dialog.py +++ b/electrum/gui/qt/qrreader/qtmultimedia/camera_dialog.py @@ -213,8 +213,8 @@ class QrReaderCameraDialog(Logger, MessageBoxMixin, QDialog): """ Returns a QRect that is scan_size x scan_size in the middle of the resolution """ - scan_pos_x = (resolution.width() - scan_size) / 2 - scan_pos_y = (resolution.height() - scan_size) / 2 + scan_pos_x = (resolution.width() - scan_size) // 2 + scan_pos_y = (resolution.height() - scan_size) // 2 return QRect(scan_pos_x, scan_pos_y, scan_size, scan_size) @staticmethod diff --git a/electrum/gui/qt/qrreader/qtmultimedia/video_overlay.py b/electrum/gui/qt/qrreader/qtmultimedia/video_overlay.py index dab3bb0f8..3c361567e 100644 --- a/electrum/gui/qt/qrreader/qtmultimedia/video_overlay.py +++ b/electrum/gui/qt/qrreader/qtmultimedia/video_overlay.py @@ -63,7 +63,7 @@ class QrReaderVideoOverlay(QWidget): self.bg_rect_pen = QPen() self.bg_rect_pen.setColor(Qt.black) self.bg_rect_pen.setStyle(Qt.DotLine) - self.bg_rect_fill = QColor(255, 255, 255, 255 * self.BG_RECT_OPACITY) + self.bg_rect_fill = QColor(255, 255, 255, int(255 * self.BG_RECT_OPACITY)) def set_results(self, results: List[QrCodeResult], flip_x: bool, validator_results: QrReaderValidatorResult): diff --git a/electrum/gui/qt/qrreader/qtmultimedia/video_surface.py b/electrum/gui/qt/qrreader/qtmultimedia/video_surface.py index ca2150038..d325622b4 100644 --- a/electrum/gui/qt/qrreader/qtmultimedia/video_surface.py +++ b/electrum/gui/qt/qrreader/qtmultimedia/video_surface.py @@ -60,7 +60,7 @@ class QrReaderVideoSurface(QAbstractVideoSurface): return False try: - img = QImage(frame.bits(), frame.width(), frame.height(), image_format) + img = QImage(int(frame.bits()), frame.width(), frame.height(), image_format) # Check whether we need to flip the image on any axis surface_format = self.surfaceFormat() diff --git a/electrum/gui/qt/util.py b/electrum/gui/qt/util.py index 03c84dd24..7c8945a59 100644 --- a/electrum/gui/qt/util.py +++ b/electrum/gui/qt/util.py @@ -1175,8 +1175,8 @@ class FixedAspectRatioLayout(QLayout): c_aratio = 1 s_aratio = self.aspect_ratio item_rect = QRect(QPoint(0, 0), QSize( - contents.width() if c_aratio < s_aratio else contents.height() * s_aratio, - contents.height() if c_aratio > s_aratio else contents.width() / s_aratio + contents.width() if c_aratio < s_aratio else int(contents.height() * s_aratio), + contents.height() if c_aratio > s_aratio else int(contents.width() / s_aratio) )) content_margins = self.contentsMargins() @@ -1187,7 +1187,7 @@ class FixedAspectRatioLayout(QLayout): if item.alignment() & Qt.AlignRight: item_rect.moveRight(contents.width() + content_margins.right()) else: - item_rect.moveLeft(content_margins.left() + (free_space.width() / 2)) + item_rect.moveLeft(content_margins.left() + (free_space.width() // 2)) else: item_rect.moveLeft(content_margins.left()) @@ -1195,7 +1195,7 @@ class FixedAspectRatioLayout(QLayout): if item.alignment() & Qt.AlignBottom: item_rect.moveBottom(contents.height() + content_margins.bottom()) else: - item_rect.moveTop(content_margins.top() + (free_space.height() / 2)) + item_rect.moveTop(content_margins.top() + (free_space.height() // 2)) else: item_rect.moveTop(content_margins.top()) @@ -1224,10 +1224,10 @@ def QColorLerp(a: QColor, b: QColor, t: float): t = max(min(t, 1.0), 0.0) i_t = 1.0 - t return QColor( - (a.red() * i_t) + (b.red() * t), - (a.green() * i_t) + (b.green() * t), - (a.blue() * i_t) + (b.blue() * t), - (a.alpha() * i_t) + (b.alpha() * t), + int((a.red() * i_t) + (b.red() * t)), + int((a.green() * i_t) + (b.green() * t)), + int((a.blue() * i_t) + (b.blue() * t)), + int((a.alpha() * i_t) + (b.alpha() * t)), ) diff --git a/electrum/plugin.py b/electrum/plugin.py index e570ce6df..c028af33c 100644 --- a/electrum/plugin.py +++ b/electrum/plugin.py @@ -60,7 +60,7 @@ class Plugins(DaemonThread): @profiler def __init__(self, config: SimpleConfig, gui_name): DaemonThread.__init__(self) - self.setName('Plugins') + self.name = 'Plugins' # set name of thread self.pkgpath = os.path.dirname(plugins.__file__) self.config = config self.hw_wallets = {} diff --git a/electrum/sql_db.py b/electrum/sql_db.py index d7315b561..a6459fc06 100644 --- a/electrum/sql_db.py +++ b/electrum/sql_db.py @@ -14,7 +14,7 @@ def sql(func): returns an awaitable asyncio.Future """ def wrapper(self: 'SqlDB', *args, **kwargs): - assert threading.currentThread() != self.sql_thread + assert threading.current_thread() != self.sql_thread f = self.asyncio_loop.create_future() self.db_requests.put((f, func, args, kwargs)) return f diff --git a/electrum/util.py b/electrum/util.py index 1faf97808..ebbbdb92d 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -340,7 +340,7 @@ class DaemonThread(threading.Thread, Logger): def __init__(self): threading.Thread.__init__(self) Logger.__init__(self) - self.parent_thread = threading.currentThread() + self.parent_thread = threading.current_thread() self.running = False self.running_lock = threading.Lock() self.job_lock = threading.Lock() @@ -1317,7 +1317,7 @@ def create_and_start_event_loop() -> Tuple[asyncio.AbstractEventLoop, loop = asyncio.get_event_loop() loop.set_exception_handler(on_exception) # loop.set_debug(1) - stopping_fut = asyncio.Future() + stopping_fut = loop.create_future() loop_thread = threading.Thread(target=loop.run_until_complete, args=(stopping_fut,), name='EventLoop') diff --git a/electrum/wallet_db.py b/electrum/wallet_db.py index 6b6a862a8..230465bae 100644 --- a/electrum/wallet_db.py +++ b/electrum/wallet_db.py @@ -1393,7 +1393,7 @@ class WalletDB(JsonDB): @profiler def _write(self, storage: 'WalletStorage'): - if threading.currentThread().isDaemon(): + if threading.current_thread().daemon: self.logger.warning('daemon thread cannot write db') return if not self.modified():