Skip to content

Commit

Permalink
python 3.10: fix some deprecation warnings and compat with 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Nov 9, 2021
1 parent ed0dd6e commit 88a1c1a
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion electrum/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ async def stop(self):
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'
Expand Down
4 changes: 2 additions & 2 deletions electrum/gui/qt/qrreader/qtmultimedia/camera_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def _get_crop(resolution: QSize, scan_size: int) -> QRect:
"""
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
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/qrreader/qtmultimedia/video_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, parent: QWidget = None):
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):
Expand Down
2 changes: 1 addition & 1 deletion electrum/gui/qt/qrreader/qtmultimedia/video_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def present(self, frame: QVideoFrame) -> bool:
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()
Expand Down
16 changes: 8 additions & 8 deletions electrum/gui/qt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ def setGeometry(self, rect: QRect):
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()
Expand All @@ -1187,15 +1187,15 @@ def setGeometry(self, rect: QRect):
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())

if free_space.height() > 0 and not item.alignment() & Qt.AlignTop:
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())

Expand Down Expand Up @@ -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)),
)


Expand Down
2 changes: 1 addition & 1 deletion electrum/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion electrum/sql_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions electrum/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -1317,7 +1317,7 @@ def on_exception(loop, context):
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')
Expand Down
2 changes: 1 addition & 1 deletion electrum/wallet_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ def write(self, storage: 'WalletStorage'):

@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():
Expand Down

0 comments on commit 88a1c1a

Please sign in to comment.