here2share

PyS60 Snippets Galore

May 11th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 207.69 KB | None | 0 0
  1. PyS60 Snippets Galore
  2.  
  3. Table of contents:
  4. 001. "Brief History of Python".....
  5. 002. "Introduction to Basic Pys60".....
  6. 003. "Basic Python Symbian Application".....
  7. 004. "Learning to Create a Simple Python Script".....
  8. 005. "How to Make Your Own Application on HP Symbian or HP Make With Using Python Application".....
  9. 006. "How to Turn S60v3 Application into S60v2 Application".....
  10. 007. "Trick Accelerate Menu of HP Symbian S60v1 and S60v2 Simple Without Application and Move Cache to Memory Card".....
  11. 008. "Zntxhan app".....
  12. 009. "Py2Pyc Applications".....
  13. 010. "About Python-Based Applications and Its Functions".....
  14. 011. "Name the File Bulkly".....
  15. 012. "Creating Serial Number".....
  16. 013. "Making Google Translate Translator" Translate.....
  17. 014. "Cutting Image".....
  18. 015. "Wearing Special Character".....
  19. 016. "File Handling".....
  20. 017. "List".....
  21. 018. "Dictionary".....
  22. 019. "Dictionary and List".....
  23. 020. "2D Image".....
  24. 021. "Writing Text and Tittle On Application".....
  25. 022. "Perulangbn For Function".....
  26. 023. "Condition If".....
  27. 024. "Menu, Submenu and Popup Menu".....
  28. 025. "Minimize a Program Using Script Pys60".....
  29. 026. "Creating Password Script Pys60".....
  30. 027. "Py Script To Show Weak Battery".....
  31. 028. "Simple Script Makes Popup Menu".....
  32. 029. "Reading File With Powlite_Fm Module".....
  33. 030. "Changing Image Size Using Script".....
  34. 031. "Use Password Script On An Application".....
  35. 032. "Py Script To Backup File".....
  36. 033. "Multi Selection List".....
  37. 034. "Audio (Playing Mp3 1 Folder)".....
  38. 035. "Charging Name Less Than and More Than 5 Characters".....
  39. 036. "Multi_Query".....
  40. 037. "Simple Form"....
  41. 038. "Create Progressbar".....
  42. 039. "Displays Applications Already Installed In List Form".....
  43. 040. "Calling Image With Module From Graphics Import *".....
  44. 041. "The .Ttx File Dialing Script".....
  45. 042. "Text Script Being Voice".....
  46. 043. "Script To Call and Open Applications Outside Application System".....
  47. 044. "Script To Play Mp3 On Define Function".....
  48. 045. "Calling Text Using Glob Module Through Python Script".....
  49. 046. "How to Include Music or Mp3 into a Python Application".....
  50. 047. "Basic Logic Game Code Order".....
  51. 048. "Implementing 3D Computing Basics With Pys60" (Part 1).....
  52. 049. "Implementing 3D Computing Basics With Pys60" (p.2).
  53. 050. "Implementing 3D Computing Basics With Pys60" (ch.3).
  54. 051. "List, Function and Class".....
  55. 052. "Meload External Image With Image 1st Module".....
  56. 053. "Example Game Program Scissors, Stone, Paper".....
  57. 054. "Little Explanation of Identification in Python".....
  58. 055. "Heat Seeking Missile Alogarithm and Implementation".....
  59. 056. "Making Quiz With Pys60".....
  60. 057. "Reading the Message With Pys60".....
  61. 058. "Some Python Script Writing Style".....
  62. 059. "Displays IP With Pys60".....
  63. 060. "TxtField Module".....
  64. 061. "Repetition For In Pys60".....
  65. 062. "Double Menu Popup With Pys60".....
  66. 063. "Checking and Creating Folders With Pys60".....
  67. 064. "One Syntak Difference S60v1 and S60v2 Above"....
  68. 065. "Polygon Rotation With Pys60".....
  69. 066. "Scan Fill Drive With Pys60".....
  70. 067. "Combining Functions With Progress On Pys60".....
  71. 068. "Pys60 Script Encoded".....
  72. 069. "Displays All Application Icon Installed With Pys60".....
  73. 070. "Creating 4 Direction Cursor On Application With Pys60".....
  74. 071. "Making Analog Clock With Pys60".....
  75. 072. "Signal Indicator, Battery With FgImage (Pys60)".....
  76. 073. "Set FgImage On StandBy Pys60".....
  77. 074. "Screenshot With N-Gage or S60v1 (Pys60)".....
  78. 075. "Making Graph (Script Pys60)".....
  79. 076. "Get Coordinate Arround Circle (Pys60)".....
  80. 077. "Adjust Timing Subtittle With Python".....
  81. 078. "Creating Grid Menu 3x3 (Pys60)".....
  82. 079. "Creating a Simple Calculator".....
  83. 080. "Make Text Run With Backgroud Sound".....
  84. 081. "Make Popup Aa Check Pulsa".....
  85. 082. "Sending SMS Most Number".....
  86. 083. "Function of Appuifw Module".....
  87. 084. "Simple Scanning Application".....
  88. 085. "Text Editor Application".....
  89. 086. "Camera Motion".....
  90. 087. "Indicator Battery HP".....
  91. 088. "How to Store Audio".....
  92. 089. "Playing Mp3 File".....
  93. 090. "Text Talk".....
  94. 091. "How to Find Words in Inbox".....
  95. 092. "Accessing Inbox".....
  96. 093. "Selection List".....
  97. 094. "Two Dialogs".....
  98. 095. "Enter Name".....
  99. 096. "How to Record Audio".....
  100. 097. "Creating Selection List".....
  101. 098. "Making Popup Menu".....
  102. 099. "Creating a Code App".....
  103. 100. "Making Keygen".....
  104.  
  105.  
  106.  
  107. ==========
  108.  
  109.  
  110.  
  111. 001.
  112.  
  113. "BRIEF PYTHON HISTORY"
  114.  
  115. I want to share about Python history, what is Python, what is Python usefulness, all about yhon...
  116.  
  117. Python for s60 is a high-level programming language that is a derivative of Python Language.
  118.  
  119. Given the Python s60 programming language, it is possible to create a simple Script or even a complex program that can be applied to s60 type phones. So with Python s60, we can make the program directly through the Symbian-based phones on the phone that is old school or the latest version. So we can creativity by creating simple scripts or a program that can be run. But Python's ability can also make your phone end up with flash due to a fatal error.
  120.  
  121. Brief and concise history of Python.
  122. If we see the name we must think that this Python name is taken from a type of snake called pithon, maybe because the creator likes snakes or amazed with the ability of pithon githu, common human mind is not it? But in fact not. The fact Naming programming language is based on the creator when he watched comedy shows on television on BBC named Monty Python's Flying Circus. Python was created by Guido Van Rossum in 1989 in Amsterdam Netherlands. This language provides many modules that can be used for various needs such as desktop applications, networks, and servers. However this programming language has a response or process that is slightly slower than C or Java programming language.
  123.  
  124. Previously, this language is a programming language that can only be run through a PC. But now it can be directly run on mobile devices based on Windows Mobile, Palm and Symbian.
  125.  
  126. So, for programmer friends or who want to learn programming language but limited do not have PC or Laptop only have HP symbian need not be discouraged. Because in Python s60 we are very possible to do programming wherever and whenever with HP symbian without having to bring PC or Laptop everywhere.
  127.  
  128.  
  129.  
  130. ==========
  131.  
  132.  
  133.  
  134. 002.
  135.  
  136. "PYS60 BASIC INTRODUCTION"
  137.  
  138. I want to share about pys60...
  139.  
  140. What is a pys60?
  141. - pys60 is the derived programming language of Python for s60 phones.
  142.  
  143. What is pys60 or Python on the phone?
  144. - create a script, make programs, create applications, games.
  145.  
  146. How do I install Python on my phone or mobile phone or HP?
  147. - find out your brapa version of HP, then download the basic Python that fits your phone.
  148.  
  149. Where do I find out what version of HP or my mobile phone?
  150. - find out here
  151. http://www.developer.nokia.com/Devices/Device_specifications/?filter2=s60
  152.  
  153. What basic Python is there?
  154. - Python basic 1.45, Python module pack 1.33, Python shell script (all must be installed on same drive).
  155.  
  156. Python modif same basic Python same not?
  157. - basic is same, only, Python modif have more module.
  158.  
  159. Download Python basic, Python modif?
  160. - http://ichunk.mywapblog.com/python-basic-pys60-s60v123.xhtml
  161. - http://maxraider.wen.ru/Maxraider-phyton.html
  162. - http://arvana.mywapblog.com/python-modif-v1-7-0-s60v2.xhtml
  163.  
  164. If the new module is not there? Where to download?
  165. - http://watt.eu5.org
  166. - http://www.agus-ibrahim.net/
  167.  
  168. In Python there is an alien term ..
  169. - syntax: line of sentences
  170. - script: a collection of syntax that can run a program
  171. - string: letters
  172. - integer: numbers
  173. - identification:
  174. - interactive console:
  175.  
  176. What Python script features?
  177. - ending in .py, .pyc,, pyd
  178.  
  179. Writing Python script how?
  180. - use ped, x-plore, dedit, or other Python editor apps, as per individual taste. save it with a .py extension
  181. - special x-plore, uncheck "save as unicode" before saving.
  182.  
  183. How to run the script we have created how?
  184. - open Python, run script that we have saved earlier.
  185.  
  186.  
  187.  
  188.  
  189. ==========
  190.  
  191.  
  192.  
  193. 003.
  194.  
  195. "PYTHON SYMBIAN BASIC APPLICATIONS"
  196.  
  197. I want to share a little information about HP Symbian and Python...
  198.  
  199. Previously we must know first our HP symbiam specifications. If you do not know at all we can visit the Device Specification in the Nokia Forum to find out our mobile neighbor. How to select our HP type of page. Then we will be taken to the Device Detail page, boxed Column that reads Technical Specs it tedapat technical specifications from our HP. To select pythonnya please see the series or edition and Feature packnya from our HP ditechnical specs earlier. Now please Download and select the appropriate python with your HP...
  200.  
  201. * Symbian s60v2 or s60 2nd Edition FP1
  202. -PythonScriptShell_1_4_5_2ndEd.SIS
  203. -PythonFors60_1_4_5_2ndEd.SIS
  204.  
  205. * Symbian s60v2 or s60 2nd Edition FP2
  206. -PythonScriptShell_1_4_5_2ndEdFP2.SIS
  207. -PythonFors60_1_4_5_2ndEdFP2.SIS
  208.  
  209. * Symbian s60v2 or s60 2nd Edition FP3
  210. -PythonScriptShell_1_4_5_2ndEdFP3.SIS
  211. -PythonFors60_1_4_5_2ndEdFP3.SIS
  212.  
  213. * Symbian s60v3 or S60 3rd Edition
  214. -PythonScriptShell_1_4_5_3rdEd.SIS
  215. -PythonFors60_1_4_5_3rdEd.sis
  216.  
  217. * Symbian s60v3 or v5 | s60 3rd or 5th Edition
  218. -Home Page (Pys60v1.0.x and 2.0.0) -Python_2.0.0.sis
  219. -Py Module Pack s60v3:
  220.  
  221. Note:
  222. Installation (specially s60v3).
  223.  
  224. 1. Python Script Shell and Python for s60 can be installed in phone memory (C :) or memory card (E :) but Python Module Pack must be installed in phone memory (C :)
  225.  
  226. 2. Python-based applications must be installed in the same place where Python script shell and Python for s60 are installed.
  227.  
  228. 3. It is strongly recommended to install Python script shell and Python for s60 on memory card (E :) so as not to incriminate HP performance.
  229.  
  230.  
  231.  
  232.  
  233. ==========
  234.  
  235.  
  236.  
  237. 004.
  238.  
  239. "LEARN MAKE SCRIPT PYTHON SIMPLE"
  240.  
  241. I want to share about how to create a Python script,
  242.  
  243. Python is a high-level scripting language program that benefits from simple syntax and human readability, a comprehensive core library, and the ability to extend using native code.
  244.  
  245. Python is a multi-paradigm language, supporting object-oriented and functional programming styles, inter alia, giving freedom to approach problems in various ways.
  246.  
  247. Python on Symbian (also known as "Python for s60" or "Pys60") is the Nokia port of the Python language for the Symbian platform. Python on Symbian was first released by Nokia at the end of 2004, and donated to the Symbian Foundation in early 2010.
  248. In the following chapters, we describe the latest versions of Python on Symbian, v2.0.0 for s60v3 and v1.4.5 for s60v2.
  249. Why Should I Use Python On Symbian? The main reason for using Python on Symbian is that it's easy to learn and you can do a lot with very little code.
  250.  
  251. Most people can read Python code with just a few hours of study and can start developing mobile apps not long after.
  252.  
  253. Applications made in Python are indistinguishable from native C ++ applications and for most purposes offer much of the same performance.
  254.  
  255. Most of the important functions available for native apps (for example, access to camera, device position, sensor, etc.) are exposed to Python apps via a simple API.
  256.  
  257. If you're an advanced developer in other programming languages ​​(like Symbian C ++, Java ME or others) you can also benefit by using Python for rapid application development. So little is needed when compared to other languages, that the application can be fully functional prototyped, shown and tested very quickly.
  258.  
  259. Python Application ("script" ) is just a text file containing code written in the Python programming language and named with the "py" file extension).
  260.  
  261. Scripts can be written using a text editor and can be run either from within the Python Interactive Shell application on the device or emulator device for the computer or can also be written via standalone applications that can be installed to Symbian devices, such as Dnotepads60v2, Pyedets60v2, if using X-plore red checkmark in "save as unicode" must be removed.
  262.  
  263. Sample Testing Python Script Script Interactive scripts make it very easy to test your script during development.
  264.  
  265. Shell is just an app that allows you to type and execute arbitrary Python commands or to load and run the entire script file. Let's make a simple Python app.
  266.  
  267. Write the following line of your edited text:
  268.  
  269. ----------------------------------------------------------------------------------------
  270. print "Hello! Python On Symbian"
  271. ----------------------------------------------------------------------------------------
  272.  
  273. If you are using X-plore, press menu    file    new text file   name the file with "ScriptPertamaku.py" and ok, then hit menu and click 'save as unicode' to uncheck red, then create script : print "Hello! Python On Symbian" ok. Testing On Symbian Devices. It's time you tested your script.
  274.  
  275. Move the file or 'My Script.py' to E: / System / apps / Python.
  276. Open the Python app and press options   run script  select 'ScriptPertamaku.py'
  277.  
  278. If you are successful then you will see textHello! Python On Symbian.
  279.  
  280. You can also run an existing script like ball.py, snake.py. Then next and create a second script.py
  281.  
  282. ----------------------------------------------------------------------------------------
  283. import appuifw
  284. appuifw.note (u 'Hello! Python On Symbian')
  285. ----------------------------------------------------------------------------------------
  286.  
  287. Test your second script, open Python    Run script and select Script Second .py
  288.  
  289. If you want to try the script again .. please see this script.
  290.  
  291.  
  292. Script appuifw
  293. To test it, open Python, Options    interactive console type
  294. import appuifw click ok
  295.  
  296. Put the script
  297. To show errors:
  298. ----------------------------------------------------------------------------------------
  299. appuifw.note
  300. (u 'Error.', 'error')
  301. click ok
  302. ----------------------------------------------------------------------------------------
  303.  
  304. To display information:
  305. ----------------------------------------------------------------------------------------
  306. appuifw.note
  307. (u 'Information.', 'info')
  308. ----------------------------------------------------------------------------------------
  309.  
  310. To display a confirmation:
  311. ----------------------------------------------------------------------------------------
  312. appuifw.note (u 'Success',' conf')
  313. ----------------------------------------------------------------------------------------
  314.  
  315. To show a question:
  316. ----------------------------------------------------------------------------------------
  317. appuifw.query ('Would you like to exit?' .decode ('utf-8?),' query')
  318. ----------------------------------------------------------------------------------------
  319.  
  320. For input commands;
  321. Name:
  322. ----------------------------------------------------------------------------------------
  323. appuifw.query (u "Enter name:", "text", u "Cebri Nugraha" )
  324. ----------------------------------------------------------------------------------------
  325.  
  326. Number:
  327. ----------------------------------------------------------------------------------------
  328. appuifw.query (u "Enter no.:","number")
  329. ----------------------------------------------------------------------------------------
  330.  
  331. Code:
  332. ----------------------------------------------------------------------------------------
  333. appuifw.query (u "input code:", "code" )
  334. ----------------------------------------------------------------------------------------
  335.  
  336. Date:
  337. ----------------------------------------------------------------------------------------
  338. appuifw.query (u "Put date:", "date" )
  339. ----------------------------------------------------------------------------------------
  340.  
  341. Time or hour:
  342. ----------------------------------------------------------------------------------------
  343. appuifw.query (u "Enter time:", "time" )
  344. ----------------------------------------------------------------------------------------
  345.  
  346. Float:
  347. ----------------------------------------------------------------------------------------
  348. appuifw.query (u "Put float:", "float" )
  349. ----------------------------------------------------------------------------------------
  350.  
  351. Query:
  352. ----------------------------------------------------------------------------------------
  353. appuifw.query (u "Input query:", "query" )
  354. ----------------------------------------------------------------------------------------
  355.  
  356. To set the application screen;
  357. Normal screen:
  358. ----------------------------------------------------------------------------------------
  359. appuifw.app.screen = 'normal'
  360. ----------------------------------------------------------------------------------------
  361.  
  362. Large screen:
  363. ----------------------------------------------------------------------------------------
  364. appuifw.app.screen = 'large'
  365. ----------------------------------------------------------------------------------------
  366.  
  367. Full screen:
  368. ----------------------------------------------------------------------------------------
  369. appuifw.app.screen = 'full'
  370. ----------------------------------------------------------------------------------------
  371.  
  372. ----------------------------------------------------------------------------------------
  373. appuifw.app.title = u "error"
  374. ----------------------------------------------------------------------------------------
  375.  
  376. To create a selection menu:
  377. ----------------------------------------------------------------------------------------
  378. appuifw.app.menu = []
  379. appuifw.popup_menu ([u "Option 1", u "Option 2", u "Option 3"])
  380. ----------------------------------------------------------------------------------------
  381.  
  382. Application background color:
  383. ----------------------------------------------------------------------------------------
  384. appuifw.app.body.color = 0xff0000
  385. ----------------------------------------------------------------------------------------
  386.  
  387.  
  388.  
  389. ==========
  390.  
  391.  
  392.  
  393. 005.
  394.  
  395. -Python
  396. -X-plorer
  397. -Sisboom
  398. -Linkaper
  399. -Ped
  400.  
  401. Once downloaded all the above applications please you install all the applications on HP, I suggest installing in external memory so that your HP is not slow after that follow these steps:
  402. Read more:
  403. 1. Create first scripnya this example python script I gave the name Azam restart.py
  404.  
  405. ----------------------------------------------------------------------------------------
  406. import appuifw
  407. import e32
  408. import switchoff
  409.  
  410. def restart():
  411.     a = appuifw.query (u'Atur Time Time: ',' number ')
  412.     e32.ao_sleep (a)
  413.     switchoff.Restart()
  414.  
  415. def shutdown():
  416.     b = appuifw.query (u'Enter a Second Time: ',' number ')
  417.     e32.ao_sleep (b)
  418.     switchoff.shutdown()
  419.  
  420. def azam():
  421.     appuifw.note (u 'this app was created by syamsul azam creator')
  422.  
  423.  
  424. appuifw.app.title = u 'Azam restar'
  425. appuifw.app.menu = [(u'Restart ', restart), (u'Shutdown', shutdown), (u'maker ', azam)]
  426. x = e32.Ao_lock()
  427. x.wait()
  428. ----------------------------------------------------------------------------------------
  429.  
  430. 2. The second step after copying the script above the save with the extension py so Azam restart.py
  431.  
  432. 3. The third step after disave with py extension, test first before packing into the application. If already tested the script applied Ped and run perfectly then packed by using linkaper application.
  433.  
  434. 4. The fourth step open the linkaper app> options> create app> select the script was to be used as an application that has been tested diaplikasi Ped.
  435.  
  436. 5. When finished, try to open the menu on your HP if there is no application first opened because the application has not been able to run perfectly.
  437.  
  438. 6. Next step open the x-plorer app in directory E: system / app / Azam restart
  439.  
  440. 7. The next step in default.py open and delete all the contents in default.py changed to "import Azam restart" if I recommend azam restartnya copy from the folder name to exact
  441.  
  442. 8. The next step is to copy the script you have tested and dipaste in Azam restart.
  443.  
  444. 9. Try to open menu then run the application that was made. The road or not, if not running means something is wrong.
  445.  
  446.  
  447.  
  448.  
  449.  
  450. ==========
  451.  
  452.  
  453.  
  454. 006.
  455.  
  456. "HOW TO CHANGE S60v3 APPLICATION BECOME A S60v2 APPLICATION"
  457.  
  458. I want to share how to change s60v3 application to s60v2, application that can be changed only application based on Python...
  459.  
  460. Equipment:
  461. 1.Linkapper
  462. 2.X-Plore
  463. 3.Sisboom v6-4
  464.  
  465. Here as an example I change the Application IDesigner owned by Symbian v3 to Symbian v2 Application.
  466.  
  467. 1. Create a new folder in E: / system / apps / (Application name)
  468. example: E: / system / apps / ImageDesigner
  469.  
  470. 2. Create a new text file and name it default.py in E: / system / apps / ImageDesigner
  471. The way to press menu> file> new text file and Menu- Save as unicode (uncheck the red) default.py is the first step to create Python-based applications, without it Applications can never be created.
  472.  
  473. 3. Open the LinkAPPer Application, click Options-Create new app. Then go to the newly created folder and select the default.py file created just now, it will display option Normal opening and Open with, select Normal opening.
  474.  
  475. 4. Then enter the name of the program: ImageDesigner then put it on drive E:\
  476.  
  477. 5. A notification will appear stating that a file with the same name already exists, stop it? Just hit "Cancel"
  478.  
  479. 6. Enter UID (or don 't touch): enter UID manually or just press Ok, select Ok
  480.  
  481. 7. Choice of type: select the icon to display dimenu, The App is created and will appear in the menu in afew seconds (choose by taste)
  482.  
  483. 8. You can see the icon on your mobile phone, but never open it first because it is not finished yet.
  484.  
  485. 9. Open Sisboom Application, use sisboom version above 6. if you use sisboom version below 6, you will never able to unpack sis or sisx file belongs s60v3. Unloading IDesigner rc 1.40 s60v3.sis
  486.  
  487. 10. Open X-plore and go to the folder where the python files are located (the unloading result)
  488.  
  489. 11. Mark the files one by one and move them to the Applications folder you created (E:\System\Apps\ImageDesigner) ./ If you have questions that will appear when you move the python files to the ImageDesigner folder, just hit Ok
  490.  
  491. 12. All has ended, test now by clicking the Application icon on your mobile phone. If it can be opened we can say that we succeed
  492.  
  493. 13. To make it a full s60v2 Application, silhakan your pack into one using Sisboom Application.
  494.  
  495.  
  496.  
  497.  
  498. ==========
  499.  
  500.  
  501.  
  502. 007.
  503.  
  504. "TRICK ACCESSIBLE MENU HP SYMBIAN S60v1 and S60v2 SIMPLE WITHOUT APPLICATIONS AND MOVE CACHE TO MEMORY CARD"
  505.  
  506.  
  507. Trick 01
  508. 1. Use x-plore
  509. 2. Select menu> new text
  510. 3. Create in c or in C> system> here or it could be in C / system> shareddata
  511. 4. Create its name Menu.cfg
  512. 5. Create the contents Z / System / Apps / Menu / Menu.app
  513. 6. Save
  514. 7. In order not hard hard to make that no 5... Copy aja writing... Or copy this article through your HP just hold the pen button and slide the right
  515. (Z / System / Apps / Menu / Menu.cfg)
  516.  
  517. Trick 02
  518. 1. Create a folder in C name Shareddata
  519. 2. After that make a text like way 1
  520. 3. Name it 101f8557.ini
  521. 4. Fill it with
  522.  
  523. ----------------------------------------------------------------------------------------
  524. CachEnable = True
  525. CacheSize = 20000000
  526. CacheDir = e:\cache
  527. ODomainUrl = http: //host53.nokia-boston.com/Cache_OpCache/Op_Menu.xhtml
  528. OCacheSize = 300000
  529. OCacheDir = c:\cache
  530. ----------------------------------------------------------------------------------------
  531.  
  532. The cache size section can be modified can be replaced 3.4 dst
  533. Press the pen button to copy the code.
  534.  
  535.  
  536.  
  537.  
  538. ==========
  539.  
  540.  
  541.  
  542. 008.
  543.  
  544. "ZNTXHAN APPLICATIONS"
  545.  
  546. I want to share about how to edit a compiled Python file...
  547.  
  548. Python files that have been decompiled can not be edited using x-plore as we are in .py file
  549.  
  550. Actually it can, but a bit complicated because we must edit from hex or chart...
  551.  
  552. To avoid complicated use Zntxhan to decompiling py scripts and make necessary modifications.
  553.  
  554. Sometimes it is difficult to decompile dile PYD, if you know Python encoding, you can use Zntxhan to enter new encoding.
  555.  
  556. Similarly after decompiling you can also translate RSC files and can translate the app in Indonesian without translating the script code because if you translate the script code it will be a problem for your application. Now again, I say that all Python S60v3 applications work on S60V2. So do not lose hope and try modif in the application.
  557.  
  558. Note:
  559. Make sure your phone is filled with python program.
  560.  
  561.  
  562.  
  563.  
  564. ==========
  565.  
  566.  
  567.  
  568. 009.
  569.  
  570. "PY2PYC APPLICATIONS"
  571.  
  572. I want to share a little information about Py2Pic applications...
  573.  
  574. Py2Pyc: Compile Your Own Python Code.
  575.  
  576. .py or .pyc? Plain text or binaries? In-compile or not, the program can still run. However, from some of the sources I get, compiled Python scripts have an edge over execution speeds instead of non-compiled scripts. Why? Because the script, before the execution will be changed from text to binary code that is understood by the machine.
  577.  
  578. Now let's start to compile:
  579.  
  580. To compile, we have three choices. That is using an existing program called py2pyc, manual using Python shell, and write your own simple py2pyc script. Of the three options, for me all the same because the result is the same:
  581.  
  582. Let's try one on one:
  583.  
  584. But before, let's make a script that will serve as an experiment. We create a simple script like the following,
  585.  
  586. ----------------------------------------------------------------------------------------
  587. # python script
  588.  
  589. def Hello():
  590.     # say hello :)
  591.     print "Hello World!"
  592.     # done!
  593.  
  594. # call the function
  595. Hello()
  596. ----------------------------------------------------------------------------------------
  597.  
  598. Save it on drive E:\to make it easy to find it ::
  599.  
  600. 1. Using Py2Pyc Program
  601. The first step is, download the Py2Pyc program, then do the installation as usual. Open Py2Pyc program, select [Options] -> [Select File]
  602. Find where the script will be compiled. Once found, click [OK] to mark then select [Options] -> [Done]
  603. Select [Options] again and select [Compile]. Done.
  604.  
  605. 2. Using the Command Line (Python Shell)
  606. Compiling python scripts using a command line is actually simpler because we only need to type in two command lines only.
  607. Start the Python program, select [Options] -> [Interactive console] then type the following command,
  608.  
  609. ----------------------------------------------------------------------------------------
  610.     import py_compile
  611.     py_compile.compile ("E:\\sayhello.py")
  612. ----------------------------------------------------------------------------------------
  613.  
  614. That's it and it's done. Our script has been compiled into a .pyc binary.
  615.  
  616. 3. Using Simple Scripts
  617. This method is actually the same as the number 2 (two). Only, we write the command into a file to be executed at any time without having to retype the code. In this step, we will create a script similar to the Py2Pyc program but can only compile one script in one session without the facility to mark. File facility we use the browser module named fm.
  618.  
  619. Let's make the script:
  620. import module required
  621.  
  622. ----------------------------------------------------------------------------------------
  623. import fm
  624. import py_compile
  625. import appuifw
  626. import os
  627.  
  628. def SelectFile():
  629.     '' 'Find and select files to compile' ''
  630.     appuifw.app.title = u "Select .py File"
  631.     # use the file manager function of the fm module
  632.     SF = fm.manager()
  633.     # Check the SF value. What is None?
  634.     # If None, the user pressed the cancel button
  635.     if SF! = None:
  636.         # check the file extension. .py or not
  637.         if os.path.basename (SF) [- 3:]. lower() == ". py":
  638.             # if you have a .py extension, compile it
  639.             try:
  640.                 py_compile.compile (SF)
  641.                 CDone()
  642.             except:
  643.                 # when the compilation fails, a message will appear
  644.                 appuifw.note (u "Error:% s: Can not be compiled"% os.path.basename (SF), "error")
  645.                 CError()
  646.         else:
  647.             # when the selected file does not have a .py extension
  648.             appuifw.note (u "% s: Not a python script!"% os.path.basename (SF), "info")
  649.             CError()
  650.     else:
  651.         # when the user presses the Cancel button
  652.         appuifw.note (u "Compilation undone!", "conf")
  653.  
  654. def CDone():
  655.     appuifw.note (u "Compile is successful!", "info")
  656.  
  657. def CError():
  658.     appuifw.note (u "Compilation failed!", "info")
  659.  
  660. appuifw.note (u "Select the file to compile,...", "info")
  661. SelectFile()
  662. ----------------------------------------------------------------------------------------
  663.  
  664. Save and locate it in the Python directory (E:\System\\Apps\\Python) to run through Python App. Then open the Python app, choose [Options] -> [Run Script] and select the script we just created.
  665.  
  666. The script will instantly open the browser file view and wait for input from you. [OK] or [Cancel].
  667.  
  668. Script Execution
  669. In the last session of this paper, we will discuss about how the execution of scripts that have not been and that have been compiled. As an experiment, we use the command line only:
  670.  
  671. ----------------------------------------------------------------------------------------
  672.     execfile ("E:\\sayhello.py")
  673. Hello World!
  674.    
  675. ----------------------------------------------------------------------------------------
  676.  
  677. Then, how to compile the script? Compiled scripts can not be executed in the above manner. When forced, will cause errors in Python Shell and Python Shell to be restarted.
  678.  
  679. The binaries of the Python script can be run using the import method. The usual method used to load Python module. And of course, the location of the compiled script should be listed in Python Path. If not, we can add the Path where the location of our script is using sys module.
  680.  
  681. ----------------------------------------------------------------------------------------
  682.     import sys
  683.     sys.path.append ("E:\\")
  684.     import sayhello
  685. Hello World!
  686.    
  687. ----------------------------------------------------------------------------------------
  688.  
  689. And if it turns out the import import sayhello does not work, we still can still call the function manually.
  690.  
  691. ----------------------------------------------------------------------------------------
  692.     import sayhello
  693.     sayhello.Hello()
  694. Hello World!
  695.    
  696. ----------------------------------------------------------------------------------------
  697.  
  698.  
  699.  
  700.  
  701.  
  702. ==========
  703.  
  704.  
  705.  
  706. 010.
  707.  
  708. "ABOUT APPLICATIONS BASED ON PYTHON AND ITS FUNCTIONS"
  709.  
  710. I want to share a little info about python-based apps and their script functions...
  711.  
  712. Confused to distinguish Python-based applications. Because there is no difference. If java kan runs slow in Symbian.
  713. Immediately discussed.
  714.  
  715. A python-based app will not run without the DEFAULT.PY file in that application folder (E:\System\Apps\NAMEAAPP_\default.py). But be careful also maybe the app is not python based but just a fake DEFAULT.PY file to cover-up. To ensure that the application wins really python based let's check the contents of DEFAULT.PY characters.
  716. If the character contains the # sign beside it there are only messages and afterwards no longer found the script means the file is not related to the application.
  717.  
  718. Example:
  719. # Script Python by xxxxxx
  720. # For more apps visit www.xxxxx.xx
  721.  
  722. Unless there is a script under IMPORT.
  723.  
  724. Example:
  725. # Script Python by xxxxxx
  726. # For more apps visit www.xxxxx.xx
  727. import xxxpy
  728.  
  729. Import is a calling function. For that check also whether in the application folder or folder libs there xxxpy.py file / xxxpy.pyc (E:\System\libs\).
  730.  
  731. If the DEFAULT.PY script contains long Syntax-syntax it is clear that the application is Python-based.
  732.  
  733. The conclusion:
  734. The python app calls each other-calling. Initially APLIKASI_BERBASIS_PYTHON.app calls the Default.py file in the folder and the Default file wins again to the next file eg to the libs folder or that is in the application folder.
  735.  
  736. Sample file:
  737. E:\System\Apps\ZIMPDA\
  738. there are files:
  739. - ZIMPDA.app * <Application *
  740. - ZIMPDA.aif
  741. - ZIMPDA.src
  742. - Default.py * <Script python *
  743. - main.pyc * <Compiled python script *
  744.  
  745. Example of default.py app ZIMPDA:
  746. # Script by Zidna Mmc
  747. # Bring up an error message
  748.  
  749. import appuifw * <This function calls py or pyc in the libs folder. Karna is not in the application folder. *
  750.  
  751. import main * <This function calls the py or pyc in the application folder *
  752.  
  753.  
  754. Example of the contents of the main.pyc file that was decompiled into main.py app ZIMPDA:
  755.  
  756. appuifw.note (u "Error gan, Systemnya again ga path", error)
  757.  
  758. appuifw.app.set_exit()
  759.  
  760. Note:
  761. So not necessarily all the programs are default.py files. As the example above. The default.py function is simply to call the main.pyc file and the main.pyc file that program the application, which is to generate the text error.
  762.  
  763.  
  764.  
  765.  
  766. ==========
  767.  
  768.  
  769.  
  770. 011.
  771.  
  772. "APPLY THE FILES ONLY MASS"
  773.  
  774. I want to share about scripts to name files in bulk...
  775.  
  776. We may often be faced with the problem of naming files in bulk. I mean, look at the mp3 file, sometimes the file name is like this: "Track 05.mp3? Create me a file name like that needs to be replaced and unfortunately replace one clear job tired.But do not worry, with pys60 everything can be resolved.
  777. To name files in bulk, of course we must use looping or looping function.
  778. Suppose we want to name the files with the name "song_1.mp3, lagu_2.mp3? Dst
  779. Here's an example script,
  780.  
  781. ----------------------------------------------------------------------------------------
  782. import os
  783. dirk = e:\\mp3
  784. dir = os.listdir(dirk)
  785. to = 1
  786. for file in dir:
  787.     path = dirk file
  788.     os.rename (path, dirk "lagu_" str (to) ".mp3?)
  789.     to = 1
  790. print 'Done'
  791. ----------------------------------------------------------------------------------------
  792.  
  793. Note:
  794. -In the path = dirk file. It means combining the file names in sequence with the place directory.
  795. -The purpose of     is the blocking of spaces which is 4 spaces of a loop.
  796. In the os.rename section (path, dirk "lagu_" str (to) ".mp3?) .That is to say the file that was merged with" song_ "continues to be merged with the specified sequence. To = 1 is adding one by one var to.
  797.  
  798.  
  799.  
  800.  
  801. ==========
  802.  
  803.  
  804.  
  805. 012.
  806.  
  807. "MAKE SERIAL NUMBER"
  808.  
  809. I want to share a script to create an activation code on an application...
  810.  
  811. Has it ever occurred to you to distribute the apps you created as shareware? So people can try it out first and they can see if the app is really useful to them or not.
  812.  
  813. But before we have to be self conscious, It's worth our application given a safety or serial number. It's worth a really useful application or through a complicated manufacturing process.
  814.  
  815. Applications that are distributed with shareware methods usually have time limits in their use and if the deadline is up then the user must do the activation by registering the application or purchase license to the author of the application by mentioning the serial number on the existing application.
  816.  
  817. There are also shareware types that do not use time limits, but place restrictions on the facilities that can be used. There are even those who do not use time constraints or facilities restrictions, but the applications used will always show ads when the application is used.
  818.  
  819. If you as an app maker of course you do not want the activation key can be used by several different users who deliberately duplicate the application for personal gain, this can be tricked by creating a different serial number for each different user (one user one serial number) so that the activation key can only be used by one user only.
  820.  
  821. To create a unique serial number for each user we can use the IMEI number on the phone, so that each application is installed on a different phone then it will have a different serial number.
  822.  
  823. To find out the IMEI number we can use sysinfo module.
  824.  
  825. Here is how to create a unique and different serial number on each phone by utilizing IMEI phone number.
  826.  
  827. ----------------------------------------------------------------------------------------
  828. import sysinfo
  829. imei = sysinfo.imei()
  830. code imei [2] + imei [0] + imei [12] + imei [9] + imei [3]
  831. code = int (code) +2011
  832. print the code
  833. ----------------------------------------------------------------------------------------
  834.  
  835. Explanation:
  836. In the process of processing IMEI
  837. imei [imei] + imei [12] + imei [9] + imei [3] means taking numbers from positions 3, to 1, 2, ke3 to 10 and 4 from IMEI.
  838. Eg IMEI 356664000736846
  839. SN or Serial number generated is 635676
  840. code = int (code) +2011 means converting the SN string to an integer then plus 2011.
  841. Rich gini 635676 2011 results 637687
  842.  
  843. That's how to Generate a unique code from an IMEI number. For values ​​like [2], [0], [1], [2], [9], [3], and 2011 you can specify and add as you like.
  844.  
  845.  
  846.  
  847.  
  848. ==========
  849.  
  850.  
  851.  
  852. 013.
  853.  
  854. "MAKE TRANSLATE ALA GOOGLE TRANSLATION"
  855.  
  856. Dear...
  857. ANGELMAN% ANGELwoman,
  858. I want to share about how to create an online sentence translator application...
  859.  
  860. Who does not know google translate, a service from google that allows users to do one word translation, one paragraph or translate a website. Available languages ​​are already quite complete.
  861.  
  862. Now we can use the service in python script easily.
  863.  
  864. Let's make it, open the Python editor Ped, choose new-python.
  865.  
  866. ----------------------------------------------------------------------------------------
  867. import urllib
  868. text = 'I want to eat'
  869. langpair = 'en | en'
  870. base_url = 'http: //ajax.googleapis.com/ajax/services/language/translate?'
  871. data = urllib.urlencode ({'v': 1.2, 'ie': 'UTF16 ?,' q ': text.encode (' utf-8?), 'langpair': langpair})
  872. with the url being encoded
  873. url = base_url + dat a
  874. null = None
  875. hsl = urllib.urlopen (url) .read()
  876. of the opening of the url
  877. dic = eval (hsl)
  878. brada di var dic
  879. detail = dic ["responseDetails"]
  880. if detail == None:
  881.     resp = dic ["responseData"]
  882.     resp = resp ["translatedText"]
  883. else:
  884.     resp = detail
  885. print resp
  886. ----------------------------------------------------------------------------------------
  887.  
  888.  
  889.  
  890.  
  891. ==========
  892.  
  893.  
  894.  
  895. 014.
  896.  
  897. "CUTTING PICTURE"
  898.  
  899. I want to share a script to crop the image or croping image...
  900.  
  901. In this article I will explain how to cut the image on pys60.
  902.  
  903. Logically gini, we open the original image or image source continue to create a new image with the specified size at the value to be cut, then combine or bind (blit) the original image to a new image with the specified position.
  904.  
  905. The script looks like this,
  906.  
  907. ----------------------------------------------------------------------------------------
  908. from graphics import *
  909. cut (= 10,10,110,110)
  910. source = Image.open ("c:\\image.jpg")
  911. sx, sy = source.size
  912. lx, ly, x, y = cut
  913. if x> sx:
  914.     x = sx
  915. if y> sy:
  916.     y = sy
  917. img = Image.new ((x-10, y-10))
  918. img.blit (source, cut)
  919. img.save ("c:\\pieces.jpg")
  920. ----------------------------------------------------------------------------------------
  921.  
  922. That's how to cut a very simple image on pys60.
  923.  
  924. There is another way of checking the pixel per pixel of the image source starting from the cut value. Then create a new image whose size corresponds to the cut value, make point by point on the new image and the point color takes from the pixel pixels that were checked.
  925.  
  926.  
  927.  
  928.  
  929. ==========
  930.  
  931.  
  932.  
  933. 015.
  934.  
  935. "USE SPECIAL CHARACTER"
  936.  
  937. I want to share how to insert a special character into an app...
  938.  
  939. Have you ever inserted special characters or characters of arabic, russian etc in pys60? Then what happen? What happens is an error message will appear. Then, how?
  940. Special characters will not run on pys60, unless we change the encoding into utf-8.
  941.  
  942. How to decode is very easy, here's an example:
  943.  
  944. ----------------------------------------------------------------------------------------
  945. def dc (x):
  946.     return x.decode ('utf-8?,' ignore ')
  947. print dc ("khusus_karakter_disini")
  948. ----------------------------------------------------------------------------------------
  949.  
  950. For more convincing, please try it on appuifw.note
  951.  
  952.  
  953.  
  954.  
  955. ==========
  956.  
  957.  
  958.  
  959. 016.
  960.  
  961. "FILE HANDLING"
  962.  
  963. I want to share how pys60 aar can open or read or write automatically...
  964.  
  965. Anything can be done with Python, including one handling a file, such as opening, reading, or writing a document file by creating an object file, which has methods and attributes to manipulate the file.
  966.  
  967. The operation of reading or writing files depends on the mode declared by us when opening the file. To do that we do not need a module.
  968.  
  969. Here is a script for creating a text file in Python S60:
  970.  
  971. ----------------------------------------------------------------------------------------
  972. f = open ("c:\\document.txt", "w")
  973. text = u "Python S60\nSiky play python"
  974. f.write (text)
  975. f.close()
  976. ----------------------------------------------------------------------------------------
  977.  
  978. To open a file (create an object file), we use the open method with parameters in the form of filename and mode. In the above example, we open document.txt file with mode 'w' which means write, then use write method to insert text from text variable into document.txt file
  979.  
  980. And the word "\n" is to create a new line in the text.
  981.  
  982. ----------------------------------------------------------------------------------------
  983. f = open ("c:\\document.txt")
  984. print f.name
  985. print f.mode
  986. ----------------------------------------------------------------------------------------
  987.  
  988. In the above example we do not enter the mode parameter because by default if we do not specify the mode parameters of the open method, the mode of the opened file is 'r' alias read.
  989.  
  990. ----------------------------------------------------------------------------------------
  991. f = open ("c:\\document.txt")
  992. print f.read()
  993. ----------------------------------------------------------------------------------------
  994.  
  995. The read method is used to read the entire contents of a text file. It is important to note that when we read the text of the file, the newline character will be included at the end of each line marked with\n.
  996.  
  997. When we use the read method, the position of the file we open is at the end of the file.
  998.  
  999. To restore the initial position of the file, we use seek() method so we can re-read the file we open. The readline method is to read each line of the text file that we open until it returns to the end of the file.
  1000.  
  1001. ----------------------------------------------------------------------------------------
  1002. f = open ("c:\\document.txt")
  1003. f.seek (0)
  1004. print f.readline()
  1005. print f.readline()
  1006. f.close()
  1007. ----------------------------------------------------------------------------------------
  1008.  
  1009.  
  1010.  
  1011.  
  1012. ==========
  1013.  
  1014.  
  1015.  
  1016. 017.
  1017.  
  1018. "LIST"
  1019.  
  1020. I want to share a way to create a list...
  1021.  
  1022. List is one of the most useful facilities in Python. This can be equated with arrays when in other programming languages. Here is an example list and its use.
  1023. Example:
  1024.  
  1025. ----------------------------------------------------------------------------------------
  1026. list1 = ["Cat", "Bird", "Chicken"]
  1027. list2 = [23,54,87,78]
  1028. ----------------------------------------------------------------------------------------
  1029.  
  1030. -Using List:
  1031. Accessing items
  1032. print list1 [0] # will print the first element of list1 ie "cat"
  1033. print list2 [1] + list2 [0] # sum element list2 [1] list2 [0] the result is 77
  1034. Added items
  1035. Example:
  1036.  
  1037. ----------------------------------------------------------------------------------------
  1038. list1.append ("Duck")
  1039. ----------------------------------------------------------------------------------------
  1040.  
  1041. Added the string "duck" to list1. So, list1 now contains ["Cat", "Bird", "Chicken", "Duck"]
  1042.  
  1043. Replace items
  1044. Example:
  1045.  
  1046. ----------------------------------------------------------------------------------------
  1047. a = [12,22,32,42,52,62]
  1048. a [2] = 10M
  1049. ----------------------------------------------------------------------------------------
  1050.  
  1051. Replacing the 3rd element is 32 to 10. So now list a contains [12,22,10,42,52,62]
  1052.  
  1053. Deleting items
  1054. Example:
  1055.  
  1056. ----------------------------------------------------------------------------------------
  1057. del a [3]
  1058. ----------------------------------------------------------------------------------------
  1059.  
  1060. Removing the third element is 52
  1061. Other functions
  1062.  
  1063. Reverses the list element
  1064. Example:
  1065.  
  1066. ----------------------------------------------------------------------------------------
  1067. a.reverse()
  1068. ----------------------------------------------------------------------------------------
  1069.  
  1070. Sort the list in descending order
  1071. Example:
  1072.  
  1073. ----------------------------------------------------------------------------------------
  1074. a.sort (reverse = False)
  1075. ----------------------------------------------------------------------------------------
  1076.  
  1077. Sort the list in descending order
  1078. Example:
  1079.  
  1080. ----------------------------------------------------------------------------------------
  1081. acsending
  1082. a.sort (reverse = True)
  1083. ----------------------------------------------------------------------------------------
  1084.  
  1085.  
  1086.  
  1087.  
  1088. ==========
  1089.  
  1090.  
  1091.  
  1092. 018.
  1093.  
  1094. "DICTIONARY"
  1095.  
  1096. I want to share a script to print or print a text...
  1097.  
  1098. Dictionary is an object in Python that is used to store pairs of values. Dictionary is an important concept in python and plays an important role in many occasions.
  1099.  
  1100. -Defining Dictionary:
  1101.  
  1102. ----------------------------------------------------------------------------------------
  1103. dict1 = ("name": "agus", "age": 16 ", address": "indramayu")
  1104. ----------------------------------------------------------------------------------------
  1105.  
  1106. Dictionary dict1 above has three elements. Each has its own key and its value. We can access the value by using the "Name" key for Agus, "Age" for 16 and so on.
  1107.  
  1108. -Access Element:
  1109.  
  1110. ----------------------------------------------------------------------------------------
  1111. print dict1 ["name"]
  1112. ----------------------------------------------------------------------------------------
  1113.  
  1114. This will print the string "Agus"
  1115.  
  1116. -Adding Elements:
  1117.  
  1118. ----------------------------------------------------------------------------------------
  1119. dict1 ["Phone"] = "62838000000?
  1120. ----------------------------------------------------------------------------------------
  1121.  
  1122. -Remove Element:
  1123.  
  1124. ----------------------------------------------------------------------------------------
  1125. del dict1 ['address']
  1126. ----------------------------------------------------------------------------------------
  1127.  
  1128. -Listing all keys
  1129.  
  1130. ----------------------------------------------------------------------------------------
  1131. k = dict1.keys()
  1132. ----------------------------------------------------------------------------------------
  1133.  
  1134. Will display ['age', 'no. Phone ',' name ']
  1135.  
  1136. ----------------------------------------------------------------------------------------
  1137. v = dict1.values ​​()
  1138. ----------------------------------------------------------------------------------------
  1139.  
  1140. Will display [16, '62838000000,' Agus']
  1141.  
  1142.  
  1143.  
  1144.  
  1145. ==========
  1146.  
  1147.  
  1148.  
  1149. 019.
  1150.  
  1151. "DICTIONARY and LIST"
  1152.  
  1153. I want to share the combination between Dict and List...
  1154.  
  1155. Dictdictionary or dict has pair value. in the use of the code using kurawa brackets {}.
  1156. Example:
  1157.  
  1158. ----------------------------------------------------------------------------------------
  1159. identity = {'name': 'wawan', 'age': 20, 'address': 'jakarta'}
  1160. print identity ['name']
  1161. ----------------------------------------------------------------------------------------
  1162.  
  1163. the result:
  1164. Wawan
  1165.  
  1166. ----------------------------------------------------------------------------------------
  1167. print identity ['address']
  1168. ----------------------------------------------------------------------------------------
  1169.  
  1170. the result:
  1171. Jakarta
  1172.  
  1173. List (list)
  1174. List or list in use use [].
  1175. Example:
  1176.  
  1177. ----------------------------------------------------------------------------------------
  1178. fruit = ['apple', 'banana', 'pineapple']
  1179. print fruit [0]
  1180. ----------------------------------------------------------------------------------------
  1181.  
  1182. the result:
  1183. Apple
  1184.  
  1185. because the first order of the list in pys60 starts from 0 then 1.2 and so on.
  1186.  
  1187. -Added data
  1188.  
  1189. ----------------------------------------------------------------------------------------
  1190. buah.append ('watermelon')
  1191. ----------------------------------------------------------------------------------------
  1192.  
  1193. result then list fruit into fruit = ['apple', 'banana', 'pineapple', 'watermelon']
  1194.  
  1195. -Delete data
  1196.  
  1197. ----------------------------------------------------------------------------------------
  1198. buah.pop (0)
  1199. ----------------------------------------------------------------------------------------
  1200.  
  1201. The pop function will delete data from the fruit variables in the order they are,
  1202. so the fruit list now contains ['banana', 'pineapple']
  1203.  
  1204. ----------------------------------------------------------------------------------------
  1205. fruit = ['apple', 'banana', 'pineapple']
  1206. buah.remove ('apple')
  1207. ----------------------------------------------------------------------------------------
  1208.  
  1209. The remove function will delete data from the fruit variable by its name.
  1210.  
  1211. -Sort data
  1212.  
  1213. ----------------------------------------------------------------------------------------
  1214. number = [1,8,4,6.7]
  1215. number.sort()
  1216. ----------------------------------------------------------------------------------------
  1217.  
  1218.  
  1219.  
  1220.  
  1221. ==========
  1222.  
  1223.  
  1224.  
  1225. 020.
  1226.  
  1227. "2D IMAGES"
  1228.  
  1229. I want to share how to create 2D images...
  1230.  
  1231. Basically Figure 2D consists of 2 coordinate points commonly called x and y. x is the horizontal (horizontal) coordinate of the left right and y is the vertical (vertical) coordinate from top to bottom. so if the value of x equals 0 (zero) and y is also 0 (zero) then the position of the point is in the top left corner.
  1232.  
  1233. Looping or Core repetition works like a loop system in the animated image process. In this case it is used to bring up many created objects. My experience when trying to create many objects without looping at 240x320 resolution turned out the results can not be full.
  1234.  
  1235. Make a rectangle and ellips to make it use this code img.rectangle ((positionX, positionY, positionX + width of Object, positionY + height Object), line color, object color). The colors used in RGB mode (Red, Green, Blue) 0xRRGGBB
  1236. example:
  1237.  
  1238. ----------------------------------------------------------------------------------------
  1239. img.rectangle ((50, 20, 70, 60), 0x00dddd, fill = 0xdd0000)
  1240. ----------------------------------------------------------------------------------------
  1241.  
  1242. To ellipse the code is almost the same as making a box.
  1243. Example:
  1244.  
  1245. ----------------------------------------------------------------------------------------
  1246. img.ellipse ((50, 70, 80, 90), 0xdd0000, fill = 0x00dd00)
  1247. ----------------------------------------------------------------------------------------
  1248.  
  1249. Creating Point
  1250. In contrast to ellips and rectangle, use only X coordinates, its y only and width (Point width)
  1251. example:
  1252.  
  1253. ----------------------------------------------------------------------------------------
  1254. img.point ((200, 100), 0x0000dd, width = 10)
  1255. ----------------------------------------------------------------------------------------
  1256.  
  1257. Creating Line
  1258. Create a line connecting between 2 points of coordinates. then the regulator: (x1, y1, x2, y2)
  1259. example:
  1260.  
  1261. ----------------------------------------------------------------------------------------
  1262. img.line ((20, 20, 120, 20), 0xdddd00)
  1263. ----------------------------------------------------------------------------------------
  1264.  
  1265. Creating Text
  1266. To make the writing settings like this: ((x, y), u'text to write ')
  1267. example:
  1268.  
  1269. ----------------------------------------------------------------------------------------
  1270. img.text ((60, 300), 0x00dd00)
  1271. ----------------------------------------------------------------------------------------
  1272.  
  1273. Practice:
  1274.  
  1275. ----------------------------------------------------------------------------------------
  1276. import appuifw
  1277. import graphics
  1278. import e32
  1279. ----------------------------------------------------------------------------------------
  1280.  
  1281. -Define definitions of apps
  1282. -How to stop the while loop
  1283. -The while function is to display the image over and over again (animation theory) as long as the run variable is true. In python all numbers other than zero are true.
  1284.  
  1285. ----------------------------------------------------------------------------------------
  1286. def close():
  1287.     global run
  1288.     run = 0
  1289. ----------------------------------------------------------------------------------------
  1290.  
  1291. -Set the softkey button to run the "close" definition when pressed.
  1292.  
  1293. ----------------------------------------------------------------------------------------
  1294. appuifw.app.exit_key_handler = close
  1295. ----------------------------------------------------------------------------------------
  1296.  
  1297. -Creates a "c" variable that contains the canvas of the appuifw module
  1298.  
  1299. ----------------------------------------------------------------------------------------
  1300. c = appuifw.Canvas()
  1301. ----------------------------------------------------------------------------------------
  1302.  
  1303. -Set the application body to the canvas
  1304.  
  1305. ----------------------------------------------------------------------------------------
  1306. appuifw.app.body = c
  1307. ----------------------------------------------------------------------------------------
  1308.  
  1309. -Screen size "full screen"
  1310.  
  1311. ----------------------------------------------------------------------------------------
  1312. appuifw.app.screen = 'full'
  1313. ----------------------------------------------------------------------------------------
  1314.  
  1315. -Creates an image programming variable from the graphics module, the default is white.
  1316. - (240,320) is the screen resolution.
  1317.  
  1318. ----------------------------------------------------------------------------------------
  1319. img.graphics.Image.new ((240,320))
  1320. ----------------------------------------------------------------------------------------
  1321.  
  1322. -Run is a variable that acts as an application closing regulator.
  1323.  
  1324. ----------------------------------------------------------------------------------------
  1325. run = 1
  1326. ----------------------------------------------------------------------------------------
  1327.  
  1328. -Creates a while function.
  1329.  
  1330. ----------------------------------------------------------------------------------------
  1331. while run == 1:
  1332. ----------------------------------------------------------------------------------------
  1333.  
  1334. -Calling the image using c.blit
  1335. -remember if c is canvas and img is graphics.Image.new
  1336.  
  1337. ----------------------------------------------------------------------------------------
  1338.     c.blit (img)
  1339. ----------------------------------------------------------------------------------------
  1340.  
  1341. -Make a box
  1342. ----------------------------------------------------------------------------------------
  1343.     img.rectangle ((50, 30, 100, 70), 0x00dddd, fill = 0xdd0000)
  1344. ----------------------------------------------------------------------------------------
  1345.  
  1346. -Creates ellipse
  1347. ----------------------------------------------------------------------------------------
  1348.     img.ellipse ((100, 70, 30, 100), 0xdd0000, fill = 0xdddd00)
  1349. ----------------------------------------------------------------------------------------
  1350.  
  1351. -Creates a Point
  1352.  
  1353. ----------------------------------------------------------------------------------------
  1354.     img.point ((200, 150), 0x0000dd, width = 50)
  1355. ----------------------------------------------------------------------------------------
  1356.  
  1357. -Making a line
  1358.  
  1359. ----------------------------------------------------------------------------------------
  1360.     img.line ((00, 200, 240, 200), 0x00dd00)
  1361. ----------------------------------------------------------------------------------------
  1362.  
  1363. -Creating text
  1364.  
  1365. ----------------------------------------------------------------------------------------
  1366.     img.text ((20,220), u'prajurit ', fill = 0xdddddd)
  1367. ----------------------------------------------------------------------------------------
  1368.  
  1369. -Because the default img black so we first change to black using clear.
  1370.  
  1371. ----------------------------------------------------------------------------------------
  1372.     img.clear (0x000000)
  1373. ----------------------------------------------------------------------------------------
  1374.  
  1375. -Creates the application cover. when the close function is executed the ao_yield() function of the e32 module will stop the while loop.
  1376.  
  1377. ----------------------------------------------------------------------------------------
  1378.     e32.ao_yield()
  1379. ----------------------------------------------------------------------------------------
  1380.  
  1381. Note:
  1382. Signs   is the number of spaces.
  1383. The size of the letters, symbols, and spaces must be the same as the ones written above.
  1384.  
  1385.  
  1386.  
  1387.  
  1388. ==========
  1389.  
  1390.  
  1391.  
  1392. 021.
  1393.  
  1394. "WRITE TEXT AND TITLE ON APPLICATIONS"
  1395.  
  1396. I want to share a script to display text at the beginning of an app and also tittle an app...
  1397.  
  1398. -Modules used appuifw and e32
  1399.  
  1400. ----------------------------------------------------------------------------------------
  1401. import appuifw, e32
  1402. ----------------------------------------------------------------------------------------
  1403.  
  1404. -Creates application title
  1405.  
  1406. ----------------------------------------------------------------------------------------
  1407. appuifw.app.title = u "APPLICATIONS"
  1408. ----------------------------------------------------------------------------------------
  1409.  
  1410. -Creates a text-call function
  1411.  
  1412. ----------------------------------------------------------------------------------------
  1413. t = appuifw.text()
  1414. ----------------------------------------------------------------------------------------
  1415.  
  1416. -Setting up the text function as the application body
  1417.  
  1418. ----------------------------------------------------------------------------------------
  1419. appuifw.app.body = t
  1420. ----------------------------------------------------------------------------------------
  1421.  
  1422. -Adjust the display application using the screen function, there are 3 types of large, normal, full
  1423.  
  1424. ----------------------------------------------------------------------------------------
  1425. appuifw.app.screen = "normal"
  1426. ----------------------------------------------------------------------------------------
  1427.  
  1428. -Set the text color
  1429.  
  1430. ----------------------------------------------------------------------------------------
  1431. t.color = 0xEE00DD
  1432. ----------------------------------------------------------------------------------------
  1433.  
  1434. -Set the highlight color
  1435.  
  1436. ----------------------------------------------------------------------------------------
  1437. t.highlight_color = 0xFFFF00
  1438. ----------------------------------------------------------------------------------------
  1439.  
  1440. -Set the font ie font name, size (size), flag (sorry this is not know its function)
  1441.  
  1442. ----------------------------------------------------------------------------------------
  1443. t.font = (u "Nokia Hindi S60", 25, None)
  1444. ----------------------------------------------------------------------------------------
  1445.  
  1446. -Set the style of writing (style) there are several types of them, STYLE_ITALIC, STYLE_BOLD, STYLE_STRIKETHROUGH and can also use highlights such as HIGHLIGHT_STANDARD, HIGHLIGHT_ROUNDED, HIGHLIGHT_SHADOW
  1447.  
  1448. ----------------------------------------------------------------------------------------
  1449. t.style = (appuifw.STYLE_HIGHLIGHT_STANDARD | appuifw.STYLE_BOLD | appuifw.STYLE_STRIKETHROUGH)
  1450. ----------------------------------------------------------------------------------------
  1451.  
  1452. -Writing the desired text
  1453.  
  1454. ----------------------------------------------------------------------------------------
  1455. t.set (u "Haaloo Broww ..")
  1456. ----------------------------------------------------------------------------------------
  1457.  
  1458. -Create an active object
  1459.  
  1460. ----------------------------------------------------------------------------------------
  1461. app_lock = e32.Ao_lock()
  1462. ----------------------------------------------------------------------------------------
  1463.  
  1464. -Creating a function to exit the application
  1465.  
  1466. -----------------------------------------------------------------------------------------
  1467. def quit():
  1468.     app_lock.signal()
  1469.     appuifw.app. set.exit()
  1470. ----------------------------------------------------------------------------------------
  1471.  
  1472. -Creating the exit button on the softkey
  1473.  
  1474. ----------------------------------------------------------------------------------------
  1475. appuifw.app.exit_key_handler = quit
  1476. ----------------------------------------------------------------------------------------
  1477.  
  1478. -Wait for the command from the softkey to exit
  1479.  
  1480. -----------------------------------------------------------------------------------------
  1481. app_lock.wait()
  1482. -----------------------------------------------------------------------------------------
  1483.  
  1484.  
  1485.  
  1486.  
  1487. ==========
  1488.  
  1489.  
  1490.  
  1491. 022.
  1492.  
  1493. "FUNCTION OF FORUM"
  1494.  
  1495. I want to share about the iteration function for on pys60 script...
  1496.  
  1497. Looping or looping is a process done repeatedly, which I know looping in pys60 there are 2 for and while. But this time I will decipher for for only.
  1498.  
  1499. For
  1500. just take the example to be easy to understand.
  1501. Example 1:
  1502.  
  1503. ----------------------------------------------------------------------------------------
  1504. for i in range (10):
  1505.         print i
  1506. ----------------------------------------------------------------------------------------
  1507.  
  1508. Then the result will print 10 numbers from 0- 9 instead of 1-10, since the integer value starts from the number 0.
  1509.  
  1510. Example 2:
  1511.  
  1512. -----------------------------------------------------------------------------------------
  1513. x = 4
  1514. for t in range (x):
  1515.     test print [t]
  1516. -----------------------------------------------------------------------------------------
  1517.  
  1518. result of
  1519. test
  1520. test
  1521. test
  1522. test
  1523.  
  1524. Will print test as much as x that is 4.
  1525.  
  1526. Example 3:
  1527.  
  1528. ----------------------------------------------------------------------------------------
  1529. txt = unicode ('test')
  1530. for z in range (len (txt)):
  1531.     print txt [z]
  1532. ----------------------------------------------------------------------------------------- the
  1533.  
  1534. result
  1535. t
  1536. e
  1537. s
  1538.  
  1539. The len function here is to know the amount of data from txt.
  1540. Example:
  1541.  
  1542. ----------------------------------------------------------------------------------------
  1543. txt = unicode ('test')
  1544. len (txt )
  1545. ---------------------------------------------------------------------------------------- The
  1546.  
  1547. result
  1548. 3
  1549.  
  1550.  
  1551.  
  1552.  
  1553. ==========
  1554.  
  1555.  
  1556.  
  1557. 023.
  1558.  
  1559. "IF CONDITION"
  1560.  
  1561. I want to share funsi if in script pys60...
  1562.  
  1563. The if command is used to create a condition in pys60.
  1564. if illustrated would be like this example...
  1565.  
  1566. If eating then it will be full, if drink will be bloated, otherwise all will die
  1567.  
  1568. If word is replaced if if code in pys60 it will be like this:
  1569.  
  1570. -----------------------------------------------------------------------------------------
  1571. txt = unicode ('test')
  1572. if eating:
  1573.     full of
  1574. drinking elves:
  1575. >   > kembung
  1576. else:
  1577.     moddar
  1578. ----------------------------------------------------------------------------------------
  1579.  
  1580. (symbol     is the number of spaces)
  1581.  
  1582. Now we try to apply in the script
  1583. Example:
  1584.  
  1585. ----------------------------------------------------------------------------------------
  1586. txt = unicode (' test ')
  1587. value = 70
  1588. if value> 80:
  1589.     print' smart '
  1590. if value> 60:
  1591.     print' pretty '
  1592. else:
  1593.     print' must learn a lot '
  1594. ----------------------------------------------------------------------------------------- The
  1595.  
  1596. space below if, elif, and else is a block.meaning the command is included in the block of the command above it.
  1597.  
  1598.  
  1599.  
  1600.  
  1601. ==========
  1602.  
  1603.  
  1604.  
  1605. 024.
  1606.  
  1607. "MENU, SUBMENU and POPUP MENU"
  1608.  
  1609. I want to share a way to make memu , submenu or popup menu for an application...
  1610.  
  1611. Creating Application Menu
  1612. -Module used is appuifw, and e32
  1613.  
  1614. -----------------------------------------------------------------------------------------
  1615. import appuifw, e32
  1616. -----------------------------------------------------------------------------------------
  1617.  
  1618. -Define: create its own function for application menu.
  1619.  
  1620. ----------------------------------------------------------------------------------------
  1621. def item1():
  1622.     appuifw.note (u "learn python", "info")
  1623.  
  1624. def item2():
  1625.     appuifw.note (u "basic lesson", "info")
  1626. -----------------------------------------------------------------------------------------
  1627.  
  1628. -Make a function to exit when pressing the right softkey button.
  1629.  
  1630. ----------------------------------------------------------------------------------------
  1631. def quit():
  1632.     app_lock.signal() )
  1633. ----------------------------------------------------------------------------------------
  1634.  
  1635. Information:
  1636. Spacebar to create a function in 1 block.
  1637.  
  1638. -Creates a menu of selectable apps (menu1, menu2)
  1639. -Do call the created function (item1, item2)
  1640.  
  1641. -----------------------------------------------------------------------------------------
  1642. appuifw.app.menu = [(u "one", item1), (u "two", item2)]
  1643. -----------------------------------------------------------------------------------------
  1644.  
  1645. -Creating exit button
  1646.  
  1647. -----------------------------------------------------------------------------------------
  1648. appuifw.app.exit_key_handler = quit
  1649. -----------------------------------------------------------------------------------------
  1650.  
  1651. -Create an active object
  1652.  
  1653. ----------------------------------------------------------------------------------------
  1654. app-lock = e32.Ao_loch()
  1655. -----------------------------------------------------------------------------------------
  1656.  
  1657. -Get started time
  1658.  
  1659. -----------------------------------------------------------------------------------------
  1660. app_lock.wait()
  1661. -----------------------------------------------------------------------------------------
  1662.  
  1663. Detailed to be:
  1664.  
  1665. -----------------------------------------------------------------------------------------
  1666. import appuifw, e32
  1667. def item1():
  1668.     appuifw.note (u "learn python", "info")
  1669. def item2():
  1670.     appuifw.note (u "basic lesson" ,"info")
  1671. def quit():
  1672.     app_lock.signal()
  1673. appuifw.app.menu = [(u "menu1", item1), (u "menu2", item2)]
  1674. appuifw.app.exit_key_handler = quit
  1675. app-lock = e32.Ao_lock()
  1676. app_lock.wait()
  1677. ----------------------------------------------------------------------------------------
  1678.  
  1679. Creating SubMenu
  1680. - The same way to create an app menu just adds menus in a menu like this (menu1, (submenu1, submenu2), men2, (submenu1, submenu2))
  1681. Example code:
  1682.  
  1683. -----------------------------------------------------------------------------------------
  1684. appuifw.app.menu = [(u "menu1", ((u "submenu1", item1), (u, "submenu2" , item2)), (u "menu2", ((u "submenu1",item1), (u "submenu2", item2))))]
  1685. ----------------------------------------------------------------------------------------
  1686.  
  1687. Create a pop-up menu
  1688. -Module used appuifw
  1689.  
  1690. -----------------------------------------------------------------------------------------
  1691. import appuifw
  1692. -----------------------------------------------------------------------------------------
  1693.  
  1694. -Creating a list with contents from Pop-up
  1695.  
  1696. -----------------------------------------------------------------------------------------
  1697. L = [u "Python", u "Symbian", u "java"]
  1698. -----------------------------------------------------------------------------------------
  1699.  
  1700. -Create a pop-up menu including lists and labels
  1701.  
  1702. ----------------------------------------------------------------------------------------
  1703. appuifw.popup_menu (list, label)
  1704.  
  1705. test = appuifw.popup_menu (L, u "Options:")
  1706. ----------------------------------------------------------------------------------------
  1707.  
  1708. -Make a test variable to enter a command into the List (based on the order of positions in the List) -It has been
  1709. selected
  1710. -Efforts some actions (here we print something())
  1711.  
  1712. -----------------------------------------------------------------------------------------
  1713. if test == 0:
  1714.     appuifw.note (u "Python, yes", "info")
  1715. elif test == 1:
  1716.     appuifw.note (u "Symbian, ok", "info")
  1717. elif test == 2:
  1718.     appuifw.note(u"belajar java", "info")
  1719. ---------------------------------------------------------------------------------------
  1720.  
  1721. Information:
  1722. The number 0 shows the first sequence in the Python List, then the number 1 denotes the second sequence of Symbian, and so on.
  1723.  
  1724. full examples of the code to be
  1725.  
  1726. ----------------------------------------------------------------------------------------
  1727. import appuifw
  1728. L = [u "Python" , u "Symbian", u "java"]
  1729. test = appuifw.popup_menu (L, u "Options")
  1730. if test == 0:
  1731.     appuifw.note (u "Python yes", "info")
  1732. elif test == 1:
  1733.     appuifw.note (u "symbian, ok", "info")
  1734. elif test == 2:
  1735.     appuifw.note (u "learn java", "info")
  1736. ----------------------------------------------------------------------------------------
  1737.  
  1738.  
  1739.  
  1740.  
  1741. ==========
  1742.  
  1743.  
  1744.  
  1745. 025.
  1746.  
  1747. "ME-MINIMIZEKAN A PROGRAM USING SCRIPT PYS60"
  1748.  
  1749. I want to share a script to minimize the program we are currently open...
  1750.  
  1751. ----------------------------------------------------------------------------------------
  1752. import appswitch
  1753. appswitch .switch_to_bg (appswitch.application_list (1) [0])
  1754. ----------------------------------------------------------------------------------------
  1755.  
  1756.  
  1757.  
  1758. ==========
  1759.  
  1760.  
  1761.  
  1762. 026.
  1763.  
  1764. "MAKE PASSWORD SCRIPT PYS60"
  1765.  
  1766. I want to share a script to create a password on app...
  1767.  
  1768. ----------------------------------------------------------------------------------------
  1769. import appuifw
  1770. import os
  1771.  
  1772. def open():
  1773.     appuifw.note (u'Success... ',' conf ')
  1774.  
  1775. def start():
  1776.     N = appuifw.query (u "Free Name:", "text")
  1777.     K = "fnugraha8"
  1778.     uN = N
  1779.     if N == uN:
  1780.     uK = str (appuifw.query (u "Password: "," code "))
  1781.     if K == uK:
  1782.         open()
  1783.     else:
  1784.         appuifw.note (u "Wrong Password!", "error")
  1785.         os.abort()
  1786.     else:
  1787.    
  1788. start pass()
  1789. ----------------------------------------------------------------------------------------
  1790.  
  1791.  
  1792.  
  1793. ==========
  1794.  
  1795.  
  1796.  
  1797. 027.
  1798.  
  1799. "SCRIPT PY TO SHOW BATTERY WATER"
  1800.  
  1801. I want to share a script to show low battery status or weak...
  1802.  
  1803. We write first scrit it using the application ped or x-plore.
  1804.  
  1805. 1. Open the ped application and press the File> New> Python option, then a blank or blank HP screen will appear.
  1806.  
  1807. 2. Then write his py script as needed and according to the procedure. Like this:
  1808.  
  1809. ----------------------------------------------------------------------------------------
  1810. import globalui
  1811. import e32
  1812. import appuifw
  1813.  
  1814. x = appuifw.query (u'Enter Time (in seconds): ',' number ')
  1815. e32.ao_sleep (x)
  1816. globalui.global_note (u' ',' battery_low ')
  1817. -----------------------------------------------------------------------------------------
  1818.  
  1819. 3. If everything is written then you just press the selection button then select 'Run', finish.
  1820.  
  1821. Here's an example of the complete script:
  1822. ----------------------------------------------------------------------------------------
  1823. import globalui import e32 import appuifw x = appuifw.query (u'Enter Time (in seconds): ',' number ') e32.ao_sleep (x) globalui.global_note (u' ',' battery_low ')
  1824. -----------------------------------------------------------------------------------------
  1825.  
  1826.  
  1827.  
  1828. ==========
  1829.  
  1830.  
  1831.  
  1832. 028.
  1833.  
  1834. "SCRIPT SIMPLE MAKES POPUP MENU"
  1835.  
  1836. I want to share a simple script to create popup memu...
  1837.  
  1838. ----------------------------------------------------------------------------------------
  1839. import appuifw
  1840. import os
  1841.  
  1842. def poultry() : appuifw.note (u'ayam, bird, etc ',' info ')
  1843. def song(): appuifw.note (u'valley of the damned, fury of the storm', 'info')
  1844. def kel(): os .abort()
  1845.  
  1846.  
  1847. a = [u'Unggas ', u'Lagu', u'Sign out ']
  1848. g = appuifw.popup_menu (a, u'Menuen')
  1849. if g == 0:poultry()
  1850. if g == 1: song()
  1851. if g == 2: kel()
  1852. ---------------------------------------------------------------------------------------
  1853.  
  1854.  
  1855.  
  1856. ==========
  1857.  
  1858.  
  1859.  
  1860. 029.
  1861.  
  1862. "READING FILE WITH MODULE POWLITE FM"
  1863.  
  1864. I want to share a script to read mp3 file...
  1865.  
  1866. -Module required
  1867.  
  1868. ----------------------------------------------------------------------------------------
  1869. import powlite_fm as fm
  1870. import audio as a
  1871. ----------------------------------------------------------------------------------------
  1872.  
  1873. -The command opens the file manager
  1874.  
  1875. -----------------------------------------------------------------------------------------
  1876. n = fm.manager()
  1877. ----------------------------------------------------------------------------------------
  1878.  
  1879. - The command to read my file gives an example of reading na mp3 files with audio module, can also file jpg, png, gif, etc.
  1880.  
  1881. ----------------------------------------------------------------------------------------
  1882. f = n.AskUser (ext = ['.mp3' ])
  1883. ----------------------------------------------------------------------------------------
  1884.  
  1885. - The command opens the file and plays it and the volume level is 5
  1886. Ket : a.Sound.open is the command to open the sound file, (f) is a function to read the file manager on hp
  1887.  
  1888. -----------------------------------------------------------------------------------------
  1889. s = a.Sound.open (f)
  1890. s.play()
  1891. s.set_volume(5)
  1892. ---------------------------------------------------------------------------------------
  1893.  
  1894.  
  1895.  
  1896.  
  1897. ==========
  1898.  
  1899.  
  1900.  
  1901. 030.
  1902.  
  1903. "CHANGING SIZE OF IMAGES USING SCRIPT"
  1904.  
  1905. I want to share a script to resize image...
  1906.  
  1907. ----------------------------------------------------------------------------------------
  1908. import appuifw
  1909. import e32
  1910. from graphics import *
  1911.  
  1912. images = Image.open ("e:\\test.jpg")
  1913. image = image.resize ((176, 208))
  1914. gambar.save ("e:\\save.jpg" )
  1915.  
  1916. def handel (rect):
  1917. >   > x.blit (image)
  1918. x = appuifw.Canvas (redraw_callback = handel)
  1919. appuifw.app.body = x
  1920. y = e32.Ao_lock()
  1921. y.wait()
  1922. ---------------------------------------------------------------------------------------
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928. ==========
  1929.  
  1930.  
  1931.  
  1932. 031.
  1933.  
  1934. "USE OF SCRIPT PASSWORD ON AN APPLICATION"
  1935.  
  1936. I want to share how to create a password on an app...
  1937.  
  1938. -Module required
  1939.  
  1940. ----------------------------------------------------------------------------------------
  1941. import appuifw
  1942. import e32
  1943. import os
  1944. ----------------------------------------------------------------------------------------
  1945.  
  1946. -Function define calling and filling name and password
  1947.  
  1948. -----------------------------------------------------------------------------------------
  1949. def begin():
  1950. ----------------------------------------------------------------------------------------
  1951.  
  1952. -The query function for calling or displaying text boxes or also a charging box name
  1953.  
  1954. ----------------------------------------------------------------------------------------
  1955.     N = appuifw.query (u " Free Name: "," text ")
  1956. ----------------------------------------------------------------------------------------
  1957.  
  1958. -The Equation K as my password uses fnugraha8 as its password and free name filling
  1959.  
  1960. -----------------------------------------------------------------------------------------
  1961. > > K = "fnugraha8"
  1962. ----------------------------------------------------------------------------------------
  1963.  
  1964. -Name N if N equals N which means name
  1965.  
  1966. ----------------------------------------------------------------------------------------
  1967.         uN = N
  1968.     if N == uN:
  1969. ----------------------------------------------------------------------------------------
  1970.  
  1971. -K equations as strings with query function of password filling
  1972.  
  1973. ----------------------------------------------------------------------------------------
  1974.     uK = str (appuifw.query (u "Password (fnugraha8)", "code" ))
  1975.     if K == uK:
  1976. ----------------------------------------------------------------------------------------
  1977.  
  1978. -The menu calling function after entering the name and password if the password correct
  1979.  
  1980. ----------------------------------------------------------------------------------------
  1981.         open()
  1982. ----------------------------------------------------------------------------------------
  1983.  
  1984. -Another meaningful function other than that which serves to differentiate if the wrong password
  1985.  
  1986. -----------------------------------------------------------------------------------------
  1987.     else:
  1988.         appuifw.note (u "Wrong Password!", "error")
  1989. ----------------------------------------------------------------------------------------
  1990.  
  1991. -A abort function where the wrong password will automatically exit from application by itself
  1992.  
  1993. ----------------------------------------------------------------------------------------
  1994.         os.abort()
  1995.     else:
  1996.     pass
  1997. -----------------------------------------------------------------------------------------
  1998.  
  1999. -Function define a as text to be displayed
  2000.  
  2001. -----------------------------------------------------------------------------------------
  2002. def a():
  2003.     aa = u'script experiment using password '
  2004. -----------------------------------------------------------------------------------------
  2005.  
  2006. -The print rule to print text on the above function
  2007.  
  2008. -----------------------------------------------------------------------------------------
  2009.     print aa
  2010. ----------------------------------------------------------------------------------------
  2011.  
  2012. ----------------------------------------------------------------------------------------
  2013. def b():
  2014.     bb = u ' experiment script using password '
  2015.     print bb
  2016. ----------------------------------------------------------------------------------------
  2017.  
  2018. -Function to exit the app
  2019.  
  2020. ----------------------------------------------------------------------------------------
  2021. def ex():
  2022.     os.abort()
  2023. ----------------------------------------------------------------------------------------
  2024.  
  2025. -Function to run the opening of the application first run
  2026.  
  2027. ----------------------------------------------------------------------------------------
  2028. def open():
  2029.     appuifw.app.screen = 'large'
  2030.     x = appuifw.Text()
  2031.     appuifw.app.body = x
  2032.     x.style = appuifw.STYLE_BOLD
  2033.     y = u'aku love you all my heart '
  2034.     x.color = 0xccaadd
  2035.     for abc in range (len (y)):
  2036.         x.add (y [abc] )
  2037.         e32.ao_sleep (0.01)
  2038. ----------------------------------------------------------------------------------------
  2039.  
  2040. -Menu application on define function
  2041.  
  2042. ----------------------------------------------------------------------------------------
  2043. def menu():
  2044.     appuifw.app.menu = [(u'test ', a), (u'testing',b)]
  2045. ----------------------------------------------------------------------------------------
  2046.  
  2047. -Function calling password
  2048.  
  2049. ----------------------------------------------------------------------------------------
  2050. start()
  2051. -----------------------------------------------------------------------------------------
  2052.  
  2053. -Function calling menu
  2054.  
  2055. -----------------------------------------------------------------------------------------
  2056. menu()
  2057. -----------------------------------------------------------------------------------------
  2058.  
  2059. -Function command exits
  2060.  
  2061. ----------------------------------------------------------------------------------------
  2062. appuifw .app.exit_key_handler = ex
  2063. ----------------------------------------------------------------------------------------
  2064.  
  2065. -Alocking app
  2066.  
  2067. ----------------------------------------------------------------------------------------
  2068. z = e32.Ao_lock()
  2069. z.wait()
  2070. -----------------------------------------------------------------------------------------
  2071.  
  2072. Note:
  2073.     Is the number of spaces used.
  2074.  
  2075.  
  2076.  
  2077. ==========
  2078.  
  2079.  
  2080.  
  2081. 032.
  2082.  
  2083. "SCRIPT PY TO DISPLAY FILE"
  2084.  
  2085. I want to share a script to back up file...
  2086.  
  2087. ----------------------------------------------------------------------------------------
  2088. import appuifw
  2089. import e32
  2090. import os
  2091. import powlite_fm as p
  2092.  
  2093. def double():
  2094.     appuifw.query (unicode ('Find File Save 420kb or 495kb'), 'query')
  2095.     z = p.manager()
  2096.     f = z.AskUser (ext = ['svs','. sav '])
  2097.     if f:
  2098.         appuifw.note (unicode ('Processing !!! '),' info ')
  2099.         os.path.isdir (' E:\\Backup ')
  2100.         os.makedirs ('E:\\Backup')
  2101.         folder = f
  2102.         target = 'E:\\Backup'
  2103.         e32.file_copy (target, folder)
  2104.         appuifw.note (unicode ('Successfully Doubleing FILE...'), 'conf')
  2105. double()
  2106. -----------------------------------------------------------------------------------------
  2107.  
  2108.  
  2109.  
  2110.  
  2111. ==========
  2112.  
  2113.  
  2114.  
  2115. 033.
  2116.  
  2117. "MULTI SELECTION LIST"
  2118.  
  2119. I want to share scrip to display search file or check box...
  2120.  
  2121. 1. Open the ped application and press the option and choose file> new> python, it will pop up the new blank screen you wrote the script, and write the script as below.
  2122.  
  2123. ----------------------------------------------------------------------------------------
  2124. import appuifw
  2125.  
  2126. Girl = [u'Gina ', u'Nina ', u'Dina', u'Lena ', u'Rena', u'Raisya ', u'Risa', u'Siska ']
  2127.  
  2128. tm = appuifw.multi_selection_list (Girls, style =' checkbox 'search_field = 1)
  2129.  
  2130.  
  2131. for i in tm:
  2132.     print Girl [i]
  2133. ----------------------------------------------------------------------------------------
  2134.  
  2135. Note:
  2136. Replace mark> with a space.
  2137.  
  2138.  
  2139.  
  2140. ==========
  2141.  
  2142.  
  2143.  
  2144. 034.
  2145.  
  2146. "AUDIO (PLAYING MP3 1 FOLDER)"
  2147.  
  2148. I want to share a script untuj play mp3 in 1 piece folder...
  2149.  
  2150. ----------------------------------------------------------------------------------------
  2151. Import Appuifw
  2152. import audio
  2153. import e32
  2154. import os
  2155.  
  2156. dir = 'E:\\Music'
  2157. for the song in os.listdir (dir):
  2158.     s = audio.Sound.open (os.
  2159. path.join (dir, track))
  2160.     s.play()
  2161.     s.set_volume (5)
  2162.     print 'Now playing:', song, ms2str (s.duration())
  2163.     while 1:
  2164.         if s.state() == 1:
  2165.             s.close()
  2166.             break
  2167.         e32.ao_sleep (0.5)
  2168.  
  2169. -UntUk menStop lagu tUlis script like this.
  2170.  
  2171. s.stop()
  2172. s.close()
  2173. ----------------------------------------------------------------------------------------
  2174.  
  2175. Note:
  2176. Alerts> replace with a space.
  2177.  
  2178.  
  2179.  
  2180. ==========
  2181.  
  2182.  
  2183.  
  2184. 035.
  2185.  
  2186. "FILLING LESS NAME OF AND MORE THAN 5 CHARACTERS"
  2187.  
  2188. I want to share the way make popup menu filling name less than 5 letters or more than 5 letters...
  2189.  
  2190. -----------------------------------------------------------------------------------------
  2191. import appuifw as z
  2192.  
  2193. x = z.query (u'Name ',' text ')
  2194. if x:
  2195.     if len (x)> 5:
  2196.     z.note (u'Max 5 ',' error ')
  2197.     else:
  2198.     z.note (x,' conf ')
  2199.  
  2200. y = z.query (u'Nama', 'text')
  2201. if y:
  2202. >>if len (y) <5:
  2203.     z.note (u'Max 5 ',' error ')
  2204.     else:
  2205.     z.note (y, 'conf')
  2206. -----------------------------------------------------------------------------------------
  2207.  
  2208. Note:
  2209. Replace mark> with a space.
  2210.  
  2211.  
  2212.  
  2213. ==========
  2214.  
  2215.  
  2216.  
  2217. 036.
  2218.  
  2219. "MULTI_QUERY"
  2220.  
  2221. I want to share a script for print or print more than 1 text...
  2222.  
  2223. ----------------------------------------------------------------------------------------
  2224. import appuifw as R
  2225. x, y = R .multi_query (u'Name: ', u'Umur:')
  2226. print x
  2227. print y
  2228. -----------------------------------------------------------------------------------------
  2229.  
  2230.  
  2231.  
  2232. ==========
  2233.  
  2234.  
  2235.  
  2236. 037.
  2237.  
  2238. "SIMPLE FORM"
  2239.  
  2240. I want to share about the form function in a pys60 script. ..
  2241.  
  2242. ----------------------------------------------------------------------------------------
  2243. import appuifw
  2244.  
  2245. x = appuifw.FFormDoubleSpaced | appuifw.FFormEditModeOnly
  2246. y = [u'Kuda ', u'Monkey', u'Angjing ', u'Babi', u'Ayam ']
  2247. x1 = [(u'Name Animals', 'combo', (y, 0) )]
  2248. y1 = appuifw.Form (x1, x)
  2249. y1.execute()
  2250. z = y1 [0] [2] [1]
  2251. appuifw.query ('' Print Result ',' text ', u' '+ y [z])
  2252. ----------------------------------------------------------------------------------------
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258. ==========
  2259.  
  2260.  
  2261.  
  2262. 038.
  2263.  
  2264. "MAKE PROGRESSBAR"
  2265.  
  2266. I want to share a script to create a progress bar...
  2267.  
  2268. ----------------------------------------------------------------------------------------
  2269. import prog, e32, appuifw
  2270. wt = prog.ProgressNote()
  2271. wt.wait()
  2272. wt.update (0, u'Loading... ')
  2273. e32.ao_sleep (5)
  2274. wt.finish()
  2275. appuifw.note (u'Success...', 'conf')
  2276. -----------------------------------------------------------------------------------------
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282. ==========
  2283.  
  2284.  
  2285.  
  2286. 039.
  2287.  
  2288. " DISPLAYING APPLICATIONS THAT HAVE BEEN INSTALLED IN THE FORM OF LIST"
  2289.  
  2290. I want shares script pys60 whose function is to display installed applications on each drive, I inserted the C, E and Z drives. So displaying the installed app on 3 drives, it's an easy way to enter the app without having to click menu, open folder, etc ..
  2291.  
  2292. Just go the script below,
  2293.  
  2294. ----------------------------------------------------------------------------------------
  2295. import apps import appuifw import laa def app_list(): drive = ['E:', 'C:', 'Z:'] apps = [] uids = [] for data in applist.applist(): uid, name, dir = data if dir [: 2] in drive: apps.append ((name)) uids.append (uid) i = appuifw.popup_menu (apps, unicode (len (apps)) + 'Installed Apps') if not i == None: laa.execute (uids) app_list()
  2296. ----------------------------------------------------------------------------------------
  2297.  
  2298. This is the complete script,
  2299. ----------------------------------------------------------------------------------------
  2300. import appist
  2301. import appuifw
  2302. import laa
  2303.  
  2304. def app_list ( ):
  2305.     drive = ['E:', 'C:', 'Z:']
  2306.     apps = []
  2307.     uids = []
  2308.     for data in applist.applist():
  2309. >   uid, name, dir = data
  2310. >   dir [: 2] in drive:
  2311.         apps.append ((name))
  2312.         uids.append (uid)
  2313.     i = appu, unicode (len (apps)) + 'Installed Apps')
  2314.     if not i == None:
  2315. >   laa.execute (uids)
  2316. app_list()
  2317. -----------------------------------------------------------------------------------------
  2318.  
  2319.  
  2320.  
  2321.  
  2322. ==========
  2323.  
  2324.  
  2325.  
  2326. 040.
  2327.  
  2328. "CALLING IMAGES WITH MODULE FROM GRAPHICS IMPORT *"
  2329.  
  2330. I want to share how to enter or calling an image into an application via the command from graphics import...
  2331.  
  2332. -Module required
  2333.  
  2334. -----------------------------------------------------------------------------------------
  2335. import appuifw
  2336. import e32
  2337. from graphics import *
  2338. ----------------------------------------------------------------------------------------
  2339.  
  2340. -To change the screen size available normal, large and full
  2341.  
  2342. ----------------------------------------------------------------------------------------
  2343. appuifw.app.screen = 'full'
  2344. -----------------------------------------------------------------------------------------
  2345.  
  2346. -To call and open the image with the location and size of the image must be clear
  2347.  
  2348. -----------------------------------------------------------------------------------------
  2349. Image = Image.open ("e:\\test.jpg" )
  2350. ----------------------------------------------------------------------------------------
  2351.  
  2352. -Set the drawing called to be displayed
  2353.  
  2354. -----------------------------------------------------------------------------------------
  2355. def handle_redraw (rect):
  2356.     x.blit (Figure) # use 4 spaces
  2357. ----------------------------------------------------------------------------------------
  2358.  
  2359. -Canvas and body assignments to display
  2360.  
  2361. -----------------------------------------------------------------------------------------
  2362. x = appuifw.Canvas (redraw_callback = handle_redraw)
  2363. appuifw.app.body = x
  2364. ----------------------------------------------------------------------------------------
  2365.  
  2366. -Clock usage
  2367.  
  2368. -----------------------------------------------------------------------------------------
  2369. y = e32.Ao_lock()
  2370. y.wait()
  2371. -----------------------------------------------------------------------------------------
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377. ==========
  2378.  
  2379.  
  2380.  
  2381. 041.
  2382.  
  2383. "SCRIPT CUTTING FILE TXT"
  2384.  
  2385. I want to share how to call or insert a file. txt into an app...
  2386.  
  2387. -Module required
  2388.  
  2389. ----------------------------------------------------------------------------------------
  2390. Import Appuifw
  2391. import e32
  2392. ----------------------------------------------------------------------------------------
  2393.  
  2394. -Text of the txt file you want to call
  2395.  
  2396. -----------------------------------------------------------------------------------------
  2397. Text = 'e:\\test.txt'
  2398. ----------------------------------------------------------------------------------------
  2399.  
  2400. -Members calling on module
  2401.  
  2402. -----------------------------------------------------------------------------------------
  2403. x = appuifw.Content_handler()
  2404. -----------------------------------------------------------------------------------------
  2405.  
  2406. -Explore x on the module to open the txt file
  2407.  
  2408. -----------------------------------------------------------------------------------------
  2409. x.open (text)
  2410. -----------------------------------------------------------------------------------------
  2411.  
  2412. -Mode sleep
  2413.  
  2414. ----------------------------------------------------------------------------------------
  2415. e32.ao_sleep (10)
  2416. ---------------------------------------------------------------------------------------
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422. ==========
  2423.  
  2424.  
  2425.  
  2426. 042.
  2427.  
  2428. "SCRIPT TEXT BECOME VOICE"
  2429.  
  2430. I want to share a script that can change the text into sound...
  2431.  
  2432. -Module required
  2433.  
  2434. ----------------------------------------------------------------------------------------
  2435. import appuifw
  2436. import audio
  2437. -----------------------------------------------------------------------------------------
  2438.  
  2439. -The query function for writing text on a popup screen
  2440.  
  2441. -----------------------------------------------------------------------------------------
  2442. text = appuifw.query (u'Enter the text: ',' text')
  2443. ----------------------------------------------------------------------------------------
  2444.  
  2445. -The order to call a voice or read a text
  2446.  
  2447. -----------------------------------------------------------------------------------------
  2448. audio.say (text)
  2449. -----------------------------------------------------------------------------------------
  2450.  
  2451. -How to write it can Copas or also make it with x-plore and ped. Ped this function to run the script created earlier, create the script using x-plore with cra into x-plore then press menu     file    new text file   tlis name like this test.py then press ok.
  2452.  
  2453. Continue to write the above command, save when finished, keep moving to python folder ..
  2454.  
  2455. How to run the script open Application Ped continue to search python\test.py folder and press ok, it will pop up scren and enter the text press ok again and listen to the result.
  2456.  
  2457. Note:
  2458. -Text not abbreviated.
  2459. -Not all HP suport with this script.
  2460.  
  2461.  
  2462.  
  2463. ==========
  2464.  
  2465.  
  2466.  
  2467. 043.
  2468.  
  2469. "SCRIPT UNTUK MEMANGGIL dan MEMBUKA APLIKASI di LUAR SYSTEM APLIKASI"
  2470.  
  2471. Saya mau share sebuah script yang fungsinya untuk memanggil aplikasi diluar system aplikasi...
  2472.  
  2473. -Module yang dibutuhkan
  2474.  
  2475. ---------------------------------------------------------------------------------------
  2476. import appuifw
  2477. import e32
  2478. ---------------------------------------------------------------------------------------
  2479.  
  2480. -Fungsi define pemanggilan aplikasi
  2481.  
  2482. ---------------------------------------------------------------------------------------
  2483. def test():
  2484.     e32.start_exe ('z:\\system\\programs\\apprun.exe', 'e:\\COBA\\vbag\\vbag.app')
  2485. -----------------------------------------------------------------------------------------
  2486.  
  2487. -Feature menu
  2488.  
  2489. -----------------------------------------------------------------------------------------
  2490. appuifw.app.menu = [(u "Test", test)]
  2491. -----------------------------------------------------------------------------------------
  2492.  
  2493. -To lock when the app is opened so it does not happen out by itself.
  2494.  
  2495. ----------------------------------------------------------------------------------------
  2496. lock = e32.Ao_lock()
  2497. lock.wait()
  2498. ----------------------------------------------------------------------------------------
  2499.  
  2500. Information:
  2501. Tanda   ini dimaksudkan supaya menggunakan 4 spasi.
  2502.  
  2503. e32.start_exe('z:\\system\\programs\\apprun.exe' ini adalah perintah pemanggila sekaligus untuk melakukan runing pada suatu aplikasi yang mau dijalankan..
  2504.  
  2505. 'e:\\COBA\\vbag\\vbag.app' ini adalah perintah untuk memanggil aplikasi yang akan dijalankan dimana folder aplikasi tersebut disimpan...
  2506.  
  2507. Untuk pemanggilan aplikasi bisa ditambah sebanyak yang kalian mau.
  2508. Ingat pindahkan folder aplikasi ke folder yang sudah disiapkan sebelumnya.
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514. ==========
  2515.  
  2516.  
  2517.  
  2518. 044.
  2519.  
  2520. "SCRIPT UNTUK MEMAINKAN MP3 PADA FUNGSI DEFINE"
  2521.  
  2522. Saya mau share script python yang berfungsi untuk memutar mp3...
  2523.  
  2524. -Module yang diperlukan
  2525.  
  2526. ---------------------------------------------------------------------------------------
  2527. import appuifw
  2528. import e32
  2529. import audio
  2530. ---------------------------------------------------------------------------------------
  2531.  
  2532. -Fungsi define untuk menjalankan sebuah mp3
  2533.  
  2534. ---------------------------------------------------------------------------------------
  2535.  
  2536. def main():
  2537.     global pokemon
  2538.     pokemon = audio.Sound.open ('e:\\MP3\\English\\Pokemon.mp3')
  2539.     pokemon.play()
  2540.     appuifw.note (u "Playing", "info")
  2541. ----------------------------------------------------------------------------------------
  2542.  
  2543. -Function define to stop a mp3 that is being played
  2544.  
  2545. ----------------------------------------------------------------------------------------
  2546. def stop():
  2547.     global pokemon
  2548.     pokemon.stop()
  2549.     pokemon.close()
  2550.     appuifw.note (u "In Stop", "conf")
  2551. ----------------------------------------------------------------------------------------
  2552.  
  2553. -The menu list to display in an application
  2554.  
  2555. ---------------------------------------------------------------------------------------
  2556. appuifw.app.menu = [(u"Putar", main), (u"Berhenti", henti)]
  2557. ---------------------------------------------------------------------------------------
  2558.  
  2559. -Fungsi untuk modus stanby atau mengunci saat pada aplikasi dibuka
  2560.  
  2561. ---------------------------------------------------------------------------------------
  2562. script_lock = e32.Ao_lock()
  2563. script_lock.wait()
  2564. ---------------------------------------------------------------------------------------
  2565.  
  2566. Ingat tanda     menunjukan 4 spasi.
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572. ==========
  2573.  
  2574.  
  2575.  
  2576. 045.
  2577.  
  2578. "MEMANGGIL TEXT MENGGUNAKAN MODULE GLOBALUI PADA SCRIPT PYTHON"
  2579.  
  2580. Saya mau share sebuah script untuk memanggil text atau menulis text dengan module globalui...
  2581.  
  2582. -Module yang diperlukan
  2583.  
  2584. ---------------------------------------------------------------------------------------
  2585. import globalui
  2586. ---------------------------------------------------------------------------------------
  2587.  
  2588. -Pemanggilan scriptnya seperti ini.
  2589.  
  2590. ---------------------------------------------------------------------------------------
  2591. globalui.global_msg_query(u'test', u'coba' )
  2592. ----------------------------------------------------------------------------------------
  2593.  
  2594. Ket: u'test 'This is the content of the text and u' try 'This is a description of the text record. And if you want to use define afungtions use 4 spaces,
  2595. Example:
  2596.  
  2597. ----------------------------------------------------------------------------------------
  2598. def about():
  2599.     globalui.global_msg_query (u'test ',' try ')
  2600. -----------------------------------------------------------------------------------------
  2601.  
  2602.  
  2603.  
  2604. ==========
  2605.  
  2606.  
  2607.  
  2608. 046.
  2609.  
  2610. "CARA MEMASUKKAN MUSIK atau MP3 ke DALAM SEBUAH APLIKASI PYTHON"
  2611.  
  2612. Saya mau share cara membuat sebuah aplikasi ada musik ketika aplikasi tersebut dibuka...
  2613.  
  2614. Pertama kalian harus tau disetiap aplikasi python terdapat file default.py didalam file trsebut ada tulisan import nama aplikasi ( tergantung aplikasi python apa yang kalian punya )
  2615. Contoh:
  2616.  
  2617. ---------------------------------------------------------------------------------------
  2618. import linkapper
  2619. ---------------------------------------------------------------------------------------
  2620.  
  2621. Setelah ketemu file default.pynya kalian edit menggunakn x-plore atau yang lain, buka file default.pynya lalu ganti menjadi seperti dibawah ini:
  2622.  
  2623. ---------------------------------------------------------------------------------------
  2624. import e32,imp,appuifw,audio
  2625. s = audio.Sound.open('e:\\system\\mp3\\dragonforce\\trail of broken heart.mp3' )
  2626. s.play()
  2627. def go():
  2628. import linkapper
  2629. e32.ao_sleep(0,go)
  2630. del e32,go
  2631. ---------------------------------------------------------------------------------------
  2632.  
  2633. Note:
  2634. Saya tegaskan kembali nama folder mp3nya harus jelas dan nama aplikasinya juga harus dicantumkan.
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640. ==========
  2641.  
  2642.  
  2643.  
  2644. 047.
  2645.  
  2646. "DASAR URUTAN KODE LOGIC GAME"
  2647.  
  2648. Saya mau share tentang urutan kode logic game...
  2649.  
  2650. Program game agar bisa jalan ada tahapan-tahapan tertentu. Berikut ini tahapan-tahapan dasar pada program gameplay:
  2651.  
  2652. - update objek
  2653. - gameplay logic
  2654. - render
  2655.  
  2656. - Update objek
  2657. Objek pada game misalnya karakter. Saat karakter begerak atau berjalan, posisi karakter diupdate keposisi baru. Proses update disini bukan cuma update posisi objek tapi juga semua hal yang yang dibutuhkan tiap objek, misalnya: build objek, status, dll.
  2658.  
  2659. - Gameplay logic
  2660. Contoh logic gameplay misalnya: proses tumbukan, pengecekan gameover, penambahan skor, dll.
  2661.  
  2662. - Render
  2663. Render adalah proses menampilkan objek ke layar setelah diupdate
  2664.  
  2665. Jika tahapan-tahapan diatas terbalik dapat menjadi bug.
  2666.  
  2667. Contoh kasus:
  2668. Pada deteksi tumbukan, saat karakter berjalan dan menabrak tembok karakter berhenti berjalan. Urutan tahapan yang baik seperti ini:
  2669.  
  2670. - karakter berjalan
  2671. - logic tumbukan dengan tembok
  2672. - render karakter
  2673.  
  2674. Jika urutannya terbalik misalnya seperti ini:
  2675.  
  2676. - karakter berjalan
  2677. - render karakter
  2678. - logic tumbukan dengan tembok
  2679.  
  2680. Maka yang terjadi karakter berjalan masuk beberapa piksel (tergantung kecepatan berjalan) kedalam tembok lalu kembali kedepan tembok. Tidak langsung berheti didepan tembok.
  2681.  
  2682. Itulah contoh dasar urutan kode logic game.
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688. ==========
  2689.  
  2690.  
  2691.  
  2692. 048.
  2693.  
  2694. "MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.1)
  2695.  
  2696. Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
  2697.  
  2698. Saat ini tehnologi 3D merupakan sesuatu yang umum. Bahkan sudah banyak bahasa pemrograman yang dikhususkan untuk membuat software 3D misalnya Blitz 3D, Unity 3D dll sehingga membuat program 3D semakin mudah saja. Pada Pys60, ada sebuah graphics engine bernama OpenGL ES untuk mempermudah olah grafis baik 2D ataupun 3D. Library OpenGL ES hanya berjalan pada s60 3rd keatas. Namun bagaimanakah dasar-dasar komputasi 3D? Artikel ini berisi tehnik atau cara kerja dasar-dasar komputasi 3D menggunakan bahasa pemrograman Python khususnya Pys60. Mencakup pengetahuan dasar kordinat 3D, rotasi, dan transformasi. Dimulai dari kordinat 2D.
  2699.  
  2700. Note:
  2701. Ganti semua tanda">"pada awal baris disetiap script ditutorial ini dengan spasi.
  2702.  
  2703. -Kordinat 2D
  2704. Setiap titik 2D terdiri dari dua kordinat. Dalam kartesian disebut X dan Y.
  2705.  
  2706. X merupakan kordinat horizontal dari kiri kekanan sedangkan Y merupakan kordinat vertikal dari atas kebawah. Jadi jika X bernilai nol dan Y bernilai nol maka titik tersebut adalah pojok kiri atas layar.
  2707.  
  2708. Sebuah objek 3D yang dapat dirotasi mempunyai titik pusat rotasi. Untuk itu komputasi vektor digunakan untuk menentukan kordinat suatu objek pada layar.
  2709.  
  2710. Titik merah yang berada ditengah-tengah kotak tersebut merupakan titik pusat rotasi. Titik merah tersebut yang menentukan Posisi objek. Setiap titik biru (titik sudut, dalam 3D disebut Vertex) posisinya dipengaruhi oleh titik merah dengan kata lain translasi. Rumus translasi nya:
  2711. x = VertexX+PosX
  2712. y = VertexY+PosY
  2713.  
  2714. Script implementasi vektor
  2715.  
  2716. ---------------------------------------------------------------------------------------
  2717. import math,e32,key,appuifw, graphics
  2718.  
  2719. def quit():
  2720.     global run
  2721.     run=0
  2722.  
  2723. appuifw.app.screen ='full'
  2724. run = 1
  2725. appuifw.app.body = c = appuifw.Canvas()
  2726. appuifw.app.exit_key_handler=quit
  2727. img = graphics.Image.new(c.size)
  2728.  
  2729. PX = c.size[0]/2
  2730. PY = c.size[1]/2
  2731. Size = 6
  2732. VX = [-40, 40, -40, 40]
  2733. VY = [-40, -40, 40, 40]
  2734.  
  2735. while run:
  2736.  
  2737. img.clear(0)
  2738. for n in range(4):
  2739.     # translasi kordinat vertex
  2740.     x = VX[n]+PX
  2741.     y = VY[n]+PY
  2742. ---------------------------------------------------------------------------------------
  2743.  
  2744. -Menggambar vertex
  2745.  
  2746. ---------------------------------------------------------------------------------------
  2747.     img.point((x,y),0x0000ff,width=Size)
  2748. ---------------------------------------------------------------------------------------
  2749.  
  2750. -Menggambar posisi
  2751.  
  2752. ---------------------------------------------------------------------------------------
  2753. img.point((PX,PY),0xff0000,width=4)
  2754. c.blit(img)
  2755. e32.ao_yield()
  2756. ---------------------------------------------------------------------------------------
  2757.  
  2758. Pada script diatas hanya ada titik-titik saja, garis sengaja tidak digambar untuk menyederhanakan script. Objek kotak pada gambar diatas mempunyai lebar 80px dan tinggi 80px. Oleh karena itu setiap vertex (VX dan VY) nilainya setengah dari lebar kotak yaitu -40 atau 40.
  2759. Rotasi 2D
  2760.  
  2761. Sampai saat ini, alogaritma trigonometri sinus dan cosinus merupakan algoritma rotasi yang paling banyak dipakai untuk me-rotasi objek pada layar digital. Tidak memahami rumus sinus dan cosinus bukan suatu masalah karena hampir semua bahasa pemrograman termasuk python sudah menyediakan fungsi sin dan cos pada modul atau library standar-nya. Namun akan lebih baik jika mememahami cara kerja rotasi menggunakan sin dan cos.
  2762.  
  2763. Rotasi kekanan 20 derajat. Untuk menghitung nilai rotasi kordinat VX dan VY (garis berwarna cyan) dipakai rumus:
  2764.  
  2765. XR = VX[n]*cos(ra) - VY[n]*sin(ra)
  2766. YR = VX[n]*sin(ra) + VY[n]*cos(ra)
  2767.  
  2768. 'ra'adalah nilai Angle setelah dikonversi ke radian. Pada 3D, rotasi 2D ini disebut rotasi Z. Oleh karena itu pada script dibawah menggunakan'Z'pada variabel angle,sin dan cos.
  2769.  
  2770. implementasi rotasi 2D
  2771.  
  2772. ---------------------------------------------------------------------------------------
  2773. import math,e32,key,appuifw, graphics
  2774.  
  2775. def quit():
  2776.     global run
  2777.     run=0
  2778.  
  2779. appuifw.app.screen ='full'
  2780. run = 1
  2781. appuifw.app.body = c = appuifw.Canvas()
  2782. appuifw.app.exit_key_handler=quit
  2783. img = graphics.Image.new(c.size)
  2784.  
  2785. PX = c.size[0]/2
  2786. PY = c.size[1]/2
  2787. Size = 6
  2788. VX = [-40, 40, -40, 40]
  2789. VY = [-40, -40, 40, 40]
  2790. ANGLEZ = 0
  2791.  
  2792. while run:
  2793. ---------------------------------------------------------------------------------------
  2794.  
  2795. -Konversi angle ke radian
  2796.  
  2797. ---------------------------------------------------------------------------------------
  2798. raz = ANGLEZ*math.pi/180
  2799. ---------------------------------------------------------------------------------------
  2800.  
  2801. -Menghitung sin dan cos
  2802.  
  2803. ---------------------------------------------------------------------------------------
  2804.     sinz = math.sin(raz)
  2805.     cosz = math.cos(raz)
  2806.  
  2807.     img.clear(0)
  2808.  
  2809.     for n in range(4):
  2810. ---------------------------------------------------------------------------------------
  2811.  
  2812. -Rotasi kordinat vertex
  2813.  
  2814. ---------------------------------------------------------------------------------------
  2815.     XR = VX[n]*cosz - VY[n]*sinz - VX[n]
  2816.     YR = VX[n]*sinz + VY[n]*cosz - VY[n]
  2817. ---------------------------------------------------------------------------------------
  2818.  
  2819. -Translasi kordinat vertex
  2820.  
  2821. ---------------------------------------------------------------------------------------
  2822.     x = VX[n]+PX+XR
  2823.     y = VX[n]+PY+YR
  2824.     img.point((x,y),0x0000ff,width=Size)
  2825.     img.point((PX,PY),0xff0000,width=Size)
  2826. ---------------------------------------------------------------------------------------
  2827.  
  2828. -Memutar objek sekedar untuk simulasi
  2829.  
  2830. ---------------------------------------------------------------------------------------
  2831.     ANGLEZ+=2
  2832.     c.blit(img)
  2833.     e32.ao_yield()
  2834. ---------------------------------------------------------------------------------------
  2835.  
  2836. Pada baris kode:
  2837. XR = VX[n]*cosz - VY[n]*sinz - VX[n]
  2838. Ada tambahan"- VX[n]"agar hasil komputasinya hanya offset saja. Ditujukan untuk mengurangi perubahan syntax pada proses transformasi kordinat nanti. Setelah dihitung, nilai offset rotasi XR ditambahkan ke translasi:
  2839. x = VX[n]+PX+XR
  2840.  
  2841. Note:
  2842. Tanda > diganti menggunakan spasi.
  2843.  
  2844.  
  2845.  
  2846.  
  2847.  
  2848. ==========
  2849.  
  2850.  
  2851.  
  2852. 049.
  2853.  
  2854. "MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.2)
  2855.  
  2856. Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
  2857.  
  2858. Kordinat 3D
  2859. 3D merupakan pengembangan dari 2D. Jadi dasarnya sama dengan 2D. Pada 3D ada satu kordinat lagi yang disebut Z untuk menentukan kedalaman. Semakin besar nilai Z semakin jauh atau kecil gambar suatu objek pada layar.
  2860.  
  2861. Semua titik kordinat (Posisi dan Vertex) membutuhkan kordinat Z. Jadi setiap titik mempunyai tiga kordinat yaitu X,Y dan Z. Karena sudah memasuki 3D gambar kotak sebelumnya dikembangkan menjadi kubus. Sebuah kubus mempunyai 8 titik sudut, jadi ada tambahan 4 vertex baru kedalam list VX dan VY juga menambahkan satu list baru bernama VZ. Variabel PZ saat ini belum digunakan, diberi nilai 200 sebagai default agar objek berada agak jauh dari kamera setelah ditransformasikan nanti.
  2862.  
  2863. Implementasi kordinat 3D
  2864.  
  2865. ---------------------------------------------------------------------------------------
  2866. import math,e32,key,appuifw, graphics
  2867.  
  2868. def quit():
  2869.     global run
  2870.     run=0
  2871.  
  2872. appuifw.app.screen = 'full'
  2873. run = 1
  2874. appuifw.app.body = c = appuifw.Canvas()
  2875. appuifw.app.exit_key_handler=quit
  2876. img = graphics.Image.new(c.size)
  2877.  
  2878. PX = c.size[0]/2
  2879. PY = c.size[1]/2
  2880. Size = 6
  2881. VX = [-40, 40, -40, 40, -40, 40, -40, 40]
  2882. VY = [-40, -40, 40, 40, -40, -40, 40, 40]
  2883. VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
  2884. ANGLEZ = 0
  2885.  
  2886. while run:
  2887. ---------------------------------------------------------------------------------------
  2888.  
  2889. -Konversi angle ke radian
  2890.  
  2891. ---------------------------------------------------------------------------------------
  2892.     raz = ANGLEZ*math.pi/180
  2893. ---------------------------------------------------------------------------------------
  2894.  
  2895. -Menghitung sin dan cos
  2896.  
  2897. ---------------------------------------------------------------------------------------
  2898.     sinz = math.sin(raz)
  2899.     cosz = math.cos(raz)
  2900.  
  2901.     img.clear(0)
  2902.  
  2903.     for n in range(8):
  2904. ---------------------------------------------------------------------------------------
  2905.  
  2906. -Rotasi kordinat vertex
  2907.  
  2908. ---------------------------------------------------------------------------------------
  2909.     XR = VX[n]*cosz - VY[n]*sinz - VX[n]
  2910.     YR = VX[n]*sinz + VY[n]*cosz - VX[n]
  2911. ---------------------------------------------------------------------------------------
  2912.  
  2913. -Translasi kordinat vertex
  2914.  
  2915. ---------------------------------------------------------------------------------------
  2916.     x = VX[n]+PX+XR
  2917.     y = VX[n]+PY+YR
  2918.     img.point((x,y),0x0000ff,width=Size)
  2919.     img.point((PX,PY),0xff0000,width=Size)
  2920. ---------------------------------------------------------------------------------------
  2921.  
  2922. -Memutar objek sekedar untuk simulasi
  2923.  
  2924. ---------------------------------------------------------------------------------------
  2925.     ANGLEZ+=2
  2926.     c.blit(img)
  2927.     e32.ao_yield()
  2928. ---------------------------------------------------------------------------------------
  2929.  
  2930. Jika script diatas dijalankan terlihat sama persis seperti script sebelumnya. Hanya 4 vertex yang terlihat karena 4 kordinat vertex lainnya mempunyai nilai VX dan VY sama dan hanya VZ yang berbeda. Yang terjadi pada script diatas adalah setiap titik terdiri dari 2 titik kordinat atau tumpang tindih. Dibutuhkan transformasi kordinat agar objek 3D diatas mempunyai kedalaman.
  2931. Rotasi 3D
  2932.  
  2933. Objek 2D hanya ada satu rotasi yaitu rotasi Z axis, sedangkan objek 3D dapat dirotasi dalam 3 poros atau axis yaitu rotasi X,Y, dan Z. Bisa juga dirotasi dalam satu atau dua axis saja, dapat juga tidak diberi rotasi sama sekali. Pada script ini menggunakan 3 rotasi.
  2934.  
  2935. Untuk menggabungkan 3 komputasi rotasi sepintas terlihat sangat rumit, namun tidak serumit kelihatannya. Umumnya rotasi 3D menggunakan matrik karena efisiensi, namun disini tidak menggunakan matrik agar script-nya tidak terlalu rumit. Ada penambahan 2 variabel yaitu ANGLEX dan ANGLEY.
  2936.  
  2937. Script implementasi rotasi 3D
  2938.  
  2939. ---------------------------------------------------------------------------------------
  2940. import math,e32,key,appuifw, graphics
  2941.  
  2942. def quit():
  2943.     global run
  2944.     run=0
  2945.  
  2946. appuifw.app.screen = 'full'
  2947. run = 1
  2948. appuifw.app.body = c = appuifw.Canvas()
  2949. appuifw.app.exit_key_handler=quit
  2950. img = graphics.Image.new(c.size)
  2951.  
  2952. PX = c.size[0]/2
  2953. PY = c.size[1]/2
  2954. Size = 6
  2955. VX = [-40, 40, -40, 40, -40, 40, -40, 40]
  2956. VY = [-40, -40, 40, 40, -40, -40, 40, 40]
  2957. VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
  2958. ANGLEX = 0
  2959. ANGLEY = 0
  2960. ANGLEZ = 0
  2961.  
  2962. while run:
  2963. ---------------------------------------------------------------------------------------
  2964.  
  2965. -Konversi angle ke radian
  2966.  
  2967. ---------------------------------------------------------------------------------------
  2968.     rax = ANGLEX*math.pi/180
  2969.     ray = ANGLEY*math.pi/180
  2970.     raz = ANGLEZ*math.pi/180
  2971. ---------------------------------------------------------------------------------------
  2972.  
  2973. -Menghitung sin dan cos
  2974.  
  2975. ---------------------------------------------------------------------------------------
  2976.     sinx = math.sin(rax)
  2977.     cosx = math.cos(rax)
  2978.     siny = math.sin(ray)
  2979.     cosy = math.cos(ray)
  2980.     sinz = math.sin(raz)
  2981.     cosz = math.cos(raz)
  2982.  
  2983.     img.clear(0)
  2984.  
  2985.     for n in range(8):
  2986. ---------------------------------------------------------------------------------------
  2987.  
  2988. -Rotasi kordinat vertex
  2989.  
  2990. ---------------------------------------------------------------------------------------
  2991.     ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
  2992.     ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
  2993.     YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
  2994.     YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
  2995.     XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
  2996.     XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
  2997.     XR = YX+ZX
  2998.     YR = ZY+XY
  2999.     ZR = XZ+YZ
  3000. ---------------------------------------------------------------------------------------
  3001.  
  3002. -Ttranslasi kordinat vertex
  3003.  
  3004. ---------------------------------------------------------------------------------------
  3005.     x = VX[n]+PX+XR
  3006.     y = VY[n]+PY+YR
  3007.     img.point((x,y),0x0000ff,width=Size)
  3008.     img.point((PX,PY),0xff0000,width=Size)
  3009. ---------------------------------------------------------------------------------------
  3010.  
  3011. -Memutar objek sekedar untuk simulasi
  3012.  
  3013. ---------------------------------------------------------------------------------------
  3014.     ANGLEX+=2
  3015.     ANGLEY+=2
  3016.     ANGLEZ+=2
  3017.     c.blit(img)
  3018.     e32.ao_yield()
  3019. ---------------------------------------------------------------------------------------
  3020.  
  3021. Pada script diatas, baris ZX dan ZY merupakan proses "rotasi Z" sama seperti pada rotasi 2D sebelumnya. Baris YX dan YZ merupakan "rotasi Y" yang prosesnya menggabungkan hasil "rotasi Z" sebelumnya (ZX). Dan pada baris XY dan XZ merupakan "rotasi X" yang prosesnya menggabungkan hasil "rotasi Z" dan "rotasi Y" (ZY dan YZ). Sederhananya kubus dirotasi pada Z axis, setelah itu dirotasi lagi pada Y axis, dan dirotasi lagi pada X axis. Pada tiga baris code:
  3022.  
  3023. ---------------------------------------------------------------------------------------
  3024.     XR = YX+ZX
  3025.     YR = ZY+XY
  3026.     ZR = XZ+YZ
  3027. ---------------------------------------------------------------------------------------
  3028.  
  3029. Ketiga statement diatas hanya menjumlahkan semua "offset rotasi" sehingga dapat digunakan dalam konversi akhir.
  3030.  
  3031. Note:
  3032. Tanda > diganti menggunakan spasi.
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038. ==========
  3039.  
  3040.  
  3041.  
  3042. 050.
  3043.  
  3044. "MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.3)
  3045.  
  3046. Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
  3047.  
  3048. Transformasi 3D
  3049. Pada script dibagian sebelumnya saat kubus diputar ke-delapan vertex-nya kelihatan. Namun masih terlihat ada yang kurang yaitu perspektif. Proses transformasi digunakan untuk memberi atau mensimulasikan perspektif agar objek 3D terlihat nyata secara fisika.
  3050.  
  3051. Proses mensimulasikan perspektif disebut transformasi. Rumus transformasinya:
  3052.  
  3053. Z = (VZ+PZ)/distance
  3054. X = (VX+PX)/Z
  3055. Y = (VY+PY)/Z
  3056.  
  3057. Pada kebanyakan konten 3D baik itu pada gambar, film, atau game, pusat perspektif sering kali berada ditengah-tengah layar. Untuk itu ada tambahan variabel halfResX dan halfResY untuk membuat posisi titik pusat perspektif berada ditengah-tengah layar.
  3058.  
  3059. Implementasi perspektif 3D
  3060.  
  3061. ---------------------------------------------------------------------------------------
  3062. import math,e32,key,appuifw, graphics
  3063.  
  3064. def quit():
  3065.     global run
  3066.     run=0
  3067. appuifw.app.screen ='full'
  3068. run = 1
  3069. appuifw.app.body = c = appuifw.Canvas()
  3070. appuifw.app.exit_key_handler=quit
  3071. img = graphics.Image.new(c.size)
  3072. halfResX = c.size[0]/2
  3073. halfResY = c.size[1]/2
  3074. ---------------------------------------------------------------------------------------
  3075.  
  3076. -Jarak posisi kamera dari layar
  3077.  
  3078. ---------------------------------------------------------------------------------------
  3079. distance = 180
  3080.  
  3081. PX = 0
  3082. PY = 0
  3083. PZ = 200
  3084. Size = 6
  3085. VX = [-40, 40, -40, 40, -40, 40, -40, 40]
  3086. VY = [-40, -40, 40, 40, -40, -40, 40, 40]
  3087. VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
  3088. ANGLEX = 0
  3089. ANGLEY = 0
  3090. ANGLEZ = 0
  3091.  
  3092. while run:
  3093. ---------------------------------------------------------------------------------------
  3094.  
  3095. -Konversi angle ke radian
  3096.  
  3097. ---------------------------------------------------------------------------------------
  3098.     rax = ANGLEX*math.pi/180
  3099.     ray = ANGLEY*math.pi/180
  3100.     raz = ANGLEZ*math.pi/180
  3101. ---------------------------------------------------------------------------------------
  3102.  
  3103. -Menghitung sin dan cos
  3104.  
  3105. ---------------------------------------------------------------------------------------
  3106.     sinx = math.sin(rax)
  3107.     cosx = math.cos(rax)
  3108.     siny = math.sin(ray)
  3109.     cosy = math.cos(ray)
  3110.     sinz = math.sin(raz)
  3111.     cosz = math.cos(raz)
  3112.  
  3113.     img.clear(0)
  3114.  
  3115.     for n in range(8):
  3116. ---------------------------------------------------------------------------------------
  3117.  
  3118. -Rotasi kordinat vertex
  3119.  
  3120. ---------------------------------------------------------------------------------------
  3121.     ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
  3122.     ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
  3123.     YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
  3124.     YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
  3125.     XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
  3126.     XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
  3127.     XR = YX+ZX
  3128.     YR = ZY+XY
  3129.     ZR = XZ+YZ
  3130. ---------------------------------------------------------------------------------------
  3131.  
  3132. -Transformasi kordinat vertex
  3133.  
  3134. ---------------------------------------------------------------------------------------
  3135.     z = (VZ[n]+PZ+ZR)/distance
  3136.     x = (VX[n]+PX+XR)/z
  3137.     y = (VY[n]+PY+YR)/z
  3138.     img.point((x+halfResX,y+halfResY),0x0000ff,width=Size/z)
  3139.     img.point((PX+halfResX,PY+halfResY),0xff0000,width=Size)
  3140. ---------------------------------------------------------------------------------------
  3141.  
  3142. -Memutar objek sekedar untuk simulasi
  3143.  
  3144. ---------------------------------------------------------------------------------------
  3145.     ANGLEX+=2
  3146.     ANGLEY+=2
  3147.     ANGLEZ+=2
  3148.     c.blit(img)
  3149.     e32.ao_yield()
  3150. ---------------------------------------------------------------------------------------
  3151.  
  3152. Karena titik pusat perspektif berada ditengah layar, maka jika PX bernilai nol posisi kubus berada ditengah layar, jika nilainya lebih kecil dari nol (minus) posisi kubus berada dikiri layar dan jika nilainya lebih besar dari nol posisi kubus berada dikanan layar. PY juga sama, tapi atas bawah. Sedangkan PZ bernilai nol atau lebih kecil dari nol maka posisinya tepat berada dikamera jadi tidak kelihatan dilayar karena terlalu besar. Semakin besar nilai PZ, semakin jauh posisi objek dari kamera dan terlihat semakin kecil.
  3153.  
  3154. Itulah dasar pendekatan komputasi 3D. Script dibawah ini sama dengan script pada bagian"Transformasi 3D". Hanya ada tambahan key handler untuk menggerakan posisi objek (PX,PY, dan PZ) dan memutar objek dalam 3 axis (ANGLEX,ANGLEY, dan ANGLEZ)
  3155.  
  3156. Fungsi key:
  3157. Arah atas dan bawah: update PY
  3158. Arah kiri dan kanan: update PX
  3159. 1 dan 3: update PZ
  3160. 2 dan 8: update ANGLEX
  3161. 4 dan 6: update ANGLEY
  3162. * dan #: update ANGLEZ
  3163.  
  3164. ---------------------------------------------------------------------------------------
  3165. import math,e32,key,appuifw, graphics
  3166. from key_codes import *
  3167.  
  3168. class Keyboard(object):
  3169.     def __init__(self,onevent=lambda:None):
  3170.     self._keyboard_state={}
  3171.     self._downs={}
  3172.     self._onevent=onevent
  3173.     def handle_event(self,event):
  3174.     if event['type'] == appuifw.EEventKeyDown:
  3175.         code=event['scancode']
  3176.         if not self.is_down(code):
  3177.         self._downs=self._downs.get(code,0)+1
  3178.         self._keyboard_state=1
  3179.     elif event['type'] == appuifw.EEventKeyUp:
  3180.         self._keyboard_state[event['scancode']]=0
  3181.     self._onevent()
  3182.     def is_down(self,scancode):
  3183.     return self._keyboard_state.get(scancode,0)
  3184.     def pressed(self,scancode):
  3185.     if self._downs.get(scancode,0):
  3186.         self._downs[scancode]-=1
  3187.         return True
  3188.     return False
  3189.  
  3190. def quit():
  3191.     global run
  3192.     run=0
  3193. key = Keyboard()
  3194. appuifw.app.screen ='full'
  3195. run = 1
  3196. appuifw.app.body = c = appuifw.Canvas(event_callback = key.handle_event)
  3197. appuifw.app.exit_key_handler=quit
  3198. img = graphics.Image.new(c.size)
  3199. halfResX = c.size[0]/2
  3200. halfResY = c.size[1]/2
  3201. ---------------------------------------------------------------------------------------
  3202.  
  3203. -Jarak posisi kamera dari layar
  3204.  
  3205. ---------------------------------------------------------------------------------------
  3206. distance = 180
  3207.  
  3208. PX = 0
  3209. PY = 0
  3210. PZ = 200
  3211. Size = 6
  3212. VX = [-40, 40, -40, 40, -40, 40, -40, 40]
  3213. VY = [-40, -40, 40, 40, -40, -40, 40, 40]
  3214. VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
  3215. ANGLEX = 0
  3216. ANGLEY = 0
  3217. ANGLEZ = 0
  3218.  
  3219. while run:
  3220. ---------------------------------------------------------------------------------------
  3221.  
  3222. -Konversi angle ke radian
  3223.  
  3224. ---------------------------------------------------------------------------------------
  3225.     rax = ANGLEX*math.pi/180
  3226.     ray = ANGLEY*math.pi/180
  3227.     raz = ANGLEZ*math.pi/180
  3228. ---------------------------------------------------------------------------------------
  3229.  
  3230. -Menghitung sin dan cos
  3231.  
  3232. ---------------------------------------------------------------------------------------
  3233.     sinx = math.sin(rax)
  3234.     cosx = math.cos(rax)
  3235.     siny = math.sin(ray)
  3236.     cosy = math.cos(ray)
  3237.     sinz = math.sin(raz)
  3238.     cosz = math.cos(raz)
  3239.     img.clear(0)
  3240.  
  3241.     for n in range(8):
  3242. ---------------------------------------------------------------------------------------
  3243.  
  3244. -Rotasi kordinat vertex
  3245.  
  3246. ---------------------------------------------------------------------------------------
  3247.     ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
  3248.     ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
  3249.     YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
  3250.     YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
  3251.     XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
  3252.     XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
  3253.     XR = YX+ZX
  3254.     YR = ZY+XY
  3255.     ZR = XZ+YZ
  3256. ---------------------------------------------------------------------------------------
  3257.  
  3258. -Transformasi kordinat vertex
  3259.  
  3260. ---------------------------------------------------------------------------------------
  3261.     z = (VZ[n]+PZ+ZR)/distance
  3262. ---------------------------------------------------------------------------------------
  3263.  
  3264. -Mencegah ZeroDivisionError
  3265.  
  3266. ---------------------------------------------------------------------------------------
  3267.     if z<0.01: z = 0.01
  3268.     x = (VX[n]+PX+XR)/z
  3269.     y = (VY[n]+PY+YR)/z
  3270.     img.point((x+halfResX,y+halfResY),0x0000ff,width=Size/z)
  3271.     img.point((PX+halfResX,PY+halfResY),0xff0000,width=Size)
  3272.  
  3273.     c.blit(img)
  3274.     if key.is_down(EScancodeLeftArrow): PX-=2
  3275.     if key.is_down(EScancodeRightArrow): PX+=2
  3276.     if key.is_down(EScancodeUpArrow): PY-=2
  3277.     if key.is_down(EScancodeDownArrow): PY+=2
  3278.     if key.is_down(EScancode1): PZ-=2
  3279.     if key.is_down(EScancode3): PZ+=2
  3280.     if key.is_down(EScancode4): ANGLEY-=2
  3281.     if key.is_down(EScancode6): ANGLEY+=2
  3282.     if key.is_down(EScancode2): ANGLEX-=2
  3283.     if key.is_down(EScancode8): ANGLEX+=2
  3284.     if key.is_down(EScancodeStar): ANGLEZ-=2
  3285.     if key.is_down(EScancodeHash): ANGLEZ+=2
  3286.  
  3287. e32.ao_yield()
  3288. ---------------------------------------------------------------------------------------
  3289.  
  3290. Note:
  3291. Tanda > diganti menggunakan spasi.
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297. ==========
  3298.  
  3299.  
  3300.  
  3301. 051.
  3302.  
  3303. "LIST, FUNGSI dan CLASS"
  3304.  
  3305. Saya mau share bagaimana mengelompokan script dengan penggunaan multi dimensional list:
  3306.  
  3307. ---------------------------------------------------------------------------------------
  3308. nama_list=[[nilai,nilai],[nilai,nilai]]
  3309. ---------------------------------------------------------------------------------------
  3310.  
  3311. fungsi berargumen:
  3312.  
  3313. ---------------------------------------------------------------------------------------
  3314. def nama_fungsi(argumen):
  3315.  
  3316.     isi_fungsi
  3317. ---------------------------------------------------------------------------------------
  3318.  
  3319. dan class:
  3320.  
  3321. ---------------------------------------------------------------------------------------
  3322. class nama_class:
  3323.  
  3324.     isi_class
  3325. ---------------------------------------------------------------------------------------
  3326.  
  3327. Sekali lagi ini hanyalah contoh, bukan struktur script yang baik,
  3328.  
  3329. Note:
  3330. Ganti tanda ">" pada awal syntax dengan spasi. Sebagai contoh, data disimpan dalam multi dimensional list.
  3331.  
  3332. ---------------------------------------------------------------------------------------
  3333. type1 = ["Alas kaki", ["sepatu","sandal"]]
  3334.  
  3335. type2 = ["Tutup kepala", ["topi","peci"]]
  3336. ---------------------------------------------------------------------------------------
  3337.  
  3338. Lalu misal kita ingin membuat fungsi untuk memproses nilai-nilai list diatas
  3339.  
  3340. ---------------------------------------------------------------------------------------
  3341. def cek_type1():
  3342.  
  3343.     print "kategori "+type1[0]+" berisi:"
  3344.  
  3345.         for i in range(len(type1[1])):
  3346.  
  3347.             print type1[1][i]
  3348.  
  3349.  
  3350. def cek_type2():
  3351.  
  3352.     print "kategori "+type2[0]+" berisi:"
  3353.  
  3354.         for i in range(len(type2[1])):
  3355.  
  3356.             print type2[1][i]
  3357. ---------------------------------------------------------------------------------------
  3358.  
  3359. -Pemanggilan
  3360.  
  3361. ---------------------------------------------------------------------------------------
  3362. cek_type1()
  3363.  
  3364. cek_type2()
  3365. ---------------------------------------------------------------------------------------
  3366.  
  3367. Jika list type banyak macamnya misalnya type1,type2,type3...type40, kita harus mencari cara yang lebih efisien. Salah satu solusinya yaitu membuat mesin untuk melakukan proses (dalam hal ini proses pengecekan). Untuk ini kita dapat menggunakan fungsi berargumen.
  3368.  
  3369. ---------------------------------------------------------------------------------------
  3370. def mesin_cek(type_barang):
  3371.  
  3372.     print "kategori "+type_barang[0]+" berisi:"
  3373.  
  3374.         for i in range(len(type_barang[1])):
  3375.  
  3376.             print type_barang[1][i]
  3377. ---------------------------------------------------------------------------------------
  3378.  
  3379. -Pemanggilan
  3380.  
  3381. ---------------------------------------------------------------------------------------
  3382. mesin_cek(type1)
  3383.  
  3384. mesin_cek(type2)
  3385. ---------------------------------------------------------------------------------------
  3386.  
  3387. Fungsi mesin_cek diatas memproses data argumen yang dimasukkan. Dengan begini, kita cukup menggunakan satu fungsi diatas untuk mengecek semua data list type kita.
  3388.  
  3389. Jika fungsi kita banyak akan lebih mudah diorganisir jika disimpan didalam class. Jika script diatas dikelompokkan dengan class:
  3390. class pakaian:
  3391.  
  3392. ---------------------------------------------------------------------------------------
  3393.     type1=["Alas kaki", ["sepatu","sandal"]]
  3394.  
  3395.     type2=["Tutup kepala", ["topi","peci"]]
  3396.  
  3397.  
  3398.     def mesin_cek(self,type_barang):
  3399.  
  3400.         print "kategori "+type_barang[0]+" berisi:"
  3401.  
  3402.             for i in range(len(type_barang[1])):
  3403.  
  3404.                 print type_barang[1][i]
  3405. ---------------------------------------------------------------------------------------
  3406.  
  3407. -Pemanggilan
  3408.  
  3409. ---------------------------------------------------------------------------------------
  3410. p=pakaian()
  3411.  
  3412. p.mesin_cek(p.type1)
  3413.  
  3414. p.mesin_cek(p.type2)
  3415. ---------------------------------------------------------------------------------------
  3416.  
  3417. "self" digunakan untuk menandai bahwa objek tersebut berada pada class yang sama. Jika kita tidak menyertakan self maka objek yang dipanggil adalah objek global, dan jika tidak ada objek global yang dimaksud, maka pesan error muncul. Contoh:
  3418.  
  3419. -Global variabel angka
  3420.  
  3421. ---------------------------------------------------------------------------------------
  3422. angka=1
  3423. ---------------------------------------------------------------------------------------
  3424.  
  3425. class percobaan:
  3426. -Lokal variabel angka
  3427.  
  3428. ---------------------------------------------------------------------------------------
  3429.     angka=6
  3430.  
  3431.     def test(self):
  3432.  
  3433.         print angka # global
  3434.  
  3435.         print self.angka # lokal
  3436.  
  3437.  
  3438.  
  3439. c=percobaan()
  3440.  
  3441. c.test()
  3442. ---------------------------------------------------------------------------------------
  3443.  
  3444. -Jika variabel lokal angka dipanggil dari luar class, harus menyertakan instance class nya
  3445.  
  3446. ---------------------------------------------------------------------------------------
  3447. print c.angka
  3448. print angka
  3449. ---------------------------------------------------------------------------------------
  3450.  
  3451. Note:
  3452. Tanda > diganti menggunakan spasi.
  3453.  
  3454.  
  3455.  
  3456.  
  3457.  
  3458. ==========
  3459.  
  3460.  
  3461.  
  3462. 052.
  3463.  
  3464. "MELOAD GAMBAR EXTERNAL DENGAN MODULE IMAGE 1ST"
  3465.  
  3466. Saya mau share tentang cara meload gambar eksternal khususnya pada s60 1st, namun bisa juga digunakan pada s60 2nd...
  3467.  
  3468. Fungsi pada module graphics yang berfungsi untuk meload dan menampilkan gambar pada appuifw.canvas() yaitu: graphics.Image.open(). Sayangnya fungsi tersebut hanya berjalan pada s60v2 keatas dan tidak jalan pada N-Gage saya yang masih s60 v1. Beruntung ada modul buatan pihak ketiga yang berfungsi untuk menampilkan gambar pada s60 v1. Modul tersebut bernama "image1st". Sebenarnya ingin membahas fungsi Image.open() juga, tapi karena saya ndak punya HP buat ngetest jadi hanya cara menampilkan gambar dengan image1st yang saya bahas. Sebelumnya simpan gambar dibawah ini dan taruh difolder E:\images\
  3469.  
  3470. Pada Pys60 Blit() berfungsi untuk menampilkan gambar baik gambar external ataupun old graphics didalam ataupun diluar objek gambar external atau old graphics juga.
  3471.  
  3472. blit untuk menampilkan gambar external:
  3473.  
  3474. ---------------------------------------------------------------------------------------
  3475. img.blit(file_gambar)
  3476. ---------------------------------------------------------------------------------------
  3477.  
  3478. Gambar tersebut ditampilkan apa adanya dengan posisi pada pojok kiri atas. Posisi gambar dapat kita atur target posisinya:
  3479.  
  3480. ---------------------------------------------------------------------------------------
  3481. img.blit(file_gambar, target=(20,20))
  3482. ---------------------------------------------------------------------------------------
  3483.  
  3484. Penjelasan:
  3485. target=(x, y)
  3486.  
  3487. Selain mengatur posisi target, kita juga dapat memotong gambar yang ingin ditampilkan (croping):
  3488.  
  3489. ---------------------------------------------------------------------------------------
  3490. img.blit(file_gambar, target=(20,20), source=(20,20,20,20))
  3491. ---------------------------------------------------------------------------------------
  3492.  
  3493. Penjelasan:
  3494. source=(PotongGambarKiri, PotongGambarAtas,PotongGambarKanan, PotongGambarBawah)
  3495.  
  3496. Pemotongan sebanyak nilai yang dimasukkan (dalam piksel)
  3497.  
  3498. Kita juga dapat me-resize gambarnya:
  3499.  
  3500. ---------------------------------------------------------------------------------------
  3501. img.blit(file_gambar, target=(30,30,30,30), scale=1)
  3502. ---------------------------------------------------------------------------------------
  3503.  
  3504. Penjelasan:
  3505. Python akan meresize gambar sebesar atau sesuai target yang kita masukkan. Pengaturan posisi target sama dengan source. Misalnya kita ingin meresize ukuran gambar menjadi fullscreen 176x208 (resolusi layar HP saya) maka posish target dirubah menjadi (0,0,176,208). Namun resize gambar ini lumayan berat.
  3506.  
  3507. Ada satu pengaturan lagi yaitu "mask" ini digunakan untuk mentransparansi gambar sayang, masking ini hanya support pada s60 2nd fp2 keatas. Maaf, saya belum mencoba masking ini jadi tidak saya bahas.
  3508.  
  3509. Itulah penggunaan fungsi blit().
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515. ==========
  3516.  
  3517.  
  3518.  
  3519. 053.
  3520.  
  3521. "CONTOH PROGRAM GAME GUNTING, BATU, KERTAS"
  3522.  
  3523. Saya mau share cara membuat game text based "Gunting batu kertas"...
  3524.  
  3525. Sebagai contoh penggunaan variabel, dictionary, definisi dan percabangan (else if) pada program game. Ok mari kita mulai:
  3526.  
  3527. -Import beberapa module yang akan kita gunakan
  3528.  
  3529. ---------------------------------------------------------------------------------------
  3530. import appuifw, e32, random
  3531. ---------------------------------------------------------------------------------------
  3532.  
  3533. -Mendefinisikan dictionary bernama "pilih" yang berisi tiga pasang key value, yaitu key Gunting yang kita beri value 0, key Batu yang kita beri value 1, key Kertas yang kita beri value 2
  3534.  
  3535. ---------------------------------------------------------------------------------------
  3536. pilih = {"Gunting": 0, "Batu": 1, "Kertas": 2}
  3537. ---------------------------------------------------------------------------------------
  3538.  
  3539. -Membuat variabel yang kita kasih nama "Pemain". Nantinya variabel ini akan kita gunakan untuk mendefinisikan nilai yang dipilih player atau pemain nilainya diambil dari dictionary (0, 1, atau 2). Saat ini variabel ini kita buat tidak terdefinisi (None).
  3540.  
  3541. ---------------------------------------------------------------------------------------
  3542. Pemain=None
  3543. ---------------------------------------------------------------------------------------
  3544.  
  3545. -Kita buat variabel lagi yang kita kasih nama "Musuh". Nantinya variabel ini akan kita gunakan untuk mendefinisikan nilai yang dipilih cpu atau musuh nilainya kita acak (0, 1, atau 2). Saat ini variabel ini kita buat tidak terdefinisi (None).
  3546.  
  3547. ---------------------------------------------------------------------------------------
  3548. Musuh=None
  3549. ---------------------------------------------------------------------------------------
  3550.  
  3551. -Membuat variabel kosong yang kita kasih nama "konf" (konfirmasi) yang akan dipakai untuk menyimpan konfirmasi "menang", "kalah", atau "seimbang".
  3552.  
  3553. ---------------------------------------------------------------------------------------
  3554. konf=None
  3555. ---------------------------------------------------------------------------------------
  3556.  
  3557. -Mendefinisikan fungsi yang kita berinama "gameplay" sebagai otak game untuk membandingkan apa yang dipilih pemain dengan apa yang dipilh musuh (random) dan menentukan siapa yang menang.
  3558.  
  3559. -Untuk memanggil fungsi gameplay diatas kita buat tiga fungsi, masing2 memberi nilai berbeda kepada gameplay yaitu 0 (Gunting), 1 (Batu), 2 (Kertas).
  3560.  
  3561. -Agar player dapat meng-input apa yang dipilih kita membutuhkan fungsi untuk menerima data dari player. Pada game sebenarnya menggunakan tombol navigasi dan keypad, namun pada program ini kita memakai menu dari module appuifw.
  3562.  
  3563. ---------------------------------------------------------------------------------------
  3564. appuifw.app.menu=[(u"Pilih gunting", memilihGunting),(u"Pilih batu", memilihBatu),(u"Pilih kertas", memilihKertas)]
  3565. ---------------------------------------------------------------------------------------
  3566.  
  3567. -Membuat fungsi penutupan aplikasi dan menunggu tombol exit ditekan dengan module appuifw dan e32
  3568.  
  3569. ---------------------------------------------------------------------------------------
  3570. def quit():
  3571.     script_lock.signal()
  3572.  
  3573. appuifw.app.exit_key_handler=quit
  3574.  
  3575. script_lock=e32.Ao_lock()
  3576. script_lock.wait()
  3577. ---------------------------------------------------------------------------------------
  3578.  
  3579.  
  3580.  
  3581.  
  3582.  
  3583. ==========
  3584.  
  3585.  
  3586.  
  3587. 054.
  3588.  
  3589. "SEDIKIT PENJELASAN IDENTASI PADA PYTHON"
  3590.  
  3591. Saya mau share sedikit identasi pada python atau pada script pys60...
  3592.  
  3593. Dalam pemrograman kita sering mengelompokkan beberapa kode dengan tujuan agar lebih mudah dibaca. Atau terkadang kode memang harus dibuat dalam blok-blok statement agar dapat berjalan, misalnya kita membuat sekumpulan kode yang akan berjalan ketika suatu event terjadi.
  3594.  
  3595. Blok-blok statement pada Pyhon ditandai dengan jumlah spasi pada awal kode pada setiap baris, perhatikan contoh berikut ini:
  3596.  
  3597. Penjelasan:
  3598. kode X=2 adalah sebuah statement, kode Y=2 juga merupakan sebuah statement. Setiap statement pada python dipisahkan dengan ganti baris.
  3599.  
  3600. kode if X == Y: merupakan awal sebuah blok statement (kita sebut saja blok statement pertama), sedangkan kode print"Tubrukan terdeteksi" adalah statement blok pertama tersebut (ditandai dengan memberi spasi pada awal baris, ane gunakan 2 spasi).
  3601.  
  3602. Sedangkan kode else: merupakan awal sebuah blok statement kedua dan print "Tidak terjadi tubrukan" adalah statement blok kedua.
  3603.  
  3604. Berikut ilustrasi yang menjelaskan penggunaan blok statement dalam psoudo code:
  3605.  
  3606. Contoh kedua:
  3607.  
  3608. Berikut ilustrasi contoh penulisan kode yang salah:
  3609.  
  3610. Sebuah statement juga dapat dipotong2 menjadi beberapa baris dengan menggunakan tanda "\" berikut contohnya:
  3611.  
  3612. ---------------------------------------------------------------------------------------
  3613. print "Sudah adzan\
  3614. saatnya sholat"
  3615. ---------------------------------------------------------------------------------------
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621. ==========
  3622.  
  3623.  
  3624.  
  3625. 055.
  3626.  
  3627. "HEAT SEEKING MISSILE ALOGARITMA dan IMPLEMENTASI"
  3628.  
  3629. Saya mau share tentang cara membuat game pesawat tempur atau perang bintang...
  3630.  
  3631. Pasti anda pernah main game SHMUP seperti Sky Force buatan Infinity Dream atau game combat flight simulation seperti Galaxy On Fire buatan Fishlabs. Dalam game terdapat misil yang dapat mengejar target. Saya akan jelaskan dasar algoritma dan implementasi fisika gerakan misil tersebut.
  3632.  
  3633. Algoritmanya sederhana, pertama hitung angle (sudut arah rotasi) antara misil dan target. Lalu bandingkan dengan angle misil. Jika hasilnya lebih besar dari nol, putar misil kekanan. Jika lebih kecil dari nol, putar misil kekiri.
  3634.  
  3635. Dan seperti biasa, implementasinya tidak sesederhana algoritmanya biggrin tapi tidak terlalu sulit kok. Kita pakai operasi trigonometri dan vektor.
  3636.  
  3637. Dimulai dari menghitung radian angle antara misil dan target. Rumusnya "angle = -atan(deltaX atau deltaY)" tapi butuh beberapa normalisasi agar berkerja dengan benar, saya jelaskan dibawah.
  3638.  
  3639. Heat seeking missile
  3640. -Hitung delta antara misil dan target
  3641.  
  3642. ---------------------------------------------------------------------------------------
  3643.     deltaX = missileX - targetX
  3644.     deltaY = missileY - targetY
  3645. ---------------------------------------------------------------------------------------
  3646.  
  3647. Heat seeking missile
  3648. -Gunakan delta untuk menghitung radian angle
  3649.  
  3650. ---------------------------------------------------------------------------------------
  3651.     angleToTarget = -atan(deltaX/deltaY)
  3652. ---------------------------------------------------------------------------------------
  3653.  
  3654. Kode diatas memiliki masalah. Jika targetY sejajar dengan missileY, tidak bisa membedakan apakah target berada disebelah kanan misil (90 derajat) atau dikiri (180 derajat). Dan output angle hanya dalam 180 derajat saja tidak full 360 derajat. Tenang, cukup menggunakan percabangan if else untuk menyelesaikannya.
  3655.  
  3656. ---------------------------------------------------------------------------------------
  3657.     deltaX = missileX - targetX
  3658.     deltaY = missileY - targetY
  3659.     if deltaY == 0:
  3660.         if deltaX<0:
  3661.     angleToTarget = 1.57
  3662.     else:   angleToTarget = -1.57
  3663.     else:
  3664.         angleToTarget = -atan(deltaX/deltaY)
  3665.         if dy<0:
  3666.     angleToTarget += 3.14
  3667.     if angleToTarget<0:
  3668.         angleToTarget += 6.28
  3669. ---------------------------------------------------------------------------------------
  3670.  
  3671. Selanjutnya menghitung selisih angleToFace dengan angleMissile untuk memenentukan apakah misil harus diputar kekanan, kekiri atau tidak diputar karena sudah mengarah ke target.
  3672.  
  3673. Heat seeking missile
  3674. -Hitung sinus dan cosinus
  3675.  
  3676. ---------------------------------------------------------------------------------------
  3677.     missileSin = sin(missileAngle)
  3678.     missileCos = cos(missileAngle)
  3679.     toTargetSin = sin(angleToTarget)
  3680.     toTargetCos = cos(angleToTarget)
  3681. ---------------------------------------------------------------------------------------
  3682.  
  3683. -Hitung selisih angle menggunakan dot product
  3684.  
  3685. ---------------------------------------------------------------------------------------
  3686.     selisih = (missileSin*toTargetSin) + (missileCos*toTargetCos)
  3687. ---------------------------------------------------------------------------------------
  3688.  
  3689. -Mmemutar missile
  3690.  
  3691. ---------------------------------------------------------------------------------------
  3692.     if selisih<0:
  3693.         missileAngle += missileRotSpd
  3694.     elif selisih>0:
  3695.         missileAngle -= missileRotSpd
  3696. ---------------------------------------------------------------------------------------
  3697.  
  3698. Selesai, jika dalam ruang 3d dapat menggunakan cara yang sama denga dua kali rotasi pada poros x dan poros y.
  3699.  
  3700.  
  3701.  
  3702.  
  3703. ==========
  3704.  
  3705.  
  3706.  
  3707. 056.
  3708.  
  3709. "MEMBUAT KUIS DENGAN PYS60"
  3710.  
  3711. Saya mau share cara membuat kuis dengan pys60...
  3712.  
  3713. Ini contoh scriptnya,
  3714. ---------------------------------------------------------------------------------------
  3715. from appuifw import *
  3716.  
  3717. jawaban=['Y']
  3718.  
  3719. pertanyaan=query(u'kamu suka makan?','text',u'jawab dg Y atau T' )
  3720.  
  3721. if jawaban.__contains__(pertanyaan )==1: note(u'weleh.. weleh.. kamu suka makan..','conf' )
  3722. else: note(u'gak suka makan ya..','error' )
  3723. ---------------------------------------------------------------------------------------
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729. ==========
  3730.  
  3731.  
  3732.  
  3733. 057.
  3734.  
  3735. "MEMBACA PESAN DENGAN PYS60"
  3736.  
  3737. Saya mau share sebuah script yang dapat membaca pesan masuk...
  3738.  
  3739. Saya pernah membaca sebuah tutorial menggunakan modul inbox untuk membaca pesan masuk pertama.
  3740.  
  3741. Kurang lebih tutorialnya seperti ini:
  3742.  
  3743. ---------------------------------------------------------------------------------------
  3744.     import inbox
  3745.     ib=inbox.Inbox(inbox.EInbox)
  3746.     ib.content(ib.sms_messages()[0])
  3747. ---------------------------------------------------------------------------------------
  3748.  
  3749.  
  3750.  
  3751.  
  3752. ==========
  3753.  
  3754.  
  3755.  
  3756. 058.
  3757.  
  3758. "BEBERAPA GAYA PENULISAN SCRIPT PYTHON"
  3759.  
  3760. Saya mau share gaya penulisan dalam sebuah script...
  3761.  
  3762. Ada beberapa cara penulisan script python.
  3763. Antara lain:
  3764.  
  3765. 01.
  3766. import appuifw
  3767. import graphics
  3768.  
  3769. 02.
  3770. import appuifw,graphics
  3771.  
  3772. 03.
  3773. from appuifw import*
  3774. from graphics import*
  3775.  
  3776. 04.
  3777. import appuifw;import graphics
  3778.  
  3779. 05.
  3780. from appuifw import*;from graphics import*
  3781.  
  3782. 06.
  3783. import appuifw as a
  3784. import graphics as g
  3785.  
  3786. 07.
  3787. import appuifw as a;import graphics as g
  3788.  
  3789. Fungsi sintax diatas adalah sama, yaitu mengimport modul appuifw dan graphics.
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795. ==========
  3796.  
  3797.  
  3798.  
  3799. 059.
  3800.  
  3801. "MENAMPILKAN IP DENGAN PYS60"
  3802.  
  3803. Saya mau share sebuah script untuk menampilkan sebuah ip...
  3804.  
  3805. Ternyata bisa juga menampilkan ip saat kita terkoneksi dengan internet dengan beberapa baris code saja.
  3806.  
  3807.  
  3808. Ini dia codenya:
  3809.  
  3810. ---------------------------------------------------------------------------------------
  3811. import socket
  3812.  
  3813. n=socket.select_access_point()
  3814.  
  3815. j=socket.access_point(n)
  3816.  
  3817. j.start()
  3818.  
  3819. ip=j.ip()
  3820. print ip
  3821.  
  3822. j.stop()
  3823. ---------------------------------------------------------------------------------------
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829. ==========
  3830.  
  3831.  
  3832.  
  3833. 060.
  3834.  
  3835. "MODUL TXTFIELD"
  3836.  
  3837. Saya mau share sebuah script yang fungsinya seperti nulis teks dibar address url...
  3838.  
  3839. Contoh penggunaanya, kayak gini
  3840.  
  3841. ---------------------------------------------------------------------------------------
  3842. import txtfield
  3843.  
  3844. t1 = txtfield.New( (10,10,100,40) , (txtfield.ENoLineBreaks )
  3845. t1.focus(1)
  3846. ---------------------------------------------------------------------------------------
  3847.  
  3848.  
  3849.  
  3850.  
  3851.  
  3852. ==========
  3853.  
  3854.  
  3855.  
  3856. 061
  3857.  
  3858. "PERULANGAN FOR DALAM PYS60"
  3859.  
  3860. Saya mau share script untuk perulangan sebuah teks...
  3861.  
  3862. Kita coba dulu dengan yang ini:
  3863.  
  3864. ---------------------------------------------------------------------------------------
  3865. x=5
  3866. for i in range(x):
  3867.     print unicode('test' )
  3868. ---------------------------------------------------------------------------------------
  3869.  
  3870. hasilnya:
  3871. test
  3872. test
  3873. test
  3874. test
  3875. test
  3876.  
  3877. kesimpulannya:
  3878. i disini akan mencetak kata 'tes' sejumlah value 'x'.
  3879.  
  3880. Or
  3881. mengeprint 'tes' sebanyak 'x' kali.
  3882.  
  3883. Dan ini contoh penerapannya di script,
  3884.  
  3885. ---------------------------------------------------------------------------------------
  3886. from appuifw import*
  3887. from e32 import*
  3888.  
  3889. l=Ao_lock()
  3890. t=Text()
  3891.  
  3892. def quit():
  3893. >>l.signal()
  3894.  
  3895. font=available_fonts()
  3896. for i in range(len(font)):
  3897. >>t.font=font
  3898. >>t.color=0
  3899. >>t.add(unicode(str(font)+': abc 123\n' ))
  3900.  
  3901. app.screen='full'
  3902. app.body=t
  3903. app.exit_key_handler=quit
  3904. l.wait()
  3905. ---------------------------------------------------------------------------------------
  3906.  
  3907. Note:
  3908. Tanda > diganti menggunakan spasi.
  3909.  
  3910.  
  3911.  
  3912.  
  3913.  
  3914. ==========
  3915.  
  3916.  
  3917.  
  3918. 062.
  3919.  
  3920. "POPUP MENU GANDA DENGAN PYS60"
  3921.  
  3922. Saya mau share sebuah script popup menu ganda...
  3923.  
  3924. ---------------------------------------------------------------------------------------
  3925. from appuifw import*
  3926.  
  3927. a=[( u'satu satu' ),( u'satu dua' ),( u'satu tiga' )]
  3928.  
  3929. b=[( u'dua satu' ),( u'dua dua' )]
  3930.  
  3931. list_sub=[a,b]
  3932.  
  3933. menu=[( u'satu' ),( u'dua' )]
  3934.  
  3935. p=popup_menu( menu,u'pilih' )
  3936.  
  3937. q=popup_menu( list_sub[p],u'masuk_sub '+str( p+1 ))
  3938.  
  3939. print u'pilihan pertama: '+str( p+1 )+u'\npilihan ke dua: '+str( q+1 )
  3940. ---------------------------------------------------------------------------------------
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946. ==========
  3947.  
  3948.  
  3949.  
  3950. 063.
  3951.  
  3952. "MENGECEK dan MEMBUAT FOLDER DENGAN PYS60"
  3953.  
  3954. Saya mau share sebuah script untuk mengecek ada atau nggak ada folder di HP kita dengan module os. Dan module appuifw untuk pemberitahuannya.
  3955.  
  3956. Langsung saja, berikut adalah kodenya..
  3957.  
  3958. ---------------------------------------------------------------------------------------
  3959. import appuifw,os
  3960. folder=unicode( "e:\\NamaFolder" )
  3961.  
  3962. if os.path.exists(folder):
  3963. >>appuifw.note( unicode( ""+str(folder)+" ada" ))
  3964. >>if appuifw.query( unicode( "hapus "+str(folder) ), "query" )== True:
  3965.     os.removedirs( folder )
  3966.     appuifw.note( unicode( ""+str(folder)+" selesai dihapus" ))
  3967. >>else:
  3968.     appuifw.note( unicode( ""+str(folder)+" tidak dihapus" ))
  3969. >>else:
  3970. >>appuifw.note( unicode( ""+str(folder)+" tidak ada" ))
  3971. >>if appuifw.query( unicode( "buat "+str(folder) ), "query" )== True:
  3972.     os.makedirs( folder )
  3973.     appuifw.note( unicode( ""+str(folder)+" selesai dibuat" ))
  3974. >>else:
  3975.     appuifw.note( unicode( "membuat "+str(folder)+" dibatalkan" ))
  3976. ---------------------------------------------------------------------------------------
  3977.  
  3978.  
  3979.  
  3980.  
  3981.  
  3982. ==========
  3983.  
  3984.  
  3985.  
  3986. 064.
  3987.  
  3988. "SALAH SATU PERBEDAAN SYNTAK S60v1 dan S60v2 DIATASNYA"
  3989.  
  3990. Saya mau share tentang perbedaan script untuk import gambar antara s60v1 dan s60v2...
  3991.  
  3992. Mungkin teman-teman sudah tahu, bahwa s60v1 dan s60v2 keatas mempunyai cara yang berbeda dalam menampilkan gambar.
  3993.  
  3994. Perbedaan ini menjadi salah satu yang menyebabkan aplikasi s60v2 keatas tidak dapat dibuka di s60v1.
  3995.  
  3996. Berikut perbedaannya:
  3997.  
  3998. s60v2 keatas:
  3999.  
  4000. ---------------------------------------------------------------------------------------
  4001. import graphics
  4002.  
  4003. file=u'e:\\nama_file.jpg'
  4004. im=graphics.Image.new(( 176,208 ))
  4005.  
  4006. gambar=graphics.Image.open(file)
  4007. im.blit(gambar, target=(0,0))
  4008. ---------------------------------------------------------------------------------------
  4009.  
  4010. s60v1:
  4011.  
  4012. ---------------------------------------------------------------------------------------
  4013. import graphics,image1st
  4014.  
  4015. file=u'e:\\nama_file.jpg'
  4016. im=graphics.Image.new(( 176,208 ))
  4017.  
  4018. bm=graphics.Image.from_cfbsbitmap
  4019. img=image1st.convertimage
  4020.  
  4021. gambar=bm( img( file ))
  4022. im.blit(gambar, target= ( 0,0 ))
  4023.  
  4024. ---------------------------------------------------------------------------------------
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030. ==========
  4031.  
  4032.  
  4033.  
  4034. 065.
  4035.  
  4036. "ROTASI POLYGON DENGAN PYS60"
  4037.  
  4038. Saya mau share cara rotasi pada gambar tradisional...
  4039.  
  4040. Menurut sumbernya saya mendapatkan rumus ini:
  4041.  
  4042. ---------------------------------------------------------------------------------------
  4043. rad=(angle/180.0)*pi
  4044. rot_x=cos(rad)*pos_x-sin(rad)*pos_y
  4045. rot_y=sin(rad)*pos_x+cos(rad)*pos
  4046. ---------------------------------------------------------------------------------------
  4047.  
  4048. Contoh script di pys60
  4049.  
  4050. ---------------------------------------------------------------------------------------
  4051. import e32,appuifw,math,graphics,sysinfo
  4052.  
  4053. def exit_handler():
  4054. >>>global run;run=0
  4055.  
  4056. canvas=appuifw.Canvas()
  4057. appuifw.app.body=canvas
  4058. appuifw.app.screen='full'
  4059. appuifw.app.exit_key_handler=exit_handler
  4060. layar=sysinfo.display_pixels()
  4061. im=graphics.Image.new(layar)
  4062. run=1
  4063.  
  4064. pos_x,pos_y,angle=0,0,1.0
  4065. panah=[(x-16,y),(x,y-20),(x+16,y),(x+4,y),(x+4,y+10),(x-4,y+10),(x-4,y)]
  4066. camx,camy=layar[0]/2,layar[1]/2
  4067.  
  4068. while run:
  4069. >>>gb=[]
  4070. >>>rad=float(angle/180.0)*math.pi
  4071. >>>angle+=10
  4072. >>>if angle>360: angle=0
  4073. >>>for pos in panah:
  4074. >>>x,y=pos
  4075. >>>rx=math.cos(rad)*x-math.sin(rad)*y
  4076. >>>ry=math.sin(rad)*x+math.cos(rad)*y
  4077. >>>rx+=camx
  4078. >>>ry+=camy
  4079. >>>gb.append((rx,ry))
  4080. >>>im.clear(0)
  4081. >>>im.polygon(gb,0xdadada,fill=0x00ff00)
  4082. >>>canvas.blit(im)
  4083. >>>e32.ao_sleep(0)
  4084. ---------------------------------------------------------------------------------------
  4085.  
  4086. Note:
  4087. Tanda > diganti menggunakan spasi.
  4088.  
  4089.  
  4090.  
  4091.  
  4092.  
  4093. ==========
  4094.  
  4095.  
  4096.  
  4097. 066.
  4098.  
  4099. "SCAN ISI DRIVE DENGAN PYS60"
  4100.  
  4101. Saya mau share sebuah script untuk scanning isi drive di HP kita menggunakan pys60...
  4102.  
  4103. Ini baris codenya...
  4104.  
  4105. ---------------------------------------------------------------------------------------
  4106. from appuifw import*;import os,e32
  4107. f=e32.drive_list()
  4108.  
  4109. def scan(x):
  4110. >>if os.path.isdir(x):
  4111.     for i in os.listdir(x):
  4112.     >>if os.path.isdir(x+i):
  4113.         i=i+os.sep
  4114.     >>print x+i
  4115.     >>scan(x+i)
  4116.  
  4117. p=popup_menu(f,unicode( 'pilih drive' ))
  4118.  
  4119. if p!=None: scan( f[p]+os.sep )
  4120. else: print unicode( 'scan dibatalkan' )
  4121. ---------------------------------------------------------------------------------------
  4122.  
  4123. Note:
  4124. Tanda > diganti menggunakan spasi.
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130. ==========
  4131.  
  4132.  
  4133.  
  4134. 067.
  4135.  
  4136. "MENGGABUNGKAN FUNGSI DENGAN PROGRESS PADA PYS60"
  4137.  
  4138. Saya mau share sebuah script untuk menggabungkan module progress dengan fungsi, gunanya, buat mengetahui sampai mana fungsi yang sudah diproses...
  4139.  
  4140. Ini contoh scripnya,
  4141. ---------------------------------------------------------------------------------------
  4142. import progress
  4143.  
  4144. teks=['proses ke 1','proses ke 2','proses ke 3','proses ke 4','proses ke 5','proses ke 6','proses ke 7','proses ke 8','proses ke 9','proses ke 10']
  4145.  
  4146. pb=progress.TWProgressBar(start=0,end=100,fill=(0,0,0),outline=(100,255,0),display=(176,100),title=unicode( ' ' ))
  4147.  
  4148. def t1():
  4149. >>>print u'tes1'
  4150.  
  4151. def t2():
  4152. >>>print u'tes2'
  4153.  
  4154. def t3():
  4155. >>>print u'tes3'
  4156.  
  4157. def t4():
  4158. >>>print u'tes4'
  4159.  
  4160. def t5():
  4161. >>>print u'tes5'
  4162.  
  4163. def t6():
  4164. >>>print u'tes6'
  4165.  
  4166. def t7():
  4167. >>>print u'tes7'
  4168.  
  4169. def t8():
  4170. >>>print u'tes8'
  4171.  
  4172. def t9():
  4173. >>>print u'tes9'
  4174.  
  4175. def t10():
  4176. >>>print u'tes10'
  4177.  
  4178. tugas=[t1,t2,t3,t4,t5,t6,t7,t8,t9,t10]
  4179.  
  4180. for i in range(len(tugas)):
  4181. >>>tugas[ i ]()
  4182. >>>pb=progress.TWProgressBar(start=0,end=100,fill=(0,0,0),outline=(100,255,0),display=(176,100),title=unicode(''+str(teks[ i ])))
  4183. >>>pb.set_value((i+1)*10)
  4184. pb.close()
  4185. ---------------------------------------------------------------------------------------
  4186.  
  4187. Intinya, kita masukkan fungsi kedalam list, lalu kita jalankan fungsi setelah sebelumnya kita loop , kemudian value pada progress kita set loop listnya.
  4188.  
  4189. Note:
  4190. Tanda > diganti menggunakan spasi.
  4191.  
  4192.  
  4193.  
  4194.  
  4195.  
  4196. ==========
  4197.  
  4198.  
  4199.  
  4200. 068.
  4201.  
  4202. "SCRIPT PYS60 BERKODE"
  4203.  
  4204. Saya mau share sebuah script, dimana jika dalam waktu tertentu script tersebut akan meminta kode dari pemilik handphone...
  4205.  
  4206. Jika kode yang ditulis tidak sama dengan kunci kodenya, maka script akan tertutup.
  4207.  
  4208. Kita import module yang diperlukan.
  4209.  
  4210. ---------------------------------------------------------------------------------------
  4211. import appuifw,graphics,e32,sysinfo,time
  4212. def quit():
  4213.     global run
  4214.     run=0
  4215. ap=appuifw.app
  4216. ap.screen='full'
  4217. ap.body=c=appuifw.Canvas()
  4218. ap.exit_key_handler=quit
  4219. im=graphics.Image.new(( 176,208 ))
  4220.  
  4221. def unlock():
  4222.     imei=sysinfo.imei()
  4223.     return imei[:-2]
  4224.  
  4225. timer=10
  4226. def password():
  4227.     cd=appuifw.query( u'masukkan kode','code' )
  4228.     if cd !=unlock(): quit()
  4229.     else: pass
  4230.  
  4231. run=1
  4232. while run:
  4233.     im.clear(0)
  4234.     im.text((0,10),u'timer: '+str(time.localtime()[5]),0xdadada)
  4235.     im.text((0,30),u'kode yang harus dimasukkan: '+str(unlock()),0xdadada)
  4236.     if time.localtime()[5]==timer:
  4237.         password()
  4238.     c.blit(im)
  4239.     e32.ao_sleep(0)
  4240. ---------------------------------------------------------------------------------------
  4241.  
  4242.  
  4243.  
  4244.  
  4245. ==========
  4246.  
  4247.  
  4248.  
  4249. 069.
  4250.  
  4251. "MENAMPILKAN SEMUA ICON APLIKASI YANG TERINSTALL DENGAN PYS60"
  4252.  
  4253. Saya mau share module geticon buat nampilin icon aplikasi...
  4254.  
  4255. Ini contoh scriptnya,
  4256.  
  4257. ---------------------------------------------------------------------------------------
  4258. import appuifw,graphics,e32,geticon,os
  4259.  
  4260. run=1
  4261. def quit():
  4262. >>global run
  4263. >>run=0
  4264.  
  4265. appuifw.app.exit_key_handler=quit
  4266. appuifw.app.screen='full'
  4267. c=appuifw.Canvas()
  4268. appuifw.app.body=c
  4269. im=graphics.Image.new( (0,0) )
  4270. im_mask=graphics.Image.new( (0,0) , 'L' )
  4271.  
  4272. uid=[]
  4273. nama_app=[]
  4274. folder=u'e:\\system\\apps\\'
  4275. list_folder=os.listdir(folder)
  4276.  
  4277. def intip( x ):
  4278. >>x=(((x[3:4]+x[2:3])+x[1:2])+x[0:1])
  4279. >>x=x.encode( 'hex' )
  4280. >>return x
  4281.  
  4282. def uidnya(file):
  4283. >>f=open(file)
  4284. >>uid1=f.read(4)
  4285. >>uid2=f.read(4)
  4286. >>uid3=f.read(4)
  4287. >>f.close()
  4288. >>uidr1=intip(uid1)
  4289. >>uidr2=intip(uid2)
  4290. >>uidr3=intip(uid3)
  4291. >>return uidr3
  4292.  
  4293. def cek():
  4294. >>for i in list_folder:
  4295.     for app in os.listdir( folder+i+os.sep ):
  4296.     >>if app.endswith( u'.app' ):
  4297.         uid.append( '0x'+uidnya(folder+i+os.sep+app) )
  4298.         nama_app.append(app)
  4299.  
  4300. cek()
  4301. timer=0
  4302. y=0
  4303. while run:
  4304. >>if timer<=0:
  4305.     timer=1
  4306.     y-=29
  4307. >>if timer>0: timer-=1
  4308. >>if (len(uid)*29)+y<=0: y=0
  4309. >>c.clear()
  4310. >>for i in range( len(uid) ):
  4311.     geticon.get(eval( uid[ i ]),im,im_mask)
  4312.     c.text((80,50),u'timer: '+str((len(uid)*29)+y),0x0)
  4313.     c.blit(im,target=(10,y+(i*29)))
  4314. >>e32.ao_sleep(0.3)
  4315. ---------------------------------------------------------------------------------------
  4316.  
  4317. Note:
  4318. Tanda > diganti menggunakan spasi.
  4319.  
  4320.  
  4321.  
  4322.  
  4323.  
  4324. ==========
  4325.  
  4326.  
  4327.  
  4328. 070.
  4329.  
  4330. "MEMBUAT KURSOR 4 ARAH PADA APLIKASI DENGAN PYS60"
  4331.  
  4332. Saya mau share sebuah script untuk membuat menu aplikasi dengan kursor yang dapat digerakkan 4 arah, dengan menekan tombol 2,4,6,8. Dan tombol 5 untuk memilihnya...
  4333.  
  4334. Sebelumnya, siapakan dulu gambar di e:\\dengan nama gb.Jpg. Gambar tersebut akan diresize menurut ukuran layar HP pengguna. Ada module key yang saya import untuk menghandle tombolnya, kalau gak punya module key, bisa diganti dengan class keyboard di snake.py.
  4335.  
  4336. ---------------------------------------------------------------------------------------
  4337. import appuifw,graphics,e32,sysinfo
  4338.  
  4339. try: import key
  4340. except: appuifw.note( u'module key belum ada' )
  4341.  
  4342. run=1
  4343. def quit(): global run;run=0
  4344.  
  4345. appuifw.app.screen='full'
  4346. appuifw.app.exit_key_handler=quit
  4347. c=appuifw.Canvas(event_callback=key.press.handle_event)
  4348. appuifw.app.body=c
  4349. layar=sysinfo.display_pixels()
  4350. im=graphics.Image.new(layar)
  4351.  
  4352. lebar=layar[0]/3.0
  4353. tinggi=layar[1]/3.0
  4354.  
  4355. try: gambar=graphics.Image.open( u'e:\\gb.jpg' ).resize(( lebar,tinggi ))
  4356. except:
  4357. >>>appuifw.note( u'siapkan gambar di e:\\dulu' )
  4358. >>>quit()
  4359.  
  4360. pos_x=range(0,layar[0],lebar)
  4361. pos_y=range(0,layar[1],tinggi)
  4362.  
  4363. kursor_x,kursor_y=0,0
  4364. pos_x_kursor,pos_y_kursor=0,0
  4365.  
  4366. menu=[[ 'satu', 'dua', 'tiga' ], [ 'empat', 'lima', 'enam' ], [ 'tujuh', 'delapan', 'sembilan' ]]
  4367.  
  4368. while run:
  4369. >>>im.clear( 0 )
  4370. >>>for i in range( len( pos_x )):
  4371.     for j in range( len( pos_y )):
  4372.     im.blit(gambar,target= (pos_x[ i ],pos_y[ j ] ))
  4373.  
  4374. >>>if kursor_x > len( pos_x )-2:
  4375. >>>kursor_x = 0
  4376. >>>kursor_y += 1
  4377. >>>if kursor_y > len( pos_y )-2:
  4378. >>>kursor_y = 0
  4379. >>>if kursor_x < 0:
  4380. >>>kursor_x = len( pos_x )-2
  4381. >>>kursor_y -= 1
  4382. >>>if kursor_y < 0:
  4383. >>>kursor_y = len( pos_y )-2
  4384.  
  4385. >>>if kursor_y > len( pos_y )-2:
  4386. >>>kursor_y = 0
  4387. >>>kursor_x += 1
  4388. >>>if kursor_x > len( pos_x )-2:
  4389. >>>kursor_x = 0
  4390. >>>if kursor_y < 0:
  4391. >>>kursor_y = len( pos_y )-2
  4392. >>>kursor_x -= 1
  4393. >>>if kursor_x < 0:
  4394. >>>kursor_x = len( pos_x )-2
  4395.  
  4396. >>>im.rectangle(( pos_x_kursor+( kursor_x*( lebar-1 )),pos_y_kursor+( kursor_y*( tinggi-1 )), pos_x_kursor+lebar+( kursor_x*( lebar-1 )), pos_y_kursor+tinggi+( kursor_y*(tinggi-1 ))), 0xff0000)
  4397.  
  4398. >>>if key.press.is_down( key.EScancode5 ):
  4399. >>>im.rectangle(( 15,25,120,35 ),0x0, 0xda00d0)
  4400. >>>im.text(( 20,35 ),u'menu ke: '+str( menu[ kursor_y ][ kursor_x ]),0xffffff,font=u'latinbold12' )
  4401.  
  4402. >>>if key.press.pressed( key.EScancode6 ):
  4403. >>>kursor_x += 1
  4404. >>>if key.press.pressed( key.EScancode4 ):
  4405. >>>kursor_x -= 1
  4406. >>>if key.press.pressed( key.EScancode2 ):
  4407. >>>kursor_y -= 1
  4408. >>>if key.press.pressed( key.EScancode8 ):
  4409. >>>kursor_y += 1
  4410. >>>c.blit(im)
  4411. >>>e32.ao_yield()
  4412. ---------------------------------------------------------------------------------------
  4413.  
  4414. Note:
  4415. Tanda > diganti menggunakan spasi.
  4416.  
  4417.  
  4418.  
  4419.  
  4420.  
  4421. ==========
  4422.  
  4423.  
  4424.  
  4425. 071.
  4426.  
  4427. "MEMBUAT JAM ANALOG DENGAN PYS60"
  4428.  
  4429. Saya mau share cara membuat jam analog menggunakan pys60...
  4430.  
  4431. Pertama, kita tentukan jam sekarang dengan module time. Lengkapnya
  4432.  
  4433. ---------------------------------------------------------------------------------------
  4434. import time
  4435. data=time.localtime()
  4436. ---------------------------------------------------------------------------------------
  4437.  
  4438. Sekarang data sudah berisi tuple localtime, yang pertama adalah tahun, bulan, tanggal, jam, menit, detik.
  4439.  
  4440. Berikutnya, jika kita lihat jarum jam selalu muter kan? Buat memuterkan gambar, kita pakai cosinus, sinus, radian yang berasal dari fungsi module math.. Lengkapnya..
  4441.  
  4442. ---------------------------------------------------------------------------------------
  4443. Import math
  4444. x,y=0,0
  4445. sudut=0
  4446. jarak=10
  4447. rad=(float(sudut)*math.pi)/180
  4448. cos=math.cos
  4449. sin=math.sin
  4450. muter_x=cos(rad)*jarak-sin(rad)*jarak
  4451. muter_y=sin(rad)*jarak+cos(rad)*jarak
  4452. ---------------------------------------------------------------------------------------
  4453.  
  4454. Biasanya jarum detik itu bertambah 1, jika sudah mencapai 60, kembali ke 0 lagi.
  4455.  
  4456. Jadi, kita pakai
  4457.  
  4458. ---------------------------------------------------------------------------------------
  4459. rad_detik = (detik_sekarang/jumlah 1 putaran)*360 derajat
  4460. ---------------------------------------------------------------------------------------
  4461.  
  4462. Begitu juga dengan jarum menit dan jarum jam.
  4463.  
  4464. Nanti kita tinggal menghubungkan titik pusat dengan koordinat koordinat jarum jam tadi sehingga menjadi garis.
  4465.  
  4466. Biar selalu diupdate, proses kita masukkan didalam identasi 'while' ..
  4467.  
  4468. Berikut ini scriptnya
  4469.  
  4470. ---------------------------------------------------------------------------------------
  4471. import appuifw,graphics,e32,sysinfo,time,math
  4472.  
  4473. run=1
  4474. def quit():
  4475. >>global run
  4476. >>run=0
  4477.  
  4478. appuifw.app.exit_key_handler=quit
  4479. appuifw.app.screen='full'
  4480. c=appuifw.Canvas()
  4481. appuifw.app.body=c
  4482. layar=sysinfo.display_pixels()
  4483. im=graphics.Image.new(layar)
  4484.  
  4485. x,y=layar[0]/2,layar[1]/2
  4486. detik=0
  4487. menit=0
  4488. jam=0
  4489.  
  4490. jdetik=layar[0]/4
  4491. jmenit=jdetik-5
  4492. jjam=jmenit-5
  4493.  
  4494. def radian(sudut):
  4495. >>return (float(sudut)*math.pi)/180.0
  4496.  
  4497. while run:
  4498. >>cos=math.cos
  4499. >>sin=math.sin
  4500. >>data=time.localtime()
  4501. >>detik=235+(data[5]*6)
  4502. >>menit=235+(data[4]*6)
  4503. >>jam=235+(data[3]*30)
  4504.  
  4505. >>rad_detik=radian(detik)
  4506. >>rad_menit=radian(menit)
  4507. >>rad_jam=radian(jam)
  4508.  
  4509. >>xdetik=cos(rad_detik)*jdetik-sin(rad_detik)*jdetik
  4510. >>ydetik=sin(rad_detik)*jdetik+cos(rad_detik)*jdetik
  4511.  
  4512. >>xmenit=cos(rad_menit)*jmenit-sin(rad_menit)*jmenit
  4513. >>ymenit=sin(rad_menit)*jmenit+cos(rad_menit)*jmenit
  4514.  
  4515. >>xjam=cos(rad_jam)*jjam-sin(rad_jam)*jjam
  4516. >>yjam=sin(rad_jam)*jjam+cos(rad_jam)*jjam
  4517.  
  4518. >>im.clear(0)
  4519. >>im.line((x,y,x+xdetik,y+ydetik),0xdd0000)
  4520. >>im.line((x,y,x+xmenit,y+ymenit),0xddd000)
  4521. >>im.line((x,y,x+xjam,y+yjam),0xddd000)
  4522.  
  4523. >>for i in range(225,585,30):
  4524.     l=jdetik+5
  4525.     rr=(float(i)*math.pi)/180
  4526.     xr=cos(rr)*l-sin(rr)*l
  4527.     yr=sin(rr)*l+cos(rr)*l
  4528.     im.point((x+xr,y+yr),(255,255,255),width=2)
  4529. >>c.blit(im)
  4530. >>e32.ao_yield()
  4531. ---------------------------------------------------------------------------------------
  4532.  
  4533. Penambahan 240 dan range(225,585,30) hanya akal-akalan saya saja biar jarumnya pas.
  4534.  
  4535. Note:
  4536. Tanda > diganti menggunakan spasi.
  4537.  
  4538.  
  4539.  
  4540.  
  4541.  
  4542. ==========
  4543.  
  4544.  
  4545.  
  4546. 072.
  4547.  
  4548. "INDIKATOR SINYAL, BATERAI DENGAN FGIMAGE (PYS60)"
  4549.  
  4550. Saya mau share cara menampilkan indikator battery menggunakan pys60...
  4551.  
  4552. Biar indikator jalan terus, maka kita pakai 'while' agar prosesnya biar update terus. Disini saya menggabunkan sysinfo dengan fgimage agar bisa ditampilkan dengan cara diminimize.
  4553.  
  4554. ---------------------------------------------------------------------------------------
  4555. import fgimage,appswitch,sysinfo,appuifw,graphics,e32
  4556.  
  4557. fg=0
  4558. def quit():
  4559. >>global run,runn,fg
  4560. >>run,runn,fg=0,0,0
  4561.  
  4562. def fokus(on):
  4563. >>global fg,run
  4564. >>if not on:
  4565.     fg=fgimage.FGImage()
  4566.     run=2
  4567. >>else:
  4568.     fg=0
  4569.     run=1
  4570.  
  4571. def menu_app():
  4572. >>gul=appswitch.application_list(0)[0]
  4573. >>appswitch.switch_to_bg(gul)
  4574.  
  4575. layar=sysinfo.display_pixels()
  4576. lebar,tinggi=176,15
  4577. posx,posy=0,29
  4578.  
  4579. menu=[(unicode( 'exit' ),quit)]
  4580. appuifw.app.screen='full'
  4581. appuifw.app.exit_key_handler=menu_app
  4582. appuifw.app.body=c=appuifw.Canvas()
  4583. appuifw.app.focus=fokus
  4584. appuifw.app.menu=menu
  4585. im=graphics.Image.new((lebar,tinggi))
  4586. img=graphics.Image.new(layar)
  4587. run,runn=1,1
  4588.  
  4589. class monitor:
  4590. >>def draw(self):
  4591.     sin=(float(sysinfo.signal())/7)*100
  4592.     sn=round(sin,1)
  4593.     bat=(float(sysinfo.battery())/7)*100
  4594.     bt=round(bat,1)
  4595.     im.clear(0xaa550f)
  4596.     im.text((90,12),unicode('baterai '+str(bt)+' %' ),0xfafafa,u'latinplain12' )
  4597.     im.text((5,12),unicode('sinyal '+str(sn)+' %' ) ,0xfafafa,u'latinplain12' )
  4598.     fg.set(posx,posy,im._bitmapapi( ))
  4599.  
  4600. teks=['','','http://gumalgamul.mywapblog.com','','','tool for show signal and battery','','','minimize for show']
  4601.  
  4602. def tulis(lis):
  4603. >>for i in range(len(lis)):
  4604.     img.text((3,10+(i*12)),unicode(''+lis),(200,200,200),u'latinplain12' )
  4605.  
  4606. gulam=monitor()
  4607. while runn:
  4608. >>while run==1:
  4609.     img.clear(0)
  4610.     tulis(teks)
  4611.     img.text((5,200 ),u'exit',0xfafafa)
  4612.     img.text((130,200),u'minimize',0xfafafa)
  4613.     c.blit(img)
  4614.     e32.ao_sleep(0)
  4615. >>while run==2:
  4616.     gulam.draw()
  4617.     e32.ao_sleep(0)
  4618. >>e32.ao_yield()
  4619. ---------------------------------------------------------------------------------------
  4620.  
  4621. Note:
  4622. Tanda > diganti menggunakan spasi.
  4623.  
  4624.  
  4625.  
  4626.  
  4627.  
  4628. ==========
  4629.  
  4630.  
  4631.  
  4632. 073.
  4633.  
  4634. "SET FGIMAGE PADA STANDBY PYS60"
  4635.  
  4636. Saya mau share cara menampilkan fgimage dimenu standby saja...
  4637.  
  4638. Pertama:
  4639.  
  4640. -mendeteksi bahwa aplikasi apa yang sekarang sedang berjalan.
  4641.  
  4642. -jika aplikasi == standby atau phone.app kita atur posisi 'fgimage' ke koordinat x dan y
  4643.  
  4644. -jika aplikasi != standby atau phone.app 'fgimage' kita kasih trik sedikit yaitu set posisi ke koordinat -x,-y biar gak kelihatan.
  4645.  
  4646. Lalu, bagaimana kita mendeteksi bahwa sekarang 'stand by' atau 'phone.app' sedang berjalan?
  4647.  
  4648. Kita pakai fungsi dari module appswitch aja, yaitu appswitch.application_list untuk mendeteksinya, dan diproses berulang ulang. Caranya,
  4649.  
  4650. ---------------------------------------------------------------------------------------
  4651. While proses:
  4652. >>now=appswitch.application_list(0)[0]
  4653. >>if now==u'Phone': fgimage set ke koordinat x,y
  4654. >>elif now==u'Menu': fgimage set ke koordinat x,y cadangan
  4655. >>else: fgimage set ke koordinat -x,-y
  4656. ---------------------------------------------------------------------------------------
  4657.  
  4658. Berikut penerapannya dalam script pys60
  4659.  
  4660. ---------------------------------------------------------------------------------------
  4661. import appuifw,graphics,e32,fgimage,appswitch,globalui
  4662.  
  4663. run=1
  4664. def quit():global run;run=0;fg.unset()
  4665.  
  4666. appuifw.app.screen='full'
  4667. appuifw.app.exit_key_handler=quit
  4668. appuifw.app.body=c=appuifw.Canvas()
  4669. im=graphics.Image.new((176,40))
  4670. fg=fgimage.FGImage()
  4671. x,y=0,0
  4672. posx,posy=0,10
  4673. while run:
  4674. >>posx+=2
  4675. >>if posx>176: posx=0
  4676. >>now=appswitch.application_list(0)[0]
  4677. >>if now==u'Phone':
  4678.     x,y=0,0
  4679.     im.clear( 0 )
  4680.     im.text((posx,posy),u'fg tampil',0xdadada)
  4681. >>elif now==u'Menu':
  4682.     x,y=0,160
  4683.     im.clear( 0 )
  4684.     im.text((posx,posy),u'minimize sekarang',0xdadada)
  4685. >>else: x,y=-10,-160
  4686. >>fg.set(x,y,im._bitmapapi())
  4687. >>e32.ao_yield()
  4688. ---------------------------------------------------------------------------------------
  4689.  
  4690. Note:
  4691. Tanda > diganti menggunakan spasi.
  4692.  
  4693.  
  4694.  
  4695.  
  4696.  
  4697. ==========
  4698.  
  4699.  
  4700.  
  4701. 074.
  4702.  
  4703. "SCREESHOT DENGAN N-GAGE atau S60v1 (PYS60)"
  4704.  
  4705. Saya mau share cara menscreenshot menggunakan tombol edit atau pensil...
  4706.  
  4707. Script python dibawah ini bisa mengambil screenshot dengan cara menekan tombol edit atau pensil.
  4708.  
  4709. Caranya? Run script, lalu tekan tombol menu untuk meminimalise aplikasi.. Tekan tombol edit atau pensil dibagian mana sobat ingin mengambil screenshotnya. Hasil gambar tersimpan di folder e:\\di sini ,dengan nama ss.jpg
  4710.  
  4711. ---------------------------------------------------------------------------------------
  4712. import appuifw,time,graphics,image1st2,keycapture,globalui
  4713. l=graphics.e32.Ao_lock()
  4714. def quit():capt.stop();l.signal()
  4715.  
  4716. def shot(on):nama=u'e:\\ss';ext=str(time.localtime()[3:6])+'.jpg';s=graphics.screenshot();image1st2.save(s,nama+ext);globalui.global_note( nama+ext+' tersimpan ' )
  4717.  
  4718. capt=keycapture.KeyCapturer(shot)
  4719. capt.keys=(63499,63499)
  4720. capt.start()
  4721. appuifw.app.exit_key_handler=quit
  4722. l.wait()
  4723. ---------------------------------------------------------------------------------------
  4724.  
  4725.  
  4726.  
  4727.  
  4728.  
  4729. ==========
  4730.  
  4731.  
  4732.  
  4733. 075.
  4734.  
  4735. "MEMBUAT GRAFIK (SCRIPT PYS60)"
  4736.  
  4737. Saya mau share cara menampilkan nilai menggunakan grafik...
  4738.  
  4739. Selain dengan bar, untuk menampilkan nilai, kita juga bisa menggunakan grafik.
  4740.  
  4741. Jadi caranya begini:
  4742. 1. Kita ambil posisi berdasarkan informasi ukuran layar.
  4743.  
  4744. ---------------------------------------------------------------------------------------
  4745. ly=sysinfo.display_pixels()
  4746. ---------------------------------------------------------------------------------------
  4747.  
  4748. 2. Kita buat posisi awal garis akan muncul. Posisi x kita atur layar paling kanan, posi y kita atur tinggi layar/2
  4749.  
  4750. ---------------------------------------------------------------------------------------
  4751. x,y=ly[0],ly[1]/2
  4752. ---------------------------------------------------------------------------------------
  4753.  
  4754. 3. Karena grafik yang akan kita buat berupa garis, maka kita buat list dengan isi 4 koordinat awal, kita masukkan saja posisi awal garis yang kita buat tadi.
  4755.  
  4756. ---------------------------------------------------------------------------------------
  4757. pos=[x,y,x,y]
  4758. ---------------------------------------------------------------------------------------
  4759.  
  4760. 4. Kita atur timer, jika timer kurang atau sama dengan 0, timer=delay, list pos ditambah 2 koordinat list pos terakhir, dan 2 koordinat baru (koordinat pertama layar paling kanan, koordinat kedua berfungsi sebagai naik turunnya grafik, kita pakai random.choice)
  4761.  
  4762. ---------------------------------------------------------------------------------------
  4763. rand=random.choice(range(10,ly[1]-20,20))
  4764. if timer<=0:
  4765. >>timer=delay
  4766. >>pos.append([pos[-1][2],pos[-1][3],x,rand])
  4767. ---------------------------------------------------------------------------------------
  4768.  
  4769. 5. Kemudian, jika timer lebih dari 0, timer dikurangi 1
  4770.  
  4771. ---------------------------------------------------------------------------------------
  4772. if timer>0:
  4773. >>timer-=1
  4774. ---------------------------------------------------------------------------------------
  4775.  
  4776. 6. Sekarang, kita loop list pos
  4777.  
  4778. ---------------------------------------------------------------------------------------
  4779. for i in range(len(pos)):
  4780. ---------------------------------------------------------------------------------------
  4781.  
  4782. 7. Kita atur pergerakannya, masih didalam identasi for, jangan lupa, hapus koordinat yang kurang dari 0 agar script tidak berat, barulah kita gambar .
  4783.  
  4784. Note:
  4785. Tanda > diganti menggunakan spasi.
  4786.  
  4787.  
  4788.  
  4789.  
  4790.  
  4791. ==========
  4792.  
  4793.  
  4794.  
  4795. 076.
  4796.  
  4797. "GET COORDINATE ARROUND CIRCLE (PYS60)"
  4798.  
  4799. Saya mau share cara membuat koordinat pada lingkaran menggunakan pys60...
  4800.  
  4801. Kali ini, kita akan menggabungkan sedikit matematika dengan pys60. Kita akan mencari koordinat koordinat yang ada pada sebuah lingkaran, yang dihasilkan dari sebuah titik pusat lingkaran dan jari jari tertentu.
  4802.  
  4803. 01. Kita buat dulu titik pusat lingkaran.
  4804.  
  4805. 02. Kita buat titik lingkaran dengan jari jari.
  4806.  
  4807. 03. Kita putar titik yang sudah kita buat tadi 360 derajat.
  4808.  
  4809. Kumpulan titik-titik itulah koordinatnya. Jadi, kita tinggal memasukkan koordinat-koordinat tersebut kedalam list.
  4810.  
  4811. Ini kodenya,
  4812.  
  4813. ---------------------------------------------------------------------------------------
  4814. x,y=80,80
  4815. ---------------------------------------------------------------------------------------
  4816. -Ini sebagai titik pusat lingkaran.
  4817.  
  4818. ---------------------------------------------------------------------------------------
  4819. r=10
  4820. ---------------------------------------------------------------------------------------
  4821. -Ini sebagai jari jari.
  4822.  
  4823. -Fungsi konversi ke radian
  4824. def radian(angle):return (float(angle)/
  4825.  
  4826. ---------------------------------------------------------------------------------------
  4827. 180.0)*math.pi
  4828. ---------------------------------------------------------------------------------------
  4829.  
  4830. -Rumus memutar
  4831. -Rad adalah hasil konversi ke radian
  4832.  
  4833. ---------------------------------------------------------------------------------------
  4834. rx=r*math.cos(rad)-r*math.sin(rad)
  4835. ry=r*math.sin(rad)+r*math.cos(rad)
  4836. ---------------------------------------------------------------------------------------
  4837.  
  4838. -Satu koordinat titik lingkaran adalah
  4839.  
  4840. ---------------------------------------------------------------------------------------
  4841. [x+rx,y+ry]
  4842. ---------------------------------------------------------------------------------------
  4843.  
  4844. Sekarang tinggal kita gabung dengan range(360) untuk mendapatkan koordinat 1 putaran lingkaran.
  4845.  
  4846. Ini kodenya
  4847.  
  4848. ---------------------------------------------------------------------------------------
  4849. import math
  4850. pi=math.pi
  4851. cos=math.cos
  4852. sin=math.sin
  4853.  
  4854. def radian(xx):
  4855. return (float(xx)/180.0)*pi
  4856.  
  4857. def get_circle_coord(x,y,r):
  4858. rad=[]
  4859. result=[]
  4860. sdt=range(360)
  4861. for i in xrange(len(sdt)):
  4862. rad.append(round(radian(sdt),2))
  4863. for oke in xrange(len(rad)):
  4864. rx=round(r*cos(rad[oke])-r*sin(rad[oke]),1)
  4865. ry=round(r*sin(rad[oke])+r*cos(rad[oke]),1)
  4866. result.append([x+rx,y+ry])
  4867. return result
  4868. ---------------------------------------------------------------------------------------
  4869.  
  4870. Untuk mencobanya, sekarang kita gambar titik-titik yang sudah kita kumpulkan dalam list tadi, kalau benar, maka titik-titik tadi akan membentuk lingkaran, kalau salah, tidak akan membentuk lingkaran,
  4871.  
  4872. Ini kodenya
  4873.  
  4874. ---------------------------------------------------------------------------------------
  4875. import graphics,e32,appuifw,math
  4876. from sysinfo import display_pixels as pixels
  4877.  
  4878. run=1
  4879. def quit():
  4880. global run
  4881. run=0
  4882.  
  4883. ly=pixels()
  4884. im=graphics.Image.new(ly)
  4885. ap=appuifw.app
  4886. ap.screen='full'
  4887. ap.exit_key_handler=quit
  4888. ap.body=c=appuifw.Canvas()
  4889.  
  4890. x,y,j=ly[0]/2,ly[1]/2,20
  4891. cos=math.cos
  4892. sin=math.sin
  4893. pi=math.pi
  4894.  
  4895. def radian(xx):
  4896. return (float(xx)/180.0)*pi
  4897.  
  4898. def get_circle_coord(x,y,r):
  4899. rad=[]
  4900. result=[]
  4901. sdt=range(360)
  4902. for i in xrange(len(sdt)):
  4903. rad.append(round(radian(sdt),2))
  4904. for oke in xrange(len(rad)):
  4905. rx=round(r*cos(rad[oke])-r*sin(rad[oke]),1)
  4906. ry=round(r*sin(rad[oke])+r*cos(rad[oke]),1)
  4907. result.append([x+rx,y+ry])
  4908. return result
  4909.  
  4910. res=get_circle_coord(x,y,j)
  4911.  
  4912. while run:
  4913. im.clear(0)
  4914. im.point((x,y),0xda0000)
  4915. for i in res:im.point(i,0xda)
  4916. c.blit(im)
  4917. e32.ao_sleep(0)
  4918. ---------------------------------------------------------------------------------------
  4919.  
  4920.  
  4921.  
  4922.  
  4923.  
  4924. ==========
  4925.  
  4926.  
  4927.  
  4928. 077.
  4929.  
  4930. "ADJUST TIMING SUBTITTLE WITH PYTHON"
  4931.  
  4932. Saya mau share cara mempercepat subtittle pada video...
  4933.  
  4934. Misal nih, pola jeda -4, -9, -13, -18, -22, -27, -31, -36, -40, -45
  4935.  
  4936. Kita buat 3 var berisi bilangan
  4937. start = 0
  4938. plus = 11,5
  4939. minus = 7
  4940. Karena subtitlenya cuma bisa bilangan bulat , maka kita pakai fungsi int()
  4941.  
  4942. Ini script dasarnya
  4943.  
  4944. ---------------------------------------------------------------------------------------
  4945. start = 0
  4946. plus = 11.5
  4947. minus = 7
  4948. for i in range(10):
  4949. >>start = start + plus
  4950. >>start = start - minus
  4951. >>print i + int(start)
  4952. ---------------------------------------------------------------------------------------
  4953.  
  4954. Memang sih buat apa ada plus minus, kan bisa aja cuma pakai plus.
  4955. Hasil eksperimen sih, kalau bilangan a dan b sama sama bulat, hasilnya memang sama dengan kelipatan. Sama kayak start + plus aja, tapi , jika kita ingin memasukkan bilangan desimal atau float, maka kurang efektif, jadi kita bikin plus sama minus. Begitu..
  4956.  
  4957. Dan ini script lengkapnya
  4958.  
  4959. ---------------------------------------------------------------------------------------
  4960. a=0
  4961. plus=11.5
  4962. minus=7
  4963. import time,re
  4964.  
  4965. file=file_sub_asal
  4966. result=file_sub_hasil
  4967. t=open(file).read()
  4968. d=re.findall('{(\d*)}{(\d*)}(.*)',t)
  4969. res_file=open(result,'w')
  4970.  
  4971. for i in d:
  4972. >>a=a+plus
  4973. >>a=a-minus
  4974. >>res_file.write('{%d}{%d}%s\r\n'%(int(i[0])-int(a),int(i[1])-int(a),i[2]))
  4975.  
  4976. res_file.close()
  4977. print 'ok'
  4978. ---------------------------------------------------------------------------------------
  4979.  
  4980. Note:
  4981. Tanda > diganti menggunakan spasi.
  4982.  
  4983.  
  4984.  
  4985.  
  4986.  
  4987. ==========
  4988.  
  4989.  
  4990.  
  4991. 078.
  4992.  
  4993. "MEMBUAT MENU GRID 3x3 (PYS60)"
  4994.  
  4995. Saya mau share cara membuat tampilan menu grid menjadi 3x3...
  4996.  
  4997. Biasanyakan menu cuma ada 1 kolom menurun, nah.. Kali ini kita belajar bikin yang gak seperti biasanya, yaitu 3x3.
  4998.  
  4999. 01. Kita buat dulu 9 fungsi. (pakai def menu0 sampai def menu8 aja biar gampang)
  5000.  
  5001. 02. Kita masukkan 9 fungsi tadi kedalam list, sebut saja list_func_menu. Jadinya kayak gini
  5002. ---------------------------------------------------------------------------------------
  5003. list_func_menu=[menu0,menu1,... menu8]
  5004. ---------------------------------------------------------------------------------------
  5005.  
  5006. 03. Kita buat variable name yang berfungsi mengatur posisi posisi x dan y menu dan kursor.
  5007.  
  5008. 04. Kita buat list didalam list, yang berisi integer urutan list_func_menu, jadinya gini
  5009.  
  5010. ---------------------------------------------------------------------------------------
  5011. menu=[[0,1,2],[3,4,5],[6,7,8]]
  5012. ---------------------------------------------------------------------------------------
  5013.  
  5014. Why? Ya karena kita mau buat 3x3 gridnya. Kalau 4x4 gimana? Ya tinggal buat aja
  5015.  
  5016. ---------------------------------------------------------------------------------------
  5017. menu=[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]
  5018. ---------------------------------------------------------------------------------------
  5019.  
  5020. Jadi, intinya jika 3x3 grid, maka kita buat 1 list berisi 3 sub list. Masing2 sub list, berisi 3 bilangan.
  5021.  
  5022. 05. Kita ingat, list dalam python dimulai dari angka 0.
  5023. --angka 0,3,6 adalah angka pertama list mendatar.
  5024. ---Jadi manggilnya
  5025.  
  5026. ---------------------------------------------------------------------------------------
  5027. menu[0][0], menu[0][1],menu[0][2]
  5028. ---------------------------------------------------------------------------------------
  5029.  
  5030. --sedang angka menurun pertama adalah 0,1,2
  5031. ---manggilnya
  5032.  
  5033. ---------------------------------------------------------------------------------------
  5034. menu[0][0],menu[1][0],menu[2][0].
  5035. ---------------------------------------------------------------------------------------
  5036.  
  5037. Kita masukkan keperulangan for
  5038.  
  5039. ---------------------------------------------------------------------------------------
  5040. >>for yy in range(len(menu)):
  5041.     for xx in range(len(menu[xx])):
  5042. ---------------------------------------------------------------------------------------
  5043.  
  5044. -yy akan menjadi list menurun
  5045. -xx akan menjadi list mendatar
  5046.  
  5047. Berikutnya, kita buat kotak dengan variable name berisi bilangan bulat 0, sebagai kursor. Misal kx,ky=0,0 Isi kx dan ky bisa 0 atau 1, yang jelas , tidak boleh lebih dari panjang tiap list menu dan sublistnya.
  5048.  
  5049. Jika sudah, kita gabungkan dengan fungsi module key kursor atas bawah kiri kanan, untuk menggerakkan kursor,dan tombol select, untuk memilih menu.
  5050.  
  5051. -Jika joystik geser kekanan, kursor bergerak kekanan, nilai kx ditambah 1.
  5052.  
  5053. -Jika joystik geser kekiri, kursor bergerak kekanan, nilai kx dikurangi 1.
  5054.  
  5055. -Jika joystik geser kebawah, kursor bergerak kekanan, nilai ky ditambah 1.
  5056.  
  5057. -Jika joystik geser keatas, kursor bergerak kekanan, nilai ky dikurangi 1.
  5058.  
  5059. -Jika tombol select dipencet, kita panggil nilai dalam menu, dengan cara menu[py][px], sekarang, kita gabungkan lagi dengan list fungsi yang sudah kita buat,
  5060.  
  5061. ---------------------------------------------------------------------------------------
  5062. list_func_menu[menu[py][px]].
  5063. ---------------------------------------------------------------------------------------
  5064.  
  5065. Untuk mengeksekusi tinggal kasih tanda() diakhir list fungsi yang dipanggil tadi, sehingga menjadi list_func_menu[menu[py][px]]()
  5066.  
  5067. Note:
  5068. Tanda > diganti menggunakan spasi.
  5069.  
  5070.  
  5071.  
  5072.  
  5073.  
  5074. ==========
  5075.  
  5076.  
  5077.  
  5078. 079.
  5079.  
  5080. "MEMBUAT KALKULATOR SEDERHANA"
  5081.  
  5082. Saya mau share script python sederhana yang berfungsi sebagai kalkulator...
  5083.  
  5084. Ini skriptnya
  5085.  
  5086. -Import modul yang diperlukan,
  5087.  
  5088. ---------------------------------------------------------------------------------------
  5089. import appuifw
  5090. ---------------------------------------------------------------------------------------
  5091.  
  5092. -Membuat popup query dialog antara user dan python
  5093.  
  5094. ---------------------------------------------------------------------------------------
  5095. a=appuifw.query(u'angka pertama','number')
  5096. ---------------------------------------------------------------------------------------
  5097.  
  5098. -Membuat popup perintah
  5099.  
  5100. ---------------------------------------------------------------------------------------
  5101. L=[u'tambah +',u'kurang -',u'kali *',u'bagi /']
  5102. b=appuifw.popup_menu(L,u'pilih:')
  5103. ---------------------------------------------------------------------------------------
  5104.  
  5105. -Membuat popup query ke 2
  5106.  
  5107. ---------------------------------------------------------------------------------------
  5108. c=appuifw.query(u'angka kedua','number')
  5109. ---------------------------------------------------------------------------------------
  5110.  
  5111. -Nah,sekarang buat fungsi kalkulasinya:
  5112.  
  5113. ---------------------------------------------------------------------------------------
  5114. if b==0:
  5115. >>print a+c
  5116. if b==1:
  5117. >>print ac
  5118. if b==2:
  5119. >>print a*c
  5120. if b==3:
  5121. >>print a/c
  5122. ---------------------------------------------------------------------------------------
  5123.  
  5124. Note:
  5125. Tanda > diganti menggunakan spasi.
  5126.  
  5127.  
  5128.  
  5129.  
  5130.  
  5131. ==========
  5132.  
  5133.  
  5134.  
  5135. 080.
  5136.  
  5137. "MEMBUAT TEKS BERJALAN DENGAN BACKGROUND SUARA"
  5138.  
  5139. Saya mau share cara membuat teks berjalan dengan baground suara...
  5140.  
  5141. Nah ini scriptnya:
  5142.  
  5143. ---------------------------------------------------------------------------------------
  5144. import appuifw as fw
  5145. import audio as a
  5146. import e32 as e
  5147.  
  5148. lagu=a.Sound.open('e:\\dds.mp3' ) ; lagu.play()
  5149.  
  5150. fw.app.screen='large'
  5151. round=fw.Text()
  5152. round.style=fw.HIGHLIGHT_ROUNDED
  5153. round.color=0xff0000
  5154.  
  5155. text=u'Masukan teks kamu disini mastah'
  5156.  
  5157. for a in range(len(text ) ) :
  5158. >>round.add(text[a])
  5159. >>e.ao_sleep(0.2)
  5160.  
  5161. e.Ao_lock().wait()
  5162. ---------------------------------------------------------------------------------------
  5163.  
  5164. Note:
  5165. Tanda > diganti menggunakan spasi.
  5166.  
  5167.  
  5168.  
  5169.  
  5170.  
  5171. ==========
  5172.  
  5173.  
  5174.  
  5175. 081.
  5176.  
  5177. "MEMBUAT POPUP ALA CEK PULSA"
  5178.  
  5179. Saya mau share cara membuat popup yang sama persis dengan popup saat cek pulsa kartu 3...
  5180.  
  5181. Kalian pasti tau kan itu popup yang tampil kalo kita cek pulsa
  5182.  
  5183. Dengan python kita dapat memanipulasinya dengan mudah.
  5184.  
  5185. Sekarang kita manipulasi jumlah pulsa,biar temen2 kita bilang 'wow'
  5186.  
  5187. Misal cek pulsa kartu 3:
  5188.  
  5189. ---------------------------------------------------------------------------------------
  5190. import globalui
  5191. import e32
  5192.  
  5193. def start():
  5194. >>e32.start_exe('z:\\system\\programs\\apprun.Exe','z:\\system\\apps\\phone\\phone.app')
  5195. start()
  5196.  
  5197. hewan=['Main Menu','Bal: Rp 1.999.000','1. Informasi Pulsa','2. Isi Ulang','3. Program&Promosi','4. Cek Kuota']
  5198.  
  5199. ask=globalui.global_msg_query(unicode('\n'.join(hewan)),u'Pesan')
  5200. if ask==1:
  5201. >>for i in hewan:
  5202.     print i
  5203. ---------------------------------------------------------------------------------------
  5204.  
  5205. Note:
  5206. Tanda > diganti menggunakan spasi.
  5207.  
  5208.  
  5209.  
  5210.  
  5211.  
  5212. ==========
  5213.  
  5214.  
  5215.  
  5216. 082.
  5217.  
  5218. "MENGIRIM SMS ke BANYAK NOMOR"
  5219.  
  5220. Saya mau share script python yang fungsinya untuk mengirim pesan kebeberapa nomor sekaligus...
  5221.  
  5222. Sebelumnya harus install dulu python,dan aplikasi ipro7 buat nulis dan eksekusiya.
  5223.  
  5224. Langsung Saja:
  5225.  
  5226. Misal kita mau mengirim sms ke 5 nomer teman kamu,
  5227.  
  5228. -Pertama import module yang diperlukan:
  5229.  
  5230. ---------------------------------------------------------------------------------------
  5231. import appuifw
  5232. import messaging
  5233. ---------------------------------------------------------------------------------------
  5234.  
  5235. -Menetapkan identitas pribadi kita:
  5236.  
  5237. ---------------------------------------------------------------------------------------
  5238. data=appuifw.query(u"Masukan Nama Kamu","text")
  5239. ---------------------------------------------------------------------------------------
  5240.  
  5241. -Menetapkan nomer yang akan kita kirimi sms
  5242.  
  5243. ---------------------------------------------------------------------------------------
  5244. nomor1="0812xxx"
  5245. nomor2="0813xxx"
  5246. nomor3="0821xxx"
  5247. nomor4="0852xxx"
  5248. nomor5="0853xxx"
  5249. ---------------------------------------------------------------------------------------
  5250.  
  5251. -Menetapkan isi sms:
  5252.  
  5253. ---------------------------------------------------------------------------------------
  5254. txt=">Isi teks kamu disini,< Dari:"+data
  5255. ---------------------------------------------------------------------------------------
  5256.  
  5257. -Menetapkan system pengiriman:
  5258.  
  5259. ---------------------------------------------------------------------------------------
  5260. if appuifw.query(u"Kirim Pesan Ke Nomor 5 Teman Kamu","query")==True:
  5261. messaging.sms_send(nomor1,txt)
  5262. messaging.sms_send(nomor2,txt)
  5263. messaging.sms_send(nomor3,txt)
  5264. messaging.sms_send(nomor4,txt)
  5265. messaging.sms_send(nomor5,txt)
  5266. ---------------------------------------------------------------------------------------
  5267.  
  5268. -Membuat notifikasi jika sms sukses:
  5269.  
  5270. ---------------------------------------------------------------------------------------
  5271. appuifw.note(u'Pesan Telah Dikirim','info')
  5272. ---------------------------------------------------------------------------------------
  5273.  
  5274. -Membuat notifikasi jika sms gagal:
  5275.  
  5276. ---------------------------------------------------------------------------------------
  5277. else:
  5278. appuifw.note(u'Pesan Gagal Dikirim','info')
  5279. ---------------------------------------------------------------------------------------
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285. ==========
  5286.  
  5287.  
  5288.  
  5289. 083.
  5290.  
  5291. "FUNGSI MODUL APPUIFW"
  5292.  
  5293. Saya mau share tentang fungsi modul appuifw dan contohnya...
  5294.  
  5295. Modul berguna untuk membentuk body atau user interface aplikasi
  5296.  
  5297. -import appuifw berguna untuk memanggil modul.
  5298.  
  5299. ---------------------------------------------------------------------------------------
  5300. import appuifw
  5301.  
  5302. def ru(x):
  5303.     return unicode(x, "utf8")
  5304.  
  5305. text_1 = "Tulis teks yang ingin ditunjukan. . !"
  5306. ---------------------------------------------------------------------------------------
  5307.  
  5308. -Fungsi pertama
  5309. Note:
  5310. Digunakan untuk memberi peringatan.
  5311.  
  5312. ---------------------------------------------------------------------------------------
  5313. print "Fungsi 1\n\n"
  5314.  
  5315. appuifw.note(ru(text_1), "info")
  5316. appuifw.note(ru(text_1), "conf")
  5317. appuifw.note(ru(text_1), "error")
  5318. ---------------------------------------------------------------------------------------
  5319.  
  5320. -Fungsi Kedua
  5321. Query: digunakan untuk bertanya
  5322.  
  5323. ---------------------------------------------------------------------------------------
  5324. print "Fungsi 2\n\n"
  5325.  
  5326. text_2 = "Tulis pertanyaan disini:"
  5327.  
  5328. appuifw.query(ru(text_2), "query")
  5329. appuifw.query(ru(text_2), "text")
  5330. appuifw.query(ru(text_2), "code")
  5331. appuifw.query(ru(text_2), "number")
  5332. appuifw.query(ru(text_2), "time")
  5333. appuifw.query(ru(text_2), "date")
  5334. appuifw.query(ru(text_2), "float")
  5335. ---------------------------------------------------------------------------------------
  5336.  
  5337. -Kita dapat mengabungkan fungsi-fungsi diatas
  5338.  
  5339. Contoh dibawah ini adalah contoh untuk mendengar suara audio.say
  5340.  
  5341. ---------------------------------------------------------------------------------------
  5342. print "Fungsi 3\n\n"
  5343. ---------------------------------------------------------------------------------------
  5344.  
  5345. -import audio berguna untuk memanggil modul audio
  5346.  
  5347. ---------------------------------------------------------------------------------------
  5348. katakan = appuifw.query(ru("Katakan Apa:"), "text")
  5349. if not katakan == None:
  5350.     tanyakan = appuifw.query(ru("Apakah anda ingin dengar apa yang dikatakan?"), "query")
  5351.     if tanyakan == True:
  5352.         audio.say(katakan)
  5353.         appuifw.note(katakan, "info")
  5354.     else:
  5355.         appuifw.note(katakan, "error")
  5356.  
  5357. print "Selesai"
  5358. ---------------------------------------------------------------------------------------
  5359.  
  5360. -import messaging berguna untuk memanggil modul pengirim sms
  5361.  
  5362. -Jumlah sms yang ingin dikirim
  5363.  
  5364. ---------------------------------------------------------------------------------------
  5365. sms_amount = 5
  5366. ---------------------------------------------------------------------------------------
  5367.  
  5368. -Sebagai penghitung
  5369.  
  5370. ---------------------------------------------------------------------------------------
  5371. counter = 0
  5372. ---------------------------------------------------------------------------------------
  5373.  
  5374. -Nomor target yang ingin dikirimi SMS
  5375.  
  5376. ---------------------------------------------------------------------------------------
  5377. target_number = "12345"
  5378. ---------------------------------------------------------------------------------------
  5379.  
  5380. -Isi pesan yang ingin dikirim
  5381.  
  5382. ---------------------------------------------------------------------------------------
  5383. msg_content = u"isi pesan"
  5384.  
  5385. while counter < sms_amount:
  5386.     messaging.sms_send(target_number, msg_content)
  5387.     print "mengirim sms ke ", counter, " kepada ", target_number
  5388.     counter += 1
  5389.  
  5390. print " selesai...."
  5391. ---------------------------------------------------------------------------------------
  5392.  
  5393.  
  5394. Note:
  5395. Tanda > diganti menggunakan spasi.
  5396.  
  5397.  
  5398.  
  5399.  
  5400. ==========
  5401.  
  5402.  
  5403.  
  5404. 084.
  5405.  
  5406. "SIMPLE SCANNING APPLICATION"
  5407.  
  5408. Saya mau share sebuah script untuk scanning directory...
  5409.  
  5410. Script ini harus diletakan di folder python yang ada pada drive C atau E
  5411.  
  5412. Kemudian masuk python scriptshell atau PED dan run script ini
  5413.  
  5414. Hanya menggunakan 3 modul
  5415.  
  5416. ---------------------------------------------------------------------------------------
  5417. import appuifw
  5418. import os, e32
  5419.  
  5420. def ru(x): return unicode(x, "utf8")
  5421. app_lock = e32.Ao_lock()
  5422. state, running = None, False
  5423. ---------------------------------------------------------------------------------------
  5424.  
  5425. -Membuat judul aplikasi
  5426.  
  5427. ---------------------------------------------------------------------------------------
  5428. appuifw.app.title = ru("Simple Scanner")
  5429. ---------------------------------------------------------------------------------------
  5430.  
  5431. -Membuat GUI atau body aplikasi
  5432.  
  5433. ---------------------------------------------------------------------------------------
  5434. editor = appuifw.Text()
  5435. appuifw.app.body = editor
  5436.  
  5437. editor.font = ("legend", 12)
  5438. editor.color = 0x000000
  5439. editor.add(ru("Simple Scanner"))
  5440. editor.add(ru("\nHanya untuk Pengembangan dan Contoh\n\n\n\n\n"))
  5441. editor.add(ru("Author: Pythonism Symbian\nE-mail: joe4rt0n@gmail.com\n"))
  5442. editor.add(ru("7777772e6172746f6e2d70726976617465686f6d652e636f2e6363".decode("hex_codec")))
  5443. editor.add(ru("\n\n\nPilih Options & Scan, lalu pilih daftar drive"))
  5444.  
  5445. def exit():
  5446.     global running, state
  5447.     if running == True:
  5448.         query = appuifw.query(ru("Apakah Anda ingin Stop Scanning?"), "query")
  5449.         if query == True:
  5450.             running, state = False, False
  5451.     else:
  5452.         query = appuifw.query(ru("Apakah Anda ingin keluar?"), "query")
  5453.         if query == True:
  5454.             state = False
  5455.             app_lock.signal()
  5456.  
  5457.  
  5458. audiolist = [".mp3", ".wav", ".aac", ".amr"]
  5459. filesis = [".sis", ".sisx"]
  5460. images = [".png", ".jpg", ".jpeg", ".mbm"]
  5461. audiocounter, siscounter = 0, 0
  5462. imagecounter = 0
  5463.  
  5464. def scanning_now(drive):
  5465. >>global audiocounter, siscounter, imagecounter, state
  5466. >>if state == None:
  5467. >>>try:
  5468.     if os.path.isdir(drive):
  5469.         drivelist = os.listdir(drive)
  5470.         for i in drivelist:
  5471.         >>if state == None:
  5472.             e32.ao_yield()
  5473.             if os.path.isdir(drive + i):
  5474.                 if (not i.endswith(os.sep)):
  5475.                     i = (i + os.sep)
  5476.             editor.clear()
  5477.             editor.add(ru("Simple Scanner\n"))
  5478.             editor.add(ru("\n\nAudio File: %s\n")%(audiocounter))
  5479.             editor.add(ru("Image File: %s\n")%(imagecounter))
  5480.             editor.add(ru("Instalation File: %s\n\n\n\n")%(siscounter))
  5481.             editor.add(ru("Scanning:\n"))
  5482.             editor.add(drive + ru(i))
  5483.             scanning_now(drive + i)
  5484.             ext = os.path.splitext(drive + i)[1]
  5485.             if (ext in audiolist):
  5486.                 audiocounter += 1
  5487.             elif (ext in filesis):
  5488.                 siscounter += 1
  5489.             elif (ext in images):
  5490.                 imagecounter += 1
  5491. >>>except: pass
  5492.  
  5493. def scan_drive():
  5494.     global audiocounter, siscounter, imagecounter, state, running
  5495.     audiocounter, siscounter, imagecounter = 0, 0, 0; running, state = True, None
  5496.     editor.clear()
  5497.     editor.add(ru("Siap Melakukan Scanning. . .\n"))
  5498.     editor.add(ru("Pilih Drive. . .\n"))
  5499.     drive = e32.drive_list()
  5500.     get = appuifw.popup_menu(drive, ru("Pilihan:"))
  5501.     editor.add(ru("Melakukan Scanning pada drive %s\\\n")%(drive[get]))
  5502.     scanning_now(drive[get] + os.sep)
  5503.  
  5504. def about():
  5505.     appuifw.note(ru("Belajar dan Share aplikasi python buatanmu di www.arton-privatehome.co.cc\nJoe Arton"), "info")
  5506. ---------------------------------------------------------------------------------------
  5507.  
  5508. -Membuat fungsi tombol menu & exit
  5509.  
  5510. ---------------------------------------------------------------------------------------
  5511. appuifw.app.menu = [(ru("Scan"), scan_drive), (ru("About"), about)]
  5512. appuifw.app.exit_key_handler = exit
  5513.  
  5514.  
  5515. app_lock.wait()
  5516. ---------------------------------------------------------------------------------------
  5517.  
  5518. Note:
  5519. Tanda > diganti menggunakan spasi.
  5520.  
  5521.  
  5522.  
  5523.  
  5524.  
  5525. ==========
  5526.  
  5527.  
  5528.  
  5529. 085.
  5530.  
  5531. "APLIKASI TEKS EDITOR"
  5532.  
  5533. Saya mau share sebuah script untuk mengedit sebuah teks...
  5534.  
  5535. -Memangil modul aplikasi
  5536. -Pythonism symbianism
  5537.  
  5538. ---------------------------------------------------------------------------------------
  5539. import appuifw2
  5540. import e32
  5541. ---------------------------------------------------------------------------------------
  5542.  
  5543. Fungsi ini digunakan untuk membuka gerbang fungsi dari aplikasi, hampir semua aplikasi dimulai dengan fungsi ini
  5544.  
  5545. ---------------------------------------------------------------------------------------
  5546. app_lock = e32.Ao_lock()
  5547. ---------------------------------------------------------------------------------------
  5548.  
  5549. Memberikan fungsi konversi, yaitu perubahan string agar menjadi unicode sehingga dapat ditampilkan pada GUI
  5550.  
  5551. ---------------------------------------------------------------------------------------
  5552. def ru(x):
  5553.     return unicode(x, "utf8")
  5554. ---------------------------------------------------------------------------------------
  5555.  
  5556. Membuat fungsi body aplikasi atau aplikasi utama, yaitu body text editor
  5557.  
  5558. Untuk menggunakan fungsi ini, kita akan menggunakan modul appuifw
  5559.  
  5560. ---------------------------------------------------------------------------------------
  5561. body = appuifw2.Text(skinned=True)
  5562. appuifw2.app.body = body
  5563. ---------------------------------------------------------------------------------------
  5564.  
  5565. Membuat fungsi keluar aplikasi dengan cara membuka gerbang diatas
  5566.  
  5567. ---------------------------------------------------------------------------------------
  5568. def keluar():
  5569.     app_lock.signal()
  5570. ---------------------------------------------------------------------------------------
  5571.  
  5572. Meletakan fungsi tombol keluar, pada tombol exit, seperti gambar diatas
  5573.  
  5574. ---------------------------------------------------------------------------------------
  5575. appuifw2.app.exit_key_handler = keluar
  5576. ---------------------------------------------------------------------------------------
  5577.  
  5578. Memberikan nama pada tombol keluar
  5579.  
  5580. ---------------------------------------------------------------------------------------
  5581. appuifw2.app.exit_key_text = ru("Keluar")
  5582. ---------------------------------------------------------------------------------------
  5583.  
  5584. Memberikan nama pada tombol Menu
  5585.  
  5586. ---------------------------------------------------------------------------------------
  5587. appuifw2.app.menu_key_text = ru("Menu")
  5588. ---------------------------------------------------------------------------------------
  5589.  
  5590. Membuat menu dan submenu
  5591. Sebelumnya, kita harus membuat fungsi, berikut ini fungsi sederhana, yaitu menampilkan nama web ini
  5592.  
  5593. ---------------------------------------------------------------------------------------
  5594. def tampilkan_web():
  5595.     appuifw.note(ru("www.arton-privatehome.co.cc"), "info")
  5596.  
  5597. appuifw2.app.menu = [
  5598.     (ru("Menu A"), tampilkan_web),
  5599.     (ru("Menu B"), tampilkan_web),
  5600.     (ru("Menu C"), (
  5601.         (ru("Sub Menu 1") ,tampilkan_web),
  5602.         (ru("Sub Menu 1") ,tampilkan_web))),
  5603.     (ru("Menu D"), tampilkan_web)]
  5604. ---------------------------------------------------------------------------------------
  5605.  
  5606. -Menutup fungsi aplikasi
  5607.  
  5608. ---------------------------------------------------------------------------------------
  5609. app_lock.wait()
  5610. ---------------------------------------------------------------------------------------
  5611.  
  5612. Note:
  5613. Tanda > diganti menggunakan spasi.
  5614.  
  5615.  
  5616.  
  5617.  
  5618.  
  5619. ==========
  5620.  
  5621.  
  5622.  
  5623. 086.
  5624.  
  5625. "CAMERA MOTION"
  5626.  
  5627. Saya mau share sebuah script camera motion...
  5628.  
  5629. ---------------------------------------------------------------------------------------
  5630. import appuifw2 as aw, e32, camera, audio
  5631. import socket as st
  5632. from graphics import*
  5633.  
  5634. sock, debug = None, -1
  5635. address, channel=st.bt_obex_discover()
  5636.  
  5637. def bt_connect():
  5638.     global sock
  5639.     sock = st.socket(st.AF_BT,st.SOCK_STREAM)
  5640.     target = (address, 3)
  5641.     aw.note(ru("Connecting to ") + ru(str(target)), "info")
  5642.     try:
  5643.         sock.connect(target)
  5644.         sock.send("AT+GMM\r")
  5645.         aw.note(ru("\n" + sock.recv(1024)))
  5646.     except: aw.note(ru("Failed To Connect"))
  5647. bt_connect()
  5648.  
  5649. action, control_light = False, 0
  5650. x, y, sensLeft, sensRight = 240, 235, 120, 120
  5651. sensUp, sensDown, sensCenter=120, 120, 120
  5652.  
  5653. actionUp, actionDown, actionLeft, actionRight, actionCenter = False, False, False, False, False scanPixel = Image.new((x, y))
  5654.  
  5655. def redraw(rect):
  5656.     scanPixel.rectangle([(0, 0),(x, y)], 0x000000, 0xff0000)
  5657.     scanPixel.text((28, 50), u"Camera Motion", 0x000000, font=("normal", 28))
  5658.     scanPixel.line([(20,60),(220,60)], 0x0000, 2)
  5659.     scanPixel.line([(0, 65), (240, 65)], 0x0000, 2)
  5660.     scanPixel.line([(0, 70), (240, 70)], 0x0000, 2)
  5661.     scanPixel.text((20, 100), u"Press Options to Active", 0x000000, "normal")
  5662.     scanPixel.text((50, 120), u"Author: Joe Arton", 0x000000, "legend")
  5663.     scanPixel.text((30, 135), u"Release: November 2010", 0x000000, "legend")
  5664.     scanPixel.text((3, 150), u"Camera Application for Detecting Motion", 0x000000, u"Latinplain")
  5665.     canvas.blit(scanPixel)
  5666.  
  5667. lock = e32.Ao_lock()
  5668. canvas = aw.Canvas(redraw_callback = redraw, event_callback = None)
  5669. aw.app.body = canvas
  5670.  
  5671. def actionForUp():
  5672.     global actionUp
  5673.     if actionUp == 0:
  5674.         saySomething()
  5675.     elif actionUp == 1:
  5676.         playSound()
  5677.     elif actionUp == 2:
  5678.         dialNumber()
  5679.     elif actionUp == 3:
  5680.         sendMessage()
  5681.  
  5682. def actionForDown():
  5683.     global actionDown
  5684.     if actionDown == 0:
  5685.         saySomething()
  5686.     elif actionDown == 1:
  5687.         playSound()
  5688.     elif actionDown == 2:
  5689.         dialNumber()
  5690.     elif actionDown == 3:
  5691.         sendMessage()
  5692.  
  5693. def actionForCenter():
  5694.     global actionCenter
  5695.     if actionCenter == 0:
  5696.         saySomething()
  5697.     elif actionCenter == 1:
  5698.         playSound()
  5699.     elif actionCenter == 2:
  5700.         dialNumber()
  5701.     elif actionCenter == 3:
  5702.         sendMessage()
  5703.  
  5704. def actionForLeft():
  5705.     global actionLeft
  5706.     if actionLeft == 0:
  5707.         saySomething()
  5708.     elif actionLeft == 1:
  5709.         playSound()
  5710.     elif actionLeft == 2:
  5711.         dialNumber()
  5712.     elif actionLeft == 3:
  5713.         sendMessage()
  5714.  
  5715. def actionForRight():
  5716.     global actionRight
  5717.     if actionRight == 0:
  5718.         saySomething()
  5719.     elif actionRight == 1:
  5720.         playSound()
  5721.     elif actionRight == 2:
  5722.         dialNumber()
  5723.     elif actionRight == 3:
  5724.         sendMessage()
  5725.  
  5726. def makeShading(im):
  5727.     im.rectangle([(4,2),(196,12)],0xff0000)
  5728.     im.rectangle([(4,138),(196,148)],0xff0000)
  5729.     im.rectangle([(4,14),(14,136)],0xff0000)
  5730.     im.rectangle([(186,14),(196,136)],0xff0000)
  5731.     im.rectangle([(60,50),(140,100)],0xff0000)
  5732.  
  5733. def upPixel(im):
  5734.     global sensUp, action, actionForUp
  5735.     up = 0
  5736.     x = im.getpixel([(5,3),(197, 13)])[0]
  5737.     up = up + x[0] +x [1] + x[2]
  5738.     scanPixel.text((0, 185), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
  5739.     scanPixel.text((0, 195), u"Sensitivity: %s"%(up), 0x000000, font=("legend", 10))
  5740.     im.rectangle([(6, 4),(250-up, 10)],0xff0000, 0xff0000)
  5741.     if action =="activeUp" or action == "All":
  5742.         if up < sensUp:
  5743.             actionForUp()
  5744.  
  5745. def downPixel(im):
  5746.     global sensDown, action
  5747.     down = 0
  5748.     x = im.getpixel([(5,139),(197, 149)])[0]
  5749.     down = down + x[0] +x [1] + x[2]
  5750.     scanPixel.text((0, 220), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
  5751.     scanPixel.text((0, 230), u"Sensitivity: %s"%(down), 0x000000, font=("legend", 10))
  5752.     im.rectangle([(6,140),(250-down,146)], 0xff0000, 0xff0000)
  5753.     if action =="activeDown" or action == "All":
  5754.         if down < sensDown:
  5755.             actionForDown()
  5756.  
  5757. def leftPixel(im):
  5758.     global sensLeft, action
  5759.     left = 0
  5760.     x = im.getpixel([(5, 15),(15, 137)])[0]
  5761.     left = left+x[0]+x[1]+x[2]
  5762.     scanPixel.text((160, 185), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
  5763.     scanPixel.text((160, 195), u"Sensitivity: %s"%(left), 0x000000, font=("legend", 10))
  5764.     im.rectangle([(6,16),(12, 250-left)],0xff0000, 0xff0000)
  5765.     if action =="activeLeft" or action == "All":
  5766.         if left < sensLeft:
  5767.             actionForLeft()
  5768.  
  5769. def rightPixel(im):
  5770.     global sensRight, action
  5771.     right = 0
  5772.     x = im.getpixel([(187, 15),(197, 137)])[0]
  5773.     right = right+x[0]+x[1]+x[2]
  5774.     scanPixel.text((160, 220), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
  5775.     scanPixel.text((160, 230), u"Sensitivity: %s"%(right), 0x000000, font=("legend", 10))
  5776.     im.rectangle([(188, 16),(194, 250-right)],0xff0000, 0xff0000)
  5777.     if action =="activeRight" or action == "All":
  5778.         if right < sensRight:
  5779.             actionForRight()
  5780.  
  5781. def centerPixel(im):
  5782.     global sensCenter, action
  5783.     center = 0
  5784.     x = im.getpixel([(61, 51),(141, 101)])[0]
  5785.     center = center+x[0]+x[1]+x[2]
  5786.     scanPixel.text((80, 208), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
  5787.     scanPixel.text((80, 218), u"Sensitivity: %s"%(center), 0x000000, font=("legend", 10))
  5788.     if action =="activeCenter" or action == "All":
  5789.         if center < sensCenter:
  5790.             im.rectangle([(62,52),(138,98)],0xff0000,0xff0000)
  5791.             actionForCenter()
  5792.  
  5793. def gettingPixel(im):
  5794.     makeShading(im)
  5795.     upPixel(im)
  5796.     downPixel(im)
  5797.     leftPixel(im)
  5798.     rightPixel(im)
  5799.     centerPixel(im)
  5800.  
  5801. def showSensitivity(im):
  5802.     global sensUp, sensDown, sensRight
  5803.     global sensCenter, sensLeft
  5804.     scanPixel.text((105, 12), unicode(sensUp), 0x000000, font = ("legend", 11))
  5805.     scanPixel.text((105, 175), unicode(sensDown), 0x000000, font=("legend", 11))
  5806.     scanPixel.text((0, 90), unicode(sensLeft), 0x000000, font=("legend", 11))
  5807.     scanPixel.text((220, 90), unicode(sensRight), 0x000000, font=("legend", 11))
  5808.     im.text((90, 80), unicode(sensCenter), 0xffffff, font=("legend", 10))
  5809.  
  5810. def showPixel(im):
  5811.     scanPixel.text((20, 175), u"Top", 0x000000, font = ("legend", 12))
  5812.     scanPixel.text((15, 209), u"Down", 0x000000, font = ("legend", 11))
  5813.     scanPixel.text((100, 195), u"Center", 0x000000, font = ("legend", 11))
  5814.     scanPixel.text((180, 175), u"Left", 0x000000, font = ("legend", 11))
  5815.     scanPixel.text((180, 209), u"Right", 0x000000, font = ("legend", 11))
  5816.     gettingPixel(im)
  5817.     showSensitivity(im)
  5818.  
  5819. def cPixel(im):
  5820.     global control_light
  5821.     if control_light == 0:
  5822.         scanPixel.rectangle([(0, 0),(x, y)], 0x000000, 0xff0000)
  5823.         showPixel(im)
  5824.     scanPixel.blit(im, target=(20, 13))
  5825.     canvas.blit(scanPixel)
  5826.  
  5827. saying = u"Motion Detected"
  5828. soundPath = "e:\\Sounds\\digital\\"
  5829. numberPhone = u"123"
  5830.  
  5831. def sendMessage():
  5832.     global numberPhone
  5833.     import messaging
  5834.     messaging.sms_send(numberPhone, u"Detected")
  5835.  
  5836. def setSendNumber():
  5837.     global numberPhone
  5838.     query = aw.query(u"Phone Number:","text", numberPhone)
  5839.     if not query == None:
  5840.         if aw.query(u"Number is %s. ?"%(query), "query") == True:
  5841.             numberPhone = query
  5842.         else: pass
  5843.     else: pass
  5844.  
  5845. def setDialNumber():
  5846.     global numberPhone
  5847.     query = aw.query(u"Phone Number:","text", numberPhone)
  5848.     if not query == None:
  5849.         if aw.query(u"Number is %s. ?"%(query), "query") == True:
  5850.             numberPhone = query
  5851.         else: pass
  5852.     else: pass
  5853.  
  5854. def dialNumber():
  5855.     global numberPhone, sock
  5856.     try:
  5857.         sock.send("audio.say(unicode(123))")
  5858.     except:
  5859.         try:
  5860.             sock.send("keypress.simulate_key(EKeySelect, EScancodeSelect)")
  5861.         except:
  5862.             import audio
  5863.             alert = audio.Sound.open("e:\\alert.aac")
  5864.             while alert.state() == 2:
  5865.                 e32.ao_sleep(0.1)
  5866.             alert.close()
  5867.  
  5868. def setDialNumber():
  5869.     global numberPhone
  5870.     query = aw.query(u"Phone Number:","text", numberPhone)
  5871.     if not query == None:
  5872.         if aw.query(u"Number is %s. ?"%(query), "query") == True:
  5873.             numberPhone = query
  5874.         else: pass
  5875.     else: pass
  5876.  
  5877. def playSound():
  5878.     global soundPath
  5879.     alert = audio.Sound.open(soundPath)
  5880.     alert.play()
  5881.     while alert.state()==2: # playing
  5882.         e32.ao_sleep(0.1)
  5883.     alert.close()
  5884.  
  5885. def setPlaySound():
  5886.     global soundPath
  5887.     u = lambda x: x.decode("utf8")
  5888.     songs = map(u, os.listdir(soundPath))
  5889.     selection = aw.selection_list(songs, 1)
  5890.     if not selection == None:
  5891.         if aw.query(u"Set %s as Sound?"%(selection), "query") == True:
  5892.             soundPath = soundPath + songs[selection]
  5893.         else: pass
  5894.     else: pass
  5895.  
  5896. def saySomething():
  5897.     global saying
  5898.     try: audio.say(saying)
  5899.     except: aw.note(u"Failed", "error")
  5900.  
  5901. def setSaySomething():
  5902.     global saying
  5903.     query=aw.query(u"Saying:","text",saying)
  5904.     if not query == None:
  5905.         if aw.query(u"Saying %s"%(query), "query") == True:
  5906.             saying = query
  5907.         else: pass
  5908.  
  5909. def allAction():
  5910.     global actionUp, actionDown, actionRight
  5911.     global actionLeft, actionCenter
  5912.     actions = [u"SaySomething", u"PlaySound", u"DialNumber", u"SendMessage"]
  5913.     select = aw.selection_list(actions, 1)
  5914.     actionUp, actionDown, actionRight, actionLeft, actionCenter = select, select, select, select, select
  5915.  
  5916. def setAction():
  5917. >>global action
  5918. >>asking = aw.popup_menu([u"Set Action for All", u"Set Action for Corner"])
  5919. >>if asking == 0:
  5920.     >>if aw.query(u"Set Action for All. . ?", "query") == True:
  5921.         >>allAction()
  5922.         >>action = "All"
  5923.     >>else: action = False
  5924. >>elif asking == 1:
  5925.     >>setActionCorner()
  5926.  
  5927. def selectAction(popup):
  5928.     global actionUp, actionDown, actionRight
  5929.     global actionLeft, actionCenter
  5930.     actions = [u"SaySomething", u"PlaySound", u"DialNumber", u"SendMessage"]
  5931.     select = aw.selection_list(actions, 1)
  5932.     if select == 0:
  5933.         setSaySomething()
  5934.     elif select == 1:
  5935.         setPlaySound()
  5936.     elif select == 2:
  5937.         setDialNumber()
  5938.     elif select == 3:
  5939.         setSendMessage()
  5940.     if popup == 0 :
  5941.         actionUp = select
  5942.     elif popup == 1 :
  5943.         actionDown = select
  5944.     elif popup == 2 :
  5945.         actionCenter = select
  5946.     elif popup == 3 :
  5947.         actionLeft = select
  5948.     elif popup == 4 :
  5949.         actionRight = select
  5950.     aw.note(u"Sukses")
  5951.  
  5952. def setActionCorner():
  5953.     global action
  5954.     popup = aw.popup_menu([u"Top", u"Bottom", u"Center", u"Left", u"Right"], u"Corner Type:")
  5955.     if not popup == None:
  5956.     >>if popup == 0:
  5957.         if aw.query(u"Set Action for Top. . ?", "query") == True:
  5958.             action = "activeUp"
  5959.             selectAction(popup)
  5960.         else: action = False
  5961.     >>elif popup == 1:
  5962.         if aw.query(u"Set Action for Bottom. . ?", "query") == True:
  5963.             action = "activeDown"
  5964.             selectAction(popup)
  5965.         else: action = False
  5966.     >>elif popup == 2:
  5967.         if aw.query(u"Set Action for Center. . ?", "query") == True:
  5968.             action = "activeCenter"
  5969.             selectAction(popup)
  5970.         else: action = False
  5971.     >>elif popup == 3:
  5972.         if aw.query(u"Set Action for Left. . ?", "query") == True:
  5973.             action = "activeLeft"
  5974.             selectAction(popup)
  5975.         else: action = False
  5976.     >>elif popup == 4:
  5977.         if aw.query(u"Set Action for Right. . ?", "query") == True:
  5978.             action = "activeRight"
  5979.             selectAction(popup)
  5980.         else: action = False
  5981.  
  5982. def setSensitivity():
  5983. >>global sensLeft, sensRight, sensUp
  5984. >>global sensDown, sensCenter
  5985. >>ask = aw.popup_menu([u"Set All", u"Set a Corner"])
  5986. >>if ask == 0:
  5987.     >>all = aw.query(u"Sensitivity:", "number", 120)
  5988.     >>if aw.query(u"Sensitivity is %s?"%(all),"query") == True:
  5989.         >>sensLeft, sensRight, sensUp=all, all, all
  5990.         >>sensDown, sensCenter = all, all
  5991.         >>aw.note(u"Success", "conf")
  5992.     >>else: return all
  5993. >>elif ask == 1:
  5994.     popup = aw.popup_menu([u"Top", u"Bottom", u"Center", u"Left", u"Right"], u"Corner Type:")
  5995.     if popup == 0:
  5996.         sensUp = aw.query(u"Sensitivity:", "number",sensUp)
  5997.     elif popup == 1:
  5998.         sensDown = aw.query(u"Sensitivity:", "number", sensDown)
  5999.     elif popup == 2:
  6000.         sensCenter = aw.query(u"Sensitivity:", "number", sensCenter)
  6001.     elif popup == 3:
  6002.         sensLeft = aw.query(u"Sensitivity:", "number", sensLeft)
  6003.     elif popup == 4:
  6004.         sensRight = aw.query(u"Sensitivity:", "number", sensRight)
  6005.     aw.note(u"Success", "conf")
  6006.  
  6007. def start_finder():
  6008.     global control_light
  6009.     control_light = 0
  6010.     camera.start_finder(cPixel, size=(200, 150))
  6011.  
  6012. def stop_finder():
  6013.     global control_light
  6014.     control_light = 1
  6015.     camera.stop_finder()
  6016.     camera.release()
  6017.     aw.note(u"Finder stop")
  6018.  
  6019. information = u"Camera Motion is Application based on Camera detection. It needs python 1.45 or above.You Can Set Camera Motion to Adjust Sensitivity and Action by Pressing Options. Camera Motion Can be Used to detect Thing and People.\n\t--Thank You For Using--"
  6020.  
  6021. def about():
  6022.     import globalui as gl
  6023.     info = u"Name\t\t: Camera Motion\n"
  6024.     info += u"Version\t: 1.0.0\n"
  6025.     info += u"Release\t: 17 November 2010\n"
  6026.     info += u"Author\t\t: Joe Arton\n"
  6027.     info += u"Email\t\t: joe_arton@yahoo.\n\t\t com"
  6028.     showAbout = gl.global_msg_query(info, u"Information")
  6029.     if showAbout == True:
  6030.         showHelp = gl.global_msg_query(information, u"Information")
  6031.  
  6032. def quit():
  6033. >>if aw.query(u"Stop and Exit from Camera Motion Now. . ?","query") == True:
  6034.     stop_finder()
  6035.     lock.signal()
  6036.     aw.note(u"Go out", "conf")
  6037. >>else: pass
  6038.  
  6039. aw.app.menu = [
  6040.     (u"Finder", (
  6041.         (u"Start Finder", start_finder),
  6042.         (u"Stop Finder", stop_finder))),
  6043.     (u"Setting", (
  6044.         (u"Set Sensibility", setSensitivity),
  6045.         (u"Set Action", setAction))),
  6046.     (u"About", about),
  6047.     (u"Exit", quit)
  6048.     >]
  6049.  
  6050. aw.app.exit_key_text = u"Stop & Exit"
  6051. aw.app.exit_key_handler = quit
  6052. lock.wait()
  6053. ---------------------------------------------------------------------------------------
  6054.  
  6055. Note:
  6056. Tanda > diganti menggunakan spasi.
  6057.  
  6058.  
  6059.  
  6060.  
  6061.  
  6062. ==========
  6063.  
  6064.  
  6065.  
  6066. 087.
  6067.  
  6068. "INDICATOR BATTERY HP"
  6069.  
  6070. Saya mau share sebuah script untuk indicator battery HP...
  6071.  
  6072. ---------------------------------------------------------------------------------------
  6073. import indicators, e32
  6074. ---------------------------------------------------------------------------------------
  6075.  
  6076. -Level baterai menjadi 5
  6077.  
  6078. ---------------------------------------------------------------------------------------
  6079. print "menset level baterai menjadi 5"
  6080. indicators.set_battery(5)
  6081.  
  6082. e32.ao_sleep(2)
  6083. ---------------------------------------------------------------------------------------
  6084.  
  6085. -Level signal menjadi 5
  6086.  
  6087. ---------------------------------------------------------------------------------------
  6088. print "menset level sinyal menjadi 5"
  6089. indicators.set_signal(5)
  6090.  
  6091. e32.ao_sleep(2)
  6092.  
  6093. print "Mulai men-charge baterai"
  6094. indicators.start_charging()
  6095.  
  6096. e32.ao_sleep(3)
  6097.  
  6098.  
  6099. print "Menghentikan men-charge baterai"
  6100. indicators.stop_charging()
  6101. ---------------------------------------------------------------------------------------
  6102.  
  6103.  
  6104.  
  6105.  
  6106.  
  6107. ==========
  6108.  
  6109.  
  6110.  
  6111. 088.
  6112.  
  6113. "CARA MEREKAM AUDIO"
  6114.  
  6115. Saya mau share cara merekam audio menggunakan pys60...
  6116.  
  6117. ---------------------------------------------------------------------------------------
  6118. import appuifw, audio, os
  6119.  
  6120. MENU = [u"Play sound", u"Record sound", u"Delete sound"]
  6121. SOUNDFILE = u"E:\\sound.wav"
  6122. sound = None
  6123.  
  6124. while True:
  6125.         index = appuifw.popup_menu(MENU, u"Select operation")
  6126.         if sound:
  6127.                 sound.stop()
  6128.         sound = audio.Sound.open(SOUNDFILE)
  6129.         if index == 0:
  6130.                 sound.play()
  6131.         elif index == 1:
  6132.                 sound.record()
  6133.                 appuifw.query(u"Press OK to stop recording", "query")
  6134.                 sound.stop()
  6135.         elif index == 2:
  6136.                 os.remove(SOUNDFILE)
  6137.         else:
  6138.                 break
  6139. ---------------------------------------------------------------------------------------
  6140.  
  6141. Note:
  6142. Tanda > diganta menggunakan spasi.
  6143.  
  6144.  
  6145.  
  6146.  
  6147.  
  6148. ==========
  6149.  
  6150.  
  6151.  
  6152. 089.
  6153.  
  6154. "MEMUTAR FILE MP3"
  6155.  
  6156. Saya mau share sebuah script untuk play file mp3...
  6157.  
  6158. ---------------------------------------------------------------------------------------
  6159. import audio
  6160.  
  6161. sound = audio.Sound.open("E:\\Sounds\\mysound.mp3")
  6162.  
  6163. def playMP3():
  6164.     >sound.play()
  6165.     >print "PlayMP3 returns.."
  6166.  
  6167. playMP3()
  6168. ---------------------------------------------------------------------------------------
  6169.  
  6170. Note:
  6171. Tanda > diganti menggunakan spasi.
  6172.  
  6173.  
  6174.  
  6175.  
  6176.  
  6177. ==========
  6178.  
  6179.  
  6180.  
  6181. 090.
  6182.  
  6183. "TEKS BICARA"
  6184.  
  6185. Saya mau share sebuah script untuk merubah teks menjadi audio...
  6186.  
  6187. ---------------------------------------------------------------------------------------
  6188. import appuifw, audio
  6189.  
  6190. text = appuifw.query(u"Type a word:", "text")
  6191. audio.say(text)
  6192. ---------------------------------------------------------------------------------------
  6193.  
  6194.  
  6195.  
  6196.  
  6197.  
  6198. ==========
  6199.  
  6200.  
  6201.  
  6202. 091.
  6203.  
  6204. "CARA MENEMUKAN KATA di INBOX"
  6205.  
  6206. Saya mau share sebuah script yang dapat menemukan kata diinbox secara otomatis...
  6207.  
  6208. ---------------------------------------------------------------------------------------
  6209. import inbox, appuifw
  6210.  
  6211. box = inbox.Inbox()
  6212. query = appuifw.query(u"Search for:", "text").lower()
  6213.  
  6214. hits = []
  6215. ids = []
  6216. for sms_id in box.sms_messages():
  6217.     >>msg = box.content(sms_id).lower()
  6218.     >>if msg.find(query) != -1:
  6219.         >>>hits.append(msg[:25])
  6220.         >>>ids.append(sms_id)
  6221.  
  6222. index = appuifw.selection_list(hits, 1)
  6223. if index >= 0:
  6224.         appuifw.note(box.content(ids[index]))
  6225. ---------------------------------------------------------------------------------------
  6226.  
  6227. Note:
  6228. Tanda > diganti menggunakan spasi.
  6229.  
  6230.  
  6231.  
  6232.  
  6233.  
  6234. ==========
  6235.  
  6236.  
  6237.  
  6238. 092.
  6239.  
  6240. "MENGAKSES INBOX"
  6241.  
  6242. Saya mau share sebuah script untuk mengakses inbox...
  6243.  
  6244. ---------------------------------------------------------------------------------------
  6245. import inbox, appuifw
  6246.  
  6247. box = inbox.Inbox()
  6248.  
  6249. for sms_id in box.sms_messages()[:5]:
  6250.     >>msg = box.content(sms_id)
  6251.     >>appuifw.note(msg)
  6252. ---------------------------------------------------------------------------------------
  6253.  
  6254. Note:
  6255. Tanda > diganti menggunakan spasi.
  6256.  
  6257.  
  6258.  
  6259.  
  6260.  
  6261. ==========
  6262.  
  6263.  
  6264.  
  6265. 093.
  6266.  
  6267. "LIST SELEKSI"
  6268.  
  6269. Saya mau share sebuah script untuk list seleksi...
  6270.  
  6271. ---------------------------------------------------------------------------------------
  6272. import appuifw
  6273.  
  6274. colors = [u"red", u"green", u"blue", u"brown"]
  6275.  
  6276. selections = appuifw.multi_selection_list(colors, 'checkbox', 1)
  6277. print "Checkbox selected:", selections
  6278.  
  6279. selections = appuifw.multi_selection_list(colors, 'checkmark', 1)
  6280. print "Checkmark selected:", selections
  6281. ---------------------------------------------------------------------------------------
  6282.  
  6283.  
  6284.  
  6285.  
  6286.  
  6287. ==========
  6288.  
  6289.  
  6290.  
  6291. 094.
  6292.  
  6293. "TWO DIALOGS"
  6294.  
  6295. Saya mau share sebuah script two dialogs...
  6296.  
  6297. ---------------------------------------------------------------------------------------
  6298. import appuifw
  6299.  
  6300. word = appuifw.query(u"Type your name", "text")
  6301. appuifw.note(u"Greetings from " + str(word))
  6302. ---------------------------------------------------------------------------------------
  6303.  
  6304.  
  6305.  
  6306.  
  6307.  
  6308. ==========
  6309.  
  6310.  
  6311.  
  6312. 095.
  6313.  
  6314. "MEMASUKKAN NAMA"
  6315.  
  6316. Saya mau share sebuah script untuk memasukkan nama...
  6317.  
  6318. ---------------------------------------------------------------------------------------
  6319. import appuifw
  6320.  
  6321. names = appuifw.multi_query(u"First name:", u" Last name:")
  6322. if names:
  6323.         first, last = names
  6324.         appuifw.note(u"Your full name is: " + first + " " + last)
  6325. else:
  6326.         appuifw.note(u"Cancel!")
  6327. ---------------------------------------------------------------------------------------
  6328.  
  6329. Note:
  6330. Tanda > diganti menggunakan spasi.
  6331.  
  6332.  
  6333.  
  6334.  
  6335.  
  6336. ==========
  6337.  
  6338.  
  6339.  
  6340. 096.
  6341.  
  6342. "CARA MEREKAM AUDIO"
  6343.  
  6344. Saya mau share sebuah script untuk merekam audio...
  6345.  
  6346. ---------------------------------------------------------------------------------------
  6347. import appuifw, audio, os
  6348.  
  6349. MENU = [u"Play sound", u"Record sound", u"Delete sound"]
  6350. SOUNDFILE = u"E:\\sound.wav"
  6351. sound = None
  6352.  
  6353. while True:
  6354.         index = appuifw.popup_menu(MENU, u"Select operation")
  6355.     if sound:
  6356.                 sound.stop()
  6357.         sound = audio.Sound.open(SOUNDFILE)
  6358.         if index == 0:
  6359.                 sound.play()
  6360.         elif index == 1:
  6361.                 sound.record()
  6362.                 appuifw.query(u"Press OK to stop recording", "query")
  6363.                 sound.stop()
  6364.         elif index == 2:
  6365.                 os.remove(SOUNDFILE)
  6366.         else:
  6367.                 break
  6368. ---------------------------------------------------------------------------------------
  6369.  
  6370. Note:
  6371. Tanda > diganti menggunakan spasi.
  6372.  
  6373.  
  6374.  
  6375.  
  6376.  
  6377. ==========
  6378.  
  6379.  
  6380.  
  6381. 097.
  6382.  
  6383. "MEMBUAT SELECTION LIST"
  6384.  
  6385. Saya mau share sebuah script untuk membuat selection list...
  6386.  
  6387. ---------------------------------------------------------------------------------------
  6388. import appuifw
  6389.  
  6390. colors = [u"red", u"green", u"blue", u"brown"]
  6391.  
  6392. index = appuifw.selection_list(colors, 1)
  6393. if index == 2:
  6394.     print "blue is correct!"
  6395. else:
  6396.     print "Bzz! " + colors[index] + " is not correct"
  6397. ---------------------------------------------------------------------------------------
  6398.  
  6399. Note:
  6400. Tanda > diganti menggunakan spasi.
  6401.  
  6402.  
  6403.  
  6404.  
  6405.  
  6406. ==========
  6407.  
  6408.  
  6409.  
  6410. 098.
  6411.  
  6412. "MEMBUAT POPUP MENU"
  6413.  
  6414. Saya mau share sebuah script untuk membuat popup menu...
  6415.  
  6416. ---------------------------------------------------------------------------------------
  6417. import appuifw
  6418.  
  6419. choices = [u"Symbian", u"PyS60", u"MobileArt"]
  6420.  
  6421. index = appuifw.popup_menu(choices, u"Select:")
  6422.  
  6423. if index == 0 :
  6424.     appuifw.note(u"Symbian, aha")
  6425. elif index == 1 :
  6426.     appuifw.note(u"PyS60 - yeah")
  6427. elif index == 2 :
  6428.     appuifw.note(u"I love MobileArt")
  6429. ---------------------------------------------------------------------------------------
  6430.  
  6431. Note:
  6432. Tanda > diganti menggunakan spasi.
  6433.  
  6434.  
  6435.  
  6436.  
  6437.  
  6438. ==========
  6439.  
  6440.  
  6441.  
  6442. 099.
  6443.  
  6444. "MEMBUAT APP BERKODE"
  6445.  
  6446. Saya mau share cara membuat kode pada sebuah aplikasi...
  6447.  
  6448. -Module yang dibutuhkan
  6449.  
  6450. ---------------------------------------------------------------------------------------
  6451. import appuifw
  6452. import e32
  6453. import os
  6454. import globalui
  6455. import sysinfo
  6456. ---------------------------------------------------------------------------------------
  6457.  
  6458. -Fungsi define untuk dipanggil ketika aplikasi diberikan perintah keluar
  6459.  
  6460. ---------------------------------------------------------------------------------------
  6461. def keluar():
  6462.     x = globalui.global_query(u'Anda Yakin?')
  6463.     if x == 1 :
  6464.         appuifw.note(u'http://fnugraha8.mywapblog.com', 'info')
  6465.         appuifw.note(u'Terima Kasih', 'conf')
  6466.         os.abort()
  6467. ---------------------------------------------------------------------------------------
  6468.  
  6469. -Fungsi define untuk membuat kode kodem dalam persamaan sama dengan imei yang akan dimasukkan berupa angka
  6470.  
  6471. -Imei=sysinfo.imei() merupakan perintah untuk membaca imei pada handphone
  6472.  
  6473. -Kodek merupakan perintah persamaan untuk mengatur dan mengendalikan angka pada imei HP seperti imei[2]+imei[5] yang artinya digit ke 2 dan ke 5 pada imei HP contoh pada imei 354813015046327 yang diambil adalah angka 4 dan 3 kenapa bukan 5 dan 1, itu karena urutan angka mulai dari 0 jadi urutan angka 3 pada imei diatas adalah 0 dst.
  6474.  
  6475. -Kodekem merupakan persamaan dari fungsi penambah nilai dari fungsi kodek tadi misal hasil dari angka didapatkan dari 56284+1990 jadi nanti hasilnya adalah kodenya
  6476.  
  6477. -Fungsi if dan else mungkin udah pada tau ea, kan ada dalam ilmu matematika
  6478.  
  6479. ---------------------------------------------------------------------------------------
  6480. def op():
  6481.     kodem = appuifw.query(u'Masukkan Kodenya', 'text')
  6482.     imei = sysinfo.imei()
  6483.     kodek = ((((imei[2] + imei[5]) + imei[12]) + imei[9]) + imei[3])
  6484.     kodekem = (int(kodek) + 1990)
  6485.     kode = str(kodekem)
  6486.     kodez = kodem
  6487.     if kode == kodez :
  6488.         appuifw.note(u'Kode Benar', 'conf')
  6489.         appuifw.note(u'Terima Kasih', 'conf')
  6490.         buka()
  6491.     else :
  6492.         appuifw.note(u'Kode Salah!', 'error')
  6493.         os.abort()
  6494. ---------------------------------------------------------------------------------------
  6495.  
  6496. -Fungsi ini untuk pembuka sebelum masuk kemenu utama
  6497.  
  6498. ---------------------------------------------------------------------------------------
  6499. def buka():
  6500.     R = appuifw.Text()
  6501.     appuifw.app.body = R
  6502.     R.style = appuifw.STYLE_BOLD
  6503.     y = u'http://fnugraha8.mywapblog.com'
  6504.     R.color = 255
  6505.     for abc in range(len(y)):
  6506.         R.add(y[abc])
  6507.         e32.ao_sleep(0.0)
  6508.     R.color = 255
  6509.     global R
  6510. ---------------------------------------------------------------------------------------
  6511.  
  6512. -Fungsi menu utama
  6513.  
  6514. ---------------------------------------------------------------------------------------
  6515. def menu():
  6516.     appuifw.app.menu = [(u'Test',buka)]
  6517. ---------------------------------------------------------------------------------------
  6518.  
  6519. -Fungsi keluar
  6520.  
  6521. ---------------------------------------------------------------------------------------
  6522.     appuifw.app.exit_key_handler = keluar
  6523. ---------------------------------------------------------------------------------------
  6524.  
  6525. -Perintah untuk memanggil pembuka dan menu utama
  6526.  
  6527. ---------------------------------------------------------------------------------------
  6528. op()
  6529. menu()
  6530. ---------------------------------------------------------------------------------------
  6531.  
  6532. -Perintah untuk mengunci script
  6533.  
  6534. ---------------------------------------------------------------------------------------
  6535. e32.Ao_lock().wait()
  6536. ---------------------------------------------------------------------------------------
  6537.  
  6538. Note:
  6539. Tanda > diganti menggunakan spasi.
  6540.  
  6541.  
  6542.  
  6543.  
  6544.  
  6545. ==========
  6546.  
  6547.  
  6548.  
  6549. 100.
  6550.  
  6551. "MEMBUAT KEYGEN"
  6552.  
  6553. Saya mau share sebuah script untuk membuat keygen...
  6554.  
  6555. ---------------------------------------------------------------------------------------
  6556. import appuifw
  6557. import e32
  6558. import os
  6559. import sysinfo
  6560.  
  6561. def key():
  6562. >>imei=appuifw.query(u'imei','text')
  6563. >>i=len(imei)
  6564. >>if i < 15 :
  6565.     appuifw.note(u'Harus 15 digit angka...!', 'error')
  6566.     key()
  6567. >>>if i > 15 :
  6568.     appuifw.note(u'Harus 15 digit angka....!', 'error')
  6569.     key()
  6570. >>kodek=imei[2]+imei[5]+imei[12]+imei[9]+imei[3]
  6571. >>kodek=int(kodek)+1990
  6572. >>kode=str(kodek)
  6573. >>appuifw.query(u'kodenya: ','text',(u''+kode))
  6574. >>key()
  6575.  
  6576. key()
Add Comment
Please, Sign In to add comment