Archived:How to define touch sensitive areas with PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Tested with
Devices(s): Nokia 5800
Platform(s): S60 5th Edition
Keywords: appuifw
Created: JOM (27 Mar 2009)
Last edited: hamishwillee (31 May 2013)


Sample PySymbian code snippet showing how to define touch-aware areas.

When pointer events occur in intersected region, where two or more screen areas overlap, the callback which was registered last will be called.

If a user binds the entire canvas and then draws and binds some buttons, touch events call the button's callback function and not the function registered for the entire canvas. Callback functions are called in the reverse order of their registeration, when touch events occur in the overlapped region.

Code Snippet

RGB_RED = (255, 0, 0)
RGB_GREEN = (0, 255, 0)
RGB_BLUE = (0, 0, 255)
g_maxx, g_maxy = canvas.size
y1 = g_maxy/3
y2 = 2 * y1
def cb_blue_down(pos=(0, 0)):
''' Event handler '''
appuifw.note(u"Blue Down")
def cb_green_down(pos=(0, 0)):
''' Event handler '''
appuifw.note(u"Green Down")
def cb_red_down(pos=(0, 0)):
''' Event handler '''
appuifw.note(u"Red Down")
# Hox: you can define several different events for same area
# Hox: you can use same callback for different events, but
# you will NOT know which event trickered your callback
# Blue vertical box
canvas.bind(key_codes.EButton1Down, cb_blue_down, ((0,y2+1), (g_maxx,g_maxy)))
canvas.bind(key_codes.EDrag, cb_blue_drag, ((0,y2+1), (g_maxx,g_maxy)))
canvas.rectangle(((0,y2+1), (g_maxx,g_maxy)), fill=RGB_BLUE, width=5)
# Green vertical box
canvas.bind(key_codes.EButton1Down, cb_green_down, ((0,y1+1), (g_maxx,y2)))
canvas.bind(key_codes.EDrag, cb_green_drag, ((0,y1+1), (g_maxx,y2)))
canvas.rectangle(((0,y1+1), (g_maxx,y2)), fill=RGB_GREEN, width=5)
# Red vertical box
canvas.bind(key_codes.EButton1Down, cb_red_down, ((0,0), (g_maxx,y1)))
canvas.bind(key_codes.EDrag, cb_red_drag, ((0,0), (g_maxx,y1)))
canvas.rectangle(((0,0), (g_maxx,y1)), fill=RGB_RED, width=5)

Please note that currently this is NOT a standalone sample application. The code does NOT work as-is, it only demonstrates one specific issue i.e. how to define touchable areas.

Known Issues

Beware that a rectangle with zero height seems to be converted as full-screen area (PySymbian 1.9.3).

# This is NOT a rect! Converted as "full screen" by default?
canvas.bind(key_codes.EButton1Down, cb_blue_down, ((0,y2+1), (g_maxx,y2+1)))
This page was last modified on 31 May 2013, at 04:03.
27 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.