tUse weakref for tabs in QShortCut lambdas - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 50755d7db3fb959edf13ace77458aa26b0ea0f41 DIR parent 91349d109e8c6d32578f64519de09f9c3e00d28c HTML Author: Neil Booth <kyuupichan@gmail.com> Date: Sat, 14 Nov 2015 10:35:29 +0900 Use weakref for tabs in QShortCut lambdas Unfortunately we have no way to directly destroy or remove the lambdas embedded in the QShortcut objects, so this is the only solution to avoid leaking references. As the QShortcut objects have the window as parent, they are destroyed with the window so dangling refs to the destroyed window can't happen. This and 91349d109e8c6d32578f64519de09f9c3e00d28c fix #1549. Diffstat: M gui/qt/main_window.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py t@@ -20,6 +20,7 @@ import sys, time, threading import os.path, json, traceback import shutil import socket +import weakref import webbrowser import csv from decimal import Decimal t@@ -144,14 +145,15 @@ class ElectrumWindow(QMainWindow, PrintError): self.setWindowIcon(QIcon(":icons/electrum.png")) self.init_menubar() + wrtabs = weakref.proxy(tabs) QShortcut(QKeySequence("Ctrl+W"), self, self.close) QShortcut(QKeySequence("Ctrl+Q"), self, self.close) QShortcut(QKeySequence("Ctrl+R"), self, self.update_wallet) - QShortcut(QKeySequence("Ctrl+PgUp"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() - 1 )%tabs.count() )) - QShortcut(QKeySequence("Ctrl+PgDown"), self, lambda: tabs.setCurrentIndex( (tabs.currentIndex() + 1 )%tabs.count() )) + QShortcut(QKeySequence("Ctrl+PgUp"), self, lambda: wrtabs.setCurrentIndex((wrtabs.currentIndex() - 1)%wrtabs.count())) + QShortcut(QKeySequence("Ctrl+PgDown"), self, lambda: wrtabs.setCurrentIndex((wrtabs.currentIndex() + 1)%wrtabs.count())) - for i in range(tabs.count()): - QShortcut(QKeySequence("Alt+" + str(i + 1)), self, lambda i=i: tabs.setCurrentIndex(i)) + for i in range(wrtabs.count()): + QShortcut(QKeySequence("Alt+" + str(i + 1)), self, lambda i=i: wrtabs.setCurrentIndex(i)) self.connect(self, QtCore.SIGNAL('payment_request_ok'), self.payment_request_ok) self.connect(self, QtCore.SIGNAL('payment_request_error'), self.payment_request_error)