misc/test_virtual_keyboard.py
changeset 0 ca70ae20a155
equal deleted inserted replaced
-1:000000000000 0:ca70ae20a155
       
     1 # Copyright (c) 2009 Nokia Corporation
       
     2 #
       
     3 # Licensed under the Apache License, Version 2.0 (the "License");
       
     4 # you may not use this file except in compliance with the License.
       
     5 # You may obtain a copy of the License at
       
     6 #
       
     7 #     http://www.apache.org/licenses/LICENSE-2.0
       
     8 #
       
     9 # Unless required by applicable law or agreed to in writing, software
       
    10 # distributed under the License is distributed on an "AS IS" BASIS,
       
    11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    12 # See the License for the specific language governing permissions and
       
    13 # limitations under the License.
       
    14 #
       
    15 """
       
    16 
       
    17     This piece of code tests for the popping up of virtual keyboard wherever
       
    18     applicable on a touch device, when PyS60 functionality is accessed.
       
    19     The modules covered for testing are appuifw, globalui, key_codes and
       
    20     btsocket.
       
    21 """
       
    22 
       
    23 import appuifw
       
    24 import globalui
       
    25 import e32
       
    26 import key_codes
       
    27 import keycapture
       
    28 import btsocket
       
    29 import socket
       
    30 import time
       
    31 
       
    32 teams = [u'Team A', u'Team B', u'Team C', u'Team D']
       
    33 team_members = [u"John", u"Harry", u"Joe", u"Tom", u"Evan",
       
    34                 u"Mary"]
       
    35 choice_list = [u"Good", u"Bad", u"Ugly"]
       
    36 text_to_show = u"Testing in progress.."
       
    37 note_type = ["error", "warn", "info", "confirm", "charging", "wait",
       
    38                  "not_charging", "battery_low", "recharge_battery"]
       
    39 
       
    40 
       
    41 def query_func():
       
    42     # This function accepts different types of input from the user
       
    43     appuifw.query(u"Your designation :", "text")
       
    44     appuifw.query(u"SSN", "number")
       
    45     appuifw.query(u"DOB", "date")
       
    46     appuifw.query(u"Time of the day:", "time")
       
    47     appuifw.query(u"Your password:", "code")
       
    48     appuifw.query(u"Still wanna continue", "query")
       
    49 
       
    50 
       
    51 def test_appuifw():
       
    52     """ Call different api's of appuifw like query, multi_query,
       
    53         selection_list, multi_selection_list, popup_menu and check if these
       
    54         respond to user input appropriately.
       
    55 
       
    56     """
       
    57     first, last = appuifw.multi_query(u"First Name", u"Last Name")
       
    58     appuifw.note(u"Enter these fields to proceed, " + first, "info")
       
    59     query_func()
       
    60     selected_team = appuifw.selection_list(choices=teams, search_field=1)
       
    61     if selected_team == 1:
       
    62         appuifw.note(u"Nice team to be in", "info")
       
    63         team_members_list = appuifw.multi_selection_list(team_members,
       
    64                             style='checkbox', search_field=1)
       
    65         appuifw.note(u"Lets verify it again", "info")
       
    66         team_members_list = appuifw.multi_selection_list(team_members,
       
    67                             style='checkmark', search_field=1)
       
    68         appuifw.note(u"Verification Done", "conf")
       
    69     option = appuifw.popup_menu(choice_list, u"How was the experience?")
       
    70     if option == 0:
       
    71         appuifw.note(u"Thank You", "info")
       
    72     else:
       
    73         appuifw.note(u"Loads to improve on!!", "error")
       
    74 
       
    75 
       
    76 def test_globalui():
       
    77     """ Call global_query, global_note, global_msg_query and global_popup_menu
       
    78         of globalui module and test for their response to key press.
       
    79 
       
    80     """
       
    81     i = 0
       
    82     for i in note_type:
       
    83         globalui.global_note(text_to_show, i)
       
    84     time.sleep(20)
       
    85     result = globalui.global_query(u"Do you want to continue?")
       
    86     if result == 1:
       
    87         globalui.global_note(u"Pressed yes")
       
    88     else:
       
    89         globalui.global_note(u"Pressed no")
       
    90     time.sleep(2)
       
    91     result = globalui.global_msg_query(u"i am global message", u"MyHeader")
       
    92     result = globalui.global_popup_menu([u"Good", u"Better", u"Best"])
       
    93     print "Selected item is: " + str(result)
       
    94 
       
    95 
       
    96 def test_socket():
       
    97     """ Tests the btsocket module for selection of access point and displays
       
    98         the selected value. Also checks if a device can be selected to connect
       
    99         via bluetooth.
       
   100 
       
   101     """
       
   102     options = [u"discover", u"select_access_point"]
       
   103     menu_index = appuifw.popup_menu(options, u"Select")
       
   104     if menu_index == 0:
       
   105         btsocket.bt_discover()
       
   106     else:
       
   107         access_point_id = btsocket.select_access_point()
       
   108         for access_point in btsocket.access_points():
       
   109             if access_point['iapid'] == access_point_id:
       
   110                 appuifw.note(u"The access point selected is: " + \
       
   111                 unicode(access_point['name']))
       
   112                 break
       
   113 
       
   114 
       
   115 def test_key_codes():
       
   116     """ Test for various key codes associated with keys of a particular device.
       
   117         The codes for the respective keys are provided in the key_codes module.
       
   118 
       
   119     """
       
   120 
       
   121     def up():
       
   122         appuifw.note(u"Arrow up was pressed")
       
   123 
       
   124     def two():
       
   125         appuifw.note(u"Key 2 was pressed")
       
   126 
       
   127     def yes():
       
   128         appuifw.note(u"Call key is pressed")
       
   129 
       
   130     def no():
       
   131         appuifw.note(u"Call end")
       
   132 
       
   133     def menu():
       
   134         appuifw.note(u"Menu key")
       
   135 
       
   136     canvas = appuifw.Canvas()
       
   137     appuifw.app.body = canvas
       
   138     canvas.text((0, 24), u'These keys are being tested for press :')
       
   139     canvas.text((0, 48), u'Up, Yes, No, Menu, Key2')
       
   140     canvas.bind(key_codes.EKeyUpArrow, up)
       
   141     canvas.bind(key_codes.EKey2, two)
       
   142     canvas.bind(key_codes.EKeyMenu, menu)
       
   143     canvas.bind(key_codes.EKeyYes, yes)
       
   144     canvas.bind(key_codes.EKeyNo, no)
       
   145 
       
   146 
       
   147 def test_keycapture():
       
   148     """ Returns key codes of the keys pressed on devices"""
       
   149 
       
   150     def quit():
       
   151         appuifw.app.exit_key_handler = None
       
   152         script_lock.signal()
       
   153         capturer.stop()
       
   154 
       
   155     def cb_capture(key):
       
   156         appuifw.note(u'Key code of last key press :' + unicode(capturer.last_key()))
       
   157 
       
   158     script_lock = e32.Ao_lock()
       
   159     appuifw.app.exit_key_handler = quit
       
   160     capturer = keycapture.KeyCapturer(cb_capture)
       
   161     capturer.keys = (keycapture._find_all_keys())
       
   162     capturer.start()
       
   163     script_lock.wait()
       
   164 
       
   165 
       
   166 if __name__ == "__main__":
       
   167     lock = e32.Ao_lock()
       
   168     appuifw.app.menu = [
       
   169     (u'test appuifw', test_appuifw),
       
   170     (u'test globalui', test_globalui),
       
   171     (u'test btsocket', test_socket),
       
   172     (u'test key_codes', test_key_codes),
       
   173     (u'test_keycapture', test_keycapture),
       
   174     (u'Exit', lock.signal)]
       
   175 
       
   176     def exit_handler():
       
   177         lock.signal()
       
   178 
       
   179     appuifw.app.exit_key_handler = exit_handler
       
   180     lock.wait()