×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    15

    Hi!How to switch between different app bodies?

    I want to switch between canvas and text (or listbox...) using right soft key .
    I set canvas as main interface,and define listbox as a function. I call the listbox function to jump to listbox body .But when I want to jump back using rightsoftkey ,I found that appuifw.app.exit_key_handler cannot set to 'return'(appuifw.app.exit_key_handler=return).

    Im new to python,please help me!
    Thank you!

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Hi!How to switch between different app bodies?

    That's strange... normally you should be able to assign any function to the right softkey. Let me see if I understand: the current body is canvas and pressing the right softkey sets the body to listbox. Then, when you try to assign the return function to the right softkey, it doesn't work?

    If possible please show the code you're using.

  3. #3
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Hi!How to switch between different app bodies?

    Quote Originally Posted by zyazy119 View Post
    I want to switch between canvas and text (or listbox...) using right soft key .
    I set canvas as main interface,and define listbox as a function. I call the listbox function to jump to listbox body .But when I want to jump back using rightsoftkey ,I found that appuifw.app.exit_key_handler cannot set to 'return'(appuifw.app.exit_key_handler=return).

    Im new to python,please help me!
    Thank you!
    Please, if you could post the code it will be easier to help you. Don't forget to use CODE tags. I have been using these body changes in several projects and it works.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    15

    Re: Hi!How to switch between different app bodies?

    oh I have to say sorry first .I'm not familiar with the terminology in Python,"return" I said is not a function.
    Sorry for my poor English.

    Here is the code.

    Code:
    import appuifw
    from graphics import *
    import e32
    from key_codes import *
    
    
    #国际化
    def cn(x):
        return x.decode('utf-8')
    
    
    #定义键盘类
    class Keyboard(object):
        def __init__(self,onevent=lambda:None):
            self._keyboard_state={}
            self._downs={}
            self._onevent=onevent
        def handle_event(self,event):
            if event['type'] == appuifw.EEventKeyDown:
                code=event['scancode']
                if not self.is_down(code):
                    self._downs[code ]=self._downs.get(code,0)+1
                self._keyboard_state[code ]=1
            elif event['type'] == appuifw.EEventKeyUp:
                self._keyboard_state[event['scancode']]=0
            self._onevent()
        def is_down(self,scancode):
            return self._keyboard_state.get(scancode,0)
        def pressed(self,scancode):
            if self._downs.get(scancode,0):
                self._downs[scancode]-=1
                return True
            return False
    keyboard=Keyboard()
    
    
    #selections
    def select1():
    
        info=appuifw.InfoPopup()
        info.show(cn('记住爱你的人,珍惜他们!!别让他们等候着你的一句问候!!'),(0,0),1000,0,appuifw.EHCenterVCenter)
    
    
        #设置窗体
        def function():
            appuifw.note(listnow[hi.current()],'info')
        
        """def goback():
            appuifw.app.body=None
            appuifw.app.exit_key_handler=None############################ So ,this is where I was stuck . I want to end the function(just like the "return"),and go back to the main(the canvas body),and can continue from the point where I called the function(select1).I know calling main() directly is not good ,but I just don't know how to switch between them.....
            appuifw.app.menu=None
            main()"""
        listnow=[cn('张'),cn('苏'),cn('张'),cn('彭')]
        hi=appuifw.Listbox(listnow,function)
        
        appuifw.app.screen='normal'
        appuifw.app.body=hi
        appuifw.app.exit_key_handler=goback#############  Here I had set it "return",and I had got a syntax error.
        
        
        def sayhi():
            appuifw.note(u'hi','info')
        appuifw.app.menu=[(cn('hi'),sayhi)]
    
        
        
        
    def select2():
        appuifw.note(u'2','info')
    
    
    
    
    def main():
        #设置屏幕
        appuifw.app.screen='full'
    
    
        #定义重画
        img=None
        def handle_redraw(rect):
            if img and canvas:
                canvas.blit(img)
    
        #设置窗体
        appuifw.app.body=canvas=appuifw.Canvas(event_callback=keyboard.handle_event,\
                                               redraw_callback=handle_redraw)
        img=Image.new(canvas.size)
    
    
        #定义跳出循环
        running=1
        def quit():
            global running
            running=0
        appuifw.app.exit_key_handler=quit
    
    
        #通用性
        width=240
        hight=320
        usefont=appuifw.available_fonts()[0]
    
    
    
    
        #绘制第一屏
        imgtodis=Image.new(canvas.size)
        imgtodis.clear(0x90f040)
    
        imgtodis.rectangle((2*width/3,hight/3,2*width/3+55,hight/3+25),fill=0xf04080)
        imgtodis.text((2*width/3,hight/3+25),cn('i问候'),font=usefont)
    
        imgtodis.rectangle((2*width/3,hight/3+30,2*width/3+55,hight/3+55),fill=0xf04080)
        imgtodis.text((2*width/3,hight/3+55),cn('关于'),font=usefont)
    
    
        selection=1
        total_sel=2
    
        
    
        #屏幕循环
        while running:
    
    
            img.clear(0)
            img.blit(imgtodis, (0,0))
            #画选框
            if selection ==1:
                img.rectangle((2*width/3,hight/3,2*width/3+55,hight/3+25),width=5,outline=0x330050)
    
            if selection ==2:
                img.rectangle((2*width/3,hight/3+30,2*width/3+55,hight/3+55),width=5,outline=0x330050)
    
    
        
            #按键动作
            e32.ao_yield()
            if keyboard.pressed(EScancodeDownArrow):
                selection += 1
                if selection>total_sel:
                    selection=total_sel
    
        
            if keyboard.pressed(EScancodeUpArrow):
                selection -= 1
                if selection<1:
                    selection =1
                    
            if keyboard.pressed(EScancodeSelect):
                #getattr(,'select%s'%selection)
                if selection==1:
                    canvas=None
                    appuifw.app.exit_key_handler=None################# And I not clear about how to jump to a new body ,so I 
    
    just set all the things to None. I want to know what are the proper things I should do when I want to go to another 
    
    interface. 
                    select1()
                if selection==2:
                    select2()
            
            handle_redraw(())
        
    main()
    Thank you!!!!
    Last edited by zyazy119; 2009-12-16 at 12:10.

Similar Threads

  1. App. closed: CONE 14 during switch view.
    By johnlg in forum Symbian
    Replies: 3
    Last Post: 2009-12-11, 03:24
  2. Uploading apps to app stores must be made a lot easier
    By svdwal in forum [Closed] Publishing to Nokia Store
    Replies: 1
    Last Post: 2009-11-30, 13:19
  3. Replies: 6
    Last Post: 2008-08-07, 10:31
  4. symbian signed testing problem.
    By anglina in forum Symbian
    Replies: 0
    Last Post: 2007-02-01, 10:15
  5. Dialog's clipping area (again). Nokia experts, please help
    By synov in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-06-26, 14:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×