×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    14

    How implement a "back" key? when I have two level of windows?

    Thanks for bogdan.galiceanu's help,now I have a skeleton of UI.
    but I have a further question, as the following codes, I have a initial window "Listbox",and the second window "Canvas". The "Canvas" shows the realtime data. I want to implement a "back" not "quit" key on the canvas' right softkey.
    How to do ?
    Thanks


    Code:
    #-*- coding: UTF-8 -*- 
    import appuifw
    import time
    # import graphics
    from graphics import *
    def quit():
         running = 0
         t.cancel()
         app_lock.signal()
    # define a callback function
    def shout():
        index = lb.current()
        if index ==0:
            global img,canvas,mytimer
            canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
            appuifw.app.directional_pad = False
            # define an initial image (white)
            img=Image.new(canvas.size)
            img.text((100,80), u'')
            update_data()
        if index == 1:
            pass
        if index ==2:
           pass
        if index ==3:
            pass
    # define your redraw function (that redraws the picture on and on)
    # in this case we redraw the image named img using the blit function
    def handle_redraw(rect):
        img.clear()
        img.line((20,20,20,120),0xff00ee)
        img.text((100,80), str1,fill = 0x0,font='normal')
        canvas.blit(img)
    flag = 1
    str1 = ''
    def  update_data():
        global flag,str1
        if flag == 1:
            str1 = u'good'
            flag =0
        else:
            str1 = u'bad'
            flag =1
        handle_redraw(())
        t.after(10,update_data)
    if __name__ == "__main__":
        import e32
        app_lock =e32.Ao_lock()
        appuifw.app.exit_key_handler = quit
        t = e32.Ao_timer()
        appuifw.app.title = u'Listbox_canvas'
        # create your content list of your listbox including the icons to be used for each entry
        entries = [u'canvas_test',u'item1',u'item2',u'item3']
        lb = appuifw.Listbox(entries,shout)
        # create an instance of appuifw.Listbox(), include the content list "entries" and the callback function "shout"
        # and set the instance of Listbox now as the application body
        appuifw.app.body = lb
        app_lock.wait()

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How implement a "back" key? when I have two level of windows?

    You might find this thread useful: http://discussion.forum.nokia.com/fo...esign-in-PyS60 (see especially post #2 and #5).

    The idea is that you memorize the UI elements of your first window, switch to the second window, and assign a function to the right softkey. This function simply replaces the elements of the current window with those from the first window, which you memorized.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    14

    Re: How implement a "back" key? when I have two level of windows?

    so clear implemtention!
    sharing my testing codes as following:
    Code:
    #-*- coding: UTF-8 -*- 
    import appuifw
    import time
    # import graphics
    from graphics import *
    def quit():
         app_lock.signal()
    # define a callback function
    def shout():
        index = lb.current()
        if index ==0:
            global img,canvas,mytimer
            canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
            appuifw.app.directional_pad = False
            viewStack.append(canvas)
            show()
            appuifw.app.exit_key_handler = back
            # define an initial image (white)
            img=Image.new(canvas.size)
            img.text((100,80), u'')
            update_data()
        if index == 1:
            pass
        if index ==2:
           pass
        if index ==3:
            pass
    # define your redraw function (that redraws the picture on and on)
    # in this case we redraw the image named img using the blit function
    def handle_redraw(rect):
        img.clear()
        img.line((20,20,20,120),0xff00ee)
        img.text((100,80), str1,fill = 0x0,font='normal')
        canvas.blit(img)
    flag = 1
    str1 = ''
    def  update_data():
        global flag,str1
        if flag == 1:
            str1 = u'good'
            flag =0
        else:
            str1 = u'bad'
            flag =1
        handle_redraw(())
        t.after(10,update_data)
    def show():
        if len(viewStack) > 0:
            appuifw.app.body = viewStack[-1]
    
    def back():
        t.cancel()
        if len(viewStack) -1 > 0:
            viewStack.pop()
            show()
    if __name__ == "__main__":
        import e32
        app_lock =e32.Ao_lock()
        viewStack =[]
        appuifw.app.exit_key_handler = quit
        t = e32.Ao_timer()
        appuifw.app.title = u'Listbox_canvas'
        # create your content list of your listbox including the icons to be used for each entry
        entries = [u'canvas_test',u'item1',u'item2',u'item3']
        lb = appuifw.Listbox(entries,shout)
        # create an instance of appuifw.Listbox(), include the content list "entries" and the callback function "shout"
        # and set the instance of Listbox now as the application body
        viewStack.append(lb)
        show()
        app_lock.wait()
    Quote Originally Posted by bogdan.galiceanu View Post
    You might find this thread useful: http://discussion.forum.nokia.com/fo...esign-in-PyS60 (see especially post #2 and #5).

    The idea is that you memorize the UI elements of your first window, switch to the second window, and assign a function to the right softkey. This function simply replaces the elements of the current window with those from the first window, which you memorized.

  4. #4
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: How implement a "back" key? when I have two level of windows?

    Quote Originally Posted by ftp2012 View Post
    Thanks for bogdan.galiceanu's help,now I have a skeleton of UI.
    but I have a further question, as the following codes, I have a initial window "Listbox",and the second window "Canvas". The "Canvas" shows the realtime data. I want to implement a "back" not "quit" key on the canvas' right softkey.
    How to do ?
    Thanks
    You can do something like:

    Code:
    def back():
        appuifw.app.body = lb
    
    appuifw.app.exit_key_handler = back
    Just a easier reference for those who will look for this later
    Last edited by Rafael T.; 2010-12-27 at 15:31.

Similar Threads

  1. How to replace "Exit" with "Back" in Menu
    By rahul.kulshreshtha in forum Qt
    Replies: 5
    Last Post: 2010-09-28, 08:29
  2. Replies: 0
    Last Post: 2010-08-09, 21:00
  3. Replies: 3
    Last Post: 2006-11-30, 14:30
  4. Replies: 0
    Last Post: 2004-04-02, 03:48

Posting Permissions

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