首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian >> 用户界面 >> 正文
S60 Python 编程指南——弹出菜单和选择列表
作者:佚名    文章来源:转载    更新时间:2007-1-6 10:46:20
信息:多重疑问,选择列表,多项选择列表
所有示例文件UI功能都由模块 appuifw_overview.py 提供
appuifw_overview.py 代码如下:
# Copyright (c) 2006 Jurgen Scheible
# Script that creates a application menue to select all possible
# appuifw functions to see how they appear

import appuifw
import e32

# define the functions:

# note (3 different types are possible) 
def note_info(): # type: info 
   # create a pop-up note: appuifw.note(label, type)    
   appuifw.note(u"Hello", "info")
   
def note_error(): # type: error  
   appuifw.note(u"file not found", "error")
   
def note_conf(): # type: conf   
   appuifw.note(u"upload done", "conf")
   
# query
def query_text():
    # create a single-field dialog (text input field):  appuifw.query(label, type)
    data = appuifw.query(u"Type a word:", "text")
    print data

def query_number():
    # create a single-field dialog (number input field):  appuifw.query(label, type)
    data = appuifw.query(u"Type a number:", "number")
    print data

def query_date():
    # create a single-field dialog (date input field):  appuifw.query(label, type)
    data = appuifw.query(u"Type a date:", "date")
    print data

def query_time():
    # create a single-field dialog (time input field):  appuifw.query(label, type)
    data = appuifw.query(u"Type a time:", "time")
    print data

def query_code():
    # create a single-field dialog (code input field):  appuifw.query(label, type)
    data = appuifw.query(u"Type a code:", "code")
    print data

def query_question():
    # create a single-field dialog (question):  appuifw.query(label, type)
    if appuifw.query(u"Are you ok:", "query") == True:
        print "you pressed ok"
    else:
        print "you pressed cancel"       

# multi_query
def multi_query():
    # create a double-field dialog (text input field):  appuifw.multi_query(label1, label2)
    data1,data2 = appuifw.multi_query(u"Type your first name:",u"Type your surname:")
    print data1
    print data2
   
# popup_menu
def popup_menu():
    # create a list as content for the menu
    L = [u"Stefan", u"Holger", u"Emil"]
    # create the popup menu: appuifw.popup_menu(list, label)
    test = appuifw.popup_menu(L, u"Select + press OK:") 
    if test == 0 : # 0 refers to the first entry in the list L
        print "Stefan was selected"
    if test == 1 : # 1 refers to the second entry in the list L
        print "Holger was selected"
    if test == 2 : # 2 refers to the third entry in the list L
        print "Emil was selected"     

# selection_list
def selection_list():
    # define the list of items
    L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']
    # create the selection list: appuifw.selection_list(list , search_field=1 or 0)
    index = appuifw.selection_list(L , search_field=1)
    # use the result of the selection to trigger some action (here we just print something)
    if index == 0:
        print "cakewalk was selected"
    else:
        print "thanks for choosing"

# - multi_selectionlist: with checkbox
def  multi_selectionlist_checkbox():
    # define the list of items
    L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']
    # create the multi-selection list with checkbox
    index = appuifw.multi_selection_list(L , style='checkbox', search_field=1)

# - multi_selectionlist: with checkmark
def  multi_selectionlist_checkmark():
    # define the list of items 
    L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']
    # create the multi-selection list with checkmark
    tuple = appuifw.multi_selection_list(L , style='checkmark', search_field=1)


# define an exit key handler
def exit_handler():
    lock.signal()   # .signal releases the Active Object 

# set an Active Object (needs to be done for application menus)
lock=e32.Ao_lock()

# create the application menu
appuifw.app.menu=[
    (u'multi_query',multi_query),
    (u'popup-menu',popup_menu),    
    (u'selection_list',selection_list),
    (u'checkbox: multi_list',multi_selectionlist_checkbox),
    (u'checkmark: multi_list',multi_selectionlist_checkmark),
    (u'Exit',lock.signal),
    (u'note info',note_info),
    (u'note error',note_error),
    (u'note conf',note_conf),
    (u'query text',query_text),
    (u'query number',query_number),
    (u'query date',query_date),
    (u'query time',query_time),
    (u'query code',query_code),
    (u'query query',query_question)] 

appuifw.app.body = appuifw.Text(u'press options')

# define what shall happen it the exit button is pressed
appuifw.app.exit_key_handler=exit_handler

lock.wait()




多重请求: appuifw.multi_query(label1,label2)

multi_query 函数创建 2 个对话框(2个输入区),如右边的屏幕截图。

  1. import appuifw
  2. data1,data2 = appuifw.multi_query(u"Type your first name:",u"Type your surname:")
  3. print data1
  4. print data2

