changeset 222:759fd7386e1e

browser_side: set the focus to the first field when a tab is selected from the register panel
author souliane <souliane@mailoo.org>
date Sun, 22 Sep 2013 20:52:59 +0200
parents f3898fbb00c3
children 624a87377412
files browser_side/register.py
diffstat 1 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/register.py	Sat Sep 21 20:24:36 2013 +0200
+++ b/browser_side/register.py	Sun Sep 22 20:52:59 2013 +0200
@@ -134,6 +134,7 @@
 
         self.right_side.add(login_tab, 'Login')
         self.right_side.add(register_tab, 'Register')
+        self.right_side.addTabListener(self)
         self.right_side.selectTab(0)
         login_tab.setWidth(None)
         register_tab.setWidth(None)
@@ -142,6 +143,15 @@
         self.addFormHandler(self)
         self.setAction('register_api/login')
 
+    def onBeforeTabSelected(self, sender, tabIndex):
+        return True
+
+    def onTabSelected(self, sender, tabIndex):
+        if tabIndex == 0:
+            self.login_box.setFocus(True)
+        elif tabIndex == 1:
+            self.register_login_box.setFocus(True)
+
     def onKeyPress(self, sender, keycode, modifiers):
         if keycode == KEY_ENTER:
             if sender == self.login_box:
@@ -210,13 +220,14 @@
         else:
             Window.alert('Submit error: %s' % result)
 
+
 class RegisterBox(PopupPanel):
 
-    def __init__(self, callback, *args,**kwargs):
-        PopupPanel.__init__(self,*args,**kwargs)
-        _form = RegisterPanel(callback)
-        self.setWidget(_form)
-    
+    def __init__(self, callback, *args, **kwargs):
+        PopupPanel.__init__(self, *args, **kwargs)
+        self._form = RegisterPanel(callback)
+        self.setWidget(self._form)
+
     def onWindowResized(self, width, height):
         super(RegisterBox, self).onWindowResized(width, height)
         self.centerBox()
@@ -224,4 +235,4 @@
     def show(self):
         super(RegisterBox, self).show()
         self.centerBox()
-
+        self._form.login_box.setFocus(True)