diff browser_side/register.py @ 216:9827cda1a6b0

browser_side: added key listener to login and register panels - pressing enter set the focus to the next field or validate the form fix bug 29
author souliane <souliane@mailoo.org>
date Sun, 08 Sep 2013 13:40:01 +0200
parents 3d998119237e
children 759fd7386e1e
line wrap: on
line diff
--- a/browser_side/register.py	Sat Sep 07 02:07:07 2013 +0200
+++ b/browser_side/register.py	Sun Sep 08 13:40:01 2013 +0200
@@ -37,6 +37,7 @@
 from pyjamas.ui.Image import Image
 from pyjamas.ui.Hidden import Hidden
 from pyjamas import Window
+from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER
 import re
 
 
@@ -58,19 +59,17 @@
         ##TabPanel##
         tab_bar = TabBar()
         tab_bar.setStyleName('registerPanel_tabs')
-        self.right_side = TabPanel(tab_bar) 
+        self.right_side = TabPanel(tab_bar)
         self.right_side.setStyleName('registerPanel_right_side')
         main_panel.add(self.right_side)
         main_panel.setCellWidth(self.right_side, '100%')
-        
 
         ##Login tab##
         login_tab = SimplePanel()
         login_tab.setStyleName('registerPanel_content')
         login_vpanel = VerticalPanel()
         login_tab.setWidget(login_vpanel)
-        
-        
+
         self.login_warning_msg = Label('')
         self.login_warning_msg.setVisible(False)
         self.login_warning_msg.setStyleName('formWarning')
@@ -79,13 +78,16 @@
         login_label = Label('Login:')
         self.login_box = TextBox()
         self.login_box.setName("login")
+        self.login_box.addKeyboardListener(self)
         login_pass_label = Label('Password:')
-        login_pass_box = PasswordTextBox()
-        login_pass_box.setName("login_password")
+        self.login_pass_box = PasswordTextBox()
+        self.login_pass_box.setName("login_password")
+        self.login_pass_box.addKeyboardListener(self)
+
         login_vpanel.add(login_label)
         login_vpanel.add(self.login_box)
         login_vpanel.add(login_pass_label)
-        login_vpanel.add(login_pass_box)
+        login_vpanel.add(self.login_pass_box)
         login_but = Button("Log in", getattr(self, "onLogin"))
         login_but.setStyleName('button')
         login_but.addStyleName('red')
@@ -95,49 +97,70 @@
         self.submit_type = Hidden('submit_type')
         login_vpanel.add(self.submit_type)
 
-        
         ##Register tab##
         register_tab = SimplePanel()
         register_tab.setStyleName('registerPanel_content')
         register_vpanel = VerticalPanel()
         register_tab.setWidget(register_vpanel)
-        
+
         self.register_warning_msg = Label('')
         self.register_warning_msg.setVisible(False)
         self.register_warning_msg.setStyleName('formWarning')
         register_vpanel.add(self.register_warning_msg)
-        
+
         register_login_label = Label('Login:')
         self.register_login_box = TextBox()
         self.register_login_box.setName("register_login")
+        self.register_login_box.addKeyboardListener(self)
         email_label = Label('E-mail:')
         self.email_box = TextBox()
         self.email_box.setName("email")
+        self.email_box.addKeyboardListener(self)
         register_pass_label = Label('Password:')
         self.register_pass_box = PasswordTextBox()
         self.register_pass_box.setName("register_password")
+        self.register_pass_box.addKeyboardListener(self)
         register_vpanel.add(register_login_label)
         register_vpanel.add(self.register_login_box)
         register_vpanel.add(email_label)
         register_vpanel.add(self.email_box)
         register_vpanel.add(register_pass_label)
         register_vpanel.add(self.register_pass_box)
-         
+
         register_but = Button("Register", getattr(self, "onRegister"))
         register_but.setStyleName('button')
         register_but.addStyleName('red')
         register_vpanel.add(register_but)
-        
+
         self.right_side.add(login_tab, 'Login')
         self.right_side.add(register_tab, 'Register')
         self.right_side.selectTab(0)
         login_tab.setWidth(None)
         register_tab.setWidth(None)
-        
+
         self.add(main_panel)
         self.addFormHandler(self)
         self.setAction('register_api/login')
 
+    def onKeyPress(self, sender, keycode, modifiers):
+        if keycode == KEY_ENTER:
+            if sender == self.login_box:
+                self.login_pass_box.setFocus(True)
+            elif sender == self.login_pass_box:
+                self.onLogin(None)
+            elif sender == self.register_login_box:
+                self.email_box.setFocus(True)
+            elif sender == self.email_box:
+                self.register_pass_box.setFocus(True)
+            elif sender == self.register_pass_box:
+                self.onRegister(None)
+
+    def onKeyUp(self, sender, keycode, modifiers):
+        pass
+
+    def onKeyDown(self, sender, keycode, modifiers):
+        pass
+
     def onLogin(self, button):
         if not re.match(r'^[a-z0-9_-]+$',self.login_box.getText(), re.IGNORECASE):
             self.login_warning_msg.setText('Invalid login, valid characters are a-z A-Z 0-9 _ -')
@@ -158,7 +181,6 @@
             self.submit_type.setValue('register')
             self.submit()
 
-    
     def onSubmit(self, event):
         pass