[f21/master] Set widgets to be focused when entering a spoke. (#1121285)

David Shea dshea at redhat.com
Mon Jul 21 19:23:38 UTC 2014


Defining the spokes and hubs in glade files without toplevels and then
putting them into a container breaks gtk's usual default focus behavior
along with the explicit has_focus that we had defined in the welcome
spoke. To work around gtk having 17 words for "focus" and yet not having
a way to say that the default thing in a container's child should grab
the focus, define in python which widgets to focus and grab the focus
for them during the GtkStack transitions.
---
 pyanaconda/ui/gui/__init__.py           | 11 +++++++++++
 pyanaconda/ui/gui/spokes/langsupport.py |  1 +
 pyanaconda/ui/gui/spokes/password.py    |  1 +
 pyanaconda/ui/gui/spokes/user.py        |  1 +
 pyanaconda/ui/gui/spokes/welcome.glade  |  1 -
 pyanaconda/ui/gui/spokes/welcome.py     |  1 +
 6 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/pyanaconda/ui/gui/__init__.py b/pyanaconda/ui/gui/__init__.py
index ecc12d5..6364f54 100644
--- a/pyanaconda/ui/gui/__init__.py
+++ b/pyanaconda/ui/gui/__init__.py
@@ -68,6 +68,8 @@ class GUIObject(common.UIObject):
        mainWidgetName   -- The name of the top-level widget this object
                            object implements.  This will be the widget searched
                            for in uiFile by the window property.
+       focusWidgetName  -- The name of the widget to focus when the object is entered,
+                           or None.
        uiFile           -- The location of an XML file that describes the layout
                            of widgets shown by this object.  UI files are
                            searched for relative to the same directory as this
@@ -81,6 +83,12 @@ class GUIObject(common.UIObject):
     """
     builderObjects = []
     mainWidgetName = None
+
+    # Since many of the builder files do not define top-level widgets, the usual
+    # {get,can,is,has}_{focus,default} properties don't work real good. Define the
+    # widget to be focused in python, instead.
+    focusWidgetName = None
+
     uiFile = ""
     translationDomain = "anaconda"
 
@@ -344,6 +352,9 @@ class MainWindow(Gtk.Window):
 
         self._stack.set_visible_child(child.window)
 
+        if child.focusWidgetName:
+            child.builder.get_object(child.focusWidgetName).grab_focus()
+
     def setCurrentAction(self, standalone):
         """Set the current standalone widget.
 
diff --git a/pyanaconda/ui/gui/spokes/langsupport.py b/pyanaconda/ui/gui/spokes/langsupport.py
index 00f6451..218a734 100644
--- a/pyanaconda/ui/gui/spokes/langsupport.py
+++ b/pyanaconda/ui/gui/spokes/langsupport.py
@@ -39,6 +39,7 @@ __all__ = ["LangsupportSpoke"]
 class LangsupportSpoke(LangLocaleHandler, NormalSpoke):
     builderObjects = ["languageStore", "languageStoreFilter", "localeStore", "langsupportWindow"]
     mainWidgetName = "langsupportWindow"
+    focusWidgetName = "languageEntry"
     uiFile = "spokes/langsupport.glade"
 
     category = LocalizationCategory
diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
index fb88b5b..ee2da7d 100644
--- a/pyanaconda/ui/gui/spokes/password.py
+++ b/pyanaconda/ui/gui/spokes/password.py
@@ -41,6 +41,7 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler)
     builderObjects = ["passwordWindow"]
 
     mainWidgetName = "passwordWindow"
+    focusWidgetName = "pw"
     uiFile = "spokes/password.glade"
 
     category = UserSettingsCategory
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index 654a647..a9fbe6a 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -202,6 +202,7 @@ class UserSpoke(FirstbootSpokeMixIn, NormalSpoke, GUISpokeInputCheckHandler):
     builderObjects = ["userCreationWindow"]
 
     mainWidgetName = "userCreationWindow"
+    focusWidgetName = "t_fullname"
     uiFile = "spokes/user.glade"
 
     category = UserSettingsCategory
diff --git a/pyanaconda/ui/gui/spokes/welcome.glade b/pyanaconda/ui/gui/spokes/welcome.glade
index 7bfb673..0516496 100644
--- a/pyanaconda/ui/gui/spokes/welcome.glade
+++ b/pyanaconda/ui/gui/spokes/welcome.glade
@@ -319,7 +319,6 @@
                       <object class="GtkEntry" id="languageEntry">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="has_focus">True</property>
                         <property name="valign">start</property>
                         <property name="invisible_char">●</property>
                         <property name="secondary_icon_name">edit-clear-symbolic</property>
diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py
index 5995bbd..c04865a 100644
--- a/pyanaconda/ui/gui/spokes/welcome.py
+++ b/pyanaconda/ui/gui/spokes/welcome.py
@@ -46,6 +46,7 @@ __all__ = ["WelcomeLanguageSpoke"]
 
 class WelcomeLanguageSpoke(LangLocaleHandler, StandaloneSpoke):
     mainWidgetName = "welcomeWindow"
+    focusWidgetName = "languageEntry"
     uiFile = "spokes/welcome.glade"
     builderObjects = ["languageStore", "languageStoreFilter", "localeStore",
                       "welcomeWindow", "betaWarnDialog", "unsupportedHardwareDialog"]
-- 
2.0.0



More information about the anaconda-patches mailing list