├── .gitignore
├── Different Examples
├── canvas-animation-house.py
├── canvas-animation-move-point-params.py
├── canvas-animation-test.py
├── canvas-camera-advanced.py
├── canvas-camera-app.py
├── canvas-camera-basic.py
├── canvas-camera-with-unusual-effect.py
├── canvas-color-gradient-test.py
├── canvas-color-showing-app-touch.py
├── canvas-color-showing-app.py
├── canvas-count-down-from-9.py
├── canvas-drawing-program.py
├── canvas-fake-password-cracker.py
├── canvas-fifteen-game-with-camera.py
├── canvas-fractal-1.py
├── canvas-fractal-2.py
├── canvas-fractal-3.py
├── canvas-fractal-4.py
├── canvas-fractal-julia-176x208.py
├── canvas-fractal-mandelbrot-176x208.py
├── canvas-img-viewer_BUG-folder-cant-open.py
├── canvas-keyboard-example.py
├── canvas-labrinth-game.py
├── canvas-py-explorer-176x208.py
├── canvas-py-spy.py
├── canvas-py-utilts60v100 (fixed bug).py
├── canvas-shoot-very-simple-game_BUG-cant-exit-bug.py
├── canvas-software-rendered-cube.py
├── canvas-tetris-game-176x208.py
├── canvas-tictactoe-176x208-RUS.py
├── canvas-tictactoe-BUG_after_draw.py
├── canvas-transparency.py
├── canvas-video-recorder.py
├── canvas-windows-cursor.py
├── canvas-zipman-app-176x208-RUS.py
├── canvas-zipman-app-176x208-TR.py
├── file-browser-and-editor.py
├── file-browser-nokia-combined.py
├── file-browser-simplest.py
├── form-1.py
├── form-2.py
├── listbox-beeper-app.py
├── listbox-mifview-mbm.PY
├── listbox-py-resize-pic_BUG-cant-read-E-drive-bug.py
├── listbox-py2pyc.py
├── listbox-random-generator.py
├── listbox-smartclock.py
├── listbox-sysinfo-app.py
├── listbox-tone-generator-BUGs.py
├── listbox-weather-info.py
├── multiui-appuifw.py
├── multiui-jomtris-best-tetris-clone_BUG-cantexit.py
├── multiui-progress-bars.py
├── multiui-rename.py
├── multiui-res-cleanup (very special app for its code).py
├── multiui-unity-game-boomblox-clone.py
├── network
│ ├── multiui-get.py
│ ├── noui-ftplib.py
│ ├── noui-read-html-from-url.py
│ ├── simpleui-http-post.py
│ ├── simpleui-urllib-example.py
│ └── text-get-url.py
├── noui-autorun-open-file-in-system-and-exit.py
├── noui-create-file.py
├── noui-read-write-config-file-to-disk.py
├── noui-simple-php-parser.py
├── opengl-3d-tetris-game.py
├── opengl-cool-example.py
├── otherui-battery-level-info.py
├── otherui-execute-python-script.py
├── otherui-multi-selection-checkbox-list.py
├── otherui-multi-selection-checkmark-list.py
├── otherui-multiquery.py
├── otherui-queries.py
├── otherui-read-folder-contents.py
├── otherui-selection-list.py
├── otherui-sound-recorder-TR-BUG_issues-with-menu.py
├── otherui-timeshot_BUG-bt.py
├── simpleui-sms-receiver.py
├── simpleui-timed-screenshot-spy.py
├── simpleui-zipfile-creator.py
├── text-auto-photo-taker.py
├── text-browser-backup-tool.py
├── text-browser-cache-remover.py
├── text-colorifer-color-generation.py
├── text-keep-screen-awake.py
├── text-life-counter.py
├── text-phone-info.py
├── text-start-exe-program.py
└── topwindow-progress-bar-advanced.py
├── Nokia Examples
├── application-skeleton.py
├── ball.py
├── calendar.py
├── dumbfeedparser.py
├── e32db-sports-diary.py
├── gles-demo.py
├── gles-simple-cube.py
├── gui-example-1.py
├── gui-example-2.py
├── img-viewer.py
├── key-viewer.py
├── rss-reader.py
├── simple-btconsole.py
├── simple-camera.py
├── sms-example.py
├── snake-1.py
├── snake-2.py
├── test-calendar.py
├── test-contacts.py
└── zipped
│ ├── filebrowser.zip
│ ├── gles_touch_demo.zip
│ ├── pyrepl.zip
│ └── scribble-touch.zip
├── PyS60 Good Examples - Jurgen Scheible
├── app_body_canvas.py
├── app_body_listbox.py
├── app_body_text.py
├── app_menu.py
├── app_screen.py
├── app_skeleton.py
├── app_skeleton_with_mainloop.py
├── app_tabs_advanced.py
├── app_tabs_simple.py
├── ask_home.py
├── codes with more description
│ ├── ex_application_menu_descr.py
│ ├── ex_bluetooth_mobile_to_pc_descr.py
│ ├── ex_camera_descr.py
│ ├── ex_define_function_descr.py
│ ├── ex_graphics_drawing_descr.py
│ ├── ex_mms_sending_descr.py
│ ├── ex_popup_menu_descr.py
│ ├── ex_sms_receiving_descr.py
│ ├── ex_sms_sending_descr.py
│ ├── ex_soundrecorder_descr.py
│ ├── ex_text_input_1_descr.py
│ ├── ex_text_to_speech_1_descr.py
│ ├── ex_text_to_speech_2_descr.py
│ ├── ex_use_of_keys_descr.py
│ ├── ex_video_download_descr.py
│ ├── image_rotation_descr.py
│ └── read_write_settings_to_OS_descr.py
├── ex_3d_cube_simple.py
├── ex_application_menu.py
├── ex_camera_viewfinder.py
├── ex_extended_graphics_drawing.py
├── ex_extended_use_of_keys.py
├── ex_graphics_drawing.py
├── ex_popup_menu.py
├── ex_soundrecorder.py
├── ex_text_input_1.py
├── ex_text_input_2.py
├── ex_text_to_speech_1.py
├── ex_text_to_speech_2.py
├── ex_topwindow.py
├── ex_use_of_keys.py
├── form.py
├── needs work
│ ├── BT
│ │ ├── ex_bluetooth_mobile_to_pc.py
│ │ ├── ex_bt_obex_phone_phone.py
│ │ ├── obex_client.py
│ │ ├── obex_server.py
│ │ ├── rfcomm_client.py
│ │ └── rfcomm_server.py
│ ├── Network
│ │ ├── ex_image_upload_to_database.py
│ │ ├── ex_setting_default_access_point.py
│ │ ├── ex_upload_file_to_url.py
│ │ ├── ex_upload_image_to_url.py
│ │ ├── ex_video_download.py
│ │ ├── ftp_example.py
│ │ ├── tcp_socket_pc_server.py
│ │ ├── tcp_socket_phone_client.py
│ │ └── urllib_example.py
│ ├── SIM
│ │ ├── ex_mms_sending.py
│ │ ├── ex_sms_receiving.py
│ │ ├── ex_sms_sending.py
│ │ └── msg.py
│ ├── ex_camera.py
│ ├── ex_midiplayer.py
│ ├── ex_mobile_midiplayer.py
│ └── image_rotation.py
├── os_dir_read.py
├── os_dir_write.py
├── pycamera_example.py
├── read_write_settings_to_OS.py
└── t_mslist.py
├── PyS60 Tool Ensymble
├── README.md
├── TODO.md
├── cmd_altere32.py
├── cmd_genuid.py
├── cmd_infoe32.py
├── cmd_mergesis.py
├── cmd_py2sis.py.in
├── cmd_signsis.py
├── cmd_simplesis.py
├── cmd_version.py
├── cmdmain.py
├── cryptutil.py
├── data
│ ├── ensymble_cert.pem
│ ├── ensymble_key.pem
│ ├── pythonlogo.svg
│ ├── rsatestcert.pem
│ ├── rsatestkey.pem
│ └── rsatestkey_passphrase.pem
├── decodemif.py
├── decodesisx.py
├── defaultcert.py
├── mbmfile.py
├── miffile.py
├── module_repo.py
├── prefix_data.txt.in
├── rscfile.py
├── sisfield.py
├── sisfile.py
├── squeeze
│ └── squeeze.py
├── symbianutil.py
├── test
│ ├── module-repo.zip
│ └── module_repo_tests.bat
└── www
│ ├── ensymble.html
│ └── ensymble_old.html
├── PyS60 from Mobile Python Book
├── 001-helloworld.py
├── 002-dialogs.py
├── 003-notes.py
├── 004-multiquery.py
├── 005-popupmenu.py
├── 006-selectionlist.py
├── 007-multilist.py
├── 008-shoppinglist.py
├── 009-twodialogs.py
├── 010-firstfunction.py
├── 011-firstapp.py
├── 012-firstmenus.py
├── 013-smsvoter.py
├── 014-smsinbox.py
├── 015-inboxsearch.py
├── 016-inboxsorter.py
├── 017-smsreceiver.py
├── 018-smsgateway.py
├── 019-hangman.py
├── 022-tts.py
├── 023-mp.py
├── 024-blockingmp.py
├── 025-midi.py
├── 026-soundrec.py
├── 027-animalsounds.py
├── 028-bindkeycode.py
├── 029-keyevent.py
├── 030-keydown.py
├── 031-dgraph.py
├── 032-screenshot.py
├── 033-movinggraph.py
├── 034-viewfinder.py
├── 035-minicam.py
├── 036-camera.py
├── 037-zapper.py
├── 040-directory.py
├── 041-fileio.py
├── 042-readsound.py
├── 043-readimage.py
├── 044-readvideo.py
├── 045-rwtext.py
├── 046-dictfile.py
├── 047-filedict.py
├── 048-localdb.py
├── 049-location.py
├── 050-gsmloca.py
├── 051-vocabu.py
├── 054-obexdisco.py
├── 055-rfcommdisco.py
├── 056-photosphone.py
├── 057-btchat.py
├── 059-btclient.py
├── 060-pyserialpc.py
├── 062-gpsreader.py
├── 063-telephone.py
├── 064-contacts.py
├── 065-sysinfo.py
├── 066-httpclient.py
├── 067-logodownloader.py
├── 068-photouploader.py
├── 069-testserver.py
├── 070-tcpclient.py
├── 072-defaultap.py
├── 077-phoneip.py
├── 085-wsreqhandlers.py
├── 087-mopymaps.py
├── 095-instaflickr.py
├── 101-listcomph.py
├── 102-searchlistcomph.py
├── 103-inputsanita.py
├── 104-distconst.py
├── 105-symtable.py
├── 107-custommod.py
├── 108-autoupdate.py
├── 109-plugin.py
├── 124-mobileosc.py
├── 3dcube.py
└── README.MD
├── README.md
└── app_skeleton.zip
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | Rapid Prototyping of Applications on the Mobile Platform.pdf
3 | _Beta/**
--------------------------------------------------------------------------------
/Different Examples/canvas-camera-basic.py:
--------------------------------------------------------------------------------
1 |
2 | import e32, camera, appuifw, key_codes
3 |
4 | def viewfinder(img):
5 | canvas.blit(img)
6 |
7 | def shoot():
8 | camera.stop_finder()
9 | photo = camera.take_photo(size = (640, 480))
10 | w, h = canvas.size
11 | canvas.blit(photo, target = (0, 0, w, 0.75 * w), scale = 1)
12 | photo.save('D:\\photo.jpg')
13 |
14 | def quit():
15 | camera.stop_finder()
16 | app_lock.signal()
17 |
18 | appuifw.app.body = canvas = appuifw.Canvas()
19 | appuifw.app.title = u"Camera"
20 | appuifw.app.exit_key_handler = quit
21 |
22 | camera.start_finder(viewfinder)
23 | canvas.bind(key_codes.EKeySelect, shoot)
24 |
25 | app_lock = e32.Ao_lock()
26 | app_lock.wait()
27 |
--------------------------------------------------------------------------------
/Different Examples/canvas-color-gradient-test.py:
--------------------------------------------------------------------------------
1 | import appuifw,e32
2 | from graphics import *
3 | img=Image.new((320,240),"RGB")
4 | def redraw(rect):
5 | canvas.blit(img)
6 |
7 | canvas=appuifw.Canvas(redraw_callback=redraw)
8 | appuifw.app.screen="full"
9 | appuifw.app.body=canvas
10 | app_lock = e32.Ao_lock()
11 |
12 | def exit():
13 | app_lock.signal()
14 |
15 | appuifw.app.exit_key_handler = exit
16 | pic=Image.new((320,1),"RGB")
17 |
18 | def color(color1, color2, pr, max):
19 | red = (color1[0]*pr + color2[0]*(max-pr) )/max
20 | green =(color1[1]*pr + color2[1]*(max-pr) )/max
21 | blue = (color1[2]*pr + color2[2]*(max-pr) )/max
22 | return (red,green,blue)
23 |
24 | c2=(210,200,100)
25 | c1=(250,250,200)
26 | max=pic.size[0]
27 |
28 | for x in range(pic.size[0]):
29 | col = color(c1,c2, max*(max-x)/max, max)
30 | pic.point((x,0), col)
31 |
32 | for y in range(240):
33 | img.blit(pic,target=(0,y))
34 | redraw(())
35 | app_lock.wait()
--------------------------------------------------------------------------------
/Different Examples/canvas-fake-password-cracker.py:
--------------------------------------------------------------------------------
1 | import appuifw,e32,random
2 | appuifw.app.body=r=appuifw.Canvas()
3 | def crack():
4 | appuifw.app.title=u'Cracking Pass...'
5 | a=str(random.randint(11111111,99999999))+str(random.randint(11111111,99999999))
6 | for i in xrange(len(a)):
7 | for p in xrange(9):
8 | r.clear(0xaaaaaa)
9 | r.text((30,70),u''+a[:i]+str(p)*(len(a)-i))
10 | r.rectangle((7,100,7+(170/len(a))*i,110),0x0000f0,0x808080)
11 | e32.ao_sleep(0.03)
12 | appuifw.app.title=u'Passwort was Cracked!'
13 | appuifw.app.menu=[(u'Crack',crack)]
14 | e32.Ao_lock().wait()
--------------------------------------------------------------------------------
/Different Examples/canvas-fractal-1.py:
--------------------------------------------------------------------------------
1 | import e32
2 | import appuifw
3 |
4 | def dragon(level, turn):
5 | global x, y, dx, dy, p
6 | if level == 0:
7 | canvas.line((x,y,x+dx,y+dy), 0x0000ff)
8 | x += dx
9 | y += dy
10 | p += 1
11 | if p % 20 == 0:
12 | e32.ao_sleep(0.01)
13 | else:
14 | dragon(level-1, 0)
15 | if turn:
16 | dx, dy = dy, -dx
17 | else:
18 | dx, dy = -dy, dx
19 | dragon(level-1, 1)
20 |
21 | def quit():
22 | appuifw.app.exit_key_handler = None
23 | lock.signal()
24 |
25 | lock = e32.Ao_lock()
26 | old_screen=appuifw.app.screen
27 | old_body=appuifw.app.body
28 | appuifw.app.exit_key_handler = quit
29 | appuifw.app.screen='full'
30 | canvas=appuifw.Canvas()
31 | appuifw.app.body=canvas
32 | x, y = 110, 160
33 | dx, dy = 1, 0
34 | p = 0
35 | dragon(14, 0)
36 | lock.wait()
37 | canvas=None
38 | appuifw.app.body=old_body
39 | appuifw.app.screen=old_screen
40 |
--------------------------------------------------------------------------------
/Different Examples/canvas-fractal-2.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import e32
3 |
4 | def hsv_to_rgb(h, s, v):
5 | if s == 0.0: return v, v, v
6 | i = int(h*6.0) # XXX assume int() truncates!
7 | f = (h*6.0) - i
8 | p = v*(1.0 - s)
9 | q = v*(1.0 - s*f)
10 | t = v*(1.0 - s*(1.0-f))
11 | if i%6 == 0: return v, t, p
12 | if i == 1: return q, v, p
13 | if i == 2: return p, v, t
14 | if i == 3: return p, q, v
15 | if i == 4: return t, p, v
16 | if i == 5: return v, p, q
17 | # Cannot get here
18 |
19 | class Mandelbrot:
20 |
21 | def __init__(self):
22 | self.canvas=appuifw.Canvas()
23 | self.old_body=appuifw.app.body
24 | self.old_screen=appuifw.app.screen
25 | appuifw.app.body=self.canvas
26 | appuifw.app.screen='full'
27 | self.max = 32
28 | self.w, self.h = self.canvas.size
29 | self.palette()
30 | self.lock = e32.Ao_lock()
31 | appuifw.app.exit_key_handler = self.quit
32 |
33 | def quit(self):
34 | appuifw.app.exit_key_handler = None
35 | self.lock.signal()
36 |
37 | def cleanup(self):
38 | self.lock.wait()
39 | appuifw.app.body=self.old_body
40 | appuifw.app.screen=self.old_screen
41 |
42 | def iterate(self, x, y):
43 | c = complex(x, y)
44 | z = 0
45 | n = 0
46 | while n < self.max and abs(z) < 2.0:
47 | z = z*z + c
48 | n = n + 1
49 | return n
50 |
51 | def palette(self):
52 | self.p = []
53 | for n in range(self.max):
54 | h = n * 1.0 / self.max
55 | r, g, b = hsv_to_rgb(h, 0.5, 1.0)
56 | c = (int(r*255), int(g*255), int(b*255))
57 | self.p.append(c)
58 | self.p.append((0,0,0))
59 |
60 | def redraw(self):
61 | for v in range(self.h):
62 | x = -2.25 + v * 3.25 / self.h
63 | for u in range(self.w):
64 | y = -1.375 + u * 2.75 / self.w
65 | n = self.iterate(x, y)
66 | self.canvas.point((u,v), self.p[n])
67 | e32.ao_sleep(0.01)
68 |
69 | m = Mandelbrot()
70 | m.redraw()
71 | m.cleanup()
72 |
--------------------------------------------------------------------------------
/Different Examples/canvas-fractal-3.py:
--------------------------------------------------------------------------------
1 | import e32
2 | from appuifw import *
3 |
4 | app.screen = 'full'
5 | app.body = canvas = Canvas()
6 | width, height = canvas.size
7 |
8 | xaxis = width/2
9 | yaxis = height/1.5
10 | scale = 60
11 | iterations = 25
12 |
13 | for y in range(height):
14 | for x in range(width):
15 | magnitude = 0
16 | z = 0+0j
17 | c = complex(float(y-yaxis)/scale, float(x-xaxis)/scale)
18 | for i in range(iterations):
19 | z = z**2+c
20 | if abs(z) > 2:
21 | v = 765*i/iterations
22 | if v > 510:
23 | color = (255, 255, v%255)
24 | elif v > 255:
25 | color = (255, v%255, 0)
26 | else:
27 | color = (v%255, 0, 0)
28 | break
29 | else:
30 | color = (0, 0, 0)
31 | canvas.point((x, y), color)
32 | e32.ao_yield()
33 |
34 | lock = e32.Ao_lock()
35 | app.exit_key_handler = lock.signal
36 | lock.wait()
37 |
--------------------------------------------------------------------------------
/Different Examples/canvas-fractal-julia-176x208.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | from appuifw import *
3 | import e32
4 | from graphics import *
5 | import time
6 |
7 | def quit():
8 | global r_var
9 | r_var=0
10 | # appuifw.app.set_exit()
11 |
12 | appuifw.app.screen='full'
13 | x=10
14 | d=3
15 | img=Image.new((176,208))
16 |
17 |
18 | def handle_redraw(rect):
19 | canvas.blit(img)
20 |
21 | r_var=1
22 |
23 | canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
24 |
25 | appuifw.app.body=canvas
26 |
27 | app.exit_key_handler=quit
28 |
29 | tm1= time.clock()
30 | a=0
31 | b=0
32 | img.clear(0x00)
33 | while b<208 and r_var:
34 | a=0
35 | while a<176:
36 | y1=3*a/176.-1.5
37 | x1=3*b/208.-1.5
38 | xx=x1
39 | yy=y1
40 | i=-1
41 | m=0
42 | run=1
43 | while i<50 and run:
44 | x=xx
45 | xx=x**2.-yy**2+0.32
46 | yy=2.*x*yy+0.042
47 | m=xx*xx+yy*yy
48 | if m>20:
49 | run=0
50 | i=i+1
51 | if m>20:
52 | rd=i*5
53 | gr=i*6*256
54 | bl=i*4*65536
55 | c=rd+gr+bl
56 | img.point((a,b),c,width=1)
57 | a=a+1
58 | handle_redraw(())
59 | e32.ao_yield()
60 | b=b+1
61 | tm2=time.clock()
62 | print u'time=',tm2-tm1
63 | while r_var:
64 | handle_redraw(())
65 | e32.ao_yield()
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/Different Examples/canvas-fractal-mandelbrot-176x208.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | from appuifw import *
3 | import e32
4 | from graphics import *
5 |
6 | def quit():
7 | global r_var
8 | r_var=0
9 | # appuifw.app.set_exit()
10 |
11 | appuifw.app.screen='full'
12 | x=10
13 | d=3
14 | img=Image.new((176,208))
15 |
16 |
17 | def handle_redraw(rect):
18 | canvas.blit(img)
19 |
20 | r_var=1
21 |
22 | canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
23 |
24 | appuifw.app.body=canvas
25 |
26 | app.exit_key_handler=quit
27 | a=0
28 | b=0
29 | img.clear(0x00)
30 | while a<176 and r_var:
31 | b=0
32 | while b<208:
33 | y1=3*a/176.-1.5
34 | x1=3*b/208.-2.3
35 | xx=0
36 | yy=0
37 | i=-1
38 | m=0
39 | run=1
40 | while i<50 and run:
41 | x=xx
42 | xx=x**2.-yy**2+x1
43 | yy=2.*x*yy+y1
44 | m=xx*xx+yy*yy
45 | if m>20:
46 | run=0
47 | i=i+1
48 | if m>20:
49 | rd=i*5
50 | gr=i*6*256
51 | bl=i*4*65536
52 | c=rd+gr+bl
53 | img.point((a,b),c,width=1)
54 | b=b+1
55 | handle_redraw(())
56 | e32.ao_yield()
57 | a=a+1
58 |
59 | while r_var:
60 | handle_redraw(())
61 | e32.ao_yield()
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/Different Examples/canvas-keyboard-example.py:
--------------------------------------------------------------------------------
1 | # use of keys
2 | # use button arrow up, down, left, right, 1 and * to trigger pop-up note
3 |
4 | import appuifw
5 | import e32
6 | from key_codes import *
7 |
8 | class Keyboard(object):
9 | def __init__(self,onevent=lambda:None):
10 | self._keyboard_state={}
11 | self._downs={}
12 | self._onevent=onevent
13 | def handle_event(self,event):
14 | if event['type'] == appuifw.EEventKeyDown:
15 | code=event['scancode']
16 | if not self.is_down(code):
17 | self._downs[code]=self._downs.get(code,0)+1
18 | self._keyboard_state[code]=1
19 | elif event['type'] == appuifw.EEventKeyUp:
20 | self._keyboard_state[event['scancode']]=0
21 | self._onevent()
22 | def is_down(self,scancode):
23 | return self._keyboard_state.get(scancode,0)
24 | def pressed(self,scancode):
25 | if self._downs.get(scancode,0):
26 | self._downs[scancode]-=1
27 | return True
28 | return False
29 |
30 | keyboard=Keyboard()
31 |
32 | def quit():
33 | global running
34 | running=0
35 |
36 | running=1
37 |
38 | appuifw.app.screen='full'
39 |
40 | canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)
41 | appuifw.app.body=canvas
42 | appuifw.app.exit_key_handler=quit
43 |
44 | while running:
45 | if keyboard.pressed(EScancodeLeftArrow):
46 | appuifw.note(u"Arrow left", "info")
47 |
48 | if keyboard.pressed(EScancodeRightArrow):
49 | appuifw.note(u"Arrow right", "info")
50 |
51 | if keyboard.pressed(EScancodeDownArrow):
52 | appuifw.note(u"Arrow down", "info")
53 |
54 | if keyboard.pressed(EScancodeUpArrow):
55 | appuifw.note(u"Arrow up", "info")
56 |
57 | if keyboard.pressed(EScancodeSelect):
58 | appuifw.note(u"Select", "info")
59 |
60 | if keyboard.pressed(EScancode1):
61 | appuifw.note(u"1", "info")
62 |
63 | if keyboard.pressed(EScancodeStar):
64 | appuifw.note(u"*", "info")
65 |
66 | e32.ao_yield()
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Different Examples/canvas-shoot-very-simple-game_BUG-cant-exit-bug.py:
--------------------------------------------------------------------------------
1 | import appuifw,e32
2 | from graphics import *
3 |
4 | img=Image.new((320,240))
5 | map=Image.new((320,240))
6 |
7 | appuifw.app.screen='full'
8 | appuifw.app.body=k=appuifw.Canvas()
9 | global x,y,x1,y1,fire
10 | x,y=5,50
11 | x1,y1=13,53
12 | fire=0
13 | map.clear((200,200,200))
14 | map.rectangle((100,30,170,150),0x0000ff,0x0000ff)
15 | def draw():
16 | global x,y,x1,y1,fire
17 | img.blit(map)
18 | img.rectangle((x,y,x+10,y+10),0x000000,0x000000)
19 | img.point((x1,y1),0x000000,0x000000,width=5)
20 | k.blit(img)
21 | def pula_letit():
22 | global x,y,x1,y1,fire
23 | if fire==1:
24 | x1+=1
25 | if map.getpixel((x1,y1))[0]==(0,0,255):
26 | map.point((x1,y1),(200,200,200),(200,200,200),width=20)
27 | fire=0
28 | x1,y1=x+3,y+3
29 | if x1>176:
30 | fire=0
31 | x1,y1=x+3,y+3
32 | def down():
33 | global x,y,x1,y1,fire
34 | y+=3
35 | if fire==0:y1+=3
36 | def up():
37 | global x,y,x1,y1,fire
38 | y-=3
39 | if fire==0:y1-=3
40 | def f():
41 | global x,y,x1,y1,fire
42 | fire=1
43 | while fire==1:
44 | draw()
45 | pula_letit()
46 | k.bind(50,up)
47 | k.bind(56,down)
48 | e32.ao_sleep(0.01)
49 |
50 | while 1:
51 | draw()
52 | k.bind(50,up)
53 | k.bind(53,f)
54 | k.bind(56,down)
55 | pula_letit()
56 | e32.ao_sleep(0.01)
57 |
--------------------------------------------------------------------------------
/Different Examples/canvas-tictactoe-176x208-RUS.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/Different Examples/canvas-tictactoe-176x208-RUS.py
--------------------------------------------------------------------------------
/Different Examples/canvas-transparency.py:
--------------------------------------------------------------------------------
1 | import e32,appuifw
2 | from graphics import *
3 |
4 | canvas=appuifw.Canvas()
5 | appuifw.app.screen="full"
6 | appuifw.app.body=canvas
7 |
8 | img=Image.new((30,30))
9 | img_mask=Image.new((30,30),'L')
10 |
11 | img.ellipse((5,5,25,25),0x5555ee,0x5555ee)
12 | img_mask.clear(0)
13 | img_mask.ellipse((5,5,25,25),0x888888,0x888888)
14 |
15 | canvas.line((30,0,0,30),0x00dd00,width=5)
16 | canvas.line((0,0,30,30),0xdd0000,width=5)
17 |
18 | canvas.blit(img,mask=img_mask)
19 |
20 | app_lock = e32.Ao_lock()
21 | def exit():
22 | app_lock.signal()
23 | appuifw.app.exit_key_handler = exit
24 |
25 | app_lock.wait()
--------------------------------------------------------------------------------
/Different Examples/canvas-video-recorder.py:
--------------------------------------------------------------------------------
1 | # Video recording application
2 | # (c) Copyright 2007 Jurgen Scheible under terms of GPL
3 |
4 | import e32, camera, appuifw, key_codes, os
5 |
6 | control_light=0
7 | videodir=u"e:\\pyvideos\\"
8 |
9 | try:
10 | if not os.path.exists(videodir):
11 | os.makedirs(videodir)
12 | else:
13 | pass
14 | except:
15 | appuifw.note(u"Problems creating directory on memorycard", "info")
16 |
17 | def finder_cb(im):
18 | global control_light
19 | if control_light==1:
20 | im.point((20, 20), outline = (255, 0, 0), width = 25)
21 | else:
22 | im.point((20, 20), outline = (0, 255, 0), width = 25)
23 | canvas.blit(im)
24 |
25 | def video_callback(err,current_state):
26 | global control_light
27 | if current_state == camera.EPrepareComplete:
28 | control_light=1
29 | else:
30 | pass
31 |
32 | def start_video():
33 | files=os.listdir(videodir)
34 | num = len(files)
35 | filename = videodir+'pyvideo'+unicode(num+1)+'.3gp'
36 | canvas.bind(key_codes.EKeySelect, stop_video)
37 | camera.start_record(filename,video_callback)
38 |
39 | def stop_video():
40 | global control_light
41 | control_light = 0
42 | camera.stop_record()
43 | canvas.bind(key_codes.EKeySelect, start_video)
44 |
45 | def quit():
46 | camera.stop_finder()
47 | camera.release()
48 | app_lock.signal()
49 |
50 | canvas = appuifw.Canvas()
51 | appuifw.app.body = canvas
52 |
53 | camera.start_finder(finder_cb)
54 | canvas.bind(key_codes.EKeySelect, start_video)
55 |
56 | appuifw.app.title = u"Video RECORDER"
57 | appuifw.app.exit_key_handler = quit
58 | app_lock = e32.Ao_lock()
59 | app_lock.wait()
--------------------------------------------------------------------------------
/Different Examples/canvas-windows-cursor.py:
--------------------------------------------------------------------------------
1 | import e32
2 | import appuifw
3 | from key_codes import *
4 |
5 | class Keyboard(object):
6 | def __init__(self):
7 | self.state = {} # is this key pressing ?
8 | self.buffer= {} # is it waiting to be processed ?
9 | def handle_event(self, event): # for event_callback
10 | code = event['scancode']
11 | if event['type'] == appuifw.EEventKeyDown:
12 | self.buffer[code]= 1 # put into queue
13 | self.state[code] = 1
14 | elif event['type'] == appuifw.EEventKeyUp:
15 | self.state[code] = 0
16 | def pressing(self, code): # just check
17 | return self.state.get(code,0)
18 | def pressed(self, code): # check and process the event
19 | if self.buffer.get(code,0):
20 | self.buffer[code] = 0 # take out of queue
21 | return 1
22 | return 0
23 |
24 | def quit():
25 | global running
26 | running = 0
27 |
28 | key = Keyboard()
29 | appuifw.app.screen = 'full'
30 | appuifw.app.body = canvas = appuifw.Canvas(event_callback=key.handle_event)
31 | appuifw.app.exit_key_handler = quit
32 | running = 1
33 |
34 | #
35 | # Calling polygon may be faster than a blit.
36 | #
37 |
38 | x,y = 20,20
39 | arrow = [(0,0), (0,10), (2,8), (4,12), (6,11), (4,7), (7,7)]
40 |
41 | while running:
42 | if key.pressing(EScancodeUpArrow):
43 | y -= 1
44 | if key.pressing(EScancodeDownArrow):
45 | y += 1
46 | if key.pressing(EScancodeLeftArrow):
47 | x -= 1
48 | if key.pressing(EScancodeRightArrow):
49 | x += 1
50 | if key.pressing(EScancodeSelect):
51 | r = 1
52 | while key.pressing(EScancodeSelect):
53 | r += 1 # bigger red circle
54 | canvas.ellipse([(x-r,y-r),(x+r,y+r)], fill=0xff0000)
55 | canvas.polygon([(x+dx,y+dy) for dx,dy in arrow], 0, 0xffffff)
56 | e32.ao_sleep(0.03)
57 |
58 | canvas.clear(0)
59 | canvas.polygon([(x+dx,y+dy) for dx,dy in arrow], 0, 0xffffff)
60 | e32.ao_sleep(0.01)
--------------------------------------------------------------------------------
/Different Examples/file-browser-simplest.py:
--------------------------------------------------------------------------------
1 | import appuifw,os,e32
2 | def ru(x):
3 | return x.decode("utf-8")
4 | def ur(x):
5 | return x.encode("utf-8")
6 | def scan(path):
7 | if path=='':
8 | return e32.drive_list()
9 | if os.path.isdir(path)==0 and os.path.isfile(path)==0:
10 | return [u'<<<']
11 | _files=[]
12 | files=[u"<<<"]
13 | for _file in os.listdir(path):
14 | if os.path.isfile(path+_file)==0:
15 | _file+="\\"
16 | files.append(ru(_file))
17 | else:
18 | _files.append(ru(_file))
19 | files.extend(_files)
20 | return files
21 | def fopen():
22 | app_lock.signal()
23 | def info():
24 | return appuifw.app.body.current()
25 | def back(path):
26 | if len(path)==3:return ''
27 | path=path.split('\\')[:-2]
28 | path= '\\'.join(path)
29 | return path+'\\'
30 | def exit():
31 | global run
32 | run=0
33 | app_lock.signal()
34 | path=u''
35 | run=1
36 | app_lock = e32.Ao_lock()
37 | lock=0
38 | appuifw.app.exit_key_handler=exit
39 | while run:
40 | files=scan(ur(path))
41 | if lock==0:
42 | appuifw.app.body=appuifw.Listbox(files,fopen)
43 | app_lock.wait()
44 | index=info()
45 | if len(path) == 0 :
46 | path=e32.drive_list()[index]+'\\'
47 | lock=0
48 | elif index==0 :
49 | path=back(ur(path))
50 | lock=0
51 | elif os.path.isfile(ur(path+files[index])):
52 | lock=1
53 | else:
54 | path+=files[index]
55 | lock=0
--------------------------------------------------------------------------------
/Different Examples/form-1.py:
--------------------------------------------------------------------------------
1 | import os, e32, appuifw
2 |
3 | def save_dict(list):
4 | global dict
5 | dict={}
6 | for index in list:
7 | dict[index[0]]=index[2]
8 | return True
9 |
10 | def insert():
11 | global dict
12 | try:
13 | key, volume = appuifw.multi_query(u'Item name:', u'Item content:')
14 | except:
15 | pass
16 | else:
17 | dict[key]=volume
18 | form.insert(len(dict)-1, (key, 'text', volume))
19 |
20 | def pop():
21 | global dict
22 | if len(dict)==1:
23 | appuifw.note(u'The form must contain at least one item', 'error')
24 | return False
25 | else:
26 | element=form.pop()
27 | del dict[element[0]]
28 | return True
29 |
30 | def clear():
31 | while pop():
32 | pass
33 |
34 | def keys():
35 | global dict
36 | appuifw.query(u', '.join(dict.keys()), 'query')
37 |
38 | def values():
39 | global dict
40 | appuifw.query(u', '.join(dict.values()), 'query')
41 |
42 | def has_key():
43 | global dict
44 | key=appuifw.query(u'Enter item name.', 'text', u'Untitled')
45 | if key:
46 | if dict.has_key(key):
47 | appuifw.note(u'Item with this key exists')
48 | else:
49 | appuifw.note(u'There is no item with this key', 'error')
50 |
51 | def get():
52 | global dict
53 | key=appuifw.query(u'Enter item name', 'text', u'Untitled')
54 | if key:
55 | appuifw.note(dict.get(key, u'No such element'))
56 |
57 | dict={u'Untitled': u'Empty'}
58 | form=appuifw.Form([(u'Untitled', 'text', u'Empty')], appuifw.FFormAutoLabelEdit | appuifw.FFormDoubleSpaced)
59 |
60 | form.save_hook=save_dict
61 | form.menu=[
62 | (u'Add', insert),
63 | (u'Delete', pop),
64 | (u'Clear', clear),
65 | (u'Keys', keys),
66 | (u'Values', values),
67 | (u'Check', has_key),
68 | (u'Find', get)]
69 |
70 | if appuifw.app.full_name().lower().find(u"python")!=-1:
71 | appuifw.app.title=u'FormBox'
72 | os.abort=lambda:0
73 |
74 | while 1:
75 | form.execute()
76 | if appuifw.query(u'Exit?', 'query'):
77 | break
78 |
79 | os.abort()
--------------------------------------------------------------------------------
/Different Examples/form-2.py:
--------------------------------------------------------------------------------
1 | # This script creates a form
2 | import appuifw, e32
3 |
4 | # create an Active Object
5 | app_lock = e32.Ao_lock()
6 |
7 |
8 | def forming():
9 | # create a list to be used in 'combo' selection mode
10 | model = [u'6600', u'6630', u'7610', u'N90', u'N70']
11 |
12 | # define the field list (consists of tuples: (label, type ,value)); label is a unicode string
13 | # type is one of the following strings: 'text', 'number', 'date', 'time',or 'combo'
14 | data = [(u'Mobile','text', u'Nokia'),(u'Model','combo', (model,0)),(u'Amount','number', 5),(u'Date','date'),(u'Time','time')]
15 |
16 | # set the view/edit mode of the form
17 | flags = appuifw.FFormEditModeOnly
18 |
19 | # creates the form
20 | f = appuifw.Form(data, flags)
21 |
22 | # make the form visible on the UI
23 | f.execute()
24 |
25 | def exit_key_handler():
26 | app_lock.signal()
27 |
28 | # set the title of the script
29 | appuifw.app.title = u'Form'
30 |
31 | # call the function that creates the form
32 | forming()
33 |
34 | appuifw.app.exit_key_handler = exit_key_handler
35 | app_lock.wait()
--------------------------------------------------------------------------------
/Different Examples/listbox-random-generator.py:
--------------------------------------------------------------------------------
1 | # Lottomat 1.00
2 | # 0xe8568866
3 | # kompiler@tlen.pl
4 |
5 | import appuifw
6 | import random
7 |
8 | lock=appuifw.e32.Ao_lock()
9 | p=49
10 | i=6
11 | los=''
12 |
13 | def losowanie():
14 | global los
15 | global lista
16 | global listbox
17 | k=range(1,p+1)
18 | random.shuffle(k)
19 | los=''
20 | kl=[]
21 | for q in range(i):
22 | try: kl.append(k[q])
23 | except: kl.append('?')
24 | kl.sort()
25 | for q in range(len(kl)): los=los+str(kl[q])+','
26 | los=los[0:len(los)-1]
27 | lista=[(u'Random numbers',unicode(los)),(u'Settings',unicode(str(i)+' from '+str(p)))]
28 | appuifw.app.body = listbox = appuifw.Listbox(lista, wybierz)
29 |
30 | def info():
31 | appuifw.note(u'Lottomat 2.10'+u'\n'+u'forum.gsmcenter.pl'+u'\n'+u'kompiler@tlen.pl','info')
32 | appuifw.note(u'English version for'+u'\n'+u'symbian-freak.com','info')
33 |
34 | def koniec():
35 | if appuifw.query(u'Exit ?','query')==True:
36 | lock.signal()
37 |
38 | def wybierz():
39 | global lista
40 | global listbox
41 | global i
42 | global p
43 | index = listbox.current()
44 | if lista[index][0]==u'Settings':
45 | g=q=0
46 | lista=[(u'Random numbers',u''),(u'Settings',u'')]
47 | appuifw.app.body = listbox = appuifw.Listbox(lista, wybierz)
48 | while q<>None:
49 | q=appuifw.query(u'('+unicode(str(i)+') from '+str(p)),'number',i)
50 | if q<>None:
51 | if q>10: appuifw.note(u'Maks (10)','info')
52 | elif q<1: appuifw.note(u'Min (1)','info')
53 | else:
54 | i=q
55 | q=None
56 | g=1
57 | if g>0:
58 | while g<>None:
59 | g=appuifw.query(unicode(str(i)+' from ('+str(p))+u')','number',p-1)
60 | if g<>None:
61 | if g>100: appuifw.note(u'Maks (100)','info')
62 | elif g<1: appuifw.note(u'Min (1)','info')
63 | else:
64 | p=g
65 | g=None
66 | losowanie()
67 | if lista[index][0]==u'Random numbers': losowanie()
68 |
69 | lista=[(u'Random numbers',unicode(los)),(u'Settings',unicode(str(i)+' from '+str(p)))]
70 | appuifw.app.body = listbox = appuifw.Listbox(lista, wybierz)
71 | appuifw.app.exit_key_handler=koniec
72 | appuifw.app.title=u'Lottomat'
73 | appuifw.app.menu=[(u'About',info)]
74 | lock.wait()
75 | appuifw.app.set_exit()
--------------------------------------------------------------------------------
/Different Examples/listbox-sysinfo-app.py:
--------------------------------------------------------------------------------
1 | # Py SysInfo.py script by gauravssn
2 | import sysinfo
3 | import appuifw
4 | import e32
5 | appuifw.app.title = u"Py SysInfo "
6 | dev = "gauravssnl"
7 | ru = lambda txt : str(txt).decode('utf-8','ignore')
8 | lock = e32.Ao_lock()
9 | def app():
10 | appuifw.app.exit_key_handler = lock.signal
11 | active_profile = sysinfo.active_profile()
12 | battery = sysinfo.battery()
13 | d1,d2 = sysinfo.display_pixels()
14 | free_ram = sysinfo.free_ram()/float(1024*1024)
15 | total_ram = sysinfo.total_ram()/float(1024*1024)
16 | imei = sysinfo.imei()
17 | sw_version_list = sysinfo.sw_version().split(' ')
18 | data_list = [(ru("Active Profile:"),ru(active_profile)),(ru("Battery Percentage:"),ru(battery)),(ru("Free RAM:"),ru(str(free_ram)[:6]+" MB/"+str(total_ram)[:6]+" MB")),(ru("Display:"),ru(str(d1)+" x "+str(d2))),(ru("IMEI:"),imei),(u"Software Version:",sw_version_list[0]),(u"Software Version Date:",sw_version_list[1]),(u"Type",sw_version_list[2])]
19 |
20 | list = appuifw.Listbox(data_list, lambda :None)
21 | appuifw.app.body = list
22 | appuifw.app.menu=[(u"Refresh Info",app),(u"About",about)]
23 | def about():
24 | appuifw.note(ru("Developed by gauravssnl"))
25 | app()
26 | lock.wait()
27 |
--------------------------------------------------------------------------------
/Different Examples/listbox-tone-generator-BUGs.py:
--------------------------------------------------------------------------------
1 | import e32
2 | import appuifw
3 | import audio
4 | import struct
5 | import math
6 | import os
7 |
8 | lock=e32.Ao_lock()
9 |
10 | frequency=duration=volume=lista=listbox=0
11 | p='d:\\au.au'
12 |
13 | def koniec():
14 | if appuifw.query(u'Exit ?','query')==True: lock.signal()
15 |
16 | def ton():
17 | f = open(p,'wb')
18 | f.write('.snd'+struct.pack('>5L',16,8*duration,2,8000,1))
19 | for i in range(duration*8):
20 | sin_i=math.sin(i*2*math.pi*frequency/8000)
21 | f.write(struct.pack('b', volume*127*sin_i))
22 | f.close()
23 | s=audio.Sound.open(p)
24 | s.play()
25 | while s.state()==2: e32.ao_yield()
26 | s.close()
27 | os.remove(p)
28 |
29 | def wybierz():
30 | global frequency
31 | global duration
32 | global volume
33 | index=listbox.current()
34 | if lista[index][0]==u'Frequency (Hz)':
35 | q=appuifw.query(u'Frequency (Hz)','number',frequency)
36 | if q<>None: frequency=q; start()
37 | elif lista[index][0]==u'Duration (ms)':
38 | q=appuifw.query(u'Duration (ms)','number',duration)
39 | if q<>None: duration=q; start()
40 | elif lista[index][0]==u'Volume (1-10)':
41 | q=appuifw.query(u'Volume (1-10)','number',int(volume*10))
42 | if 0<=q<=10: volume=float(q)/float(10); start()
43 | elif lista[index][0]==u'Generate tone':
44 | ton()
45 |
46 | def info():
47 | appuifw.note(u'pyGenerator 1.00'+u'\n'+'forum.gsmcenter.pl'+u'\n'+'kompiler@tlen.pl','info')
48 |
49 | def start():
50 | global lista
51 | global listbox
52 | lista=[
53 | (u'Generate tone',u''),(u'Frequency (Hz)',unicode(frequency)),(u'Duration (ms)',unicode(duration)),(u'Volume (1-10)',unicode(int(volume*10)))]
54 | appuifw.app.body=listbox=appuifw.Listbox(lista,wybierz)
55 | appuifw.app.exit_key_handler=koniec
56 | appuifw.app.menu=[(u'About',info)]
57 |
58 | start()
59 | lock.wait()
60 | appuifw.app.set_exit()
--------------------------------------------------------------------------------
/Different Examples/listbox-weather-info.py:
--------------------------------------------------------------------------------
1 | # Programming example -- see license agreement for additional rights
2 | # Simple GUI example 2
3 |
4 | import socket
5 | import urllib
6 |
7 | import e32
8 | import appuifw
9 |
10 | choices =[(u"Los Angeles Intl Airport", "KLAX"),
11 | (u"Dallas/Fort Forth", "KDFW"),
12 | (u"New York/John F. Kennedy", "KJFK")]
13 | choices_labels = [x[0] for x in choices]
14 |
15 | weather_url_base = "http://weather.gov/data/current_obs/"
16 | tempfile = "D:\\weather.xml"
17 |
18 | def find_value(text, tag):
19 | "Find the value between and in text. Always returns a string"
20 | begin_tag = "<" + tag + ">"
21 | begin = text.find(begin_tag)
22 | end = text.find("" + tag + ">")
23 | if begin == -1 or end == -1:
24 | return ""
25 | begin += len(begin_tag)
26 | return text[begin:end]
27 |
28 | def handle_selection():
29 | index = lb.current()
30 | code = choices[index][1]
31 | weather_url = weather_url_base + code + ".xml"
32 | lb.set_list([u"Please wait..."])
33 | appuifw.note(u"Fetching "+ weather_url, 'info')
34 | try:
35 | urllib.urlretrieve(weather_url, tempfile)
36 | f = open(tempfile, 'r')
37 | weatherinfo = f.read()
38 | f.close()
39 | weather = find_value(weatherinfo, "weather")
40 | temperature_string = find_value(weatherinfo,
41 | "temperature_string")
42 | appuifw.popup_menu([(u"Weather", unicode(weather)),
43 | (u"Temperature",
44 | unicode(temperature_string))],
45 | unicode(code))
46 | except IOError:
47 | appuifw.note(u"Connection error to server", 'error')
48 | except:
49 | appuifw.note(u"Could not fetch information", 'error')
50 | lb.set_list(choices_labels)
51 |
52 | def handle_add():
53 | pass
54 |
55 | def handle_delete():
56 | pass
57 |
58 | def exit_key_handler():
59 | app_lock.signal()
60 |
61 | lb = appuifw.Listbox(choices_labels, handle_selection)
62 |
63 | old_title = appuifw.app.title
64 | appuifw.app.title = u"Weather report"
65 | appuifw.app.body = lb
66 | appuifw.app.menu = [(u"Add new item", handle_add),
67 | (u"Delete item", handle_delete)]
68 | appuifw.app.exit_key_handler = exit_key_handler
69 |
70 | app_lock = e32.Ao_lock()
71 | app_lock.wait()
72 |
73 | appuifw.app.title = old_title
74 |
75 |
--------------------------------------------------------------------------------
/Different Examples/multiui-progress-bars.py:
--------------------------------------------------------------------------------
1 | import appuifw,e32
2 | appuifw.app.body=r=appuifw.Text()
3 | ##########################
4 |
5 | l=150
6 |
7 | ##########################
8 | ##########################
9 | ##########################
10 |
11 | def text_bar(i,l,name=None):
12 | if name==None:pass
13 | else:
14 | r.set(u''+str(name)+'\n'+str(i)+'/'+str(l))
15 | e32.ao_sleep(0.001)
16 |
17 | for i in xrange(l):
18 | text_bar(i,l,'text_bar')
19 |
20 | ##########################
21 |
22 | def text_procent_bar(i,l,name=None):
23 | procent=l*0.01
24 | obw=i/procent
25 | if name==None:pass
26 | else:
27 | r.set(u''+str(name)+'\n'+str(obw)[:5]+'%')
28 | e32.ao_sleep(0.001)
29 |
30 | for i in xrange(l):
31 | text_procent_bar(i,l,'text_procent_bar')
32 |
33 | ##########################
34 | ##########################
35 | ##########################
36 |
37 | appuifw.app.body=canv=appuifw.Canvas()
38 |
39 | ##########################
40 |
41 | def canvas_bar(i,l,name=None):
42 | procent=l*0.01
43 | obw=i/procent
44 | canv.clear(0xaaaaaa)
45 | if name==None:pass
46 | else:
47 | canv.text((10,80),u''+str(name))
48 | canv.rectangle((7,100,7+obw*1.6,110),0xff0000,0x0000ff)
49 | canv.text((7,95),u''+str(obw)[:5]+u'%')
50 | e32.ao_sleep(0.1)
51 |
52 | for i in xrange(l):
53 | canvas_bar(i,l,'canvas_bar')
54 |
55 | ##########################
56 |
57 | def new_canvas_bar(i,l,name=None):
58 | procent=l*0.01
59 | obw=i/procent
60 | canv.clear(0xaaaaaa)
61 | if name==None:pass
62 | else:
63 | canv.text((10,80),u''+str(name))
64 | canv.rectangle((7,100,7+obw*1.6,110),0xff0000,0x0000ff)
65 | canv.text((7+obw,95),u''+str(obw)[:5]+u'%')
66 | e32.ao_sleep(0.00001)
67 |
68 | for i in xrange(l):
69 | new_canvas_bar(i,l,'new_canvas_bar')
70 |
71 | ##########################
--------------------------------------------------------------------------------
/Different Examples/network/noui-read-html-from-url.py:
--------------------------------------------------------------------------------
1 | import urllib
2 |
3 | def get_text_from_url(address):
4 | return urllib.urlopen(address).read()
5 |
6 | url_address = "http://google.com"
7 | data_from_url = get_text_from_url(url_address)
8 |
9 | # don't print whole string, it causes bugs, print is only for debugging
10 | print(data_from_url[:128])
11 |
--------------------------------------------------------------------------------
/Different Examples/network/simpleui-http-post.py:
--------------------------------------------------------------------------------
1 | # this script lets you upload an XML file to a server.
2 | import httplib, urllib
3 | import appuifw
4 |
5 | def senddata():
6 | # read the xml file from the c drive and put it into a variable called xmlfile
7 | f=open('c:/xml_btscan.xml','rt')
8 | xmlfile = f.read()
9 | f.close()
10 |
11 | # define your parameters that shall be posted and assign its content: the parameter 'data' gets assigned the content of variable xmlfile
12 | params = urllib.urlencode({'data': xmlfile, 'eggs': 0, 'bacon': 0})
13 | # define your headers
14 | headers = {"Content-type": "application/x-www-form-urlencoded",
15 | "Accept": "text/plain"}
16 | try:
17 | # connect to the server: put here your server URL
18 | conn = httplib.HTTPConnection("www.exampleserver.com")
19 | # make the post request to call the example.php file and handover the parameters and headers (put the correct folder structure here!)
20 | conn.request("POST", "/examplefolder/example.php", params, headers)
21 | response = conn.getresponse()
22 | # close the connection
23 | conn.close()
24 | appuifw.note(u"Data sent", "info")
25 | except:
26 | appuifw.note(u"ok something went wrong", "info")
27 |
28 |
29 | if appuifw.query(u"Upload XML file?","query") == True:
30 | senddata()
--------------------------------------------------------------------------------
/Different Examples/network/simpleui-urllib-example.py:
--------------------------------------------------------------------------------
1 | # this script lets you download a picture from the net
2 | import urllib
3 | import appuifw
4 |
5 | def fetchfile():
6 | # HTTP supported url (not HTTPS-only) where a picture is located
7 | url = "http://eu.httpbin.org/image/jpeg"
8 | # the file name and the location of the file download
9 | tempfile = "D:\\testimg.jpeg"
10 | try:
11 | # fetch the image
12 | urllib.urlretrieve(url, tempfile)
13 | appuifw.note(u"Image received", "info")
14 | except:
15 | appuifw.note(u"Could not fetch file", "info")
16 |
17 | if appuifw.query(u"fetch image?","query"):
18 | fetchfile()
--------------------------------------------------------------------------------
/Different Examples/network/text-get-url.py:
--------------------------------------------------------------------------------
1 | import urllib
2 | import appuifw
3 | import e32
4 |
5 | text = appuifw.Text()
6 | text.set(u'http://httpforever.com')
7 | appuifw.app.body = text
8 | appuifw.app.body.color = 255
9 | appuifw.app.title = u'Enter URL'
10 |
11 | def ok():
12 | url_address = text.get()
13 | html_content = urllib.urlopen(url_address).read()
14 | text.set(unicode(html_content))
15 |
16 | def clear():
17 | text.set(u'')
18 |
19 | appuifw.app.menu = [
20 | (u'Ok', ok),
21 | (u'Clear', clear),
22 | ]
23 |
24 | def exit():
25 | appuifw.app.set_exit()
26 |
27 | lock = e32.Ao_lock()
28 | appuifw.app.exit_key_handler = exit
29 | lock.wait()
30 |
31 |
--------------------------------------------------------------------------------
/Different Examples/noui-autorun-open-file-in-system-and-exit.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | appuifw.Content_handler().open_standalone(u"E:\\Python\\PyfClock.swf")
3 | appuifw.app.set_exit()
--------------------------------------------------------------------------------
/Different Examples/noui-create-file.py:
--------------------------------------------------------------------------------
1 | # this script lets you write a file to drive
2 |
3 | # drefine the directory and file name to write the file into
4 | imageLocation=u'D:\\writetest.txt'
5 |
6 | # create the file
7 | file = open(imageLocation,'w')
8 |
9 | # write some text into it
10 | file.write('Hello, this works!')
11 |
12 | # close the file
13 | file.close()
14 |
15 | print("file stored")
16 |
--------------------------------------------------------------------------------
/Different Examples/noui-read-write-config-file-to-disk.py:
--------------------------------------------------------------------------------
1 | # This script lets you write settings into a file on the OS and also lets you read them
2 | # in this case I store 2 variables, each with a certain value.
3 |
4 |
5 | import os
6 |
7 |
8 | def write_settings():
9 | CONFIG_DIR='e:/mynewfolder'
10 | CONFIG_FILE=os.path.join(CONFIG_DIR,'mysettings.txt')
11 | if not os.path.isdir(CONFIG_DIR):
12 | os.makedirs(CONFIG_DIR)
13 | CONFIG_FILE=os.path.join(CONFIG_DIR,'mysettings.txt')
14 | value1 = 'man'
15 | value2 = 3.15
16 | config={}
17 | config['variable1']= value1
18 | config['variable2']= value2
19 | f=open(CONFIG_FILE,'wt')
20 | f.write(repr(config))
21 | f.close()
22 |
23 |
24 | def read_settings():
25 | CONFIG_FILE='e:/mynewfolder/mysettings.txt'
26 | try:
27 | f=open(CONFIG_FILE,'rt')
28 | try:
29 | content = f.read()
30 | config=eval(content)
31 | f.close()
32 | value1=config.get('variable1','')
33 | value2=config.get('variable2','')
34 | print value1
35 | print value2
36 | except:
37 | print 'can not read file'
38 | except:
39 | print 'can not open file'
40 |
41 |
42 | write_settings()
43 |
44 | read_settings()
--------------------------------------------------------------------------------
/Different Examples/noui-simple-php-parser.py:
--------------------------------------------------------------------------------
1 | import re
2 | varname=re.compile('\$[a-zA-Z]+[0-9a-zA-Z]*')
3 | kw=['include','new']
4 | def parse_php(php):
5 | index={}
6 | m=varname.search(php)
7 | while m:
8 | index[m.start()]=('variable',m.end())
9 | m=varname.search(php,m.end())
10 | for w in kw:
11 | for o in re.finditer(w,php):
12 | index[o.start()]=('keyword',o.end())
13 | k=index.keys()
14 | k.sort()
15 | y=0
16 | i2=[]
17 | for i in k:
18 | if yenable("stats");
31 | $w->public_page();
32 | $w->if_admin();
33 | $w->display_page();'''
34 |
35 | p=parse_php(PHP)
36 | for e in p:
37 | print e
38 |
39 | a=raw_input()
--------------------------------------------------------------------------------
/Different Examples/otherui-battery-level-info.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # sysinfo: check_battery_level
3 |
4 | import appuifw, e32, sysinfo
5 |
6 | def check_battery_level():
7 | battery_level = sysinfo.battery()
8 | appuifw.note(u"Battery Level:\n" + unicode(battery_level) + u"%")
9 |
10 | def exit_key_handler():
11 | script_lock.signal()
12 | appuifw.app.set_exit()
13 |
14 |
15 | script_lock = e32.Ao_lock()
16 |
17 | appuifw.app.title = u"Battery level"
18 |
19 | appuifw.app.menu = [(u"Check Battery Level", check_battery_level)]
20 |
21 | appuifw.app.exit_key_handler = exit_key_handler
22 | script_lock.wait()
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Different Examples/otherui-execute-python-script.py:
--------------------------------------------------------------------------------
1 | import os, appuifw
2 |
3 | home_dir = u'e:\\python\\'
4 | tx_chose = u'Script to run?'
5 |
6 | appuifw.app.title = tx_chose
7 | py_files = []
8 | all_files = os.listdir(home_dir)
9 |
10 | for file_n in all_files:
11 | if file_n.lower().endswith('.py'): py_files.append(u''+file_n)
12 | chose = appuifw.selection_list(py_files,1)
13 |
14 | if chose != None:
15 | execfile(home_dir+py_files[chose])
16 |
17 | appuifw.app.set_exit()
18 |
--------------------------------------------------------------------------------
/Different Examples/otherui-multi-selection-checkbox-list.py:
--------------------------------------------------------------------------------
1 | # This script executes a dialog that allows the users to make multiple selections
2 | # of items in a list via checkbox. It returns the indexes (of the list) of the chosen items
3 | # It uses the .multi_selection_list() function of the appuifw module
4 | # appuifw.multi_selection_list(choices=list , style='checkbox', search_field=1)
5 |
6 |
7 | # import the application user interface framework module
8 | import appuifw
9 |
10 | # define the list of items (items must written in unicode! -> put a u in front)
11 | L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']
12 |
13 | # create the multi-selection list
14 | index = appuifw.multi_selection_list(L , style='checkbox', search_field=1)
15 |
16 | # create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)
17 | Lnew = index
18 | print Lnew
19 |
--------------------------------------------------------------------------------
/Different Examples/otherui-multi-selection-checkmark-list.py:
--------------------------------------------------------------------------------
1 | # This script executes a dialog that allows the users to make multiple selections
2 | # of items in a list and returns the indexes (of the list) of the chosen items
3 | # It uses the .multi_selection_list() function of the appuifw module
4 | # appuifw.multi_selection_list(choices=list , style='checkmark', search_field=0 or 1)
5 |
6 |
7 | # import the application user interface framework module
8 | import appuifw
9 |
10 | # define the list of items (items must written in unicode! -> put a u in front)
11 | L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']
12 |
13 | # create the multi-selection list
14 | tuple = appuifw.multi_selection_list(L , style='checkmark', search_field=1)
15 |
16 | # create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)
17 | Lnew = tuple
18 | print Lnew
19 | print tuple
20 |
21 |
22 | # Note: if you set the style parameter to style='checkmark' like here, then you can put
23 | # a mark behind the items by pressing the EDIT key once you have navigated to an item to
24 | # make your selection.
25 |
26 | # the search_field=1 (set to 1) enables a search functionality for looking
27 | # up items in the list (applies only when style='checkmark').
28 | # IMPORTANT: to activate the find pane
29 | # (search functionality) you need to press a keyboard key when the script
30 | # is executed and the list has appeared on the screen.
31 | # if search_field=0 no search functionality is enabled.
--------------------------------------------------------------------------------
/Different Examples/otherui-multiquery.py:
--------------------------------------------------------------------------------
1 | # This script creates 2 text input fields on one screen
2 | # It uses the multi_query function of the appuifw module
3 |
4 | # import the application user interface framework module
5 | import appuifw
6 |
7 | # create 2 text input fields at the same time: appuifw.multi_query(label1, label2)
8 | data1,data2 = appuifw.multi_query(u"Type your first name:",u"Type your surname:")
9 |
10 | # print the reuslts on the screen
11 | print data1
12 | print data2
--------------------------------------------------------------------------------
/Different Examples/otherui-queries.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2005 Jurgen Scheible
2 | # This script performs a query with a single-field dialog, each with a
3 | # different input type.
4 | # It uses the .query() function of the appuifw module
5 |
6 |
7 | # import the application user interface framework module
8 | import appuifw
9 |
10 |
11 | # text:
12 | # create a single-field dialog (text input field): appuifw.query(label, type)
13 | data = appuifw.query(u"Type a word:", "text")
14 | print data
15 |
16 | # number:
17 | # create a single-field dialog (number input field): appuifw.query(label, type)
18 | data = appuifw.query(u"Type a number:", "number")
19 | print data
20 |
21 | # date:
22 | # create a single-field dialog (date input field): appuifw.query(label, type)
23 | data = appuifw.query(u"Type a date:", "date")
24 | print data
25 |
26 | # time:
27 | # create a single-field dialog (time input field): appuifw.query(label, type)
28 | data = appuifw.query(u"Type a time:", "time")
29 | print data
30 |
31 | # code:
32 | # create a single-field dialog (code input field): appuifw.query(label, type)
33 | data = appuifw.query(u"Type a code:", "code")
34 | print data
35 |
36 | # query:
37 | # create a single-field dialog (question): appuifw.query(label, type)
38 | if appuifw.query(u"Are you ok:", "query") == True:
39 | print "you pressed ok"
40 | else:
41 | print "you pressed cancel"
42 |
43 |
--------------------------------------------------------------------------------
/Different Examples/otherui-read-folder-contents.py:
--------------------------------------------------------------------------------
1 | # this script lets you read the content of the image directory
2 | # and displays the results in a selection list (UI)
3 |
4 | import appuifw
5 | import e32
6 | import os
7 |
8 | # drefine the directory to read
9 | imagedir=u'c:\\Data'
10 |
11 | # read the directory
12 | files=map(unicode,os.listdir(imagedir))
13 |
14 | # put the found items of the directory in to a selction list for showing them on the screen
15 | index=appuifw.selection_list(files)
16 |
17 | # show the slected item
18 | print files[index]
--------------------------------------------------------------------------------
/Different Examples/otherui-selection-list.py:
--------------------------------------------------------------------------------
1 | # This script executes a dialog that allows the users to select
2 | # an item in a list and returns the index (of the list) of the chosen item
3 | # It uses the .selection_list() function of the appuifw module
4 | # appuifw.selection_list(choices=list , search_field=0 or 1)
5 |
6 |
7 | # import the application user interface framework module
8 | import appuifw
9 |
10 | # define the list of items (items must written in unicode! -> put a u in front)
11 | L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']
12 |
13 | # create the selection list
14 | index = appuifw.selection_list(choices=L , search_field=1)
15 |
16 | # use the result of the selection to trigger some action (here we just print something)
17 | if index == 0:
18 | print "cakewalk was selected"
19 | else:
20 | print "thanks for choosing"
21 |
22 |
23 | # the search_field=1 (set to 1) enables a search functionality for looking
24 | # up items in the list. IMPORTANT: to activate the find pane
25 | # (search functionality) you need to press a keyboard key when the script
26 | # is executed and the list has appeared on the screen.
27 | # if search_field=0 no search functionality is enabled.
--------------------------------------------------------------------------------
/Different Examples/otherui-sound-recorder-TR-BUG_issues-with-menu.py:
--------------------------------------------------------------------------------
1 | # -*- coding: 'utf-8' -*-
2 | import os
3 | from appuifw import *
4 | import audio
5 | running=1
6 | def quit():
7 | global running
8 | running=0
9 | app.set_exit()
10 | app.exit_key_handler=quit
11 | def record():
12 | try:
13 | soundname=query(u"Kayit ismi:", "text")
14 | global s
15 | quality=[u".wav", u".amr"]
16 | selectQUALITY=selection_list(quality)
17 | if selectQUALITY == 0:
18 | point=u".wav"
19 | if selectQUALITY == 1:
20 | point=u".amr"
21 | sound=u"e:\\sounds\\digital\\"+soundname+point
22 | s=audio.Sound.open(sound)
23 | s.record()
24 | note(u"Kaydediliyor!", "info")
25 | except:
26 | sound=u"e:\\sounds\\digital\\sound.amr"
27 | s=audio.Sound.open(sound)
28 | s.record()
29 | note(u"Kaydediliyor!", "info")
30 | def stop():
31 | try:
32 | s.stop()
33 | s.close()
34 | except:
35 | note(u"once kayit et", "error")
36 | def play():
37 | try:
38 | global dir, files, select
39 | fil=u"e:\\sounds\\digital\\"+files[select]
40 | global s
41 | s=audio.Sound.open(fil)
42 | s.play()
43 | note(u"Oynatiliyor!", "info")
44 | except:
45 | note(u"once kaydet!", "error")
46 | while running:
47 | popupmenu=[u"Kayit", u"Durdur", u"Oynat", u"Cikis"]
48 | pop=popup_menu(popupmenu, u"Tr:mustafa038")
49 | if pop == 0:
50 | record()
51 | if pop == 1:
52 | stop()
53 | if pop == 2:
54 | play()
55 | if pop == 3:
56 | quit()
57 | dir="e:\\sounds\\digital"
58 | files=map(unicode, os.listdir(dir))
59 | select=selection_list(files)
60 | if select == 1:
61 | play()
62 | app.exit_key_handler=app.set_exit()
--------------------------------------------------------------------------------
/Different Examples/otherui-timeshot_BUG-bt.py:
--------------------------------------------------------------------------------
1 | import e32, time
2 | import socket
3 | import appuifw
4 | import graphics
5 | from time import sleep
6 |
7 |
8 |
9 | index = 2
10 |
11 | if index == 2 :
12 |
13 | nameOfProject = appuifw.query(u"Set name for the (.jpg) file: ", "text")
14 | numImages = 1
15 | delay = appuifw.query(u"Set Time Trigger(after how many seconds screenshot is taken):", "number")
16 |
17 |
18 | ImagequalityDisplay = [u'Low Quality',u'Medium Quality',u'High Quality']
19 | Imagequality = [(85),(92),(100)]
20 | ImagequalitySelect = appuifw.selection_list(choices=ImagequalityDisplay)
21 | appuifw.note(u"OK time is running, press Symbian button to return in menu!","info")
22 |
23 | x = 0
24 | while x != numImages:
25 | sleep(delay)
26 | image = graphics.screenshot()
27 | file ='C:\\Data\\Images\\'+nameOfProject+'.jpg'
28 | image.save(file,quality=Imagequality[ImagequalitySelect])
29 | appuifw.note(u"Screenshot saved in C:\u005CData\u005CImages\u005C","conf",1)
30 | appuifw.note(u"Return in TimeShot to send picture using bluetooth.","conf",1)
31 | x +=1
32 |
33 |
34 |
35 |
36 | def quit():
37 | app_lock.signal()
38 | appuifw.app.exit_key_handler = quit
39 | app_lock = e32.Ao_lock()
40 | app_lock.wait()
41 |
42 |
43 |
44 | def bt_send():
45 | device=socket.bt_obex_discover()
46 | print 'device:', device
47 | address=device[0]
48 | print 'address:', address
49 | channel=device[1][u'OBEX Object Push']
50 | print 'channel:', channel
51 | socket.bt_obex_send_file(address,channel,file)
52 | appuifw.note(u"Image sent!","info")
53 |
54 |
55 | app_lock = e32.Ao_lock()
56 | appuifw.app.title = u"Send screenshot by bluetooth!"
57 | appuifw.app.menu = [(u"Start sending...!", bt_send)]
58 | app_lock.wait()
59 |
60 |
61 |
--------------------------------------------------------------------------------
/Different Examples/simpleui-sms-receiver.py:
--------------------------------------------------------------------------------
1 | import inbox, appuifw, e32
2 |
3 | def message_received(msg_id):
4 | box = inbox.Inbox()
5 | appuifw.note(u"New message: %s" % box.content(msg_id))
6 | app_lock.signal()
7 |
8 | box = inbox.Inbox()
9 | box.bind(message_received)
10 |
11 | print "Waiting for new SMS messages.."
12 | app_lock = e32.Ao_lock()
13 | app_lock.wait()
14 | print "Message handled!"
--------------------------------------------------------------------------------
/Different Examples/simpleui-timed-screenshot-spy.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import graphics
3 | import e32
4 |
5 | running=1
6 | switch = 0
7 | appuifw.app.screen='normal'
8 |
9 | def quit():
10 | global running
11 | running=0
12 | appuifw.app.set_exit()
13 |
14 |
15 | interval = appuifw.query(u"Interval:", "number", 10)
16 | maxscreen = appuifw.query(u"Screenshot number:", "number" ,20)
17 |
18 | print "starting"
19 | while running:
20 | if switch < maxscreen:
21 | e32.ao_sleep(interval)
22 | image = graphics.screenshot()
23 | switch = switch + 1
24 | filename="e:\\python\\picture"+str(switch)+".jpg"
25 | image.save(filename,quality=25)
26 | else:
27 | print "done"
28 | quit()
29 |
--------------------------------------------------------------------------------
/Different Examples/simpleui-zipfile-creator.py:
--------------------------------------------------------------------------------
1 | import zipfile
2 | import e32
3 | import appuifw
4 | import os
5 |
6 | def zip(path, name):
7 | name=appuifw.query(u'name', 'text', u'New archive')
8 | c=os.listdir(path)
9 | z=zipfile.ZipFile('e:/'+name+'.zip', 'w', zf.ZIP_DEFLATED)
10 | for i in xrange(len(c)):
11 | if os.path.isdir(path+c[i])==1:pass
12 | else:
13 | print c[i]
14 | e32.ao_sleep(0.01)
15 | z.write(path+c[i],path[3:]+c[i])
16 | e32.ao_sleep(0.01)
17 | z.close()
18 | print 'e:/'+name+'.zip'
19 |
20 | zip('e:/0/', 'test')
--------------------------------------------------------------------------------
/Different Examples/text-colorifer-color-generation.py:
--------------------------------------------------------------------------------
1 | #
2 | #
3 | # screept by _killed_
4 | # http://killed.h2m.ru
5 | #
6 | #
7 | import appuifw,e32
8 | appuifw.app.body=t=appuifw.Text()
9 | r,g,b=0,0,0
10 | for r in xrange(0,255,25):
11 | for g in xrange(0,255,25):
12 | for b in xrange(0,255,25):
13 | appuifw.app.body.color=r,g,b
14 | appuifw.app.title=unicode(str(r)+','+str(g)+','+str(b))
15 | t.add(u'#')
16 | e32.ao_sleep(0.01)
17 | t.add(u'\n')
18 | t.add(u''+str(r)+','+str(g)+','+str(b)+'\n')
19 | e32.Ao_lock().wait()
--------------------------------------------------------------------------------
/Different Examples/text-keep-screen-awake.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import e32
3 | import appuifw
4 | import os
5 |
6 | start_timer = e32.Ao_timer()
7 | screensaver_on = True
8 |
9 | def u(x):
10 | return x.decode('utf8')
11 |
12 | def handle_screensaver():
13 | global g_screensaver_on
14 | if screensaver_on:
15 | e32.reset_inactivity()
16 | start_timer.cancel()
17 | start_timer.after(4, handle_screensaver)
18 | else:
19 | start_timer.cancel()
20 |
21 | def bye():
22 | os.abort()
23 |
24 | def main():
25 | body.color = (0,0,255)
26 | body.set(u"\n Your Screensaver now is disable. Do not close this application if you still want the Screensaver disable.\n\n To close this app, please select 'Close Me' from menu.\n\n Compile by MightyGhost")
27 |
28 | def help():
29 | body.color = (0,0,255)
30 | body.set(u"1. This program is used to pause the screensaver that currently active. That mean,after this program is run, the screensaver will automatically turn off.\n2. The screensaver will be off until this program is close. This mean this program need to be run in background so it will continue working.\n3. The 'Close Me' is use to close this program because the 'Exit' did'nt work.\n4. This program tested on N95-1 and maybe will work on other S60v3 or FP1 phone.\n5. This program is used with other python application that need the screensaver off.")
31 | body.color = (255,0,0)
32 | body.add(u"\n\nAuto Return to Menu after 20seconds")
33 | e32.ao_sleep(20)
34 | main()
35 |
36 | def info():
37 | body.color = (200,0,0)
38 | body.set(u"\n Screensaver Killer")
39 | body.color = (0,150,0)
40 | body.add(u"\n Version 1.50")
41 | body.color = (150,0,0)
42 | body.add(u"\n by Mighty Ghost")
43 | body.color = (0,0,255)
44 | body.add(u"\n\n I create this application because I can't find any better solution for disable the screensaver.")
45 | body.color = (255,0,0)
46 | body.add(u"\n\n Have Fun All!")
47 | e32.ao_sleep(10)
48 | main()
49 |
50 | def quit():
51 | start_timer.cancel()
52 | app_lock.signal()
53 |
54 | body = appuifw.Text()
55 | main()
56 | appuifw.app.screen = "full"
57 | appuifw.app.body = body
58 | appuifw.app.exit_key_handler = quit
59 | appuifw.app.menu = [
60 | (u'Close Me!', bye),
61 | (u'Help', help),
62 | (u'About', info),
63 | (u"Exit", quit)]
64 | appuifw.app.title = u"ScreenSaver Killer";
65 |
66 | handle_screensaver()
67 | app_lock = e32.Ao_lock()
68 | app_lock.wait()
--------------------------------------------------------------------------------
/Different Examples/text-life-counter.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import e32
3 |
4 | def exit_key_handler():
5 | app_lock.signal()
6 |
7 | def info():
8 | appuifw.note(u'Calculate how long you lived until now', 'info')
9 |
10 | def start():
11 | z = appuifw.query(u'Enter your name:', 'text')
12 | round.set(u'\nDear ' + z + u'\n')
13 | y = appuifw.query(u'Birth date:', 'date')
14 | x = appuifw.query(u'Birth hour:', 'time')
15 | d = appuifw.query(u'Current date:', 'date')
16 | f = appuifw.query(u'Current hour:', 'time')
17 |
18 | round.add(u'Life is short, enjoy it while you can! :)\n')
19 | u = int((d + f) - (y + x))
20 | round.add(u'\nTime passed since you were born:\n\n')
21 | round.add(unicode(u) + u' second...\n')
22 | s = (u / 60)
23 | round.add(u'or ' + str(s) + u' minute...\n')
24 | i = (s / 60)
25 | round.add(u'or ' + str(i) + u' hour...\n')
26 | j = (i / 24)
27 | round.add(u'or ' + str(j) + u' day...\n')
28 | month = (j / 30)
29 | round.add(u'or ' + str(month) + u' month...\n')
30 | year = (j / 365)
31 | round.add(u'or ' + str(year) + u' year...\n')
32 | appuifw.app.screen = 'full'
33 |
34 |
35 | def exit():
36 | if (appuifw.query(u'Exit?', 'query') == 1):
37 | appuifw.app.set_exit()
38 |
39 | app_lock = e32.Ao_lock()
40 | round = appuifw.Text()
41 | round.font = u'LatinBold12'
42 | round.style = appuifw.HIGHLIGHT_ROUNDED
43 | round.color = 0
44 | round.set(u'Life Counter\n\nWith this app, you can learn how much time passed since the day you were born\n')
45 | appuifw.app.title = u'Life Counter'
46 | appuifw.app.screen = 'normal'
47 | appuifw.app.body = round
48 | appuifw.app.menu = [(u'Start',start), (u'Exit', exit)]
49 | appuifw.app.exit_key_handler = exit_key_handler
50 | app_lock.wait()
51 |
52 |
--------------------------------------------------------------------------------
/Different Examples/text-phone-info.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import e32
3 | import location
4 | import sysinfo
5 |
6 | appuifw.app.screen = 'normal'
7 | textbox = appuifw.Text()
8 | textbox.style = appuifw.STYLE_BOLD
9 | textbox.set(unicode('Mobile Info\n'))
10 | appuifw.app.body = textbox
11 | appuifw.app.title = u'Mobile Info'
12 |
13 | def imei():
14 | imei_number = sysinfo.imei()
15 | appuifw.note(imei_number)
16 | textbox.add(u'\nThe IMEI of phone is: \n' + imei_number + u'\n')
17 |
18 | def phone():
19 | (p_x, p_y) = sysinfo.display_pixels()
20 | textbox.add(u'\nSoftware version:\n' + sysinfo.sw_version())
21 | textbox.add(u'\nDisplay pixel size:\n' + str(p_x) + u'x' + str(p_y))
22 | textbox.add(u'\nSelected profile:\n' + sysinfo.active_profile())
23 | textbox.add(u'\nRingtone type:\n' + sysinfo.ring_type() + u'\n')
24 |
25 | def net():
26 | if not location.gsm_location():
27 | textbox.add(u'\nNetwork not available\n')
28 | return
29 | (mcc, mnc, lac, cellid) = location.gsm_location()
30 | si = sysinfo.signal_bars()
31 | textbox.add(u'\nMCC: ' + unicode(mcc))
32 | textbox.add(u'\nMNC: ' + unicode(mnc))
33 | textbox.add(u'\nLAC: ' + unicode(lac))
34 | textbox.add(u'\nCell id: ' + unicode(cellid))
35 | textbox.add(u'\n\nSignal strength: \n' + str(si) + u'\n')
36 |
37 | def battery():
38 | b = sysinfo.battery()
39 | textbox.add(u'\nBattery level: ' + str(b) + u'%\n')
40 |
41 | def memory():
42 | tram = sysinfo.total_ram() / 1048576
43 | trom = sysinfo.total_rom() / 1048576
44 | fram = sysinfo.free_ram() / 1048576
45 | textbox.add(u'\nTotal RAM:\n' + str(tram) + u' MB')
46 | textbox.add(u'\nFree RAM:\n' + str(fram) + u' MB')
47 | textbox.add(u'\nTotal ROM size is:\n' + str(trom) + u' MB')
48 | textbox.add(u'\n\nDrive free space in bytes:\n' + str(sysinfo.free_drivespace()) + u'\n')
49 |
50 | def quit():
51 | if (appuifw.query(unicode('Are you Sure?'), 'query')):
52 | app_lock.signal()
53 |
54 |
55 | appuifw.app.menu = [
56 | (unicode('Phone IMEI'), imei),
57 | (unicode('Phone Info'), phone),
58 | (unicode('Memory Info'), memory),
59 | (unicode('Network Info'), net),
60 | (unicode('Battery Info'), battery),
61 | (unicode('Exit'), quit)]
62 |
63 | appuifw.app.exit_key_handler = quit
64 | app_lock = e32.Ao_lock()
65 | app_lock.wait()
66 |
67 |
--------------------------------------------------------------------------------
/Different Examples/text-start-exe-program.py:
--------------------------------------------------------------------------------
1 | # calling a native symbian app from within script
2 |
3 | import appuifw
4 | import e32
5 |
6 | def startApp():
7 | try:
8 | # start_exe(filename, command [,wait ])
9 | # this starts the "Calendar" app on your phone
10 | e32.start_exe("z:\\sys\\bin\\Calendar.exe", "")
11 | except:
12 | appuifw.note(u"Something went wrong", "error")
13 |
14 |
15 | def exit_key_handler():
16 | script_lock.signal()
17 | appuifw.app.set_exit()
18 |
19 | script_lock = e32.Ao_lock()
20 |
21 | appuifw.app.title = u"App Start Test"
22 | appuifw.app.menu = [(u"Start Some App", startApp)]
23 | appuifw.app.exit_key_handler = exit_key_handler
24 |
25 | script_lock.wait()
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Nokia Examples/calendar.py:
--------------------------------------------------------------------------------
1 | import time, calendar
2 |
3 | now = time.time()
4 | cal = calendar.open()
5 |
6 |
7 | # add new appointment
8 | a = cal.add_appointment()
9 | a.content = 'urgent meeting'
10 | a.description = 'this is the description'
11 | a.set_time(now+3600, now+7200) # start and end time
12 | a.commit()
13 | print 'Calendar added'
14 | print '---------------------------------'
15 | todaytime = time.mktime((2008,7,14,0,0,0,0,0,0))
16 | daily_instances = cal.daily_instances(todaytime)
17 | print "daily instances:" + str(daily_instances)
18 |
19 | for entry_id in cal:
20 | ent=cal[entry_id]
21 |
22 | print 'id:%i'%ent.id
23 | for entry in daily_instances:
24 | if entry["id"] == ent.id:
25 | print 'content:%s'%ent.content
26 | print 'description:%s'%ent.description
27 | print 'originating:%d'%ent.originating
28 | print 'location:%s'%ent.location
29 | print 'start_time:%s'%time.ctime(ent.start_time)
30 | print 'end_time:%s'%time.ctime(ent.end_time)
31 | print 'repeat:'
32 | print ent.get_repeat()
33 | print '--------'
--------------------------------------------------------------------------------
/Nokia Examples/dumbfeedparser.py:
--------------------------------------------------------------------------------
1 | # A simple and limited RSS feed parser used in the RSS reader example.
2 |
3 | import re
4 | import urllib
5 |
6 | def parse(url):
7 | return parse_feed(urllib.urlopen(url).read())
8 |
9 | def parse_feed(text):
10 | feed={}
11 | items=[]
12 | currentitem=[{}]
13 |
14 | def clean_entities(text): return re.sub('&[#0-9a-z]+;','?',text)
15 | def clean_lf(text): return re.sub('[\n\t\r]',' ',text)
16 |
17 | def end_a(tag,content): write('LINK(%s)'%gettext())
18 | def start_item(tag,content):
19 | gettext()
20 | write(content)
21 | currentitem[0]={}
22 | def end_item(tag,content):
23 | items.append(currentitem[0])
24 | currentitem[0]={}
25 | def end_link(tag,content):
26 | if within('item'):
27 | currentitem[0]['link']=gettext()
28 | def end_description(tag,content):
29 | if within('item'):
30 | currentitem[0]['summary']=clean_entities(gettext())
31 | def end_title(tag,content):
32 | text=clean_lf(gettext()).strip()
33 | if within('item'):
34 | currentitem[0]['title']=text
35 | elif parentis('channel'):
36 | feed['title']=text
37 |
38 | tagre=re.compile('([^ \n\t]+)(.*)>(.*)',re.S)
39 | tagpath=[]
40 | textbuffer=[[]]
41 | assumed_encoding='latin-1'
42 | lines=text.split('<')
43 | def start_default(tag,content): write(content)
44 | def end_default(tag,content): pass
45 | def tag_default(tag,content): pass
46 | def write(text): textbuffer[0].append(text)
47 | def gettext():
48 | text=''.join(textbuffer[0])
49 | textbuffer[0]=[]
50 | return unicode(text,assumed_encoding)
51 | def current_tag(): return tagpath[-1]
52 | def current_path(): return '/'.join(tagpath)
53 | def within(tag): return tag in tagpath
54 | def parentis(tag): return current_tag()==tag
55 | for k in lines:
56 | m=tagre.match(k)
57 | if m:
58 | (tag,attributes,content)=m.groups()
59 | if tag.startswith('?'):
60 | continue
61 | if tag.startswith('/'):
62 | tagname=tag[1:]
63 | handler='end_%s'%tagname
64 | generic_handler=end_default
65 | if current_tag() != tagname:
66 | pass # Unbalanced tags, just ignore for now.
67 | del tagpath[-1]
68 | elif tag.endswith('/'):
69 | tagname=tag[0:-1]
70 | handler='tag_%s'%tagname
71 | generic_handler=tag_default
72 | else:
73 | tagname=tag
74 | handler='start_%s'%tagname
75 | generic_handler=start_default
76 | tagpath.append(tagname)
77 | locals().get(handler,generic_handler)(tagname,content)
78 | else:
79 | pass # Malformed line, just ignore.
80 |
81 | feed['entries']=items
82 | return feed
83 |
84 |
--------------------------------------------------------------------------------
/Nokia Examples/gui-example-1.py:
--------------------------------------------------------------------------------
1 | # Simple GUI example
2 |
3 | import socket
4 | import urllib
5 |
6 | import e32
7 | import appuifw
8 |
9 | # List of triplets "Name", "URL", "extension"
10 | choices=[(u"US Graphical Forecast", "http://weather.gov/forecasts/graphical/images/thumbnail/Thumbnail_Wx4_conus.png", "png"),
11 | (u"US Radar Image", "http://weather.gov/mdl/radar/rcm1pix_b.gif", "gif"),
12 | (u"US Satellite Image", "http://weather.gov/satellite_images/national.jpg", "jpg") ]
13 | tempfile_without_extension = "c:\\weather"
14 |
15 | old_title = appuifw.app.title
16 | appuifw.app.title = u"Weather forecast"
17 |
18 | L = [ x[0] for x in choices ]
19 | index = appuifw.popup_menu(L, u"Select picture")
20 |
21 | if index is not None:
22 | url = choices[index][1]
23 | ext = choices[index][2]
24 | tempfile = tempfile_without_extension + "." + ext
25 |
26 | try:
27 | print "Retrieving information..."
28 | urllib.urlretrieve(url, tempfile)
29 | lock=e32.Ao_lock()
30 | content_handler = appuifw.Content_handler(lock.signal)
31 | content_handler.open(tempfile)
32 | # Wait for the user to exit the image viewer.
33 | lock.wait()
34 | print "Image viewer finished."
35 | except IOError:
36 | print "Could not fetch the image."
37 | except:
38 | print "Could not open data received."
39 |
40 | appuifw.app.title = old_title
41 |
--------------------------------------------------------------------------------
/Nokia Examples/gui-example-2.py:
--------------------------------------------------------------------------------
1 | # Simple GUI example 2
2 |
3 | import socket
4 | import urllib
5 |
6 | import e32
7 | import appuifw
8 |
9 | choices =[(u"Los Angeles Intl Airport", "KLAX"),
10 | (u"Dallas/Fort Forth", "KDFW"),
11 | (u"New York/John F. Kennedy", "KJFK")]
12 | choices_labels = [x[0] for x in choices]
13 |
14 | weather_url_base = "http://weather.gov/data/current_obs/"
15 | tempfile = "c:\\weather.xml"
16 |
17 | def find_value(text, tag):
18 | "Find the value between and in text. Always returns a string"
19 | begin_tag = "<" + tag + ">"
20 | begin = text.find(begin_tag)
21 | end = text.find("" + tag + ">")
22 | if begin == -1 or end == -1:
23 | return ""
24 | begin += len(begin_tag)
25 | return text[begin:end]
26 |
27 | def handle_selection():
28 | index = lb.current()
29 | code = choices[index][1]
30 | weather_url = weather_url_base + code + ".xml"
31 | lb.set_list([u"Please wait..."])
32 | appuifw.note(u"Fetching "+ weather_url, 'info')
33 | try:
34 | urllib.urlretrieve(weather_url, tempfile)
35 | f = open(tempfile, 'r')
36 | weatherinfo = f.read()
37 | f.close()
38 | weather = find_value(weatherinfo, "weather")
39 | temperature_string = find_value(weatherinfo, "temperature_string")
40 | appuifw.popup_menu([(u"Weather", unicode(weather)),
41 | (u"Temperature", unicode(temperature_string))],
42 | unicode(code))
43 | except IOError:
44 | appuifw.note(u"Connection error to server", 'error')
45 | except:
46 | appuifw.note(u"Could not fetch information", 'error')
47 | lb.set_list(choices_labels)
48 |
49 | def handle_add():
50 | pass
51 |
52 | def handle_delete():
53 | pass
54 |
55 | def exit_key_handler():
56 | app_lock.signal()
57 |
58 | lb = appuifw.Listbox(choices_labels, handle_selection)
59 |
60 | old_title = appuifw.app.title
61 | appuifw.app.title = u"Weather report"
62 | appuifw.app.body = lb
63 | appuifw.app.menu = [(u"Add new item", handle_add),
64 | (u"Delete item", handle_delete)]
65 | appuifw.app.exit_key_handler = exit_key_handler
66 |
67 | app_lock = e32.Ao_lock()
68 | app_lock.wait()
69 |
70 | appuifw.app.title = old_title
71 |
--------------------------------------------------------------------------------
/Nokia Examples/key-viewer.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import graphics
3 | import e32
4 |
5 | keyboard_state={}
6 | last_keycode=0
7 |
8 | def draw_state():
9 | canvas.clear()
10 | canvas.text((0,12),u'Scancodes of pressed keys:',0x008000)
11 | canvas.text((0,24),u' '.join([unicode(k) for k in keyboard_state if keyboard_state[k]]))
12 | canvas.text((0,36),u' '.join([unicode(hex(k)) for k in keyboard_state if keyboard_state[k]]))
13 | canvas.text((0,48),u'Last received keycode:', 0x008000)
14 | canvas.text((0,60),u'%s (0x%x)'%(last_keycode,last_keycode))
15 |
16 | def callback(event):
17 | global last_keycode
18 | if event['type'] == appuifw.EEventKeyDown:
19 | keyboard_state[event['scancode']]=1
20 | elif event['type'] == appuifw.EEventKeyUp:
21 | keyboard_state[event['scancode']]=0
22 | elif event['type'] == appuifw.EEventKey:
23 | last_keycode=event['keycode']
24 | draw_state()
25 |
26 | canvas=appuifw.Canvas(event_callback=callback,
27 | redraw_callback=lambda rect:draw_state())
28 | appuifw.app.body=canvas
29 |
30 | lock=e32.Ao_lock()
31 | appuifw.app.exit_key_handler=lock.signal
32 | lock.wait()
33 |
--------------------------------------------------------------------------------
/Nokia Examples/simple-btconsole.py:
--------------------------------------------------------------------------------
1 | # A simple interactive console over Bluetooth.
2 |
3 | import socket
4 |
5 | class socket_stdio:
6 | def __init__(self,sock):
7 | self.socket=sock
8 | def read(self,n=1):
9 | return self.socket.recv(n)
10 | def write(self,str):
11 | return self.socket.send(str.replace('\n','\r\n'))
12 | def readline(self,n=None):
13 | buffer=[]
14 | while 1:
15 | ch=self.read(1)
16 | if ch == '\n' or ch == '\r': # return
17 | buffer.append('\n')
18 | self.write('\n')
19 | break
20 | if ch == '\177' or ch == '\010': # backspace
21 | self.write('\010 \010') # erase character from the screen
22 | del buffer[-1:] # and from the buffer
23 | else:
24 | self.write(ch)
25 | buffer.append(ch)
26 | if n and len(buffer)>=n:
27 | break
28 | return ''.join(buffer)
29 | def raw_input(self,prompt=""):
30 | self.write(prompt)
31 | return self.readline()
32 | def flush(self):
33 | pass
34 |
35 | sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
36 | # For quicker startup, enter here the address and port to connect to.
37 | target='' #('00:20:e0:76:c3:52',1)
38 | if not target:
39 | address,services=socket.bt_discover()
40 | print "Discovered: %s, %s"%(address,services)
41 | if len(services)>1:
42 | import appuifw
43 | choices=services.keys()
44 | choices.sort()
45 | choice=appuifw.popup_menu(
46 | [unicode(services[x])+": "+x for x in choices],u'Choose port:')
47 | target=(address,services[choices[choice]])
48 | else:
49 | target=(address,services.values()[0])
50 | print "Connecting to "+str(target)
51 | sock.connect(target)
52 | socketio=socket_stdio(sock)
53 | realio=(sys.stdout,sys.stdin,sys.stderr)
54 | (sys.stdout,sys.stdin,sys.stderr)=(socketio,socketio,socketio)
55 | import code
56 | try:
57 | code.interact()
58 | finally:
59 | (sys.stdout,sys.stdin,sys.stderr)=realio
60 | sock.close()
61 |
--------------------------------------------------------------------------------
/Nokia Examples/simple-camera.py:
--------------------------------------------------------------------------------
1 | import e32
2 | import appuifw
3 | import camera
4 | import key_codes
5 |
6 | def viewfinder_cb(img):
7 | appuifw.app.body.blit(img)
8 |
9 | def capture_cb():
10 | global photo
11 | photo=camera.take_photo()
12 | camera.stop_finder()
13 | lock.signal()
14 |
15 | old_body=appuifw.app.body
16 | appuifw.app.body=appuifw.Canvas()
17 | lock=e32.Ao_lock()
18 | photo=None
19 | camera.start_finder(viewfinder_cb)
20 | appuifw.app.body.bind(key_codes.EKeySelect, capture_cb)
21 | lock.wait()
22 | appuifw.app.body=old_body
23 |
24 | filename=u'c:\\photo.jpg'
25 | photo.save(filename)
26 | print "Photo taken and saved at:",filename
27 |
--------------------------------------------------------------------------------
/Nokia Examples/zipped/filebrowser.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/Nokia Examples/zipped/filebrowser.zip
--------------------------------------------------------------------------------
/Nokia Examples/zipped/gles_touch_demo.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/Nokia Examples/zipped/gles_touch_demo.zip
--------------------------------------------------------------------------------
/Nokia Examples/zipped/pyrepl.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/Nokia Examples/zipped/pyrepl.zip
--------------------------------------------------------------------------------
/Nokia Examples/zipped/scribble-touch.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/Nokia Examples/zipped/scribble-touch.zip
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_body_canvas.py:
--------------------------------------------------------------------------------
1 | # This script draws different shapes and text to the canvas
2 |
3 |
4 | import appuifw
5 | from appuifw import *
6 | import e32
7 | # import graphics
8 | from graphics import *
9 |
10 |
11 |
12 | # create an exit handler
13 | def quit():
14 | global running
15 | running=0
16 | appuifw.app.set_exit()
17 |
18 | # set the screen size to large
19 | appuifw.app.screen='large'
20 |
21 | # define an initial image (white)
22 | img=Image.new((176,208))
23 |
24 | # add different shapes and text to the image
25 | # coord. sequence x1,x2,y1,y2
26 | img.line((20,20,20,120),0xff00ee)
27 | img.rectangle((40,60,50,80),0xff0000)
28 | img.point((50.,150.),0xff0000,width=40)
29 | img.ellipse((100,150,150,180),0x0000ff)
30 | img.text((100,80), u'hello')
31 |
32 |
33 | # define your redraw function (that redraws the picture on and on)
34 | # in this case we redraw the image named img using the blit function
35 | def handle_redraw(rect):
36 | canvas.blit(img)
37 |
38 | running=1
39 |
40 | # define the canvas, include the redraw callback function
41 | canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
42 |
43 | # set the app.body to canvas
44 | appuifw.app.body=canvas
45 |
46 | app.exit_key_handler=quit
47 |
48 |
49 | # create a loop to redraw the the screen again and again until the exit button is pressed
50 | while running:
51 | # redraw the screen
52 | handle_redraw(())
53 | # yield needs to be here in order that key pressings can be noticed
54 | e32.ao_yield()
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_body_listbox.py:
--------------------------------------------------------------------------------
1 | # do not call "print" statement on listbox app, it causes rendering issues
2 | # it is recommended to use "print" statements only for debugging purposes
3 |
4 | import appuifw
5 | import e32
6 |
7 | def exit_key_handler():
8 | app_lock.signal()
9 |
10 | # define a callback function
11 | def shout():
12 | index = lb.current()
13 | #print index
14 | #print entries[index]
15 | appuifw.note(unicode(index) + "\n" +unicode(entries[index]))
16 |
17 | # create your content list of your listbox including the icons to be used for each entry
18 | entries = [u"Signal",u"Battery"]
19 | lb = appuifw.Listbox(entries,shout)
20 |
21 | # create an Active Object
22 | app_lock = e32.Ao_lock()
23 |
24 | # create an instance of appuifw.Listbox(), include the content list "entries" and the callback function "shout"
25 | # and set the instance of Listbox now as the application body
26 | appuifw.app.body = lb
27 |
28 |
29 | appuifw.app.exit_key_handler = exit_key_handler
30 | app_lock.wait()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_body_text.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import e32
3 |
4 | def exit_key_handler():
5 | app_lock.signal()
6 |
7 | # create an instance of appuifw.Text()
8 | round = appuifw.Text()
9 | # change the style of the text
10 | round.style = appuifw.STYLE_UNDERLINE
11 | # set the text to 'hello'
12 | round.set(u'hello')
13 |
14 | # put the screen size to full screen
15 | appuifw.app.screen='full'
16 |
17 | # create an Active Object
18 | app_lock = e32.Ao_lock()
19 |
20 | # set the application body to Text
21 | # by handing over "round" which is an instance of appuifw.Text() as definded above
22 | appuifw.app.body = round
23 |
24 | appuifw.app.exit_key_handler = exit_key_handler
25 | app_lock.wait()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_menu.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import e32
3 |
4 | def exit_key_handler():
5 | app_lock.signal()
6 |
7 |
8 | # create the callback functions for the application menu and its submenus
9 | def item1():
10 | round.set(u'item one was selected')
11 |
12 | def subitem1():
13 | round.set(u'subitem one was selected')
14 |
15 | def subitem2():
16 | round.set(u'subitem two was selected')
17 |
18 |
19 | app_lock = e32.Ao_lock()
20 | round = appuifw.Text()
21 | round.set(u'press options')
22 | appuifw.app.screen='large'
23 | appuifw.app.body = round
24 |
25 | # create the application menu including submenus
26 | appuifw.app.menu = [(u"item 1", item1),
27 | (u"Submenu 1", ((u"sub item 1", subitem1),
28 | (u"sub item 2", subitem2)))]
29 |
30 |
31 | appuifw.app.exit_key_handler = exit_key_handler
32 | app_lock.wait()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_screen.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | import e32
3 |
4 | def exit_key_handler():
5 | app_lock.signal()
6 |
7 |
8 | round = appuifw.Text()
9 | round.set(u'hello')
10 |
11 | # put the application screen size to full screen
12 | appuifw.app.screen='full' #(a full screen)
13 |
14 | # other options:
15 | #appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)
16 | #appuifw.app.screen='large' #(only softkeys visible)
17 |
18 |
19 |
20 | app_lock = e32.Ao_lock()
21 |
22 | appuifw.app.body = round
23 |
24 | appuifw.app.exit_key_handler = exit_key_handler
25 | app_lock.wait()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_skeleton.py:
--------------------------------------------------------------------------------
1 | # application skeleton (no main loop)
2 | # it is recommended to use "print" statements only for debugging purposes
3 |
4 |
5 | # 1. import all modules needed
6 | import appuifw
7 | import e32
8 |
9 |
10 | # 2. set the screen size to large
11 | appuifw.app.screen='large'
12 |
13 |
14 | # 3. create your application logic ...
15 | # e.g. create all your definitions (functions) or classes and build instances of them or call them etc.
16 | # ...... application logic ....
17 | application_body = appuifw.Text()
18 |
19 |
20 | # 4. create the application menu including submenus
21 | # create the callback functions for the application menu and its submenus
22 | def item1():
23 | #print "hello"
24 | appuifw.note(unicode("hello"))
25 |
26 | def subitem1():
27 | #print "aha"
28 | appuifw.note(unicode("aha"))
29 |
30 | def subitem2():
31 | #print "good"
32 | appuifw.note(unicode("good"))
33 |
34 | appuifw.app.menu = [(u"item 1", item1),
35 | (u"Submenu 1", ((u"sub item 1", subitem1),
36 | (u"sub item 2", subitem2)))]
37 |
38 |
39 | # 5. create and set an exit key handler
40 | def exit_key_handler():
41 | app_lock.signal()
42 |
43 |
44 | # 6. set the application title
45 | appuifw.app.title = u"drawing"
46 |
47 |
48 | # 7. crate an active object
49 | app_lock = e32.Ao_lock()
50 |
51 |
52 | # 8. set the application body
53 | appuifw.app.body = application_body
54 |
55 | # 9. set exit key handler (right softkey) and application lock (so app won't exit)
56 | appuifw.app.exit_key_handler = exit_key_handler
57 | app_lock.wait()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_skeleton_with_mainloop.py:
--------------------------------------------------------------------------------
1 | # note - this approach is not preferable
2 |
3 | # 1. import all modules needed
4 | import appuifw
5 | import e32
6 |
7 | # 2. set the screen size to large
8 | appuifw.app.screen='large'
9 |
10 |
11 | # 3. create your application logic ...
12 | # e.g. create all your definitions (functions) or classes and build instances of them or call them etc.
13 | # ...... application logic ....
14 | running=1
15 |
16 |
17 | # 4. no application menu here neccessary
18 |
19 | # 5. create and set an exit key handler: when exit ley is pressed, the main loop stops going (because the variable running will be put to 0=
20 | def quit():
21 | global running
22 | running=0
23 |
24 | appuifw.app.exit_key_handler=quit
25 |
26 | # 6. set the application title
27 | appuifw.app.title = u"drawing"
28 |
29 | # 7. no active objects needed
30 |
31 | # 8. set the application body
32 | appuifw.app.body = appuifw.Text()
33 |
34 | # 9. create a main loop (e.g. redraw the the screen again and again)
35 | while running:
36 | # #put here things that need to be run through again and again
37 | # #e.g. redraw the screen:
38 | # handle_redraw(())
39 | # yield needs to be here so events can be noticed
40 | # without yield application won't work properly
41 | e32.ao_yield()
42 | e32.ao_sleep(0.2)
43 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/app_tabs_simple.py:
--------------------------------------------------------------------------------
1 | # This script creates tabs that let you switch between different applications
2 |
3 |
4 | import appuifw
5 | import e32
6 | from graphics import *
7 |
8 |
9 | # define application 1: text app
10 | app1 = appuifw.Text(u'Appliation o-n-e is on')
11 |
12 | # define application 2: text app
13 | app2 = appuifw.Text(u'Appliation t-w-o is on')
14 |
15 | # define application 3: text app
16 | app3 = appuifw.Text(u'Appliation t-h-r-e-e is on')
17 |
18 |
19 | def exit_key_handler():
20 | app_lock.signal()
21 |
22 | # create a tab handler that switches the application based on what tab is selected
23 | def handle_tab(index):
24 | global lb
25 | if index == 0:
26 | appuifw.app.body = app1 # switch to application 1
27 | if index == 1:
28 | appuifw.app.body = app2 # switch to application 2
29 | if index == 2:
30 | appuifw.app.body = app3 # switch to application 3
31 |
32 |
33 | # create an Active Object
34 | app_lock = e32.Ao_lock()
35 |
36 | # create the tabs with its names in unicode as a list, include the tab handler
37 | appuifw.app.set_tabs([u"One", u"Two", u"Three"],handle_tab)
38 |
39 | # set the title of the script
40 | appuifw.app.title = u'Tabs'
41 |
42 | # set app.body to app1 (for start of script)
43 | appuifw.app.body = app1
44 |
45 |
46 | appuifw.app.exit_key_handler = exit_key_handler
47 | app_lock.wait()
48 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ask_home.py:
--------------------------------------------------------------------------------
1 | import appuifw
2 | planets = [ u'Mars', u'Earth', u'Venus' ]
3 | prompt = u'Enter your home planet'
4 | index = appuifw.popup_menu(planets, prompt)
5 | appuifw.note(u'Hello ' + planets[index], u'info')
6 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_application_menu_descr.py:
--------------------------------------------------------------------------------
1 | # this script lets you create a simple application menu
2 |
3 | # NOTE:
4 | # press the options key in order to open the applicaion menu
5 | # when running the script!
6 |
7 | # imort appuifw and the e32 modules
8 | import appuifw
9 | import e32
10 |
11 | # define an exit handler
12 | def exit_key_handler():
13 | app_lock.signal()
14 |
15 |
16 | # create the "callback functions" for the application menu
17 | def item1():
18 | appuifw.note(u"Foo", "info")
19 |
20 | def item2():
21 | appuifw.note(u"Outch", "info")
22 |
23 |
24 | # create an active object
25 | app_lock = e32.Ao_lock()
26 |
27 | # create the application menu include the selectable options (one, two)
28 | # and the related callback functions (item1, item2)
29 | appuifw.app.menu = [(u"one", item1),
30 | (u"two", item2)]
31 |
32 |
33 | appuifw.app.exit_key_handler = exit_key_handler
34 |
35 | # start a scheduler
36 | app_lock.wait()
37 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_bluetooth_mobile_to_pc_descr.py:
--------------------------------------------------------------------------------
1 | # script that connects to the serial port of the PC
2 | # and lets you send characters to the PC
3 |
4 | import appuifw
5 | # import the module socket
6 | import socket
7 | import e32
8 |
9 | # function that handles the bluetooth connection:
10 | def bt_connect():
11 | global sock
12 | # create a bluetooth socket
13 | sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
14 | target=''# here you can give the bt address of the other mobile if you know it
15 | if not target:
16 | # scan for bluetooth devices
17 | address,services=socket.bt_discover()
18 | print "Discovered: %s, %s"%(address,services)
19 | if len(services)>1:
20 | choices=services.keys()
21 | choices.sort()
22 | # bring up a popup menu and show the available bt devices for selection
23 | choice=appuifw.popup_menu([unicode(services[x])+": "+x
24 | for x in choices],u'Choose port:')
25 | target=(address,services[choices[choice]])
26 | else:
27 | target=(address,services.values()[0])
28 | print "Connecting to "+str(target)
29 | # connect to the serial port of the PC
30 | sock.connect(target)
31 | print "OK."
32 |
33 | # call the text input field function
34 | bt_typetext()
35 |
36 | # define the textinput function
37 | def bt_typetext():
38 | global sock
39 | # create the text input field
40 | test = appuifw.query(u"Type words", "text", u"")
41 | # if cancel has been pressed, then quit the application otherwise send the character over bluetooth
42 | if test == None:
43 | exit_key_handler()
44 | else:
45 | # send the typed in characters over bluetooth to the PC
46 | sock.send(test)
47 | # call again the textinput field function to show the text input again
48 | bt_typetext()
49 |
50 | def exit_key_handler():
51 | script_lock.signal()
52 | appuifw.app.set_exit()
53 |
54 | appuifw.app.title = u"bt mob to PC"
55 |
56 | script_lock = e32.Ao_lock()
57 |
58 | appuifw.app.exit_key_handler = exit_key_handler()
59 |
60 | # call the function that handles the bluetooth connection
61 | bt_connect()
62 |
63 | script_lock.wait()
64 |
65 |
66 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_define_function_descr.py:
--------------------------------------------------------------------------------
1 | # defining a simple function
2 |
3 |
4 | import appuifw
5 |
6 | # a function is definded with: def nameoffunction():
7 | # be aware of the indentation! (4 x spacebar)
8 |
9 | def afunction():
10 | data = appuifw.query(u"Type a word:", "text")
11 | appuifw.note(u"The typed word was: " +data, "info")
12 |
13 |
14 | # a function is called with its name and brackets behind it
15 | afunction()
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_mms_sending_descr.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2007 Jurgen Scheible
2 | # this script lets you send an mms to another phone including text and an image
3 |
4 | import appuifw
5 | import messaging
6 |
7 | # create text input field
8 | data = appuifw.query(u"Type your name:", "text")
9 |
10 | # define the mobile number here where to send the MMS
11 | nbr = "123456" # change the mobile number here
12 |
13 | # define the text that the sms shall contain
14 | txt = u"Greetings from:" +data
15 |
16 |
17 | # image attachment: You must have an picture already available with the name picture1.jpg
18 | # inside the folder called Images on your memory card. ('e:\\Images\\picture1.jpg')
19 | # otherwise the script won't work. (use video or sound file instead of image)
20 |
21 | # send out the mms; include the mobile number, the text and the attachement to be sent
22 | messaging.mms_send(nbr, txt, attachment='e:\\Images\\picture1.jpg')
23 |
24 | # confirm with a pop-up note that the sms has been sent out
25 | appuifw.note(u"MMS sent", "info")
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_popup_menu_descr.py:
--------------------------------------------------------------------------------
1 | # simple pop-up menu
2 |
3 |
4 | import appuifw
5 |
6 | # create a list with the content of the pop-up note
7 | L = [u"Python", u"Symbian", u"Mlab"]
8 |
9 | # create the pop-up menu including the list of content and a label
10 | # -> appuifw.popup_menu(list , label)
11 | test = appuifw.popup_menu(L, u"Select + press OK:")
12 |
13 | # the variable test holds the indicator which list item (position in the list)
14 | # has been selected
15 | # trigger some action (here we print something)
16 | if test == 0 :
17 | appuifw.note(u"Python, yeah", "info")
18 | if test == 1 :
19 | appuifw.note(u"Symbian, ok", "info")
20 | if test == 2 :
21 | appuifw.note(u"Mlab, cool students", "info")
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_sms_receiving_descr.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script waits for an incoming sms, reads its
3 | # content and shows it inside a pop-up note
4 | # NOTE: PyS60 version 1.3.1 or higher is needed to run this script.
5 |
6 | #import the module inbox (that handles incoming sms things)
7 | import inbox
8 | import e32
9 |
10 | #create a function that does the content sms reading
11 | def read_sms(id):
12 | e32.ao_sleep(0.1)
13 | # create once more an instance of the inbox() class
14 | i=inbox.Inbox()
15 | # read the content out of the message that has just arrived
16 | sms_text = i.content(id)
17 | # display the content inside a pop-up note
18 | appuifw.note(u"sms content: " + sms_text , "info")
19 |
20 | # create an instance of the inbox() class
21 | i=inbox.Inbox()
22 | print "send now sms to this phone"
23 | # put the phone into waiting stage to wait for an incoming message
24 | i.bind(read_sms)
25 |
26 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_sms_sending_descr.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2005 Jurgen Scheible
2 | # this script lets you send an sms to 2 users at the same time.
3 |
4 |
5 | # import the messaging module
6 | import appuifw
7 | import messaging
8 |
9 | # create text input field
10 | data = appuifw.query(u"Type your name:", "text")
11 |
12 | # define the mobile numbers here
13 | nbr1 = "123456"
14 | nbr2 = "234567"
15 |
16 | # define the text that the sms shall contain
17 | txt = u"Greetings from:" +data
18 |
19 | # create a query with type: "query" -> appuifw.query(label, type)
20 | # by using an if statement one can check whether the user has pressed "ok" -> True or "cancel" -> False
21 | if appuifw.query(u"Send message to your 2 friends","query") == True:
22 | # send out the sms; include the mobile number and the text to be sent
23 | messaging.sms_send(nbr1, txt)
24 | messaging.sms_send(nbr2, txt)
25 |
26 | # confirm with a pop-up note that the sms has been sent out
27 | appuifw.note(u"Messages sent", "info")
28 | else:
29 | # in case the user had pressed "cancel", send a pop-up note that the messages have not been sent out
30 | appuifw.note(u"Well, your Messages are not sent then", "info")
31 |
32 |
33 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_soundrecorder_descr.py:
--------------------------------------------------------------------------------
1 | # Sound recording / playing script
2 |
3 | import appuifw
4 | import e32
5 | # import the audio module
6 | import audio
7 |
8 |
9 | # define a name of the file to be the sound file, incl. its full path
10 | filename = 'c:\\boo.wav'
11 |
12 | # define the recording part:
13 | def recording():
14 | global S
15 | # open the sound file to be ready for recording and set an instance (S) of it
16 | S=audio.Sound.open(filename)
17 | # do the recording (has to be stopped by closing() function below)
18 | S.record()
19 | print "Recording on! To end it, select stop from menu!"
20 |
21 | # define the playing part:
22 | def playing():
23 | global S
24 | try:
25 | # open the sound file to be ready for playing by setting an instance (S) of it
26 | S=audio.Sound.open(filename)
27 | # play the sound file
28 | S.play()
29 | print "Playing"
30 | except:
31 | print "Record first a sound!"
32 |
33 | # stopping of recording / playing and closing of the sound file
34 | def closing():
35 | global S
36 | S.stop()
37 | S.close()
38 | print "Stopped"
39 |
40 |
41 | def exit_key_handler():
42 | script_lock.signal()
43 | appuifw.app.set_exit()
44 |
45 |
46 | script_lock = e32.Ao_lock()
47 |
48 | appuifw.app.title = u"Sound recorder"
49 |
50 | # define the application menu
51 | appuifw.app.menu = [(u"play", playing),
52 | (u"record", recording),
53 | (u"stop", closing)]
54 |
55 | appuifw.app.exit_key_handler = exit_key_handler
56 | script_lock.wait()
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_text_input_1_descr.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2005 Jurgen Scheible
2 | # This script performs a query with a single-field dialog (text input field)
3 | # and displays the users input as a pop-up note
4 |
5 |
6 | # 1. import the application user interface framework module
7 | import appuifw
8 |
9 | # 2. , 3. create a text input field: appuifw.query(label, type) and variable
10 | data = appuifw.query(u"Type a word:", "text")
11 |
12 | # 4. create a pop-up note: appuifw.note(label, type)
13 | appuifw.note(u"The typed word was: " + data, "info")
14 |
15 |
16 |
17 | """ detailed description:
18 |
19 | 1. we import the "appuifw" module to handle UI widgets like text input fields and
20 | pop-up notes etc.
21 | 2. we create a single-field dialog (text input field) using the .query() function
22 | of the appuifw module.
23 | we include in the brackets 2 parameters:
24 | - label: as label we put the text u"Type a word:" (the u must be there because
25 | the phone understands only text declared as unicode, the high commas
26 | must be there because label must be given as a string)
27 | - type: as type we put "text". It declares the input field as text type
28 | (other possible types: "number", "date", "time", "query", "code")
29 | -> separate the the two parameters with a comma.
30 | 3. We create a variable called data, and by putting data = appui... we write
31 | the result of the text input field into this variable
32 | (after user has typed something when he/she runs the script)
33 |
34 | 4. We create a pop-up note using the .note() function of the appuifw module.
35 | we include in the brackets the 2 parameters:
36 | - label: as label we put the text u"The typed word was: " + data
37 | This is the text that will appear in the pop-up note. Again the text
38 | must be given as a string in highcommas.
39 | But our pop-up note shall also inculde the result that the user
40 | has typed in, therefore we add the content of our variable data to our label
41 | string by writing + data (adding the content of a variable to a string)
42 | - type: as type we put "info". It declares the pop-up note as info. This puts
43 | an exclamationmark in the pop-up note (other possible types: "error","conf")
44 | -> again, separate the the two parameters with a comma.
45 |
46 | """
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_text_to_speech_1_descr.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script performs a query with a single-field dialog (text input field)
3 | # and lets the phone speak out the text (text to speech) that the users have typed in
4 |
5 | # NOTE: this script runs only with Python S60 version 3.1.14 or above
6 | # NOTE: this script doesn't work on all S60 phones neccessarily. Check your phone model if it has text to speech capability at all
7 |
8 |
9 | # import the module called audio
10 | import appuifw
11 | import audio
12 |
13 | # trigger a text input-field to let the user type a word
14 | text = appuifw.query(u"Type few words:", "text")
15 | # the phone speaks out the text that you have just typed (you can hear it through the loudspeakers of your phone)
16 | audio.say(text)
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_text_to_speech_2_descr.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script waits for an incoming sms, reads its
3 | # content and shows it inside a pop-up note
4 | # NOTE: PyS60 version 1.3.14 or higher is needed to run this script.
5 |
6 | import inbox
7 | import e32
8 | import audio
9 |
10 | #create a function that does the reading of the content of the sms
11 | def read_sms(id):
12 | e32.ao_sleep(0.1)
13 | # read the content out of the message that has just arrived
14 | sms_text = i.content(id)
15 | # the phone speaks out the text that just arrived by sms (you can hear it through the loudspeakers of your phone)
16 | audio.say(sms_text)
17 |
18 | # create an instance of the inbox() class
19 | i=inbox.Inbox()
20 | print "send now sms to this phone"
21 | # put the phone into waiting stage to wait for an incoming message
22 | i.bind(read_sms)
23 |
24 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_use_of_keys_descr.py:
--------------------------------------------------------------------------------
1 | # use keyboard keys Arrow up,down,lefet,right, 1 and * to trigger pop-up note
2 |
3 | import appuifw
4 | import e32
5 | from key_codes import *
6 |
7 | # you can use this class as a chunk as it is.
8 | class Keyboard(object):
9 | def __init__(self,onevent=lambda:None):
10 | self._keyboard_state={}
11 | self._downs={}
12 | self._onevent=onevent
13 | def handle_event(self,event):
14 | if event['type'] == appuifw.EEventKeyDown:
15 | code=event['scancode']
16 | if not self.is_down(code):
17 | self._downs[code]=self._downs.get(code,0)+1
18 | self._keyboard_state[code]=1
19 | elif event['type'] == appuifw.EEventKeyUp:
20 | self._keyboard_state[event['scancode']]=0
21 | self._onevent()
22 | def is_down(self,scancode):
23 | return self._keyboard_state.get(scancode,0)
24 | def pressed(self,scancode):
25 | if self._downs.get(scancode,0):
26 | self._downs[scancode]-=1
27 | return True
28 | return False
29 |
30 | # set and instance of Keyboard (so you can use all the functions of
31 | # that class later in the script by typing e.g. keyboard.pressed...)
32 | keyboard=Keyboard()
33 |
34 | # define the function that lets the application quit
35 | def quit():
36 | global running
37 | running=0
38 | appuifw.app.set_exit()
39 |
40 | running=1
41 |
42 | appuifw.app.screen='normal'
43 |
44 | # use the appuifw.Canvas function and as "event_callback" put "
45 | # keyboard.handle_event", a function which does the keyboard scan
46 | canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)
47 |
48 | # set the application body to canvas
49 | appuifw.app.body=canvas
50 |
51 | appuifw.app.exit_key_handler=quit
52 |
53 | # create a loop which the script runs all the time through to check whether a
54 | # key has been pressed.
55 | while running:
56 | # check if the left arrow key has been pressed
57 | if keyboard.pressed(EScancodeLeftArrow):
58 | appuifw.note(u"Arrow left", "info")
59 | # check if the right arrow key has been pressed
60 | if keyboard.pressed(EScancodeRightArrow):
61 | appuifw.note(u"Arrow right", "info")
62 |
63 |
64 | if keyboard.pressed(EScancodeDownArrow):
65 | appuifw.note(u"Arrow down", "info")
66 |
67 |
68 | if keyboard.pressed(EScancodeUpArrow):
69 | appuifw.note(u"Arrow up", "info")
70 |
71 | if keyboard.pressed(EScancodeSelect):
72 | appuifw.note(u"Select", "info")
73 |
74 | if keyboard.pressed(EScancode1):
75 | appuifw.note(u"1", "info")
76 |
77 | if keyboard.pressed(EScancodeStar):
78 | appuifw.note(u"*", "info")
79 |
80 | e32.ao_yield()
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/ex_video_download_descr.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 | import e32
4 | # import urllib
5 | import urllib
6 |
7 | print "press options"
8 |
9 | # function that handles the fetching and the playing of the video
10 | def fetching():
11 | # define the url where the video file is located on the server
12 | url = "http://www.leninsgodson.com/courses/pys60/resources/vid001.3gp"
13 | # define the loction on the phone where the fetched video file shall be stored
14 | tempfile = "c:\\video01.3gp"
15 | try:
16 | print "Retrieving information..."
17 | # fetch down the video and store it to you hard drive
18 | urllib.urlretrieve(url, tempfile)
19 | # create an active object before playin the video
20 | lock=e32.Ao_lock()
21 | # a content handler handles the playing of the video
22 | # load the content handler and tell to release the active object after the video has finnished playing (lock.signal)
23 | content_handler = appuifw.Content_handler(lock.signal)
24 | # open the video via the content handler. It will start playing automatically
25 | content_handler.open(tempfile)
26 | # Wait for the user to exit the image viewer.
27 | lock.wait()
28 | print "Video viewing finished."
29 | print "press options or exit."
30 | except IOError:
31 | print "Could not fetch the image."
32 | except:
33 | print "Could not open data received."
34 |
35 | # define the application menu with one choice "get video" and call the fetching video
36 | def main_menu_setup():
37 | appuifw.app.menu = [(u"get video", fetching)]
38 |
39 | def exit_key_handler():
40 | global script_lock
41 | script_lock.signal()
42 | appuifw.app.set_exit()
43 |
44 | script_lock = e32.Ao_lock()
45 |
46 | appuifw.app.title = u"Get video"
47 |
48 | # call the application menu function
49 | main_menu_setup()
50 |
51 | appuifw.app.exit_key_handler = exit_key_handler
52 | script_lock.wait()
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/image_rotation_descr.py:
--------------------------------------------------------------------------------
1 | import camera
2 | # import from graphics all functions
3 | from graphics import *
4 | # import all functions of appuifw -> means we can leave the "appuifw" away when calling its funtions
5 | # because they are known now by this script by their name (namespace issue)
6 | # so instead of using appuifw.app.body = ... we can do now use app.body = ...
7 | from appuifw import *
8 | import e32
9 | import key_codes
10 | import time
11 |
12 | def exit_key_callback():
13 | global running
14 | running=0
15 | lock.signal()
16 |
17 | # get a photo in using the camera function
18 | def getphoto_callback():
19 | global photo
20 | photo=camera.take_photo(size=(160,120))
21 | # release the active object scheduler
22 | lock.signal()
23 |
24 | # rotatate the photo and set "photo" newly
25 | def rotate_left_callback():
26 | global photo
27 | photo=photo.transpose(ROTATE_90)
28 | # release the active object scheduler
29 | lock.signal()
30 |
31 | # rotatate the photo and set "photo" newly
32 | def rotate_right_callback():
33 | global photo
34 | photo=photo.transpose(ROTATE_270)
35 | # release the active object scheduler
36 | lock.signal()
37 |
38 | # reopen the photo and set "photo" newly (afer the timecode has been printed on the photo)
39 | def load_callback():
40 | global photo
41 | photo=Image.open('e:\\photo.jpg')
42 | # release the active object scheduler
43 | lock.signal()
44 |
45 | # label the photo with the time and date
46 | def save_callback():
47 | photo.text((0,60),unicode(time.asctime()),fill=0xffff00)
48 | # save the photo with the time imprinted
49 | photo.save('e:\\photo.jpg')
50 | # release the active object scheduler
51 | lock.signal()
52 |
53 | def refresh(rect):
54 | # clear screen to black
55 | c.clear(0)
56 | # draw the photo there
57 | c.blit(photo)
58 | # print some explanatory white text
59 | c.text((10,10),u'Select to take picture', fill=0xffffff)
60 | c.text((10,20),u'Left/Right to rotate', fill=0xffffff)
61 | c.text((10,30),u'Down to save', fill=0xffffff)
62 | c.text((10,40),u'Up to load', fill=0xffffff)
63 |
64 | # create an initial image and store it to photo
65 | photo=Image.new((160,120))
66 | # clear the photo to black
67 | photo.clear(0)
68 |
69 | # create the canvas
70 | c=Canvas(redraw_callback=refresh)
71 | app.body=c
72 | app.exit_key_handler=exit_key_callback
73 |
74 | # bind certain keys to certain callback functions
75 | c.bind(key_codes.EKeySelect, getphoto_callback)
76 | c.bind(key_codes.EKeyLeftArrow, rotate_left_callback)
77 | c.bind(key_codes.EKeyRightArrow, rotate_right_callback)
78 | c.bind(key_codes.EKeyDownArrow, save_callback)
79 | c.bind(key_codes.EKeyUpArrow, load_callback)
80 |
81 | running=1
82 | # create an active object
83 | lock=e32.Ao_lock()
84 | while running:
85 | # draw the screen again and again
86 | refresh(())
87 | # Wait for something to happen (start a scheduler)
88 | lock.wait()
89 |
90 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/codes with more description/read_write_settings_to_OS_descr.py:
--------------------------------------------------------------------------------
1 | # This script lets you write settings into a file on the OS and also lets you read them
2 | # in this case I store 2 variables, each with a certain value.
3 |
4 |
5 | # import os is needed to create a new directory or check whether a directory exists
6 | import os
7 |
8 |
9 | def write_settings():
10 | # write your settings:
11 | # define the directory where you want to store your settings
12 | CONFIG_DIR='e:/mynewfolder'
13 | # define the settings file
14 | CONFIG_FILE=os.path.join(CONFIG_DIR,'mysettings.txt')
15 | # make sure the settings file exists (created here when running the script for the first time).
16 | if not os.path.isdir(CONFIG_DIR):
17 | os.makedirs(CONFIG_DIR)
18 | CONFIG_FILE=os.path.join(CONFIG_DIR,'mysettings.txt')
19 | # your settings:
20 | value1 = 'man'
21 | value2 = 3.15
22 | # create an empty dictionary (to store your values attached to variables)
23 | config={}
24 | # attach value1 with variable1 and write them into the dictonary: {'variable1':'man'}
25 | config['variable1']= value1
26 | # attach value2 with variable2 and add them into the dictonary: {'variable1':'man' , 'variable2':'woman'}
27 | config['variable2']= value2
28 | # HINT: you can add here more variables and attach values to them freely as you wish.
29 | # config['...']= ....
30 | # open the your "settings" file in "write mode" where to store the dictionary
31 | f=open(CONFIG_FILE,'wt')
32 | # write the dictinary into into the settings file
33 | f.write(repr(config))
34 | f.close()
35 |
36 |
37 | def read_settings():
38 | # read your settings:
39 | # define the settings file where to read from
40 | CONFIG_FILE='e:/mynewfolder/mysettings.txt'
41 | try:
42 | # open the settings file in "read mode"
43 | f=open(CONFIG_FILE,'rt')
44 | try:
45 | # read the file
46 | content = f.read()
47 | # separate the content
48 | config=eval(content)
49 | f.close()
50 | # get the value that is attached to the variable
51 | value1=config.get('variable1','')
52 | value2=config.get('variable2','')
53 | print value1
54 | print value2
55 | except:
56 | print 'can not read file'
57 | except:
58 | print 'can not open file'
59 |
60 | # call the write settings function
61 | write_settings()
62 |
63 | # call the read settings function
64 | read_settings()
65 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_application_menu.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # this script lets you create a simple application menu
3 |
4 | # NOTE:
5 | # press the options key in order to open the applicaion menu
6 | # when running the script!
7 |
8 |
9 | import appuifw, e32
10 |
11 |
12 | def item1():
13 | appuifw.note(u"Foo", "info")
14 |
15 | def item2():
16 | appuifw.note(u"Outch", "info")
17 |
18 | def quit():
19 | app_lock.signal()
20 |
21 | appuifw.app.menu = [(u"one", item1),
22 | (u"two", item2)]
23 |
24 | appuifw.app.exit_key_handler = quit
25 | app_lock = e32.Ao_lock()
26 | app_lock.wait()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_camera_viewfinder.py:
--------------------------------------------------------------------------------
1 | import e32, camera, appuifw, key_codes
2 |
3 | def finder_cb(im):
4 | canvas.blit(im)
5 |
6 | def take_picture():
7 | camera.stop_finder()
8 | pic = camera.take_photo(size = (640,480))
9 | w,h = canvas.size
10 | canvas.blit(pic,target=(0, 0, w, 0.75 * w), scale = 1)
11 | pic.save('e:\\Images\\picture1.jpg')
12 |
13 | def quit():
14 | camera.stop_finder()
15 | app_lock.signal()
16 |
17 | canvas = appuifw.Canvas()
18 | appuifw.app.body = canvas
19 |
20 | camera.start_finder(finder_cb)
21 | canvas.bind(key_codes.EKeySelect, take_picture)
22 |
23 | appuifw.app.title = u"My Camera"
24 | appuifw.app.exit_key_handler = quit
25 | app_lock = e32.Ao_lock()
26 | app_lock.wait()
27 |
28 |
29 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_extended_use_of_keys.py:
--------------------------------------------------------------------------------
1 |
2 | # use button Arrow up,down,lefet,right, 1 and * to trigger pop-up note
3 | # use button 3 to trigger an text input field and button # to show the result
4 |
5 | import appuifw
6 | from appuifw import *
7 | import e32
8 | from key_codes import *
9 |
10 |
11 | class Keyboard(object):
12 | def __init__(self,onevent=lambda:None):
13 | self._keyboard_state={}
14 | self._downs={}
15 | self._onevent=onevent
16 | def handle_event(self,event):
17 | if event['type'] == appuifw.EEventKeyDown:
18 | code=event['scancode']
19 | if not self.is_down(code):
20 | self._downs[code]=self._downs.get(code,0)+1
21 | self._keyboard_state[code]=1
22 | elif event['type'] == appuifw.EEventKeyUp:
23 | self._keyboard_state[event['scancode']]=0
24 | self._onevent()
25 | def is_down(self,scancode):
26 | return self._keyboard_state.get(scancode,0)
27 | def pressed(self,scancode):
28 | if self._downs.get(scancode,0):
29 | self._downs[scancode]-=1
30 | return True
31 | return False
32 |
33 | keyboard=Keyboard()
34 |
35 |
36 |
37 | def quit():
38 | global running
39 | running=0
40 | appuifw.app.set_exit()
41 |
42 |
43 |
44 | running=1
45 |
46 | appuifw.app.screen='full'
47 |
48 | canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)
49 | appuifw.app.body=canvas
50 |
51 | app.exit_key_handler=quit
52 |
53 |
54 |
55 |
56 | while running:
57 |
58 | if keyboard.pressed(EScancodeLeftArrow):
59 | appuifw.note(u"Arrow left", "info")
60 |
61 | if keyboard.pressed(EScancodeRightArrow):
62 | appuifw.note(u"Arrow right", "info")
63 |
64 |
65 | if keyboard.pressed(EScancodeDownArrow):
66 | appuifw.note(u"Arrow down", "info")
67 |
68 |
69 | if keyboard.pressed(EScancodeUpArrow):
70 | appuifw.note(u"Arrow up", "info")
71 |
72 | if keyboard.pressed(EScancodeSelect):
73 | appuifw.note(u"Select", "info")
74 |
75 | if keyboard.pressed(EScancode1):
76 | appuifw.note(u"1", "info")
77 |
78 | if keyboard.pressed(EScancodeStar):
79 | appuifw.note(u"*", "info")
80 |
81 | if keyboard.pressed(EScancode3):
82 | data = appuifw.query(u"Type your name:", "text")
83 |
84 | if keyboard.pressed(EScancodeHash):
85 | appuifw.note(u"Your name is: " +data, "info")
86 |
87 | e32.ao_yield()
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_graphics_drawing.py:
--------------------------------------------------------------------------------
1 | # Graphics drawing
2 | # use button Arrow up,down,left,right, to move the colour point
3 |
4 | import appuifw, graphics, e32
5 | from key_codes import *
6 |
7 |
8 | class Keyboard(object):
9 | def __init__(self,onevent=lambda:None):
10 | self._keyboard_state={}
11 | self._downs={}
12 | self._onevent=onevent
13 | def handle_event(self,event):
14 | if event['type'] == appuifw.EEventKeyDown:
15 | code=event['scancode']
16 | if not self.is_down(code):
17 | self._downs[code]=self._downs.get(code,0)+1
18 | self._keyboard_state[code]=1
19 | elif event['type'] == appuifw.EEventKeyUp:
20 | self._keyboard_state[event['scancode']]=0
21 | self._onevent()
22 | def is_down(self,scancode):
23 | return self._keyboard_state.get(scancode,0)
24 | def pressed(self,scancode):
25 | if self._downs.get(scancode,0):
26 | self._downs[scancode]-=1
27 | return True
28 | return False
29 |
30 | keyboard=Keyboard()
31 |
32 | blobsize=30
33 | location_x = 100
34 | location_y = 100
35 | BLUE=0x0000ff
36 | RED=0xff0000
37 | running=1
38 |
39 | def handle_redraw(rect):
40 | canvas.blit(img)
41 |
42 | def quit():
43 | global running
44 | running=0
45 |
46 |
47 | canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=handle_redraw)
48 | appuifw.app.body=canvas
49 |
50 | appuifw.app.screen='full'
51 | w,h = canvas.size
52 | img=graphics.Image.new((w,h))
53 |
54 | appuifw.app.exit_key_handler=quit
55 |
56 | while running:
57 |
58 | img.clear(BLUE)
59 | img.point((location_x,location_y),RED,width=blobsize)
60 |
61 | handle_redraw(())
62 | e32.ao_yield()
63 |
64 | if keyboard.is_down(EScancodeLeftArrow):
65 | location_x = location_x - 1
66 |
67 | if keyboard.is_down(EScancodeRightArrow):
68 | location_x = location_x + 1
69 |
70 |
71 | if keyboard.is_down(EScancodeDownArrow):
72 | location_y = location_y + 1
73 |
74 |
75 | if keyboard.is_down(EScancodeUpArrow):
76 | location_y = location_y - 1
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_popup_menu.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2005 Jurgen Scheible
2 | # simple pop-up menu
3 |
4 | import appuifw
5 |
6 | L = [u"Python", u"Symbian", u"Mlab"]
7 |
8 | test = appuifw.popup_menu(L, u"Select + press OK:")
9 |
10 | if test == 0 :
11 | appuifw.note(u"Python, yeah", "info")
12 | elif test == 1 :
13 | appuifw.note(u"Symbian, ok", "info")
14 | elif test == 2 :
15 | appuifw.note(u"Mlab, cool students", "info")
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_soundrecorder.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # Sound recording / playing script
3 |
4 | import appuifw, e32, audio
5 |
6 | filename = 'e:\\boo.wav'
7 |
8 | def recording():
9 | global S
10 | S=audio.Sound.open(filename)
11 | S.record()
12 | print "Recording on! To end it, select stop from menu!"
13 |
14 | def playing():
15 | global S
16 | try:
17 | S=audio.Sound.open(filename)
18 | S.play()
19 | print "Playing"
20 | except:
21 | print "Record first a sound!"
22 |
23 | def closing():
24 | global S
25 | S.stop()
26 | S.close()
27 | print "Stopped"
28 |
29 | def quit():
30 | script_lock.signal()
31 | appuifw.app.set_exit()
32 |
33 | appuifw.app.menu = [(u"play", playing),
34 | (u"record", recording),
35 | (u"stop", closing)]
36 |
37 | appuifw.app.title = u"Sound recorder"
38 |
39 | appuifw.app.exit_key_handler = quit
40 | script_lock = e32.Ao_lock()
41 | script_lock.wait()
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_text_input_1.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2005 Jurgen Scheible
2 | # This script performs a query with a single-field dialog (text input field)
3 | # and displays the users input as a pop-up note
4 |
5 |
6 | import appuifw
7 |
8 | data = appuifw.query(u"Type a word:", "text")
9 |
10 | appuifw.note(u"The typed word was: " + data, "info")
11 |
12 |
13 |
14 |
15 | # NOTE: a text string must be defined as unicode
16 | # u"..."
17 | # The mobile can not diplay the text otherwise properly!
18 |
19 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_text_input_2.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 |
5 | data1 = appuifw.query(u"Type your first name:", "text")
6 |
7 | appuifw.note(u"Your first name is: " + data1, "info")
8 |
9 | data2 = appuifw.query(u"Type your surname:", "text")
10 |
11 | appuifw.note(u"Your surname is: " + data2, "info")
12 |
13 | appuifw.note(u"Your full name is: " + data1 +u" " + data2, "info")
14 |
15 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_text_to_speech_1.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script performs a query with a single-field dialog (text input field)
3 | # and lets the phone speak out the text (text to speech) that the users have typed in
4 | # NOTE: this script runs only with Python S60 version 3.1.14 or above
5 | # NOTE: this script doesn't work on all S60 phones neccessarily. Check your phone model if it has text to speech capability at all
6 |
7 | import appuifw
8 | import audio
9 |
10 | text = appuifw.query(u"Type a word:", "text")
11 | audio.say(text)
12 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_text_to_speech_2.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script waits for an incoming sms, reads its
3 | # content and shows it inside a pop-up note
4 | # NOTE: PyS60 version 1.3.14 or higher is needed to run this script.
5 |
6 | import inbox
7 | import e32
8 | import audio
9 |
10 | def read_sms(id):
11 | e32.ao_sleep(0.1)
12 | sms_text = i.content(id)
13 | audio.say(sms_text)
14 |
15 | i=inbox.Inbox()
16 | print "send now sms to this phone"
17 | i.bind(read_sms)
18 |
19 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_topwindow.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script allows to show a topwindow on the phone's screen
3 | # in which a blue square appears and on top of it a white square smaller in size.
4 | # Using the application menu the topwindow can be switched on and off.
5 | # NOTE: PyS60 version 1.3.14 or higher is needed to run this script.
6 |
7 | import topwindow
8 | import graphics
9 | import appuifw
10 | import e32
11 |
12 | screen = topwindow.TopWindow()
13 | img = graphics.Image.new((50,50))
14 | screen.add_image(img, (5,5,45,45))
15 | screen.size = (50, 50)
16 | screen.corner_type = 'square'
17 | screen.background_color = 0xff0000
18 | screen.shadow = 2
19 |
20 | def show_screen():
21 | screen.show()
22 |
23 | def hide_screen():
24 | screen.hide()
25 |
26 | def exit_key_handler():
27 | app_lock.signal()
28 |
29 | app_lock = e32.Ao_lock()
30 |
31 | appuifw.app.menu = [(u"show", show_screen),
32 | (u"hide", hide_screen)]
33 |
34 | appuifw.app.exit_key_handler = exit_key_handler
35 | app_lock.wait()
36 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/ex_use_of_keys.py:
--------------------------------------------------------------------------------
1 |
2 | # use keyboard keys Arrow up,down,lefet,right, 1 and * to trigger pop-up note
3 |
4 | import appuifw
5 | import e32
6 | from key_codes import *
7 |
8 |
9 | class Keyboard(object):
10 | def __init__(self,onevent=lambda:None):
11 | self._keyboard_state={}
12 | self._downs={}
13 | self._onevent=onevent
14 | def handle_event(self,event):
15 | if event['type'] == appuifw.EEventKeyDown:
16 | code=event['scancode']
17 | if not self.is_down(code):
18 | self._downs[code]=self._downs.get(code,0)+1
19 | self._keyboard_state[code]=1
20 | elif event['type'] == appuifw.EEventKeyUp:
21 | self._keyboard_state[event['scancode']]=0
22 | self._onevent()
23 | def is_down(self,scancode):
24 | return self._keyboard_state.get(scancode,0)
25 | def pressed(self,scancode):
26 | if self._downs.get(scancode,0):
27 | self._downs[scancode]-=1
28 | return True
29 | return False
30 |
31 | keyboard=Keyboard()
32 |
33 | def quit():
34 | global running
35 | running=0
36 | appuifw.app.set_exit()
37 |
38 | running=1
39 |
40 | appuifw.app.screen='normal'
41 |
42 | canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=None)
43 | appuifw.app.body=canvas
44 |
45 | appuifw.app.exit_key_handler=quit
46 |
47 |
48 | while running:
49 |
50 | if keyboard.pressed(EScancodeLeftArrow):
51 | appuifw.note(u"Arrow left", "info")
52 |
53 | if keyboard.pressed(EScancodeRightArrow):
54 | appuifw.note(u"Arrow right", "info")
55 |
56 |
57 | if keyboard.pressed(EScancodeDownArrow):
58 | appuifw.note(u"Arrow down", "info")
59 |
60 |
61 | if keyboard.pressed(EScancodeUpArrow):
62 | appuifw.note(u"Arrow up", "info")
63 |
64 | if keyboard.pressed(EScancodeSelect):
65 | appuifw.note(u"Select", "info")
66 |
67 | if keyboard.pressed(EScancode1):
68 | appuifw.note(u"1", "info")
69 |
70 | if keyboard.pressed(EScancodeStar):
71 | appuifw.note(u"*", "info")
72 |
73 | e32.ao_yield()
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/form.py:
--------------------------------------------------------------------------------
1 | # this script creates a form
2 |
3 | import appuifw
4 | import e32
5 |
6 | # create an Active Object
7 | app_lock = e32.Ao_lock()
8 |
9 |
10 | def forming():
11 | # create a list to be used in 'combo' selection mode
12 | model = [u'6600', u'6630', u'7610', u'N90', u'N70']
13 |
14 | # define the field list (consists of tuples: (label, type ,value)); label is a unicode string
15 | # type is one of the following strings: 'text', 'number', 'date', 'time',or 'combo'
16 | data = [(u'Mobile','text', u'Nokia'),(u'Model','combo', (model,0)),(u'Amount','number', 5),(u'Date','date'),(u'Time','time')]
17 |
18 | # set the view/edit mode of the form
19 | flags = appuifw.FFormEditModeOnly
20 |
21 | # creates the form
22 | f = appuifw.Form(data, flags)
23 |
24 | # make the form visible on the UI
25 | f.execute()
26 |
27 | def exit_key_handler():
28 | app_lock.signal()
29 |
30 | # set the title of the script
31 | appuifw.app.title = u'Form'
32 |
33 | # call the function that creates the form
34 | forming()
35 |
36 | appuifw.app.exit_key_handler = exit_key_handler
37 | app_lock.wait()
38 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/BT/ex_bluetooth_mobile_to_pc.py:
--------------------------------------------------------------------------------
1 | # script that connects to the serial port of the PC
2 | # and lets you send characters to the PC
3 |
4 | import appuifw
5 | import socket
6 | import e32
7 |
8 |
9 | def bt_connect():
10 | global sock
11 | sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
12 | target=''
13 | if not target:
14 | address,services=socket.bt_discover()
15 | print "Discovered: %s, %s"%(address,services)
16 | if len(services)>1:
17 | import appuifw
18 | choices=services.keys()
19 | choices.sort()
20 | choice=appuifw.popup_menu([unicode(services[x])+": "+x
21 | for x in choices],u'Choose port:')
22 | target=(address,services[choices[choice]])
23 | else:
24 | target=(address,services.values()[0])
25 | print "Connecting to "+str(target)
26 | sock.connect(target)
27 | print "OK."
28 |
29 | bt_typetext()
30 |
31 |
32 | def bt_typetext():
33 | global sock
34 | test = appuifw.query(u"Type words", "text", u"")
35 | if test == None:
36 | exit_key_handler()
37 | else:
38 | sock.send(test)
39 | bt_typetext()
40 |
41 | def exit_key_handler():
42 | script_lock.signal()
43 | appuifw.app.set_exit()
44 |
45 | appuifw.app.title = u"bt mob to PC"
46 |
47 | script_lock = e32.Ao_lock()
48 |
49 | appuifw.app.exit_key_handler = exit_key_handler()
50 |
51 | bt_connect()
52 |
53 | script_lock.wait()
54 |
55 |
56 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/BT/ex_bt_obex_phone_phone.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2007 Jurgen Scheible
2 |
3 | import camera,e32,socket,appuifw
4 |
5 | def start():
6 | image= camera.take_photo()
7 | appuifw.app.body=c=appuifw.Canvas()
8 | c.blit(image,scale=1)
9 | file=(u'e:\\Images\\picture1.jpg')
10 | image.save(file)
11 | device=socket.bt_obex_discover()
12 | address=device[0]
13 | channel=device[1][u'OBEX Object Push']
14 | socket.bt_obex_send_file(address,channel,file)
15 | appuifw.note(u"Picture sent","info")
16 |
17 | def quit():
18 | app_lock.signal()
19 | appuifw.app.set_exit()
20 |
21 | app_lock = e32.Ao_lock()
22 | appuifw.app.title = u"Bluetooth photo"
23 | appuifw.app.menu = [(u"Start", start),(u"Exit",quit)]
24 | app_lock.wait()
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/BT/obex_client.py:
--------------------------------------------------------------------------------
1 | # this file lets 2 phones exchange a file via OBEX
2 | # this file is the client side
3 | # the corresponding server side file is called obex_server.py
4 |
5 | from socket import *
6 | import appuifw
7 | import e32
8 |
9 | # JL: you don't need a socket for this!
10 | ## create socket
11 | #s=socket(AF_BT,SOCK_STREAM)
12 |
13 | # scan for other phones offering OBEX service
14 | addr,services=bt_obex_discover()
15 | print "Discovered: %s, %s"%(addr,services)
16 | if len(services)>0:
17 | choices=services.keys()
18 | choices.sort()
19 | choice=appuifw.popup_menu([unicode(services[x])+": "+x
20 | for x in choices],u'Choose port:')
21 | port=services[choices[choice]]
22 | else:
23 | port=services[services.keys()[0]]
24 | address=(addr,port)
25 |
26 | # create file to be sent
27 | send_path = u"c:\\test.txt"
28 | f=open(send_path, 'w')
29 | f.write("hello")
30 | f.close() # NOTE: parens were missing here before!
31 |
32 | # send file via OBEX
33 | print "Sending file %s to host %s port %s"%(send_path, address[0], address[1])
34 | bt_obex_send_file(address[0], address[1], send_path)
35 | print "File sent."
36 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/BT/obex_server.py:
--------------------------------------------------------------------------------
1 | # This script lets 2 phones exchange a file via OBEX.
2 | # This is the server, the corresponding client is obex_client.py
3 | from socket import *
4 | import appuifw
5 |
6 | # Create a bluetooth socket in waiting state to be connected to
7 | s = socket(AF_BT, SOCK_STREAM)
8 | port = bt_rfcomm_get_available_server_channel(s)
9 | print "Binding service to port %s"%port
10 | s.bind(("", port))
11 | print "Service bound."
12 |
13 | # Advertise the OBEX service, so it can be seen by other phones
14 | service_name=u"Test OBEX service"
15 |
16 | print "Advertising service as %s"%repr(service_name)
17 | bt_advertise_service(service_name, s, True, OBEX)
18 |
19 | try:
20 | print "Setting security to AUTH."
21 | set_security(s, AUTH)
22 |
23 | receive_path = u"c:\\obex.txt"
24 | print "Receiving file."
25 | bt_obex_receive(s, receive_path)
26 | print "File received."
27 |
28 | import e32
29 | e32.ao_sleep(1)
30 | finally:
31 | print "Stopping service advertising."
32 | bt_advertise_service(service_name, s, False, OBEX)
33 |
34 | print "Closing socket."
35 | s.close()
36 | print "Socket closed."
37 | print "Finished."
38 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/BT/rfcomm_client.py:
--------------------------------------------------------------------------------
1 | # this file lets 2 phones exchange data via RFCOMM
2 | # this file is the client side
3 | # the corresponding server side file is called rfcomm_server.py
4 |
5 | import socket
6 | import appuifw
7 | import e32
8 |
9 | class BTReader:
10 | def connect(self):
11 | self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
12 | addr,services=socket.bt_discover()
13 | print "Discovered: %s, %s"%(addr,services)
14 | if len(services)>0:
15 | import appuifw
16 | choices=services.keys()
17 | choices.sort()
18 | choice=appuifw.popup_menu([unicode(services[x])+": "+x
19 | for x in choices],u'Choose port:')
20 | port=services[choices[choice]]
21 | else:
22 | port=services[services.keys()[0]]
23 | address=(addr,port)
24 | print "Connecting to "+str(address)+"...",
25 | self.sock.connect(address)
26 | print "OK."
27 | def readline(self):
28 | line=[]
29 | while 1:
30 | ch=self.sock.recv(1)
31 | if(ch=='\n'):
32 | break
33 | line.append(ch)
34 | return ''.join(line)
35 | def close(self):
36 | self.sock.close()
37 |
38 | bt=BTReader()
39 | bt.connect()
40 | print "Received: "+bt.readline()
41 | bt.close()
42 |
43 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/BT/rfcomm_server.py:
--------------------------------------------------------------------------------
1 | # this file lets 2 phones exchange data via RFCOMM
2 | # this file is the server side
3 | # the corresponding client side file is called rfcomm_client.py
4 |
5 | from socket import *
6 | import appuifw
7 |
8 | server_socket = socket(AF_BT, SOCK_STREAM)
9 | p = bt_rfcomm_get_available_server_channel(server_socket)
10 | server_socket.bind(("", p))
11 | print "bind done"
12 | server_socket.listen(1)
13 | bt_advertise_service( u"jurgen", server_socket, True, RFCOMM)
14 | set_security(server_socket, AUTH)
15 | print "I am listening"
16 |
17 | # Note: Don't call .send or .recv on the server_socket!
18 | # Use the sock object returned by server_socket.accept().
19 | (sock,peer_addr) = server_socket.accept()
20 | print "Connection from %s"%peer_addr
21 | test = appuifw.query(u"Type words", "text", u"")
22 | sock.send(test+'\n')
23 | print "sending done"
24 | import e32
25 | # Allow time for data to be sent to work around a bug in the socket
26 | # module.
27 | e32.ao_sleep(1)
28 | sock.close()
29 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/ex_image_upload_to_database.py:
--------------------------------------------------------------------------------
1 | import httplib, urllib
2 | import e32
3 |
4 | def main_menu_setup():
5 | appuifw.app.menu = [(u"send file", senddata)]
6 |
7 | def quit():
8 | appuifw.app.set_exit()
9 |
10 |
11 | def senddata():
12 | dep = appuifw.query(u"Anotate:", "text")
13 | if dep == None:
14 | test1 = (u"...")
15 | else:
16 | test1 = (u""+dep)
17 |
18 | e32.ao_yield()
19 | f=open('e:\\picture.jpg','rt')
20 | test3 = f.read()
21 | f.close()
22 |
23 | params = urllib.urlencode({'data': test1, 'eggs': 0, 'bacon': test3})
24 | headers = {"Content-type": "application/x-www-form-urlencoded",
25 | "Accept": "text/plain"}
26 | e32.ao_yield()
27 | conn = httplib.HTTPConnection("www.leninsgodson.com")
28 | conn.request("POST", "/courses/pys60/php/insert_moblog.php", params, headers)
29 | response = conn.getresponse()
30 | conn.close()
31 | e32.ao_yield()
32 | appuifw.note(u"Data sent", "info")
33 |
34 |
35 | script_lock = e32.Ao_lock()
36 |
37 | main_menu_setup()
38 |
39 | script_lock.wait()
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/ex_setting_default_access_point.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2007 Jurgen Scheible
2 | # This script allows setting a default Access Point for connecting to the internet
3 | # which omits the task of always manually selecting an Access Point each time when you
4 | # open a Python script that connects to the internet.
5 |
6 | import appuifw, socket, urllib, e32
7 |
8 | def unset_accesspoint():
9 | f = open('e:\\apid.txt','w')
10 | f.write(repr(None))
11 | f.close()
12 | appuifw.note(u"Default access point is unset ", "info")
13 |
14 |
15 | def set_accesspoint():
16 | apid = socket.select_access_point()
17 | if appuifw.query(u"Set as default access point","query") == True:
18 | f = open('e:\\apid.txt','w')
19 | f.write(repr(apid))
20 | f.close()
21 | appuifw.note(u"Saved default access point ", "info")
22 | apo = socket.access_point(apid)
23 | socket.set_default_access_point(apo)
24 |
25 | def download():
26 | #---------------------- copy from here ---------------------------------------
27 | try:
28 | f=open('e:\\apid.txt','rb')
29 | setting = f.read()
30 | apid = eval(setting)
31 | f.close()
32 | if not apid == None :
33 | apo = socket.access_point(apid)
34 | socket.set_default_access_point(apo)
35 | else:
36 | set_accesspoint()
37 | except:
38 | set_accesspoint()
39 | #------------------------- copy till here --------------------------------------
40 | # and put it before the line of code in your script that invokes a connection to the internet
41 | # like here with urllib.urlretrieve(url, tempfile)
42 |
43 | # your own code here
44 | url = "http://www.leninsgodson.com/courses/pys60/resources/vid001.3gp"
45 | tempfile = 'e:\\Videos\\video.3gp'
46 | urllib.urlretrieve(url, tempfile)
47 | appuifw.note(u"Video downloaded" , "info")
48 |
49 |
50 | def quit():
51 | app_lock.signal()
52 | appuifw.app.set_exit()
53 |
54 | appuifw.app.menu = [(u"unset ap",unset_accesspoint),(u"download",download)]
55 | appuifw.app.exit_key_handler = quit
56 | app_lock = e32.Ao_lock()
57 | app_lock.wait()
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/ex_upload_file_to_url.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 |
3 | import httplib, urllib, e32
4 |
5 |
6 | def senddata():
7 | dep = appuifw.query(u"Anotate:", "text")
8 | if dep == None:
9 | test1 = (u"...")
10 | else:
11 | test1 = (u""+dep)
12 |
13 | params = urllib.urlencode({'data': test1, 'eggs': 0, 'bacon': 0})
14 | headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
15 | conn = httplib.HTTPConnection("www.leninsgodson.com")
16 | conn.request("POST", "/courses/pys60/php/set_text.php", params, headers)
17 | conn.close()
18 | e32.ao_yield()
19 | appuifw.note(u"Data sent", "info")
20 |
21 | def quit():
22 | script_lock.signal()
23 |
24 | appuifw.app.menu = [(u"send file", senddata)]
25 |
26 | appuifw.app.exit_key_handler = quit
27 | script_lock = e32.Ao_lock()
28 | script_lock.wait()
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/ex_upload_image_to_url.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # image upload to URL
3 |
4 | import appuifw,e32,httplib
5 |
6 |
7 | def upload_image_to_url():
8 |
9 | filename = 'e:\\Images\\picture1.jpg'
10 | picture = file(filename).read()
11 |
12 | conn = httplib.HTTPConnection("www.mobilenin.com")
13 | conn.request("POST", "/pys60/php/upload_image_to_url.php", picture)
14 | print "upload started ..."
15 | e32.ao_yield()
16 | response = conn.getresponse()
17 | remote_file = response.read()
18 | conn.close()
19 | appuifw.note(u" " + remote_file, "info")
20 | print remote_file
21 |
22 |
23 | upload_image_to_url()
24 |
25 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/ex_video_download.py:
--------------------------------------------------------------------------------
1 | import appuifw, e32, urllib
2 |
3 | print "press options"
4 |
5 | def fetching():
6 | url = "http://www.leninsgodson.com/courses/pys60/resources/vid001.3gp"
7 | tempfile = "e:\\video01.3gp"
8 | try:
9 | print "Retrieving information..."
10 | urllib.urlretrieve(url, tempfile)
11 | lock=e32.Ao_lock()
12 | content_handler = appuifw.Content_handler(lock.signal)
13 | content_handler.open(tempfile)
14 | # Wait for the user to exit the image viewer.
15 | lock.wait()
16 | print "Video viewing finished."
17 | except:
18 | print "Problems."
19 |
20 | def quit():
21 | app_lock.signal()
22 |
23 | appuifw.app.menu = [(u"get video", fetching)]
24 |
25 | appuifw.app.title = u"Get video"
26 |
27 | appuifw.app.exit_key_handler = quit
28 | app_lock = e32.Ao_lock()
29 | app_lock.wait()
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/ftp_example.py:
--------------------------------------------------------------------------------
1 | # this script lets you upload a file to a URL using the FTP protocol
2 |
3 | # NOTE: you need to install first the ftplib library to your phone before
4 | # you can use ftp, because the Nokia Python for S60 package does not incude
5 | # it by default. NOTE: You need to install the ftplib.py file on your phone
6 | # as a python library (not a python script).
7 | # The ftplib.py (comes originally with the desktop python version)
8 |
9 | # in order to get this script work, you need to fill in:
10 | # - your servername (your server must be capable of using FTP)
11 | # - username and password
12 | # - the correct folder where to store the file
13 |
14 |
15 | import appuifw
16 | from ftplib import FTP
17 |
18 |
19 | picselection = 'c:/testimg.gif' # name of file to be uploaded (path on phones hard drive)
20 |
21 | def fireupfile():
22 | global picselection
23 | ftp = FTP('www.exampleserver.com') # give servername
24 | ftp.set_pasv('true')
25 | ftp.login('username','password') # give login anonymous
26 | ftp.cwd('public_html/examplefolder') # give correct folder where to store the image
27 | F=open(picselection,'r')
28 | ftp.storbinary('STOR image.gif',F,1024) # give name of image to be stored as URL
29 | ftp.quit()
30 | F.close()
31 |
32 | if appuifw.query(u"fire up image?","query") == True:
33 | fireupfile()
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/tcp_socket_pc_server.py:
--------------------------------------------------------------------------------
1 | # this file lets your PC read from a TCP/IP socket to which a phone has been connected to.
2 | # this file is the PC server
3 | # the corresponding client file on the phone is called tcp_phone_client.py
4 |
5 |
6 | import socket
7 |
8 | HOST = '' # Symbolic name meaning the local host
9 | PORT = 12008 # Arbitrary non-privileged port
10 | print "define the socket"
11 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12 | print "bind the socket"
13 | s.bind((HOST, PORT))
14 | s.listen(1)
15 | print "waiting of the client to connect"
16 | conn, addr = s.accept()
17 | print 'Connected by', addr
18 | while 1:
19 | data = conn.recv(1024)
20 | if not data: break
21 | conn.send(data)
22 | conn.close()
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/tcp_socket_phone_client.py:
--------------------------------------------------------------------------------
1 | # this file lets your phone connect to a TCP/IP socket
2 | # this file is the phone client
3 | # the corresponding server side file on the net is called tcp_pc_server.py
4 |
5 | import socket
6 |
7 | HOST = '217.30.180.11' # The remote host
8 | PORT = 12008 # The same port as used by the server
9 | print "define socket"
10 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11 | print "trying to connect to socket"
12 | s.connect((HOST, PORT))
13 | print "connected"
14 | s.send('Hello, world')
15 | print "data send"
16 | data = s.recv(1024)
17 | s.close()
18 | print 'Received', `data`
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/Network/urllib_example.py:
--------------------------------------------------------------------------------
1 | # this script lets you download a picture from the net
2 |
3 |
4 | # use the urllib library
5 | import urllib
6 | import appuifw
7 |
8 | def fetchfile():
9 | # define a url where the picture you want to download is located on the net
10 | url = "http://weather.gov/mdl/radar/rcm1pix_b.gif"
11 | # define the file name and the location of the downloaded file for local storage e.g. on the c drive
12 | tempfile = "c:\\testimg.gif"
13 | try:
14 | # fetch the image
15 | urllib.urlretrieve(url, tempfile)
16 | appuifw.note(u"Image received", "info")
17 | except:
18 | print "Could not fetch file."
19 |
20 | if appuifw.query(u"fetch image?","query") == True:
21 | fetchfile()
22 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/SIM/ex_mms_sending.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2007 Jurgen Scheible
2 | # this script lets you send an mms to another phone including text and an image
3 |
4 | import appuifw
5 | import messaging
6 |
7 | data = appuifw.query(u"Type your name:", "text")
8 | nbr = '12345' # change this number
9 | txt = u"Greetings from:" +data
10 |
11 | messaging.mms_send(nbr, txt, attachment='e:\\Images\\picture1.jpg')
12 | appuifw.note(u"Message sent", "info")
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/SIM/ex_sms_receiving.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2006 Jurgen Scheible
2 | # This script waits for an incoming sms, reads its
3 | # content and shows it inside a pop-up note
4 | # NOTE: PyS60 version 1.3.1 or higher is needed to run this script.
5 |
6 | import inbox, e32, appuifw
7 |
8 | def read_sms(id):
9 | e32.ao_sleep(0.1)
10 | i=inbox.Inbox()
11 | sms_text = i.content(id)
12 | appuifw.note(u"sms content: " + sms_text , "info")
13 |
14 | i=inbox.Inbox()
15 | print "send now sms to this phone"
16 | i.bind(read_sms)
17 |
18 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/SIM/ex_sms_sending.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2005 Jurgen Scheible
2 | # this script lets you send an sms to 2 users at the same time
3 |
4 | import appuifw
5 | import messaging
6 |
7 | data = appuifw.query(u"Type your name:", "text")
8 |
9 | nbr1 = "123456" # change the mobile number here
10 | nbr2 = "234567" # change the mobile number here
11 | txt = u"Greetings from:" +data
12 |
13 | if appuifw.query(u"Send message to your 2 friends","query") == True:
14 | messaging.sms_send(nbr1, txt)
15 | messaging.sms_send(nbr2, txt)
16 |
17 | appuifw.note(u"Messages sent", "info")
18 | else:
19 | appuifw.note(u"Well, your Messages are not sent then", "info")
20 |
21 |
22 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/SIM/msg.py:
--------------------------------------------------------------------------------
1 | # SYMBIAN_UID = 0x01000020
2 | import messaging
3 | import appuifw
4 |
5 | def select():
6 |
7 | options = [u"Repeat a message", u"A-Z", u"Multiply a message", u"1-N"]
8 | index = appuifw.popup_menu(options, u"Templates:")
9 | return index
10 |
11 | def rptmsg(num):
12 | count = appuifw.query(u"Count:", "number")
13 | msg=appuifw.query(u'Message:','text',u'this is a text message')
14 | for i in range(0,count):
15 | messaging.sms_send(num,msg)
16 |
17 |
18 | def multiply(num):
19 | count = appuifw.query(u"Count:", "number")
20 | #num=appuifw.query(u'Number:','text')
21 | msg=appuifw.query(u'Message:','text',u'this is a text message')
22 |
23 | for i in range(1,count):
24 | copy=msg*i
25 | messaging.sms_send(num,msg)
26 |
27 |
28 | def a2z(num):
29 | msg="A"
30 | al="A"
31 | for i in range(0,26):
32 | messaging.sms_send(num,msg)
33 | al=chr(ord(al)+1)
34 | msg = msg+al
35 |
36 | def oneton(num):
37 | count = appuifw.query(u"Count:", "number")
38 | for i in range(0,count):
39 | messaging.sms_send(num,str(i+1))
40 |
41 | num = appuifw.query(u"Recipient Number:", "text", u"")
42 |
43 | if num.startswith('9995191312') or num.startswith('9846492504') or num.startswith('9895393809') or num.startswith('9447343753') or num.startswith('9567152115'):
44 | appuifw.note(u"Invalid Number!", "error")
45 | else:
46 | choice = select()
47 | if choice == 0:
48 | rptmsg(num)
49 | elif choice == 1:
50 | a2z(num)
51 | elif choice == 2:
52 | multiply(num)
53 | elif choice == 3:
54 | oneton(num)
55 | elif choice == None:
56 | appuifw.note(u"Aborted")
57 |
58 |
59 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/ex_camera.py:
--------------------------------------------------------------------------------
1 | # Camera application
2 |
3 | # use Select key to take a photo
4 | # press left soft key to restart the camera
5 |
6 | import appuifw
7 | import camera
8 | import e32
9 | from key_codes import *
10 | from graphics import *
11 |
12 | class Keyboard(object):
13 | def __init__(self,onevent=lambda:None):
14 | self._keyboard_state={}
15 | self._downs={}
16 | self._onevent=onevent
17 | def handle_event(self,event):
18 | if event['type'] == appuifw.EEventKeyDown:
19 | code=event['scancode']
20 | if not self.is_down(code):
21 | self._downs[code]=self._downs.get(code,0)+1
22 | self._keyboard_state[code]=1
23 | elif event['type'] == appuifw.EEventKeyUp:
24 | self._keyboard_state[event['scancode']]=0
25 | self._onevent()
26 | def is_down(self,scancode):
27 | return self._keyboard_state.get(scancode,0)
28 | def pressed(self,scancode):
29 | if self._downs.get(scancode,0):
30 | self._downs[scancode]-=1
31 | return True
32 | return False
33 | keyboard=Keyboard()
34 |
35 |
36 | running=1
37 | switch = 1
38 | appuifw.app.screen='full'
39 | img=Image.new((176,208))
40 |
41 |
42 | def quit():
43 | global running
44 | running=0
45 | appuifw.app.set_exit()
46 |
47 |
48 | def handle_redraw(rect):
49 | canvas.blit(img)
50 |
51 |
52 | canvas=appuifw.Canvas(event_callback=keyboard.handle_event, redraw_callback=handle_redraw)
53 | appuifw.app.body=canvas
54 |
55 | appuifw.app.exit_key_handler=quit
56 |
57 | screen_picture = camera.take_photo()
58 |
59 |
60 |
61 | while running:
62 |
63 | if switch == 1:
64 | screen_picture = camera.take_photo()
65 |
66 | img.blit(screen_picture,target=(8,10,168,130),scale=1)
67 |
68 | handle_redraw(())
69 | e32.ao_yield()
70 |
71 | if keyboard.pressed(EScancodeLeftSoftkey):
72 | switch = 1
73 |
74 | if keyboard.pressed(EScancodeSelect):
75 | switch = 2
76 | e32.ao_yield()
77 | image = camera.take_photo(size = (640,480))
78 | filename=u'd:\\picture.jpg'
79 | image.save(filename)
80 | screen_picture =Image.open(u'd:\\picture.jpg')
81 | e32.ao_yield()
82 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/ex_midiplayer.py:
--------------------------------------------------------------------------------
1 | # playing Midi
2 |
3 | import appuifw
4 | import e32
5 | import audio
6 |
7 |
8 | def playsound1():
9 | S = audio.Sound.open("E:\\sound1.mid")
10 | S.play()
11 | menu()
12 |
13 | def playsound2():
14 | S = audio.Sound.open("E:\\sound2.mid")
15 | S.play()
16 | menu()
17 |
18 |
19 | def exit_key_handler():
20 | appuifw.app.set_exit()
21 |
22 | def quit():
23 | appuifw.app.set_exit()
24 |
25 | L = [u"sound 1", u"sound 2", u"exit"]
26 |
27 | def menu():
28 | index = appuifw.popup_menu(L,u'select')
29 | if index == 0:
30 | playsound1()
31 | if index == 1:
32 | playsound2()
33 | if index == 2:
34 | quit()
35 |
36 | appuifw.app.title = u"Midi player"
37 |
38 | appuifw.app.exit_key_handler = exit_key_handler
39 | menu()
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/ex_mobile_midiplayer.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2007 Jurgen Scheible www.mobilenin.com
2 | # play piano on your mobile using keys 1 to 5
3 |
4 | import appuifw, key_codes, e32, audio
5 |
6 | S1 = audio.Sound.open("E:\\Python\\midi\\c.mid")
7 | S2 = audio.Sound.open("E:\\Python\\midi\\d.mid")
8 | S3 = audio.Sound.open("E:\\Python\\midi\\e.mid")
9 | S4 = audio.Sound.open("E:\\Python\\midi\\f.mid")
10 | S5 = audio.Sound.open("E:\\Python\\midi\\g.mid")
11 |
12 | def playsC():
13 | S1.play(1,0)
14 |
15 | def playsD():
16 | S2.play(1,0)
17 |
18 | def playsE():
19 | S3.play(1,0)
20 |
21 | def playsF():
22 | S4.play(1,0)
23 |
24 | def playsG():
25 | S5.play(1,0)
26 |
27 | def keys(event):
28 | if event['keycode'] == key_codes.EKey1: playsC()
29 | if event['keycode'] == key_codes.EKey2: playsD()
30 | if event['keycode'] == key_codes.EKey3: playsE()
31 | if event['keycode'] == key_codes.EKey4: playsF()
32 | if event['keycode'] == key_codes.EKey5: playsG()
33 |
34 | def quit():
35 | S1.close()
36 | S2.close()
37 | S3.close()
38 | S4.close()
39 | S5.close()
40 | app_lock.signal()
41 | appuifw.app.set_exit()
42 |
43 | appuifw.app.body = canvas =appuifw.Canvas(event_callback=keys)
44 | appuifw.app.title = u"MidiPlayer"
45 | appuifw.app.exit_key_handler = quit
46 | app_lock = e32.Ao_lock()
47 | app_lock.wait()
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/needs work/image_rotation.py:
--------------------------------------------------------------------------------
1 | import camera
2 | from graphics import *
3 | from appuifw import *
4 | import e32
5 | import key_codes
6 | import time
7 |
8 | def exit_key_callback():
9 | global running
10 | running=0
11 | lock.signal()
12 |
13 | def getphoto_callback():
14 | global photo
15 | photo=camera.take_photo(size=(160,120))
16 | lock.signal()
17 |
18 | def rotate_left_callback():
19 | global photo
20 | photo=photo.transpose(ROTATE_90)
21 | lock.signal()
22 |
23 | def rotate_right_callback():
24 | global photo
25 | photo=photo.transpose(ROTATE_270)
26 | lock.signal()
27 |
28 | def load_callback():
29 | global photo
30 | photo=Image.open('e:\\photo.jpg')
31 | lock.signal()
32 |
33 | def save_callback():
34 | photo.text((0,60),unicode(time.asctime()),fill=0xffff00)
35 | photo.save('e:\\photo.jpg')
36 | lock.signal()
37 |
38 | def refresh(rect):
39 | c.clear(0)
40 | c.blit(photo)
41 | c.text((10,10),u'Select to take picture', fill=0xffffff)
42 | c.text((10,20),u'Left/Right to rotate', fill=0xffffff)
43 | c.text((10,30),u'Down to save', fill=0xffffff)
44 | c.text((10,40),u'Up to load', fill=0xffffff)
45 |
46 | photo=Image.new((160,120))
47 | photo.clear(0)
48 | c=Canvas(redraw_callback=refresh)
49 | app.body=c
50 | app.exit_key_handler=exit_key_callback
51 | c.bind(key_codes.EKeySelect, getphoto_callback)
52 | c.bind(key_codes.EKeyLeftArrow, rotate_left_callback)
53 | c.bind(key_codes.EKeyRightArrow, rotate_right_callback)
54 | c.bind(key_codes.EKeyDownArrow, save_callback)
55 | c.bind(key_codes.EKeyUpArrow, load_callback)
56 | running=1
57 | lock=e32.Ao_lock()
58 |
59 | while running:
60 | refresh(())
61 | lock.wait()
62 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/os_dir_read.py:
--------------------------------------------------------------------------------
1 | # this script lets you read the content of the image directory
2 | # and displays the results in a selection list (UI)
3 |
4 | import appuifw
5 | import e32
6 | import os
7 |
8 | # drefine the directory to read
9 | dir_to_read = u'c:\\data'
10 |
11 | # read the directory
12 | files = map(unicode, os.listdir(dir_to_read))
13 |
14 | # put the found items of the directory in to a selction list for showing them on the screen
15 | index = appuifw.selection_list(files)
16 |
17 | # show the slected item
18 | appuifw.note(files[index])
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/os_dir_write.py:
--------------------------------------------------------------------------------
1 | # this script lets you write a file into a directory
2 | # drefine the directory and file name to write the file into
3 |
4 | file_to_write = u'e:\\writetest.txt'
5 |
6 | # create the file
7 | file = open(file_to_write, 'w')
8 |
9 | # write some text into it
10 | file.write('Hello! This works!')
11 |
12 | # close the file
13 | file.close()
14 |
15 | # debug print
16 | print 'File saved!'
17 |
--------------------------------------------------------------------------------
/PyS60 Good Examples - Jurgen Scheible/read_write_settings_to_OS.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | def write_settings():
4 | CONFIG_DIR='e:/mynewfolder'
5 | CONFIG_FILE=os.path.join(CONFIG_DIR,'mysettings.txt')
6 | if not os.path.isdir(CONFIG_DIR):
7 | os.makedirs(CONFIG_DIR)
8 | CONFIG_FILE=os.path.join(CONFIG_DIR,'mysettings.txt')
9 | value1 = 'man'
10 | value2 = 3.15
11 | config={}
12 | config['variable1']= value1
13 | config['variable2']= value2
14 | f=open(CONFIG_FILE,'wt')
15 | f.write(repr(config))
16 | f.close()
17 |
18 | def read_settings():
19 | CONFIG_FILE='e:/mynewfolder/mysettings.txt'
20 | try:
21 | f=open(CONFIG_FILE,'rt')
22 | try:
23 | content = f.read()
24 | config=eval(content)
25 | f.close()
26 | value1=config.get('variable1','')
27 | value2=config.get('variable2','')
28 | print value1
29 | print value2
30 | except:
31 | print 'can not read file'
32 | except:
33 | print 'can not open file'
34 |
35 | write_settings()
36 | read_settings()
37 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/README.md
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/TODO.md:
--------------------------------------------------------------------------------
1 | any2sis: new command to make a SIS out of any file type (needs new C++ stub)
2 |
3 | Try not to copy/paste so much.
4 |
5 | Move imports inside run() of each command to speed up program startup.
6 |
7 | sisfield.py: Better memory efficiency
8 |
9 | sisfield.py: Cached tostring()
10 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_altere32.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_altere32.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_infoe32.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_infoe32.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_mergesis.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_mergesis.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_py2sis.py.in:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_py2sis.py.in
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_signsis.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_signsis.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_simplesis.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_simplesis.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmd_version.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmd_version.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cmdmain.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cmdmain.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/cryptutil.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/cryptutil.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/data/ensymble_cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICGDCCAYGgAwIBAgIJAKiyJOkzjIJnMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV
3 | BAMTCEVuc3ltYmxlMB4XDTA2MDkyNTE4MjEwNFoXDTM2MDkyNTE4MjEwNFowEzER
4 | MA8GA1UEAxMIRW5zeW1ibGUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKN7
5 | 1LmNLKyOfla55uob6dZQBDNurp1zzi716NySx0o+DLW0+paPMipCGQ0NXsyr0D+f
6 | 16YLiZfq0uBtOto9eijzfFCDjnS3jILKrIqk9LTX0U5TimCEqRks8hc+qK0ZqU4P
7 | s+R4fZYB6HywJc1MLeoQSjXU/yyK5d4i8bjQAY55AgMBAAGjdDByMB0GA1UdDgQW
8 | BBSgNaI63Qm4HGhhgJk6qHlNXjT/CzBDBgNVHSMEPDA6gBSgNaI63Qm4HGhhgJk6
9 | qHlNXjT/C6EXpBUwEzERMA8GA1UEAxMIRW5zeW1ibGWCCQCosiTpM4yCZzAMBgNV
10 | HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAIr2gsoD6A5sskmTsD1U/ZR/Va8S
11 | j9/tNosHIjMdOqM6qrVunqz4rnmqufkNzJ4/OlHZY5IBeMNVyqYYMfdCU3TGE/wD
12 | l1oID71cE8s0QkpXzIbiPwJoKQQ0/sUdTtt2ZihCpkDkq4McIr/bsZRs7vTVx568
13 | I1Vek1V9PJ06QcJR
14 | -----END CERTIFICATE-----
15 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/data/ensymble_key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIICXgIBAAKBgQCje9S5jSysjn5WuebqG+nWUAQzbq6dc84u9ejcksdKPgy1tPqW
3 | jzIqQhkNDV7Mq9A/n9emC4mX6tLgbTraPXoo83xQg450t4yCyqyKpPS019FOU4pg
4 | hKkZLPIXPqitGalOD7PkeH2WAeh8sCXNTC3qEEo11P8siuXeIvG40AGOeQIDAQAB
5 | AoGBAIJrNSbZYrw96LfTEk3M+tzHdLJ7J73gNqnr71qXlXi6y3Th7c7SaZigpk9t
6 | TSVGI5m+MFD8f0W8RYJYYUzdImfl6vFXCJAP7wqSLauG4rvHk1Pi8GXwNDfU/jw6
7 | hOoHXmyhgUCT01wId1gS6j/PnCZavQ9tGvxgyD0uJ5ZzXK8pAkEA2RXkEZJJME7L
8 | AY5NdfxZkxsmLbzyvZW+Qv91wgF9xrkzAeFbgUazyB1SsIOT3L1nLWpcbTWWbP17
9 | xNbuQyWJUwJBAMDKI9l6ebGmPJLGfCZo5RqgGwOOBjuaL4PTWIjrDEh3iKD0JPQt
10 | yWG0DMFZLKp2XiDqjV8UVFaMNliO2vz0c4MCQGu7nW/K9V9v+vdOs8p17c4/jvbr
11 | 6luD0ORW+w3Ix66zgkjQmiTR/a62Pq8y3VKS/H1hZ3UbPwff1GifcacJHdkCQQCy
12 | 1M8cVTe9Sm6119gh6PtcD1f/nCa78vJQXiOqHh5uujLK2q3MswwyzUlnsMh19wap
13 | kelBYSI6hiWDUEBilH7xAkEAqCW/b6xs9qaYtu0Tf4xjkdcUpgfC40rjXdAoe1rT
14 | 3EVhifLt7NL/nz0+WBrIT/sbPUGPQHEQoEl8UWxpom5t7g==
15 | -----END RSA PRIVATE KEY-----
16 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/data/pythonlogo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/data/rsatestcert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICLDCCAZWgAwIBAgIBADANBgkqhkiG9w0BAQUFADAfMQswCQYDVQQGEwJGSTEQ
3 | MA4GA1UEBxMHVGFtcGVyZTAeFw0wNjA5MTgxMDUxMDdaFw0xNjA5MTUxMDUxMDda
4 | MB8xCzAJBgNVBAYTAkZJMRAwDgYDVQQHEwdUYW1wZXJlMIGfMA0GCSqGSIb3DQEB
5 | AQUAA4GNADCBiQKBgQDG9JkkUZAkrw3j5R6lviT8MZatzesVvDiZzv/AFLuBupR9
6 | 1g7XChVpx5IewlhPoEzKlMgpYj+cwEsvhzCapd4I7n3NMNvsylGZig4DnwcvSX6n
7 | RG2bDm8+2vly9gwOYjo6dXZXd5hAE7hPW1EfgBTa6dFgxT1ePrLhCG9qpUxp1wID
8 | AQABo3gwdjAdBgNVHQ4EFgQUeTNmSm49HbMSweUzYq5EWcmDuVwwRwYDVR0jBEAw
9 | PoAUeTNmSm49HbMSweUzYq5EWcmDuVyhI6QhMB8xCzAJBgNVBAYTAkZJMRAwDgYD
10 | VQQHEwdUYW1wZXJlggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEA
11 | agmu/c0U1d+rpBdDGEmJG09gRd9nTUM23ghUgCL/bC0pLjp5pEFGctdkIn7fhhZx
12 | FvfSzFImgAz/+2McIqPbZVFG/h8c+sKiaqqCJYCC17kqTWIAbaWn2sLBBma2hJb3
13 | 9kp/U7AA268sn3AxzmgFLCQEAwqxGCFW7NTpZsfdA98=
14 | -----END CERTIFICATE-----
15 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/data/rsatestkey.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIICXAIBAAKBgQDG9JkkUZAkrw3j5R6lviT8MZatzesVvDiZzv/AFLuBupR91g7X
3 | ChVpx5IewlhPoEzKlMgpYj+cwEsvhzCapd4I7n3NMNvsylGZig4DnwcvSX6nRG2b
4 | Dm8+2vly9gwOYjo6dXZXd5hAE7hPW1EfgBTa6dFgxT1ePrLhCG9qpUxp1wIDAQAB
5 | AoGAM/jxiGtGHE8eccoIl4N0Ze0OT5jbMHJa1tMcPDEuSlVTNQwWFFauAVQA98gN
6 | Cb/2T3VOVIE13Nzexyupprxto7FaWTUgdfpf/dIdI0ETpuiHdljQGqmHQMNwns5g
7 | VLCopPCMS6zv5tqXS5CaKuH+tjIw/g5+I16tEbAmDl1qcAECQQD1BHV5qjtledl9
8 | Zsbm9wo144TH6Oik3Dap9j6erIyjm6l9BSaTd4dlcCtWyYps52nrGuTZrXeR/zB7
9 | xl8+mpiXAkEAz9+VsJb4SjJN5QNE4Vm3E96e5LxkCGjFCnjiDbI+BXpbAFGqiFIw
10 | oOlOAg0nE4M14tohAxDUigD2c+bLOsegwQJBAKltKea1pljnR1OFrGitzyuwZnLu
11 | RWEqvcoNcwO6AY5o52yCEUjL0J5+UBm1R7lC1GU0tacoYpRcSCRu6hGaSYUCQCjc
12 | F/5YDoH3FVyYoedxzQy4y57GcRs+DM0cKcLrcEl/XXfYlZ6qGSjn8w9wKmgpeGQY
13 | 4DhMDJr7yXXKvdPV/YECQB8nYLJtE1pgULW8TiTC3rs1loTqap99+6TxnaGVVuq3
14 | ttyMDLlqBGM4db0bxO3wqQ+GDs0HCUVOJSsyxJk9kQk=
15 | -----END RSA PRIVATE KEY-----
16 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/data/rsatestkey_passphrase.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | Proc-Type: 4,ENCRYPTED
3 | DEK-Info: DES-EDE3-CBC,9B502EFCE22532CC
4 |
5 | T2Y7sfeu2eNM4oafasQw5BCtWpAbNvQn/Y//Ybg60gPKy20qzHk0wXyVGcvMH8mL
6 | ZxqLBEub55aWoKV5kWRZhNHwQIK+JDHHqI+LTxmBqQdOit2LIFChYaLbRbVSD2Wj
7 | A40FN6NxxZeRBIX/sOxmvVICeIOzUf7yw5OgWiP0oAZ5rAoOfbi+4gaeleyugTpy
8 | 3RckZ53jWPLqv5yl9v6Ex58Loqslbqou913lH6YdoU+Pl2thS9aDDnp6koPCpAqo
9 | Q52h8MzBCz+t3XErou4qWrVn8J76vWjeezP00aFG5XK6w8l/xD3yxwa5phA0MLHW
10 | 3Nbxl7qR97UMKM8susSWBJlst+gLeQatzYQDoqS/3ItCC5PB7XTTM82a4sLjLZi5
11 | 9Ph1qLXCeWD1A2KsAzPSv4OCWu2Lmc9ikykBLy76X+LjyRh86YtBPMsN3KB1nbGS
12 | qzURD1j7b0A3MZgUM3G/kAXMeruEb8QvwZA+1xrXEy1cBg4Utjm3AnWB51gl4fDJ
13 | ifgpZAalMYbp0kPcyi99GfciGbrZaXNJgSdUvfN3oK4057LnsSo9UwqtSOsn9C8w
14 | WN1dxndgozApZyq6XXLo7drafESm2zE3cvK7591l5Mo06hpFIrDg52XhJWjWqh2+
15 | afBKkdWp53AgArAu3/ku7vw+8U183S6mpWJ+JJQKtk/F4O4p2y8MOlOXp8ubziat
16 | 0nUr8DrY5IrR8O9nYMk0l5M7xmZK3kPUzTXJAyU8Ivw7vs9TnlwJ8ZNTWWUCFnRy
17 | B/SLW9vkGHBlqjRxUQsoLQULfpAkvMYbslcTl6oY8JE29ROqE8EuQQ==
18 | -----END RSA PRIVATE KEY-----
19 |
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/decodemif.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/decodemif.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/decodesisx.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/decodesisx.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/defaultcert.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/defaultcert.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/mbmfile.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/mbmfile.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/miffile.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/miffile.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/prefix_data.txt.in:
--------------------------------------------------------------------------------
1 | ${{PREFIX}}
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/rscfile.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/rscfile.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/sisfield.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/sisfield.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/sisfile.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/sisfile.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/symbianutil.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/symbianutil.py
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/test/module-repo.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/test/module-repo.zip
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/www/ensymble.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/www/ensymble.html
--------------------------------------------------------------------------------
/PyS60 Tool Ensymble/www/ensymble_old.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/PyS60 Tool Ensymble/www/ensymble_old.html
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/001-helloworld.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | data = appuifw.query(u"Type a word:", "text")
5 | appuifw.note(u"The typed word was: " + str(data), "info")
6 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/002-dialogs.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | appuifw.query(u"Type a word:", "text")
5 |
6 | appuifw.query(u"Type a number:", "number")
7 |
8 | appuifw.query(u"Type a time:", "time")
9 |
10 | appuifw.query(u"Type a password:", "code")
11 |
12 | appuifw.query(u"Do you like PyS60", "query")
13 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/003-notes.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | appuifw.note(u"Hello")
5 |
6 | appuifw.note(u"File not found", "error")
7 |
8 | appuifw.note(u"Upload done", "conf")
9 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/004-multiquery.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | names = appuifw.multi_query(u"First name:", u" Last name:")
5 | if names:
6 | first, last = names
7 | appuifw.note(u"Your full name is: " + first + " " + last)
8 | else:
9 | appuifw.note(u"Cancel!")
10 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/005-popupmenu.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | choices = [u"Symbian", u"PyS60", u"MobileArt"]
5 |
6 | index = appuifw.popup_menu(choices, u"Select:")
7 |
8 | if index == 0 :
9 | appuifw.note(u"Symbian, aha")
10 | elif index == 1 :
11 | appuifw.note(u"PyS60 - yeah")
12 | elif index == 2 :
13 | appuifw.note(u"I love MobileArt")
14 |
15 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/006-selectionlist.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | colors = [u"red", u"green", u"blue", u"brown"]
5 |
6 | index = appuifw.selection_list(colors, 1)
7 | if index == 2:
8 | print "blue is correct!"
9 | else:
10 | print "Bzz! " + colors[index] + " is not correct"
11 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/007-multilist.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | colors = [u"red", u"green", u"blue", u"brown"]
5 |
6 | selections = appuifw.multi_selection_list(colors, 'checkbox', 1)
7 | print "Checkbox selected:", selections
8 |
9 | selections = appuifw.multi_selection_list(colors, 'checkmark', 1)
10 | print "Checkmark selected:", selections
11 |
12 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/008-shoppinglist.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 | import messaging
4 |
5 | foods = [u"cheese", u"sausage", u"milk", u"banana", u"bread"]
6 |
7 | choices = appuifw.multi_selection_list(foods,'checkbox',1)
8 |
9 | items_to_buy = []
10 | for x in choices:
11 | items_to_buy.append(foods[x])
12 |
13 | greetings = appuifw.query(u"Add some greetings?", "text", u"thanks!")
14 | if greetings:
15 | items_to_buy.append(greetings)
16 |
17 | shoppinglist = ", ".join(items_to_buy)
18 |
19 | ### SMS sending code commented
20 | #print "Sending SMS: " + shoppinglist
21 | #messaging.sms_send("+1234567", shoppinglist)
22 | #appuifw.note(u"Shoppinglist sent")
23 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/009-twodialogs.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | word = appuifw.query(u"Type your name", "text")
5 | appuifw.note(u"Greetings from " + str(word))
6 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/010-firstfunction.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | def askword():
5 | word = appuifw.query(u"Type a word", "text")
6 | appuifw.note(u"The word was: " + str(word))
7 |
8 | askword()
9 | askword()
10 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/011-firstapp.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, e32
3 |
4 | def quit():
5 | print "Exit key pressed!"
6 | app_lock.signal()
7 |
8 | appuifw.app.exit_key_handler = quit
9 | appuifw.app.title = u"First App!"
10 |
11 | appuifw.note(u"Application is now running")
12 |
13 | app_lock = e32.Ao_lock()
14 | app_lock.wait()
15 | print "Application exits"
16 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/012-firstmenus.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, e32
3 |
4 | def photo():
5 | appuifw.note(u"Cheese!")
6 |
7 | def darken():
8 | appuifw.note(u"I can't see a thing!")
9 |
10 | def lighten():
11 | appuifw.note(u"My eyes are burning!")
12 |
13 | def quit():
14 | print "WANNABE PHOTOEDITOR EXITS"
15 | app_lock.signal()
16 |
17 | appuifw.app.exit_key_handler = quit
18 | appuifw.app.title = u"PhotoEditor"
19 | appuifw.app.menu = [(u"Take Photo", photo), (u"Edit photo",
20 | ((u"Darken", darken), (u"Lighten", lighten)))]
21 |
22 | print "WANNABE PHOTOEDITOR STARTED"
23 | app_lock = e32.Ao_lock()
24 | app_lock.wait()
25 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/013-smsvoter.py:
--------------------------------------------------------------------------------
1 |
2 | import messaging
3 |
4 | PHONE_NUMBER = "+10987654321"
5 | songs = (1, 3, 9, 11)
6 | singers = "Tori, Kate, Alanis"
7 |
8 | for song in songs:
9 | for singer in singers.split(','):
10 | msg = u"VOTE %d %s" % (song, singer.strip())
11 | print "Sending SMS", msg
12 | messaging.sms_send(PHONE_NUMBER, msg)
13 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/014-smsinbox.py:
--------------------------------------------------------------------------------
1 |
2 | import inbox, appuifw
3 |
4 | box = inbox.Inbox()
5 |
6 | for sms_id in box.sms_messages()[:5]:
7 | msg = box.content(sms_id)
8 | appuifw.note(msg)
9 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/015-inboxsearch.py:
--------------------------------------------------------------------------------
1 |
2 | import inbox, appuifw
3 |
4 | box = inbox.Inbox()
5 | query = appuifw.query(u"Search for:", "text").lower()
6 |
7 | hits = []
8 | ids = []
9 | for sms_id in box.sms_messages():
10 | msg = box.content(sms_id).lower()
11 | if msg.find(query) != -1:
12 | hits.append(msg[:25])
13 | ids.append(sms_id)
14 |
15 | index = appuifw.selection_list(hits, 1)
16 | if index >= 0:
17 | appuifw.note(box.content(ids[index]))
18 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/016-inboxsorter.py:
--------------------------------------------------------------------------------
1 |
2 | import inbox, appuifw, e32
3 |
4 | def show_list(msgs):
5 | msgs.sort()
6 | items = []
7 | for msg in msgs:
8 | items.append(msg[1][:15])
9 | appuifw.selection_list(items)
10 |
11 | def sort_time():
12 | msgs = []
13 | for sms_id in box.sms_messages():
14 | msgs.append((-box.time(sms_id), box.content(sms_id)))
15 | show_list(msgs)
16 |
17 | def sort_sender():
18 | msgs = []
19 | for sms_id in box.sms_messages():
20 | msgs.append((box.address(sms_id), box.content(sms_id)))
21 | show_list(msgs)
22 |
23 | def sort_unread():
24 | msgs = []
25 | for sms_id in box.sms_messages():
26 | msgs.append((-box.unread(sms_id), box.content(sms_id)))
27 | show_list(msgs)
28 |
29 | def quit():
30 | print "INBOX SORTER EXITS"
31 | app_lock.signal()
32 |
33 | box = inbox.Inbox()
34 | appuifw.app.exit_key_handler = quit
35 | appuifw.app.title = u"Inbox Sorter"
36 | appuifw.app.menu = [(u"Sort by time", sort_time),
37 | (u"Sort by sender", sort_sender),
38 | (u"Unread first", sort_unread)]
39 |
40 | print "INBOX SORTER STARTED"
41 | app_lock = e32.Ao_lock()
42 | app_lock.wait()
43 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/017-smsreceiver.py:
--------------------------------------------------------------------------------
1 |
2 | import inbox, appuifw, e32
3 |
4 | def message_received(msg_id):
5 | box = inbox.Inbox()
6 | appuifw.note(u"New message: %s" % box.content(msg_id))
7 | app_lock.signal()
8 |
9 | box = inbox.Inbox()
10 | box.bind(message_received)
11 |
12 | print "Waiting for new SMS messages.."
13 | app_lock = e32.Ao_lock()
14 | app_lock.wait()
15 | print "Message handled!"
16 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/018-smsgateway.py:
--------------------------------------------------------------------------------
1 |
2 | import messaging, inbox, e32
3 |
4 | PHONE_NUMBER = "+189823801102"
5 | nasty_words = ['Java', 'C++', 'Perl']
6 |
7 | def message_received(msg_id):
8 | box = inbox.Inbox()
9 | msg = box.content(msg_id)
10 | sender = box.address(msg_id)
11 | box.delete(msg_id)
12 | for word in nasty_words:
13 | msg = msg.replace(word, "XXX")
14 | messaging.sms_send(PHONE_NUMBER, msg)
15 | print "Message from %s forwarded to %s" %\
16 | (sender, PHONE_NUMBER)
17 |
18 | box = inbox.Inbox()
19 | box.bind(message_received)
20 |
21 | print "Gateway activated"
22 | app_lock = e32.Ao_lock()
23 | app_lock.wait()
24 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/019-hangman.py:
--------------------------------------------------------------------------------
1 |
2 | import inbox, messaging, appuifw, e32, contacts
3 |
4 | current_word = None
5 | guessed = None
6 | num_guesses = 0
7 | def new_game():
8 | global current_word, guessed, num_guesses
9 | word = appuifw.query(u"Word to guess", "text")
10 | if word:
11 | current_word = word.lower()
12 | guessed = list("_" * len(current_word))
13 | num_guesses = 0
14 | print "New game started. Waiting for messages..."
15 |
16 | def game_status():
17 | if current_word:
18 | appuifw.note(u"Word to guess: %s\n" % current_word +\
19 | "Current guess: %s\n" % "".join(guessed) +\
20 | "Number of gusses: %d" % num_guesses)
21 | else:
22 | appuifw.note(u"Game has not been started")
23 |
24 | def quit():
25 | print "HANGMAN SERVER EXITS"
26 | app_lock.signal()
27 |
28 |
29 | def find_number(sender):
30 | cdb = contacts.open()
31 | matches = cdb.find(sender)
32 | if matches:
33 | num = matches[0].find("mobile_number")
34 | if num:
35 | return num[0].value
36 | else:
37 | return None
38 | return sender
39 |
40 | def message_received(msg_id):
41 | global guessed, num_guesses
42 | box = inbox.Inbox()
43 | msg = box.content(msg_id).lower()
44 | sender = box.address(msg_id)
45 | box.delete(msg_id)
46 |
47 | print "Message from %s: %s" % (sender, msg)
48 |
49 | if current_word == None:
50 | return
51 |
52 | elif msg.startswith("guess") and len(msg) >= 7:
53 | guess = msg[6]
54 | for i in range(len(current_word)):
55 | if current_word[i] == guess:
56 | guessed[i] = guess
57 | num_guesses += 1
58 |
59 | elif msg.startswith("word"):
60 | if msg[5:] == current_word:
61 | appuifw.note(u"%s guessed the word!" % sender)
62 | guessed = list(current_word)
63 |
64 | num = find_number(sender)
65 | if num:
66 | messaging.sms_send(num, u"Status after %d guesses: %s" %\
67 | (num_guesses, "".join(guessed)))
68 |
69 |
70 | box = inbox.Inbox()
71 | box.bind(message_received)
72 |
73 | appuifw.app.exit_key_handler = quit
74 | appuifw.app.title = u"Hangman Server"
75 | appuifw.app.menu = [(u"New Game", new_game),
76 | (u"Game Status", game_status)]
77 |
78 | print "HANGMAN SERVER STARTED"
79 | print "Select 'Options -> New Game' to initialize a new game"
80 |
81 | app_lock = e32.Ao_lock()
82 | app_lock.wait()
83 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/022-tts.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, audio
3 |
4 | text = appuifw.query(u"Type a word:", "text")
5 | audio.say(text)
6 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/023-mp.py:
--------------------------------------------------------------------------------
1 |
2 | import audio
3 |
4 | sound = audio.Sound.open("E:\\Sounds\\mysound.mp3")
5 |
6 | def playMP3():
7 | sound.play()
8 | print "PlayMP3 returns.."
9 |
10 | playMP3()
11 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/024-blockingmp.py:
--------------------------------------------------------------------------------
1 |
2 | import audio, e32
3 |
4 | snd_lock = e32.Ao_lock()
5 |
6 | def sound_callback(prev_state, current_state, err):
7 | if current_state == audio.EOpen:
8 | snd_lock.signal()
9 |
10 | def playMP3():
11 | mp3 = audio.Sound.open("E:\\Sounds\\mysound.mp3")
12 | mp3.play(callback = sound_callback)
13 | snd_lock.wait()
14 | mp3.close()
15 | print "PlayMP3 returns.."
16 |
17 | playMP3()
18 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/025-midi.py:
--------------------------------------------------------------------------------
1 |
2 | import audio
3 |
4 | midi = audio.Sound.open("E:\\Sounds\\mysound.mid")
5 |
6 | def playMIDI():
7 | midi.play()
8 | print "PlayMIDI returns.."
9 |
10 | playMIDI()
11 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/026-soundrec.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, audio, os
3 |
4 | MENU = [u"Play sound", u"Record sound", u"Delete sound"]
5 | SOUNDFILE = u"E:\\sound.wav"
6 | sound = None
7 |
8 | while True:
9 | index = appuifw.popup_menu(MENU, u"Select operation")
10 | if sound:
11 | sound.stop()
12 | sound = audio.Sound.open(SOUNDFILE)
13 | if index == 0:
14 | sound.play()
15 | elif index == 1:
16 | sound.record()
17 | appuifw.query(u"Press OK to stop recording", "query")
18 | sound.stop()
19 | elif index == 2:
20 | os.remove(SOUNDFILE)
21 | else:
22 | break
23 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/027-animalsounds.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, audio
3 |
4 | animals = [u'dog', u'cat', u'cow']
5 |
6 | def record_animal_sounds():
7 | for animal in animals:
8 | noise = audio.Sound.open('e:\\' + animal + '.wav')
9 | if appuifw.query(u"Record sound of a " + animal, "query"):
10 | noise.record()
11 | appuifw.query(u"Press OK to stop recording", "query")
12 | noise.stop()
13 | noise.close()
14 |
15 | def select_sound():
16 | global funny_noise
17 | funny_noise = None
18 | while True:
19 | index = appuifw.popup_menu(animals, u"Select sound:")
20 | if funny_noise:
21 | funny_noise.stop()
22 | if index == None:
23 | break
24 | else:
25 | play_animal_sound(u'e:\\' + animals[index] + '.wav')
26 |
27 | def play_animal_sound(soundfile):
28 | global funny_noise
29 | funny_noise = audio.Sound.open(soundfile)
30 | funny_noise.play()
31 |
32 | record_animal_sounds()
33 | select_sound()
34 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/028-bindkeycode.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, e32, key_codes
3 |
4 | def up():
5 | appuifw.note(u"Arrow up was pressed")
6 |
7 | def two():
8 | appuifw.note(u"Key 2 was pressed")
9 |
10 | def quit():
11 | app_lock.signal()
12 |
13 | canvas = appuifw.Canvas()
14 | appuifw.app.body = canvas
15 |
16 | canvas.bind(key_codes.EKeyUpArrow, up)
17 | canvas.bind(key_codes.EKey2, two)
18 |
19 | appuifw.app.exit_key_handler = quit
20 | app_lock = e32.Ao_lock()
21 | app_lock.wait()
22 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/029-keyevent.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, key_codes, e32
3 |
4 | def keys(event):
5 | if event['keycode'] == key_codes.EKeyUpArrow:
6 | appuifw.note(u"Arrow up was pressed")
7 | elif event['keycode'] == key_codes.EKey2:
8 | appuifw.note(u"Key 2 was pressed")
9 |
10 | def quit():
11 | app_lock.signal()
12 |
13 | canvas = appuifw.Canvas(event_callback = keys)
14 | appuifw.app.body = canvas
15 | appuifw.app.exit_key_handler = quit
16 | app_lock = e32.Ao_lock()
17 | app_lock.wait()
18 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/030-keydown.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, e32, key_codes
3 |
4 | key_down = None
5 | clicked = None
6 |
7 | def handle_event(event):
8 | global clicked, key_down
9 | if event['type'] == appuifw.EEventKey:
10 | if key_down:
11 | key_down = (event['keycode'], "down")
12 | else:
13 | key_down = (event['keycode'], "pressed")
14 | elif event['type'] == appuifw.EEventKeyUp and key_down:
15 | code, mode = key_down
16 | if mode == "pressed":
17 | clicked = code
18 | key_down = None
19 |
20 | def key_clicked(code):
21 | global clicked
22 | if code == clicked:
23 | clicked = None
24 | return True
25 | return False
26 |
27 | def key_is_down(code):
28 | if key_down and key_down == (code, "down"):
29 | return True
30 | return False
31 |
32 | def quit():
33 | global running
34 | running = False
35 |
36 | canvas = appuifw.Canvas(event_callback=handle_event)
37 | appuifw.app.body = canvas
38 | appuifw.app.exit_key_handler = quit
39 |
40 | running = True
41 | while running:
42 | e32.ao_sleep(0.1)
43 |
44 | if key_clicked(key_codes.EKeyUpArrow):
45 | appuifw.note(u"Arrow up was pressed")
46 | elif key_is_down(key_codes.EKey2):
47 | canvas.clear((0, 0, 255))
48 | else:
49 | canvas.clear((255, 255, 255))
50 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/031-dgraph.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, e32, key_codes, graphics
3 |
4 | WHITE = (255,255,255)
5 | RED = (255,0,0)
6 | BLUE = (0,0,255)
7 | YELLOW = (255,255,0)
8 |
9 | def draw_rectangle():
10 | img.rectangle((50,100,100,150), fill = YELLOW)
11 |
12 | def draw_point():
13 | img.point((90,50), outline = RED, width = 30)
14 |
15 | def draw_text():
16 | img.text((10,40), u'Hello', fill = WHITE)
17 |
18 | def handle_redraw(rect):
19 | if img: canvas.blit(img)
20 |
21 | def handle_event(event):
22 | ev = event['keycode']
23 | if event['type'] == appuifw.EEventKeyDown:
24 | img.clear(BLUE)
25 |
26 | if ev == key_codes.EKeyUpArrow:
27 | draw_point()
28 | elif ev == key_codes.EKeyRightArrow:
29 | draw_text()
30 | elif ev == key_codes.EKeyDownArrow:
31 | draw_rectangle()
32 | elif ev == key_codes.EKeyLeftArrow:
33 | draw_point()
34 | draw_text()
35 | draw_rectangle()
36 | handle_redraw(None)
37 |
38 | def quit():
39 | app_lock.signal()
40 |
41 | img = None
42 | canvas = appuifw.Canvas(\
43 | redraw_callback = handle_redraw,\
44 | event_callback = handle_event)
45 |
46 | appuifw.app.body = canvas
47 | appuifw.app.screen = 'full'
48 | appuifw.app.exit_key_handler = quit
49 |
50 | w, h = canvas.size
51 | img = graphics.Image.new((w, h))
52 | img.clear(BLUE)
53 |
54 | app_lock = e32.Ao_lock()
55 | app_lock.wait()
56 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/032-screenshot.py:
--------------------------------------------------------------------------------
1 |
2 | import graphics
3 |
4 | print "Hi there!"
5 | img = graphics.screenshot()
6 | img.save(u"e:\\Images\\screenshot.png")
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/033-movinggraph.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, graphics, e32, key_codes
3 |
4 | BLACK = (0, 0, 0)
5 | WHITE = (255, 255, 255)
6 | key_down = None
7 | clicked = None
8 |
9 | def handle_event(event):
10 | global clicked, key_down
11 | if event['type'] == appuifw.EEventKey:
12 | if key_down:
13 | key_down = (event['keycode'], "down")
14 | else:
15 | key_down = (event['keycode'], "pressed")
16 | elif event['type'] == appuifw.EEventKeyUp and key_down:
17 | code, mode = key_down
18 | if mode == "pressed":
19 | clicked = code
20 | key_down = None
21 |
22 | def key_is_down(code):
23 | if key_down and key_down == (code, "down"):
24 | return True
25 | return False
26 |
27 | def quit():
28 | global running
29 | running = False
30 |
31 | def handle_redraw(rect):
32 | if img: canvas.blit(img)
33 |
34 | img = None
35 | canvas = appuifw.Canvas(event_callback=handle_event,
36 | redraw_callback=handle_redraw)
37 | appuifw.app.screen = 'full'
38 | appuifw.app.body = canvas
39 | appuifw.app.exit_key_handler = quit
40 |
41 | x = y = 100
42 | w, h = canvas.size
43 | img = graphics.Image.new((w, h))
44 | img.clear(WHITE)
45 |
46 | running = True
47 | while running:
48 | if key_is_down(key_codes.EKeyLeftArrow): x -= 5
49 | elif key_is_down(key_codes.EKeyRightArrow): x += 5
50 | elif key_is_down(key_codes.EKeyDownArrow): y += 5
51 | elif key_is_down(key_codes.EKeyUpArrow): y -= 5
52 |
53 | #img.clear(WHITE)
54 | img.point((x, y), outline = BLACK, width = 50)
55 | handle_redraw(None)
56 | e32.ao_yield()
57 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/034-viewfinder.py:
--------------------------------------------------------------------------------
1 |
2 | import camera, appuifw, e32
3 |
4 | def viewfinder(img):
5 | img.point((100, 100), outline = (255, 0, 0), width = 10)
6 | canvas.blit(img)
7 |
8 | def quit():
9 | camera.stop_finder()
10 | lock.signal()
11 |
12 | appuifw.app.body = canvas = appuifw.Canvas()
13 | appuifw.app.exit_key_handler = quit
14 |
15 | camera.start_finder(viewfinder)
16 | lock = e32.Ao_lock()
17 | lock.wait()
18 |
19 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/035-minicam.py:
--------------------------------------------------------------------------------
1 |
2 | import camera
3 | photo = camera.take_photo()
4 | photo.save("E:\\Images\\minicam.jpg")
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/036-camera.py:
--------------------------------------------------------------------------------
1 |
2 | import e32, camera, appuifw, key_codes
3 |
4 | def viewfinder(img):
5 | canvas.blit(img)
6 |
7 | def shoot():
8 | camera.stop_finder()
9 | photo = camera.take_photo(size = (640, 480))
10 | w, h = canvas.size
11 | canvas.blit(photo, target = (0, 0, w, 0.75 * w), scale = 1)
12 | photo.save('e:\\Images\\photo.jpg')
13 |
14 | def quit():
15 | app_lock.signal()
16 |
17 | appuifw.app.body = canvas = appuifw.Canvas()
18 | appuifw.app.title = u"Camera"
19 | appuifw.app.exit_key_handler = quit
20 |
21 | camera.start_finder(viewfinder)
22 | canvas.bind(key_codes.EKeySelect, shoot)
23 |
24 | app_lock = e32.Ao_lock()
25 | app_lock.wait()
26 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/040-directory.py:
--------------------------------------------------------------------------------
1 |
2 | import os, os.path
3 |
4 | PATH = u"C:\\Data\\MyApp"
5 | if not os.path.exists(PATH):
6 | os.makedirs(PATH)
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/041-fileio.py:
--------------------------------------------------------------------------------
1 |
2 | f = file(u"c:\\python\\test.txt", "w+")
3 | print >> f, "Ip dip, sky blue"
4 | f.seek(0)
5 | print "File says", f.read()
6 | f.close()
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/042-readsound.py:
--------------------------------------------------------------------------------
1 |
2 | f = file('E:\\Sounds\\Digital\\boo.wav', 'r')
3 | mysound = f.read()
4 | f.close()
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/043-readimage.py:
--------------------------------------------------------------------------------
1 |
2 | f = file('E:\\Images\\picture.jpg', 'r')
3 | img = f.read()
4 | f.close()
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/044-readvideo.py:
--------------------------------------------------------------------------------
1 |
2 | f = file('E:\\Videos\\200703\\video.mp4','r')
3 | myvideo = f.read()
4 | f.close()
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/045-rwtext.py:
--------------------------------------------------------------------------------
1 |
2 | def save_list(filename, list):
3 | f = file(filename, "w")
4 | for item in list:
5 | print >> f, item
6 | f.close()
7 |
8 | def load_list(filename):
9 | f = file(filename, "r")
10 | lst = []
11 | for line in f:
12 | lst.append(line.strip())
13 | f.close()
14 | return lst
15 |
16 | test_list = ["first line", "second line", "that's all"]
17 | save_list(u"c:\\python\\test.txt", test_list)
18 | print load_list(u"c:\\python\\test.txt")
19 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/046-dictfile.py:
--------------------------------------------------------------------------------
1 |
2 | def save_dictionary(filename, dict):
3 | f = file(filename, "w")
4 | for key, value in dict.items():
5 | print >> f, "%s: %s" % (key, value)
6 | f.close()
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/047-filedict.py:
--------------------------------------------------------------------------------
1 |
2 | def load_dictionary(filename):
3 | f = file(filename, "r")
4 | dict = {}
5 | for line in f:
6 | key, value = line.split(":")
7 | dict[key.strip()] = value.strip()
8 | f.close()
9 | return dict
10 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/048-localdb.py:
--------------------------------------------------------------------------------
1 |
2 | import e32dbm
3 |
4 | DB_FILE = u"c:\\python\\test.db"
5 |
6 | def write_db():
7 | db = e32dbm.open(DB_FILE, "cf")
8 | db[u"host"] = u"www.google.com"
9 | db[u"port"] = u"80"
10 | db[u"username"] = u"musli"
11 | db[u"password"] = u"my secret"
12 | db.close()
13 |
14 | def read_db():
15 | db = e32dbm.open(DB_FILE, "r")
16 | for key, value in db.items():
17 | print "KEY", key, "VALUE", value
18 | db.close()
19 |
20 | print "Writing db.."
21 | write_db()
22 | print "Reading db.."
23 | read_db()
24 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/049-location.py:
--------------------------------------------------------------------------------
1 |
2 | import location
3 | print location.gsm_location()
4 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/050-gsmloca.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, e32, location, time, os.path
3 |
4 | PATH = u"E:\\Data\\gsm_loca\\"
5 | if not os.path.exists(PATH):
6 | os.makedirs(PATH)
7 |
8 | INTERVAL = 5.0
9 | CELL_FILE = PATH + "known_cells.txt"
10 | LOG_FILE = PATH + "visited_cells.txt"
11 | log = file(LOG_FILE, "a")
12 | timer = e32.Ao_timer()
13 |
14 | def current_location():
15 | gsm_loc = location.gsm_location()
16 | return "%d/%d/%d/%d" % gsm_loc
17 |
18 | def show_location():
19 | loc = current_location()
20 | if loc in known_cells:
21 | here = known_cells[loc]
22 | print "You are currently at", here
23 | else:
24 | here = ""
25 | print "Unknown location", loc
26 |
27 | print >> log, time.ctime(), loc, here
28 | timer.after(INTERVAL, show_location)
29 |
30 | def name_location():
31 | loc = current_location()
32 | name = appuifw.query(u"Name this location", "text")
33 | if name:
34 | known_cells[loc] = name
35 |
36 | def load_cells():
37 | global known_cells
38 | try:
39 | known_cells = load_dictionary(CELL_FILE)
40 | except:
41 | known_cells = {}
42 |
43 | def quit():
44 | print "SAVING LOCATIONS TO", CELL_FILE
45 | save_dictionary(CELL_FILE, known_cells)
46 | print "GSM LOCATIONING APP EXITS"
47 | timer.cancel()
48 | log.close()
49 | app_lock.signal()
50 |
51 | appuifw.app.exit_key_handler = quit
52 | appuifw.app.title = u"GSM location App"
53 | appuifw.app.menu = [(u"Name this location", name_location)]
54 |
55 | print "RECORDING VISITED CELLS TO", LOG_FILE
56 | print "LOADING LOCATIONS FROM", CELL_FILE
57 | load_cells()
58 | print "%d KNOWN CELLS LOADED" % len(known_cells)
59 | show_location()
60 |
61 | print "GSM LOCATIONING APP STARTED"
62 | app_lock = e32.Ao_lock()
63 | app_lock.wait()
64 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/054-obexdisco.py:
--------------------------------------------------------------------------------
1 |
2 | import socket
3 | address, services = socket.bt_obex_discover()
4 | print "Chosen device:", address, services
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/055-rfcommdisco.py:
--------------------------------------------------------------------------------
1 |
2 | import socket
3 | address, services = socket.bt_discover()
4 | print "Chosen device:", address, services
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/056-photosphone.py:
--------------------------------------------------------------------------------
1 |
2 | import camera, e32, socket, appuifw
3 |
4 | PHOTO = u"e:\\Images\\bt_photo_send.jpg"
5 |
6 | def send_photo():
7 | try:
8 | address, services = socket.bt_obex_discover()
9 | except:
10 | appuifw.note(u"OBEX Push not available", "error")
11 | return
12 |
13 | if u'OBEX Object Push' in services:
14 | channel = services[u'OBEX Object Push']
15 | socket.bt_obex_send_file(address, channel, PHOTO)
16 | appuifw.note(u"photo sent", "info")
17 | else:
18 | appuifw.note(u"OBEX Push not available", "error")
19 |
20 | def take_photo():
21 | photo = camera.take_photo()
22 | canvas.blit(photo, scale = 1)
23 | photo.save(PHOTO)
24 |
25 | def quit():
26 | app_lock.signal()
27 |
28 | canvas = appuifw.Canvas()
29 | appuifw.app.body = canvas
30 | appuifw.app.exit_key_handler = quit
31 | appuifw.app.title = u"BT photo send"
32 | appuifw.app.menu = [(u"Take photo", take_photo),
33 | (u"Send photo", send_photo)]
34 | app_lock = e32.Ao_lock()
35 | app_lock.wait()
36 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/057-btchat.py:
--------------------------------------------------------------------------------
1 |
2 | import socket, appuifw
3 |
4 | def chat_server():
5 | server = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
6 | channel = socket.bt_rfcomm_get_available_server_channel(server)
7 | server.bind(("", channel))
8 | server.listen(1)
9 | socket.bt_advertise_service(u"btchat", server, True, socket.RFCOMM)
10 | socket.set_security(server, socket.AUTH | socket.AUTHOR)
11 | print "Waiting for clients..."
12 | conn, client_addr = server.accept()
13 | print "Client connected!"
14 | talk(conn, None)
15 |
16 | def chat_client():
17 | conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
18 | address, services = socket.bt_discover()
19 | if 'btchat' in services:
20 | channel = services[u'btchat']
21 | conn.connect((address, channel))
22 | print "Connected to server!"
23 | talk(None, conn)
24 | else:
25 | appuifw.note(u"Target is not running a btchat server",
26 | "error")
27 |
28 |
29 | def receive_msg(fd):
30 | print "Waiting for message.."
31 | reply = fd.readline()
32 | print "Received: " + reply
33 | appuifw.note(unicode(reply), "info")
34 |
35 | def send_msg(fd):
36 | msg = appuifw.query(u"Send a message:", "text")
37 | print "Sending: " + msg
38 | print >> fd, msg
39 |
40 | def talk(client, server):
41 | try:
42 | if server:
43 | fd = server.makefile("rw", 0)
44 | receive_msg(fd)
45 | if client:
46 | fd = client.makefile("rw", 0)
47 | while True:
48 | send_msg(fd)
49 | receive_msg(fd)
50 | except:
51 | appuifw.note(u"Connection lost", "info")
52 | if client: client.close()
53 | if server: server.close()
54 | print "Bye!"
55 |
56 | index = appuifw.popup_menu([u"New server", u"Connect to server"],
57 | u"BTChat mode")
58 | if index != None:
59 | if index:
60 | chat_client()
61 | else:
62 | chat_server()
63 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/059-btclient.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw, socket, e32
3 |
4 | ECHO = True
5 |
6 | def choose_service(services):
7 | names = []
8 | channels = []
9 | for name, channel in services.items():
10 | names.append(name)
11 | channels.append(channel)
12 | index = appuifw.popup_menu(names, u"Choose service")
13 | return channels[index]
14 |
15 | def read_and_echo(fd):
16 | buf = r = ""
17 | while r != "\n" and r != "\r":
18 | r = fd.read(1)
19 | if ECHO: fd.write(r)
20 | buf += r
21 | if ECHO: fd.write("\n")
22 | return buf
23 |
24 | address, services = socket.bt_discover()
25 | channel = choose_service(services)
26 | conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
27 | conn.connect((address, channel))
28 | to_peer = conn.makefile("rw", 0)
29 |
30 | while True:
31 | msg = appuifw.query(u"Send a message", "text")
32 | if msg:
33 | print >> to_peer, msg + "\r"
34 | print "Sending: " + msg
35 | print "Waiting for reply..."
36 | reply = read_and_echo(to_peer).strip()
37 | appuifw.note(unicode(reply), "info")
38 | if reply.find("bye!") != -1:
39 | break
40 | else:
41 | break
42 | to_peer.close()
43 | conn.close()
44 | print "bye!"
45 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/060-pyserialpc.py:
--------------------------------------------------------------------------------
1 |
2 | import serial, sys, random
3 |
4 | if sys.platform.find("win") != -1:
5 | PORT = 0
6 | elif sys.platform.find("linux") != -1:
7 | PORT = "/dev/rfcomm0"
8 | elif sys.platform.find("darwin") != -1:
9 | PORT = "/dev/tty.pybook"
10 |
11 | num = random.randint(1, 10)
12 |
13 | serial = serial.Serial(PORT)
14 | print "Waiting for message..."
15 | while True:
16 | msg = serial.readline().strip()
17 | guess = int(msg)
18 | print "Guess: %d" % guess
19 | if guess > num:
20 | print >> serial, "My number is smaller"
21 | elif guess < num:
22 | print >> serial, "My number is larger"
23 | else:
24 | print >> serial, "Correct! bye!"
25 | break
26 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/062-gpsreader.py:
--------------------------------------------------------------------------------
1 |
2 | import socket
3 |
4 | address, services = socket.bt_discover()
5 | print "Discovered: %s, %s" % (address, services)
6 | target = (address, services.values()[0])
7 |
8 | conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
9 | conn.connect(target)
10 | to_gps = conn.makefile("r", 0)
11 |
12 | while True:
13 | msg = to_gps.readline()
14 | if msg.startswith("$GPGGA"):
15 | gps_data = msg.split(",")
16 | lat = gps_data[2]
17 | lon = gps_data[4]
18 | break
19 |
20 | to_gps.close()
21 | conn.close()
22 | print "You are now at latitude %s and longitude %s" % (lat, lon)
23 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/063-telephone.py:
--------------------------------------------------------------------------------
1 |
2 | import telephone, e32
3 |
4 | telephone.dial('+1412345602')
5 | e32.ao_sleep(10)
6 | telephone.hang_up()
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/064-contacts.py:
--------------------------------------------------------------------------------
1 |
2 | import contacts, appuifw, telephone
3 |
4 | name = appuifw.query(u'Call to', 'text')
5 | db = contacts.open()
6 | entries = db.find(name)
7 | names = []
8 | for item in entries:
9 | names.append(item.title)
10 | if names:
11 | index = appuifw.selection_list(names, search_field=0)
12 | num = entries[index].find('mobile_number')
13 | if num:
14 | telephone.dial(num[0].value)
15 | else:
16 | appuifw.note(u'Missing mobile phone number', 'error')
17 | else:
18 | appuifw.note(u'No matches','error')
19 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/065-sysinfo.py:
--------------------------------------------------------------------------------
1 |
2 | import sysinfo
3 | print "Battery level: %d" % sysinfo.battery()
4 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/066-httpclient.py:
--------------------------------------------------------------------------------
1 |
2 | import urllib
3 | page = urllib.urlopen("http://www.python.org").read()
4 | print page
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/067-logodownloader.py:
--------------------------------------------------------------------------------
1 |
2 | import urllib, appuifw, e32
3 |
4 | URL = "http://www.python.org/images/python-logo.gif"
5 |
6 | dest_file = u"E:\\Images\\python-logo.gif"
7 | urllib.urlretrieve(URL, dest_file)
8 |
9 | lock = e32.Ao_lock()
10 | viewer = appuifw.Content_handler(lock.signal)
11 | viewer.open(dest_file)
12 | lock.wait()
13 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/068-photouploader.py:
--------------------------------------------------------------------------------
1 |
2 | import camera, httplib
3 |
4 | PHOTO = u"e:\\Images\\photo_upload.jpg"
5 |
6 | def photo():
7 | photo = camera.take_photo()
8 | photo.save(PHOTO)
9 |
10 | def upload():
11 | image = file(PHOTO).read()
12 | conn = httplib.HTTPConnection("www.myserver.com")
13 | conn.request("POST", "/upload.php", image)
14 | conn.close()
15 |
16 | photo()
17 | print "photo taken"
18 | upload()
19 | print "uploading done"
20 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/069-testserver.py:
--------------------------------------------------------------------------------
1 |
2 | import SocketServer
3 |
4 | class Server(SocketServer.TCPServer):
5 | allow_reuse_address = True
6 |
7 | class Handler(SocketServer.StreamRequestHandler):
8 | def handle(self):
9 | print "CLIENT IP %s:%d" % self.client_address
10 | print "Message: " + self.rfile.readline()
11 |
12 | server = Server(('', 9000), Handler)
13 | print "WAITING FOR NEW CONNECTIONS.."
14 | server.serve_forever()
15 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/070-tcpclient.py:
--------------------------------------------------------------------------------
1 |
2 | import socket
3 |
4 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5 | sock.connect(("192.168.0.2", 9000))
6 | out = sock.makefile("rw", 0)
7 | print >> out, "Hi! I'm the TCP client"
8 | out.close()
9 | print "Client ok"
10 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/072-defaultap.py:
--------------------------------------------------------------------------------
1 |
2 | import socket
3 |
4 | ap_id = socket.select_access_point()
5 | apo = socket.access_point(ap_id)
6 | socket.set_default_access_point(apo)
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/077-phoneip.py:
--------------------------------------------------------------------------------
1 |
2 | import socket
3 | ap_id = socket.select_access_point()
4 | apo = socket.access_point(ap_id)
5 | apo.start()
6 | print "PHONE IP IS", apo.ip()
7 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/085-wsreqhandlers.py:
--------------------------------------------------------------------------------
1 |
2 | def init_server():
3 | global phone_req, cache
4 | phone_req = {}
5 | cache = {}
6 |
7 | def process_json(msg):
8 | global cache
9 | cache = msg
10 | return phone_req
11 |
12 | def process_get(path, query):
13 | phone_req[path] = True
14 | if path in cache:
15 | return cache[path]
16 | return "text/plain",\
17 | "Your request is being processed."\
18 | "Reload the page after a while."
19 |
20 | init_server()
21 | httpd = Server(('', 9000), Handler)
22 | httpd.serve_forever()
23 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/101-listcomph.py:
--------------------------------------------------------------------------------
1 |
2 | a = ["user%d" % x for x in range(10)]
3 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/102-searchlistcomph.py:
--------------------------------------------------------------------------------
1 |
2 | import inbox, appuifw
3 |
4 | box = inbox.Inbox()
5 | query = appuifw.query(u"Type in the query", "text")
6 |
7 | hits = [sms_id for sms_id in box.sms_messages()\
8 | if box.content(sms_id).find(query) != -1]
9 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/103-inputsanita.py:
--------------------------------------------------------------------------------
1 |
2 | input = " this is, a TEST input!"
3 | allowed = "abcdefghijklmnopqrstuvwxyz"
4 | print "".join([c for c in input if c in allowed])
5 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/104-distconst.py:
--------------------------------------------------------------------------------
1 |
2 | a = [1, 2, "a", 1, "b", 2, "b"]
3 | print len(dict([(x, True) for x in a]))
4 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/105-symtable.py:
--------------------------------------------------------------------------------
1 |
2 | import appuifw
3 |
4 | def bark():
5 | appuifw.note(u"Ruff ruff!")
6 |
7 | def sing():
8 | appuifw.note(u"Tralala")
9 |
10 | func_name = appuifw.query(u"What shall I do?", "text")
11 | func = globals()[func_name]
12 | print globals()
13 | func()
14 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/107-custommod.py:
--------------------------------------------------------------------------------
1 |
2 | import mymodule, appuifw
3 |
4 | appuifw.note(u"This is the main program")
5 | mymodule.askword()
6 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/108-autoupdate.py:
--------------------------------------------------------------------------------
1 |
2 | import urllib
3 |
4 | CODE = "mytest.py"
5 | URL = "http://www.myownserver.com/pycode/"
6 |
7 | code = urllib.urlopen(URL + CODE).read()
8 | f = file(u"E:\\Python\\" + CODE, "w")
9 | f.write(code)
10 | f.close()
11 | print "File %s updated succesfully!" % CODE
12 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/109-plugin.py:
--------------------------------------------------------------------------------
1 |
2 | import urllib, appuifw
3 |
4 | URL = "http://www.myownserver.com/pycode/"
5 |
6 | def download_plugin(plugin_name):
7 | filename = plugin_name + ".py"
8 | code = urllib.urlopen(URL + filename).read()
9 | f = file(u"E:\\Python\\Lib\\" + filename, "w")
10 | f.write(code)
11 | f.close()
12 | return __import__(plugin_name)
13 |
14 | plugin_name = appuifw.query(u"Give plug-in name", "text")
15 | print "Downloading plugin", plugin_name
16 | plugin = download_plugin(plugin_name)
17 | print "Plugin loaded!"
18 | plugin.askword()
19 |
20 |
--------------------------------------------------------------------------------
/PyS60 from Mobile Python Book/124-mobileosc.py:
--------------------------------------------------------------------------------
1 | import appuifw, e32, graphics, key_codes, socket, OSCmobile
2 |
3 | sound = 0
4 | y_pos_contr = 100
5 |
6 | slidershaft = graphics.Image.open("e:\\background.jpg")
7 |
8 | makeMaskTemp = graphics.Image.open('e:\\controller_mask.jpg')
9 | makeMaskTemp.save("e:\\controller_mask.png", bpp=1)
10 | contrMask = graphics.Image.new(size = (97,149),mode = '1')
11 | contrMask.load("e:\\controller_mask.png")
12 | contr = graphics.Image.open("e:\\controller.jpg")
13 |
14 | makeMaskTemp = graphics.Image.open('e:\\button_mask.jpg')
15 | makeMaskTemp.save("e:\\button_mask.png", bpp=1)
16 | buttnMask = graphics.Image.new(size = (111,78),mode = '1')
17 | buttnMask.load("e:\\button_mask.png")
18 | buttnOn = graphics.Image.open("e:\\button_red.jpg")
19 | buttnOff = graphics.Image.open("e:\\button_dark.jpg")
20 |
21 | def keys(event):
22 | global y_pos_contr, sound
23 | if event['keycode'] == key_codes.EKeyDownArrow:
24 | if y_pos_contr < 260 :
25 | y_pos_contr = y_pos_contr + 5
26 | sending(str(3))
27 |
28 | if event['keycode'] == key_codes.EKeyUpArrow:
29 | if y_pos_contr > 0 :
30 | y_pos_contr = y_pos_contr - 5
31 | sending(str(4))
32 |
33 | if event['keycode'] == key_codes.EKeySelect:
34 | if sound == 1:
35 | sound = 0
36 | else:
37 | sound = 1
38 | sending(str(5))
39 |
40 | handle_redraw(())
41 |
42 | def handle_redraw(rect):
43 | global sound, img, w,h
44 | img.blit(slidershaft, target = (0,0,w,h))
45 | img.blit(contr, target=(142,y_pos_contr), mask=contrMask)
46 | if sound == 1:
47 | img.blit(buttnOn, target=(8,328), mask=buttnMask)
48 | else:
49 | img.blit(buttnOff, target=(8,328), mask=buttnMask)
50 | canvas.blit(img, target = (0,0,w,h), scale = 1 )
51 |
52 | def choose_service(services):
53 | names = []
54 | channels = []
55 | for name, channel in services.items():
56 | names.append(name)
57 | channels.append(channel)
58 | index = appuifw.popup_menu(names, u"Choose service")
59 | return channels[index]
60 |
61 | def connect():
62 | global sock
63 | address, services = socket.bt_discover()
64 | channel = choose_service(services)
65 | sock = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
66 | sock.connect((address, channel))
67 |
68 | def sending(data):
69 | global sock
70 | message = OSCmobile.OSCMessage()
71 | message.setAddress("/phone/user1")
72 | message.append(data)
73 | sock.send(message.getBinary())
74 |
75 | def quit():
76 | app_lock.signal()
77 |
78 | canvas=appuifw.Canvas(event_callback=keys,redraw_callback=handle_redraw)
79 | appuifw.app.body=canvas
80 | appuifw.app.screen='full'
81 | w, h = canvas.size
82 | img = graphics.Image.new((w,h))
83 | appuifw.app.exit_key_handler=quit
84 | handle_redraw(())
85 | connect()
86 | app_lock = e32.Ao_lock()
87 | app_lock.wait()
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # pys60-examples-mega-pack
2 |
3 | These examples will help you if you code for PyS60.
4 | Most of them are tested on PyS60 v1.4.5 (based on Python 2.5.4) and PyS60 2.0.0 (based on Python 2.5.4).
5 |
6 | Please open issues for bugs and errors, I will take a look at them
--------------------------------------------------------------------------------
/app_skeleton.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NuruDashdamir/pys60-examples-mega-pack/0689954ad962ee519bab0b279fd94a55893f0846/app_skeleton.zip
--------------------------------------------------------------------------------