示例代码:

# Copyright (c) 2005 Jurgen Scheible
# This script creates 2 text input fields on one screen
# It uses the multi_query function of the appuifw module

# import the application user interface framework module
import appuifw

# create 2 text input fields at the same time:  appuifw.multi_query(label1, label2)
data1,data2 = appuifw.multi_query(u"Type your first name:",u"Type your surname:")

# print the reuslts on the screen
print data1
print data2

选择列表:appuifw.selection_list(choices=list,search_field=1)

  1. import appuifw
  2. # define the list of items (put a u in front - items must be written in unicode!)
  3.  L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'keys']
  4. # create the selection list
  5.  index = appuifw.selection_list(choices=L , search_field=1)
  6. # use the result of the selection to trigger some action (here we just print something)
  7. if index == 0:
  8.      print "cakewalk was selected"
  9. else:
  10.      print "thanks for choosing"


注意: search_field=1 可以在列表末尾显示一个搜索框。
search_field=0 则反之。
示例代码:

# Copyright (c) 2005 Jurgen Scheible
# This script executes a dialog that allows the users to select
# an item in a list and returns the index (of the list) of the chosen item
# It uses the .selection_list() function of the appuifw module
# appuifw.selection_list(choices=list , search_field=0 or 1)

# import the application user interface framework module
import appuifw

# define the list of items (items must written in unicode! -> put a u in front)
L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']

# create the selection list
index = appuifw.selection_list(choices=L , search_field=1)

# use the result of the selection to trigger some action (here we just print something)
if index == 0:
    print "cakewalk was selected"
else:
    print "thanks for choosing"

# the search_field=1 (set to 1) enables a search functionality for looking
# up items in the list. IMPORTANT: to activate the find pane
# (search functionality) you need to press a keyboard key when the script
# is executed and the list has appeared on the screen.
# if search_field=0 no search functionality is enabled.
复选列表
两种不同样式:
1、使用复选框: appuifw.multi_selection_list(list , style=’checkbox’, search_field=1)
2、使用标记: appuifw.multi_selection_list(L , style=’checkmark’, search_field=1)
使用复选框
  1. # define the list of items (items must written in unicode! -> put a u in front)
  2.  L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'keys']
  3. # create the multi-selection list with checkbox
  4.  index = appuifw.multi_selection_list(L , style='checkbox', search_field=1)

示例代码:

# Copyright (c) 2005 Jurgen Scheible
# This script executes a dialog that allows the users to make multiple selections
# of items in a list via checkbox. It returns the indexes (of the list) of the chosen items
# It uses the .multi_selection_list() function of the appuifw module
# appuifw.multi_selection_list(choices=list , style='checkbox', search_field=1)

# import the application user interface framework module
import appuifw

# define the list of items (items must written in unicode! -> put a u in front)
L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']

# create the multi-selection list
index = appuifw.multi_selection_list(L , style='checkbox', search_field=1)

# create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)
Lnew = index
print Lnew

使用标记
  1. import appuifw
  2. # define the list of items (items must written in unicode! -> put a u in front)
  3.  L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'keys']
  4. # create the multi-selection list with checkmark
  5.  tuple = appuifw.multi_selection_list(L , style='checkmark', search_field=1)

示例代码:

# Copyright (c) 2005 Jurgen Scheible
# This script executes a dialog that allows the users to make multiple selections
# of items in a list and returns the indexes (of the list) of the chosen items
# It uses the .multi_selection_list() function of the appuifw module
# appuifw.multi_selection_list(choices=list , style='checkmark', search_field=0 or 1)

# import the application user interface framework module
import appuifw

# define the list of items (items must written in unicode! -> put a u in front)
L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']

# create the multi-selection list
tuple = appuifw.multi_selection_list(L , style='checkmark', search_field=1)

# create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)
Lnew = tuple
print Lnew
print tuple 

# Note: if you set the style parameter to style='checkmark' like here, then you can put
# a mark behind the items by pressing the EDIT key once you have navigated to an item to
# make your selection.

# the search_field=1 (set to 1) enables a search functionality for looking
# up items in the list (applies only when style='checkmark').
# IMPORTANT: to activate the find pane
# (search functionality) you need to press a keyboard key when the script
# is executed and the list has appeared on the screen.
# if search_field=0 no search functionality is enabled.
相关文章:
显示图片
让TList类型安全
在CB中如何自定义属性[properties]
排序算法比较程序
态生成的对话框上的Listbox加上Scrollbar
模拟Grid的快捷效果
高效C++编程—面向对象设计(中)
深入浅出VA函数
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号