View Single Post
Posts: 402 | Thanked: 229 times | Joined on Nov 2009 @ Missouri, USA
#20
Originally Posted by ossipena View Post
i made entire app from zero. now I have working UI and problem how to get text input working. I have some ideas I am testing actively. now it only prints "aaaaaa" when I tap button number 1

there is a contact dialog (that gives the name instead of number for now but hey the dialog is working).

heres one screenshot. yes, backspace is missing
I don't see a screenshot... I see it now.

Anyways, as for the "aaaaaa" what about keeping a global variable (or class attribute) that keeps track of the number of sequential presses?

Something like:
Code:
sequential_presses  = 0
last_key_pressed = None

on_key_press(key):
  if key == last_key_pressed:
    seuqential_presses +=1
  else:
    sequential_presses = 1
    last_key_pressed = key

  if sequential_presses == 1:
    ..
  elif sequential_presses == 2:
    ..
Of course, using something like this would be more pythonic than the if/elif clauses. I don't know what toolkit you're using, so it's hard to give concrete examples. Also, it might be worth using ord() or char() instead of manually having to figure out which character needs to be displayed.

BTW, space is usually the 0 key, isn't it? Might help if each key had the letters it can input under them in a smaller font. Looking good so far though.

edit:
Just another idea:
Code:
letters = {}
letters[2] = [_, 'a', 'b', 'c']
letters[3] = [_, 'd', 'e', 'f']

print letters[key][sequential_presses]
The names are verbose just to convey my ideas. Also, the _ is used so that you don't have to do something like "sequential_presses - 1" when doing index referencing.
__________________
aspidites | blog | aspidites@inbox.com

Last edited by aspidites; 2010-04-27 at 18:24.
 

The Following User Says Thank You to aspidites For This Useful Post: