Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User bubuuns's Avatar
    Join Date
    Dec 2006
    Posts
    10
    Code:
    i=3
    def minus():
    	global i
    	i-=1
    app.exit_key_handler=minus
    while i>0:
    	print i
    When I press 'Exit' button, it should decrease 'i' untill 'i' is zero and then exit, but it does not decreases 'i'. Where is my mistake?

  2. #2
    Super Contributor jplauril's Avatar
    Join Date
    Dec 2004
    Posts
    643
    Your while loop doesn't allow UI events to be processed. Add e32.ao_yield() in the loop to make it possible.

  3. #3
    Registered User bubuuns's Avatar
    Join Date
    Dec 2006
    Posts
    10
    It prints:
    3
    3
    3
    3
    3
    3
    3
    3
    3
    3
    3
    3
    ...

    When I press that Exit button, it prints the same, only on phone display not in Hyperterm. If I press that Exit button again - it exits python. (Im using BT console).

  4. #4
    Super Contributor lfd's Avatar
    Join Date
    May 2006
    Location
    Oulu, Finland
    Posts
    622
    Hi bubuuns,

    Check the following source and twist it to get what you want

    Code:
    # Copyright (c) 2005 Jurgen Scheible
    
    # use keyboard keys Arrow up,down,lefet,right, 1 and * to trigger pop-up note
    
    import appuifw
    import e32
    from key_codes import *
    
    # you can use this class as a chunk as it is.
    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[ccode]=self._downs.get(code,0)+1    # change ccode to code. modified cause the code tag breaks
                self._keyboard_state[ccode]=1    # change ccode to code. modified cause the code tag breaks
            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
    
    # set and instance of Keyboard (so you can use all the functions of
    # that class later in the script by typing e.g. keyboard.pressed...)
    keyboard=Keyboard()
    
    # define the function that lets the application quit
    def quit():
        global running
        running=0
        appuifw.app.set_exit()
    
    running=1
    
    appuifw.app.screen='normal'
    
    # use the appuifw.Canvas function and as "event_callback" put "
    # keyboard.handle_event", a function which does the keyboard scan
    canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)
    
    # set the application body to canvas
    appuifw.app.body=canvas
    
    appuifw.app.exit_key_handler=quit
    
    # create a loop which the script runs all the time through to check whether a
    # key has been pressed.
    while running:
        # check if the left arrow key has been pressed
        if keyboard.pressed(EScancodeLeftArrow):
            appuifw.note(u"Arrow left", "info")
        # check if the right arrow key has been pressed
        if keyboard.pressed(EScancodeRightArrow):
            appuifw.note(u"Arrow right", "info")
    
    
        if keyboard.pressed(EScancodeDownArrow):
            appuifw.note(u"Arrow down", "info")
    
    
        if keyboard.pressed(EScancodeUpArrow):
            appuifw.note(u"Arrow up", "info")
            
        if keyboard.pressed(EScancodeSelect):
            appuifw.note(u"Select", "info")
    
        if keyboard.pressed(EScancode1):
            appuifw.note(u"1", "info")
        
        if keyboard.pressed(EScancodeStar):
            appuifw.note(u"*", "info")
            
        e32.ao_yield()
    LFD
    Devices:
    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:
    http://www.lfdm.net/thesis

  5. #5
    Registered User krzysiekj's Avatar
    Join Date
    Mar 2003
    Posts
    12
    isn't it like exit key always exits app even if you change it handler to do something else? I've read something like this on forum

  6. #6
    Super Contributor lfd's Avatar
    Join Date
    May 2006
    Location
    Oulu, Finland
    Posts
    622
    Noups. Exit key handler does what you want if you implement it properly. If there's an error in the method or function you make it point to, it will then exit.

    I'm for example using it to navigate in some application by making it switching listboxes. So it works I confirm.

    LFD
    Devices:
    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:
    http://www.lfdm.net/thesis

Similar Threads

  1. Please explain the differences between forward locking and combined and separate opti
    By cuono in forum Digital Rights Management & Content Downloading
    Replies: 1
    Last Post: 2004-03-18, 12:46
  2. I Have Maybe Problems With Wireless Kit 1.04 Explain Me!
    By rosarioz in forum Mobile Java General
    Replies: 1
    Last Post: 2003-09-02, 20:30
  3. Please explain what is SYmbian
    By lin_albert in forum Symbian C++
    Replies: 2
    Last Post: 2003-06-04, 10:49
  4. Mistake
    By Obakeng in forum Mobile Web Site Development
    Replies: 1
    Last Post: 2003-02-26, 13:12
  5. I would like to know the structure of the WBMP, so please explain about the
    By ask_expert in forum Mobile Web Site Development
    Replies: 1
    Last Post: 2002-05-10, 16:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved