changeset 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 e830a0c60d32
children f7ec248192de
files browser_side/dialog.py browser_side/register.py
diffstat 2 files changed, 44 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/dialog.py	Sat Sep 07 02:07:07 2013 +0200
+++ b/browser_side/dialog.py	Sun Sep 08 13:40:01 2013 +0200
@@ -195,26 +195,26 @@
 
     def onKeyUp(self, sender, keycode, modifiers):
         pass
-    
+
     def onKeyDown(self, sender, keycode, modifiers):
         pass
-    
+
     def onKeyPress(self, sender, keycode, modifiers):
         if self.enter_cb and keycode == KEY_ENTER:
             self.enter_cb(self)
 
 class GroupSelector(DialogBox):
-    
+
     def __init__(self, top_widgets, initial_groups, selected_groups,
                  ok_title, ok_cb = None, cancel_cb = None):
         DialogBox.__init__(self, centered = True)
         main_panel = VerticalPanel()
         self.ok_cb = ok_cb
         self.cancel_cb = cancel_cb
-        
+
         for wid in top_widgets:
             main_panel.add(wid)
-        
+
         main_panel.add(Label('Select in which groups your contact is:'))
         self.list_box = ListBox()
         self.list_box.setMultipleSelect(True)
@@ -222,7 +222,7 @@
         self.setAvailableGroups(initial_groups)
         self.setGroupsSelected(selected_groups)
         main_panel.add(self.list_box)
-        
+
         add_group_panel = HorizontalPanel()
         add_group_lb = Label('Add group:')
         add_group_tb = ExtTextBox(enter_cb = self.onGroupInput)
@@ -231,12 +231,12 @@
         add_group_panel.add(add_group_tb)
         add_group_panel.add(add_group_bt)
         main_panel.add(add_group_panel)
-        
+
         button_panel = HorizontalPanel()
         button_panel.add(Button(ok_title, self.onOK))
         button_panel.add(Button("Cancel", self.onCancel))
         main_panel.add(button_panel)
-        
+
         self.setWidget(main_panel)
 
     def getSelectedGroups(self):
--- 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