Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PyS60 Snippets Galore
- Table of contents:
- 001. "Brief History of Python".....
- 002. "Introduction to Basic Pys60".....
- 003. "Basic Python Symbian Application".....
- 004. "Learning to Create a Simple Python Script".....
- 005. "How to Make Your Own Application on HP Symbian or HP Make With Using Python Application".....
- 006. "How to Turn S60v3 Application into S60v2 Application".....
- 007. "Trick Accelerate Menu of HP Symbian S60v1 and S60v2 Simple Without Application and Move Cache to Memory Card".....
- 008. "Zntxhan app".....
- 009. "Py2Pyc Applications".....
- 010. "About Python-Based Applications and Its Functions".....
- 011. "Name the File Bulkly".....
- 012. "Creating Serial Number".....
- 013. "Making Google Translate Translator" Translate.....
- 014. "Cutting Image".....
- 015. "Wearing Special Character".....
- 016. "File Handling".....
- 017. "List".....
- 018. "Dictionary".....
- 019. "Dictionary and List".....
- 020. "2D Image".....
- 021. "Writing Text and Tittle On Application".....
- 022. "Perulangbn For Function".....
- 023. "Condition If".....
- 024. "Menu, Submenu and Popup Menu".....
- 025. "Minimize a Program Using Script Pys60".....
- 026. "Creating Password Script Pys60".....
- 027. "Py Script To Show Weak Battery".....
- 028. "Simple Script Makes Popup Menu".....
- 029. "Reading File With Powlite_Fm Module".....
- 030. "Changing Image Size Using Script".....
- 031. "Use Password Script On An Application".....
- 032. "Py Script To Backup File".....
- 033. "Multi Selection List".....
- 034. "Audio (Playing Mp3 1 Folder)".....
- 035. "Charging Name Less Than and More Than 5 Characters".....
- 036. "Multi_Query".....
- 037. "Simple Form"....
- 038. "Create Progressbar".....
- 039. "Displays Applications Already Installed In List Form".....
- 040. "Calling Image With Module From Graphics Import *".....
- 041. "The .Ttx File Dialing Script".....
- 042. "Text Script Being Voice".....
- 043. "Script To Call and Open Applications Outside Application System".....
- 044. "Script To Play Mp3 On Define Function".....
- 045. "Calling Text Using Glob Module Through Python Script".....
- 046. "How to Include Music or Mp3 into a Python Application".....
- 047. "Basic Logic Game Code Order".....
- 048. "Implementing 3D Computing Basics With Pys60" (Part 1).....
- 049. "Implementing 3D Computing Basics With Pys60" (p.2).
- 050. "Implementing 3D Computing Basics With Pys60" (ch.3).
- 051. "List, Function and Class".....
- 052. "Meload External Image With Image 1st Module".....
- 053. "Example Game Program Scissors, Stone, Paper".....
- 054. "Little Explanation of Identification in Python".....
- 055. "Heat Seeking Missile Alogarithm and Implementation".....
- 056. "Making Quiz With Pys60".....
- 057. "Reading the Message With Pys60".....
- 058. "Some Python Script Writing Style".....
- 059. "Displays IP With Pys60".....
- 060. "TxtField Module".....
- 061. "Repetition For In Pys60".....
- 062. "Double Menu Popup With Pys60".....
- 063. "Checking and Creating Folders With Pys60".....
- 064. "One Syntak Difference S60v1 and S60v2 Above"....
- 065. "Polygon Rotation With Pys60".....
- 066. "Scan Fill Drive With Pys60".....
- 067. "Combining Functions With Progress On Pys60".....
- 068. "Pys60 Script Encoded".....
- 069. "Displays All Application Icon Installed With Pys60".....
- 070. "Creating 4 Direction Cursor On Application With Pys60".....
- 071. "Making Analog Clock With Pys60".....
- 072. "Signal Indicator, Battery With FgImage (Pys60)".....
- 073. "Set FgImage On StandBy Pys60".....
- 074. "Screenshot With N-Gage or S60v1 (Pys60)".....
- 075. "Making Graph (Script Pys60)".....
- 076. "Get Coordinate Arround Circle (Pys60)".....
- 077. "Adjust Timing Subtittle With Python".....
- 078. "Creating Grid Menu 3x3 (Pys60)".....
- 079. "Creating a Simple Calculator".....
- 080. "Make Text Run With Backgroud Sound".....
- 081. "Make Popup Aa Check Pulsa".....
- 082. "Sending SMS Most Number".....
- 083. "Function of Appuifw Module".....
- 084. "Simple Scanning Application".....
- 085. "Text Editor Application".....
- 086. "Camera Motion".....
- 087. "Indicator Battery HP".....
- 088. "How to Store Audio".....
- 089. "Playing Mp3 File".....
- 090. "Text Talk".....
- 091. "How to Find Words in Inbox".....
- 092. "Accessing Inbox".....
- 093. "Selection List".....
- 094. "Two Dialogs".....
- 095. "Enter Name".....
- 096. "How to Record Audio".....
- 097. "Creating Selection List".....
- 098. "Making Popup Menu".....
- 099. "Creating a Code App".....
- 100. "Making Keygen".....
- ==========
- 001.
- "BRIEF PYTHON HISTORY"
- I want to share about Python history, what is Python, what is Python usefulness, all about yhon...
- Python for s60 is a high-level programming language that is a derivative of Python Language.
- Given the Python s60 programming language, it is possible to create a simple Script or even a complex program that can be applied to s60 type phones. So with Python s60, we can make the program directly through the Symbian-based phones on the phone that is old school or the latest version. So we can creativity by creating simple scripts or a program that can be run. But Python's ability can also make your phone end up with flash due to a fatal error.
- Brief and concise history of Python.
- If we see the name we must think that this Python name is taken from a type of snake called pithon, maybe because the creator likes snakes or amazed with the ability of pithon githu, common human mind is not it? But in fact not. The fact Naming programming language is based on the creator when he watched comedy shows on television on BBC named Monty Python's Flying Circus. Python was created by Guido Van Rossum in 1989 in Amsterdam Netherlands. This language provides many modules that can be used for various needs such as desktop applications, networks, and servers. However this programming language has a response or process that is slightly slower than C or Java programming language.
- Previously, this language is a programming language that can only be run through a PC. But now it can be directly run on mobile devices based on Windows Mobile, Palm and Symbian.
- So, for programmer friends or who want to learn programming language but limited do not have PC or Laptop only have HP symbian need not be discouraged. Because in Python s60 we are very possible to do programming wherever and whenever with HP symbian without having to bring PC or Laptop everywhere.
- ==========
- 002.
- "PYS60 BASIC INTRODUCTION"
- I want to share about pys60...
- What is a pys60?
- - pys60 is the derived programming language of Python for s60 phones.
- What is pys60 or Python on the phone?
- - create a script, make programs, create applications, games.
- How do I install Python on my phone or mobile phone or HP?
- - find out your brapa version of HP, then download the basic Python that fits your phone.
- Where do I find out what version of HP or my mobile phone?
- - find out here
- http://www.developer.nokia.com/Devices/Device_specifications/?filter2=s60
- What basic Python is there?
- - Python basic 1.45, Python module pack 1.33, Python shell script (all must be installed on same drive).
- Python modif same basic Python same not?
- - basic is same, only, Python modif have more module.
- Download Python basic, Python modif?
- - http://ichunk.mywapblog.com/python-basic-pys60-s60v123.xhtml
- - http://maxraider.wen.ru/Maxraider-phyton.html
- - http://arvana.mywapblog.com/python-modif-v1-7-0-s60v2.xhtml
- If the new module is not there? Where to download?
- - http://watt.eu5.org
- - http://www.agus-ibrahim.net/
- In Python there is an alien term ..
- - syntax: line of sentences
- - script: a collection of syntax that can run a program
- - string: letters
- - integer: numbers
- - identification:
- - interactive console:
- What Python script features?
- - ending in .py, .pyc,, pyd
- Writing Python script how?
- - use ped, x-plore, dedit, or other Python editor apps, as per individual taste. save it with a .py extension
- - special x-plore, uncheck "save as unicode" before saving.
- How to run the script we have created how?
- - open Python, run script that we have saved earlier.
- ==========
- 003.
- "PYTHON SYMBIAN BASIC APPLICATIONS"
- I want to share a little information about HP Symbian and Python...
- Previously we must know first our HP symbiam specifications. If you do not know at all we can visit the Device Specification in the Nokia Forum to find out our mobile neighbor. How to select our HP type of page. Then we will be taken to the Device Detail page, boxed Column that reads Technical Specs it tedapat technical specifications from our HP. To select pythonnya please see the series or edition and Feature packnya from our HP ditechnical specs earlier. Now please Download and select the appropriate python with your HP...
- * Symbian s60v2 or s60 2nd Edition FP1
- -PythonScriptShell_1_4_5_2ndEd.SIS
- -PythonFors60_1_4_5_2ndEd.SIS
- * Symbian s60v2 or s60 2nd Edition FP2
- -PythonScriptShell_1_4_5_2ndEdFP2.SIS
- -PythonFors60_1_4_5_2ndEdFP2.SIS
- * Symbian s60v2 or s60 2nd Edition FP3
- -PythonScriptShell_1_4_5_2ndEdFP3.SIS
- -PythonFors60_1_4_5_2ndEdFP3.SIS
- * Symbian s60v3 or S60 3rd Edition
- -PythonScriptShell_1_4_5_3rdEd.SIS
- -PythonFors60_1_4_5_3rdEd.sis
- * Symbian s60v3 or v5 | s60 3rd or 5th Edition
- -Home Page (Pys60v1.0.x and 2.0.0) -Python_2.0.0.sis
- -Py Module Pack s60v3:
- Note:
- Installation (specially s60v3).
- 1. Python Script Shell and Python for s60 can be installed in phone memory (C :) or memory card (E :) but Python Module Pack must be installed in phone memory (C :)
- 2. Python-based applications must be installed in the same place where Python script shell and Python for s60 are installed.
- 3. It is strongly recommended to install Python script shell and Python for s60 on memory card (E :) so as not to incriminate HP performance.
- ==========
- 004.
- "LEARN MAKE SCRIPT PYTHON SIMPLE"
- I want to share about how to create a Python script,
- Python is a high-level scripting language program that benefits from simple syntax and human readability, a comprehensive core library, and the ability to extend using native code.
- Python is a multi-paradigm language, supporting object-oriented and functional programming styles, inter alia, giving freedom to approach problems in various ways.
- Python on Symbian (also known as "Python for s60" or "Pys60") is the Nokia port of the Python language for the Symbian platform. Python on Symbian was first released by Nokia at the end of 2004, and donated to the Symbian Foundation in early 2010.
- In the following chapters, we describe the latest versions of Python on Symbian, v2.0.0 for s60v3 and v1.4.5 for s60v2.
- Why Should I Use Python On Symbian? The main reason for using Python on Symbian is that it's easy to learn and you can do a lot with very little code.
- Most people can read Python code with just a few hours of study and can start developing mobile apps not long after.
- Applications made in Python are indistinguishable from native C ++ applications and for most purposes offer much of the same performance.
- Most of the important functions available for native apps (for example, access to camera, device position, sensor, etc.) are exposed to Python apps via a simple API.
- If you're an advanced developer in other programming languages (like Symbian C ++, Java ME or others) you can also benefit by using Python for rapid application development. So little is needed when compared to other languages, that the application can be fully functional prototyped, shown and tested very quickly.
- Python Application ("script" ) is just a text file containing code written in the Python programming language and named with the "py" file extension).
- Scripts can be written using a text editor and can be run either from within the Python Interactive Shell application on the device or emulator device for the computer or can also be written via standalone applications that can be installed to Symbian devices, such as Dnotepads60v2, Pyedets60v2, if using X-plore red checkmark in "save as unicode" must be removed.
- Sample Testing Python Script Script Interactive scripts make it very easy to test your script during development.
- Shell is just an app that allows you to type and execute arbitrary Python commands or to load and run the entire script file. Let's make a simple Python app.
- Write the following line of your edited text:
- ----------------------------------------------------------------------------------------
- print "Hello! Python On Symbian"
- ----------------------------------------------------------------------------------------
- If you are using X-plore, press menu file new text file name the file with "ScriptPertamaku.py" and ok, then hit menu and click 'save as unicode' to uncheck red, then create script : print "Hello! Python On Symbian" ok. Testing On Symbian Devices. It's time you tested your script.
- Move the file or 'My Script.py' to E: / System / apps / Python.
- Open the Python app and press options run script select 'ScriptPertamaku.py'
- If you are successful then you will see textHello! Python On Symbian.
- You can also run an existing script like ball.py, snake.py. Then next and create a second script.py
- ----------------------------------------------------------------------------------------
- import appuifw
- appuifw.note (u 'Hello! Python On Symbian')
- ----------------------------------------------------------------------------------------
- Test your second script, open Python Run script and select Script Second .py
- If you want to try the script again .. please see this script.
- Script appuifw
- To test it, open Python, Options interactive console type
- import appuifw click ok
- Put the script
- To show errors:
- ----------------------------------------------------------------------------------------
- appuifw.note
- (u 'Error.', 'error')
- click ok
- ----------------------------------------------------------------------------------------
- To display information:
- ----------------------------------------------------------------------------------------
- appuifw.note
- (u 'Information.', 'info')
- ----------------------------------------------------------------------------------------
- To display a confirmation:
- ----------------------------------------------------------------------------------------
- appuifw.note (u 'Success',' conf')
- ----------------------------------------------------------------------------------------
- To show a question:
- ----------------------------------------------------------------------------------------
- appuifw.query ('Would you like to exit?' .decode ('utf-8?),' query')
- ----------------------------------------------------------------------------------------
- For input commands;
- Name:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "Enter name:", "text", u "Cebri Nugraha" )
- ----------------------------------------------------------------------------------------
- Number:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "Enter no.:","number")
- ----------------------------------------------------------------------------------------
- Code:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "input code:", "code" )
- ----------------------------------------------------------------------------------------
- Date:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "Put date:", "date" )
- ----------------------------------------------------------------------------------------
- Time or hour:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "Enter time:", "time" )
- ----------------------------------------------------------------------------------------
- Float:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "Put float:", "float" )
- ----------------------------------------------------------------------------------------
- Query:
- ----------------------------------------------------------------------------------------
- appuifw.query (u "Input query:", "query" )
- ----------------------------------------------------------------------------------------
- To set the application screen;
- Normal screen:
- ----------------------------------------------------------------------------------------
- appuifw.app.screen = 'normal'
- ----------------------------------------------------------------------------------------
- Large screen:
- ----------------------------------------------------------------------------------------
- appuifw.app.screen = 'large'
- ----------------------------------------------------------------------------------------
- Full screen:
- ----------------------------------------------------------------------------------------
- appuifw.app.screen = 'full'
- ----------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------
- appuifw.app.title = u "error"
- ----------------------------------------------------------------------------------------
- To create a selection menu:
- ----------------------------------------------------------------------------------------
- appuifw.app.menu = []
- appuifw.popup_menu ([u "Option 1", u "Option 2", u "Option 3"])
- ----------------------------------------------------------------------------------------
- Application background color:
- ----------------------------------------------------------------------------------------
- appuifw.app.body.color = 0xff0000
- ----------------------------------------------------------------------------------------
- ==========
- 005.
- -Python
- -X-plorer
- -Sisboom
- -Linkaper
- -Ped
- Once downloaded all the above applications please you install all the applications on HP, I suggest installing in external memory so that your HP is not slow after that follow these steps:
- Read more:
- 1. Create first scripnya this example python script I gave the name Azam restart.py
- ----------------------------------------------------------------------------------------
- import appuifw
- import e32
- import switchoff
- def restart():
- a = appuifw.query (u'Atur Time Time: ',' number ')
- e32.ao_sleep (a)
- switchoff.Restart()
- def shutdown():
- b = appuifw.query (u'Enter a Second Time: ',' number ')
- e32.ao_sleep (b)
- switchoff.shutdown()
- def azam():
- appuifw.note (u 'this app was created by syamsul azam creator')
- appuifw.app.title = u 'Azam restar'
- appuifw.app.menu = [(u'Restart ', restart), (u'Shutdown', shutdown), (u'maker ', azam)]
- x = e32.Ao_lock()
- x.wait()
- ----------------------------------------------------------------------------------------
- 2. The second step after copying the script above the save with the extension py so Azam restart.py
- 3. The third step after disave with py extension, test first before packing into the application. If already tested the script applied Ped and run perfectly then packed by using linkaper application.
- 4. The fourth step open the linkaper app> options> create app> select the script was to be used as an application that has been tested diaplikasi Ped.
- 5. When finished, try to open the menu on your HP if there is no application first opened because the application has not been able to run perfectly.
- 6. Next step open the x-plorer app in directory E: system / app / Azam restart
- 7. The next step in default.py open and delete all the contents in default.py changed to "import Azam restart" if I recommend azam restartnya copy from the folder name to exact
- 8. The next step is to copy the script you have tested and dipaste in Azam restart.
- 9. Try to open menu then run the application that was made. The road or not, if not running means something is wrong.
- ==========
- 006.
- "HOW TO CHANGE S60v3 APPLICATION BECOME A S60v2 APPLICATION"
- I want to share how to change s60v3 application to s60v2, application that can be changed only application based on Python...
- Equipment:
- 1.Linkapper
- 2.X-Plore
- 3.Sisboom v6-4
- Here as an example I change the Application IDesigner owned by Symbian v3 to Symbian v2 Application.
- 1. Create a new folder in E: / system / apps / (Application name)
- example: E: / system / apps / ImageDesigner
- 2. Create a new text file and name it default.py in E: / system / apps / ImageDesigner
- The way to press menu> file> new text file and Menu- Save as unicode (uncheck the red) default.py is the first step to create Python-based applications, without it Applications can never be created.
- 3. Open the LinkAPPer Application, click Options-Create new app. Then go to the newly created folder and select the default.py file created just now, it will display option Normal opening and Open with, select Normal opening.
- 4. Then enter the name of the program: ImageDesigner then put it on drive E:\
- 5. A notification will appear stating that a file with the same name already exists, stop it? Just hit "Cancel"
- 6. Enter UID (or don 't touch): enter UID manually or just press Ok, select Ok
- 7. Choice of type: select the icon to display dimenu, The App is created and will appear in the menu in afew seconds (choose by taste)
- 8. You can see the icon on your mobile phone, but never open it first because it is not finished yet.
- 9. Open Sisboom Application, use sisboom version above 6. if you use sisboom version below 6, you will never able to unpack sis or sisx file belongs s60v3. Unloading IDesigner rc 1.40 s60v3.sis
- 10. Open X-plore and go to the folder where the python files are located (the unloading result)
- 11. Mark the files one by one and move them to the Applications folder you created (E:\System\Apps\ImageDesigner) ./ If you have questions that will appear when you move the python files to the ImageDesigner folder, just hit Ok
- 12. All has ended, test now by clicking the Application icon on your mobile phone. If it can be opened we can say that we succeed
- 13. To make it a full s60v2 Application, silhakan your pack into one using Sisboom Application.
- ==========
- 007.
- "TRICK ACCESSIBLE MENU HP SYMBIAN S60v1 and S60v2 SIMPLE WITHOUT APPLICATIONS AND MOVE CACHE TO MEMORY CARD"
- Trick 01
- 1. Use x-plore
- 2. Select menu> new text
- 3. Create in c or in C> system> here or it could be in C / system> shareddata
- 4. Create its name Menu.cfg
- 5. Create the contents Z / System / Apps / Menu / Menu.app
- 6. Save
- 7. In order not hard hard to make that no 5... Copy aja writing... Or copy this article through your HP just hold the pen button and slide the right
- (Z / System / Apps / Menu / Menu.cfg)
- Trick 02
- 1. Create a folder in C name Shareddata
- 2. After that make a text like way 1
- 3. Name it 101f8557.ini
- 4. Fill it with
- ----------------------------------------------------------------------------------------
- CachEnable = True
- CacheSize = 20000000
- CacheDir = e:\cache
- ODomainUrl = http: //host53.nokia-boston.com/Cache_OpCache/Op_Menu.xhtml
- OCacheSize = 300000
- OCacheDir = c:\cache
- ----------------------------------------------------------------------------------------
- The cache size section can be modified can be replaced 3.4 dst
- Press the pen button to copy the code.
- ==========
- 008.
- "ZNTXHAN APPLICATIONS"
- I want to share about how to edit a compiled Python file...
- Python files that have been decompiled can not be edited using x-plore as we are in .py file
- Actually it can, but a bit complicated because we must edit from hex or chart...
- To avoid complicated use Zntxhan to decompiling py scripts and make necessary modifications.
- Sometimes it is difficult to decompile dile PYD, if you know Python encoding, you can use Zntxhan to enter new encoding.
- Similarly after decompiling you can also translate RSC files and can translate the app in Indonesian without translating the script code because if you translate the script code it will be a problem for your application. Now again, I say that all Python S60v3 applications work on S60V2. So do not lose hope and try modif in the application.
- Note:
- Make sure your phone is filled with python program.
- ==========
- 009.
- "PY2PYC APPLICATIONS"
- I want to share a little information about Py2Pic applications...
- Py2Pyc: Compile Your Own Python Code.
- .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.
- Now let's start to compile:
- To compile, we have three choices. That is using an existing program called py2pyc, manual using Python shell, and write your own simple py2pyc script. Of the three options, for me all the same because the result is the same:
- Let's try one on one:
- But before, let's make a script that will serve as an experiment. We create a simple script like the following,
- ----------------------------------------------------------------------------------------
- # python script
- def Hello():
- # say hello :)
- print "Hello World!"
- # done!
- # call the function
- Hello()
- ----------------------------------------------------------------------------------------
- Save it on drive E:\to make it easy to find it ::
- 1. Using Py2Pyc Program
- The first step is, download the Py2Pyc program, then do the installation as usual. Open Py2Pyc program, select [Options] -> [Select File]
- Find where the script will be compiled. Once found, click [OK] to mark then select [Options] -> [Done]
- Select [Options] again and select [Compile]. Done.
- 2. Using the Command Line (Python Shell)
- Compiling python scripts using a command line is actually simpler because we only need to type in two command lines only.
- Start the Python program, select [Options] -> [Interactive console] then type the following command,
- ----------------------------------------------------------------------------------------
- import py_compile
- py_compile.compile ("E:\\sayhello.py")
- ----------------------------------------------------------------------------------------
- That's it and it's done. Our script has been compiled into a .pyc binary.
- 3. Using Simple Scripts
- This method is actually the same as the number 2 (two). Only, we write the command into a file to be executed at any time without having to retype the code. In this step, we will create a script similar to the Py2Pyc program but can only compile one script in one session without the facility to mark. File facility we use the browser module named fm.
- Let's make the script:
- import module required
- ----------------------------------------------------------------------------------------
- import fm
- import py_compile
- import appuifw
- import os
- def SelectFile():
- '' 'Find and select files to compile' ''
- appuifw.app.title = u "Select .py File"
- # use the file manager function of the fm module
- SF = fm.manager()
- # Check the SF value. What is None?
- # If None, the user pressed the cancel button
- if SF! = None:
- # check the file extension. .py or not
- if os.path.basename (SF) [- 3:]. lower() == ". py":
- # if you have a .py extension, compile it
- try:
- py_compile.compile (SF)
- CDone()
- except:
- # when the compilation fails, a message will appear
- appuifw.note (u "Error:% s: Can not be compiled"% os.path.basename (SF), "error")
- CError()
- else:
- # when the selected file does not have a .py extension
- appuifw.note (u "% s: Not a python script!"% os.path.basename (SF), "info")
- CError()
- else:
- # when the user presses the Cancel button
- appuifw.note (u "Compilation undone!", "conf")
- def CDone():
- appuifw.note (u "Compile is successful!", "info")
- def CError():
- appuifw.note (u "Compilation failed!", "info")
- appuifw.note (u "Select the file to compile,...", "info")
- SelectFile()
- ----------------------------------------------------------------------------------------
- Save and locate it in the Python directory (E:\System\\Apps\\Python) to run through Python App. Then open the Python app, choose [Options] -> [Run Script] and select the script we just created.
- The script will instantly open the browser file view and wait for input from you. [OK] or [Cancel].
- Script Execution
- In the last session of this paper, we will discuss about how the execution of scripts that have not been and that have been compiled. As an experiment, we use the command line only:
- ----------------------------------------------------------------------------------------
- execfile ("E:\\sayhello.py")
- Hello World!
- ----------------------------------------------------------------------------------------
- Then, how to compile the script? Compiled scripts can not be executed in the above manner. When forced, will cause errors in Python Shell and Python Shell to be restarted.
- The binaries of the Python script can be run using the import method. The usual method used to load Python module. And of course, the location of the compiled script should be listed in Python Path. If not, we can add the Path where the location of our script is using sys module.
- ----------------------------------------------------------------------------------------
- import sys
- sys.path.append ("E:\\")
- import sayhello
- Hello World!
- ----------------------------------------------------------------------------------------
- And if it turns out the import import sayhello does not work, we still can still call the function manually.
- ----------------------------------------------------------------------------------------
- import sayhello
- sayhello.Hello()
- Hello World!
- ----------------------------------------------------------------------------------------
- ==========
- 010.
- "ABOUT APPLICATIONS BASED ON PYTHON AND ITS FUNCTIONS"
- I want to share a little info about python-based apps and their script functions...
- Confused to distinguish Python-based applications. Because there is no difference. If java kan runs slow in Symbian.
- Immediately discussed.
- A python-based app will not run without the DEFAULT.PY file in that application folder (E:\System\Apps\NAMEAAPP_\default.py). But be careful also maybe the app is not python based but just a fake DEFAULT.PY file to cover-up. To ensure that the application wins really python based let's check the contents of DEFAULT.PY characters.
- If the character contains the # sign beside it there are only messages and afterwards no longer found the script means the file is not related to the application.
- Example:
- # Script Python by xxxxxx
- # For more apps visit www.xxxxx.xx
- Unless there is a script under IMPORT.
- Example:
- # Script Python by xxxxxx
- # For more apps visit www.xxxxx.xx
- import xxxpy
- Import is a calling function. For that check also whether in the application folder or folder libs there xxxpy.py file / xxxpy.pyc (E:\System\libs\).
- If the DEFAULT.PY script contains long Syntax-syntax it is clear that the application is Python-based.
- The conclusion:
- The python app calls each other-calling. Initially APLIKASI_BERBASIS_PYTHON.app calls the Default.py file in the folder and the Default file wins again to the next file eg to the libs folder or that is in the application folder.
- Sample file:
- E:\System\Apps\ZIMPDA\
- there are files:
- - ZIMPDA.app * <Application *
- - ZIMPDA.aif
- - ZIMPDA.src
- - Default.py * <Script python *
- - main.pyc * <Compiled python script *
- Example of default.py app ZIMPDA:
- # Script by Zidna Mmc
- # Bring up an error message
- import appuifw * <This function calls py or pyc in the libs folder. Karna is not in the application folder. *
- import main * <This function calls the py or pyc in the application folder *
- Example of the contents of the main.pyc file that was decompiled into main.py app ZIMPDA:
- appuifw.note (u "Error gan, Systemnya again ga path", error)
- appuifw.app.set_exit()
- Note:
- So not necessarily all the programs are default.py files. As the example above. The default.py function is simply to call the main.pyc file and the main.pyc file that program the application, which is to generate the text error.
- ==========
- 011.
- "APPLY THE FILES ONLY MASS"
- I want to share about scripts to name files in bulk...
- We may often be faced with the problem of naming files in bulk. I mean, look at the mp3 file, sometimes the file name is like this: "Track 05.mp3? Create me a file name like that needs to be replaced and unfortunately replace one clear job tired.But do not worry, with pys60 everything can be resolved.
- To name files in bulk, of course we must use looping or looping function.
- Suppose we want to name the files with the name "song_1.mp3, lagu_2.mp3? Dst
- Here's an example script,
- ----------------------------------------------------------------------------------------
- import os
- dirk = e:\\mp3
- dir = os.listdir(dirk)
- to = 1
- for file in dir:
- path = dirk file
- os.rename (path, dirk "lagu_" str (to) ".mp3?)
- to = 1
- print 'Done'
- ----------------------------------------------------------------------------------------
- Note:
- -In the path = dirk file. It means combining the file names in sequence with the place directory.
- -The purpose of is the blocking of spaces which is 4 spaces of a loop.
- In the os.rename section (path, dirk "lagu_" str (to) ".mp3?) .That is to say the file that was merged with" song_ "continues to be merged with the specified sequence. To = 1 is adding one by one var to.
- ==========
- 012.
- "MAKE SERIAL NUMBER"
- I want to share a script to create an activation code on an application...
- Has it ever occurred to you to distribute the apps you created as shareware? So people can try it out first and they can see if the app is really useful to them or not.
- But before we have to be self conscious, It's worth our application given a safety or serial number. It's worth a really useful application or through a complicated manufacturing process.
- Applications that are distributed with shareware methods usually have time limits in their use and if the deadline is up then the user must do the activation by registering the application or purchase license to the author of the application by mentioning the serial number on the existing application.
- There are also shareware types that do not use time limits, but place restrictions on the facilities that can be used. There are even those who do not use time constraints or facilities restrictions, but the applications used will always show ads when the application is used.
- If you as an app maker of course you do not want the activation key can be used by several different users who deliberately duplicate the application for personal gain, this can be tricked by creating a different serial number for each different user (one user one serial number) so that the activation key can only be used by one user only.
- To create a unique serial number for each user we can use the IMEI number on the phone, so that each application is installed on a different phone then it will have a different serial number.
- To find out the IMEI number we can use sysinfo module.
- Here is how to create a unique and different serial number on each phone by utilizing IMEI phone number.
- ----------------------------------------------------------------------------------------
- import sysinfo
- imei = sysinfo.imei()
- code imei [2] + imei [0] + imei [12] + imei [9] + imei [3]
- code = int (code) +2011
- print the code
- ----------------------------------------------------------------------------------------
- Explanation:
- In the process of processing IMEI
- imei [imei] + imei [12] + imei [9] + imei [3] means taking numbers from positions 3, to 1, 2, ke3 to 10 and 4 from IMEI.
- Eg IMEI 356664000736846
- SN or Serial number generated is 635676
- code = int (code) +2011 means converting the SN string to an integer then plus 2011.
- Rich gini 635676 2011 results 637687
- That's how to Generate a unique code from an IMEI number. For values like [2], [0], [1], [2], [9], [3], and 2011 you can specify and add as you like.
- ==========
- 013.
- "MAKE TRANSLATE ALA GOOGLE TRANSLATION"
- Dear...
- ANGELMAN% ANGELwoman,
- I want to share about how to create an online sentence translator application...
- Who does not know google translate, a service from google that allows users to do one word translation, one paragraph or translate a website. Available languages are already quite complete.
- Now we can use the service in python script easily.
- Let's make it, open the Python editor Ped, choose new-python.
- ----------------------------------------------------------------------------------------
- import urllib
- text = 'I want to eat'
- langpair = 'en | en'
- base_url = 'http: //ajax.googleapis.com/ajax/services/language/translate?'
- data = urllib.urlencode ({'v': 1.2, 'ie': 'UTF16 ?,' q ': text.encode (' utf-8?), 'langpair': langpair})
- with the url being encoded
- url = base_url + dat a
- null = None
- hsl = urllib.urlopen (url) .read()
- of the opening of the url
- dic = eval (hsl)
- brada di var dic
- detail = dic ["responseDetails"]
- if detail == None:
- resp = dic ["responseData"]
- resp = resp ["translatedText"]
- else:
- resp = detail
- print resp
- ----------------------------------------------------------------------------------------
- ==========
- 014.
- "CUTTING PICTURE"
- I want to share a script to crop the image or croping image...
- In this article I will explain how to cut the image on pys60.
- Logically gini, we open the original image or image source continue to create a new image with the specified size at the value to be cut, then combine or bind (blit) the original image to a new image with the specified position.
- The script looks like this,
- ----------------------------------------------------------------------------------------
- from graphics import *
- cut (= 10,10,110,110)
- source = Image.open ("c:\\image.jpg")
- sx, sy = source.size
- lx, ly, x, y = cut
- if x> sx:
- x = sx
- if y> sy:
- y = sy
- img = Image.new ((x-10, y-10))
- img.blit (source, cut)
- img.save ("c:\\pieces.jpg")
- ----------------------------------------------------------------------------------------
- That's how to cut a very simple image on pys60.
- There is another way of checking the pixel per pixel of the image source starting from the cut value. Then create a new image whose size corresponds to the cut value, make point by point on the new image and the point color takes from the pixel pixels that were checked.
- ==========
- 015.
- "USE SPECIAL CHARACTER"
- I want to share how to insert a special character into an app...
- Have you ever inserted special characters or characters of arabic, russian etc in pys60? Then what happen? What happens is an error message will appear. Then, how?
- Special characters will not run on pys60, unless we change the encoding into utf-8.
- How to decode is very easy, here's an example:
- ----------------------------------------------------------------------------------------
- def dc (x):
- return x.decode ('utf-8?,' ignore ')
- print dc ("khusus_karakter_disini")
- ----------------------------------------------------------------------------------------
- For more convincing, please try it on appuifw.note
- ==========
- 016.
- "FILE HANDLING"
- I want to share how pys60 aar can open or read or write automatically...
- Anything can be done with Python, including one handling a file, such as opening, reading, or writing a document file by creating an object file, which has methods and attributes to manipulate the file.
- The operation of reading or writing files depends on the mode declared by us when opening the file. To do that we do not need a module.
- Here is a script for creating a text file in Python S60:
- ----------------------------------------------------------------------------------------
- f = open ("c:\\document.txt", "w")
- text = u "Python S60\nSiky play python"
- f.write (text)
- f.close()
- ----------------------------------------------------------------------------------------
- To open a file (create an object file), we use the open method with parameters in the form of filename and mode. In the above example, we open document.txt file with mode 'w' which means write, then use write method to insert text from text variable into document.txt file
- And the word "\n" is to create a new line in the text.
- ----------------------------------------------------------------------------------------
- f = open ("c:\\document.txt")
- print f.name
- print f.mode
- ----------------------------------------------------------------------------------------
- In the above example we do not enter the mode parameter because by default if we do not specify the mode parameters of the open method, the mode of the opened file is 'r' alias read.
- ----------------------------------------------------------------------------------------
- f = open ("c:\\document.txt")
- print f.read()
- ----------------------------------------------------------------------------------------
- The read method is used to read the entire contents of a text file. It is important to note that when we read the text of the file, the newline character will be included at the end of each line marked with\n.
- When we use the read method, the position of the file we open is at the end of the file.
- To restore the initial position of the file, we use seek() method so we can re-read the file we open. The readline method is to read each line of the text file that we open until it returns to the end of the file.
- ----------------------------------------------------------------------------------------
- f = open ("c:\\document.txt")
- f.seek (0)
- print f.readline()
- print f.readline()
- f.close()
- ----------------------------------------------------------------------------------------
- ==========
- 017.
- "LIST"
- I want to share a way to create a list...
- List is one of the most useful facilities in Python. This can be equated with arrays when in other programming languages. Here is an example list and its use.
- Example:
- ----------------------------------------------------------------------------------------
- list1 = ["Cat", "Bird", "Chicken"]
- list2 = [23,54,87,78]
- ----------------------------------------------------------------------------------------
- -Using List:
- Accessing items
- print list1 [0] # will print the first element of list1 ie "cat"
- print list2 [1] + list2 [0] # sum element list2 [1] list2 [0] the result is 77
- Added items
- Example:
- ----------------------------------------------------------------------------------------
- list1.append ("Duck")
- ----------------------------------------------------------------------------------------
- Added the string "duck" to list1. So, list1 now contains ["Cat", "Bird", "Chicken", "Duck"]
- Replace items
- Example:
- ----------------------------------------------------------------------------------------
- a = [12,22,32,42,52,62]
- a [2] = 10M
- ----------------------------------------------------------------------------------------
- Replacing the 3rd element is 32 to 10. So now list a contains [12,22,10,42,52,62]
- Deleting items
- Example:
- ----------------------------------------------------------------------------------------
- del a [3]
- ----------------------------------------------------------------------------------------
- Removing the third element is 52
- Other functions
- Reverses the list element
- Example:
- ----------------------------------------------------------------------------------------
- a.reverse()
- ----------------------------------------------------------------------------------------
- Sort the list in descending order
- Example:
- ----------------------------------------------------------------------------------------
- a.sort (reverse = False)
- ----------------------------------------------------------------------------------------
- Sort the list in descending order
- Example:
- ----------------------------------------------------------------------------------------
- acsending
- a.sort (reverse = True)
- ----------------------------------------------------------------------------------------
- ==========
- 018.
- "DICTIONARY"
- I want to share a script to print or print a text...
- Dictionary is an object in Python that is used to store pairs of values. Dictionary is an important concept in python and plays an important role in many occasions.
- -Defining Dictionary:
- ----------------------------------------------------------------------------------------
- dict1 = ("name": "agus", "age": 16 ", address": "indramayu")
- ----------------------------------------------------------------------------------------
- Dictionary dict1 above has three elements. Each has its own key and its value. We can access the value by using the "Name" key for Agus, "Age" for 16 and so on.
- -Access Element:
- ----------------------------------------------------------------------------------------
- print dict1 ["name"]
- ----------------------------------------------------------------------------------------
- This will print the string "Agus"
- -Adding Elements:
- ----------------------------------------------------------------------------------------
- dict1 ["Phone"] = "62838000000?
- ----------------------------------------------------------------------------------------
- -Remove Element:
- ----------------------------------------------------------------------------------------
- del dict1 ['address']
- ----------------------------------------------------------------------------------------
- -Listing all keys
- ----------------------------------------------------------------------------------------
- k = dict1.keys()
- ----------------------------------------------------------------------------------------
- Will display ['age', 'no. Phone ',' name ']
- ----------------------------------------------------------------------------------------
- v = dict1.values ()
- ----------------------------------------------------------------------------------------
- Will display [16, '62838000000,' Agus']
- ==========
- 019.
- "DICTIONARY and LIST"
- I want to share the combination between Dict and List...
- Dictdictionary or dict has pair value. in the use of the code using kurawa brackets {}.
- Example:
- ----------------------------------------------------------------------------------------
- identity = {'name': 'wawan', 'age': 20, 'address': 'jakarta'}
- print identity ['name']
- ----------------------------------------------------------------------------------------
- the result:
- Wawan
- ----------------------------------------------------------------------------------------
- print identity ['address']
- ----------------------------------------------------------------------------------------
- the result:
- Jakarta
- List (list)
- List or list in use use [].
- Example:
- ----------------------------------------------------------------------------------------
- fruit = ['apple', 'banana', 'pineapple']
- print fruit [0]
- ----------------------------------------------------------------------------------------
- the result:
- Apple
- because the first order of the list in pys60 starts from 0 then 1.2 and so on.
- -Added data
- ----------------------------------------------------------------------------------------
- buah.append ('watermelon')
- ----------------------------------------------------------------------------------------
- result then list fruit into fruit = ['apple', 'banana', 'pineapple', 'watermelon']
- -Delete data
- ----------------------------------------------------------------------------------------
- buah.pop (0)
- ----------------------------------------------------------------------------------------
- The pop function will delete data from the fruit variables in the order they are,
- so the fruit list now contains ['banana', 'pineapple']
- ----------------------------------------------------------------------------------------
- fruit = ['apple', 'banana', 'pineapple']
- buah.remove ('apple')
- ----------------------------------------------------------------------------------------
- The remove function will delete data from the fruit variable by its name.
- -Sort data
- ----------------------------------------------------------------------------------------
- number = [1,8,4,6.7]
- number.sort()
- ----------------------------------------------------------------------------------------
- ==========
- 020.
- "2D IMAGES"
- I want to share how to create 2D images...
- Basically Figure 2D consists of 2 coordinate points commonly called x and y. x is the horizontal (horizontal) coordinate of the left right and y is the vertical (vertical) coordinate from top to bottom. so if the value of x equals 0 (zero) and y is also 0 (zero) then the position of the point is in the top left corner.
- Looping or Core repetition works like a loop system in the animated image process. In this case it is used to bring up many created objects. My experience when trying to create many objects without looping at 240x320 resolution turned out the results can not be full.
- Make a rectangle and ellips to make it use this code img.rectangle ((positionX, positionY, positionX + width of Object, positionY + height Object), line color, object color). The colors used in RGB mode (Red, Green, Blue) 0xRRGGBB
- example:
- ----------------------------------------------------------------------------------------
- img.rectangle ((50, 20, 70, 60), 0x00dddd, fill = 0xdd0000)
- ----------------------------------------------------------------------------------------
- To ellipse the code is almost the same as making a box.
- Example:
- ----------------------------------------------------------------------------------------
- img.ellipse ((50, 70, 80, 90), 0xdd0000, fill = 0x00dd00)
- ----------------------------------------------------------------------------------------
- Creating Point
- In contrast to ellips and rectangle, use only X coordinates, its y only and width (Point width)
- example:
- ----------------------------------------------------------------------------------------
- img.point ((200, 100), 0x0000dd, width = 10)
- ----------------------------------------------------------------------------------------
- Creating Line
- Create a line connecting between 2 points of coordinates. then the regulator: (x1, y1, x2, y2)
- example:
- ----------------------------------------------------------------------------------------
- img.line ((20, 20, 120, 20), 0xdddd00)
- ----------------------------------------------------------------------------------------
- Creating Text
- To make the writing settings like this: ((x, y), u'text to write ')
- example:
- ----------------------------------------------------------------------------------------
- img.text ((60, 300), 0x00dd00)
- ----------------------------------------------------------------------------------------
- Practice:
- ----------------------------------------------------------------------------------------
- import appuifw
- import graphics
- import e32
- ----------------------------------------------------------------------------------------
- -Define definitions of apps
- -How to stop the while loop
- -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.
- ----------------------------------------------------------------------------------------
- def close():
- global run
- run = 0
- ----------------------------------------------------------------------------------------
- -Set the softkey button to run the "close" definition when pressed.
- ----------------------------------------------------------------------------------------
- appuifw.app.exit_key_handler = close
- ----------------------------------------------------------------------------------------
- -Creates a "c" variable that contains the canvas of the appuifw module
- ----------------------------------------------------------------------------------------
- c = appuifw.Canvas()
- ----------------------------------------------------------------------------------------
- -Set the application body to the canvas
- ----------------------------------------------------------------------------------------
- appuifw.app.body = c
- ----------------------------------------------------------------------------------------
- -Screen size "full screen"
- ----------------------------------------------------------------------------------------
- appuifw.app.screen = 'full'
- ----------------------------------------------------------------------------------------
- -Creates an image programming variable from the graphics module, the default is white.
- - (240,320) is the screen resolution.
- ----------------------------------------------------------------------------------------
- img.graphics.Image.new ((240,320))
- ----------------------------------------------------------------------------------------
- -Run is a variable that acts as an application closing regulator.
- ----------------------------------------------------------------------------------------
- run = 1
- ----------------------------------------------------------------------------------------
- -Creates a while function.
- ----------------------------------------------------------------------------------------
- while run == 1:
- ----------------------------------------------------------------------------------------
- -Calling the image using c.blit
- -remember if c is canvas and img is graphics.Image.new
- ----------------------------------------------------------------------------------------
- c.blit (img)
- ----------------------------------------------------------------------------------------
- -Make a box
- ----------------------------------------------------------------------------------------
- img.rectangle ((50, 30, 100, 70), 0x00dddd, fill = 0xdd0000)
- ----------------------------------------------------------------------------------------
- -Creates ellipse
- ----------------------------------------------------------------------------------------
- img.ellipse ((100, 70, 30, 100), 0xdd0000, fill = 0xdddd00)
- ----------------------------------------------------------------------------------------
- -Creates a Point
- ----------------------------------------------------------------------------------------
- img.point ((200, 150), 0x0000dd, width = 50)
- ----------------------------------------------------------------------------------------
- -Making a line
- ----------------------------------------------------------------------------------------
- img.line ((00, 200, 240, 200), 0x00dd00)
- ----------------------------------------------------------------------------------------
- -Creating text
- ----------------------------------------------------------------------------------------
- img.text ((20,220), u'prajurit ', fill = 0xdddddd)
- ----------------------------------------------------------------------------------------
- -Because the default img black so we first change to black using clear.
- ----------------------------------------------------------------------------------------
- img.clear (0x000000)
- ----------------------------------------------------------------------------------------
- -Creates the application cover. when the close function is executed the ao_yield() function of the e32 module will stop the while loop.
- ----------------------------------------------------------------------------------------
- e32.ao_yield()
- ----------------------------------------------------------------------------------------
- Note:
- Signs is the number of spaces.
- The size of the letters, symbols, and spaces must be the same as the ones written above.
- ==========
- 021.
- "WRITE TEXT AND TITLE ON APPLICATIONS"
- I want to share a script to display text at the beginning of an app and also tittle an app...
- -Modules used appuifw and e32
- ----------------------------------------------------------------------------------------
- import appuifw, e32
- ----------------------------------------------------------------------------------------
- -Creates application title
- ----------------------------------------------------------------------------------------
- appuifw.app.title = u "APPLICATIONS"
- ----------------------------------------------------------------------------------------
- -Creates a text-call function
- ----------------------------------------------------------------------------------------
- t = appuifw.text()
- ----------------------------------------------------------------------------------------
- -Setting up the text function as the application body
- ----------------------------------------------------------------------------------------
- appuifw.app.body = t
- ----------------------------------------------------------------------------------------
- -Adjust the display application using the screen function, there are 3 types of large, normal, full
- ----------------------------------------------------------------------------------------
- appuifw.app.screen = "normal"
- ----------------------------------------------------------------------------------------
- -Set the text color
- ----------------------------------------------------------------------------------------
- t.color = 0xEE00DD
- ----------------------------------------------------------------------------------------
- -Set the highlight color
- ----------------------------------------------------------------------------------------
- t.highlight_color = 0xFFFF00
- ----------------------------------------------------------------------------------------
- -Set the font ie font name, size (size), flag (sorry this is not know its function)
- ----------------------------------------------------------------------------------------
- t.font = (u "Nokia Hindi S60", 25, None)
- ----------------------------------------------------------------------------------------
- -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
- ----------------------------------------------------------------------------------------
- t.style = (appuifw.STYLE_HIGHLIGHT_STANDARD | appuifw.STYLE_BOLD | appuifw.STYLE_STRIKETHROUGH)
- ----------------------------------------------------------------------------------------
- -Writing the desired text
- ----------------------------------------------------------------------------------------
- t.set (u "Haaloo Broww ..")
- ----------------------------------------------------------------------------------------
- -Create an active object
- ----------------------------------------------------------------------------------------
- app_lock = e32.Ao_lock()
- ----------------------------------------------------------------------------------------
- -Creating a function to exit the application
- -----------------------------------------------------------------------------------------
- def quit():
- app_lock.signal()
- appuifw.app. set.exit()
- ----------------------------------------------------------------------------------------
- -Creating the exit button on the softkey
- ----------------------------------------------------------------------------------------
- appuifw.app.exit_key_handler = quit
- ----------------------------------------------------------------------------------------
- -Wait for the command from the softkey to exit
- -----------------------------------------------------------------------------------------
- app_lock.wait()
- -----------------------------------------------------------------------------------------
- ==========
- 022.
- "FUNCTION OF FORUM"
- I want to share about the iteration function for on pys60 script...
- Looping or looping is a process done repeatedly, which I know looping in pys60 there are 2 for and while. But this time I will decipher for for only.
- For
- just take the example to be easy to understand.
- Example 1:
- ----------------------------------------------------------------------------------------
- for i in range (10):
- print i
- ----------------------------------------------------------------------------------------
- Then the result will print 10 numbers from 0- 9 instead of 1-10, since the integer value starts from the number 0.
- Example 2:
- -----------------------------------------------------------------------------------------
- x = 4
- for t in range (x):
- test print [t]
- -----------------------------------------------------------------------------------------
- result of
- test
- test
- test
- test
- Will print test as much as x that is 4.
- Example 3:
- ----------------------------------------------------------------------------------------
- txt = unicode ('test')
- for z in range (len (txt)):
- print txt [z]
- ----------------------------------------------------------------------------------------- the
- result
- t
- e
- s
- The len function here is to know the amount of data from txt.
- Example:
- ----------------------------------------------------------------------------------------
- txt = unicode ('test')
- len (txt )
- ---------------------------------------------------------------------------------------- The
- result
- 3
- ==========
- 023.
- "IF CONDITION"
- I want to share funsi if in script pys60...
- The if command is used to create a condition in pys60.
- if illustrated would be like this example...
- If eating then it will be full, if drink will be bloated, otherwise all will die
- If word is replaced if if code in pys60 it will be like this:
- -----------------------------------------------------------------------------------------
- txt = unicode ('test')
- if eating:
- full of
- drinking elves:
- > > kembung
- else:
- moddar
- ----------------------------------------------------------------------------------------
- (symbol is the number of spaces)
- Now we try to apply in the script
- Example:
- ----------------------------------------------------------------------------------------
- txt = unicode (' test ')
- value = 70
- if value> 80:
- print' smart '
- if value> 60:
- print' pretty '
- else:
- print' must learn a lot '
- ----------------------------------------------------------------------------------------- The
- space below if, elif, and else is a block.meaning the command is included in the block of the command above it.
- ==========
- 024.
- "MENU, SUBMENU and POPUP MENU"
- I want to share a way to make memu , submenu or popup menu for an application...
- Creating Application Menu
- -Module used is appuifw, and e32
- -----------------------------------------------------------------------------------------
- import appuifw, e32
- -----------------------------------------------------------------------------------------
- -Define: create its own function for application menu.
- ----------------------------------------------------------------------------------------
- def item1():
- appuifw.note (u "learn python", "info")
- def item2():
- appuifw.note (u "basic lesson", "info")
- -----------------------------------------------------------------------------------------
- -Make a function to exit when pressing the right softkey button.
- ----------------------------------------------------------------------------------------
- def quit():
- app_lock.signal() )
- ----------------------------------------------------------------------------------------
- Information:
- Spacebar to create a function in 1 block.
- -Creates a menu of selectable apps (menu1, menu2)
- -Do call the created function (item1, item2)
- -----------------------------------------------------------------------------------------
- appuifw.app.menu = [(u "one", item1), (u "two", item2)]
- -----------------------------------------------------------------------------------------
- -Creating exit button
- -----------------------------------------------------------------------------------------
- appuifw.app.exit_key_handler = quit
- -----------------------------------------------------------------------------------------
- -Create an active object
- ----------------------------------------------------------------------------------------
- app-lock = e32.Ao_loch()
- -----------------------------------------------------------------------------------------
- -Get started time
- -----------------------------------------------------------------------------------------
- app_lock.wait()
- -----------------------------------------------------------------------------------------
- Detailed to be:
- -----------------------------------------------------------------------------------------
- import appuifw, e32
- def item1():
- appuifw.note (u "learn python", "info")
- def item2():
- appuifw.note (u "basic lesson" ,"info")
- def quit():
- app_lock.signal()
- appuifw.app.menu = [(u "menu1", item1), (u "menu2", item2)]
- appuifw.app.exit_key_handler = quit
- app-lock = e32.Ao_lock()
- app_lock.wait()
- ----------------------------------------------------------------------------------------
- Creating SubMenu
- - The same way to create an app menu just adds menus in a menu like this (menu1, (submenu1, submenu2), men2, (submenu1, submenu2))
- Example code:
- -----------------------------------------------------------------------------------------
- appuifw.app.menu = [(u "menu1", ((u "submenu1", item1), (u, "submenu2" , item2)), (u "menu2", ((u "submenu1",item1), (u "submenu2", item2))))]
- ----------------------------------------------------------------------------------------
- Create a pop-up menu
- -Module used appuifw
- -----------------------------------------------------------------------------------------
- import appuifw
- -----------------------------------------------------------------------------------------
- -Creating a list with contents from Pop-up
- -----------------------------------------------------------------------------------------
- L = [u "Python", u "Symbian", u "java"]
- -----------------------------------------------------------------------------------------
- -Create a pop-up menu including lists and labels
- ----------------------------------------------------------------------------------------
- appuifw.popup_menu (list, label)
- test = appuifw.popup_menu (L, u "Options:")
- ----------------------------------------------------------------------------------------
- -Make a test variable to enter a command into the List (based on the order of positions in the List) -It has been
- selected
- -Efforts some actions (here we print something())
- -----------------------------------------------------------------------------------------
- if test == 0:
- appuifw.note (u "Python, yes", "info")
- elif test == 1:
- appuifw.note (u "Symbian, ok", "info")
- elif test == 2:
- appuifw.note(u"belajar java", "info")
- ---------------------------------------------------------------------------------------
- Information:
- The number 0 shows the first sequence in the Python List, then the number 1 denotes the second sequence of Symbian, and so on.
- full examples of the code to be
- ----------------------------------------------------------------------------------------
- import appuifw
- L = [u "Python" , u "Symbian", u "java"]
- test = appuifw.popup_menu (L, u "Options")
- if test == 0:
- appuifw.note (u "Python yes", "info")
- elif test == 1:
- appuifw.note (u "symbian, ok", "info")
- elif test == 2:
- appuifw.note (u "learn java", "info")
- ----------------------------------------------------------------------------------------
- ==========
- 025.
- "ME-MINIMIZEKAN A PROGRAM USING SCRIPT PYS60"
- I want to share a script to minimize the program we are currently open...
- ----------------------------------------------------------------------------------------
- import appswitch
- appswitch .switch_to_bg (appswitch.application_list (1) [0])
- ----------------------------------------------------------------------------------------
- ==========
- 026.
- "MAKE PASSWORD SCRIPT PYS60"
- I want to share a script to create a password on app...
- ----------------------------------------------------------------------------------------
- import appuifw
- import os
- def open():
- appuifw.note (u'Success... ',' conf ')
- def start():
- N = appuifw.query (u "Free Name:", "text")
- K = "fnugraha8"
- uN = N
- if N == uN:
- uK = str (appuifw.query (u "Password: "," code "))
- if K == uK:
- open()
- else:
- appuifw.note (u "Wrong Password!", "error")
- os.abort()
- else:
- start pass()
- ----------------------------------------------------------------------------------------
- ==========
- 027.
- "SCRIPT PY TO SHOW BATTERY WATER"
- I want to share a script to show low battery status or weak...
- We write first scrit it using the application ped or x-plore.
- 1. Open the ped application and press the File> New> Python option, then a blank or blank HP screen will appear.
- 2. Then write his py script as needed and according to the procedure. Like this:
- ----------------------------------------------------------------------------------------
- import globalui
- import e32
- import appuifw
- x = appuifw.query (u'Enter Time (in seconds): ',' number ')
- e32.ao_sleep (x)
- globalui.global_note (u' ',' battery_low ')
- -----------------------------------------------------------------------------------------
- 3. If everything is written then you just press the selection button then select 'Run', finish.
- Here's an example of the complete script:
- ----------------------------------------------------------------------------------------
- import globalui import e32 import appuifw x = appuifw.query (u'Enter Time (in seconds): ',' number ') e32.ao_sleep (x) globalui.global_note (u' ',' battery_low ')
- -----------------------------------------------------------------------------------------
- ==========
- 028.
- "SCRIPT SIMPLE MAKES POPUP MENU"
- I want to share a simple script to create popup memu...
- ----------------------------------------------------------------------------------------
- import appuifw
- import os
- def poultry() : appuifw.note (u'ayam, bird, etc ',' info ')
- def song(): appuifw.note (u'valley of the damned, fury of the storm', 'info')
- def kel(): os .abort()
- a = [u'Unggas ', u'Lagu', u'Sign out ']
- g = appuifw.popup_menu (a, u'Menuen')
- if g == 0:poultry()
- if g == 1: song()
- if g == 2: kel()
- ---------------------------------------------------------------------------------------
- ==========
- 029.
- "READING FILE WITH MODULE POWLITE FM"
- I want to share a script to read mp3 file...
- -Module required
- ----------------------------------------------------------------------------------------
- import powlite_fm as fm
- import audio as a
- ----------------------------------------------------------------------------------------
- -The command opens the file manager
- -----------------------------------------------------------------------------------------
- n = fm.manager()
- ----------------------------------------------------------------------------------------
- - The command to read my file gives an example of reading na mp3 files with audio module, can also file jpg, png, gif, etc.
- ----------------------------------------------------------------------------------------
- f = n.AskUser (ext = ['.mp3' ])
- ----------------------------------------------------------------------------------------
- - The command opens the file and plays it and the volume level is 5
- Ket : a.Sound.open is the command to open the sound file, (f) is a function to read the file manager on hp
- -----------------------------------------------------------------------------------------
- s = a.Sound.open (f)
- s.play()
- s.set_volume(5)
- ---------------------------------------------------------------------------------------
- ==========
- 030.
- "CHANGING SIZE OF IMAGES USING SCRIPT"
- I want to share a script to resize image...
- ----------------------------------------------------------------------------------------
- import appuifw
- import e32
- from graphics import *
- images = Image.open ("e:\\test.jpg")
- image = image.resize ((176, 208))
- gambar.save ("e:\\save.jpg" )
- def handel (rect):
- > > x.blit (image)
- x = appuifw.Canvas (redraw_callback = handel)
- appuifw.app.body = x
- y = e32.Ao_lock()
- y.wait()
- ---------------------------------------------------------------------------------------
- ==========
- 031.
- "USE OF SCRIPT PASSWORD ON AN APPLICATION"
- I want to share how to create a password on an app...
- -Module required
- ----------------------------------------------------------------------------------------
- import appuifw
- import e32
- import os
- ----------------------------------------------------------------------------------------
- -Function define calling and filling name and password
- -----------------------------------------------------------------------------------------
- def begin():
- ----------------------------------------------------------------------------------------
- -The query function for calling or displaying text boxes or also a charging box name
- ----------------------------------------------------------------------------------------
- N = appuifw.query (u " Free Name: "," text ")
- ----------------------------------------------------------------------------------------
- -The Equation K as my password uses fnugraha8 as its password and free name filling
- -----------------------------------------------------------------------------------------
- > > K = "fnugraha8"
- ----------------------------------------------------------------------------------------
- -Name N if N equals N which means name
- ----------------------------------------------------------------------------------------
- uN = N
- if N == uN:
- ----------------------------------------------------------------------------------------
- -K equations as strings with query function of password filling
- ----------------------------------------------------------------------------------------
- uK = str (appuifw.query (u "Password (fnugraha8)", "code" ))
- if K == uK:
- ----------------------------------------------------------------------------------------
- -The menu calling function after entering the name and password if the password correct
- ----------------------------------------------------------------------------------------
- open()
- ----------------------------------------------------------------------------------------
- -Another meaningful function other than that which serves to differentiate if the wrong password
- -----------------------------------------------------------------------------------------
- else:
- appuifw.note (u "Wrong Password!", "error")
- ----------------------------------------------------------------------------------------
- -A abort function where the wrong password will automatically exit from application by itself
- ----------------------------------------------------------------------------------------
- os.abort()
- else:
- pass
- -----------------------------------------------------------------------------------------
- -Function define a as text to be displayed
- -----------------------------------------------------------------------------------------
- def a():
- aa = u'script experiment using password '
- -----------------------------------------------------------------------------------------
- -The print rule to print text on the above function
- -----------------------------------------------------------------------------------------
- print aa
- ----------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------
- def b():
- bb = u ' experiment script using password '
- print bb
- ----------------------------------------------------------------------------------------
- -Function to exit the app
- ----------------------------------------------------------------------------------------
- def ex():
- os.abort()
- ----------------------------------------------------------------------------------------
- -Function to run the opening of the application first run
- ----------------------------------------------------------------------------------------
- def open():
- appuifw.app.screen = 'large'
- x = appuifw.Text()
- appuifw.app.body = x
- x.style = appuifw.STYLE_BOLD
- y = u'aku love you all my heart '
- x.color = 0xccaadd
- for abc in range (len (y)):
- x.add (y [abc] )
- e32.ao_sleep (0.01)
- ----------------------------------------------------------------------------------------
- -Menu application on define function
- ----------------------------------------------------------------------------------------
- def menu():
- appuifw.app.menu = [(u'test ', a), (u'testing',b)]
- ----------------------------------------------------------------------------------------
- -Function calling password
- ----------------------------------------------------------------------------------------
- start()
- -----------------------------------------------------------------------------------------
- -Function calling menu
- -----------------------------------------------------------------------------------------
- menu()
- -----------------------------------------------------------------------------------------
- -Function command exits
- ----------------------------------------------------------------------------------------
- appuifw .app.exit_key_handler = ex
- ----------------------------------------------------------------------------------------
- -Alocking app
- ----------------------------------------------------------------------------------------
- z = e32.Ao_lock()
- z.wait()
- -----------------------------------------------------------------------------------------
- Note:
- Is the number of spaces used.
- ==========
- 032.
- "SCRIPT PY TO DISPLAY FILE"
- I want to share a script to back up file...
- ----------------------------------------------------------------------------------------
- import appuifw
- import e32
- import os
- import powlite_fm as p
- def double():
- appuifw.query (unicode ('Find File Save 420kb or 495kb'), 'query')
- z = p.manager()
- f = z.AskUser (ext = ['svs','. sav '])
- if f:
- appuifw.note (unicode ('Processing !!! '),' info ')
- os.path.isdir (' E:\\Backup ')
- os.makedirs ('E:\\Backup')
- folder = f
- target = 'E:\\Backup'
- e32.file_copy (target, folder)
- appuifw.note (unicode ('Successfully Doubleing FILE...'), 'conf')
- double()
- -----------------------------------------------------------------------------------------
- ==========
- 033.
- "MULTI SELECTION LIST"
- I want to share scrip to display search file or check box...
- 1. Open the ped application and press the option and choose file> new> python, it will pop up the new blank screen you wrote the script, and write the script as below.
- ----------------------------------------------------------------------------------------
- import appuifw
- Girl = [u'Gina ', u'Nina ', u'Dina', u'Lena ', u'Rena', u'Raisya ', u'Risa', u'Siska ']
- tm = appuifw.multi_selection_list (Girls, style =' checkbox 'search_field = 1)
- for i in tm:
- print Girl [i]
- ----------------------------------------------------------------------------------------
- Note:
- Replace mark> with a space.
- ==========
- 034.
- "AUDIO (PLAYING MP3 1 FOLDER)"
- I want to share a script untuj play mp3 in 1 piece folder...
- ----------------------------------------------------------------------------------------
- Import Appuifw
- import audio
- import e32
- import os
- dir = 'E:\\Music'
- for the song in os.listdir (dir):
- s = audio.Sound.open (os.
- path.join (dir, track))
- s.play()
- s.set_volume (5)
- print 'Now playing:', song, ms2str (s.duration())
- while 1:
- if s.state() == 1:
- s.close()
- break
- e32.ao_sleep (0.5)
- -UntUk menStop lagu tUlis script like this.
- s.stop()
- s.close()
- ----------------------------------------------------------------------------------------
- Note:
- Alerts> replace with a space.
- ==========
- 035.
- "FILLING LESS NAME OF AND MORE THAN 5 CHARACTERS"
- I want to share the way make popup menu filling name less than 5 letters or more than 5 letters...
- -----------------------------------------------------------------------------------------
- import appuifw as z
- x = z.query (u'Name ',' text ')
- if x:
- if len (x)> 5:
- z.note (u'Max 5 ',' error ')
- else:
- z.note (x,' conf ')
- y = z.query (u'Nama', 'text')
- if y:
- >>if len (y) <5:
- z.note (u'Max 5 ',' error ')
- else:
- z.note (y, 'conf')
- -----------------------------------------------------------------------------------------
- Note:
- Replace mark> with a space.
- ==========
- 036.
- "MULTI_QUERY"
- I want to share a script for print or print more than 1 text...
- ----------------------------------------------------------------------------------------
- import appuifw as R
- x, y = R .multi_query (u'Name: ', u'Umur:')
- print x
- print y
- -----------------------------------------------------------------------------------------
- ==========
- 037.
- "SIMPLE FORM"
- I want to share about the form function in a pys60 script. ..
- ----------------------------------------------------------------------------------------
- import appuifw
- x = appuifw.FFormDoubleSpaced | appuifw.FFormEditModeOnly
- y = [u'Kuda ', u'Monkey', u'Angjing ', u'Babi', u'Ayam ']
- x1 = [(u'Name Animals', 'combo', (y, 0) )]
- y1 = appuifw.Form (x1, x)
- y1.execute()
- z = y1 [0] [2] [1]
- appuifw.query ('' Print Result ',' text ', u' '+ y [z])
- ----------------------------------------------------------------------------------------
- ==========
- 038.
- "MAKE PROGRESSBAR"
- I want to share a script to create a progress bar...
- ----------------------------------------------------------------------------------------
- import prog, e32, appuifw
- wt = prog.ProgressNote()
- wt.wait()
- wt.update (0, u'Loading... ')
- e32.ao_sleep (5)
- wt.finish()
- appuifw.note (u'Success...', 'conf')
- -----------------------------------------------------------------------------------------
- ==========
- 039.
- " DISPLAYING APPLICATIONS THAT HAVE BEEN INSTALLED IN THE FORM OF LIST"
- I want shares script pys60 whose function is to display installed applications on each drive, I inserted the C, E and Z drives. So displaying the installed app on 3 drives, it's an easy way to enter the app without having to click menu, open folder, etc ..
- Just go the script below,
- ----------------------------------------------------------------------------------------
- import apps import appuifw import laa def app_list(): drive = ['E:', 'C:', 'Z:'] apps = [] uids = [] for data in applist.applist(): uid, name, dir = data if dir [: 2] in drive: apps.append ((name)) uids.append (uid) i = appuifw.popup_menu (apps, unicode (len (apps)) + 'Installed Apps') if not i == None: laa.execute (uids) app_list()
- ----------------------------------------------------------------------------------------
- This is the complete script,
- ----------------------------------------------------------------------------------------
- import appist
- import appuifw
- import laa
- def app_list ( ):
- drive = ['E:', 'C:', 'Z:']
- apps = []
- uids = []
- for data in applist.applist():
- > uid, name, dir = data
- > dir [: 2] in drive:
- apps.append ((name))
- uids.append (uid)
- i = appu, unicode (len (apps)) + 'Installed Apps')
- if not i == None:
- > laa.execute (uids)
- app_list()
- -----------------------------------------------------------------------------------------
- ==========
- 040.
- "CALLING IMAGES WITH MODULE FROM GRAPHICS IMPORT *"
- I want to share how to enter or calling an image into an application via the command from graphics import...
- -Module required
- -----------------------------------------------------------------------------------------
- import appuifw
- import e32
- from graphics import *
- ----------------------------------------------------------------------------------------
- -To change the screen size available normal, large and full
- ----------------------------------------------------------------------------------------
- appuifw.app.screen = 'full'
- -----------------------------------------------------------------------------------------
- -To call and open the image with the location and size of the image must be clear
- -----------------------------------------------------------------------------------------
- Image = Image.open ("e:\\test.jpg" )
- ----------------------------------------------------------------------------------------
- -Set the drawing called to be displayed
- -----------------------------------------------------------------------------------------
- def handle_redraw (rect):
- x.blit (Figure) # use 4 spaces
- ----------------------------------------------------------------------------------------
- -Canvas and body assignments to display
- -----------------------------------------------------------------------------------------
- x = appuifw.Canvas (redraw_callback = handle_redraw)
- appuifw.app.body = x
- ----------------------------------------------------------------------------------------
- -Clock usage
- -----------------------------------------------------------------------------------------
- y = e32.Ao_lock()
- y.wait()
- -----------------------------------------------------------------------------------------
- ==========
- 041.
- "SCRIPT CUTTING FILE TXT"
- I want to share how to call or insert a file. txt into an app...
- -Module required
- ----------------------------------------------------------------------------------------
- Import Appuifw
- import e32
- ----------------------------------------------------------------------------------------
- -Text of the txt file you want to call
- -----------------------------------------------------------------------------------------
- Text = 'e:\\test.txt'
- ----------------------------------------------------------------------------------------
- -Members calling on module
- -----------------------------------------------------------------------------------------
- x = appuifw.Content_handler()
- -----------------------------------------------------------------------------------------
- -Explore x on the module to open the txt file
- -----------------------------------------------------------------------------------------
- x.open (text)
- -----------------------------------------------------------------------------------------
- -Mode sleep
- ----------------------------------------------------------------------------------------
- e32.ao_sleep (10)
- ---------------------------------------------------------------------------------------
- ==========
- 042.
- "SCRIPT TEXT BECOME VOICE"
- I want to share a script that can change the text into sound...
- -Module required
- ----------------------------------------------------------------------------------------
- import appuifw
- import audio
- -----------------------------------------------------------------------------------------
- -The query function for writing text on a popup screen
- -----------------------------------------------------------------------------------------
- text = appuifw.query (u'Enter the text: ',' text')
- ----------------------------------------------------------------------------------------
- -The order to call a voice or read a text
- -----------------------------------------------------------------------------------------
- audio.say (text)
- -----------------------------------------------------------------------------------------
- -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.
- Continue to write the above command, save when finished, keep moving to python folder ..
- How to run the script open Application Ped continue to search python\test.py folder and press ok, it will pop up scren and enter the text press ok again and listen to the result.
- Note:
- -Text not abbreviated.
- -Not all HP suport with this script.
- ==========
- 043.
- "SCRIPT UNTUK MEMANGGIL dan MEMBUKA APLIKASI di LUAR SYSTEM APLIKASI"
- Saya mau share sebuah script yang fungsinya untuk memanggil aplikasi diluar system aplikasi...
- -Module yang dibutuhkan
- ---------------------------------------------------------------------------------------
- import appuifw
- import e32
- ---------------------------------------------------------------------------------------
- -Fungsi define pemanggilan aplikasi
- ---------------------------------------------------------------------------------------
- def test():
- e32.start_exe ('z:\\system\\programs\\apprun.exe', 'e:\\COBA\\vbag\\vbag.app')
- -----------------------------------------------------------------------------------------
- -Feature menu
- -----------------------------------------------------------------------------------------
- appuifw.app.menu = [(u "Test", test)]
- -----------------------------------------------------------------------------------------
- -To lock when the app is opened so it does not happen out by itself.
- ----------------------------------------------------------------------------------------
- lock = e32.Ao_lock()
- lock.wait()
- ----------------------------------------------------------------------------------------
- Information:
- Tanda ini dimaksudkan supaya menggunakan 4 spasi.
- e32.start_exe('z:\\system\\programs\\apprun.exe' ini adalah perintah pemanggila sekaligus untuk melakukan runing pada suatu aplikasi yang mau dijalankan..
- 'e:\\COBA\\vbag\\vbag.app' ini adalah perintah untuk memanggil aplikasi yang akan dijalankan dimana folder aplikasi tersebut disimpan...
- Untuk pemanggilan aplikasi bisa ditambah sebanyak yang kalian mau.
- Ingat pindahkan folder aplikasi ke folder yang sudah disiapkan sebelumnya.
- ==========
- 044.
- "SCRIPT UNTUK MEMAINKAN MP3 PADA FUNGSI DEFINE"
- Saya mau share script python yang berfungsi untuk memutar mp3...
- -Module yang diperlukan
- ---------------------------------------------------------------------------------------
- import appuifw
- import e32
- import audio
- ---------------------------------------------------------------------------------------
- -Fungsi define untuk menjalankan sebuah mp3
- ---------------------------------------------------------------------------------------
- def main():
- global pokemon
- pokemon = audio.Sound.open ('e:\\MP3\\English\\Pokemon.mp3')
- pokemon.play()
- appuifw.note (u "Playing", "info")
- ----------------------------------------------------------------------------------------
- -Function define to stop a mp3 that is being played
- ----------------------------------------------------------------------------------------
- def stop():
- global pokemon
- pokemon.stop()
- pokemon.close()
- appuifw.note (u "In Stop", "conf")
- ----------------------------------------------------------------------------------------
- -The menu list to display in an application
- ---------------------------------------------------------------------------------------
- appuifw.app.menu = [(u"Putar", main), (u"Berhenti", henti)]
- ---------------------------------------------------------------------------------------
- -Fungsi untuk modus stanby atau mengunci saat pada aplikasi dibuka
- ---------------------------------------------------------------------------------------
- script_lock = e32.Ao_lock()
- script_lock.wait()
- ---------------------------------------------------------------------------------------
- Ingat tanda menunjukan 4 spasi.
- ==========
- 045.
- "MEMANGGIL TEXT MENGGUNAKAN MODULE GLOBALUI PADA SCRIPT PYTHON"
- Saya mau share sebuah script untuk memanggil text atau menulis text dengan module globalui...
- -Module yang diperlukan
- ---------------------------------------------------------------------------------------
- import globalui
- ---------------------------------------------------------------------------------------
- -Pemanggilan scriptnya seperti ini.
- ---------------------------------------------------------------------------------------
- globalui.global_msg_query(u'test', u'coba' )
- ----------------------------------------------------------------------------------------
- Ket: u'test 'This is the content of the text and u' try 'This is a description of the text record. And if you want to use define afungtions use 4 spaces,
- Example:
- ----------------------------------------------------------------------------------------
- def about():
- globalui.global_msg_query (u'test ',' try ')
- -----------------------------------------------------------------------------------------
- ==========
- 046.
- "CARA MEMASUKKAN MUSIK atau MP3 ke DALAM SEBUAH APLIKASI PYTHON"
- Saya mau share cara membuat sebuah aplikasi ada musik ketika aplikasi tersebut dibuka...
- Pertama kalian harus tau disetiap aplikasi python terdapat file default.py didalam file trsebut ada tulisan import nama aplikasi ( tergantung aplikasi python apa yang kalian punya )
- Contoh:
- ---------------------------------------------------------------------------------------
- import linkapper
- ---------------------------------------------------------------------------------------
- Setelah ketemu file default.pynya kalian edit menggunakn x-plore atau yang lain, buka file default.pynya lalu ganti menjadi seperti dibawah ini:
- ---------------------------------------------------------------------------------------
- import e32,imp,appuifw,audio
- s = audio.Sound.open('e:\\system\\mp3\\dragonforce\\trail of broken heart.mp3' )
- s.play()
- def go():
- import linkapper
- e32.ao_sleep(0,go)
- del e32,go
- ---------------------------------------------------------------------------------------
- Note:
- Saya tegaskan kembali nama folder mp3nya harus jelas dan nama aplikasinya juga harus dicantumkan.
- ==========
- 047.
- "DASAR URUTAN KODE LOGIC GAME"
- Saya mau share tentang urutan kode logic game...
- Program game agar bisa jalan ada tahapan-tahapan tertentu. Berikut ini tahapan-tahapan dasar pada program gameplay:
- - update objek
- - gameplay logic
- - render
- - Update objek
- Objek pada game misalnya karakter. Saat karakter begerak atau berjalan, posisi karakter diupdate keposisi baru. Proses update disini bukan cuma update posisi objek tapi juga semua hal yang yang dibutuhkan tiap objek, misalnya: build objek, status, dll.
- - Gameplay logic
- Contoh logic gameplay misalnya: proses tumbukan, pengecekan gameover, penambahan skor, dll.
- - Render
- Render adalah proses menampilkan objek ke layar setelah diupdate
- Jika tahapan-tahapan diatas terbalik dapat menjadi bug.
- Contoh kasus:
- Pada deteksi tumbukan, saat karakter berjalan dan menabrak tembok karakter berhenti berjalan. Urutan tahapan yang baik seperti ini:
- - karakter berjalan
- - logic tumbukan dengan tembok
- - render karakter
- Jika urutannya terbalik misalnya seperti ini:
- - karakter berjalan
- - render karakter
- - logic tumbukan dengan tembok
- Maka yang terjadi karakter berjalan masuk beberapa piksel (tergantung kecepatan berjalan) kedalam tembok lalu kembali kedepan tembok. Tidak langsung berheti didepan tembok.
- Itulah contoh dasar urutan kode logic game.
- ==========
- 048.
- "MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.1)
- Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
- Saat ini tehnologi 3D merupakan sesuatu yang umum. Bahkan sudah banyak bahasa pemrograman yang dikhususkan untuk membuat software 3D misalnya Blitz 3D, Unity 3D dll sehingga membuat program 3D semakin mudah saja. Pada Pys60, ada sebuah graphics engine bernama OpenGL ES untuk mempermudah olah grafis baik 2D ataupun 3D. Library OpenGL ES hanya berjalan pada s60 3rd keatas. Namun bagaimanakah dasar-dasar komputasi 3D? Artikel ini berisi tehnik atau cara kerja dasar-dasar komputasi 3D menggunakan bahasa pemrograman Python khususnya Pys60. Mencakup pengetahuan dasar kordinat 3D, rotasi, dan transformasi. Dimulai dari kordinat 2D.
- Note:
- Ganti semua tanda">"pada awal baris disetiap script ditutorial ini dengan spasi.
- -Kordinat 2D
- Setiap titik 2D terdiri dari dua kordinat. Dalam kartesian disebut X dan Y.
- X merupakan kordinat horizontal dari kiri kekanan sedangkan Y merupakan kordinat vertikal dari atas kebawah. Jadi jika X bernilai nol dan Y bernilai nol maka titik tersebut adalah pojok kiri atas layar.
- Sebuah objek 3D yang dapat dirotasi mempunyai titik pusat rotasi. Untuk itu komputasi vektor digunakan untuk menentukan kordinat suatu objek pada layar.
- Titik merah yang berada ditengah-tengah kotak tersebut merupakan titik pusat rotasi. Titik merah tersebut yang menentukan Posisi objek. Setiap titik biru (titik sudut, dalam 3D disebut Vertex) posisinya dipengaruhi oleh titik merah dengan kata lain translasi. Rumus translasi nya:
- x = VertexX+PosX
- y = VertexY+PosY
- Script implementasi vektor
- ---------------------------------------------------------------------------------------
- import math,e32,key,appuifw, graphics
- def quit():
- global run
- run=0
- appuifw.app.screen ='full'
- run = 1
- appuifw.app.body = c = appuifw.Canvas()
- appuifw.app.exit_key_handler=quit
- img = graphics.Image.new(c.size)
- PX = c.size[0]/2
- PY = c.size[1]/2
- Size = 6
- VX = [-40, 40, -40, 40]
- VY = [-40, -40, 40, 40]
- while run:
- img.clear(0)
- for n in range(4):
- # translasi kordinat vertex
- x = VX[n]+PX
- y = VY[n]+PY
- ---------------------------------------------------------------------------------------
- -Menggambar vertex
- ---------------------------------------------------------------------------------------
- img.point((x,y),0x0000ff,width=Size)
- ---------------------------------------------------------------------------------------
- -Menggambar posisi
- ---------------------------------------------------------------------------------------
- img.point((PX,PY),0xff0000,width=4)
- c.blit(img)
- e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Pada script diatas hanya ada titik-titik saja, garis sengaja tidak digambar untuk menyederhanakan script. Objek kotak pada gambar diatas mempunyai lebar 80px dan tinggi 80px. Oleh karena itu setiap vertex (VX dan VY) nilainya setengah dari lebar kotak yaitu -40 atau 40.
- Rotasi 2D
- Sampai saat ini, alogaritma trigonometri sinus dan cosinus merupakan algoritma rotasi yang paling banyak dipakai untuk me-rotasi objek pada layar digital. Tidak memahami rumus sinus dan cosinus bukan suatu masalah karena hampir semua bahasa pemrograman termasuk python sudah menyediakan fungsi sin dan cos pada modul atau library standar-nya. Namun akan lebih baik jika mememahami cara kerja rotasi menggunakan sin dan cos.
- Rotasi kekanan 20 derajat. Untuk menghitung nilai rotasi kordinat VX dan VY (garis berwarna cyan) dipakai rumus:
- XR = VX[n]*cos(ra) - VY[n]*sin(ra)
- YR = VX[n]*sin(ra) + VY[n]*cos(ra)
- '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.
- implementasi rotasi 2D
- ---------------------------------------------------------------------------------------
- import math,e32,key,appuifw, graphics
- def quit():
- global run
- run=0
- appuifw.app.screen ='full'
- run = 1
- appuifw.app.body = c = appuifw.Canvas()
- appuifw.app.exit_key_handler=quit
- img = graphics.Image.new(c.size)
- PX = c.size[0]/2
- PY = c.size[1]/2
- Size = 6
- VX = [-40, 40, -40, 40]
- VY = [-40, -40, 40, 40]
- ANGLEZ = 0
- while run:
- ---------------------------------------------------------------------------------------
- -Konversi angle ke radian
- ---------------------------------------------------------------------------------------
- raz = ANGLEZ*math.pi/180
- ---------------------------------------------------------------------------------------
- -Menghitung sin dan cos
- ---------------------------------------------------------------------------------------
- sinz = math.sin(raz)
- cosz = math.cos(raz)
- img.clear(0)
- for n in range(4):
- ---------------------------------------------------------------------------------------
- -Rotasi kordinat vertex
- ---------------------------------------------------------------------------------------
- XR = VX[n]*cosz - VY[n]*sinz - VX[n]
- YR = VX[n]*sinz + VY[n]*cosz - VY[n]
- ---------------------------------------------------------------------------------------
- -Translasi kordinat vertex
- ---------------------------------------------------------------------------------------
- x = VX[n]+PX+XR
- y = VX[n]+PY+YR
- img.point((x,y),0x0000ff,width=Size)
- img.point((PX,PY),0xff0000,width=Size)
- ---------------------------------------------------------------------------------------
- -Memutar objek sekedar untuk simulasi
- ---------------------------------------------------------------------------------------
- ANGLEZ+=2
- c.blit(img)
- e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Pada baris kode:
- XR = VX[n]*cosz - VY[n]*sinz - VX[n]
- Ada tambahan"- VX[n]"agar hasil komputasinya hanya offset saja. Ditujukan untuk mengurangi perubahan syntax pada proses transformasi kordinat nanti. Setelah dihitung, nilai offset rotasi XR ditambahkan ke translasi:
- x = VX[n]+PX+XR
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 049.
- "MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.2)
- Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
- Kordinat 3D
- 3D merupakan pengembangan dari 2D. Jadi dasarnya sama dengan 2D. Pada 3D ada satu kordinat lagi yang disebut Z untuk menentukan kedalaman. Semakin besar nilai Z semakin jauh atau kecil gambar suatu objek pada layar.
- Semua titik kordinat (Posisi dan Vertex) membutuhkan kordinat Z. Jadi setiap titik mempunyai tiga kordinat yaitu X,Y dan Z. Karena sudah memasuki 3D gambar kotak sebelumnya dikembangkan menjadi kubus. Sebuah kubus mempunyai 8 titik sudut, jadi ada tambahan 4 vertex baru kedalam list VX dan VY juga menambahkan satu list baru bernama VZ. Variabel PZ saat ini belum digunakan, diberi nilai 200 sebagai default agar objek berada agak jauh dari kamera setelah ditransformasikan nanti.
- Implementasi kordinat 3D
- ---------------------------------------------------------------------------------------
- import math,e32,key,appuifw, graphics
- def quit():
- global run
- run=0
- appuifw.app.screen = 'full'
- run = 1
- appuifw.app.body = c = appuifw.Canvas()
- appuifw.app.exit_key_handler=quit
- img = graphics.Image.new(c.size)
- PX = c.size[0]/2
- PY = c.size[1]/2
- Size = 6
- VX = [-40, 40, -40, 40, -40, 40, -40, 40]
- VY = [-40, -40, 40, 40, -40, -40, 40, 40]
- VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
- ANGLEZ = 0
- while run:
- ---------------------------------------------------------------------------------------
- -Konversi angle ke radian
- ---------------------------------------------------------------------------------------
- raz = ANGLEZ*math.pi/180
- ---------------------------------------------------------------------------------------
- -Menghitung sin dan cos
- ---------------------------------------------------------------------------------------
- sinz = math.sin(raz)
- cosz = math.cos(raz)
- img.clear(0)
- for n in range(8):
- ---------------------------------------------------------------------------------------
- -Rotasi kordinat vertex
- ---------------------------------------------------------------------------------------
- XR = VX[n]*cosz - VY[n]*sinz - VX[n]
- YR = VX[n]*sinz + VY[n]*cosz - VX[n]
- ---------------------------------------------------------------------------------------
- -Translasi kordinat vertex
- ---------------------------------------------------------------------------------------
- x = VX[n]+PX+XR
- y = VX[n]+PY+YR
- img.point((x,y),0x0000ff,width=Size)
- img.point((PX,PY),0xff0000,width=Size)
- ---------------------------------------------------------------------------------------
- -Memutar objek sekedar untuk simulasi
- ---------------------------------------------------------------------------------------
- ANGLEZ+=2
- c.blit(img)
- e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Jika script diatas dijalankan terlihat sama persis seperti script sebelumnya. Hanya 4 vertex yang terlihat karena 4 kordinat vertex lainnya mempunyai nilai VX dan VY sama dan hanya VZ yang berbeda. Yang terjadi pada script diatas adalah setiap titik terdiri dari 2 titik kordinat atau tumpang tindih. Dibutuhkan transformasi kordinat agar objek 3D diatas mempunyai kedalaman.
- Rotasi 3D
- Objek 2D hanya ada satu rotasi yaitu rotasi Z axis, sedangkan objek 3D dapat dirotasi dalam 3 poros atau axis yaitu rotasi X,Y, dan Z. Bisa juga dirotasi dalam satu atau dua axis saja, dapat juga tidak diberi rotasi sama sekali. Pada script ini menggunakan 3 rotasi.
- Untuk menggabungkan 3 komputasi rotasi sepintas terlihat sangat rumit, namun tidak serumit kelihatannya. Umumnya rotasi 3D menggunakan matrik karena efisiensi, namun disini tidak menggunakan matrik agar script-nya tidak terlalu rumit. Ada penambahan 2 variabel yaitu ANGLEX dan ANGLEY.
- Script implementasi rotasi 3D
- ---------------------------------------------------------------------------------------
- import math,e32,key,appuifw, graphics
- def quit():
- global run
- run=0
- appuifw.app.screen = 'full'
- run = 1
- appuifw.app.body = c = appuifw.Canvas()
- appuifw.app.exit_key_handler=quit
- img = graphics.Image.new(c.size)
- PX = c.size[0]/2
- PY = c.size[1]/2
- Size = 6
- VX = [-40, 40, -40, 40, -40, 40, -40, 40]
- VY = [-40, -40, 40, 40, -40, -40, 40, 40]
- VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
- ANGLEX = 0
- ANGLEY = 0
- ANGLEZ = 0
- while run:
- ---------------------------------------------------------------------------------------
- -Konversi angle ke radian
- ---------------------------------------------------------------------------------------
- rax = ANGLEX*math.pi/180
- ray = ANGLEY*math.pi/180
- raz = ANGLEZ*math.pi/180
- ---------------------------------------------------------------------------------------
- -Menghitung sin dan cos
- ---------------------------------------------------------------------------------------
- sinx = math.sin(rax)
- cosx = math.cos(rax)
- siny = math.sin(ray)
- cosy = math.cos(ray)
- sinz = math.sin(raz)
- cosz = math.cos(raz)
- img.clear(0)
- for n in range(8):
- ---------------------------------------------------------------------------------------
- -Rotasi kordinat vertex
- ---------------------------------------------------------------------------------------
- ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
- ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
- YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
- YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
- XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
- XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
- XR = YX+ZX
- YR = ZY+XY
- ZR = XZ+YZ
- ---------------------------------------------------------------------------------------
- -Ttranslasi kordinat vertex
- ---------------------------------------------------------------------------------------
- x = VX[n]+PX+XR
- y = VY[n]+PY+YR
- img.point((x,y),0x0000ff,width=Size)
- img.point((PX,PY),0xff0000,width=Size)
- ---------------------------------------------------------------------------------------
- -Memutar objek sekedar untuk simulasi
- ---------------------------------------------------------------------------------------
- ANGLEX+=2
- ANGLEY+=2
- ANGLEZ+=2
- c.blit(img)
- e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Pada script diatas, baris ZX dan ZY merupakan proses "rotasi Z" sama seperti pada rotasi 2D sebelumnya. Baris YX dan YZ merupakan "rotasi Y" yang prosesnya menggabungkan hasil "rotasi Z" sebelumnya (ZX). Dan pada baris XY dan XZ merupakan "rotasi X" yang prosesnya menggabungkan hasil "rotasi Z" dan "rotasi Y" (ZY dan YZ). Sederhananya kubus dirotasi pada Z axis, setelah itu dirotasi lagi pada Y axis, dan dirotasi lagi pada X axis. Pada tiga baris code:
- ---------------------------------------------------------------------------------------
- XR = YX+ZX
- YR = ZY+XY
- ZR = XZ+YZ
- ---------------------------------------------------------------------------------------
- Ketiga statement diatas hanya menjumlahkan semua "offset rotasi" sehingga dapat digunakan dalam konversi akhir.
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 050.
- "MENGIMPLEMENTASIKAN DASAR-DASAR KOMPUTASI 3D DENGAN PYS60" (bag.3)
- Saya mau share tentang cara mengimplementasikan suatu object 3D dengan pys60...
- Transformasi 3D
- Pada script dibagian sebelumnya saat kubus diputar ke-delapan vertex-nya kelihatan. Namun masih terlihat ada yang kurang yaitu perspektif. Proses transformasi digunakan untuk memberi atau mensimulasikan perspektif agar objek 3D terlihat nyata secara fisika.
- Proses mensimulasikan perspektif disebut transformasi. Rumus transformasinya:
- Z = (VZ+PZ)/distance
- X = (VX+PX)/Z
- Y = (VY+PY)/Z
- Pada kebanyakan konten 3D baik itu pada gambar, film, atau game, pusat perspektif sering kali berada ditengah-tengah layar. Untuk itu ada tambahan variabel halfResX dan halfResY untuk membuat posisi titik pusat perspektif berada ditengah-tengah layar.
- Implementasi perspektif 3D
- ---------------------------------------------------------------------------------------
- import math,e32,key,appuifw, graphics
- def quit():
- global run
- run=0
- appuifw.app.screen ='full'
- run = 1
- appuifw.app.body = c = appuifw.Canvas()
- appuifw.app.exit_key_handler=quit
- img = graphics.Image.new(c.size)
- halfResX = c.size[0]/2
- halfResY = c.size[1]/2
- ---------------------------------------------------------------------------------------
- -Jarak posisi kamera dari layar
- ---------------------------------------------------------------------------------------
- distance = 180
- PX = 0
- PY = 0
- PZ = 200
- Size = 6
- VX = [-40, 40, -40, 40, -40, 40, -40, 40]
- VY = [-40, -40, 40, 40, -40, -40, 40, 40]
- VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
- ANGLEX = 0
- ANGLEY = 0
- ANGLEZ = 0
- while run:
- ---------------------------------------------------------------------------------------
- -Konversi angle ke radian
- ---------------------------------------------------------------------------------------
- rax = ANGLEX*math.pi/180
- ray = ANGLEY*math.pi/180
- raz = ANGLEZ*math.pi/180
- ---------------------------------------------------------------------------------------
- -Menghitung sin dan cos
- ---------------------------------------------------------------------------------------
- sinx = math.sin(rax)
- cosx = math.cos(rax)
- siny = math.sin(ray)
- cosy = math.cos(ray)
- sinz = math.sin(raz)
- cosz = math.cos(raz)
- img.clear(0)
- for n in range(8):
- ---------------------------------------------------------------------------------------
- -Rotasi kordinat vertex
- ---------------------------------------------------------------------------------------
- ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
- ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
- YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
- YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
- XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
- XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
- XR = YX+ZX
- YR = ZY+XY
- ZR = XZ+YZ
- ---------------------------------------------------------------------------------------
- -Transformasi kordinat vertex
- ---------------------------------------------------------------------------------------
- z = (VZ[n]+PZ+ZR)/distance
- x = (VX[n]+PX+XR)/z
- y = (VY[n]+PY+YR)/z
- img.point((x+halfResX,y+halfResY),0x0000ff,width=Size/z)
- img.point((PX+halfResX,PY+halfResY),0xff0000,width=Size)
- ---------------------------------------------------------------------------------------
- -Memutar objek sekedar untuk simulasi
- ---------------------------------------------------------------------------------------
- ANGLEX+=2
- ANGLEY+=2
- ANGLEZ+=2
- c.blit(img)
- e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Karena titik pusat perspektif berada ditengah layar, maka jika PX bernilai nol posisi kubus berada ditengah layar, jika nilainya lebih kecil dari nol (minus) posisi kubus berada dikiri layar dan jika nilainya lebih besar dari nol posisi kubus berada dikanan layar. PY juga sama, tapi atas bawah. Sedangkan PZ bernilai nol atau lebih kecil dari nol maka posisinya tepat berada dikamera jadi tidak kelihatan dilayar karena terlalu besar. Semakin besar nilai PZ, semakin jauh posisi objek dari kamera dan terlihat semakin kecil.
- Itulah dasar pendekatan komputasi 3D. Script dibawah ini sama dengan script pada bagian"Transformasi 3D". Hanya ada tambahan key handler untuk menggerakan posisi objek (PX,PY, dan PZ) dan memutar objek dalam 3 axis (ANGLEX,ANGLEY, dan ANGLEZ)
- Fungsi key:
- Arah atas dan bawah: update PY
- Arah kiri dan kanan: update PX
- 1 dan 3: update PZ
- 2 dan 8: update ANGLEX
- 4 dan 6: update ANGLEY
- * dan #: update ANGLEZ
- ---------------------------------------------------------------------------------------
- import math,e32,key,appuifw, graphics
- from key_codes import *
- class Keyboard(object):
- def __init__(self,onevent=lambda:None):
- self._keyboard_state={}
- self._downs={}
- self._onevent=onevent
- def handle_event(self,event):
- if event['type'] == appuifw.EEventKeyDown:
- code=event['scancode']
- if not self.is_down(code):
- self._downs=self._downs.get(code,0)+1
- self._keyboard_state=1
- elif event['type'] == appuifw.EEventKeyUp:
- self._keyboard_state[event['scancode']]=0
- self._onevent()
- def is_down(self,scancode):
- return self._keyboard_state.get(scancode,0)
- def pressed(self,scancode):
- if self._downs.get(scancode,0):
- self._downs[scancode]-=1
- return True
- return False
- def quit():
- global run
- run=0
- key = Keyboard()
- appuifw.app.screen ='full'
- run = 1
- appuifw.app.body = c = appuifw.Canvas(event_callback = key.handle_event)
- appuifw.app.exit_key_handler=quit
- img = graphics.Image.new(c.size)
- halfResX = c.size[0]/2
- halfResY = c.size[1]/2
- ---------------------------------------------------------------------------------------
- -Jarak posisi kamera dari layar
- ---------------------------------------------------------------------------------------
- distance = 180
- PX = 0
- PY = 0
- PZ = 200
- Size = 6
- VX = [-40, 40, -40, 40, -40, 40, -40, 40]
- VY = [-40, -40, 40, 40, -40, -40, 40, 40]
- VZ = [-40, -40, -40, -40, 40, 40, 40, 40]
- ANGLEX = 0
- ANGLEY = 0
- ANGLEZ = 0
- while run:
- ---------------------------------------------------------------------------------------
- -Konversi angle ke radian
- ---------------------------------------------------------------------------------------
- rax = ANGLEX*math.pi/180
- ray = ANGLEY*math.pi/180
- raz = ANGLEZ*math.pi/180
- ---------------------------------------------------------------------------------------
- -Menghitung sin dan cos
- ---------------------------------------------------------------------------------------
- sinx = math.sin(rax)
- cosx = math.cos(rax)
- siny = math.sin(ray)
- cosy = math.cos(ray)
- sinz = math.sin(raz)
- cosz = math.cos(raz)
- img.clear(0)
- for n in range(8):
- ---------------------------------------------------------------------------------------
- -Rotasi kordinat vertex
- ---------------------------------------------------------------------------------------
- ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
- ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
- YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
- YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
- XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
- XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
- XR = YX+ZX
- YR = ZY+XY
- ZR = XZ+YZ
- ---------------------------------------------------------------------------------------
- -Transformasi kordinat vertex
- ---------------------------------------------------------------------------------------
- z = (VZ[n]+PZ+ZR)/distance
- ---------------------------------------------------------------------------------------
- -Mencegah ZeroDivisionError
- ---------------------------------------------------------------------------------------
- if z<0.01: z = 0.01
- x = (VX[n]+PX+XR)/z
- y = (VY[n]+PY+YR)/z
- img.point((x+halfResX,y+halfResY),0x0000ff,width=Size/z)
- img.point((PX+halfResX,PY+halfResY),0xff0000,width=Size)
- c.blit(img)
- if key.is_down(EScancodeLeftArrow): PX-=2
- if key.is_down(EScancodeRightArrow): PX+=2
- if key.is_down(EScancodeUpArrow): PY-=2
- if key.is_down(EScancodeDownArrow): PY+=2
- if key.is_down(EScancode1): PZ-=2
- if key.is_down(EScancode3): PZ+=2
- if key.is_down(EScancode4): ANGLEY-=2
- if key.is_down(EScancode6): ANGLEY+=2
- if key.is_down(EScancode2): ANGLEX-=2
- if key.is_down(EScancode8): ANGLEX+=2
- if key.is_down(EScancodeStar): ANGLEZ-=2
- if key.is_down(EScancodeHash): ANGLEZ+=2
- e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 051.
- "LIST, FUNGSI dan CLASS"
- Saya mau share bagaimana mengelompokan script dengan penggunaan multi dimensional list:
- ---------------------------------------------------------------------------------------
- nama_list=[[nilai,nilai],[nilai,nilai]]
- ---------------------------------------------------------------------------------------
- fungsi berargumen:
- ---------------------------------------------------------------------------------------
- def nama_fungsi(argumen):
- isi_fungsi
- ---------------------------------------------------------------------------------------
- dan class:
- ---------------------------------------------------------------------------------------
- class nama_class:
- isi_class
- ---------------------------------------------------------------------------------------
- Sekali lagi ini hanyalah contoh, bukan struktur script yang baik,
- Note:
- Ganti tanda ">" pada awal syntax dengan spasi. Sebagai contoh, data disimpan dalam multi dimensional list.
- ---------------------------------------------------------------------------------------
- type1 = ["Alas kaki", ["sepatu","sandal"]]
- type2 = ["Tutup kepala", ["topi","peci"]]
- ---------------------------------------------------------------------------------------
- Lalu misal kita ingin membuat fungsi untuk memproses nilai-nilai list diatas
- ---------------------------------------------------------------------------------------
- def cek_type1():
- print "kategori "+type1[0]+" berisi:"
- for i in range(len(type1[1])):
- print type1[1][i]
- def cek_type2():
- print "kategori "+type2[0]+" berisi:"
- for i in range(len(type2[1])):
- print type2[1][i]
- ---------------------------------------------------------------------------------------
- -Pemanggilan
- ---------------------------------------------------------------------------------------
- cek_type1()
- cek_type2()
- ---------------------------------------------------------------------------------------
- Jika list type banyak macamnya misalnya type1,type2,type3...type40, kita harus mencari cara yang lebih efisien. Salah satu solusinya yaitu membuat mesin untuk melakukan proses (dalam hal ini proses pengecekan). Untuk ini kita dapat menggunakan fungsi berargumen.
- ---------------------------------------------------------------------------------------
- def mesin_cek(type_barang):
- print "kategori "+type_barang[0]+" berisi:"
- for i in range(len(type_barang[1])):
- print type_barang[1][i]
- ---------------------------------------------------------------------------------------
- -Pemanggilan
- ---------------------------------------------------------------------------------------
- mesin_cek(type1)
- mesin_cek(type2)
- ---------------------------------------------------------------------------------------
- Fungsi mesin_cek diatas memproses data argumen yang dimasukkan. Dengan begini, kita cukup menggunakan satu fungsi diatas untuk mengecek semua data list type kita.
- Jika fungsi kita banyak akan lebih mudah diorganisir jika disimpan didalam class. Jika script diatas dikelompokkan dengan class:
- class pakaian:
- ---------------------------------------------------------------------------------------
- type1=["Alas kaki", ["sepatu","sandal"]]
- type2=["Tutup kepala", ["topi","peci"]]
- def mesin_cek(self,type_barang):
- print "kategori "+type_barang[0]+" berisi:"
- for i in range(len(type_barang[1])):
- print type_barang[1][i]
- ---------------------------------------------------------------------------------------
- -Pemanggilan
- ---------------------------------------------------------------------------------------
- p=pakaian()
- p.mesin_cek(p.type1)
- p.mesin_cek(p.type2)
- ---------------------------------------------------------------------------------------
- "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:
- -Global variabel angka
- ---------------------------------------------------------------------------------------
- angka=1
- ---------------------------------------------------------------------------------------
- class percobaan:
- -Lokal variabel angka
- ---------------------------------------------------------------------------------------
- angka=6
- def test(self):
- print angka # global
- print self.angka # lokal
- c=percobaan()
- c.test()
- ---------------------------------------------------------------------------------------
- -Jika variabel lokal angka dipanggil dari luar class, harus menyertakan instance class nya
- ---------------------------------------------------------------------------------------
- print c.angka
- print angka
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 052.
- "MELOAD GAMBAR EXTERNAL DENGAN MODULE IMAGE 1ST"
- Saya mau share tentang cara meload gambar eksternal khususnya pada s60 1st, namun bisa juga digunakan pada s60 2nd...
- Fungsi pada module graphics yang berfungsi untuk meload dan menampilkan gambar pada appuifw.canvas() yaitu: graphics.Image.open(). Sayangnya fungsi tersebut hanya berjalan pada s60v2 keatas dan tidak jalan pada N-Gage saya yang masih s60 v1. Beruntung ada modul buatan pihak ketiga yang berfungsi untuk menampilkan gambar pada s60 v1. Modul tersebut bernama "image1st". Sebenarnya ingin membahas fungsi Image.open() juga, tapi karena saya ndak punya HP buat ngetest jadi hanya cara menampilkan gambar dengan image1st yang saya bahas. Sebelumnya simpan gambar dibawah ini dan taruh difolder E:\images\
- Pada Pys60 Blit() berfungsi untuk menampilkan gambar baik gambar external ataupun old graphics didalam ataupun diluar objek gambar external atau old graphics juga.
- blit untuk menampilkan gambar external:
- ---------------------------------------------------------------------------------------
- img.blit(file_gambar)
- ---------------------------------------------------------------------------------------
- Gambar tersebut ditampilkan apa adanya dengan posisi pada pojok kiri atas. Posisi gambar dapat kita atur target posisinya:
- ---------------------------------------------------------------------------------------
- img.blit(file_gambar, target=(20,20))
- ---------------------------------------------------------------------------------------
- Penjelasan:
- target=(x, y)
- Selain mengatur posisi target, kita juga dapat memotong gambar yang ingin ditampilkan (croping):
- ---------------------------------------------------------------------------------------
- img.blit(file_gambar, target=(20,20), source=(20,20,20,20))
- ---------------------------------------------------------------------------------------
- Penjelasan:
- source=(PotongGambarKiri, PotongGambarAtas,PotongGambarKanan, PotongGambarBawah)
- Pemotongan sebanyak nilai yang dimasukkan (dalam piksel)
- Kita juga dapat me-resize gambarnya:
- ---------------------------------------------------------------------------------------
- img.blit(file_gambar, target=(30,30,30,30), scale=1)
- ---------------------------------------------------------------------------------------
- Penjelasan:
- Python akan meresize gambar sebesar atau sesuai target yang kita masukkan. Pengaturan posisi target sama dengan source. Misalnya kita ingin meresize ukuran gambar menjadi fullscreen 176x208 (resolusi layar HP saya) maka posish target dirubah menjadi (0,0,176,208). Namun resize gambar ini lumayan berat.
- Ada satu pengaturan lagi yaitu "mask" ini digunakan untuk mentransparansi gambar sayang, masking ini hanya support pada s60 2nd fp2 keatas. Maaf, saya belum mencoba masking ini jadi tidak saya bahas.
- Itulah penggunaan fungsi blit().
- ==========
- 053.
- "CONTOH PROGRAM GAME GUNTING, BATU, KERTAS"
- Saya mau share cara membuat game text based "Gunting batu kertas"...
- Sebagai contoh penggunaan variabel, dictionary, definisi dan percabangan (else if) pada program game. Ok mari kita mulai:
- -Import beberapa module yang akan kita gunakan
- ---------------------------------------------------------------------------------------
- import appuifw, e32, random
- ---------------------------------------------------------------------------------------
- -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
- ---------------------------------------------------------------------------------------
- pilih = {"Gunting": 0, "Batu": 1, "Kertas": 2}
- ---------------------------------------------------------------------------------------
- -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).
- ---------------------------------------------------------------------------------------
- Pemain=None
- ---------------------------------------------------------------------------------------
- -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).
- ---------------------------------------------------------------------------------------
- Musuh=None
- ---------------------------------------------------------------------------------------
- -Membuat variabel kosong yang kita kasih nama "konf" (konfirmasi) yang akan dipakai untuk menyimpan konfirmasi "menang", "kalah", atau "seimbang".
- ---------------------------------------------------------------------------------------
- konf=None
- ---------------------------------------------------------------------------------------
- -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.
- -Untuk memanggil fungsi gameplay diatas kita buat tiga fungsi, masing2 memberi nilai berbeda kepada gameplay yaitu 0 (Gunting), 1 (Batu), 2 (Kertas).
- -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.
- ---------------------------------------------------------------------------------------
- appuifw.app.menu=[(u"Pilih gunting", memilihGunting),(u"Pilih batu", memilihBatu),(u"Pilih kertas", memilihKertas)]
- ---------------------------------------------------------------------------------------
- -Membuat fungsi penutupan aplikasi dan menunggu tombol exit ditekan dengan module appuifw dan e32
- ---------------------------------------------------------------------------------------
- def quit():
- script_lock.signal()
- appuifw.app.exit_key_handler=quit
- script_lock=e32.Ao_lock()
- script_lock.wait()
- ---------------------------------------------------------------------------------------
- ==========
- 054.
- "SEDIKIT PENJELASAN IDENTASI PADA PYTHON"
- Saya mau share sedikit identasi pada python atau pada script pys60...
- Dalam pemrograman kita sering mengelompokkan beberapa kode dengan tujuan agar lebih mudah dibaca. Atau terkadang kode memang harus dibuat dalam blok-blok statement agar dapat berjalan, misalnya kita membuat sekumpulan kode yang akan berjalan ketika suatu event terjadi.
- Blok-blok statement pada Pyhon ditandai dengan jumlah spasi pada awal kode pada setiap baris, perhatikan contoh berikut ini:
- Penjelasan:
- kode X=2 adalah sebuah statement, kode Y=2 juga merupakan sebuah statement. Setiap statement pada python dipisahkan dengan ganti baris.
- kode if X == Y: merupakan awal sebuah blok statement (kita sebut saja blok statement pertama), sedangkan kode print"Tubrukan terdeteksi" adalah statement blok pertama tersebut (ditandai dengan memberi spasi pada awal baris, ane gunakan 2 spasi).
- Sedangkan kode else: merupakan awal sebuah blok statement kedua dan print "Tidak terjadi tubrukan" adalah statement blok kedua.
- Berikut ilustrasi yang menjelaskan penggunaan blok statement dalam psoudo code:
- Contoh kedua:
- Berikut ilustrasi contoh penulisan kode yang salah:
- Sebuah statement juga dapat dipotong2 menjadi beberapa baris dengan menggunakan tanda "\" berikut contohnya:
- ---------------------------------------------------------------------------------------
- print "Sudah adzan\
- saatnya sholat"
- ---------------------------------------------------------------------------------------
- ==========
- 055.
- "HEAT SEEKING MISSILE ALOGARITMA dan IMPLEMENTASI"
- Saya mau share tentang cara membuat game pesawat tempur atau perang bintang...
- Pasti anda pernah main game SHMUP seperti Sky Force buatan Infinity Dream atau game combat flight simulation seperti Galaxy On Fire buatan Fishlabs. Dalam game terdapat misil yang dapat mengejar target. Saya akan jelaskan dasar algoritma dan implementasi fisika gerakan misil tersebut.
- Algoritmanya sederhana, pertama hitung angle (sudut arah rotasi) antara misil dan target. Lalu bandingkan dengan angle misil. Jika hasilnya lebih besar dari nol, putar misil kekanan. Jika lebih kecil dari nol, putar misil kekiri.
- Dan seperti biasa, implementasinya tidak sesederhana algoritmanya biggrin tapi tidak terlalu sulit kok. Kita pakai operasi trigonometri dan vektor.
- Dimulai dari menghitung radian angle antara misil dan target. Rumusnya "angle = -atan(deltaX atau deltaY)" tapi butuh beberapa normalisasi agar berkerja dengan benar, saya jelaskan dibawah.
- Heat seeking missile
- -Hitung delta antara misil dan target
- ---------------------------------------------------------------------------------------
- deltaX = missileX - targetX
- deltaY = missileY - targetY
- ---------------------------------------------------------------------------------------
- Heat seeking missile
- -Gunakan delta untuk menghitung radian angle
- ---------------------------------------------------------------------------------------
- angleToTarget = -atan(deltaX/deltaY)
- ---------------------------------------------------------------------------------------
- Kode diatas memiliki masalah. Jika targetY sejajar dengan missileY, tidak bisa membedakan apakah target berada disebelah kanan misil (90 derajat) atau dikiri (180 derajat). Dan output angle hanya dalam 180 derajat saja tidak full 360 derajat. Tenang, cukup menggunakan percabangan if else untuk menyelesaikannya.
- ---------------------------------------------------------------------------------------
- deltaX = missileX - targetX
- deltaY = missileY - targetY
- if deltaY == 0:
- if deltaX<0:
- angleToTarget = 1.57
- else: angleToTarget = -1.57
- else:
- angleToTarget = -atan(deltaX/deltaY)
- if dy<0:
- angleToTarget += 3.14
- if angleToTarget<0:
- angleToTarget += 6.28
- ---------------------------------------------------------------------------------------
- Selanjutnya menghitung selisih angleToFace dengan angleMissile untuk memenentukan apakah misil harus diputar kekanan, kekiri atau tidak diputar karena sudah mengarah ke target.
- Heat seeking missile
- -Hitung sinus dan cosinus
- ---------------------------------------------------------------------------------------
- missileSin = sin(missileAngle)
- missileCos = cos(missileAngle)
- toTargetSin = sin(angleToTarget)
- toTargetCos = cos(angleToTarget)
- ---------------------------------------------------------------------------------------
- -Hitung selisih angle menggunakan dot product
- ---------------------------------------------------------------------------------------
- selisih = (missileSin*toTargetSin) + (missileCos*toTargetCos)
- ---------------------------------------------------------------------------------------
- -Mmemutar missile
- ---------------------------------------------------------------------------------------
- if selisih<0:
- missileAngle += missileRotSpd
- elif selisih>0:
- missileAngle -= missileRotSpd
- ---------------------------------------------------------------------------------------
- Selesai, jika dalam ruang 3d dapat menggunakan cara yang sama denga dua kali rotasi pada poros x dan poros y.
- ==========
- 056.
- "MEMBUAT KUIS DENGAN PYS60"
- Saya mau share cara membuat kuis dengan pys60...
- Ini contoh scriptnya,
- ---------------------------------------------------------------------------------------
- from appuifw import *
- jawaban=['Y']
- pertanyaan=query(u'kamu suka makan?','text',u'jawab dg Y atau T' )
- if jawaban.__contains__(pertanyaan )==1: note(u'weleh.. weleh.. kamu suka makan..','conf' )
- else: note(u'gak suka makan ya..','error' )
- ---------------------------------------------------------------------------------------
- ==========
- 057.
- "MEMBACA PESAN DENGAN PYS60"
- Saya mau share sebuah script yang dapat membaca pesan masuk...
- Saya pernah membaca sebuah tutorial menggunakan modul inbox untuk membaca pesan masuk pertama.
- Kurang lebih tutorialnya seperti ini:
- ---------------------------------------------------------------------------------------
- import inbox
- ib=inbox.Inbox(inbox.EInbox)
- ib.content(ib.sms_messages()[0])
- ---------------------------------------------------------------------------------------
- ==========
- 058.
- "BEBERAPA GAYA PENULISAN SCRIPT PYTHON"
- Saya mau share gaya penulisan dalam sebuah script...
- Ada beberapa cara penulisan script python.
- Antara lain:
- 01.
- import appuifw
- import graphics
- 02.
- import appuifw,graphics
- 03.
- from appuifw import*
- from graphics import*
- 04.
- import appuifw;import graphics
- 05.
- from appuifw import*;from graphics import*
- 06.
- import appuifw as a
- import graphics as g
- 07.
- import appuifw as a;import graphics as g
- Fungsi sintax diatas adalah sama, yaitu mengimport modul appuifw dan graphics.
- ==========
- 059.
- "MENAMPILKAN IP DENGAN PYS60"
- Saya mau share sebuah script untuk menampilkan sebuah ip...
- Ternyata bisa juga menampilkan ip saat kita terkoneksi dengan internet dengan beberapa baris code saja.
- Ini dia codenya:
- ---------------------------------------------------------------------------------------
- import socket
- n=socket.select_access_point()
- j=socket.access_point(n)
- j.start()
- ip=j.ip()
- print ip
- j.stop()
- ---------------------------------------------------------------------------------------
- ==========
- 060.
- "MODUL TXTFIELD"
- Saya mau share sebuah script yang fungsinya seperti nulis teks dibar address url...
- Contoh penggunaanya, kayak gini
- ---------------------------------------------------------------------------------------
- import txtfield
- t1 = txtfield.New( (10,10,100,40) , (txtfield.ENoLineBreaks )
- t1.focus(1)
- ---------------------------------------------------------------------------------------
- ==========
- 061
- "PERULANGAN FOR DALAM PYS60"
- Saya mau share script untuk perulangan sebuah teks...
- Kita coba dulu dengan yang ini:
- ---------------------------------------------------------------------------------------
- x=5
- for i in range(x):
- print unicode('test' )
- ---------------------------------------------------------------------------------------
- hasilnya:
- test
- test
- test
- test
- test
- kesimpulannya:
- i disini akan mencetak kata 'tes' sejumlah value 'x'.
- Or
- mengeprint 'tes' sebanyak 'x' kali.
- Dan ini contoh penerapannya di script,
- ---------------------------------------------------------------------------------------
- from appuifw import*
- from e32 import*
- l=Ao_lock()
- t=Text()
- def quit():
- >>l.signal()
- font=available_fonts()
- for i in range(len(font)):
- >>t.font=font
- >>t.color=0
- >>t.add(unicode(str(font)+': abc 123\n' ))
- app.screen='full'
- app.body=t
- app.exit_key_handler=quit
- l.wait()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 062.
- "POPUP MENU GANDA DENGAN PYS60"
- Saya mau share sebuah script popup menu ganda...
- ---------------------------------------------------------------------------------------
- from appuifw import*
- a=[( u'satu satu' ),( u'satu dua' ),( u'satu tiga' )]
- b=[( u'dua satu' ),( u'dua dua' )]
- list_sub=[a,b]
- menu=[( u'satu' ),( u'dua' )]
- p=popup_menu( menu,u'pilih' )
- q=popup_menu( list_sub[p],u'masuk_sub '+str( p+1 ))
- print u'pilihan pertama: '+str( p+1 )+u'\npilihan ke dua: '+str( q+1 )
- ---------------------------------------------------------------------------------------
- ==========
- 063.
- "MENGECEK dan MEMBUAT FOLDER DENGAN PYS60"
- Saya mau share sebuah script untuk mengecek ada atau nggak ada folder di HP kita dengan module os. Dan module appuifw untuk pemberitahuannya.
- Langsung saja, berikut adalah kodenya..
- ---------------------------------------------------------------------------------------
- import appuifw,os
- folder=unicode( "e:\\NamaFolder" )
- if os.path.exists(folder):
- >>appuifw.note( unicode( ""+str(folder)+" ada" ))
- >>if appuifw.query( unicode( "hapus "+str(folder) ), "query" )== True:
- os.removedirs( folder )
- appuifw.note( unicode( ""+str(folder)+" selesai dihapus" ))
- >>else:
- appuifw.note( unicode( ""+str(folder)+" tidak dihapus" ))
- >>else:
- >>appuifw.note( unicode( ""+str(folder)+" tidak ada" ))
- >>if appuifw.query( unicode( "buat "+str(folder) ), "query" )== True:
- os.makedirs( folder )
- appuifw.note( unicode( ""+str(folder)+" selesai dibuat" ))
- >>else:
- appuifw.note( unicode( "membuat "+str(folder)+" dibatalkan" ))
- ---------------------------------------------------------------------------------------
- ==========
- 064.
- "SALAH SATU PERBEDAAN SYNTAK S60v1 dan S60v2 DIATASNYA"
- Saya mau share tentang perbedaan script untuk import gambar antara s60v1 dan s60v2...
- Mungkin teman-teman sudah tahu, bahwa s60v1 dan s60v2 keatas mempunyai cara yang berbeda dalam menampilkan gambar.
- Perbedaan ini menjadi salah satu yang menyebabkan aplikasi s60v2 keatas tidak dapat dibuka di s60v1.
- Berikut perbedaannya:
- s60v2 keatas:
- ---------------------------------------------------------------------------------------
- import graphics
- file=u'e:\\nama_file.jpg'
- im=graphics.Image.new(( 176,208 ))
- gambar=graphics.Image.open(file)
- im.blit(gambar, target=(0,0))
- ---------------------------------------------------------------------------------------
- s60v1:
- ---------------------------------------------------------------------------------------
- import graphics,image1st
- file=u'e:\\nama_file.jpg'
- im=graphics.Image.new(( 176,208 ))
- bm=graphics.Image.from_cfbsbitmap
- img=image1st.convertimage
- gambar=bm( img( file ))
- im.blit(gambar, target= ( 0,0 ))
- ---------------------------------------------------------------------------------------
- ==========
- 065.
- "ROTASI POLYGON DENGAN PYS60"
- Saya mau share cara rotasi pada gambar tradisional...
- Menurut sumbernya saya mendapatkan rumus ini:
- ---------------------------------------------------------------------------------------
- rad=(angle/180.0)*pi
- rot_x=cos(rad)*pos_x-sin(rad)*pos_y
- rot_y=sin(rad)*pos_x+cos(rad)*pos
- ---------------------------------------------------------------------------------------
- Contoh script di pys60
- ---------------------------------------------------------------------------------------
- import e32,appuifw,math,graphics,sysinfo
- def exit_handler():
- >>>global run;run=0
- canvas=appuifw.Canvas()
- appuifw.app.body=canvas
- appuifw.app.screen='full'
- appuifw.app.exit_key_handler=exit_handler
- layar=sysinfo.display_pixels()
- im=graphics.Image.new(layar)
- run=1
- pos_x,pos_y,angle=0,0,1.0
- panah=[(x-16,y),(x,y-20),(x+16,y),(x+4,y),(x+4,y+10),(x-4,y+10),(x-4,y)]
- camx,camy=layar[0]/2,layar[1]/2
- while run:
- >>>gb=[]
- >>>rad=float(angle/180.0)*math.pi
- >>>angle+=10
- >>>if angle>360: angle=0
- >>>for pos in panah:
- >>>x,y=pos
- >>>rx=math.cos(rad)*x-math.sin(rad)*y
- >>>ry=math.sin(rad)*x+math.cos(rad)*y
- >>>rx+=camx
- >>>ry+=camy
- >>>gb.append((rx,ry))
- >>>im.clear(0)
- >>>im.polygon(gb,0xdadada,fill=0x00ff00)
- >>>canvas.blit(im)
- >>>e32.ao_sleep(0)
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 066.
- "SCAN ISI DRIVE DENGAN PYS60"
- Saya mau share sebuah script untuk scanning isi drive di HP kita menggunakan pys60...
- Ini baris codenya...
- ---------------------------------------------------------------------------------------
- from appuifw import*;import os,e32
- f=e32.drive_list()
- def scan(x):
- >>if os.path.isdir(x):
- for i in os.listdir(x):
- >>if os.path.isdir(x+i):
- i=i+os.sep
- >>print x+i
- >>scan(x+i)
- p=popup_menu(f,unicode( 'pilih drive' ))
- if p!=None: scan( f[p]+os.sep )
- else: print unicode( 'scan dibatalkan' )
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 067.
- "MENGGABUNGKAN FUNGSI DENGAN PROGRESS PADA PYS60"
- Saya mau share sebuah script untuk menggabungkan module progress dengan fungsi, gunanya, buat mengetahui sampai mana fungsi yang sudah diproses...
- Ini contoh scripnya,
- ---------------------------------------------------------------------------------------
- import progress
- teks=['proses ke 1','proses ke 2','proses ke 3','proses ke 4','proses ke 5','proses ke 6','proses ke 7','proses ke 8','proses ke 9','proses ke 10']
- pb=progress.TWProgressBar(start=0,end=100,fill=(0,0,0),outline=(100,255,0),display=(176,100),title=unicode( ' ' ))
- def t1():
- >>>print u'tes1'
- def t2():
- >>>print u'tes2'
- def t3():
- >>>print u'tes3'
- def t4():
- >>>print u'tes4'
- def t5():
- >>>print u'tes5'
- def t6():
- >>>print u'tes6'
- def t7():
- >>>print u'tes7'
- def t8():
- >>>print u'tes8'
- def t9():
- >>>print u'tes9'
- def t10():
- >>>print u'tes10'
- tugas=[t1,t2,t3,t4,t5,t6,t7,t8,t9,t10]
- for i in range(len(tugas)):
- >>>tugas[ i ]()
- >>>pb=progress.TWProgressBar(start=0,end=100,fill=(0,0,0),outline=(100,255,0),display=(176,100),title=unicode(''+str(teks[ i ])))
- >>>pb.set_value((i+1)*10)
- pb.close()
- ---------------------------------------------------------------------------------------
- Intinya, kita masukkan fungsi kedalam list, lalu kita jalankan fungsi setelah sebelumnya kita loop , kemudian value pada progress kita set loop listnya.
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 068.
- "SCRIPT PYS60 BERKODE"
- Saya mau share sebuah script, dimana jika dalam waktu tertentu script tersebut akan meminta kode dari pemilik handphone...
- Jika kode yang ditulis tidak sama dengan kunci kodenya, maka script akan tertutup.
- Kita import module yang diperlukan.
- ---------------------------------------------------------------------------------------
- import appuifw,graphics,e32,sysinfo,time
- def quit():
- global run
- run=0
- ap=appuifw.app
- ap.screen='full'
- ap.body=c=appuifw.Canvas()
- ap.exit_key_handler=quit
- im=graphics.Image.new(( 176,208 ))
- def unlock():
- imei=sysinfo.imei()
- return imei[:-2]
- timer=10
- def password():
- cd=appuifw.query( u'masukkan kode','code' )
- if cd !=unlock(): quit()
- else: pass
- run=1
- while run:
- im.clear(0)
- im.text((0,10),u'timer: '+str(time.localtime()[5]),0xdadada)
- im.text((0,30),u'kode yang harus dimasukkan: '+str(unlock()),0xdadada)
- if time.localtime()[5]==timer:
- password()
- c.blit(im)
- e32.ao_sleep(0)
- ---------------------------------------------------------------------------------------
- ==========
- 069.
- "MENAMPILKAN SEMUA ICON APLIKASI YANG TERINSTALL DENGAN PYS60"
- Saya mau share module geticon buat nampilin icon aplikasi...
- Ini contoh scriptnya,
- ---------------------------------------------------------------------------------------
- import appuifw,graphics,e32,geticon,os
- run=1
- def quit():
- >>global run
- >>run=0
- appuifw.app.exit_key_handler=quit
- appuifw.app.screen='full'
- c=appuifw.Canvas()
- appuifw.app.body=c
- im=graphics.Image.new( (0,0) )
- im_mask=graphics.Image.new( (0,0) , 'L' )
- uid=[]
- nama_app=[]
- folder=u'e:\\system\\apps\\'
- list_folder=os.listdir(folder)
- def intip( x ):
- >>x=(((x[3:4]+x[2:3])+x[1:2])+x[0:1])
- >>x=x.encode( 'hex' )
- >>return x
- def uidnya(file):
- >>f=open(file)
- >>uid1=f.read(4)
- >>uid2=f.read(4)
- >>uid3=f.read(4)
- >>f.close()
- >>uidr1=intip(uid1)
- >>uidr2=intip(uid2)
- >>uidr3=intip(uid3)
- >>return uidr3
- def cek():
- >>for i in list_folder:
- for app in os.listdir( folder+i+os.sep ):
- >>if app.endswith( u'.app' ):
- uid.append( '0x'+uidnya(folder+i+os.sep+app) )
- nama_app.append(app)
- cek()
- timer=0
- y=0
- while run:
- >>if timer<=0:
- timer=1
- y-=29
- >>if timer>0: timer-=1
- >>if (len(uid)*29)+y<=0: y=0
- >>c.clear()
- >>for i in range( len(uid) ):
- geticon.get(eval( uid[ i ]),im,im_mask)
- c.text((80,50),u'timer: '+str((len(uid)*29)+y),0x0)
- c.blit(im,target=(10,y+(i*29)))
- >>e32.ao_sleep(0.3)
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 070.
- "MEMBUAT KURSOR 4 ARAH PADA APLIKASI DENGAN PYS60"
- Saya mau share sebuah script untuk membuat menu aplikasi dengan kursor yang dapat digerakkan 4 arah, dengan menekan tombol 2,4,6,8. Dan tombol 5 untuk memilihnya...
- Sebelumnya, siapakan dulu gambar di e:\\dengan nama gb.Jpg. Gambar tersebut akan diresize menurut ukuran layar HP pengguna. Ada module key yang saya import untuk menghandle tombolnya, kalau gak punya module key, bisa diganti dengan class keyboard di snake.py.
- ---------------------------------------------------------------------------------------
- import appuifw,graphics,e32,sysinfo
- try: import key
- except: appuifw.note( u'module key belum ada' )
- run=1
- def quit(): global run;run=0
- appuifw.app.screen='full'
- appuifw.app.exit_key_handler=quit
- c=appuifw.Canvas(event_callback=key.press.handle_event)
- appuifw.app.body=c
- layar=sysinfo.display_pixels()
- im=graphics.Image.new(layar)
- lebar=layar[0]/3.0
- tinggi=layar[1]/3.0
- try: gambar=graphics.Image.open( u'e:\\gb.jpg' ).resize(( lebar,tinggi ))
- except:
- >>>appuifw.note( u'siapkan gambar di e:\\dulu' )
- >>>quit()
- pos_x=range(0,layar[0],lebar)
- pos_y=range(0,layar[1],tinggi)
- kursor_x,kursor_y=0,0
- pos_x_kursor,pos_y_kursor=0,0
- menu=[[ 'satu', 'dua', 'tiga' ], [ 'empat', 'lima', 'enam' ], [ 'tujuh', 'delapan', 'sembilan' ]]
- while run:
- >>>im.clear( 0 )
- >>>for i in range( len( pos_x )):
- for j in range( len( pos_y )):
- im.blit(gambar,target= (pos_x[ i ],pos_y[ j ] ))
- >>>if kursor_x > len( pos_x )-2:
- >>>kursor_x = 0
- >>>kursor_y += 1
- >>>if kursor_y > len( pos_y )-2:
- >>>kursor_y = 0
- >>>if kursor_x < 0:
- >>>kursor_x = len( pos_x )-2
- >>>kursor_y -= 1
- >>>if kursor_y < 0:
- >>>kursor_y = len( pos_y )-2
- >>>if kursor_y > len( pos_y )-2:
- >>>kursor_y = 0
- >>>kursor_x += 1
- >>>if kursor_x > len( pos_x )-2:
- >>>kursor_x = 0
- >>>if kursor_y < 0:
- >>>kursor_y = len( pos_y )-2
- >>>kursor_x -= 1
- >>>if kursor_x < 0:
- >>>kursor_x = len( pos_x )-2
- >>>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)
- >>>if key.press.is_down( key.EScancode5 ):
- >>>im.rectangle(( 15,25,120,35 ),0x0, 0xda00d0)
- >>>im.text(( 20,35 ),u'menu ke: '+str( menu[ kursor_y ][ kursor_x ]),0xffffff,font=u'latinbold12' )
- >>>if key.press.pressed( key.EScancode6 ):
- >>>kursor_x += 1
- >>>if key.press.pressed( key.EScancode4 ):
- >>>kursor_x -= 1
- >>>if key.press.pressed( key.EScancode2 ):
- >>>kursor_y -= 1
- >>>if key.press.pressed( key.EScancode8 ):
- >>>kursor_y += 1
- >>>c.blit(im)
- >>>e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 071.
- "MEMBUAT JAM ANALOG DENGAN PYS60"
- Saya mau share cara membuat jam analog menggunakan pys60...
- Pertama, kita tentukan jam sekarang dengan module time. Lengkapnya
- ---------------------------------------------------------------------------------------
- import time
- data=time.localtime()
- ---------------------------------------------------------------------------------------
- Sekarang data sudah berisi tuple localtime, yang pertama adalah tahun, bulan, tanggal, jam, menit, detik.
- Berikutnya, jika kita lihat jarum jam selalu muter kan? Buat memuterkan gambar, kita pakai cosinus, sinus, radian yang berasal dari fungsi module math.. Lengkapnya..
- ---------------------------------------------------------------------------------------
- Import math
- x,y=0,0
- sudut=0
- jarak=10
- rad=(float(sudut)*math.pi)/180
- cos=math.cos
- sin=math.sin
- muter_x=cos(rad)*jarak-sin(rad)*jarak
- muter_y=sin(rad)*jarak+cos(rad)*jarak
- ---------------------------------------------------------------------------------------
- Biasanya jarum detik itu bertambah 1, jika sudah mencapai 60, kembali ke 0 lagi.
- Jadi, kita pakai
- ---------------------------------------------------------------------------------------
- rad_detik = (detik_sekarang/jumlah 1 putaran)*360 derajat
- ---------------------------------------------------------------------------------------
- Begitu juga dengan jarum menit dan jarum jam.
- Nanti kita tinggal menghubungkan titik pusat dengan koordinat koordinat jarum jam tadi sehingga menjadi garis.
- Biar selalu diupdate, proses kita masukkan didalam identasi 'while' ..
- Berikut ini scriptnya
- ---------------------------------------------------------------------------------------
- import appuifw,graphics,e32,sysinfo,time,math
- run=1
- def quit():
- >>global run
- >>run=0
- appuifw.app.exit_key_handler=quit
- appuifw.app.screen='full'
- c=appuifw.Canvas()
- appuifw.app.body=c
- layar=sysinfo.display_pixels()
- im=graphics.Image.new(layar)
- x,y=layar[0]/2,layar[1]/2
- detik=0
- menit=0
- jam=0
- jdetik=layar[0]/4
- jmenit=jdetik-5
- jjam=jmenit-5
- def radian(sudut):
- >>return (float(sudut)*math.pi)/180.0
- while run:
- >>cos=math.cos
- >>sin=math.sin
- >>data=time.localtime()
- >>detik=235+(data[5]*6)
- >>menit=235+(data[4]*6)
- >>jam=235+(data[3]*30)
- >>rad_detik=radian(detik)
- >>rad_menit=radian(menit)
- >>rad_jam=radian(jam)
- >>xdetik=cos(rad_detik)*jdetik-sin(rad_detik)*jdetik
- >>ydetik=sin(rad_detik)*jdetik+cos(rad_detik)*jdetik
- >>xmenit=cos(rad_menit)*jmenit-sin(rad_menit)*jmenit
- >>ymenit=sin(rad_menit)*jmenit+cos(rad_menit)*jmenit
- >>xjam=cos(rad_jam)*jjam-sin(rad_jam)*jjam
- >>yjam=sin(rad_jam)*jjam+cos(rad_jam)*jjam
- >>im.clear(0)
- >>im.line((x,y,x+xdetik,y+ydetik),0xdd0000)
- >>im.line((x,y,x+xmenit,y+ymenit),0xddd000)
- >>im.line((x,y,x+xjam,y+yjam),0xddd000)
- >>for i in range(225,585,30):
- l=jdetik+5
- rr=(float(i)*math.pi)/180
- xr=cos(rr)*l-sin(rr)*l
- yr=sin(rr)*l+cos(rr)*l
- im.point((x+xr,y+yr),(255,255,255),width=2)
- >>c.blit(im)
- >>e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Penambahan 240 dan range(225,585,30) hanya akal-akalan saya saja biar jarumnya pas.
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 072.
- "INDIKATOR SINYAL, BATERAI DENGAN FGIMAGE (PYS60)"
- Saya mau share cara menampilkan indikator battery menggunakan pys60...
- Biar indikator jalan terus, maka kita pakai 'while' agar prosesnya biar update terus. Disini saya menggabunkan sysinfo dengan fgimage agar bisa ditampilkan dengan cara diminimize.
- ---------------------------------------------------------------------------------------
- import fgimage,appswitch,sysinfo,appuifw,graphics,e32
- fg=0
- def quit():
- >>global run,runn,fg
- >>run,runn,fg=0,0,0
- def fokus(on):
- >>global fg,run
- >>if not on:
- fg=fgimage.FGImage()
- run=2
- >>else:
- fg=0
- run=1
- def menu_app():
- >>gul=appswitch.application_list(0)[0]
- >>appswitch.switch_to_bg(gul)
- layar=sysinfo.display_pixels()
- lebar,tinggi=176,15
- posx,posy=0,29
- menu=[(unicode( 'exit' ),quit)]
- appuifw.app.screen='full'
- appuifw.app.exit_key_handler=menu_app
- appuifw.app.body=c=appuifw.Canvas()
- appuifw.app.focus=fokus
- appuifw.app.menu=menu
- im=graphics.Image.new((lebar,tinggi))
- img=graphics.Image.new(layar)
- run,runn=1,1
- class monitor:
- >>def draw(self):
- sin=(float(sysinfo.signal())/7)*100
- sn=round(sin,1)
- bat=(float(sysinfo.battery())/7)*100
- bt=round(bat,1)
- im.clear(0xaa550f)
- im.text((90,12),unicode('baterai '+str(bt)+' %' ),0xfafafa,u'latinplain12' )
- im.text((5,12),unicode('sinyal '+str(sn)+' %' ) ,0xfafafa,u'latinplain12' )
- fg.set(posx,posy,im._bitmapapi( ))
- teks=['','','http://gumalgamul.mywapblog.com','','','tool for show signal and battery','','','minimize for show']
- def tulis(lis):
- >>for i in range(len(lis)):
- img.text((3,10+(i*12)),unicode(''+lis),(200,200,200),u'latinplain12' )
- gulam=monitor()
- while runn:
- >>while run==1:
- img.clear(0)
- tulis(teks)
- img.text((5,200 ),u'exit',0xfafafa)
- img.text((130,200),u'minimize',0xfafafa)
- c.blit(img)
- e32.ao_sleep(0)
- >>while run==2:
- gulam.draw()
- e32.ao_sleep(0)
- >>e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 073.
- "SET FGIMAGE PADA STANDBY PYS60"
- Saya mau share cara menampilkan fgimage dimenu standby saja...
- Pertama:
- -mendeteksi bahwa aplikasi apa yang sekarang sedang berjalan.
- -jika aplikasi == standby atau phone.app kita atur posisi 'fgimage' ke koordinat x dan y
- -jika aplikasi != standby atau phone.app 'fgimage' kita kasih trik sedikit yaitu set posisi ke koordinat -x,-y biar gak kelihatan.
- Lalu, bagaimana kita mendeteksi bahwa sekarang 'stand by' atau 'phone.app' sedang berjalan?
- Kita pakai fungsi dari module appswitch aja, yaitu appswitch.application_list untuk mendeteksinya, dan diproses berulang ulang. Caranya,
- ---------------------------------------------------------------------------------------
- While proses:
- >>now=appswitch.application_list(0)[0]
- >>if now==u'Phone': fgimage set ke koordinat x,y
- >>elif now==u'Menu': fgimage set ke koordinat x,y cadangan
- >>else: fgimage set ke koordinat -x,-y
- ---------------------------------------------------------------------------------------
- Berikut penerapannya dalam script pys60
- ---------------------------------------------------------------------------------------
- import appuifw,graphics,e32,fgimage,appswitch,globalui
- run=1
- def quit():global run;run=0;fg.unset()
- appuifw.app.screen='full'
- appuifw.app.exit_key_handler=quit
- appuifw.app.body=c=appuifw.Canvas()
- im=graphics.Image.new((176,40))
- fg=fgimage.FGImage()
- x,y=0,0
- posx,posy=0,10
- while run:
- >>posx+=2
- >>if posx>176: posx=0
- >>now=appswitch.application_list(0)[0]
- >>if now==u'Phone':
- x,y=0,0
- im.clear( 0 )
- im.text((posx,posy),u'fg tampil',0xdadada)
- >>elif now==u'Menu':
- x,y=0,160
- im.clear( 0 )
- im.text((posx,posy),u'minimize sekarang',0xdadada)
- >>else: x,y=-10,-160
- >>fg.set(x,y,im._bitmapapi())
- >>e32.ao_yield()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 074.
- "SCREESHOT DENGAN N-GAGE atau S60v1 (PYS60)"
- Saya mau share cara menscreenshot menggunakan tombol edit atau pensil...
- Script python dibawah ini bisa mengambil screenshot dengan cara menekan tombol edit atau pensil.
- Caranya? Run script, lalu tekan tombol menu untuk meminimalise aplikasi.. Tekan tombol edit atau pensil dibagian mana sobat ingin mengambil screenshotnya. Hasil gambar tersimpan di folder e:\\di sini ,dengan nama ss.jpg
- ---------------------------------------------------------------------------------------
- import appuifw,time,graphics,image1st2,keycapture,globalui
- l=graphics.e32.Ao_lock()
- def quit():capt.stop();l.signal()
- def shot(on):nama=u'e:\\ss';ext=str(time.localtime()[3:6])+'.jpg';s=graphics.screenshot();image1st2.save(s,nama+ext);globalui.global_note( nama+ext+' tersimpan ' )
- capt=keycapture.KeyCapturer(shot)
- capt.keys=(63499,63499)
- capt.start()
- appuifw.app.exit_key_handler=quit
- l.wait()
- ---------------------------------------------------------------------------------------
- ==========
- 075.
- "MEMBUAT GRAFIK (SCRIPT PYS60)"
- Saya mau share cara menampilkan nilai menggunakan grafik...
- Selain dengan bar, untuk menampilkan nilai, kita juga bisa menggunakan grafik.
- Jadi caranya begini:
- 1. Kita ambil posisi berdasarkan informasi ukuran layar.
- ---------------------------------------------------------------------------------------
- ly=sysinfo.display_pixels()
- ---------------------------------------------------------------------------------------
- 2. Kita buat posisi awal garis akan muncul. Posisi x kita atur layar paling kanan, posi y kita atur tinggi layar/2
- ---------------------------------------------------------------------------------------
- x,y=ly[0],ly[1]/2
- ---------------------------------------------------------------------------------------
- 3. Karena grafik yang akan kita buat berupa garis, maka kita buat list dengan isi 4 koordinat awal, kita masukkan saja posisi awal garis yang kita buat tadi.
- ---------------------------------------------------------------------------------------
- pos=[x,y,x,y]
- ---------------------------------------------------------------------------------------
- 4. Kita atur timer, jika timer kurang atau sama dengan 0, timer=delay, list pos ditambah 2 koordinat list pos terakhir, dan 2 koordinat baru (koordinat pertama layar paling kanan, koordinat kedua berfungsi sebagai naik turunnya grafik, kita pakai random.choice)
- ---------------------------------------------------------------------------------------
- rand=random.choice(range(10,ly[1]-20,20))
- if timer<=0:
- >>timer=delay
- >>pos.append([pos[-1][2],pos[-1][3],x,rand])
- ---------------------------------------------------------------------------------------
- 5. Kemudian, jika timer lebih dari 0, timer dikurangi 1
- ---------------------------------------------------------------------------------------
- if timer>0:
- >>timer-=1
- ---------------------------------------------------------------------------------------
- 6. Sekarang, kita loop list pos
- ---------------------------------------------------------------------------------------
- for i in range(len(pos)):
- ---------------------------------------------------------------------------------------
- 7. Kita atur pergerakannya, masih didalam identasi for, jangan lupa, hapus koordinat yang kurang dari 0 agar script tidak berat, barulah kita gambar .
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 076.
- "GET COORDINATE ARROUND CIRCLE (PYS60)"
- Saya mau share cara membuat koordinat pada lingkaran menggunakan pys60...
- Kali ini, kita akan menggabungkan sedikit matematika dengan pys60. Kita akan mencari koordinat koordinat yang ada pada sebuah lingkaran, yang dihasilkan dari sebuah titik pusat lingkaran dan jari jari tertentu.
- 01. Kita buat dulu titik pusat lingkaran.
- 02. Kita buat titik lingkaran dengan jari jari.
- 03. Kita putar titik yang sudah kita buat tadi 360 derajat.
- Kumpulan titik-titik itulah koordinatnya. Jadi, kita tinggal memasukkan koordinat-koordinat tersebut kedalam list.
- Ini kodenya,
- ---------------------------------------------------------------------------------------
- x,y=80,80
- ---------------------------------------------------------------------------------------
- -Ini sebagai titik pusat lingkaran.
- ---------------------------------------------------------------------------------------
- r=10
- ---------------------------------------------------------------------------------------
- -Ini sebagai jari jari.
- -Fungsi konversi ke radian
- def radian(angle):return (float(angle)/
- ---------------------------------------------------------------------------------------
- 180.0)*math.pi
- ---------------------------------------------------------------------------------------
- -Rumus memutar
- -Rad adalah hasil konversi ke radian
- ---------------------------------------------------------------------------------------
- rx=r*math.cos(rad)-r*math.sin(rad)
- ry=r*math.sin(rad)+r*math.cos(rad)
- ---------------------------------------------------------------------------------------
- -Satu koordinat titik lingkaran adalah
- ---------------------------------------------------------------------------------------
- [x+rx,y+ry]
- ---------------------------------------------------------------------------------------
- Sekarang tinggal kita gabung dengan range(360) untuk mendapatkan koordinat 1 putaran lingkaran.
- Ini kodenya
- ---------------------------------------------------------------------------------------
- import math
- pi=math.pi
- cos=math.cos
- sin=math.sin
- def radian(xx):
- return (float(xx)/180.0)*pi
- def get_circle_coord(x,y,r):
- rad=[]
- result=[]
- sdt=range(360)
- for i in xrange(len(sdt)):
- rad.append(round(radian(sdt),2))
- for oke in xrange(len(rad)):
- rx=round(r*cos(rad[oke])-r*sin(rad[oke]),1)
- ry=round(r*sin(rad[oke])+r*cos(rad[oke]),1)
- result.append([x+rx,y+ry])
- return result
- ---------------------------------------------------------------------------------------
- Untuk mencobanya, sekarang kita gambar titik-titik yang sudah kita kumpulkan dalam list tadi, kalau benar, maka titik-titik tadi akan membentuk lingkaran, kalau salah, tidak akan membentuk lingkaran,
- Ini kodenya
- ---------------------------------------------------------------------------------------
- import graphics,e32,appuifw,math
- from sysinfo import display_pixels as pixels
- run=1
- def quit():
- global run
- run=0
- ly=pixels()
- im=graphics.Image.new(ly)
- ap=appuifw.app
- ap.screen='full'
- ap.exit_key_handler=quit
- ap.body=c=appuifw.Canvas()
- x,y,j=ly[0]/2,ly[1]/2,20
- cos=math.cos
- sin=math.sin
- pi=math.pi
- def radian(xx):
- return (float(xx)/180.0)*pi
- def get_circle_coord(x,y,r):
- rad=[]
- result=[]
- sdt=range(360)
- for i in xrange(len(sdt)):
- rad.append(round(radian(sdt),2))
- for oke in xrange(len(rad)):
- rx=round(r*cos(rad[oke])-r*sin(rad[oke]),1)
- ry=round(r*sin(rad[oke])+r*cos(rad[oke]),1)
- result.append([x+rx,y+ry])
- return result
- res=get_circle_coord(x,y,j)
- while run:
- im.clear(0)
- im.point((x,y),0xda0000)
- for i in res:im.point(i,0xda)
- c.blit(im)
- e32.ao_sleep(0)
- ---------------------------------------------------------------------------------------
- ==========
- 077.
- "ADJUST TIMING SUBTITTLE WITH PYTHON"
- Saya mau share cara mempercepat subtittle pada video...
- Misal nih, pola jeda -4, -9, -13, -18, -22, -27, -31, -36, -40, -45
- Kita buat 3 var berisi bilangan
- start = 0
- plus = 11,5
- minus = 7
- Karena subtitlenya cuma bisa bilangan bulat , maka kita pakai fungsi int()
- Ini script dasarnya
- ---------------------------------------------------------------------------------------
- start = 0
- plus = 11.5
- minus = 7
- for i in range(10):
- >>start = start + plus
- >>start = start - minus
- >>print i + int(start)
- ---------------------------------------------------------------------------------------
- Memang sih buat apa ada plus minus, kan bisa aja cuma pakai plus.
- Hasil eksperimen sih, kalau bilangan a dan b sama sama bulat, hasilnya memang sama dengan kelipatan. Sama kayak start + plus aja, tapi , jika kita ingin memasukkan bilangan desimal atau float, maka kurang efektif, jadi kita bikin plus sama minus. Begitu..
- Dan ini script lengkapnya
- ---------------------------------------------------------------------------------------
- a=0
- plus=11.5
- minus=7
- import time,re
- file=file_sub_asal
- result=file_sub_hasil
- t=open(file).read()
- d=re.findall('{(\d*)}{(\d*)}(.*)',t)
- res_file=open(result,'w')
- for i in d:
- >>a=a+plus
- >>a=a-minus
- >>res_file.write('{%d}{%d}%s\r\n'%(int(i[0])-int(a),int(i[1])-int(a),i[2]))
- res_file.close()
- print 'ok'
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 078.
- "MEMBUAT MENU GRID 3x3 (PYS60)"
- Saya mau share cara membuat tampilan menu grid menjadi 3x3...
- Biasanyakan menu cuma ada 1 kolom menurun, nah.. Kali ini kita belajar bikin yang gak seperti biasanya, yaitu 3x3.
- 01. Kita buat dulu 9 fungsi. (pakai def menu0 sampai def menu8 aja biar gampang)
- 02. Kita masukkan 9 fungsi tadi kedalam list, sebut saja list_func_menu. Jadinya kayak gini
- ---------------------------------------------------------------------------------------
- list_func_menu=[menu0,menu1,... menu8]
- ---------------------------------------------------------------------------------------
- 03. Kita buat variable name yang berfungsi mengatur posisi posisi x dan y menu dan kursor.
- 04. Kita buat list didalam list, yang berisi integer urutan list_func_menu, jadinya gini
- ---------------------------------------------------------------------------------------
- menu=[[0,1,2],[3,4,5],[6,7,8]]
- ---------------------------------------------------------------------------------------
- Why? Ya karena kita mau buat 3x3 gridnya. Kalau 4x4 gimana? Ya tinggal buat aja
- ---------------------------------------------------------------------------------------
- menu=[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]
- ---------------------------------------------------------------------------------------
- Jadi, intinya jika 3x3 grid, maka kita buat 1 list berisi 3 sub list. Masing2 sub list, berisi 3 bilangan.
- 05. Kita ingat, list dalam python dimulai dari angka 0.
- --angka 0,3,6 adalah angka pertama list mendatar.
- ---Jadi manggilnya
- ---------------------------------------------------------------------------------------
- menu[0][0], menu[0][1],menu[0][2]
- ---------------------------------------------------------------------------------------
- --sedang angka menurun pertama adalah 0,1,2
- ---manggilnya
- ---------------------------------------------------------------------------------------
- menu[0][0],menu[1][0],menu[2][0].
- ---------------------------------------------------------------------------------------
- Kita masukkan keperulangan for
- ---------------------------------------------------------------------------------------
- >>for yy in range(len(menu)):
- for xx in range(len(menu[xx])):
- ---------------------------------------------------------------------------------------
- -yy akan menjadi list menurun
- -xx akan menjadi list mendatar
- Berikutnya, kita buat kotak dengan variable name berisi bilangan bulat 0, sebagai kursor. Misal kx,ky=0,0 Isi kx dan ky bisa 0 atau 1, yang jelas , tidak boleh lebih dari panjang tiap list menu dan sublistnya.
- Jika sudah, kita gabungkan dengan fungsi module key kursor atas bawah kiri kanan, untuk menggerakkan kursor,dan tombol select, untuk memilih menu.
- -Jika joystik geser kekanan, kursor bergerak kekanan, nilai kx ditambah 1.
- -Jika joystik geser kekiri, kursor bergerak kekanan, nilai kx dikurangi 1.
- -Jika joystik geser kebawah, kursor bergerak kekanan, nilai ky ditambah 1.
- -Jika joystik geser keatas, kursor bergerak kekanan, nilai ky dikurangi 1.
- -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,
- ---------------------------------------------------------------------------------------
- list_func_menu[menu[py][px]].
- ---------------------------------------------------------------------------------------
- Untuk mengeksekusi tinggal kasih tanda() diakhir list fungsi yang dipanggil tadi, sehingga menjadi list_func_menu[menu[py][px]]()
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 079.
- "MEMBUAT KALKULATOR SEDERHANA"
- Saya mau share script python sederhana yang berfungsi sebagai kalkulator...
- Ini skriptnya
- -Import modul yang diperlukan,
- ---------------------------------------------------------------------------------------
- import appuifw
- ---------------------------------------------------------------------------------------
- -Membuat popup query dialog antara user dan python
- ---------------------------------------------------------------------------------------
- a=appuifw.query(u'angka pertama','number')
- ---------------------------------------------------------------------------------------
- -Membuat popup perintah
- ---------------------------------------------------------------------------------------
- L=[u'tambah +',u'kurang -',u'kali *',u'bagi /']
- b=appuifw.popup_menu(L,u'pilih:')
- ---------------------------------------------------------------------------------------
- -Membuat popup query ke 2
- ---------------------------------------------------------------------------------------
- c=appuifw.query(u'angka kedua','number')
- ---------------------------------------------------------------------------------------
- -Nah,sekarang buat fungsi kalkulasinya:
- ---------------------------------------------------------------------------------------
- if b==0:
- >>print a+c
- if b==1:
- >>print ac
- if b==2:
- >>print a*c
- if b==3:
- >>print a/c
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 080.
- "MEMBUAT TEKS BERJALAN DENGAN BACKGROUND SUARA"
- Saya mau share cara membuat teks berjalan dengan baground suara...
- Nah ini scriptnya:
- ---------------------------------------------------------------------------------------
- import appuifw as fw
- import audio as a
- import e32 as e
- lagu=a.Sound.open('e:\\dds.mp3' ) ; lagu.play()
- fw.app.screen='large'
- round=fw.Text()
- round.style=fw.HIGHLIGHT_ROUNDED
- round.color=0xff0000
- text=u'Masukan teks kamu disini mastah'
- for a in range(len(text ) ) :
- >>round.add(text[a])
- >>e.ao_sleep(0.2)
- e.Ao_lock().wait()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 081.
- "MEMBUAT POPUP ALA CEK PULSA"
- Saya mau share cara membuat popup yang sama persis dengan popup saat cek pulsa kartu 3...
- Kalian pasti tau kan itu popup yang tampil kalo kita cek pulsa
- Dengan python kita dapat memanipulasinya dengan mudah.
- Sekarang kita manipulasi jumlah pulsa,biar temen2 kita bilang 'wow'
- Misal cek pulsa kartu 3:
- ---------------------------------------------------------------------------------------
- import globalui
- import e32
- def start():
- >>e32.start_exe('z:\\system\\programs\\apprun.Exe','z:\\system\\apps\\phone\\phone.app')
- start()
- hewan=['Main Menu','Bal: Rp 1.999.000','1. Informasi Pulsa','2. Isi Ulang','3. Program&Promosi','4. Cek Kuota']
- ask=globalui.global_msg_query(unicode('\n'.join(hewan)),u'Pesan')
- if ask==1:
- >>for i in hewan:
- print i
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 082.
- "MENGIRIM SMS ke BANYAK NOMOR"
- Saya mau share script python yang fungsinya untuk mengirim pesan kebeberapa nomor sekaligus...
- Sebelumnya harus install dulu python,dan aplikasi ipro7 buat nulis dan eksekusiya.
- Langsung Saja:
- Misal kita mau mengirim sms ke 5 nomer teman kamu,
- -Pertama import module yang diperlukan:
- ---------------------------------------------------------------------------------------
- import appuifw
- import messaging
- ---------------------------------------------------------------------------------------
- -Menetapkan identitas pribadi kita:
- ---------------------------------------------------------------------------------------
- data=appuifw.query(u"Masukan Nama Kamu","text")
- ---------------------------------------------------------------------------------------
- -Menetapkan nomer yang akan kita kirimi sms
- ---------------------------------------------------------------------------------------
- nomor1="0812xxx"
- nomor2="0813xxx"
- nomor3="0821xxx"
- nomor4="0852xxx"
- nomor5="0853xxx"
- ---------------------------------------------------------------------------------------
- -Menetapkan isi sms:
- ---------------------------------------------------------------------------------------
- txt=">Isi teks kamu disini,< Dari:"+data
- ---------------------------------------------------------------------------------------
- -Menetapkan system pengiriman:
- ---------------------------------------------------------------------------------------
- if appuifw.query(u"Kirim Pesan Ke Nomor 5 Teman Kamu","query")==True:
- messaging.sms_send(nomor1,txt)
- messaging.sms_send(nomor2,txt)
- messaging.sms_send(nomor3,txt)
- messaging.sms_send(nomor4,txt)
- messaging.sms_send(nomor5,txt)
- ---------------------------------------------------------------------------------------
- -Membuat notifikasi jika sms sukses:
- ---------------------------------------------------------------------------------------
- appuifw.note(u'Pesan Telah Dikirim','info')
- ---------------------------------------------------------------------------------------
- -Membuat notifikasi jika sms gagal:
- ---------------------------------------------------------------------------------------
- else:
- appuifw.note(u'Pesan Gagal Dikirim','info')
- ---------------------------------------------------------------------------------------
- ==========
- 083.
- "FUNGSI MODUL APPUIFW"
- Saya mau share tentang fungsi modul appuifw dan contohnya...
- Modul berguna untuk membentuk body atau user interface aplikasi
- -import appuifw berguna untuk memanggil modul.
- ---------------------------------------------------------------------------------------
- import appuifw
- def ru(x):
- return unicode(x, "utf8")
- text_1 = "Tulis teks yang ingin ditunjukan. . !"
- ---------------------------------------------------------------------------------------
- -Fungsi pertama
- Note:
- Digunakan untuk memberi peringatan.
- ---------------------------------------------------------------------------------------
- print "Fungsi 1\n\n"
- appuifw.note(ru(text_1), "info")
- appuifw.note(ru(text_1), "conf")
- appuifw.note(ru(text_1), "error")
- ---------------------------------------------------------------------------------------
- -Fungsi Kedua
- Query: digunakan untuk bertanya
- ---------------------------------------------------------------------------------------
- print "Fungsi 2\n\n"
- text_2 = "Tulis pertanyaan disini:"
- appuifw.query(ru(text_2), "query")
- appuifw.query(ru(text_2), "text")
- appuifw.query(ru(text_2), "code")
- appuifw.query(ru(text_2), "number")
- appuifw.query(ru(text_2), "time")
- appuifw.query(ru(text_2), "date")
- appuifw.query(ru(text_2), "float")
- ---------------------------------------------------------------------------------------
- -Kita dapat mengabungkan fungsi-fungsi diatas
- Contoh dibawah ini adalah contoh untuk mendengar suara audio.say
- ---------------------------------------------------------------------------------------
- print "Fungsi 3\n\n"
- ---------------------------------------------------------------------------------------
- -import audio berguna untuk memanggil modul audio
- ---------------------------------------------------------------------------------------
- katakan = appuifw.query(ru("Katakan Apa:"), "text")
- if not katakan == None:
- tanyakan = appuifw.query(ru("Apakah anda ingin dengar apa yang dikatakan?"), "query")
- if tanyakan == True:
- audio.say(katakan)
- appuifw.note(katakan, "info")
- else:
- appuifw.note(katakan, "error")
- print "Selesai"
- ---------------------------------------------------------------------------------------
- -import messaging berguna untuk memanggil modul pengirim sms
- -Jumlah sms yang ingin dikirim
- ---------------------------------------------------------------------------------------
- sms_amount = 5
- ---------------------------------------------------------------------------------------
- -Sebagai penghitung
- ---------------------------------------------------------------------------------------
- counter = 0
- ---------------------------------------------------------------------------------------
- -Nomor target yang ingin dikirimi SMS
- ---------------------------------------------------------------------------------------
- target_number = "12345"
- ---------------------------------------------------------------------------------------
- -Isi pesan yang ingin dikirim
- ---------------------------------------------------------------------------------------
- msg_content = u"isi pesan"
- while counter < sms_amount:
- messaging.sms_send(target_number, msg_content)
- print "mengirim sms ke ", counter, " kepada ", target_number
- counter += 1
- print " selesai...."
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 084.
- "SIMPLE SCANNING APPLICATION"
- Saya mau share sebuah script untuk scanning directory...
- Script ini harus diletakan di folder python yang ada pada drive C atau E
- Kemudian masuk python scriptshell atau PED dan run script ini
- Hanya menggunakan 3 modul
- ---------------------------------------------------------------------------------------
- import appuifw
- import os, e32
- def ru(x): return unicode(x, "utf8")
- app_lock = e32.Ao_lock()
- state, running = None, False
- ---------------------------------------------------------------------------------------
- -Membuat judul aplikasi
- ---------------------------------------------------------------------------------------
- appuifw.app.title = ru("Simple Scanner")
- ---------------------------------------------------------------------------------------
- -Membuat GUI atau body aplikasi
- ---------------------------------------------------------------------------------------
- editor = appuifw.Text()
- appuifw.app.body = editor
- editor.font = ("legend", 12)
- editor.color = 0x000000
- editor.add(ru("Simple Scanner"))
- editor.add(ru("\nHanya untuk Pengembangan dan Contoh\n\n\n\n\n"))
- editor.add(ru("Author: Pythonism Symbian\nE-mail: joe4rt0n@gmail.com\n"))
- editor.add(ru("7777772e6172746f6e2d70726976617465686f6d652e636f2e6363".decode("hex_codec")))
- editor.add(ru("\n\n\nPilih Options & Scan, lalu pilih daftar drive"))
- def exit():
- global running, state
- if running == True:
- query = appuifw.query(ru("Apakah Anda ingin Stop Scanning?"), "query")
- if query == True:
- running, state = False, False
- else:
- query = appuifw.query(ru("Apakah Anda ingin keluar?"), "query")
- if query == True:
- state = False
- app_lock.signal()
- audiolist = [".mp3", ".wav", ".aac", ".amr"]
- filesis = [".sis", ".sisx"]
- images = [".png", ".jpg", ".jpeg", ".mbm"]
- audiocounter, siscounter = 0, 0
- imagecounter = 0
- def scanning_now(drive):
- >>global audiocounter, siscounter, imagecounter, state
- >>if state == None:
- >>>try:
- if os.path.isdir(drive):
- drivelist = os.listdir(drive)
- for i in drivelist:
- >>if state == None:
- e32.ao_yield()
- if os.path.isdir(drive + i):
- if (not i.endswith(os.sep)):
- i = (i + os.sep)
- editor.clear()
- editor.add(ru("Simple Scanner\n"))
- editor.add(ru("\n\nAudio File: %s\n")%(audiocounter))
- editor.add(ru("Image File: %s\n")%(imagecounter))
- editor.add(ru("Instalation File: %s\n\n\n\n")%(siscounter))
- editor.add(ru("Scanning:\n"))
- editor.add(drive + ru(i))
- scanning_now(drive + i)
- ext = os.path.splitext(drive + i)[1]
- if (ext in audiolist):
- audiocounter += 1
- elif (ext in filesis):
- siscounter += 1
- elif (ext in images):
- imagecounter += 1
- >>>except: pass
- def scan_drive():
- global audiocounter, siscounter, imagecounter, state, running
- audiocounter, siscounter, imagecounter = 0, 0, 0; running, state = True, None
- editor.clear()
- editor.add(ru("Siap Melakukan Scanning. . .\n"))
- editor.add(ru("Pilih Drive. . .\n"))
- drive = e32.drive_list()
- get = appuifw.popup_menu(drive, ru("Pilihan:"))
- editor.add(ru("Melakukan Scanning pada drive %s\\\n")%(drive[get]))
- scanning_now(drive[get] + os.sep)
- def about():
- appuifw.note(ru("Belajar dan Share aplikasi python buatanmu di www.arton-privatehome.co.cc\nJoe Arton"), "info")
- ---------------------------------------------------------------------------------------
- -Membuat fungsi tombol menu & exit
- ---------------------------------------------------------------------------------------
- appuifw.app.menu = [(ru("Scan"), scan_drive), (ru("About"), about)]
- appuifw.app.exit_key_handler = exit
- app_lock.wait()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 085.
- "APLIKASI TEKS EDITOR"
- Saya mau share sebuah script untuk mengedit sebuah teks...
- -Memangil modul aplikasi
- -Pythonism symbianism
- ---------------------------------------------------------------------------------------
- import appuifw2
- import e32
- ---------------------------------------------------------------------------------------
- Fungsi ini digunakan untuk membuka gerbang fungsi dari aplikasi, hampir semua aplikasi dimulai dengan fungsi ini
- ---------------------------------------------------------------------------------------
- app_lock = e32.Ao_lock()
- ---------------------------------------------------------------------------------------
- Memberikan fungsi konversi, yaitu perubahan string agar menjadi unicode sehingga dapat ditampilkan pada GUI
- ---------------------------------------------------------------------------------------
- def ru(x):
- return unicode(x, "utf8")
- ---------------------------------------------------------------------------------------
- Membuat fungsi body aplikasi atau aplikasi utama, yaitu body text editor
- Untuk menggunakan fungsi ini, kita akan menggunakan modul appuifw
- ---------------------------------------------------------------------------------------
- body = appuifw2.Text(skinned=True)
- appuifw2.app.body = body
- ---------------------------------------------------------------------------------------
- Membuat fungsi keluar aplikasi dengan cara membuka gerbang diatas
- ---------------------------------------------------------------------------------------
- def keluar():
- app_lock.signal()
- ---------------------------------------------------------------------------------------
- Meletakan fungsi tombol keluar, pada tombol exit, seperti gambar diatas
- ---------------------------------------------------------------------------------------
- appuifw2.app.exit_key_handler = keluar
- ---------------------------------------------------------------------------------------
- Memberikan nama pada tombol keluar
- ---------------------------------------------------------------------------------------
- appuifw2.app.exit_key_text = ru("Keluar")
- ---------------------------------------------------------------------------------------
- Memberikan nama pada tombol Menu
- ---------------------------------------------------------------------------------------
- appuifw2.app.menu_key_text = ru("Menu")
- ---------------------------------------------------------------------------------------
- Membuat menu dan submenu
- Sebelumnya, kita harus membuat fungsi, berikut ini fungsi sederhana, yaitu menampilkan nama web ini
- ---------------------------------------------------------------------------------------
- def tampilkan_web():
- appuifw.note(ru("www.arton-privatehome.co.cc"), "info")
- appuifw2.app.menu = [
- (ru("Menu A"), tampilkan_web),
- (ru("Menu B"), tampilkan_web),
- (ru("Menu C"), (
- (ru("Sub Menu 1") ,tampilkan_web),
- (ru("Sub Menu 1") ,tampilkan_web))),
- (ru("Menu D"), tampilkan_web)]
- ---------------------------------------------------------------------------------------
- -Menutup fungsi aplikasi
- ---------------------------------------------------------------------------------------
- app_lock.wait()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 086.
- "CAMERA MOTION"
- Saya mau share sebuah script camera motion...
- ---------------------------------------------------------------------------------------
- import appuifw2 as aw, e32, camera, audio
- import socket as st
- from graphics import*
- sock, debug = None, -1
- address, channel=st.bt_obex_discover()
- def bt_connect():
- global sock
- sock = st.socket(st.AF_BT,st.SOCK_STREAM)
- target = (address, 3)
- aw.note(ru("Connecting to ") + ru(str(target)), "info")
- try:
- sock.connect(target)
- sock.send("AT+GMM\r")
- aw.note(ru("\n" + sock.recv(1024)))
- except: aw.note(ru("Failed To Connect"))
- bt_connect()
- action, control_light = False, 0
- x, y, sensLeft, sensRight = 240, 235, 120, 120
- sensUp, sensDown, sensCenter=120, 120, 120
- actionUp, actionDown, actionLeft, actionRight, actionCenter = False, False, False, False, False scanPixel = Image.new((x, y))
- def redraw(rect):
- scanPixel.rectangle([(0, 0),(x, y)], 0x000000, 0xff0000)
- scanPixel.text((28, 50), u"Camera Motion", 0x000000, font=("normal", 28))
- scanPixel.line([(20,60),(220,60)], 0x0000, 2)
- scanPixel.line([(0, 65), (240, 65)], 0x0000, 2)
- scanPixel.line([(0, 70), (240, 70)], 0x0000, 2)
- scanPixel.text((20, 100), u"Press Options to Active", 0x000000, "normal")
- scanPixel.text((50, 120), u"Author: Joe Arton", 0x000000, "legend")
- scanPixel.text((30, 135), u"Release: November 2010", 0x000000, "legend")
- scanPixel.text((3, 150), u"Camera Application for Detecting Motion", 0x000000, u"Latinplain")
- canvas.blit(scanPixel)
- lock = e32.Ao_lock()
- canvas = aw.Canvas(redraw_callback = redraw, event_callback = None)
- aw.app.body = canvas
- def actionForUp():
- global actionUp
- if actionUp == 0:
- saySomething()
- elif actionUp == 1:
- playSound()
- elif actionUp == 2:
- dialNumber()
- elif actionUp == 3:
- sendMessage()
- def actionForDown():
- global actionDown
- if actionDown == 0:
- saySomething()
- elif actionDown == 1:
- playSound()
- elif actionDown == 2:
- dialNumber()
- elif actionDown == 3:
- sendMessage()
- def actionForCenter():
- global actionCenter
- if actionCenter == 0:
- saySomething()
- elif actionCenter == 1:
- playSound()
- elif actionCenter == 2:
- dialNumber()
- elif actionCenter == 3:
- sendMessage()
- def actionForLeft():
- global actionLeft
- if actionLeft == 0:
- saySomething()
- elif actionLeft == 1:
- playSound()
- elif actionLeft == 2:
- dialNumber()
- elif actionLeft == 3:
- sendMessage()
- def actionForRight():
- global actionRight
- if actionRight == 0:
- saySomething()
- elif actionRight == 1:
- playSound()
- elif actionRight == 2:
- dialNumber()
- elif actionRight == 3:
- sendMessage()
- def makeShading(im):
- im.rectangle([(4,2),(196,12)],0xff0000)
- im.rectangle([(4,138),(196,148)],0xff0000)
- im.rectangle([(4,14),(14,136)],0xff0000)
- im.rectangle([(186,14),(196,136)],0xff0000)
- im.rectangle([(60,50),(140,100)],0xff0000)
- def upPixel(im):
- global sensUp, action, actionForUp
- up = 0
- x = im.getpixel([(5,3),(197, 13)])[0]
- up = up + x[0] +x [1] + x[2]
- scanPixel.text((0, 185), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
- scanPixel.text((0, 195), u"Sensitivity: %s"%(up), 0x000000, font=("legend", 10))
- im.rectangle([(6, 4),(250-up, 10)],0xff0000, 0xff0000)
- if action =="activeUp" or action == "All":
- if up < sensUp:
- actionForUp()
- def downPixel(im):
- global sensDown, action
- down = 0
- x = im.getpixel([(5,139),(197, 149)])[0]
- down = down + x[0] +x [1] + x[2]
- scanPixel.text((0, 220), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
- scanPixel.text((0, 230), u"Sensitivity: %s"%(down), 0x000000, font=("legend", 10))
- im.rectangle([(6,140),(250-down,146)], 0xff0000, 0xff0000)
- if action =="activeDown" or action == "All":
- if down < sensDown:
- actionForDown()
- def leftPixel(im):
- global sensLeft, action
- left = 0
- x = im.getpixel([(5, 15),(15, 137)])[0]
- left = left+x[0]+x[1]+x[2]
- scanPixel.text((160, 185), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
- scanPixel.text((160, 195), u"Sensitivity: %s"%(left), 0x000000, font=("legend", 10))
- im.rectangle([(6,16),(12, 250-left)],0xff0000, 0xff0000)
- if action =="activeLeft" or action == "All":
- if left < sensLeft:
- actionForLeft()
- def rightPixel(im):
- global sensRight, action
- right = 0
- x = im.getpixel([(187, 15),(197, 137)])[0]
- right = right+x[0]+x[1]+x[2]
- scanPixel.text((160, 220), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
- scanPixel.text((160, 230), u"Sensitivity: %s"%(right), 0x000000, font=("legend", 10))
- im.rectangle([(188, 16),(194, 250-right)],0xff0000, 0xff0000)
- if action =="activeRight" or action == "All":
- if right < sensRight:
- actionForRight()
- def centerPixel(im):
- global sensCenter, action
- center = 0
- x = im.getpixel([(61, 51),(141, 101)])[0]
- center = center+x[0]+x[1]+x[2]
- scanPixel.text((80, 208), u"Pixel: [%s, %s, %s]"%(x), 0x000000, font=("legend", 10))
- scanPixel.text((80, 218), u"Sensitivity: %s"%(center), 0x000000, font=("legend", 10))
- if action =="activeCenter" or action == "All":
- if center < sensCenter:
- im.rectangle([(62,52),(138,98)],0xff0000,0xff0000)
- actionForCenter()
- def gettingPixel(im):
- makeShading(im)
- upPixel(im)
- downPixel(im)
- leftPixel(im)
- rightPixel(im)
- centerPixel(im)
- def showSensitivity(im):
- global sensUp, sensDown, sensRight
- global sensCenter, sensLeft
- scanPixel.text((105, 12), unicode(sensUp), 0x000000, font = ("legend", 11))
- scanPixel.text((105, 175), unicode(sensDown), 0x000000, font=("legend", 11))
- scanPixel.text((0, 90), unicode(sensLeft), 0x000000, font=("legend", 11))
- scanPixel.text((220, 90), unicode(sensRight), 0x000000, font=("legend", 11))
- im.text((90, 80), unicode(sensCenter), 0xffffff, font=("legend", 10))
- def showPixel(im):
- scanPixel.text((20, 175), u"Top", 0x000000, font = ("legend", 12))
- scanPixel.text((15, 209), u"Down", 0x000000, font = ("legend", 11))
- scanPixel.text((100, 195), u"Center", 0x000000, font = ("legend", 11))
- scanPixel.text((180, 175), u"Left", 0x000000, font = ("legend", 11))
- scanPixel.text((180, 209), u"Right", 0x000000, font = ("legend", 11))
- gettingPixel(im)
- showSensitivity(im)
- def cPixel(im):
- global control_light
- if control_light == 0:
- scanPixel.rectangle([(0, 0),(x, y)], 0x000000, 0xff0000)
- showPixel(im)
- scanPixel.blit(im, target=(20, 13))
- canvas.blit(scanPixel)
- saying = u"Motion Detected"
- soundPath = "e:\\Sounds\\digital\\"
- numberPhone = u"123"
- def sendMessage():
- global numberPhone
- import messaging
- messaging.sms_send(numberPhone, u"Detected")
- def setSendNumber():
- global numberPhone
- query = aw.query(u"Phone Number:","text", numberPhone)
- if not query == None:
- if aw.query(u"Number is %s. ?"%(query), "query") == True:
- numberPhone = query
- else: pass
- else: pass
- def setDialNumber():
- global numberPhone
- query = aw.query(u"Phone Number:","text", numberPhone)
- if not query == None:
- if aw.query(u"Number is %s. ?"%(query), "query") == True:
- numberPhone = query
- else: pass
- else: pass
- def dialNumber():
- global numberPhone, sock
- try:
- sock.send("audio.say(unicode(123))")
- except:
- try:
- sock.send("keypress.simulate_key(EKeySelect, EScancodeSelect)")
- except:
- import audio
- alert = audio.Sound.open("e:\\alert.aac")
- while alert.state() == 2:
- e32.ao_sleep(0.1)
- alert.close()
- def setDialNumber():
- global numberPhone
- query = aw.query(u"Phone Number:","text", numberPhone)
- if not query == None:
- if aw.query(u"Number is %s. ?"%(query), "query") == True:
- numberPhone = query
- else: pass
- else: pass
- def playSound():
- global soundPath
- alert = audio.Sound.open(soundPath)
- alert.play()
- while alert.state()==2: # playing
- e32.ao_sleep(0.1)
- alert.close()
- def setPlaySound():
- global soundPath
- u = lambda x: x.decode("utf8")
- songs = map(u, os.listdir(soundPath))
- selection = aw.selection_list(songs, 1)
- if not selection == None:
- if aw.query(u"Set %s as Sound?"%(selection), "query") == True:
- soundPath = soundPath + songs[selection]
- else: pass
- else: pass
- def saySomething():
- global saying
- try: audio.say(saying)
- except: aw.note(u"Failed", "error")
- def setSaySomething():
- global saying
- query=aw.query(u"Saying:","text",saying)
- if not query == None:
- if aw.query(u"Saying %s"%(query), "query") == True:
- saying = query
- else: pass
- def allAction():
- global actionUp, actionDown, actionRight
- global actionLeft, actionCenter
- actions = [u"SaySomething", u"PlaySound", u"DialNumber", u"SendMessage"]
- select = aw.selection_list(actions, 1)
- actionUp, actionDown, actionRight, actionLeft, actionCenter = select, select, select, select, select
- def setAction():
- >>global action
- >>asking = aw.popup_menu([u"Set Action for All", u"Set Action for Corner"])
- >>if asking == 0:
- >>if aw.query(u"Set Action for All. . ?", "query") == True:
- >>allAction()
- >>action = "All"
- >>else: action = False
- >>elif asking == 1:
- >>setActionCorner()
- def selectAction(popup):
- global actionUp, actionDown, actionRight
- global actionLeft, actionCenter
- actions = [u"SaySomething", u"PlaySound", u"DialNumber", u"SendMessage"]
- select = aw.selection_list(actions, 1)
- if select == 0:
- setSaySomething()
- elif select == 1:
- setPlaySound()
- elif select == 2:
- setDialNumber()
- elif select == 3:
- setSendMessage()
- if popup == 0 :
- actionUp = select
- elif popup == 1 :
- actionDown = select
- elif popup == 2 :
- actionCenter = select
- elif popup == 3 :
- actionLeft = select
- elif popup == 4 :
- actionRight = select
- aw.note(u"Sukses")
- def setActionCorner():
- global action
- popup = aw.popup_menu([u"Top", u"Bottom", u"Center", u"Left", u"Right"], u"Corner Type:")
- if not popup == None:
- >>if popup == 0:
- if aw.query(u"Set Action for Top. . ?", "query") == True:
- action = "activeUp"
- selectAction(popup)
- else: action = False
- >>elif popup == 1:
- if aw.query(u"Set Action for Bottom. . ?", "query") == True:
- action = "activeDown"
- selectAction(popup)
- else: action = False
- >>elif popup == 2:
- if aw.query(u"Set Action for Center. . ?", "query") == True:
- action = "activeCenter"
- selectAction(popup)
- else: action = False
- >>elif popup == 3:
- if aw.query(u"Set Action for Left. . ?", "query") == True:
- action = "activeLeft"
- selectAction(popup)
- else: action = False
- >>elif popup == 4:
- if aw.query(u"Set Action for Right. . ?", "query") == True:
- action = "activeRight"
- selectAction(popup)
- else: action = False
- def setSensitivity():
- >>global sensLeft, sensRight, sensUp
- >>global sensDown, sensCenter
- >>ask = aw.popup_menu([u"Set All", u"Set a Corner"])
- >>if ask == 0:
- >>all = aw.query(u"Sensitivity:", "number", 120)
- >>if aw.query(u"Sensitivity is %s?"%(all),"query") == True:
- >>sensLeft, sensRight, sensUp=all, all, all
- >>sensDown, sensCenter = all, all
- >>aw.note(u"Success", "conf")
- >>else: return all
- >>elif ask == 1:
- popup = aw.popup_menu([u"Top", u"Bottom", u"Center", u"Left", u"Right"], u"Corner Type:")
- if popup == 0:
- sensUp = aw.query(u"Sensitivity:", "number",sensUp)
- elif popup == 1:
- sensDown = aw.query(u"Sensitivity:", "number", sensDown)
- elif popup == 2:
- sensCenter = aw.query(u"Sensitivity:", "number", sensCenter)
- elif popup == 3:
- sensLeft = aw.query(u"Sensitivity:", "number", sensLeft)
- elif popup == 4:
- sensRight = aw.query(u"Sensitivity:", "number", sensRight)
- aw.note(u"Success", "conf")
- def start_finder():
- global control_light
- control_light = 0
- camera.start_finder(cPixel, size=(200, 150))
- def stop_finder():
- global control_light
- control_light = 1
- camera.stop_finder()
- camera.release()
- aw.note(u"Finder stop")
- information = u"Camera Motion is Application based on Camera detection. It needs python 1.45 or above.You Can Set Camera Motion to Adjust Sensitivity and Action by Pressing Options. Camera Motion Can be Used to detect Thing and People.\n\t--Thank You For Using--"
- def about():
- import globalui as gl
- info = u"Name\t\t: Camera Motion\n"
- info += u"Version\t: 1.0.0\n"
- info += u"Release\t: 17 November 2010\n"
- info += u"Author\t\t: Joe Arton\n"
- info += u"Email\t\t: joe_arton@yahoo.\n\t\t com"
- showAbout = gl.global_msg_query(info, u"Information")
- if showAbout == True:
- showHelp = gl.global_msg_query(information, u"Information")
- def quit():
- >>if aw.query(u"Stop and Exit from Camera Motion Now. . ?","query") == True:
- stop_finder()
- lock.signal()
- aw.note(u"Go out", "conf")
- >>else: pass
- aw.app.menu = [
- (u"Finder", (
- (u"Start Finder", start_finder),
- (u"Stop Finder", stop_finder))),
- (u"Setting", (
- (u"Set Sensibility", setSensitivity),
- (u"Set Action", setAction))),
- (u"About", about),
- (u"Exit", quit)
- >]
- aw.app.exit_key_text = u"Stop & Exit"
- aw.app.exit_key_handler = quit
- lock.wait()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 087.
- "INDICATOR BATTERY HP"
- Saya mau share sebuah script untuk indicator battery HP...
- ---------------------------------------------------------------------------------------
- import indicators, e32
- ---------------------------------------------------------------------------------------
- -Level baterai menjadi 5
- ---------------------------------------------------------------------------------------
- print "menset level baterai menjadi 5"
- indicators.set_battery(5)
- e32.ao_sleep(2)
- ---------------------------------------------------------------------------------------
- -Level signal menjadi 5
- ---------------------------------------------------------------------------------------
- print "menset level sinyal menjadi 5"
- indicators.set_signal(5)
- e32.ao_sleep(2)
- print "Mulai men-charge baterai"
- indicators.start_charging()
- e32.ao_sleep(3)
- print "Menghentikan men-charge baterai"
- indicators.stop_charging()
- ---------------------------------------------------------------------------------------
- ==========
- 088.
- "CARA MEREKAM AUDIO"
- Saya mau share cara merekam audio menggunakan pys60...
- ---------------------------------------------------------------------------------------
- import appuifw, audio, os
- MENU = [u"Play sound", u"Record sound", u"Delete sound"]
- SOUNDFILE = u"E:\\sound.wav"
- sound = None
- while True:
- index = appuifw.popup_menu(MENU, u"Select operation")
- if sound:
- sound.stop()
- sound = audio.Sound.open(SOUNDFILE)
- if index == 0:
- sound.play()
- elif index == 1:
- sound.record()
- appuifw.query(u"Press OK to stop recording", "query")
- sound.stop()
- elif index == 2:
- os.remove(SOUNDFILE)
- else:
- break
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganta menggunakan spasi.
- ==========
- 089.
- "MEMUTAR FILE MP3"
- Saya mau share sebuah script untuk play file mp3...
- ---------------------------------------------------------------------------------------
- import audio
- sound = audio.Sound.open("E:\\Sounds\\mysound.mp3")
- def playMP3():
- >sound.play()
- >print "PlayMP3 returns.."
- playMP3()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 090.
- "TEKS BICARA"
- Saya mau share sebuah script untuk merubah teks menjadi audio...
- ---------------------------------------------------------------------------------------
- import appuifw, audio
- text = appuifw.query(u"Type a word:", "text")
- audio.say(text)
- ---------------------------------------------------------------------------------------
- ==========
- 091.
- "CARA MENEMUKAN KATA di INBOX"
- Saya mau share sebuah script yang dapat menemukan kata diinbox secara otomatis...
- ---------------------------------------------------------------------------------------
- import inbox, appuifw
- box = inbox.Inbox()
- query = appuifw.query(u"Search for:", "text").lower()
- hits = []
- ids = []
- for sms_id in box.sms_messages():
- >>msg = box.content(sms_id).lower()
- >>if msg.find(query) != -1:
- >>>hits.append(msg[:25])
- >>>ids.append(sms_id)
- index = appuifw.selection_list(hits, 1)
- if index >= 0:
- appuifw.note(box.content(ids[index]))
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 092.
- "MENGAKSES INBOX"
- Saya mau share sebuah script untuk mengakses inbox...
- ---------------------------------------------------------------------------------------
- import inbox, appuifw
- box = inbox.Inbox()
- for sms_id in box.sms_messages()[:5]:
- >>msg = box.content(sms_id)
- >>appuifw.note(msg)
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 093.
- "LIST SELEKSI"
- Saya mau share sebuah script untuk list seleksi...
- ---------------------------------------------------------------------------------------
- import appuifw
- colors = [u"red", u"green", u"blue", u"brown"]
- selections = appuifw.multi_selection_list(colors, 'checkbox', 1)
- print "Checkbox selected:", selections
- selections = appuifw.multi_selection_list(colors, 'checkmark', 1)
- print "Checkmark selected:", selections
- ---------------------------------------------------------------------------------------
- ==========
- 094.
- "TWO DIALOGS"
- Saya mau share sebuah script two dialogs...
- ---------------------------------------------------------------------------------------
- import appuifw
- word = appuifw.query(u"Type your name", "text")
- appuifw.note(u"Greetings from " + str(word))
- ---------------------------------------------------------------------------------------
- ==========
- 095.
- "MEMASUKKAN NAMA"
- Saya mau share sebuah script untuk memasukkan nama...
- ---------------------------------------------------------------------------------------
- import appuifw
- names = appuifw.multi_query(u"First name:", u" Last name:")
- if names:
- first, last = names
- appuifw.note(u"Your full name is: " + first + " " + last)
- else:
- appuifw.note(u"Cancel!")
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 096.
- "CARA MEREKAM AUDIO"
- Saya mau share sebuah script untuk merekam audio...
- ---------------------------------------------------------------------------------------
- import appuifw, audio, os
- MENU = [u"Play sound", u"Record sound", u"Delete sound"]
- SOUNDFILE = u"E:\\sound.wav"
- sound = None
- while True:
- index = appuifw.popup_menu(MENU, u"Select operation")
- if sound:
- sound.stop()
- sound = audio.Sound.open(SOUNDFILE)
- if index == 0:
- sound.play()
- elif index == 1:
- sound.record()
- appuifw.query(u"Press OK to stop recording", "query")
- sound.stop()
- elif index == 2:
- os.remove(SOUNDFILE)
- else:
- break
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 097.
- "MEMBUAT SELECTION LIST"
- Saya mau share sebuah script untuk membuat selection list...
- ---------------------------------------------------------------------------------------
- import appuifw
- colors = [u"red", u"green", u"blue", u"brown"]
- index = appuifw.selection_list(colors, 1)
- if index == 2:
- print "blue is correct!"
- else:
- print "Bzz! " + colors[index] + " is not correct"
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 098.
- "MEMBUAT POPUP MENU"
- Saya mau share sebuah script untuk membuat popup menu...
- ---------------------------------------------------------------------------------------
- import appuifw
- choices = [u"Symbian", u"PyS60", u"MobileArt"]
- index = appuifw.popup_menu(choices, u"Select:")
- if index == 0 :
- appuifw.note(u"Symbian, aha")
- elif index == 1 :
- appuifw.note(u"PyS60 - yeah")
- elif index == 2 :
- appuifw.note(u"I love MobileArt")
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 099.
- "MEMBUAT APP BERKODE"
- Saya mau share cara membuat kode pada sebuah aplikasi...
- -Module yang dibutuhkan
- ---------------------------------------------------------------------------------------
- import appuifw
- import e32
- import os
- import globalui
- import sysinfo
- ---------------------------------------------------------------------------------------
- -Fungsi define untuk dipanggil ketika aplikasi diberikan perintah keluar
- ---------------------------------------------------------------------------------------
- def keluar():
- x = globalui.global_query(u'Anda Yakin?')
- if x == 1 :
- appuifw.note(u'http://fnugraha8.mywapblog.com', 'info')
- appuifw.note(u'Terima Kasih', 'conf')
- os.abort()
- ---------------------------------------------------------------------------------------
- -Fungsi define untuk membuat kode kodem dalam persamaan sama dengan imei yang akan dimasukkan berupa angka
- -Imei=sysinfo.imei() merupakan perintah untuk membaca imei pada handphone
- -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.
- -Kodekem merupakan persamaan dari fungsi penambah nilai dari fungsi kodek tadi misal hasil dari angka didapatkan dari 56284+1990 jadi nanti hasilnya adalah kodenya
- -Fungsi if dan else mungkin udah pada tau ea, kan ada dalam ilmu matematika
- ---------------------------------------------------------------------------------------
- def op():
- kodem = appuifw.query(u'Masukkan Kodenya', 'text')
- imei = sysinfo.imei()
- kodek = ((((imei[2] + imei[5]) + imei[12]) + imei[9]) + imei[3])
- kodekem = (int(kodek) + 1990)
- kode = str(kodekem)
- kodez = kodem
- if kode == kodez :
- appuifw.note(u'Kode Benar', 'conf')
- appuifw.note(u'Terima Kasih', 'conf')
- buka()
- else :
- appuifw.note(u'Kode Salah!', 'error')
- os.abort()
- ---------------------------------------------------------------------------------------
- -Fungsi ini untuk pembuka sebelum masuk kemenu utama
- ---------------------------------------------------------------------------------------
- def buka():
- R = appuifw.Text()
- appuifw.app.body = R
- R.style = appuifw.STYLE_BOLD
- y = u'http://fnugraha8.mywapblog.com'
- R.color = 255
- for abc in range(len(y)):
- R.add(y[abc])
- e32.ao_sleep(0.0)
- R.color = 255
- global R
- ---------------------------------------------------------------------------------------
- -Fungsi menu utama
- ---------------------------------------------------------------------------------------
- def menu():
- appuifw.app.menu = [(u'Test',buka)]
- ---------------------------------------------------------------------------------------
- -Fungsi keluar
- ---------------------------------------------------------------------------------------
- appuifw.app.exit_key_handler = keluar
- ---------------------------------------------------------------------------------------
- -Perintah untuk memanggil pembuka dan menu utama
- ---------------------------------------------------------------------------------------
- op()
- menu()
- ---------------------------------------------------------------------------------------
- -Perintah untuk mengunci script
- ---------------------------------------------------------------------------------------
- e32.Ao_lock().wait()
- ---------------------------------------------------------------------------------------
- Note:
- Tanda > diganti menggunakan spasi.
- ==========
- 100.
- "MEMBUAT KEYGEN"
- Saya mau share sebuah script untuk membuat keygen...
- ---------------------------------------------------------------------------------------
- import appuifw
- import e32
- import os
- import sysinfo
- def key():
- >>imei=appuifw.query(u'imei','text')
- >>i=len(imei)
- >>if i < 15 :
- appuifw.note(u'Harus 15 digit angka...!', 'error')
- key()
- >>>if i > 15 :
- appuifw.note(u'Harus 15 digit angka....!', 'error')
- key()
- >>kodek=imei[2]+imei[5]+imei[12]+imei[9]+imei[3]
- >>kodek=int(kodek)+1990
- >>kode=str(kodek)
- >>appuifw.query(u'kodenya: ','text',(u''+kode))
- >>key()
- key()
Add Comment
Please, Sign In to add comment