| Reply | « Previous Thread | Next Thread » |
|
Hi,
I've got a problem with refreshing Images! The following App. refreshes the Screen with specific Images (as indication for a pressed button)and sends a String to a PC over Bluetooth at the same time. Code:
import appuifw, e32, key_codes, socket
from graphics import *
def quit():
app_lock.signal()
def choose_service(services):
names = []
channels = []
for name, channel in services.items():
names.append(name)
channels.append(channel)
index = appuifw.popup_menu(names, u"Choose service")
return channels[index]
def up():
print "Up"
print >> to_peer, "Up"
def down():
print "Down"
print >> to_peer, "Down"
def left():
print "Left"
print >> to_peer, "Left"
def right():
print "Right"
print >> to_peer, "Right"
def initialize():
global address, services, channel, conn, to_peer
address, services = socket.bt_discover()
channel = choose_service(services)
conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
conn.connect((address, channel))
to_peer = conn.makefile("rw", 0)
def handle_redraw(rect):
canvas.blit(bgimage) #"draws" the image on the background canvas
def handle_event(event):
global rectO, rectU
#if event['type'] == appuifw.EEventKeyUp:
# bgimage.load("E:\\Images\\main.jpg")
# handle_redraw(())
if event['keycode'] == key_codes.EKey2:
bgimage.load("E:\\Images\\left.jpg")
handle_redraw(())
if event['keycode'] == key_codes.EKey8:
bgimage.load("E:\\Images\\right.jpg")
handle_redraw(())
if event['keycode'] == key_codes.EKey4:
bgimage.load("E:\\Images\\down.jpg")
handle_redraw(())
if event['keycode'] == key_codes.EKey6:
bgimage.load("E:\\Images\\up.jpg")
handle_redraw(())
def quit():
app_lock.signal()
appuifw.app.screen='full' #set the screen size (area of screen to be used)
bgimage=Image.open("E:\\Images\\a.jpg") #Image path should be
canvas=appuifw.Canvas(event_callback=handle_event, redraw_callback=handle_redraw)
appuifw.app.body=canvas
e32.ao_sleep(3)
initialize()
bgimage.load("E:\\Images\\b.jpg")
handle_redraw(())
canvas.bind(key_codes.EKey2, up)
canvas.bind(key_codes.EKey4, left)
canvas.bind(key_codes.EKey6, right)
canvas.bind(key_codes.EKey8, down)
appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
Now I'd like to do the same with orientation events from the sensor class instead. This doesn't work and I don't understand the result! The order of the outgoing strings and the drawn images isn't correct! Could anybody give an advise how it should work? Or is there a chance to use the event_callback with orientations? Btw. here is the code: Code:
import appuifw, e32, key_codes, socket, sensor
from sensor import orientation
from graphics import *
orientations = {
orientation.TOP: 'Right',
orientation.BOTTOM: 'Left',
orientation.LEFT: 'Up',
orientation.RIGHT: 'Down',
orientation.FRONT: 'front',
orientation.BACK: 'Back' }
def choose_service(services):
names = []
channels = []
for name, channel in services.items():
names.append(name)
channels.append(channel)
index = appuifw.popup_menu(names, u"Choose service")
return channels[index]
def quit():
orientation_sensor.disconnect()
app_lock.signal()
def initialize():
global address, services, channel, conn, to_peer
address, services = socket.bt_discover()
channel = choose_service(services)
conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
conn.connect((address, channel))
to_peer = conn.makefile("rw", 0)
def handle_redraw(rect):
canvas.blit(bgimage)
def print_orientation(orientation_value):
print >> to_peer, orientations[orientation_value]
if orientations[orientation_value] == 'Right':
bgimage.load("E:\\Images\\right.jpg")
handle_redraw(())
elif orientations[orientation_value] == 'Left':
bgimage.load("E:\\Images\\left.jpg")
handle_redraw(())
elif orientations[orientation_value] == 'Up':
bgimage.load("E:\\Images\\up.jpg")
handle_redraw(())
elif orientations[orientation_value] == 'Down':
bgimage.load("E:\\Images\\down.jpg")
handle_redraw(())
else:
bgimage.load("E:\\Images\\main.jpg")
handle_redraw(())
appuifw.app.screen='full'
bgimage=Image.open("E:\\Images\\a.jpg")
canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
appuifw.app.body=canvas
e32.ao_sleep(3)
initialize()
bgimage.load("E:\\Images\\b.jpg")
handle_redraw(())
sensors = sensor.sensors()
acc_sensor_data = sensors['AccSensor']
orientation_sensor = sensor.Sensor(acc_sensor_data['id'], acc_sensor_data['category'])
orientation_sensor.set_event_filter(sensor.OrientationEventFilter())
orientation_sensor.connect(print_orientation)
appuifw.app.exit_key_handler = quit
app_lock = e32.Ao_lock()
app_lock.wait()
|
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Hi Slowmoe,
Have you tried using resize_callback? From the Python Library Reference: Quote:
Rafael. |
|
Hi Rafael!
I didn't try this callback until now, but to tell you the truth...I have no idea how this event could help me to initialize a refresh of the screen directed on a change in the accelerometer orientation! ![]() Or have I misunderstood this event?!? |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Quote:
Code:
def print_orientation(orientation_value):
if orientation_value == orientation.LEFT:
bgimage.load("E:\\Images\\right.jpg")
handle_redraw(())
elif orientation_value == orientation.RIGHT:
bgimage.load("E:\\Images\\left.jpg")
handle_redraw(())
elif orientation_value == orientation.TOP:
bgimage.load("E:\\Images\\up.jpg")
handle_redraw(())
elif orientation_value == orientation.BOTTOM:
bgimage.load("E:\\Images\\down.jpg")
handle_redraw(())
else:
bgimage.load("E:\\Images\\main.jpg")
handle_redraw(())
Hope it helps, Rafael. |
|
Hi,
thx 4 your answer! This will not work, because orientation_value is an integer delievered from the sensor (every orientation has a special identifier/ integer...for example: "5" for back). It defines the position in the array "orientation". This part of the code works fine (without GUI). ![]() I have solved the problem now with seperat redraw methods and image objects! ![]() |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Quote:
![]() Good luck, Rafael. |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Is MIDP2.0 over Symbian OS slow? | epolitakis | Mobile Java Games | 7 | 2007-03-16 10:32 |
| Drawing Lines on an Image (image graphics object returns null) | nicenouman | Mobile Java General | 4 | 2006-09-21 11:15 |
| saving jpeg image on grid list | flicker82 | General Symbian C++ | 0 | 2005-01-21 05:22 |
| Image Uploader / Image Downloader / Image Server | kehong | General Symbian C++ | 0 | 2003-05-12 18:38 |
| Loading Image data from 'raw' bytes | LongSteve | Mobile Java General | 2 | 2002-11-20 18:38 |