· 8 years ago · May 12, 2018, 01:12 AM
1PyS60 Snippets Galore
2
3Table of contents:
4001. "Brief History of Python".....
5002. "Introduction to Basic Pys60".....
6003. "Basic Python Symbian Application".....
7004. "Learning to Create a Simple Python Script".....
8005. "How to Make Your Own Application on HP Symbian or HP Make With Using Python Application".....
9006. "How to Turn S60v3 Application into S60v2 Application".....
10007. "Trick Accelerate Menu of HP Symbian S60v1 and S60v2 Simple Without Application and Move Cache to Memory Card".....
11008. "Zntxhan app".....
12009. "Py2Pyc Applications".....
13010. "About Python-Based Applications and Its Functions".....
14011. "Name the File Bulkly".....
15012. "Creating Serial Number".....
16013. "Making Google Translate Translator" Translate.....
17014. "Cutting Image".....
18015. "Wearing Special Character".....
19016. "File Handling".....
20017. "List".....
21018. "Dictionary".....
22019. "Dictionary and List".....
23020. "2D Image".....
24021. "Writing Text and Tittle On Application".....
25022. "Perulangbn For Function".....
26023. "Condition If".....
27024. "Menu, Submenu and Popup Menu".....
28025. "Minimize a Program Using Script Pys60".....
29026. "Creating Password Script Pys60".....
30027. "Py Script To Show Weak Battery".....
31028. "Simple Script Makes Popup Menu".....
32029. "Reading File With Powlite_Fm Module".....
33030. "Changing Image Size Using Script".....
34031. "Use Password Script On An Application".....
35032. "Py Script To Backup File".....
36033. "Multi Selection List".....
37034. "Audio (Playing Mp3 1 Folder)".....
38035. "Charging Name Less Than and More Than 5 Characters".....
39036. "Multi_Query".....
40037. "Simple Form"....
41038. "Create Progressbar".....
42039. "Displays Applications Already Installed In List Form".....
43040. "Calling Image With Module From Graphics Import *".....
44041. "The .Ttx File Dialing Script".....
45042. "Text Script Being Voice".....
46043. "Script To Call and Open Applications Outside Application System".....
47044. "Script To Play Mp3 On Define Function".....
48045. "Calling Text Using Glob Module Through Python Script".....
49046. "How to Include Music or Mp3 into a Python Application".....
50047. "Basic Logic Game Code Order".....
51048. "Implementing 3D Computing Basics With Pys60" (Part 1).....
52049. "Implementing 3D Computing Basics With Pys60" (p.2).
53050. "Implementing 3D Computing Basics With Pys60" (ch.3).
54051. "List, Function and Class".....
55052. "Meload External Image With Image 1st Module".....
56053. "Example Game Program Scissors, Stone, Paper".....
57054. "Little Explanation of Identification in Python".....
58055. "Heat Seeking Missile Alogarithm and Implementation".....
59056. "Making Quiz With Pys60".....
60057. "Reading the Message With Pys60".....
61058. "Some Python Script Writing Style".....
62059. "Displays IP With Pys60".....
63060. "TxtField Module".....
64061. "Repetition For In Pys60".....
65062. "Double Menu Popup With Pys60".....
66063. "Checking and Creating Folders With Pys60".....
67064. "One Syntak Difference S60v1 and S60v2 Above"....
68065. "Polygon Rotation With Pys60".....
69066. "Scan Fill Drive With Pys60".....
70067. "Combining Functions With Progress On Pys60".....
71068. "Pys60 Script Encoded".....
72069. "Displays All Application Icon Installed With Pys60".....
73070. "Creating 4 Direction Cursor On Application With Pys60".....
74071. "Making Analog Clock With Pys60".....
75072. "Signal Indicator, Battery With FgImage (Pys60)".....
76073. "Set FgImage On StandBy Pys60".....
77074. "Screenshot With N-Gage or S60v1 (Pys60)".....
78075. "Making Graph (Script Pys60)".....
79076. "Get Coordinate Arround Circle (Pys60)".....
80077. "Adjust Timing Subtittle With Python".....
81078. "Creating Grid Menu 3x3 (Pys60)".....
82079. "Creating a Simple Calculator".....
83080. "Make Text Run With Backgroud Sound".....
84081. "Make Popup Aa Check Pulsa".....
85082. "Sending SMS Most Number".....
86083. "Function of Appuifw Module".....
87084. "Simple Scanning Application".....
88085. "Text Editor Application".....
89086. "Camera Motion".....
90087. "Indicator Battery HP".....
91088. "How to Store Audio".....
92089. "Playing Mp3 File".....
93090. "Text Talk".....
94091. "How to Find Words in Inbox".....
95092. "Accessing Inbox".....
96093. "Selection List".....
97094. "Two Dialogs".....
98095. "Enter Name".....
99096. "How to Record Audio".....
100097. "Creating Selection List".....
101098. "Making Popup Menu".....
102099. "Creating a Code App".....
103100. "Making Keygen".....
104
105
106
107==========
108
109
110
111001.
112
113"BRIEF PYTHON HISTORY"
114
115I want to share about Python history, what is Python, what is Python usefulness, all about yhon...
116
117Python for s60 is a high-level programming language that is a derivative of Python Language.
118
119Given 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
121Brief and concise history of Python.
122If 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
124Previously, 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
126So, 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
134002.
135
136"PYS60 BASIC INTRODUCTION"
137
138I want to share about pys60...
139
140What is a pys60?
141- pys60 is the derived programming language of Python for s60 phones.
142
143What is pys60 or Python on the phone?
144- create a script, make programs, create applications, games.
145
146How 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
149Where do I find out what version of HP or my mobile phone?
150- find out here
151http://www.developer.nokia.com/Devices/Device_specifications/?filter2=s60
152
153What 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
156Python modif same basic Python same not?
157- basic is same, only, Python modif have more module.
158
159Download 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
164If the new module is not there? Where to download?
165- http://watt.eu5.org
166- http://www.agus-ibrahim.net/
167
168In 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
176What Python script features?
177- ending in .py, .pyc,, pyd
178
179Writing 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
183How 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
193003.
194
195"PYTHON SYMBIAN BASIC APPLICATIONS"
196
197I want to share a little information about HP Symbian and Python...
198
199Previously 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
221Note:
222Installation (specially s60v3).
223
2241. 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
2262. Python-based applications must be installed in the same place where Python script shell and Python for s60 are installed.
227
2283. 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
237004.
238
239"LEARN MAKE SCRIPT PYTHON SIMPLE"
240
241I want to share about how to create a Python script,
242
243Python 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
245Python is a multi-paradigm language, supporting object-oriented and functional programming styles, inter alia, giving freedom to approach problems in various ways.
246
247Python 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.
248In the following chapters, we describe the latest versions of Python on Symbian, v2.0.0 for s60v3 and v1.4.5 for s60v2.
249Why 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
251Most people can read Python code with just a few hours of study and can start developing mobile apps not long after.
252
253Applications made in Python are indistinguishable from native C ++ applications and for most purposes offer much of the same performance.
254
255Most 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
257If 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
259Python Application ("script" ) is just a text file containing code written in the Python programming language and named with the "py" file extension).
260
261Scripts 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
263Sample Testing Python Script Script Interactive scripts make it very easy to test your script during development.
264
265Shell 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
267Write the following line of your edited text:
268
269----------------------------------------------------------------------------------------
270print "Hello! Python On Symbian"
271----------------------------------------------------------------------------------------
272
273If 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
275Move the file or 'My Script.py' to E: / System / apps / Python.
276Open the Python app and press options run script select 'ScriptPertamaku.py'
277
278If you are successful then you will see textHello! Python On Symbian.
279
280You can also run an existing script like ball.py, snake.py. Then next and create a second script.py
281
282----------------------------------------------------------------------------------------
283import appuifw
284appuifw.note (u 'Hello! Python On Symbian')
285----------------------------------------------------------------------------------------
286
287Test your second script, open Python Run script and select Script Second .py
288
289If you want to try the script again .. please see this script.
290
291
292Script appuifw
293To test it, open Python, Options interactive console type
294import appuifw click ok
295
296Put the script
297To show errors:
298----------------------------------------------------------------------------------------
299appuifw.note
300(u 'Error.', 'error')
301click ok
302----------------------------------------------------------------------------------------
303
304To display information:
305----------------------------------------------------------------------------------------
306appuifw.note
307(u 'Information.', 'info')
308----------------------------------------------------------------------------------------
309
310To display a confirmation:
311----------------------------------------------------------------------------------------
312appuifw.note (u 'Success',' conf')
313----------------------------------------------------------------------------------------
314
315To show a question:
316----------------------------------------------------------------------------------------
317appuifw.query ('Would you like to exit?' .decode ('utf-8?),' query')
318----------------------------------------------------------------------------------------
319
320For input commands;
321Name:
322----------------------------------------------------------------------------------------
323appuifw.query (u "Enter name:", "text", u "Cebri Nugraha" )
324----------------------------------------------------------------------------------------
325
326Number:
327----------------------------------------------------------------------------------------
328appuifw.query (u "Enter no.:","number")
329----------------------------------------------------------------------------------------
330
331Code:
332----------------------------------------------------------------------------------------
333appuifw.query (u "input code:", "code" )
334----------------------------------------------------------------------------------------
335
336Date:
337----------------------------------------------------------------------------------------
338appuifw.query (u "Put date:", "date" )
339----------------------------------------------------------------------------------------
340
341Time or hour:
342----------------------------------------------------------------------------------------
343appuifw.query (u "Enter time:", "time" )
344----------------------------------------------------------------------------------------
345
346Float:
347----------------------------------------------------------------------------------------
348appuifw.query (u "Put float:", "float" )
349----------------------------------------------------------------------------------------
350
351Query:
352----------------------------------------------------------------------------------------
353appuifw.query (u "Input query:", "query" )
354----------------------------------------------------------------------------------------
355
356To set the application screen;
357Normal screen:
358----------------------------------------------------------------------------------------
359appuifw.app.screen = 'normal'
360----------------------------------------------------------------------------------------
361
362Large screen:
363----------------------------------------------------------------------------------------
364appuifw.app.screen = 'large'
365----------------------------------------------------------------------------------------
366
367Full screen:
368----------------------------------------------------------------------------------------
369appuifw.app.screen = 'full'
370----------------------------------------------------------------------------------------
371
372----------------------------------------------------------------------------------------
373appuifw.app.title = u "error"
374----------------------------------------------------------------------------------------
375
376To create a selection menu:
377----------------------------------------------------------------------------------------
378appuifw.app.menu = []
379appuifw.popup_menu ([u "Option 1", u "Option 2", u "Option 3"])
380----------------------------------------------------------------------------------------
381
382Application background color:
383----------------------------------------------------------------------------------------
384appuifw.app.body.color = 0xff0000
385----------------------------------------------------------------------------------------
386
387
388
389==========
390
391
392
393005.
394
395-Python
396-X-plorer
397-Sisboom
398-Linkaper
399-Ped
400
401Once 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:
402Read more:
4031. Create first scripnya this example python script I gave the name Azam restart.py
404
405----------------------------------------------------------------------------------------
406import appuifw
407import e32
408import switchoff
409
410def restart():
411 a = appuifw.query (u'Atur Time Time: ',' number ')
412 e32.ao_sleep (a)
413 switchoff.Restart()
414
415def shutdown():
416 b = appuifw.query (u'Enter a Second Time: ',' number ')
417 e32.ao_sleep (b)
418 switchoff.shutdown()
419
420def azam():
421 appuifw.note (u 'this app was created by syamsul azam creator')
422
423
424appuifw.app.title = u 'Azam restar'
425appuifw.app.menu = [(u'Restart ', restart), (u'Shutdown', shutdown), (u'maker ', azam)]
426x = e32.Ao_lock()
427x.wait()
428----------------------------------------------------------------------------------------
429
4302. The second step after copying the script above the save with the extension py so Azam restart.py
431
4323. 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
4344. 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
4365. 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
4386. Next step open the x-plorer app in directory E: system / app / Azam restart
439
4407. 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
4428. The next step is to copy the script you have tested and dipaste in Azam restart.
443
4449. 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
454006.
455
456"HOW TO CHANGE S60v3 APPLICATION BECOME A S60v2 APPLICATION"
457
458I want to share how to change s60v3 application to s60v2, application that can be changed only application based on Python...
459
460Equipment:
4611.Linkapper
4622.X-Plore
4633.Sisboom v6-4
464
465Here as an example I change the Application IDesigner owned by Symbian v3 to Symbian v2 Application.
466
4671. Create a new folder in E: / system / apps / (Application name)
468example: E: / system / apps / ImageDesigner
469
4702. Create a new text file and name it default.py in E: / system / apps / ImageDesigner
471The 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
4733. 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
4754. Then enter the name of the program: ImageDesigner then put it on drive E:\
476
4775. A notification will appear stating that a file with the same name already exists, stop it? Just hit "Cancel"
478
4796. Enter UID (or don 't touch): enter UID manually or just press Ok, select Ok
480
4817. 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
4838. You can see the icon on your mobile phone, but never open it first because it is not finished yet.
484
4859. 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
48710. Open X-plore and go to the folder where the python files are located (the unloading result)
488
48911. 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
49112. 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
49313. To make it a full s60v2 Application, silhakan your pack into one using Sisboom Application.
494
495
496
497
498==========
499
500
501
502007.
503
504"TRICK ACCESSIBLE MENU HP SYMBIAN S60v1 and S60v2 SIMPLE WITHOUT APPLICATIONS AND MOVE CACHE TO MEMORY CARD"
505
506
507Trick 01
5081. Use x-plore
5092. Select menu> new text
5103. Create in c or in C> system> here or it could be in C / system> shareddata
5114. Create its name Menu.cfg
5125. Create the contents Z / System / Apps / Menu / Menu.app
5136. Save
5147. 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
517Trick 02
5181. Create a folder in C name Shareddata
5192. After that make a text like way 1
5203. Name it 101f8557.ini
5214. Fill it with
522
523----------------------------------------------------------------------------------------
524CachEnable = True
525CacheSize = 20000000
526CacheDir = e:\cache
527ODomainUrl = http: //host53.nokia-boston.com/Cache_OpCache/Op_Menu.xhtml
528OCacheSize = 300000
529OCacheDir = c:\cache
530----------------------------------------------------------------------------------------
531
532The cache size section can be modified can be replaced 3.4 dst
533Press the pen button to copy the code.
534
535
536
537
538==========
539
540
541
542008.
543
544"ZNTXHAN APPLICATIONS"
545
546I want to share about how to edit a compiled Python file...
547
548Python files that have been decompiled can not be edited using x-plore as we are in .py file
549
550Actually it can, but a bit complicated because we must edit from hex or chart...
551
552To avoid complicated use Zntxhan to decompiling py scripts and make necessary modifications.
553
554Sometimes it is difficult to decompile dile PYD, if you know Python encoding, you can use Zntxhan to enter new encoding.
555
556Similarly 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
558Note:
559Make sure your phone is filled with python program.
560
561
562
563
564==========
565
566
567
568009.
569
570"PY2PYC APPLICATIONS"
571
572I want to share a little information about Py2Pic applications...
573
574Py2Pyc: 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
578Now let's start to compile:
579
580To 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
582Let's try one on one:
583
584But 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
589def Hello():
590 # say hello :)
591 print "Hello World!"
592 # done!
593
594# call the function
595Hello()
596----------------------------------------------------------------------------------------
597
598Save it on drive E:\to make it easy to find it ::
599
6001. Using Py2Pyc Program
601The first step is, download the Py2Pyc program, then do the installation as usual. Open Py2Pyc program, select [Options] -> [Select File]
602Find where the script will be compiled. Once found, click [OK] to mark then select [Options] -> [Done]
603Select [Options] again and select [Compile]. Done.
604
6052. Using the Command Line (Python Shell)
606Compiling python scripts using a command line is actually simpler because we only need to type in two command lines only.
607Start 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
614That's it and it's done. Our script has been compiled into a .pyc binary.
615
6163. Using Simple Scripts
617This 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
619Let's make the script:
620import module required
621
622----------------------------------------------------------------------------------------
623import fm
624import py_compile
625import appuifw
626import os
627
628def 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
654def CDone():
655 appuifw.note (u "Compile is successful!", "info")
656
657def CError():
658 appuifw.note (u "Compilation failed!", "info")
659
660appuifw.note (u "Select the file to compile,...", "info")
661SelectFile()
662----------------------------------------------------------------------------------------
663
664Save 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
666The script will instantly open the browser file view and wait for input from you. [OK] or [Cancel].
667
668Script Execution
669In 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")
673Hello World!
674
675----------------------------------------------------------------------------------------
676
677Then, 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
679The 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
685Hello World!
686
687----------------------------------------------------------------------------------------
688
689And 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()
694Hello World!
695
696----------------------------------------------------------------------------------------
697
698
699
700
701
702==========
703
704
705
706010.
707
708"ABOUT APPLICATIONS BASED ON PYTHON AND ITS FUNCTIONS"
709
710I want to share a little info about python-based apps and their script functions...
711
712Confused to distinguish Python-based applications. Because there is no difference. If java kan runs slow in Symbian.
713Immediately discussed.
714
715A 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.
716If 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
718Example:
719# Script Python by xxxxxx
720# For more apps visit www.xxxxx.xx
721
722Unless there is a script under IMPORT.
723
724Example:
725# Script Python by xxxxxx
726# For more apps visit www.xxxxx.xx
727import xxxpy
728
729Import 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
731If the DEFAULT.PY script contains long Syntax-syntax it is clear that the application is Python-based.
732
733The conclusion:
734The 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
736Sample file:
737E:\System\Apps\ZIMPDA\
738there are files:
739- ZIMPDA.app * <Application *
740- ZIMPDA.aif
741- ZIMPDA.src
742- Default.py * <Script python *
743- main.pyc * <Compiled python script *
744
745Example of default.py app ZIMPDA:
746# Script by Zidna Mmc
747# Bring up an error message
748
749import appuifw * <This function calls py or pyc in the libs folder. Karna is not in the application folder. *
750
751import main * <This function calls the py or pyc in the application folder *
752
753
754Example of the contents of the main.pyc file that was decompiled into main.py app ZIMPDA:
755
756appuifw.note (u "Error gan, Systemnya again ga path", error)
757
758appuifw.app.set_exit()
759
760Note:
761So 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
770011.
771
772"APPLY THE FILES ONLY MASS"
773
774I want to share about scripts to name files in bulk...
775
776We 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.
777To name files in bulk, of course we must use looping or looping function.
778Suppose we want to name the files with the name "song_1.mp3, lagu_2.mp3? Dst
779Here's an example script,
780
781----------------------------------------------------------------------------------------
782import os
783dirk = e:\\mp3
784dir = os.listdir(dirk)
785to = 1
786for file in dir:
787 path = dirk file
788 os.rename (path, dirk "lagu_" str (to) ".mp3?)
789 to = 1
790print 'Done'
791----------------------------------------------------------------------------------------
792
793Note:
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.
796In 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
805012.
806
807"MAKE SERIAL NUMBER"
808
809I want to share a script to create an activation code on an application...
810
811Has 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
813But 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
815Applications 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
817There 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
819If 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
821To 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
823To find out the IMEI number we can use sysinfo module.
824
825Here is how to create a unique and different serial number on each phone by utilizing IMEI phone number.
826
827----------------------------------------------------------------------------------------
828import sysinfo
829imei = sysinfo.imei()
830code imei [2] + imei [0] + imei [12] + imei [9] + imei [3]
831code = int (code) +2011
832print the code
833----------------------------------------------------------------------------------------
834
835Explanation:
836In the process of processing IMEI
837imei [imei] + imei [12] + imei [9] + imei [3] means taking numbers from positions 3, to 1, 2, ke3 to 10 and 4 from IMEI.
838Eg IMEI 356664000736846
839SN or Serial number generated is 635676
840code = int (code) +2011 means converting the SN string to an integer then plus 2011.
841Rich gini 635676 2011 results 637687
842
843That'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
852013.
853
854"MAKE TRANSLATE ALA GOOGLE TRANSLATION"
855
856Dear...
857ANGELMAN% ANGELwoman,
858I want to share about how to create an online sentence translator application...
859
860Who 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
862Now we can use the service in python script easily.
863
864Let's make it, open the Python editor Ped, choose new-python.
865
866----------------------------------------------------------------------------------------
867import urllib
868text = 'I want to eat'
869langpair = 'en | en'
870base_url = 'http: //ajax.googleapis.com/ajax/services/language/translate?'
871data = urllib.urlencode ({'v': 1.2, 'ie': 'UTF16 ?,' q ': text.encode (' utf-8?), 'langpair': langpair})
872with the url being encoded
873url = base_url + dat a
874null = None
875hsl = urllib.urlopen (url) .read()
876of the opening of the url
877dic = eval (hsl)
878brada di var dic
879detail = dic ["responseDetails"]
880if detail == None:
881 resp = dic ["responseData"]
882 resp = resp ["translatedText"]
883else:
884 resp = detail
885print resp
886----------------------------------------------------------------------------------------
887
888
889
890
891==========
892
893
894
895014.
896
897"CUTTING PICTURE"
898
899I want to share a script to crop the image or croping image...
900
901In this article I will explain how to cut the image on pys60.
902
903Logically 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
905The script looks like this,
906
907----------------------------------------------------------------------------------------
908from graphics import *
909cut (= 10,10,110,110)
910source = Image.open ("c:\\image.jpg")
911sx, sy = source.size
912lx, ly, x, y = cut
913if x> sx:
914 x = sx
915if y> sy:
916 y = sy
917img = Image.new ((x-10, y-10))
918img.blit (source, cut)
919img.save ("c:\\pieces.jpg")
920----------------------------------------------------------------------------------------
921
922That's how to cut a very simple image on pys60.
923
924There 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
933015.
934
935"USE SPECIAL CHARACTER"
936
937I want to share how to insert a special character into an app...
938
939Have 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?
940Special characters will not run on pys60, unless we change the encoding into utf-8.
941
942How to decode is very easy, here's an example:
943
944----------------------------------------------------------------------------------------
945def dc (x):
946 return x.decode ('utf-8?,' ignore ')
947print dc ("khusus_karakter_disini")
948----------------------------------------------------------------------------------------
949
950For more convincing, please try it on appuifw.note
951
952
953
954
955==========
956
957
958
959016.
960
961"FILE HANDLING"
962
963I want to share how pys60 aar can open or read or write automatically...
964
965Anything 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
967The 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
969Here is a script for creating a text file in Python S60:
970
971----------------------------------------------------------------------------------------
972f = open ("c:\\document.txt", "w")
973text = u "Python S60\nSiky play python"
974f.write (text)
975f.close()
976----------------------------------------------------------------------------------------
977
978To 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
980And the word "\n" is to create a new line in the text.
981
982----------------------------------------------------------------------------------------
983f = open ("c:\\document.txt")
984print f.name
985print f.mode
986----------------------------------------------------------------------------------------
987
988In 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----------------------------------------------------------------------------------------
991f = open ("c:\\document.txt")
992print f.read()
993----------------------------------------------------------------------------------------
994
995The 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
997When we use the read method, the position of the file we open is at the end of the file.
998
999To 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----------------------------------------------------------------------------------------
1002f = open ("c:\\document.txt")
1003f.seek (0)
1004print f.readline()
1005print f.readline()
1006f.close()
1007----------------------------------------------------------------------------------------
1008
1009
1010
1011
1012==========
1013
1014
1015
1016017.
1017
1018"LIST"
1019
1020I want to share a way to create a list...
1021
1022List 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.
1023Example:
1024
1025----------------------------------------------------------------------------------------
1026list1 = ["Cat", "Bird", "Chicken"]
1027list2 = [23,54,87,78]
1028----------------------------------------------------------------------------------------
1029
1030-Using List:
1031Accessing items
1032print list1 [0] # will print the first element of list1 ie "cat"
1033print list2 [1] + list2 [0] # sum element list2 [1] list2 [0] the result is 77
1034Added items
1035Example:
1036
1037----------------------------------------------------------------------------------------
1038list1.append ("Duck")
1039----------------------------------------------------------------------------------------
1040
1041Added the string "duck" to list1. So, list1 now contains ["Cat", "Bird", "Chicken", "Duck"]
1042
1043Replace items
1044Example:
1045
1046----------------------------------------------------------------------------------------
1047a = [12,22,32,42,52,62]
1048a [2] = 10M
1049----------------------------------------------------------------------------------------
1050
1051Replacing the 3rd element is 32 to 10. So now list a contains [12,22,10,42,52,62]
1052
1053Deleting items
1054Example:
1055
1056----------------------------------------------------------------------------------------
1057del a [3]
1058----------------------------------------------------------------------------------------
1059
1060Removing the third element is 52
1061Other functions
1062
1063Reverses the list element
1064Example:
1065
1066----------------------------------------------------------------------------------------
1067a.reverse()
1068----------------------------------------------------------------------------------------
1069
1070Sort the list in descending order
1071Example:
1072
1073----------------------------------------------------------------------------------------
1074a.sort (reverse = False)
1075----------------------------------------------------------------------------------------
1076
1077Sort the list in descending order
1078Example:
1079
1080----------------------------------------------------------------------------------------
1081acsending
1082a.sort (reverse = True)
1083----------------------------------------------------------------------------------------
1084
1085
1086
1087
1088==========
1089
1090
1091
1092018.
1093
1094"DICTIONARY"
1095
1096I want to share a script to print or print a text...
1097
1098Dictionary 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----------------------------------------------------------------------------------------
1103dict1 = ("name": "agus", "age": 16 ", address": "indramayu")
1104----------------------------------------------------------------------------------------
1105
1106Dictionary 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----------------------------------------------------------------------------------------
1111print dict1 ["name"]
1112----------------------------------------------------------------------------------------
1113
1114This will print the string "Agus"
1115
1116-Adding Elements:
1117
1118----------------------------------------------------------------------------------------
1119dict1 ["Phone"] = "62838000000?
1120----------------------------------------------------------------------------------------
1121
1122-Remove Element:
1123
1124----------------------------------------------------------------------------------------
1125del dict1 ['address']
1126----------------------------------------------------------------------------------------
1127
1128-Listing all keys
1129
1130----------------------------------------------------------------------------------------
1131k = dict1.keys()
1132----------------------------------------------------------------------------------------
1133
1134Will display ['age', 'no. Phone ',' name ']
1135
1136----------------------------------------------------------------------------------------
1137v = dict1.values ​​()
1138----------------------------------------------------------------------------------------
1139
1140Will display [16, '62838000000,' Agus']
1141
1142
1143
1144
1145==========
1146
1147
1148
1149019.
1150
1151"DICTIONARY and LIST"
1152
1153I want to share the combination between Dict and List...
1154
1155Dictdictionary or dict has pair value. in the use of the code using kurawa brackets {}.
1156Example:
1157
1158----------------------------------------------------------------------------------------
1159identity = {'name': 'wawan', 'age': 20, 'address': 'jakarta'}
1160print identity ['name']
1161----------------------------------------------------------------------------------------
1162
1163the result:
1164Wawan
1165
1166----------------------------------------------------------------------------------------
1167print identity ['address']
1168----------------------------------------------------------------------------------------
1169
1170the result:
1171Jakarta
1172
1173List (list)
1174List or list in use use [].
1175Example:
1176
1177----------------------------------------------------------------------------------------
1178fruit = ['apple', 'banana', 'pineapple']
1179print fruit [0]
1180----------------------------------------------------------------------------------------
1181
1182the result:
1183Apple
1184
1185because the first order of the list in pys60 starts from 0 then 1.2 and so on.
1186
1187-Added data
1188
1189----------------------------------------------------------------------------------------
1190buah.append ('watermelon')
1191----------------------------------------------------------------------------------------
1192
1193result then list fruit into fruit = ['apple', 'banana', 'pineapple', 'watermelon']
1194
1195-Delete data
1196
1197----------------------------------------------------------------------------------------
1198buah.pop (0)
1199----------------------------------------------------------------------------------------
1200
1201The pop function will delete data from the fruit variables in the order they are,
1202so the fruit list now contains ['banana', 'pineapple']
1203
1204----------------------------------------------------------------------------------------
1205fruit = ['apple', 'banana', 'pineapple']
1206buah.remove ('apple')
1207----------------------------------------------------------------------------------------
1208
1209The remove function will delete data from the fruit variable by its name.
1210
1211-Sort data
1212
1213----------------------------------------------------------------------------------------
1214number = [1,8,4,6.7]
1215number.sort()
1216----------------------------------------------------------------------------------------
1217
1218
1219
1220
1221==========
1222
1223
1224
1225020.
1226
1227"2D IMAGES"
1228
1229I want to share how to create 2D images...
1230
1231Basically 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
1233Looping 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
1235Make 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
1236example:
1237
1238----------------------------------------------------------------------------------------
1239img.rectangle ((50, 20, 70, 60), 0x00dddd, fill = 0xdd0000)
1240----------------------------------------------------------------------------------------
1241
1242To ellipse the code is almost the same as making a box.
1243Example:
1244
1245----------------------------------------------------------------------------------------
1246img.ellipse ((50, 70, 80, 90), 0xdd0000, fill = 0x00dd00)
1247----------------------------------------------------------------------------------------
1248
1249Creating Point
1250In contrast to ellips and rectangle, use only X coordinates, its y only and width (Point width)
1251example:
1252
1253----------------------------------------------------------------------------------------
1254img.point ((200, 100), 0x0000dd, width = 10)
1255----------------------------------------------------------------------------------------
1256
1257Creating Line
1258Create a line connecting between 2 points of coordinates. then the regulator: (x1, y1, x2, y2)
1259example:
1260
1261----------------------------------------------------------------------------------------
1262img.line ((20, 20, 120, 20), 0xdddd00)
1263----------------------------------------------------------------------------------------
1264
1265Creating Text
1266To make the writing settings like this: ((x, y), u'text to write ')
1267example:
1268
1269----------------------------------------------------------------------------------------
1270img.text ((60, 300), 0x00dd00)
1271----------------------------------------------------------------------------------------
1272
1273Practice:
1274
1275----------------------------------------------------------------------------------------
1276import appuifw
1277import graphics
1278import 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----------------------------------------------------------------------------------------
1286def close():
1287 global run
1288 run = 0
1289----------------------------------------------------------------------------------------
1290
1291-Set the softkey button to run the "close" definition when pressed.
1292
1293----------------------------------------------------------------------------------------
1294appuifw.app.exit_key_handler = close
1295----------------------------------------------------------------------------------------
1296
1297-Creates a "c" variable that contains the canvas of the appuifw module
1298
1299----------------------------------------------------------------------------------------
1300c = appuifw.Canvas()
1301----------------------------------------------------------------------------------------
1302
1303-Set the application body to the canvas
1304
1305----------------------------------------------------------------------------------------
1306appuifw.app.body = c
1307----------------------------------------------------------------------------------------
1308
1309-Screen size "full screen"
1310
1311----------------------------------------------------------------------------------------
1312appuifw.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----------------------------------------------------------------------------------------
1319img.graphics.Image.new ((240,320))
1320----------------------------------------------------------------------------------------
1321
1322-Run is a variable that acts as an application closing regulator.
1323
1324----------------------------------------------------------------------------------------
1325run = 1
1326----------------------------------------------------------------------------------------
1327
1328-Creates a while function.
1329
1330----------------------------------------------------------------------------------------
1331while 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
1381Note:
1382Signs is the number of spaces.
1383The size of the letters, symbols, and spaces must be the same as the ones written above.
1384
1385
1386
1387
1388==========
1389
1390
1391
1392021.
1393
1394"WRITE TEXT AND TITLE ON APPLICATIONS"
1395
1396I 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----------------------------------------------------------------------------------------
1401import appuifw, e32
1402----------------------------------------------------------------------------------------
1403
1404-Creates application title
1405
1406----------------------------------------------------------------------------------------
1407appuifw.app.title = u "APPLICATIONS"
1408----------------------------------------------------------------------------------------
1409
1410-Creates a text-call function
1411
1412----------------------------------------------------------------------------------------
1413t = appuifw.text()
1414----------------------------------------------------------------------------------------
1415
1416-Setting up the text function as the application body
1417
1418----------------------------------------------------------------------------------------
1419appuifw.app.body = t
1420----------------------------------------------------------------------------------------
1421
1422-Adjust the display application using the screen function, there are 3 types of large, normal, full
1423
1424----------------------------------------------------------------------------------------
1425appuifw.app.screen = "normal"
1426----------------------------------------------------------------------------------------
1427
1428-Set the text color
1429
1430----------------------------------------------------------------------------------------
1431t.color = 0xEE00DD
1432----------------------------------------------------------------------------------------
1433
1434-Set the highlight color
1435
1436----------------------------------------------------------------------------------------
1437t.highlight_color = 0xFFFF00
1438----------------------------------------------------------------------------------------
1439
1440-Set the font ie font name, size (size), flag (sorry this is not know its function)
1441
1442----------------------------------------------------------------------------------------
1443t.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----------------------------------------------------------------------------------------
1449t.style = (appuifw.STYLE_HIGHLIGHT_STANDARD | appuifw.STYLE_BOLD | appuifw.STYLE_STRIKETHROUGH)
1450----------------------------------------------------------------------------------------
1451
1452-Writing the desired text
1453
1454----------------------------------------------------------------------------------------
1455t.set (u "Haaloo Broww ..")
1456----------------------------------------------------------------------------------------
1457
1458-Create an active object
1459
1460----------------------------------------------------------------------------------------
1461app_lock = e32.Ao_lock()
1462----------------------------------------------------------------------------------------
1463
1464-Creating a function to exit the application
1465
1466-----------------------------------------------------------------------------------------
1467def quit():
1468 app_lock.signal()
1469 appuifw.app. set.exit()
1470----------------------------------------------------------------------------------------
1471
1472-Creating the exit button on the softkey
1473
1474----------------------------------------------------------------------------------------
1475appuifw.app.exit_key_handler = quit
1476----------------------------------------------------------------------------------------
1477
1478-Wait for the command from the softkey to exit
1479
1480-----------------------------------------------------------------------------------------
1481app_lock.wait()
1482-----------------------------------------------------------------------------------------
1483
1484
1485
1486
1487==========
1488
1489
1490
1491022.
1492
1493"FUNCTION OF FORUM"
1494
1495I want to share about the iteration function for on pys60 script...
1496
1497Looping 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
1499For
1500just take the example to be easy to understand.
1501Example 1:
1502
1503----------------------------------------------------------------------------------------
1504for i in range (10):
1505 print i
1506----------------------------------------------------------------------------------------
1507
1508Then the result will print 10 numbers from 0- 9 instead of 1-10, since the integer value starts from the number 0.
1509
1510Example 2:
1511
1512-----------------------------------------------------------------------------------------
1513x = 4
1514for t in range (x):
1515 test print [t]
1516-----------------------------------------------------------------------------------------
1517
1518result of
1519test
1520test
1521test
1522test
1523
1524Will print test as much as x that is 4.
1525
1526Example 3:
1527
1528----------------------------------------------------------------------------------------
1529txt = unicode ('test')
1530for z in range (len (txt)):
1531 print txt [z]
1532----------------------------------------------------------------------------------------- the
1533
1534result
1535t
1536e
1537s
1538
1539The len function here is to know the amount of data from txt.
1540Example:
1541
1542----------------------------------------------------------------------------------------
1543txt = unicode ('test')
1544len (txt )
1545---------------------------------------------------------------------------------------- The
1546
1547result
15483
1549
1550
1551
1552
1553==========
1554
1555
1556
1557023.
1558
1559"IF CONDITION"
1560
1561I want to share funsi if in script pys60...
1562
1563The if command is used to create a condition in pys60.
1564if illustrated would be like this example...
1565
1566If eating then it will be full, if drink will be bloated, otherwise all will die
1567
1568If word is replaced if if code in pys60 it will be like this:
1569
1570-----------------------------------------------------------------------------------------
1571txt = unicode ('test')
1572if eating:
1573 full of
1574drinking elves:
1575> > kembung
1576else:
1577 moddar
1578----------------------------------------------------------------------------------------
1579
1580(symbol is the number of spaces)
1581
1582Now we try to apply in the script
1583Example:
1584
1585----------------------------------------------------------------------------------------
1586txt = unicode (' test ')
1587value = 70
1588if value> 80:
1589 print' smart '
1590if value> 60:
1591 print' pretty '
1592else:
1593 print' must learn a lot '
1594----------------------------------------------------------------------------------------- The
1595
1596space 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
1605024.
1606
1607"MENU, SUBMENU and POPUP MENU"
1608
1609I want to share a way to make memu , submenu or popup menu for an application...
1610
1611Creating Application Menu
1612-Module used is appuifw, and e32
1613
1614-----------------------------------------------------------------------------------------
1615import appuifw, e32
1616-----------------------------------------------------------------------------------------
1617
1618-Define: create its own function for application menu.
1619
1620----------------------------------------------------------------------------------------
1621def item1():
1622 appuifw.note (u "learn python", "info")
1623
1624def item2():
1625 appuifw.note (u "basic lesson", "info")
1626-----------------------------------------------------------------------------------------
1627
1628-Make a function to exit when pressing the right softkey button.
1629
1630----------------------------------------------------------------------------------------
1631def quit():
1632 app_lock.signal() )
1633----------------------------------------------------------------------------------------
1634
1635Information:
1636Spacebar 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-----------------------------------------------------------------------------------------
1642appuifw.app.menu = [(u "one", item1), (u "two", item2)]
1643-----------------------------------------------------------------------------------------
1644
1645-Creating exit button
1646
1647-----------------------------------------------------------------------------------------
1648appuifw.app.exit_key_handler = quit
1649-----------------------------------------------------------------------------------------
1650
1651-Create an active object
1652
1653----------------------------------------------------------------------------------------
1654app-lock = e32.Ao_loch()
1655-----------------------------------------------------------------------------------------
1656
1657-Get started time
1658
1659-----------------------------------------------------------------------------------------
1660app_lock.wait()
1661-----------------------------------------------------------------------------------------
1662
1663Detailed to be:
1664
1665-----------------------------------------------------------------------------------------
1666import appuifw, e32
1667def item1():
1668 appuifw.note (u "learn python", "info")
1669def item2():
1670 appuifw.note (u "basic lesson" ,"info")
1671def quit():
1672 app_lock.signal()
1673appuifw.app.menu = [(u "menu1", item1), (u "menu2", item2)]
1674appuifw.app.exit_key_handler = quit
1675app-lock = e32.Ao_lock()
1676app_lock.wait()
1677----------------------------------------------------------------------------------------
1678
1679Creating SubMenu
1680- The same way to create an app menu just adds menus in a menu like this (menu1, (submenu1, submenu2), men2, (submenu1, submenu2))
1681Example code:
1682
1683-----------------------------------------------------------------------------------------
1684appuifw.app.menu = [(u "menu1", ((u "submenu1", item1), (u, "submenu2" , item2)), (u "menu2", ((u "submenu1",item1), (u "submenu2", item2))))]
1685----------------------------------------------------------------------------------------
1686
1687Create a pop-up menu
1688-Module used appuifw
1689
1690-----------------------------------------------------------------------------------------
1691import appuifw
1692-----------------------------------------------------------------------------------------
1693
1694-Creating a list with contents from Pop-up
1695
1696-----------------------------------------------------------------------------------------
1697L = [u "Python", u "Symbian", u "java"]
1698-----------------------------------------------------------------------------------------
1699
1700-Create a pop-up menu including lists and labels
1701
1702----------------------------------------------------------------------------------------
1703appuifw.popup_menu (list, label)
1704
1705test = 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
1709selected
1710-Efforts some actions (here we print something())
1711
1712-----------------------------------------------------------------------------------------
1713if test == 0:
1714 appuifw.note (u "Python, yes", "info")
1715elif test == 1:
1716 appuifw.note (u "Symbian, ok", "info")
1717elif test == 2:
1718 appuifw.note(u"belajar java", "info")
1719---------------------------------------------------------------------------------------
1720
1721Information:
1722The number 0 shows the first sequence in the Python List, then the number 1 denotes the second sequence of Symbian, and so on.
1723
1724full examples of the code to be
1725
1726----------------------------------------------------------------------------------------
1727import appuifw
1728L = [u "Python" , u "Symbian", u "java"]
1729test = appuifw.popup_menu (L, u "Options")
1730if test == 0:
1731 appuifw.note (u "Python yes", "info")
1732elif test == 1:
1733 appuifw.note (u "symbian, ok", "info")
1734elif test == 2:
1735 appuifw.note (u "learn java", "info")
1736----------------------------------------------------------------------------------------
1737
1738
1739
1740
1741==========
1742
1743
1744
1745025.
1746
1747"ME-MINIMIZEKAN A PROGRAM USING SCRIPT PYS60"
1748
1749I want to share a script to minimize the program we are currently open...
1750
1751----------------------------------------------------------------------------------------
1752import appswitch
1753appswitch .switch_to_bg (appswitch.application_list (1) [0])
1754----------------------------------------------------------------------------------------
1755
1756
1757
1758==========
1759
1760
1761
1762026.
1763
1764"MAKE PASSWORD SCRIPT PYS60"
1765
1766I want to share a script to create a password on app...
1767
1768----------------------------------------------------------------------------------------
1769import appuifw
1770import os
1771
1772def open():
1773 appuifw.note (u'Success... ',' conf ')
1774
1775def 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
1788start pass()
1789----------------------------------------------------------------------------------------
1790
1791
1792
1793==========
1794
1795
1796
1797027.
1798
1799"SCRIPT PY TO SHOW BATTERY WATER"
1800
1801I want to share a script to show low battery status or weak...
1802
1803We write first scrit it using the application ped or x-plore.
1804
18051. Open the ped application and press the File> New> Python option, then a blank or blank HP screen will appear.
1806
18072. Then write his py script as needed and according to the procedure. Like this:
1808
1809----------------------------------------------------------------------------------------
1810import globalui
1811import e32
1812import appuifw
1813
1814x = appuifw.query (u'Enter Time (in seconds): ',' number ')
1815e32.ao_sleep (x)
1816globalui.global_note (u' ',' battery_low ')
1817-----------------------------------------------------------------------------------------
1818
18193. If everything is written then you just press the selection button then select 'Run', finish.
1820
1821Here's an example of the complete script:
1822----------------------------------------------------------------------------------------
1823import 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
1832028.
1833
1834"SCRIPT SIMPLE MAKES POPUP MENU"
1835
1836I want to share a simple script to create popup memu...
1837
1838----------------------------------------------------------------------------------------
1839import appuifw
1840import os
1841
1842def poultry() : appuifw.note (u'ayam, bird, etc ',' info ')
1843def song(): appuifw.note (u'valley of the damned, fury of the storm', 'info')
1844def kel(): os .abort()
1845
1846
1847a = [u'Unggas ', u'Lagu', u'Sign out ']
1848g = appuifw.popup_menu (a, u'Menuen')
1849if g == 0:poultry()
1850if g == 1: song()
1851if g == 2: kel()
1852---------------------------------------------------------------------------------------
1853
1854
1855
1856==========
1857
1858
1859
1860029.
1861
1862"READING FILE WITH MODULE POWLITE FM"
1863
1864I want to share a script to read mp3 file...
1865
1866-Module required
1867
1868----------------------------------------------------------------------------------------
1869import powlite_fm as fm
1870import audio as a
1871----------------------------------------------------------------------------------------
1872
1873-The command opens the file manager
1874
1875-----------------------------------------------------------------------------------------
1876n = 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----------------------------------------------------------------------------------------
1882f = n.AskUser (ext = ['.mp3' ])
1883----------------------------------------------------------------------------------------
1884
1885- The command opens the file and plays it and the volume level is 5
1886Ket : a.Sound.open is the command to open the sound file, (f) is a function to read the file manager on hp
1887
1888-----------------------------------------------------------------------------------------
1889s = a.Sound.open (f)
1890s.play()
1891s.set_volume(5)
1892---------------------------------------------------------------------------------------
1893
1894
1895
1896
1897==========
1898
1899
1900
1901030.
1902
1903"CHANGING SIZE OF IMAGES USING SCRIPT"
1904
1905I want to share a script to resize image...
1906
1907----------------------------------------------------------------------------------------
1908import appuifw
1909import e32
1910from graphics import *
1911
1912images = Image.open ("e:\\test.jpg")
1913image = image.resize ((176, 208))
1914gambar.save ("e:\\save.jpg" )
1915
1916def handel (rect):
1917> > x.blit (image)
1918x = appuifw.Canvas (redraw_callback = handel)
1919appuifw.app.body = x
1920y = e32.Ao_lock()
1921y.wait()
1922---------------------------------------------------------------------------------------
1923
1924
1925
1926
1927
1928==========
1929
1930
1931
1932031.
1933
1934"USE OF SCRIPT PASSWORD ON AN APPLICATION"
1935
1936I want to share how to create a password on an app...
1937
1938-Module required
1939
1940----------------------------------------------------------------------------------------
1941import appuifw
1942import e32
1943import os
1944----------------------------------------------------------------------------------------
1945
1946-Function define calling and filling name and password
1947
1948-----------------------------------------------------------------------------------------
1949def 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-----------------------------------------------------------------------------------------
2002def 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----------------------------------------------------------------------------------------
2013def b():
2014 bb = u ' experiment script using password '
2015 print bb
2016----------------------------------------------------------------------------------------
2017
2018-Function to exit the app
2019
2020----------------------------------------------------------------------------------------
2021def ex():
2022 os.abort()
2023----------------------------------------------------------------------------------------
2024
2025-Function to run the opening of the application first run
2026
2027----------------------------------------------------------------------------------------
2028def 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----------------------------------------------------------------------------------------
2043def menu():
2044 appuifw.app.menu = [(u'test ', a), (u'testing',b)]
2045----------------------------------------------------------------------------------------
2046
2047-Function calling password
2048
2049----------------------------------------------------------------------------------------
2050start()
2051-----------------------------------------------------------------------------------------
2052
2053-Function calling menu
2054
2055-----------------------------------------------------------------------------------------
2056menu()
2057-----------------------------------------------------------------------------------------
2058
2059-Function command exits
2060
2061----------------------------------------------------------------------------------------
2062appuifw .app.exit_key_handler = ex
2063----------------------------------------------------------------------------------------
2064
2065-Alocking app
2066
2067----------------------------------------------------------------------------------------
2068z = e32.Ao_lock()
2069z.wait()
2070-----------------------------------------------------------------------------------------
2071
2072Note:
2073 Is the number of spaces used.
2074
2075
2076
2077==========
2078
2079
2080
2081032.
2082
2083"SCRIPT PY TO DISPLAY FILE"
2084
2085I want to share a script to back up file...
2086
2087----------------------------------------------------------------------------------------
2088import appuifw
2089import e32
2090import os
2091import powlite_fm as p
2092
2093def 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')
2105double()
2106-----------------------------------------------------------------------------------------
2107
2108
2109
2110
2111==========
2112
2113
2114
2115033.
2116
2117"MULTI SELECTION LIST"
2118
2119I want to share scrip to display search file or check box...
2120
21211. 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----------------------------------------------------------------------------------------
2124import appuifw
2125
2126Girl = [u'Gina ', u'Nina ', u'Dina', u'Lena ', u'Rena', u'Raisya ', u'Risa', u'Siska ']
2127
2128tm = appuifw.multi_selection_list (Girls, style =' checkbox 'search_field = 1)
2129
2130
2131for i in tm:
2132 print Girl [i]
2133----------------------------------------------------------------------------------------
2134
2135Note:
2136Replace mark> with a space.
2137
2138
2139
2140==========
2141
2142
2143
2144034.
2145
2146"AUDIO (PLAYING MP3 1 FOLDER)"
2147
2148I want to share a script untuj play mp3 in 1 piece folder...
2149
2150----------------------------------------------------------------------------------------
2151Import Appuifw
2152import audio
2153import e32
2154import os
2155
2156dir = 'E:\\Music'
2157for the song in os.listdir (dir):
2158 s = audio.Sound.open (os.
2159path.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
2171s.stop()
2172s.close()
2173----------------------------------------------------------------------------------------
2174
2175Note:
2176Alerts> replace with a space.
2177
2178
2179
2180==========
2181
2182
2183
2184035.
2185
2186"FILLING LESS NAME OF AND MORE THAN 5 CHARACTERS"
2187
2188I want to share the way make popup menu filling name less than 5 letters or more than 5 letters...
2189
2190-----------------------------------------------------------------------------------------
2191import appuifw as z
2192
2193x = z.query (u'Name ',' text ')
2194if x:
2195 if len (x)> 5:
2196 z.note (u'Max 5 ',' error ')
2197 else:
2198 z.note (x,' conf ')
2199
2200y = z.query (u'Nama', 'text')
2201if y:
2202>>if len (y) <5:
2203 z.note (u'Max 5 ',' error ')
2204 else:
2205 z.note (y, 'conf')
2206-----------------------------------------------------------------------------------------
2207
2208Note:
2209Replace mark> with a space.
2210
2211
2212
2213==========
2214
2215
2216
2217036.
2218
2219"MULTI_QUERY"
2220
2221I want to share a script for print or print more than 1 text...
2222
2223----------------------------------------------------------------------------------------
2224import appuifw as R
2225x, y = R .multi_query (u'Name: ', u'Umur:')
2226print x
2227print y
2228-----------------------------------------------------------------------------------------
2229
2230
2231
2232==========
2233
2234
2235
2236037.
2237
2238"SIMPLE FORM"
2239
2240I want to share about the form function in a pys60 script. ..
2241
2242----------------------------------------------------------------------------------------
2243import appuifw
2244
2245x = appuifw.FFormDoubleSpaced | appuifw.FFormEditModeOnly
2246y = [u'Kuda ', u'Monkey', u'Angjing ', u'Babi', u'Ayam ']
2247x1 = [(u'Name Animals', 'combo', (y, 0) )]
2248y1 = appuifw.Form (x1, x)
2249y1.execute()
2250z = y1 [0] [2] [1]
2251appuifw.query ('' Print Result ',' text ', u' '+ y [z])
2252----------------------------------------------------------------------------------------
2253
2254
2255
2256
2257
2258==========
2259
2260
2261
2262038.
2263
2264"MAKE PROGRESSBAR"
2265
2266I want to share a script to create a progress bar...
2267
2268----------------------------------------------------------------------------------------
2269import prog, e32, appuifw
2270wt = prog.ProgressNote()
2271wt.wait()
2272wt.update (0, u'Loading... ')
2273e32.ao_sleep (5)
2274wt.finish()
2275appuifw.note (u'Success...', 'conf')
2276-----------------------------------------------------------------------------------------
2277
2278
2279
2280
2281
2282==========
2283
2284
2285
2286039.
2287
2288" DISPLAYING APPLICATIONS THAT HAVE BEEN INSTALLED IN THE FORM OF LIST"
2289
2290I 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
2292Just go the script below,
2293
2294----------------------------------------------------------------------------------------
2295import 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
2298This is the complete script,
2299----------------------------------------------------------------------------------------
2300import appist
2301import appuifw
2302import laa
2303
2304def 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)
2316app_list()
2317-----------------------------------------------------------------------------------------
2318
2319
2320
2321
2322==========
2323
2324
2325
2326040.
2327
2328"CALLING IMAGES WITH MODULE FROM GRAPHICS IMPORT *"
2329
2330I 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-----------------------------------------------------------------------------------------
2335import appuifw
2336import e32
2337from graphics import *
2338----------------------------------------------------------------------------------------
2339
2340-To change the screen size available normal, large and full
2341
2342----------------------------------------------------------------------------------------
2343appuifw.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-----------------------------------------------------------------------------------------
2349Image = Image.open ("e:\\test.jpg" )
2350----------------------------------------------------------------------------------------
2351
2352-Set the drawing called to be displayed
2353
2354-----------------------------------------------------------------------------------------
2355def handle_redraw (rect):
2356 x.blit (Figure) # use 4 spaces
2357----------------------------------------------------------------------------------------
2358
2359-Canvas and body assignments to display
2360
2361-----------------------------------------------------------------------------------------
2362x = appuifw.Canvas (redraw_callback = handle_redraw)
2363appuifw.app.body = x
2364----------------------------------------------------------------------------------------
2365
2366-Clock usage
2367
2368-----------------------------------------------------------------------------------------
2369y = e32.Ao_lock()
2370y.wait()
2371-----------------------------------------------------------------------------------------
2372
2373
2374
2375
2376
2377==========
2378
2379
2380
2381041.
2382
2383"SCRIPT CUTTING FILE TXT"
2384
2385I want to share how to call or insert a file. txt into an app...
2386
2387-Module required
2388
2389----------------------------------------------------------------------------------------
2390Import Appuifw
2391import e32
2392----------------------------------------------------------------------------------------
2393
2394-Text of the txt file you want to call
2395
2396-----------------------------------------------------------------------------------------
2397Text = 'e:\\test.txt'
2398----------------------------------------------------------------------------------------
2399
2400-Members calling on module
2401
2402-----------------------------------------------------------------------------------------
2403x = appuifw.Content_handler()
2404-----------------------------------------------------------------------------------------
2405
2406-Explore x on the module to open the txt file
2407
2408-----------------------------------------------------------------------------------------
2409x.open (text)
2410-----------------------------------------------------------------------------------------
2411
2412-Mode sleep
2413
2414----------------------------------------------------------------------------------------
2415e32.ao_sleep (10)
2416---------------------------------------------------------------------------------------
2417
2418
2419
2420
2421
2422==========
2423
2424
2425
2426042.
2427
2428"SCRIPT TEXT BECOME VOICE"
2429
2430I want to share a script that can change the text into sound...
2431
2432-Module required
2433
2434----------------------------------------------------------------------------------------
2435import appuifw
2436import audio
2437-----------------------------------------------------------------------------------------
2438
2439-The query function for writing text on a popup screen
2440
2441-----------------------------------------------------------------------------------------
2442text = appuifw.query (u'Enter the text: ',' text')
2443----------------------------------------------------------------------------------------
2444
2445-The order to call a voice or read a text
2446
2447-----------------------------------------------------------------------------------------
2448audio.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
2453Continue to write the above command, save when finished, keep moving to python folder ..
2454
2455How 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
2457Note:
2458-Text not abbreviated.
2459-Not all HP suport with this script.
2460
2461
2462
2463==========
2464
2465
2466
2467043.
2468
2469"SCRIPT UNTUK MEMANGGIL dan MEMBUKA APLIKASI di LUAR SYSTEM APLIKASI"
2470
2471Saya mau share sebuah script yang fungsinya untuk memanggil aplikasi diluar system aplikasi...
2472
2473-Module yang dibutuhkan
2474
2475---------------------------------------------------------------------------------------
2476import appuifw
2477import e32
2478---------------------------------------------------------------------------------------
2479
2480-Fungsi define pemanggilan aplikasi
2481
2482---------------------------------------------------------------------------------------
2483def test():
2484 e32.start_exe ('z:\\system\\programs\\apprun.exe', 'e:\\COBA\\vbag\\vbag.app')
2485-----------------------------------------------------------------------------------------
2486
2487-Feature menu
2488
2489-----------------------------------------------------------------------------------------
2490appuifw.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----------------------------------------------------------------------------------------
2496lock = e32.Ao_lock()
2497lock.wait()
2498----------------------------------------------------------------------------------------
2499
2500Information:
2501Tanda ini dimaksudkan supaya menggunakan 4 spasi.
2502
2503e32.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
2507Untuk pemanggilan aplikasi bisa ditambah sebanyak yang kalian mau.
2508Ingat pindahkan folder aplikasi ke folder yang sudah disiapkan sebelumnya.
2509
2510
2511
2512
2513
2514==========
2515
2516
2517
2518044.
2519
2520"SCRIPT UNTUK MEMAINKAN MP3 PADA FUNGSI DEFINE"
2521
2522Saya mau share script python yang berfungsi untuk memutar mp3...
2523
2524-Module yang diperlukan
2525
2526---------------------------------------------------------------------------------------
2527import appuifw
2528import e32
2529import audio
2530---------------------------------------------------------------------------------------
2531
2532-Fungsi define untuk menjalankan sebuah mp3
2533
2534---------------------------------------------------------------------------------------
2535
2536def 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----------------------------------------------------------------------------------------
2546def 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---------------------------------------------------------------------------------------
2556appuifw.app.menu = [(u"Putar", main), (u"Berhenti", henti)]
2557---------------------------------------------------------------------------------------
2558
2559-Fungsi untuk modus stanby atau mengunci saat pada aplikasi dibuka
2560
2561---------------------------------------------------------------------------------------
2562script_lock = e32.Ao_lock()
2563script_lock.wait()
2564---------------------------------------------------------------------------------------
2565
2566Ingat tanda menunjukan 4 spasi.
2567
2568
2569
2570
2571
2572==========
2573
2574
2575
2576045.
2577
2578"MEMANGGIL TEXT MENGGUNAKAN MODULE GLOBALUI PADA SCRIPT PYTHON"
2579
2580Saya mau share sebuah script untuk memanggil text atau menulis text dengan module globalui...
2581
2582-Module yang diperlukan
2583
2584---------------------------------------------------------------------------------------
2585import globalui
2586---------------------------------------------------------------------------------------
2587
2588-Pemanggilan scriptnya seperti ini.
2589
2590---------------------------------------------------------------------------------------
2591globalui.global_msg_query(u'test', u'coba' )
2592----------------------------------------------------------------------------------------
2593
2594Ket: 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,
2595Example:
2596
2597----------------------------------------------------------------------------------------
2598def about():
2599 globalui.global_msg_query (u'test ',' try ')
2600-----------------------------------------------------------------------------------------
2601
2602
2603
2604==========
2605
2606
2607
2608046.
2609
2610"CARA MEMASUKKAN MUSIK atau MP3 ke DALAM SEBUAH APLIKASI PYTHON"
2611
2612Saya mau share cara membuat sebuah aplikasi ada musik ketika aplikasi tersebut dibuka...
2613
2614Pertama 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 )
2615Contoh:
2616
2617---------------------------------------------------------------------------------------
2618import linkapper
2619---------------------------------------------------------------------------------------
2620
2621Setelah ketemu file default.pynya kalian edit menggunakn x-plore atau yang lain, buka file default.pynya lalu ganti menjadi seperti dibawah ini:
2622
2623---------------------------------------------------------------------------------------
2624import e32,imp,appuifw,audio
2625s = audio.Sound.open('e:\\system\\mp3\\dragonforce\\trail of broken heart.mp3' )
2626s.play()
2627def go():
2628import linkapper
2629e32.ao_sleep(0,go)
2630del e32,go
2631---------------------------------------------------------------------------------------
2632
2633Note:
2634Saya tegaskan kembali nama folder mp3nya harus jelas dan nama aplikasinya juga harus dicantumkan.
2635
2636
2637
2638
2639
2640==========
2641
2642
2643
2644047.
2645
2646"DASAR URUTAN KODE LOGIC GAME"
2647
2648Saya mau share tentang urutan kode logic game...
2649
2650Program 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
2657Objek 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
2660Contoh logic gameplay misalnya: proses tumbukan, pengecekan gameover, penambahan skor, dll.
2661
2662- Render
2663Render adalah proses menampilkan objek ke layar setelah diupdate
2664
2665Jika tahapan-tahapan diatas terbalik dapat menjadi bug.
2666
2667Contoh kasus:
2668Pada 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
2674Jika urutannya terbalik misalnya seperti ini:
2675
2676- karakter berjalan
2677- render karakter
2678- logic tumbukan dengan tembok
2679
2680Maka yang terjadi karakter berjalan masuk beberapa piksel (tergantung kecepatan berjalan) kedalam tembok lalu kembali kedepan tembok. Tidak langsung berheti didepan tembok.
2681
2682Itulah contoh dasar urutan kode logic game.
2683
2684
2685
2686
2687
2688==========
2689
2690
2691
2692048.
2693
2694"MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.1)
2695
2696Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
2697
2698Saat 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
2700Note:
2701Ganti semua tanda">"pada awal baris disetiap script ditutorial ini dengan spasi.
2702
2703-Kordinat 2D
2704Setiap titik 2D terdiri dari dua kordinat. Dalam kartesian disebut X dan Y.
2705
2706X 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
2708Sebuah objek 3D yang dapat dirotasi mempunyai titik pusat rotasi. Untuk itu komputasi vektor digunakan untuk menentukan kordinat suatu objek pada layar.
2709
2710Titik 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:
2711x = VertexX+PosX
2712y = VertexY+PosY
2713
2714Script implementasi vektor
2715
2716---------------------------------------------------------------------------------------
2717import math,e32,key,appuifw, graphics
2718
2719def quit():
2720 global run
2721 run=0
2722
2723appuifw.app.screen ='full'
2724run = 1
2725appuifw.app.body = c = appuifw.Canvas()
2726appuifw.app.exit_key_handler=quit
2727img = graphics.Image.new(c.size)
2728
2729PX = c.size[0]/2
2730PY = c.size[1]/2
2731Size = 6
2732VX = [-40, 40, -40, 40]
2733VY = [-40, -40, 40, 40]
2734
2735while run:
2736
2737img.clear(0)
2738for 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---------------------------------------------------------------------------------------
2753img.point((PX,PY),0xff0000,width=4)
2754c.blit(img)
2755e32.ao_yield()
2756---------------------------------------------------------------------------------------
2757
2758Pada 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.
2759Rotasi 2D
2760
2761Sampai 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
2763Rotasi kekanan 20 derajat. Untuk menghitung nilai rotasi kordinat VX dan VY (garis berwarna cyan) dipakai rumus:
2764
2765XR = VX[n]*cos(ra) - VY[n]*sin(ra)
2766YR = 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
2770implementasi rotasi 2D
2771
2772---------------------------------------------------------------------------------------
2773import math,e32,key,appuifw, graphics
2774
2775def quit():
2776 global run
2777 run=0
2778
2779appuifw.app.screen ='full'
2780run = 1
2781appuifw.app.body = c = appuifw.Canvas()
2782appuifw.app.exit_key_handler=quit
2783img = graphics.Image.new(c.size)
2784
2785PX = c.size[0]/2
2786PY = c.size[1]/2
2787Size = 6
2788VX = [-40, 40, -40, 40]
2789VY = [-40, -40, 40, 40]
2790ANGLEZ = 0
2791
2792while run:
2793---------------------------------------------------------------------------------------
2794
2795-Konversi angle ke radian
2796
2797---------------------------------------------------------------------------------------
2798raz = 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
2836Pada baris kode:
2837XR = VX[n]*cosz - VY[n]*sinz - VX[n]
2838Ada 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:
2839x = VX[n]+PX+XR
2840
2841Note:
2842Tanda > diganti menggunakan spasi.
2843
2844
2845
2846
2847
2848==========
2849
2850
2851
2852049.
2853
2854"MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.2)
2855
2856Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
2857
2858Kordinat 3D
28593D 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
2861Semua 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
2863Implementasi kordinat 3D
2864
2865---------------------------------------------------------------------------------------
2866import math,e32,key,appuifw, graphics
2867
2868def quit():
2869 global run
2870 run=0
2871
2872appuifw.app.screen = 'full'
2873run = 1
2874appuifw.app.body = c = appuifw.Canvas()
2875appuifw.app.exit_key_handler=quit
2876img = graphics.Image.new(c.size)
2877
2878PX = c.size[0]/2
2879PY = c.size[1]/2
2880Size = 6
2881VX = [-40, 40, -40, 40, -40, 40, -40, 40]
2882VY = [-40, -40, 40, 40, -40, -40, 40, 40]
2883VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
2884ANGLEZ = 0
2885
2886while 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
2930Jika 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.
2931Rotasi 3D
2932
2933Objek 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
2935Untuk 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
2937Script implementasi rotasi 3D
2938
2939---------------------------------------------------------------------------------------
2940import math,e32,key,appuifw, graphics
2941
2942def quit():
2943 global run
2944 run=0
2945
2946appuifw.app.screen = 'full'
2947run = 1
2948appuifw.app.body = c = appuifw.Canvas()
2949appuifw.app.exit_key_handler=quit
2950img = graphics.Image.new(c.size)
2951
2952PX = c.size[0]/2
2953PY = c.size[1]/2
2954Size = 6
2955VX = [-40, 40, -40, 40, -40, 40, -40, 40]
2956VY = [-40, -40, 40, 40, -40, -40, 40, 40]
2957VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
2958ANGLEX = 0
2959ANGLEY = 0
2960ANGLEZ = 0
2961
2962while 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
3021Pada 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
3029Ketiga statement diatas hanya menjumlahkan semua "offset rotasi" sehingga dapat digunakan dalam konversi akhir.
3030
3031Note:
3032Tanda > diganti menggunakan spasi.
3033
3034
3035
3036
3037
3038==========
3039
3040
3041
3042050.
3043
3044"MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.3)
3045
3046Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
3047
3048Transformasi 3D
3049Pada 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
3051Proses mensimulasikan perspektif disebut transformasi. Rumus transformasinya:
3052
3053Z = (VZ+PZ)/distance
3054X = (VX+PX)/Z
3055Y = (VY+PY)/Z
3056
3057Pada 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
3059Implementasi perspektif 3D
3060
3061---------------------------------------------------------------------------------------
3062import math,e32,key,appuifw, graphics
3063
3064def quit():
3065 global run
3066 run=0
3067appuifw.app.screen ='full'
3068run = 1
3069appuifw.app.body = c = appuifw.Canvas()
3070appuifw.app.exit_key_handler=quit
3071img = graphics.Image.new(c.size)
3072halfResX = c.size[0]/2
3073halfResY = c.size[1]/2
3074---------------------------------------------------------------------------------------
3075
3076-Jarak posisi kamera dari layar
3077
3078---------------------------------------------------------------------------------------
3079distance = 180
3080
3081PX = 0
3082PY = 0
3083PZ = 200
3084Size = 6
3085VX = [-40, 40, -40, 40, -40, 40, -40, 40]
3086VY = [-40, -40, 40, 40, -40, -40, 40, 40]
3087VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
3088ANGLEX = 0
3089ANGLEY = 0
3090ANGLEZ = 0
3091
3092while 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
3152Karena 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
3154Itulah 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
3156Fungsi key:
3157Arah atas dan bawah: update PY
3158Arah kiri dan kanan: update PX
31591 dan 3: update PZ
31602 dan 8: update ANGLEX
31614 dan 6: update ANGLEY
3162* dan #: update ANGLEZ
3163
3164---------------------------------------------------------------------------------------
3165import math,e32,key,appuifw, graphics
3166from key_codes import *
3167
3168class 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
3190def quit():
3191 global run
3192 run=0
3193key = Keyboard()
3194appuifw.app.screen ='full'
3195run = 1
3196appuifw.app.body = c = appuifw.Canvas(event_callback = key.handle_event)
3197appuifw.app.exit_key_handler=quit
3198img = graphics.Image.new(c.size)
3199halfResX = c.size[0]/2
3200halfResY = c.size[1]/2
3201---------------------------------------------------------------------------------------
3202
3203-Jarak posisi kamera dari layar
3204
3205---------------------------------------------------------------------------------------
3206distance = 180
3207
3208PX = 0
3209PY = 0
3210PZ = 200
3211Size = 6
3212VX = [-40, 40, -40, 40, -40, 40, -40, 40]
3213VY = [-40, -40, 40, 40, -40, -40, 40, 40]
3214VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
3215ANGLEX = 0
3216ANGLEY = 0
3217ANGLEZ = 0
3218
3219while 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
3287e32.ao_yield()
3288---------------------------------------------------------------------------------------
3289
3290Note:
3291Tanda > diganti menggunakan spasi.
3292
3293
3294
3295
3296
3297==========
3298
3299
3300
3301051.
3302
3303"LIST, FUNGSI dan CLASS"
3304
3305Saya mau share bagaimana mengelompokan script dengan penggunaan multi dimensional list:
3306
3307---------------------------------------------------------------------------------------
3308nama_list=[[nilai,nilai],[nilai,nilai]]
3309---------------------------------------------------------------------------------------
3310
3311fungsi berargumen:
3312
3313---------------------------------------------------------------------------------------
3314def nama_fungsi(argumen):
3315
3316 isi_fungsi
3317---------------------------------------------------------------------------------------
3318
3319dan class:
3320
3321---------------------------------------------------------------------------------------
3322class nama_class:
3323
3324 isi_class
3325---------------------------------------------------------------------------------------
3326
3327Sekali lagi ini hanyalah contoh, bukan struktur script yang baik,
3328
3329Note:
3330Ganti tanda ">" pada awal syntax dengan spasi. Sebagai contoh, data disimpan dalam multi dimensional list.
3331
3332---------------------------------------------------------------------------------------
3333type1 = ["Alas kaki", ["sepatu","sandal"]]
3334
3335type2 = ["Tutup kepala", ["topi","peci"]]
3336---------------------------------------------------------------------------------------
3337
3338Lalu misal kita ingin membuat fungsi untuk memproses nilai-nilai list diatas
3339
3340---------------------------------------------------------------------------------------
3341def 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
3350def 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---------------------------------------------------------------------------------------
3362cek_type1()
3363
3364cek_type2()
3365---------------------------------------------------------------------------------------
3366
3367Jika 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---------------------------------------------------------------------------------------
3370def 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---------------------------------------------------------------------------------------
3382mesin_cek(type1)
3383
3384mesin_cek(type2)
3385---------------------------------------------------------------------------------------
3386
3387Fungsi mesin_cek diatas memproses data argumen yang dimasukkan. Dengan begini, kita cukup menggunakan satu fungsi diatas untuk mengecek semua data list type kita.
3388
3389Jika fungsi kita banyak akan lebih mudah diorganisir jika disimpan didalam class. Jika script diatas dikelompokkan dengan class:
3390class 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---------------------------------------------------------------------------------------
3410p=pakaian()
3411
3412p.mesin_cek(p.type1)
3413
3414p.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---------------------------------------------------------------------------------------
3422angka=1
3423---------------------------------------------------------------------------------------
3424
3425class 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
3439c=percobaan()
3440
3441c.test()
3442---------------------------------------------------------------------------------------
3443
3444-Jika variabel lokal angka dipanggil dari luar class, harus menyertakan instance class nya
3445
3446---------------------------------------------------------------------------------------
3447print c.angka
3448print angka
3449---------------------------------------------------------------------------------------
3450
3451Note:
3452Tanda > diganti menggunakan spasi.
3453
3454
3455
3456
3457
3458==========
3459
3460
3461
3462052.
3463
3464"MELOAD GAMBAR EXTERNAL DENGAN MODULE IMAGE 1ST"
3465
3466Saya mau share tentang cara meload gambar eksternal khususnya pada s60 1st, namun bisa juga digunakan pada s60 2nd...
3467
3468Fungsi 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
3470Pada Pys60 Blit() berfungsi untuk menampilkan gambar baik gambar external ataupun old graphics didalam ataupun diluar objek gambar external atau old graphics juga.
3471
3472blit untuk menampilkan gambar external:
3473
3474---------------------------------------------------------------------------------------
3475img.blit(file_gambar)
3476---------------------------------------------------------------------------------------
3477
3478Gambar tersebut ditampilkan apa adanya dengan posisi pada pojok kiri atas. Posisi gambar dapat kita atur target posisinya:
3479
3480---------------------------------------------------------------------------------------
3481img.blit(file_gambar, target=(20,20))
3482---------------------------------------------------------------------------------------
3483
3484Penjelasan:
3485target=(x, y)
3486
3487Selain mengatur posisi target, kita juga dapat memotong gambar yang ingin ditampilkan (croping):
3488
3489---------------------------------------------------------------------------------------
3490img.blit(file_gambar, target=(20,20), source=(20,20,20,20))
3491---------------------------------------------------------------------------------------
3492
3493Penjelasan:
3494source=(PotongGambarKiri, PotongGambarAtas,PotongGambarKanan, PotongGambarBawah)
3495
3496Pemotongan sebanyak nilai yang dimasukkan (dalam piksel)
3497
3498Kita juga dapat me-resize gambarnya:
3499
3500---------------------------------------------------------------------------------------
3501img.blit(file_gambar, target=(30,30,30,30), scale=1)
3502---------------------------------------------------------------------------------------
3503
3504Penjelasan:
3505Python 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
3507Ada 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
3509Itulah penggunaan fungsi blit().
3510
3511
3512
3513
3514
3515==========
3516
3517
3518
3519053.
3520
3521"CONTOH PROGRAM GAME GUNTING, BATU, KERTAS"
3522
3523Saya mau share cara membuat game text based "Gunting batu kertas"...
3524
3525Sebagai 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---------------------------------------------------------------------------------------
3530import 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---------------------------------------------------------------------------------------
3536pilih = {"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---------------------------------------------------------------------------------------
3542Pemain=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---------------------------------------------------------------------------------------
3548Musuh=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---------------------------------------------------------------------------------------
3554konf=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---------------------------------------------------------------------------------------
3564appuifw.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---------------------------------------------------------------------------------------
3570def quit():
3571 script_lock.signal()
3572
3573appuifw.app.exit_key_handler=quit
3574
3575script_lock=e32.Ao_lock()
3576script_lock.wait()
3577---------------------------------------------------------------------------------------
3578
3579
3580
3581
3582
3583==========
3584
3585
3586
3587054.
3588
3589"SEDIKIT PENJELASAN IDENTASI PADA PYTHON"
3590
3591Saya mau share sedikit identasi pada python atau pada script pys60...
3592
3593Dalam 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
3595Blok-blok statement pada Pyhon ditandai dengan jumlah spasi pada awal kode pada setiap baris, perhatikan contoh berikut ini:
3596
3597Penjelasan:
3598kode X=2 adalah sebuah statement, kode Y=2 juga merupakan sebuah statement. Setiap statement pada python dipisahkan dengan ganti baris.
3599
3600kode 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
3602Sedangkan kode else: merupakan awal sebuah blok statement kedua dan print "Tidak terjadi tubrukan" adalah statement blok kedua.
3603
3604Berikut ilustrasi yang menjelaskan penggunaan blok statement dalam psoudo code:
3605
3606Contoh kedua:
3607
3608Berikut ilustrasi contoh penulisan kode yang salah:
3609
3610Sebuah statement juga dapat dipotong2 menjadi beberapa baris dengan menggunakan tanda "\" berikut contohnya:
3611
3612---------------------------------------------------------------------------------------
3613print "Sudah adzan\
3614saatnya sholat"
3615---------------------------------------------------------------------------------------
3616
3617
3618
3619
3620
3621==========
3622
3623
3624
3625055.
3626
3627"HEAT SEEKING MISSILE ALOGARITMA dan IMPLEMENTASI"
3628
3629Saya mau share tentang cara membuat game pesawat tempur atau perang bintang...
3630
3631Pasti 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
3633Algoritmanya 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
3635Dan seperti biasa, implementasinya tidak sesederhana algoritmanya biggrin tapi tidak terlalu sulit kok. Kita pakai operasi trigonometri dan vektor.
3636
3637Dimulai 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
3639Heat seeking missile
3640-Hitung delta antara misil dan target
3641
3642---------------------------------------------------------------------------------------
3643 deltaX = missileX - targetX
3644 deltaY = missileY - targetY
3645---------------------------------------------------------------------------------------
3646
3647Heat seeking missile
3648-Gunakan delta untuk menghitung radian angle
3649
3650---------------------------------------------------------------------------------------
3651 angleToTarget = -atan(deltaX/deltaY)
3652---------------------------------------------------------------------------------------
3653
3654Kode 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
3671Selanjutnya menghitung selisih angleToFace dengan angleMissile untuk memenentukan apakah misil harus diputar kekanan, kekiri atau tidak diputar karena sudah mengarah ke target.
3672
3673Heat 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
3698Selesai, 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
3707056.
3708
3709"MEMBUAT KUIS DENGAN PYS60"
3710
3711Saya mau share cara membuat kuis dengan pys60...
3712
3713Ini contoh scriptnya,
3714---------------------------------------------------------------------------------------
3715from appuifw import *
3716
3717jawaban=['Y']
3718
3719pertanyaan=query(u'kamu suka makan?','text',u'jawab dg Y atau T' )
3720
3721if jawaban.__contains__(pertanyaan )==1: note(u'weleh.. weleh.. kamu suka makan..','conf' )
3722else: note(u'gak suka makan ya..','error' )
3723---------------------------------------------------------------------------------------
3724
3725
3726
3727
3728
3729==========
3730
3731
3732
3733057.
3734
3735"MEMBACA PESAN DENGAN PYS60"
3736
3737Saya mau share sebuah script yang dapat membaca pesan masuk...
3738
3739Saya pernah membaca sebuah tutorial menggunakan modul inbox untuk membaca pesan masuk pertama.
3740
3741Kurang 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
3756058.
3757
3758"BEBERAPA GAYA PENULISAN SCRIPT PYTHON"
3759
3760Saya mau share gaya penulisan dalam sebuah script...
3761
3762Ada beberapa cara penulisan script python.
3763Antara lain:
3764
376501.
3766import appuifw
3767import graphics
3768
376902.
3770import appuifw,graphics
3771
377203.
3773from appuifw import*
3774from graphics import*
3775
377604.
3777import appuifw;import graphics
3778
377905.
3780from appuifw import*;from graphics import*
3781
378206.
3783import appuifw as a
3784import graphics as g
3785
378607.
3787import appuifw as a;import graphics as g
3788
3789Fungsi sintax diatas adalah sama, yaitu mengimport modul appuifw dan graphics.
3790
3791
3792
3793
3794
3795==========
3796
3797
3798
3799059.
3800
3801"MENAMPILKAN IP DENGAN PYS60"
3802
3803Saya mau share sebuah script untuk menampilkan sebuah ip...
3804
3805Ternyata bisa juga menampilkan ip saat kita terkoneksi dengan internet dengan beberapa baris code saja.
3806
3807
3808Ini dia codenya:
3809
3810---------------------------------------------------------------------------------------
3811import socket
3812
3813n=socket.select_access_point()
3814
3815j=socket.access_point(n)
3816
3817j.start()
3818
3819ip=j.ip()
3820print ip
3821
3822j.stop()
3823---------------------------------------------------------------------------------------
3824
3825
3826
3827
3828
3829==========
3830
3831
3832
3833060.
3834
3835"MODUL TXTFIELD"
3836
3837Saya mau share sebuah script yang fungsinya seperti nulis teks dibar address url...
3838
3839Contoh penggunaanya, kayak gini
3840
3841---------------------------------------------------------------------------------------
3842import txtfield
3843
3844t1 = txtfield.New( (10,10,100,40) , (txtfield.ENoLineBreaks )
3845t1.focus(1)
3846---------------------------------------------------------------------------------------
3847
3848
3849
3850
3851
3852==========
3853
3854
3855
3856061
3857
3858"PERULANGAN FOR DALAM PYS60"
3859
3860Saya mau share script untuk perulangan sebuah teks...
3861
3862Kita coba dulu dengan yang ini:
3863
3864---------------------------------------------------------------------------------------
3865x=5
3866for i in range(x):
3867 print unicode('test' )
3868---------------------------------------------------------------------------------------
3869
3870hasilnya:
3871test
3872test
3873test
3874test
3875test
3876
3877kesimpulannya:
3878i disini akan mencetak kata 'tes' sejumlah value 'x'.
3879
3880Or
3881mengeprint 'tes' sebanyak 'x' kali.
3882
3883Dan ini contoh penerapannya di script,
3884
3885---------------------------------------------------------------------------------------
3886from appuifw import*
3887from e32 import*
3888
3889l=Ao_lock()
3890t=Text()
3891
3892def quit():
3893>>l.signal()
3894
3895font=available_fonts()
3896for i in range(len(font)):
3897>>t.font=font
3898>>t.color=0
3899>>t.add(unicode(str(font)+': abc 123\n' ))
3900
3901app.screen='full'
3902app.body=t
3903app.exit_key_handler=quit
3904l.wait()
3905---------------------------------------------------------------------------------------
3906
3907Note:
3908Tanda > diganti menggunakan spasi.
3909
3910
3911
3912
3913
3914==========
3915
3916
3917
3918062.
3919
3920"POPUP MENU GANDA DENGAN PYS60"
3921
3922Saya mau share sebuah script popup menu ganda...
3923
3924---------------------------------------------------------------------------------------
3925from appuifw import*
3926
3927a=[( u'satu satu' ),( u'satu dua' ),( u'satu tiga' )]
3928
3929b=[( u'dua satu' ),( u'dua dua' )]
3930
3931list_sub=[a,b]
3932
3933menu=[( u'satu' ),( u'dua' )]
3934
3935p=popup_menu( menu,u'pilih' )
3936
3937q=popup_menu( list_sub[p],u'masuk_sub '+str( p+1 ))
3938
3939print u'pilihan pertama: '+str( p+1 )+u'\npilihan ke dua: '+str( q+1 )
3940---------------------------------------------------------------------------------------
3941
3942
3943
3944
3945
3946==========
3947
3948
3949
3950063.
3951
3952"MENGECEK dan MEMBUAT FOLDER DENGAN PYS60"
3953
3954Saya mau share sebuah script untuk mengecek ada atau nggak ada folder di HP kita dengan module os. Dan module appuifw untuk pemberitahuannya.
3955
3956Langsung saja, berikut adalah kodenya..
3957
3958---------------------------------------------------------------------------------------
3959import appuifw,os
3960folder=unicode( "e:\\NamaFolder" )
3961
3962if 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
3986064.
3987
3988"SALAH SATU PERBEDAAN SYNTAK S60v1 dan S60v2 DIATASNYA"
3989
3990Saya mau share tentang perbedaan script untuk import gambar antara s60v1 dan s60v2...
3991
3992Mungkin teman-teman sudah tahu, bahwa s60v1 dan s60v2 keatas mempunyai cara yang berbeda dalam menampilkan gambar.
3993
3994Perbedaan ini menjadi salah satu yang menyebabkan aplikasi s60v2 keatas tidak dapat dibuka di s60v1.
3995
3996Berikut perbedaannya:
3997
3998s60v2 keatas:
3999
4000---------------------------------------------------------------------------------------
4001import graphics
4002
4003file=u'e:\\nama_file.jpg'
4004im=graphics.Image.new(( 176,208 ))
4005
4006gambar=graphics.Image.open(file)
4007im.blit(gambar, target=(0,0))
4008---------------------------------------------------------------------------------------
4009
4010s60v1:
4011
4012---------------------------------------------------------------------------------------
4013import graphics,image1st
4014
4015file=u'e:\\nama_file.jpg'
4016im=graphics.Image.new(( 176,208 ))
4017
4018bm=graphics.Image.from_cfbsbitmap
4019img=image1st.convertimage
4020
4021gambar=bm( img( file ))
4022im.blit(gambar, target= ( 0,0 ))
4023
4024---------------------------------------------------------------------------------------
4025
4026
4027
4028
4029
4030==========
4031
4032
4033
4034065.
4035
4036"ROTASI POLYGON DENGAN PYS60"
4037
4038Saya mau share cara rotasi pada gambar tradisional...
4039
4040Menurut sumbernya saya mendapatkan rumus ini:
4041
4042---------------------------------------------------------------------------------------
4043rad=(angle/180.0)*pi
4044rot_x=cos(rad)*pos_x-sin(rad)*pos_y
4045rot_y=sin(rad)*pos_x+cos(rad)*pos
4046---------------------------------------------------------------------------------------
4047
4048Contoh script di pys60
4049
4050---------------------------------------------------------------------------------------
4051import e32,appuifw,math,graphics,sysinfo
4052
4053def exit_handler():
4054>>>global run;run=0
4055
4056canvas=appuifw.Canvas()
4057appuifw.app.body=canvas
4058appuifw.app.screen='full'
4059appuifw.app.exit_key_handler=exit_handler
4060layar=sysinfo.display_pixels()
4061im=graphics.Image.new(layar)
4062run=1
4063
4064pos_x,pos_y,angle=0,0,1.0
4065panah=[(x-16,y),(x,y-20),(x+16,y),(x+4,y),(x+4,y+10),(x-4,y+10),(x-4,y)]
4066camx,camy=layar[0]/2,layar[1]/2
4067
4068while 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
4086Note:
4087Tanda > diganti menggunakan spasi.
4088
4089
4090
4091
4092
4093==========
4094
4095
4096
4097066.
4098
4099"SCAN ISI DRIVE DENGAN PYS60"
4100
4101Saya mau share sebuah script untuk scanning isi drive di HP kita menggunakan pys60...
4102
4103Ini baris codenya...
4104
4105---------------------------------------------------------------------------------------
4106from appuifw import*;import os,e32
4107f=e32.drive_list()
4108
4109def 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
4117p=popup_menu(f,unicode( 'pilih drive' ))
4118
4119if p!=None: scan( f[p]+os.sep )
4120else: print unicode( 'scan dibatalkan' )
4121---------------------------------------------------------------------------------------
4122
4123Note:
4124Tanda > diganti menggunakan spasi.
4125
4126
4127
4128
4129
4130==========
4131
4132
4133
4134067.
4135
4136"MENGGABUNGKAN FUNGSI DENGAN PROGRESS PADA PYS60"
4137
4138Saya mau share sebuah script untuk menggabungkan module progress dengan fungsi, gunanya, buat mengetahui sampai mana fungsi yang sudah diproses...
4139
4140Ini contoh scripnya,
4141---------------------------------------------------------------------------------------
4142import progress
4143
4144teks=['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
4146pb=progress.TWProgressBar(start=0,end=100,fill=(0,0,0),outline=(100,255,0),display=(176,100),title=unicode( ' ' ))
4147
4148def t1():
4149>>>print u'tes1'
4150
4151def t2():
4152>>>print u'tes2'
4153
4154def t3():
4155>>>print u'tes3'
4156
4157def t4():
4158>>>print u'tes4'
4159
4160def t5():
4161>>>print u'tes5'
4162
4163def t6():
4164>>>print u'tes6'
4165
4166def t7():
4167>>>print u'tes7'
4168
4169def t8():
4170>>>print u'tes8'
4171
4172def t9():
4173>>>print u'tes9'
4174
4175def t10():
4176>>>print u'tes10'
4177
4178tugas=[t1,t2,t3,t4,t5,t6,t7,t8,t9,t10]
4179
4180for 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)
4184pb.close()
4185---------------------------------------------------------------------------------------
4186
4187Intinya, kita masukkan fungsi kedalam list, lalu kita jalankan fungsi setelah sebelumnya kita loop , kemudian value pada progress kita set loop listnya.
4188
4189Note:
4190Tanda > diganti menggunakan spasi.
4191
4192
4193
4194
4195
4196==========
4197
4198
4199
4200068.
4201
4202"SCRIPT PYS60 BERKODE"
4203
4204Saya mau share sebuah script, dimana jika dalam waktu tertentu script tersebut akan meminta kode dari pemilik handphone...
4205
4206Jika kode yang ditulis tidak sama dengan kunci kodenya, maka script akan tertutup.
4207
4208Kita import module yang diperlukan.
4209
4210---------------------------------------------------------------------------------------
4211import appuifw,graphics,e32,sysinfo,time
4212def quit():
4213 global run
4214 run=0
4215ap=appuifw.app
4216ap.screen='full'
4217ap.body=c=appuifw.Canvas()
4218ap.exit_key_handler=quit
4219im=graphics.Image.new(( 176,208 ))
4220
4221def unlock():
4222 imei=sysinfo.imei()
4223 return imei[:-2]
4224
4225timer=10
4226def password():
4227 cd=appuifw.query( u'masukkan kode','code' )
4228 if cd !=unlock(): quit()
4229 else: pass
4230
4231run=1
4232while 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
4249069.
4250
4251"MENAMPILKAN SEMUA ICON APLIKASI YANG TERINSTALL DENGAN PYS60"
4252
4253Saya mau share module geticon buat nampilin icon aplikasi...
4254
4255Ini contoh scriptnya,
4256
4257---------------------------------------------------------------------------------------
4258import appuifw,graphics,e32,geticon,os
4259
4260run=1
4261def quit():
4262>>global run
4263>>run=0
4264
4265appuifw.app.exit_key_handler=quit
4266appuifw.app.screen='full'
4267c=appuifw.Canvas()
4268appuifw.app.body=c
4269im=graphics.Image.new( (0,0) )
4270im_mask=graphics.Image.new( (0,0) , 'L' )
4271
4272uid=[]
4273nama_app=[]
4274folder=u'e:\\system\\apps\\'
4275list_folder=os.listdir(folder)
4276
4277def 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
4282def 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
4293def 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
4300cek()
4301timer=0
4302y=0
4303while 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
4317Note:
4318Tanda > diganti menggunakan spasi.
4319
4320
4321
4322
4323
4324==========
4325
4326
4327
4328070.
4329
4330"MEMBUAT KURSOR 4 ARAH PADA APLIKASI DENGAN PYS60"
4331
4332Saya 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
4334Sebelumnya, 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---------------------------------------------------------------------------------------
4337import appuifw,graphics,e32,sysinfo
4338
4339try: import key
4340except: appuifw.note( u'module key belum ada' )
4341
4342run=1
4343def quit(): global run;run=0
4344
4345appuifw.app.screen='full'
4346appuifw.app.exit_key_handler=quit
4347c=appuifw.Canvas(event_callback=key.press.handle_event)
4348appuifw.app.body=c
4349layar=sysinfo.display_pixels()
4350im=graphics.Image.new(layar)
4351
4352lebar=layar[0]/3.0
4353tinggi=layar[1]/3.0
4354
4355try: gambar=graphics.Image.open( u'e:\\gb.jpg' ).resize(( lebar,tinggi ))
4356except:
4357>>>appuifw.note( u'siapkan gambar di e:\\dulu' )
4358>>>quit()
4359
4360pos_x=range(0,layar[0],lebar)
4361pos_y=range(0,layar[1],tinggi)
4362
4363kursor_x,kursor_y=0,0
4364pos_x_kursor,pos_y_kursor=0,0
4365
4366menu=[[ 'satu', 'dua', 'tiga' ], [ 'empat', 'lima', 'enam' ], [ 'tujuh', 'delapan', 'sembilan' ]]
4367
4368while 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
4414Note:
4415Tanda > diganti menggunakan spasi.
4416
4417
4418
4419
4420
4421==========
4422
4423
4424
4425071.
4426
4427"MEMBUAT JAM ANALOG DENGAN PYS60"
4428
4429Saya mau share cara membuat jam analog menggunakan pys60...
4430
4431Pertama, kita tentukan jam sekarang dengan module time. Lengkapnya
4432
4433---------------------------------------------------------------------------------------
4434import time
4435data=time.localtime()
4436---------------------------------------------------------------------------------------
4437
4438Sekarang data sudah berisi tuple localtime, yang pertama adalah tahun, bulan, tanggal, jam, menit, detik.
4439
4440Berikutnya, 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---------------------------------------------------------------------------------------
4443Import math
4444x,y=0,0
4445sudut=0
4446jarak=10
4447rad=(float(sudut)*math.pi)/180
4448cos=math.cos
4449sin=math.sin
4450muter_x=cos(rad)*jarak-sin(rad)*jarak
4451muter_y=sin(rad)*jarak+cos(rad)*jarak
4452---------------------------------------------------------------------------------------
4453
4454Biasanya jarum detik itu bertambah 1, jika sudah mencapai 60, kembali ke 0 lagi.
4455
4456Jadi, kita pakai
4457
4458---------------------------------------------------------------------------------------
4459rad_detik = (detik_sekarang/jumlah 1 putaran)*360 derajat
4460---------------------------------------------------------------------------------------
4461
4462Begitu juga dengan jarum menit dan jarum jam.
4463
4464Nanti kita tinggal menghubungkan titik pusat dengan koordinat koordinat jarum jam tadi sehingga menjadi garis.
4465
4466Biar selalu diupdate, proses kita masukkan didalam identasi 'while' ..
4467
4468Berikut ini scriptnya
4469
4470---------------------------------------------------------------------------------------
4471import appuifw,graphics,e32,sysinfo,time,math
4472
4473run=1
4474def quit():
4475>>global run
4476>>run=0
4477
4478appuifw.app.exit_key_handler=quit
4479appuifw.app.screen='full'
4480c=appuifw.Canvas()
4481appuifw.app.body=c
4482layar=sysinfo.display_pixels()
4483im=graphics.Image.new(layar)
4484
4485x,y=layar[0]/2,layar[1]/2
4486detik=0
4487menit=0
4488jam=0
4489
4490jdetik=layar[0]/4
4491jmenit=jdetik-5
4492jjam=jmenit-5
4493
4494def radian(sudut):
4495>>return (float(sudut)*math.pi)/180.0
4496
4497while 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
4533Penambahan 240 dan range(225,585,30) hanya akal-akalan saya saja biar jarumnya pas.
4534
4535Note:
4536Tanda > diganti menggunakan spasi.
4537
4538
4539
4540
4541
4542==========
4543
4544
4545
4546072.
4547
4548"INDIKATOR SINYAL, BATERAI DENGAN FGIMAGE (PYS60)"
4549
4550Saya mau share cara menampilkan indikator battery menggunakan pys60...
4551
4552Biar 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---------------------------------------------------------------------------------------
4555import fgimage,appswitch,sysinfo,appuifw,graphics,e32
4556
4557fg=0
4558def quit():
4559>>global run,runn,fg
4560>>run,runn,fg=0,0,0
4561
4562def 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
4571def menu_app():
4572>>gul=appswitch.application_list(0)[0]
4573>>appswitch.switch_to_bg(gul)
4574
4575layar=sysinfo.display_pixels()
4576lebar,tinggi=176,15
4577posx,posy=0,29
4578
4579menu=[(unicode( 'exit' ),quit)]
4580appuifw.app.screen='full'
4581appuifw.app.exit_key_handler=menu_app
4582appuifw.app.body=c=appuifw.Canvas()
4583appuifw.app.focus=fokus
4584appuifw.app.menu=menu
4585im=graphics.Image.new((lebar,tinggi))
4586img=graphics.Image.new(layar)
4587run,runn=1,1
4588
4589class 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
4600teks=['','','http://gumalgamul.mywapblog.com','','','tool for show signal and battery','','','minimize for show']
4601
4602def tulis(lis):
4603>>for i in range(len(lis)):
4604 img.text((3,10+(i*12)),unicode(''+lis),(200,200,200),u'latinplain12' )
4605
4606gulam=monitor()
4607while 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
4621Note:
4622Tanda > diganti menggunakan spasi.
4623
4624
4625
4626
4627
4628==========
4629
4630
4631
4632073.
4633
4634"SET FGIMAGE PADA STANDBY PYS60"
4635
4636Saya mau share cara menampilkan fgimage dimenu standby saja...
4637
4638Pertama:
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
4646Lalu, bagaimana kita mendeteksi bahwa sekarang 'stand by' atau 'phone.app' sedang berjalan?
4647
4648Kita pakai fungsi dari module appswitch aja, yaitu appswitch.application_list untuk mendeteksinya, dan diproses berulang ulang. Caranya,
4649
4650---------------------------------------------------------------------------------------
4651While 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
4658Berikut penerapannya dalam script pys60
4659
4660---------------------------------------------------------------------------------------
4661import appuifw,graphics,e32,fgimage,appswitch,globalui
4662
4663run=1
4664def quit():global run;run=0;fg.unset()
4665
4666appuifw.app.screen='full'
4667appuifw.app.exit_key_handler=quit
4668appuifw.app.body=c=appuifw.Canvas()
4669im=graphics.Image.new((176,40))
4670fg=fgimage.FGImage()
4671x,y=0,0
4672posx,posy=0,10
4673while 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
4690Note:
4691Tanda > diganti menggunakan spasi.
4692
4693
4694
4695
4696
4697==========
4698
4699
4700
4701074.
4702
4703"SCREESHOT DENGAN N-GAGE atau S60v1 (PYS60)"
4704
4705Saya mau share cara menscreenshot menggunakan tombol edit atau pensil...
4706
4707Script python dibawah ini bisa mengambil screenshot dengan cara menekan tombol edit atau pensil.
4708
4709Caranya? 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---------------------------------------------------------------------------------------
4712import appuifw,time,graphics,image1st2,keycapture,globalui
4713l=graphics.e32.Ao_lock()
4714def quit():capt.stop();l.signal()
4715
4716def 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
4718capt=keycapture.KeyCapturer(shot)
4719capt.keys=(63499,63499)
4720capt.start()
4721appuifw.app.exit_key_handler=quit
4722l.wait()
4723---------------------------------------------------------------------------------------
4724
4725
4726
4727
4728
4729==========
4730
4731
4732
4733075.
4734
4735"MEMBUAT GRAFIK (SCRIPT PYS60)"
4736
4737Saya mau share cara menampilkan nilai menggunakan grafik...
4738
4739Selain dengan bar, untuk menampilkan nilai, kita juga bisa menggunakan grafik.
4740
4741Jadi caranya begini:
47421. Kita ambil posisi berdasarkan informasi ukuran layar.
4743
4744---------------------------------------------------------------------------------------
4745ly=sysinfo.display_pixels()
4746---------------------------------------------------------------------------------------
4747
47482. Kita buat posisi awal garis akan muncul. Posisi x kita atur layar paling kanan, posi y kita atur tinggi layar/2
4749
4750---------------------------------------------------------------------------------------
4751x,y=ly[0],ly[1]/2
4752---------------------------------------------------------------------------------------
4753
47543. 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---------------------------------------------------------------------------------------
4757pos=[x,y,x,y]
4758---------------------------------------------------------------------------------------
4759
47604. 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---------------------------------------------------------------------------------------
4763rand=random.choice(range(10,ly[1]-20,20))
4764if timer<=0:
4765>>timer=delay
4766>>pos.append([pos[-1][2],pos[-1][3],x,rand])
4767---------------------------------------------------------------------------------------
4768
47695. Kemudian, jika timer lebih dari 0, timer dikurangi 1
4770
4771---------------------------------------------------------------------------------------
4772if timer>0:
4773>>timer-=1
4774---------------------------------------------------------------------------------------
4775
47766. Sekarang, kita loop list pos
4777
4778---------------------------------------------------------------------------------------
4779for i in range(len(pos)):
4780---------------------------------------------------------------------------------------
4781
47827. Kita atur pergerakannya, masih didalam identasi for, jangan lupa, hapus koordinat yang kurang dari 0 agar script tidak berat, barulah kita gambar .
4783
4784Note:
4785Tanda > diganti menggunakan spasi.
4786
4787
4788
4789
4790
4791==========
4792
4793
4794
4795076.
4796
4797"GET COORDINATE ARROUND CIRCLE (PYS60)"
4798
4799Saya mau share cara membuat koordinat pada lingkaran menggunakan pys60...
4800
4801Kali 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
480301. Kita buat dulu titik pusat lingkaran.
4804
480502. Kita buat titik lingkaran dengan jari jari.
4806
480703. Kita putar titik yang sudah kita buat tadi 360 derajat.
4808
4809Kumpulan titik-titik itulah koordinatnya. Jadi, kita tinggal memasukkan koordinat-koordinat tersebut kedalam list.
4810
4811Ini kodenya,
4812
4813---------------------------------------------------------------------------------------
4814x,y=80,80
4815---------------------------------------------------------------------------------------
4816-Ini sebagai titik pusat lingkaran.
4817
4818---------------------------------------------------------------------------------------
4819r=10
4820---------------------------------------------------------------------------------------
4821-Ini sebagai jari jari.
4822
4823-Fungsi konversi ke radian
4824def radian(angle):return (float(angle)/
4825
4826---------------------------------------------------------------------------------------
4827180.0)*math.pi
4828---------------------------------------------------------------------------------------
4829
4830-Rumus memutar
4831-Rad adalah hasil konversi ke radian
4832
4833---------------------------------------------------------------------------------------
4834rx=r*math.cos(rad)-r*math.sin(rad)
4835ry=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
4844Sekarang tinggal kita gabung dengan range(360) untuk mendapatkan koordinat 1 putaran lingkaran.
4845
4846Ini kodenya
4847
4848---------------------------------------------------------------------------------------
4849import math
4850pi=math.pi
4851cos=math.cos
4852sin=math.sin
4853
4854def radian(xx):
4855return (float(xx)/180.0)*pi
4856
4857def get_circle_coord(x,y,r):
4858rad=[]
4859result=[]
4860sdt=range(360)
4861for i in xrange(len(sdt)):
4862rad.append(round(radian(sdt),2))
4863for oke in xrange(len(rad)):
4864rx=round(r*cos(rad[oke])-r*sin(rad[oke]),1)
4865ry=round(r*sin(rad[oke])+r*cos(rad[oke]),1)
4866result.append([x+rx,y+ry])
4867return result
4868---------------------------------------------------------------------------------------
4869
4870Untuk 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
4872Ini kodenya
4873
4874---------------------------------------------------------------------------------------
4875import graphics,e32,appuifw,math
4876from sysinfo import display_pixels as pixels
4877
4878run=1
4879def quit():
4880global run
4881run=0
4882
4883ly=pixels()
4884im=graphics.Image.new(ly)
4885ap=appuifw.app
4886ap.screen='full'
4887ap.exit_key_handler=quit
4888ap.body=c=appuifw.Canvas()
4889
4890x,y,j=ly[0]/2,ly[1]/2,20
4891cos=math.cos
4892sin=math.sin
4893pi=math.pi
4894
4895def radian(xx):
4896return (float(xx)/180.0)*pi
4897
4898def get_circle_coord(x,y,r):
4899rad=[]
4900result=[]
4901sdt=range(360)
4902for i in xrange(len(sdt)):
4903rad.append(round(radian(sdt),2))
4904for oke in xrange(len(rad)):
4905rx=round(r*cos(rad[oke])-r*sin(rad[oke]),1)
4906ry=round(r*sin(rad[oke])+r*cos(rad[oke]),1)
4907result.append([x+rx,y+ry])
4908return result
4909
4910res=get_circle_coord(x,y,j)
4911
4912while run:
4913im.clear(0)
4914im.point((x,y),0xda0000)
4915for i in res:im.point(i,0xda)
4916c.blit(im)
4917e32.ao_sleep(0)
4918---------------------------------------------------------------------------------------
4919
4920
4921
4922
4923
4924==========
4925
4926
4927
4928077.
4929
4930"ADJUST TIMING SUBTITTLE WITH PYTHON"
4931
4932Saya mau share cara mempercepat subtittle pada video...
4933
4934Misal nih, pola jeda -4, -9, -13, -18, -22, -27, -31, -36, -40, -45
4935
4936Kita buat 3 var berisi bilangan
4937start = 0
4938plus = 11,5
4939minus = 7
4940Karena subtitlenya cuma bisa bilangan bulat , maka kita pakai fungsi int()
4941
4942Ini script dasarnya
4943
4944---------------------------------------------------------------------------------------
4945start = 0
4946plus = 11.5
4947minus = 7
4948for i in range(10):
4949>>start = start + plus
4950>>start = start - minus
4951>>print i + int(start)
4952---------------------------------------------------------------------------------------
4953
4954Memang sih buat apa ada plus minus, kan bisa aja cuma pakai plus.
4955Hasil 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
4957Dan ini script lengkapnya
4958
4959---------------------------------------------------------------------------------------
4960a=0
4961plus=11.5
4962minus=7
4963import time,re
4964
4965file=file_sub_asal
4966result=file_sub_hasil
4967t=open(file).read()
4968d=re.findall('{(\d*)}{(\d*)}(.*)',t)
4969res_file=open(result,'w')
4970
4971for 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
4976res_file.close()
4977print 'ok'
4978---------------------------------------------------------------------------------------
4979
4980Note:
4981Tanda > diganti menggunakan spasi.
4982
4983
4984
4985
4986
4987==========
4988
4989
4990
4991078.
4992
4993"MEMBUAT MENU GRID 3x3 (PYS60)"
4994
4995Saya mau share cara membuat tampilan menu grid menjadi 3x3...
4996
4997Biasanyakan menu cuma ada 1 kolom menurun, nah.. Kali ini kita belajar bikin yang gak seperti biasanya, yaitu 3x3.
4998
499901. Kita buat dulu 9 fungsi. (pakai def menu0 sampai def menu8 aja biar gampang)
5000
500102. Kita masukkan 9 fungsi tadi kedalam list, sebut saja list_func_menu. Jadinya kayak gini
5002---------------------------------------------------------------------------------------
5003list_func_menu=[menu0,menu1,... menu8]
5004---------------------------------------------------------------------------------------
5005
500603. Kita buat variable name yang berfungsi mengatur posisi posisi x dan y menu dan kursor.
5007
500804. Kita buat list didalam list, yang berisi integer urutan list_func_menu, jadinya gini
5009
5010---------------------------------------------------------------------------------------
5011menu=[[0,1,2],[3,4,5],[6,7,8]]
5012---------------------------------------------------------------------------------------
5013
5014Why? Ya karena kita mau buat 3x3 gridnya. Kalau 4x4 gimana? Ya tinggal buat aja
5015
5016---------------------------------------------------------------------------------------
5017menu=[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]
5018---------------------------------------------------------------------------------------
5019
5020Jadi, intinya jika 3x3 grid, maka kita buat 1 list berisi 3 sub list. Masing2 sub list, berisi 3 bilangan.
5021
502205. Kita ingat, list dalam python dimulai dari angka 0.
5023--angka 0,3,6 adalah angka pertama list mendatar.
5024---Jadi manggilnya
5025
5026---------------------------------------------------------------------------------------
5027menu[0][0], menu[0][1],menu[0][2]
5028---------------------------------------------------------------------------------------
5029
5030--sedang angka menurun pertama adalah 0,1,2
5031---manggilnya
5032
5033---------------------------------------------------------------------------------------
5034menu[0][0],menu[1][0],menu[2][0].
5035---------------------------------------------------------------------------------------
5036
5037Kita 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
5047Berikutnya, 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
5049Jika 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---------------------------------------------------------------------------------------
5062list_func_menu[menu[py][px]].
5063---------------------------------------------------------------------------------------
5064
5065Untuk mengeksekusi tinggal kasih tanda() diakhir list fungsi yang dipanggil tadi, sehingga menjadi list_func_menu[menu[py][px]]()
5066
5067Note:
5068Tanda > diganti menggunakan spasi.
5069
5070
5071
5072
5073
5074==========
5075
5076
5077
5078079.
5079
5080"MEMBUAT KALKULATOR SEDERHANA"
5081
5082Saya mau share script python sederhana yang berfungsi sebagai kalkulator...
5083
5084Ini skriptnya
5085
5086-Import modul yang diperlukan,
5087
5088---------------------------------------------------------------------------------------
5089import appuifw
5090---------------------------------------------------------------------------------------
5091
5092-Membuat popup query dialog antara user dan python
5093
5094---------------------------------------------------------------------------------------
5095a=appuifw.query(u'angka pertama','number')
5096---------------------------------------------------------------------------------------
5097
5098-Membuat popup perintah
5099
5100---------------------------------------------------------------------------------------
5101L=[u'tambah +',u'kurang -',u'kali *',u'bagi /']
5102b=appuifw.popup_menu(L,u'pilih:')
5103---------------------------------------------------------------------------------------
5104
5105-Membuat popup query ke 2
5106
5107---------------------------------------------------------------------------------------
5108c=appuifw.query(u'angka kedua','number')
5109---------------------------------------------------------------------------------------
5110
5111-Nah,sekarang buat fungsi kalkulasinya:
5112
5113---------------------------------------------------------------------------------------
5114if b==0:
5115>>print a+c
5116if b==1:
5117>>print ac
5118if b==2:
5119>>print a*c
5120if b==3:
5121>>print a/c
5122---------------------------------------------------------------------------------------
5123
5124Note:
5125Tanda > diganti menggunakan spasi.
5126
5127
5128
5129
5130
5131==========
5132
5133
5134
5135080.
5136
5137"MEMBUAT TEKS BERJALAN DENGAN BACKGROUND SUARA"
5138
5139Saya mau share cara membuat teks berjalan dengan baground suara...
5140
5141Nah ini scriptnya:
5142
5143---------------------------------------------------------------------------------------
5144import appuifw as fw
5145import audio as a
5146import e32 as e
5147
5148lagu=a.Sound.open('e:\\dds.mp3' ) ; lagu.play()
5149
5150fw.app.screen='large'
5151round=fw.Text()
5152round.style=fw.HIGHLIGHT_ROUNDED
5153round.color=0xff0000
5154
5155text=u'Masukan teks kamu disini mastah'
5156
5157for a in range(len(text ) ) :
5158>>round.add(text[a])
5159>>e.ao_sleep(0.2)
5160
5161e.Ao_lock().wait()
5162---------------------------------------------------------------------------------------
5163
5164Note:
5165Tanda > diganti menggunakan spasi.
5166
5167
5168
5169
5170
5171==========
5172
5173
5174
5175081.
5176
5177"MEMBUAT POPUP ALA CEK PULSA"
5178
5179Saya mau share cara membuat popup yang sama persis dengan popup saat cek pulsa kartu 3...
5180
5181Kalian pasti tau kan itu popup yang tampil kalo kita cek pulsa
5182
5183Dengan python kita dapat memanipulasinya dengan mudah.
5184
5185Sekarang kita manipulasi jumlah pulsa,biar temen2 kita bilang 'wow'
5186
5187Misal cek pulsa kartu 3:
5188
5189---------------------------------------------------------------------------------------
5190import globalui
5191import e32
5192
5193def start():
5194>>e32.start_exe('z:\\system\\programs\\apprun.Exe','z:\\system\\apps\\phone\\phone.app')
5195start()
5196
5197hewan=['Main Menu','Bal: Rp 1.999.000','1. Informasi Pulsa','2. Isi Ulang','3. Program&Promosi','4. Cek Kuota']
5198
5199ask=globalui.global_msg_query(unicode('\n'.join(hewan)),u'Pesan')
5200if ask==1:
5201>>for i in hewan:
5202 print i
5203---------------------------------------------------------------------------------------
5204
5205Note:
5206Tanda > diganti menggunakan spasi.
5207
5208
5209
5210
5211
5212==========
5213
5214
5215
5216082.
5217
5218"MENGIRIM SMS ke BANYAK NOMOR"
5219
5220Saya mau share script python yang fungsinya untuk mengirim pesan kebeberapa nomor sekaligus...
5221
5222Sebelumnya harus install dulu python,dan aplikasi ipro7 buat nulis dan eksekusiya.
5223
5224Langsung Saja:
5225
5226Misal kita mau mengirim sms ke 5 nomer teman kamu,
5227
5228-Pertama import module yang diperlukan:
5229
5230---------------------------------------------------------------------------------------
5231import appuifw
5232import messaging
5233---------------------------------------------------------------------------------------
5234
5235-Menetapkan identitas pribadi kita:
5236
5237---------------------------------------------------------------------------------------
5238data=appuifw.query(u"Masukan Nama Kamu","text")
5239---------------------------------------------------------------------------------------
5240
5241-Menetapkan nomer yang akan kita kirimi sms
5242
5243---------------------------------------------------------------------------------------
5244nomor1="0812xxx"
5245nomor2="0813xxx"
5246nomor3="0821xxx"
5247nomor4="0852xxx"
5248nomor5="0853xxx"
5249---------------------------------------------------------------------------------------
5250
5251-Menetapkan isi sms:
5252
5253---------------------------------------------------------------------------------------
5254txt=">Isi teks kamu disini,< Dari:"+data
5255---------------------------------------------------------------------------------------
5256
5257-Menetapkan system pengiriman:
5258
5259---------------------------------------------------------------------------------------
5260if appuifw.query(u"Kirim Pesan Ke Nomor 5 Teman Kamu","query")==True:
5261messaging.sms_send(nomor1,txt)
5262messaging.sms_send(nomor2,txt)
5263messaging.sms_send(nomor3,txt)
5264messaging.sms_send(nomor4,txt)
5265messaging.sms_send(nomor5,txt)
5266---------------------------------------------------------------------------------------
5267
5268-Membuat notifikasi jika sms sukses:
5269
5270---------------------------------------------------------------------------------------
5271appuifw.note(u'Pesan Telah Dikirim','info')
5272---------------------------------------------------------------------------------------
5273
5274-Membuat notifikasi jika sms gagal:
5275
5276---------------------------------------------------------------------------------------
5277else:
5278appuifw.note(u'Pesan Gagal Dikirim','info')
5279---------------------------------------------------------------------------------------
5280
5281
5282
5283
5284
5285==========
5286
5287
5288
5289083.
5290
5291"FUNGSI MODUL APPUIFW"
5292
5293Saya mau share tentang fungsi modul appuifw dan contohnya...
5294
5295Modul berguna untuk membentuk body atau user interface aplikasi
5296
5297-import appuifw berguna untuk memanggil modul.
5298
5299---------------------------------------------------------------------------------------
5300import appuifw
5301
5302def ru(x):
5303 return unicode(x, "utf8")
5304
5305text_1 = "Tulis teks yang ingin ditunjukan. . !"
5306---------------------------------------------------------------------------------------
5307
5308-Fungsi pertama
5309Note:
5310Digunakan untuk memberi peringatan.
5311
5312---------------------------------------------------------------------------------------
5313print "Fungsi 1\n\n"
5314
5315appuifw.note(ru(text_1), "info")
5316appuifw.note(ru(text_1), "conf")
5317appuifw.note(ru(text_1), "error")
5318---------------------------------------------------------------------------------------
5319
5320-Fungsi Kedua
5321Query: digunakan untuk bertanya
5322
5323---------------------------------------------------------------------------------------
5324print "Fungsi 2\n\n"
5325
5326text_2 = "Tulis pertanyaan disini:"
5327
5328appuifw.query(ru(text_2), "query")
5329appuifw.query(ru(text_2), "text")
5330appuifw.query(ru(text_2), "code")
5331appuifw.query(ru(text_2), "number")
5332appuifw.query(ru(text_2), "time")
5333appuifw.query(ru(text_2), "date")
5334appuifw.query(ru(text_2), "float")
5335---------------------------------------------------------------------------------------
5336
5337-Kita dapat mengabungkan fungsi-fungsi diatas
5338
5339Contoh dibawah ini adalah contoh untuk mendengar suara audio.say
5340
5341---------------------------------------------------------------------------------------
5342print "Fungsi 3\n\n"
5343---------------------------------------------------------------------------------------
5344
5345-import audio berguna untuk memanggil modul audio
5346
5347---------------------------------------------------------------------------------------
5348katakan = appuifw.query(ru("Katakan Apa:"), "text")
5349if 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
5357print "Selesai"
5358---------------------------------------------------------------------------------------
5359
5360-import messaging berguna untuk memanggil modul pengirim sms
5361
5362-Jumlah sms yang ingin dikirim
5363
5364---------------------------------------------------------------------------------------
5365sms_amount = 5
5366---------------------------------------------------------------------------------------
5367
5368-Sebagai penghitung
5369
5370---------------------------------------------------------------------------------------
5371counter = 0
5372---------------------------------------------------------------------------------------
5373
5374-Nomor target yang ingin dikirimi SMS
5375
5376---------------------------------------------------------------------------------------
5377target_number = "12345"
5378---------------------------------------------------------------------------------------
5379
5380-Isi pesan yang ingin dikirim
5381
5382---------------------------------------------------------------------------------------
5383msg_content = u"isi pesan"
5384
5385while counter < sms_amount:
5386 messaging.sms_send(target_number, msg_content)
5387 print "mengirim sms ke ", counter, " kepada ", target_number
5388 counter += 1
5389
5390print " selesai...."
5391---------------------------------------------------------------------------------------
5392
5393
5394Note:
5395Tanda > diganti menggunakan spasi.
5396
5397
5398
5399
5400==========
5401
5402
5403
5404084.
5405
5406"SIMPLE SCANNING APPLICATION"
5407
5408Saya mau share sebuah script untuk scanning directory...
5409
5410Script ini harus diletakan di folder python yang ada pada drive C atau E
5411
5412Kemudian masuk python scriptshell atau PED dan run script ini
5413
5414Hanya menggunakan 3 modul
5415
5416---------------------------------------------------------------------------------------
5417import appuifw
5418import os, e32
5419
5420def ru(x): return unicode(x, "utf8")
5421app_lock = e32.Ao_lock()
5422state, running = None, False
5423---------------------------------------------------------------------------------------
5424
5425-Membuat judul aplikasi
5426
5427---------------------------------------------------------------------------------------
5428appuifw.app.title = ru("Simple Scanner")
5429---------------------------------------------------------------------------------------
5430
5431-Membuat GUI atau body aplikasi
5432
5433---------------------------------------------------------------------------------------
5434editor = appuifw.Text()
5435appuifw.app.body = editor
5436
5437editor.font = ("legend", 12)
5438editor.color = 0x000000
5439editor.add(ru("Simple Scanner"))
5440editor.add(ru("\nHanya untuk Pengembangan dan Contoh\n\n\n\n\n"))
5441editor.add(ru("Author: Pythonism Symbian\nE-mail: joe4rt0n@gmail.com\n"))
5442editor.add(ru("7777772e6172746f6e2d70726976617465686f6d652e636f2e6363".decode("hex_codec")))
5443editor.add(ru("\n\n\nPilih Options & Scan, lalu pilih daftar drive"))
5444
5445def 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
5458audiolist = [".mp3", ".wav", ".aac", ".amr"]
5459filesis = [".sis", ".sisx"]
5460images = [".png", ".jpg", ".jpeg", ".mbm"]
5461audiocounter, siscounter = 0, 0
5462imagecounter = 0
5463
5464def 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
5493def 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
5504def 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---------------------------------------------------------------------------------------
5511appuifw.app.menu = [(ru("Scan"), scan_drive), (ru("About"), about)]
5512appuifw.app.exit_key_handler = exit
5513
5514
5515app_lock.wait()
5516---------------------------------------------------------------------------------------
5517
5518Note:
5519Tanda > diganti menggunakan spasi.
5520
5521
5522
5523
5524
5525==========
5526
5527
5528
5529085.
5530
5531"APLIKASI TEKS EDITOR"
5532
5533Saya mau share sebuah script untuk mengedit sebuah teks...
5534
5535-Memangil modul aplikasi
5536-Pythonism symbianism
5537
5538---------------------------------------------------------------------------------------
5539import appuifw2
5540import e32
5541---------------------------------------------------------------------------------------
5542
5543Fungsi ini digunakan untuk membuka gerbang fungsi dari aplikasi, hampir semua aplikasi dimulai dengan fungsi ini
5544
5545---------------------------------------------------------------------------------------
5546app_lock = e32.Ao_lock()
5547---------------------------------------------------------------------------------------
5548
5549Memberikan fungsi konversi, yaitu perubahan string agar menjadi unicode sehingga dapat ditampilkan pada GUI
5550
5551---------------------------------------------------------------------------------------
5552def ru(x):
5553 return unicode(x, "utf8")
5554---------------------------------------------------------------------------------------
5555
5556Membuat fungsi body aplikasi atau aplikasi utama, yaitu body text editor
5557
5558Untuk menggunakan fungsi ini, kita akan menggunakan modul appuifw
5559
5560---------------------------------------------------------------------------------------
5561body = appuifw2.Text(skinned=True)
5562appuifw2.app.body = body
5563---------------------------------------------------------------------------------------
5564
5565Membuat fungsi keluar aplikasi dengan cara membuka gerbang diatas
5566
5567---------------------------------------------------------------------------------------
5568def keluar():
5569 app_lock.signal()
5570---------------------------------------------------------------------------------------
5571
5572Meletakan fungsi tombol keluar, pada tombol exit, seperti gambar diatas
5573
5574---------------------------------------------------------------------------------------
5575appuifw2.app.exit_key_handler = keluar
5576---------------------------------------------------------------------------------------
5577
5578Memberikan nama pada tombol keluar
5579
5580---------------------------------------------------------------------------------------
5581appuifw2.app.exit_key_text = ru("Keluar")
5582---------------------------------------------------------------------------------------
5583
5584Memberikan nama pada tombol Menu
5585
5586---------------------------------------------------------------------------------------
5587appuifw2.app.menu_key_text = ru("Menu")
5588---------------------------------------------------------------------------------------
5589
5590Membuat menu dan submenu
5591Sebelumnya, kita harus membuat fungsi, berikut ini fungsi sederhana, yaitu menampilkan nama web ini
5592
5593---------------------------------------------------------------------------------------
5594def tampilkan_web():
5595 appuifw.note(ru("www.arton-privatehome.co.cc"), "info")
5596
5597appuifw2.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---------------------------------------------------------------------------------------
5609app_lock.wait()
5610---------------------------------------------------------------------------------------
5611
5612Note:
5613Tanda > diganti menggunakan spasi.
5614
5615
5616
5617
5618
5619==========
5620
5621
5622
5623086.
5624
5625"CAMERA MOTION"
5626
5627Saya mau share sebuah script camera motion...
5628
5629---------------------------------------------------------------------------------------
5630import appuifw2 as aw, e32, camera, audio
5631import socket as st
5632from graphics import*
5633
5634sock, debug = None, -1
5635address, channel=st.bt_obex_discover()
5636
5637def 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"))
5647bt_connect()
5648
5649action, control_light = False, 0
5650x, y, sensLeft, sensRight = 240, 235, 120, 120
5651sensUp, sensDown, sensCenter=120, 120, 120
5652
5653actionUp, actionDown, actionLeft, actionRight, actionCenter = False, False, False, False, False scanPixel = Image.new((x, y))
5654
5655def 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
5667lock = e32.Ao_lock()
5668canvas = aw.Canvas(redraw_callback = redraw, event_callback = None)
5669aw.app.body = canvas
5670
5671def 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
5682def 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
5693def 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
5704def 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
5715def 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
5726def 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
5733def 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
5745def 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
5757def 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
5769def 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
5781def 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
5793def gettingPixel(im):
5794 makeShading(im)
5795 upPixel(im)
5796 downPixel(im)
5797 leftPixel(im)
5798 rightPixel(im)
5799 centerPixel(im)
5800
5801def 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
5810def 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
5819def 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
5827saying = u"Motion Detected"
5828soundPath = "e:\\Sounds\\digital\\"
5829numberPhone = u"123"
5830
5831def sendMessage():
5832 global numberPhone
5833 import messaging
5834 messaging.sms_send(numberPhone, u"Detected")
5835
5836def 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
5845def 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
5854def 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
5868def 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
5877def 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
5885def 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
5896def saySomething():
5897 global saying
5898 try: audio.say(saying)
5899 except: aw.note(u"Failed", "error")
5900
5901def 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
5909def 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
5916def 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
5927def 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
5952def 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
5982def 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
6007def start_finder():
6008 global control_light
6009 control_light = 0
6010 camera.start_finder(cPixel, size=(200, 150))
6011
6012def stop_finder():
6013 global control_light
6014 control_light = 1
6015 camera.stop_finder()
6016 camera.release()
6017 aw.note(u"Finder stop")
6018
6019information = 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
6021def 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
6032def 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
6039aw.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
6050aw.app.exit_key_text = u"Stop & Exit"
6051aw.app.exit_key_handler = quit
6052lock.wait()
6053---------------------------------------------------------------------------------------
6054
6055Note:
6056Tanda > diganti menggunakan spasi.
6057
6058
6059
6060
6061
6062==========
6063
6064
6065
6066087.
6067
6068"INDICATOR BATTERY HP"
6069
6070Saya mau share sebuah script untuk indicator battery HP...
6071
6072---------------------------------------------------------------------------------------
6073import indicators, e32
6074---------------------------------------------------------------------------------------
6075
6076-Level baterai menjadi 5
6077
6078---------------------------------------------------------------------------------------
6079print "menset level baterai menjadi 5"
6080indicators.set_battery(5)
6081
6082e32.ao_sleep(2)
6083---------------------------------------------------------------------------------------
6084
6085-Level signal menjadi 5
6086
6087---------------------------------------------------------------------------------------
6088print "menset level sinyal menjadi 5"
6089indicators.set_signal(5)
6090
6091e32.ao_sleep(2)
6092
6093print "Mulai men-charge baterai"
6094indicators.start_charging()
6095
6096e32.ao_sleep(3)
6097
6098
6099print "Menghentikan men-charge baterai"
6100indicators.stop_charging()
6101---------------------------------------------------------------------------------------
6102
6103
6104
6105
6106
6107==========
6108
6109
6110
6111088.
6112
6113"CARA MEREKAM AUDIO"
6114
6115Saya mau share cara merekam audio menggunakan pys60...
6116
6117---------------------------------------------------------------------------------------
6118import appuifw, audio, os
6119
6120MENU = [u"Play sound", u"Record sound", u"Delete sound"]
6121SOUNDFILE = u"E:\\sound.wav"
6122sound = None
6123
6124while 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
6141Note:
6142Tanda > diganta menggunakan spasi.
6143
6144
6145
6146
6147
6148==========
6149
6150
6151
6152089.
6153
6154"MEMUTAR FILE MP3"
6155
6156Saya mau share sebuah script untuk play file mp3...
6157
6158---------------------------------------------------------------------------------------
6159import audio
6160
6161sound = audio.Sound.open("E:\\Sounds\\mysound.mp3")
6162
6163def playMP3():
6164 >sound.play()
6165 >print "PlayMP3 returns.."
6166
6167playMP3()
6168---------------------------------------------------------------------------------------
6169
6170Note:
6171Tanda > diganti menggunakan spasi.
6172
6173
6174
6175
6176
6177==========
6178
6179
6180
6181090.
6182
6183"TEKS BICARA"
6184
6185Saya mau share sebuah script untuk merubah teks menjadi audio...
6186
6187---------------------------------------------------------------------------------------
6188import appuifw, audio
6189
6190text = appuifw.query(u"Type a word:", "text")
6191audio.say(text)
6192---------------------------------------------------------------------------------------
6193
6194
6195
6196
6197
6198==========
6199
6200
6201
6202091.
6203
6204"CARA MENEMUKAN KATA di INBOX"
6205
6206Saya mau share sebuah script yang dapat menemukan kata diinbox secara otomatis...
6207
6208---------------------------------------------------------------------------------------
6209import inbox, appuifw
6210
6211box = inbox.Inbox()
6212query = appuifw.query(u"Search for:", "text").lower()
6213
6214hits = []
6215ids = []
6216for 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
6222index = appuifw.selection_list(hits, 1)
6223if index >= 0:
6224 appuifw.note(box.content(ids[index]))
6225---------------------------------------------------------------------------------------
6226
6227Note:
6228Tanda > diganti menggunakan spasi.
6229
6230
6231
6232
6233
6234==========
6235
6236
6237
6238092.
6239
6240"MENGAKSES INBOX"
6241
6242Saya mau share sebuah script untuk mengakses inbox...
6243
6244---------------------------------------------------------------------------------------
6245import inbox, appuifw
6246
6247box = inbox.Inbox()
6248
6249for sms_id in box.sms_messages()[:5]:
6250 >>msg = box.content(sms_id)
6251 >>appuifw.note(msg)
6252---------------------------------------------------------------------------------------
6253
6254Note:
6255Tanda > diganti menggunakan spasi.
6256
6257
6258
6259
6260
6261==========
6262
6263
6264
6265093.
6266
6267"LIST SELEKSI"
6268
6269Saya mau share sebuah script untuk list seleksi...
6270
6271---------------------------------------------------------------------------------------
6272import appuifw
6273
6274colors = [u"red", u"green", u"blue", u"brown"]
6275
6276selections = appuifw.multi_selection_list(colors, 'checkbox', 1)
6277print "Checkbox selected:", selections
6278
6279selections = appuifw.multi_selection_list(colors, 'checkmark', 1)
6280print "Checkmark selected:", selections
6281---------------------------------------------------------------------------------------
6282
6283
6284
6285
6286
6287==========
6288
6289
6290
6291094.
6292
6293"TWO DIALOGS"
6294
6295Saya mau share sebuah script two dialogs...
6296
6297---------------------------------------------------------------------------------------
6298import appuifw
6299
6300word = appuifw.query(u"Type your name", "text")
6301appuifw.note(u"Greetings from " + str(word))
6302---------------------------------------------------------------------------------------
6303
6304
6305
6306
6307
6308==========
6309
6310
6311
6312095.
6313
6314"MEMASUKKAN NAMA"
6315
6316Saya mau share sebuah script untuk memasukkan nama...
6317
6318---------------------------------------------------------------------------------------
6319import appuifw
6320
6321names = appuifw.multi_query(u"First name:", u" Last name:")
6322if names:
6323 first, last = names
6324 appuifw.note(u"Your full name is: " + first + " " + last)
6325else:
6326 appuifw.note(u"Cancel!")
6327---------------------------------------------------------------------------------------
6328
6329Note:
6330Tanda > diganti menggunakan spasi.
6331
6332
6333
6334
6335
6336==========
6337
6338
6339
6340096.
6341
6342"CARA MEREKAM AUDIO"
6343
6344Saya mau share sebuah script untuk merekam audio...
6345
6346---------------------------------------------------------------------------------------
6347import appuifw, audio, os
6348
6349MENU = [u"Play sound", u"Record sound", u"Delete sound"]
6350SOUNDFILE = u"E:\\sound.wav"
6351sound = None
6352
6353while 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
6370Note:
6371Tanda > diganti menggunakan spasi.
6372
6373
6374
6375
6376
6377==========
6378
6379
6380
6381097.
6382
6383"MEMBUAT SELECTION LIST"
6384
6385Saya mau share sebuah script untuk membuat selection list...
6386
6387---------------------------------------------------------------------------------------
6388import appuifw
6389
6390colors = [u"red", u"green", u"blue", u"brown"]
6391
6392index = appuifw.selection_list(colors, 1)
6393if index == 2:
6394 print "blue is correct!"
6395else:
6396 print "Bzz! " + colors[index] + " is not correct"
6397---------------------------------------------------------------------------------------
6398
6399Note:
6400Tanda > diganti menggunakan spasi.
6401
6402
6403
6404
6405
6406==========
6407
6408
6409
6410098.
6411
6412"MEMBUAT POPUP MENU"
6413
6414Saya mau share sebuah script untuk membuat popup menu...
6415
6416---------------------------------------------------------------------------------------
6417import appuifw
6418
6419choices = [u"Symbian", u"PyS60", u"MobileArt"]
6420
6421index = appuifw.popup_menu(choices, u"Select:")
6422
6423if index == 0 :
6424 appuifw.note(u"Symbian, aha")
6425elif index == 1 :
6426 appuifw.note(u"PyS60 - yeah")
6427elif index == 2 :
6428 appuifw.note(u"I love MobileArt")
6429---------------------------------------------------------------------------------------
6430
6431Note:
6432Tanda > diganti menggunakan spasi.
6433
6434
6435
6436
6437
6438==========
6439
6440
6441
6442099.
6443
6444"MEMBUAT APP BERKODE"
6445
6446Saya mau share cara membuat kode pada sebuah aplikasi...
6447
6448-Module yang dibutuhkan
6449
6450---------------------------------------------------------------------------------------
6451import appuifw
6452import e32
6453import os
6454import globalui
6455import sysinfo
6456---------------------------------------------------------------------------------------
6457
6458-Fungsi define untuk dipanggil ketika aplikasi diberikan perintah keluar
6459
6460---------------------------------------------------------------------------------------
6461def 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---------------------------------------------------------------------------------------
6480def 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---------------------------------------------------------------------------------------
6499def 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---------------------------------------------------------------------------------------
6515def 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---------------------------------------------------------------------------------------
6528op()
6529menu()
6530---------------------------------------------------------------------------------------
6531
6532-Perintah untuk mengunci script
6533
6534---------------------------------------------------------------------------------------
6535e32.Ao_lock().wait()
6536---------------------------------------------------------------------------------------
6537
6538Note:
6539Tanda > diganti menggunakan spasi.
6540
6541
6542
6543
6544
6545==========
6546
6547
6548
6549100.
6550
6551"MEMBUAT KEYGEN"
6552
6553Saya mau share sebuah script untuk membuat keygen...
6554
6555---------------------------------------------------------------------------------------
6556import appuifw
6557import e32
6558import os
6559import sysinfo
6560
6561def 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
6576key()