[master 8/8] Fix the password/confirm checks to work with delayed validation

dashea installerbot-noreply at redhat.com
Wed Jun 17 18:07:18 UTC 2015


From: David Shea <dshea at redhat.com>

For each of the password windows, only use one InputCheck instance to
validate the match, attached to confirm field so that the confirm field
is focused on errors. Add a changed handler to update the InputCheck
whenever the main password field changes.
---
 pyanaconda/ui/gui/spokes/lib/passphrase.py | 23 ++++++++---------------
 pyanaconda/ui/gui/spokes/password.glade    |  2 +-
 pyanaconda/ui/gui/spokes/password.py       | 28 ++++++++++------------------
 pyanaconda/ui/gui/spokes/user.py           | 23 ++++++-----------------
 4 files changed, 25 insertions(+), 51 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/lib/passphrase.py b/pyanaconda/ui/gui/spokes/lib/passphrase.py
index c104194..7b04653 100644
--- a/pyanaconda/ui/gui/spokes/lib/passphrase.py
+++ b/pyanaconda/ui/gui/spokes/lib/passphrase.py
@@ -70,8 +70,10 @@ def __init__(self, data):
         self._pwq_error = None
         self.passphrase = ""
 
-        self._passphrase_match_check = self.add_check(self._passphrase_entry, self._checkMatch)
-        self._confirm_match_check = self.add_check(self._confirm_entry, self._checkMatch)
+        # the passphrase confirmation needs to be checked whenever either of the password
+        # fields change. attach to the confirm field and check changes to the
+        # password field in on_passphrase_changed
+        self._passphrase_match_check = self.add_check(self._confirm_entry, self._checkMatch)
         self._strength_check = self.add_check(self._passphrase_entry, self._checkStrength)
         self._ascii_check = self.add_check(self._passphrase_entry, self._checkASCII)
 
@@ -98,11 +100,10 @@ def refresh(self):
 
         self._update_passphrase_strength()
 
-        # Update the check states and force a status update
+        # Update the check states
         self._passphrase_match_check.update_check_status()
         self._strength_check.update_check_status()
         self._ascii_check.update_check_status()
-        self.set_status(None)
 
     def run(self):
         self.refresh()
@@ -152,7 +153,6 @@ def set_status(self, inputcheck):
 
         # The save button should only be sensitive if the match check passes
         if self._passphrase_match_check.check_status == InputCheck.CHECK_OK and \
-                self._confirm_match_check.check_status == InputCheck.CHECK_OK and \
                 (not self.policy.strict or self._strength_check.check_status == InputCheck.CHECK_OK):
             self._save_button.set_sensitive(True)
         else:
@@ -180,21 +180,14 @@ def _checkMatch(self, inputcheck):
         else:
             result = InputCheck.CHECK_OK
 
-        # If the check succeeded, reset the status of the other check object
-        # Disable the current check to prevent a cycle
-        if result == InputCheck.CHECK_OK:
-            inputcheck.enabled = False
-            if inputcheck == self._passphrase_match_check:
-                self._confirm_match_check.update_check_status()
-            else:
-                self._passphrase_match_check.update_check_status()
-            inputcheck.enabled = True
-
         return result
 
     def on_passphrase_changed(self, entry):
         self._update_passphrase_strength()
 
+        # Update the match check for changes in the main passphrase field
+        self._passphrase_match_check.update_check_status()
+
     def on_save_clicked(self, button):
         self.passphrase = self._passphrase_entry.get_text()
 
diff --git a/pyanaconda/ui/gui/spokes/password.glade b/pyanaconda/ui/gui/spokes/password.glade
index a146741..c0b38f6 100644
--- a/pyanaconda/ui/gui/spokes/password.glade
+++ b/pyanaconda/ui/gui/spokes/password.glade
@@ -80,7 +80,7 @@
                         <property name="can_focus">True</property>
                         <property name="visibility">False</property>
                         <property name="invisible_char">●</property>
-                        <signal name="changed" handler="_updatePwQuality" swapped="no"/>
+                        <signal name="changed" handler="on_password_changed" swapped="no"/>
                         <child internal-child="accessible">
                           <object class="AtkObject" id="pw-atkobject">
                             <property name="AtkObject::accessible-name" translatable="yes">Password</property>
diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
index 1eeb426..b0b8265 100644
--- a/pyanaconda/ui/gui/spokes/password.py
+++ b/pyanaconda/ui/gui/spokes/password.py
@@ -70,14 +70,10 @@ def initialize(self):
         # - Is there any data in the confirm box?
         self.add_check(self.pw, self._checkPasswordEmpty)
 
-        # The password confirmation needs to be checked whenever either of the password
-        # fields change. Separate checks are created for each field so that edits on either
-        # will trigger a new check and so that the last edited field will get focus when
-        # Done is clicked. The checks are saved here so that either check can trigger the
-        # other check in order to reset the status on both when either field is changed.
-        # The check_data field is used as a flag to prevent infinite recursion.
+        # the password confirmation needs to be checked whenever either of the password
+        # fields change. attach to the confirm field so that errors focus on confirm,
+        # and check changes to the password field in on_password_changed
         self._confirm_check = self.add_check(self.confirm, self._checkPasswordConfirm)
-        self._password_check = self.add_check(self.pw, self._checkPasswordConfirm)
 
         # Keep a reference for these checks, since they have to be manually run for the
         # click Done twice check.
@@ -193,19 +189,9 @@ def _checkPasswordConfirm(self, inputcheck):
         else:
             result = InputCheck.CHECK_OK
 
-        # If the check succeeded, reset the status of the other check object
-        # Disable the current check to prevent a cycle
-        inputcheck.enabled = False
-        if result == InputCheck.CHECK_OK:
-            if inputcheck == self._confirm_check:
-                self._password_check.update_check_status()
-            else:
-                self._confirm_check.update_check_status()
-        inputcheck.enabled = True
-
         return result
 
-    def _updatePwQuality(self, editable=None, data=None):
+    def _updatePwQuality(self):
         """Update the password quality information.
 
            This function is called by the ::changed signal handler on the
@@ -235,6 +221,12 @@ def _updatePwQuality(self, editable=None, data=None):
         self.pw_bar.set_value(val)
         self.pw_label.set_text(text)
 
+    def on_password_changed(self, editable, data=None):
+        # Update the password/confirm match check on changes to the main password field
+        self._confirm_check.update_check_status()
+
+        self._updatePwQuality()
+
     def _checkPasswordStrength(self, inputcheck):
         """Update the error message based on password strength.
 
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index 947e281..e837d88 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -308,14 +308,10 @@ def initialize(self):
         # - if a password is required, is there any data in the confirm box?
         self.add_check(self.pw, self._checkPasswordEmpty)
 
-        # The password confirmation needs to be checked whenever either of the password
-        # fields change. Separate checks are created on each field so that edits on
-        # either will trigger a check and so that the last edited field will get the focus
-        # when Done is clicked. Whichever check is run needs to run the other check in
-        # order to reset the status. The check_data field is used as a flag to prevent
-        # infinite recursion.
+        # the password confirmation needs to be checked whenever either of the password
+        # fields change. attach to the confirm field so that errors focus on confirm,
+        # and check changes to the password field in password_changed
         self._confirm_check = self.add_check(self.confirm, self._checkPasswordConfirm)
-        self._password_check = self.add_check(self.pw, self._checkPasswordConfirm)
 
         # Keep a reference to these checks, since they have to be manually run for the
         # click Done twice check.
@@ -476,6 +472,9 @@ def password_changed(self, editable=None, data=None):
         """Update the password strength level bar"""
         self._updatePwQuality()
 
+        # Update the password/confirm match check on changes to the main password field
+        self._confirm_check.update_check_status()
+
     def username_changed(self, editable=None, data=None):
         """Called by Gtk callback when the username or hostname
         entry changes. It disables the guess algorithm if the
@@ -538,16 +537,6 @@ def _checkPasswordConfirm(self, inputcheck):
         else:
             result = InputCheck.CHECK_OK
 
-        # If the check succeeded, reset the status of the other check object
-        # Disable the current check to prevent a cycle
-        inputcheck.enabled = False
-        if result == InputCheck.CHECK_OK:
-            if inputcheck == self._confirm_check:
-                self._password_check.update_check_status()
-            else:
-                self._confirm_check.update_check_status()
-        inputcheck.enabled = True
-
         return result
 
     def _checkPasswordStrength(self, inputcheck):


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/c7c84224855eb2a1246ddf40b53f5c4afe47c360


More information about the anaconda-patches mailing list