Posted by: Dava
empeg control via Nokia S60 E71 etc - 31/05/2009 09:16
I have been playing with Python on the S60 platform for Nokia phones lately and have made a simple quick and dirty interface to allow control and searching on my E71 allowing use of the full keyboard.
You will need to have the correct Python runtime on the phone (link below) and then run the attached script. enjoy!
Python Runtime
You will need to have the correct Python runtime on the phone (link below) and then run the attached script. enjoy!
Python Runtime
Code:
import appuifw from graphics import * import e32 import urllib def connectError(): sc.text((36,48), u'Cannot Connect to ' + unicode(empegIP), font=('normal', 18), fill=0xffffff) handle_redraw(None) e32.ao_sleep(1) def getScreen(empegIP,empegPath): empegURL='HTTP://' + empegIP + empegPath try: urllib.urlretrieve(empegURL,localFile) return 1 except: connectError() return 0 def handle_redraw(rect): canvas.blit(sc, target=(0, 0)) def sendButton(button): empegURL='HTTP://' + empegIP + '/proc/empeg_notify?button=' + button try: urllib.urlretrieve(empegURL,localFile + '.txt') except: connectError() def keypressCB(keydict): if keydict['type'] != appuifw.EEventKey: return if keydict['scancode']==14: #left sendButton('left') if keydict['scancode']==15: #right sendButton('right') if keydict['scancode']==16: #up sendButton('top') if keydict['scancode']==1: #del sendButton('cancel') if keydict['scancode']==17: #down sendButton('bottom') if keydict['scancode']==167: #select sendButton('bottom') if keydict['modifiers']==10241: #CTRL + if keydict['scancode']==83: #ctrl S sendButton('search') if keydict['scancode']==73: #ctrl I sendButton('info') if keydict['scancode']==76: #ctrl L keepAliveToggle() if keydict['scancode']==80: #ctrl P sendButton('power.L') if keydict['scancode']==86: #ctrl V sendButton('NextVisual') if keydict['scancode']==66: #ctrl B apprun = 'z:\\system\\bin\\apprun.exe' browser = 'z:\\system\\bin\\BrowserNG.app' url='http://'+empegIP + '/?fid=101&ext=.htm' e32.start_exe( u'browserng.exe' ,' " %s 0"' %url,0) # + ' "%s"' %url , 1) elif keydict['modifiers']==1 and keydict['scancode'] >64 and keydict['scancode'] < 91: # normal letters if keydict['scancode'] >=65 and keydict['scancode'] <=67: sendButton('two') #ABC if keydict['scancode'] >=68 and keydict['scancode'] <=70: sendButton('three') #DEF if keydict['scancode'] >=71 and keydict['scancode'] <=73: sendButton('four') #GHI if keydict['scancode'] >=74 and keydict['scancode'] <=76: sendButton('five') #JKL if keydict['scancode'] >=77 and keydict['scancode'] <=79: sendButton('six') #MNO if keydict['scancode'] ==80 or keydict['scancode'] == 82 or keydict['scancode'] == 83: sendButton('seven') #PRS if keydict['scancode'] >=84 and keydict['scancode'] <=86: sendButton('eight') #TUV if keydict['scancode'] >=87 and keydict['scancode'] <=89: sendButton('nine') #WXY if keydict['scancode'] ==81 or keydict['scancode'] ==90: sendButton('zero') #QZ print 'key:' + str(keydict['scancode']) print keydict def keepAliveToggle(): global keepAlive keepAlive=not(keepAlive) print 'ka' if keepAlive: sc.ellipse((150,204,166,220),fill=0xffff00) else: sc.ellipse((150,204,166,220),fill=0x000000) handle_redraw(None) def showKeys(): global showHelp if showHelp: sc.rectangle((15,105,305,165),fill=0x333366) sc.text((20,120),u'Ctrl + V:', fill=0xffffff) sc.text((80,120),u'Visuals', fill=0xffffff) sc.text((20,140),u'Ctrl + P:', fill=0xffffff) sc.text((80,140),u'Power', fill=0xffffff) sc.text((20,160),u'Ctrl + B:', fill=0xffffff) sc.text((80,160),u'Browse', fill=0xffffff) sc.text((200,120),u'Ctrl + I:', fill=0xffffff) sc.text((260,120),u'Info', fill=0xffffff) sc.text((200,140),u'Ctrl + S:', fill=0xffffff) sc.text((260,140),u'Search', fill=0xffffff) sc.text((200,160),u'Ctrl + L:', fill=0xffffff) sc.text((260,160),u'Light', fill=0xffffff) else: clearCanvas() showHelp = not(showHelp) handle_redraw(None) def showEmpeg(): res=getScreen(empegIP, empegPath) if res: try: empegScreen=Image.open(localFile) canvas.blit(empegScreen, target=((32,10),(288,74)), source=((0,0), (128,32)), scale=1) except: pass def clearCanvas(bgCol=0x000000): sc.clear(bgCol) sc.rectangle((28,6,292,78),width=2,fill=0, outline=0x555555) def exitApp(): global running running=0 def selectSilver(): global empegIP empegIP='192.168.1.99' def selectBlack(): global empegIP empegIP='192.168.1.97' def selectIP(): global empegIP res=appuifw.query(u'empeg IP address / Name','text', unicode (empegIP)) if res != None: empegIP=res sc=Image.new((320,222)) clearCanvas() canvas=appuifw.Canvas(event_callback=keypressCB, redraw_callback=handle_redraw) appuifw.app.screen = "large" appuifw.app.body = canvas appuifw.app.menu = [(u'Select Player IP', selectIP),(u'Black', selectBlack),(u'Silver',selectSilver),(u'Toggle Key Help', showKeys),(u'Exit',exitApp)] appuifw.app.exit_key_handler=exitApp empegIP='192.168.1.99' empegPort=80 empegPath='/proc/empeg_screen.png' showHelp=0 keepAlive=0 localFile='d:\\empeg.png' e32.ao_sleep(1) showKeys() running=1 while running: showEmpeg() if keepAlive: e32.reset_inactivity() #e32.ao_sleep(.2)