diff options
author | elijah <elijah@riseup.net> | 2014-09-19 14:22:42 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2014-09-19 14:23:14 -0700 |
commit | d47adca6cb7494e55c4a9fbc88896c62c06affa5 (patch) | |
tree | 7b53fbd9344baeadd569ca972a401cd4d52b1771 /src/leap | |
parent | 0ad8c8ea3f8d5130f44aa90b55da59622d0048c7 (diff) |
single pref win: fix problems with cleaning up closed windows (lambdas were keeping the python object from getting garbage collected, and this keeps the old signal connections active)
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/bitmask/gui/passwordwindow.py | 61 | ||||
-rw-r--r-- | src/leap/bitmask/gui/preferenceswindow.py | 14 |
2 files changed, 37 insertions, 38 deletions
diff --git a/src/leap/bitmask/gui/passwordwindow.py b/src/leap/bitmask/gui/passwordwindow.py index 5354ab86..f7ef079e 100644 --- a/src/leap/bitmask/gui/passwordwindow.py +++ b/src/leap/bitmask/gui/passwordwindow.py @@ -31,6 +31,8 @@ logger = logging.getLogger(__name__) class PasswordWindow(QtGui.QDialog, Flashable): + _current_window = None # currently visible password window + def __init__(self, parent, account, app): """ :param parent: parent object of the PreferencesWindow. @@ -53,9 +55,13 @@ class PasswordWindow(QtGui.QDialog, Flashable): self.hide_flash() self.ui.ok_button.clicked.connect(self._change_password) - self.ui.cancel_button.clicked.connect(self._close) + self.ui.cancel_button.clicked.connect(self.close) self.ui.username_lineedit.setText(account.address) + if PasswordWindow._current_window is not None: + PasswordWindow._current_window.close() + PasswordWindow._current_window = self + self._disabled = False # if set to True, never again enable widgets. if account.username is None: @@ -132,22 +138,11 @@ class PasswordWindow(QtGui.QDialog, Flashable): Helper to connect to backend signals """ sig = self.app.signaler - sig.srp_password_change_ok.connect(self._srp_change_password_ok) - - pwd_change_error = lambda: self._srp_change_password_problem( - self.tr("There was a problem changing the password."), - None) - sig.srp_password_change_error.connect(pwd_change_error) - - pwd_change_badpw = lambda: self._srp_change_password_problem( - self.tr("You did not enter a correct current password."), - 'current_password') - sig.srp_password_change_badpw.connect(pwd_change_badpw) - + sig.srp_password_change_error.connect(self._srp_password_change_error) + sig.srp_password_change_badpw.connect(self._srp_password_change_badpw) sig.soledad_password_change_ok.connect( self._soledad_change_password_ok) - sig.soledad_password_change_error.connect( self._soledad_change_password_problem) @@ -188,15 +183,16 @@ class PasswordWindow(QtGui.QDialog, Flashable): current_password=current_password, new_password=new_password) - @QtCore.Slot() - def _close(self): + def closeEvent(self, event=None): """ TRIGGERS: - self.ui.buttonBox.rejected + cancel_button (indirectly via self.close()) + or when window is closed - Close this dialog + Close this dialog & delete ourselves to clean up signals. """ - self.hide() + PasswordWindow._current_window = None + self.deleteLater() @QtCore.Slot() def _srp_change_password_ok(self): @@ -214,23 +210,32 @@ class PasswordWindow(QtGui.QDialog, Flashable): else: self._change_password_success() - @QtCore.Slot(unicode) - def _srp_change_password_problem(self, msg, field): + @QtCore.Slot() + def _srp_password_change_error(self): """ TRIGGERS: self._backend.signaler.srp_password_change_error - self._backend.signaler.srp_password_change_badpw - Callback used to display an error on changing password. + Unknown problem changing password + """ + msg = self.tr("There was a problem changing the password.") + logger.error(msg) + self._enable_password_widgets(True) + self.flash_error(msg) - :param msg: the message to show to the user. - :type msg: unicode + @QtCore.Slot() + def _srp_password_change_badpw(self): """ - logger.error("Error changing password: %s" % (msg,)) + TRIGGERS: + self._backend.signaler.srp_password_change_badpw + + The password the user entered was wrong. + """ + msg = self.tr("You did not enter a correct current password.") + logger.error(msg) self._enable_password_widgets(True) self.flash_error(msg) - if field == 'current_password': - self.ui.current_password_lineedit.setFocus() + self.ui.current_password_lineedit.setFocus() @QtCore.Slot() def _soledad_change_password_ok(self): diff --git a/src/leap/bitmask/gui/preferenceswindow.py b/src/leap/bitmask/gui/preferenceswindow.py index e18be976..f1252301 100644 --- a/src/leap/bitmask/gui/preferenceswindow.py +++ b/src/leap/bitmask/gui/preferenceswindow.py @@ -59,7 +59,7 @@ class PreferencesWindow(QtGui.QDialog): self.ui = Ui_Preferences() self.ui.setupUi(self) - self.ui.close_button.clicked.connect(self.close_window) + self.ui.close_button.clicked.connect(self.close) self.ui.account_label.setText(account.address) self.app.service_selection_changed.connect(self._update_icons) @@ -129,26 +129,20 @@ class PreferencesWindow(QtGui.QDialog): self.ui.pages_widget.addWidget(self._vpn_page) self.ui.pages_widget.addWidget(self._email_page) - def closeEvent(self, e): - """ - Override closeEvent to capture when user closes the window. - """ - self.close_window() - # # Slots # - @QtCore.Slot() - def close_window(self): + def closeEvent(self, e): """ TRIGGERS: self.ui.close_button.clicked + (since self.close() will trigger closeEvent) + whenever the window is closed Close this dialog and destroy it. """ PreferencesWindow._current_window = None - self.close() # deleteLater does not seem to cascade to items in stackLayout # (even with QtCore.Qt.WA_DeleteOnClose attribute). |