Foreword
Good day, habrayuzyra!
It so happens that most of the time I am away from my PC, so most of its functions are assigned to the device, which is always with me - on a Symbian 9.4-based smartphone. Along with multimedia functions, it is very often necessary for me to make text notes, outline articles for a blog, and it happens that I have to work with (x) html and CSS. And if Nokia 5530XM copes with multimedia functions with a bang, then working with text is complicated by the lack of convenient software for me - my picky temper does not recognize those software products that I had the opportunity to find on the Internet and test it on my device. I needed the simplest notebook, while I met text editors, burdened with unnecessary functions for me. And when I remembered that the rescue of the drowning was the work of the drowning themselves, then I realized that I would have to satisfy my own needs.
Lifebuoy
To be honest, I don’t have a direct relationship to programming, because my hobby is design for mobile sites, but at the same time programming is not alien to me - during my studies at the university I had a chance to get acquainted (quite successfully) with classics - with Pascal, with C / C ++ and with Delphi, therefore, having passed the stage of sad sighs of hopelessness, I began to choose a language for development.
There was no particular choice:
In order to write comfortably in Qt / C ++, you need a lot of things to download and install, which was too lazy for me.
mShell is a paskalep-like undisclosed language. After installing the interpreter, it is necessary to carry out a free registration procedure via SMS, which I did not want.
But Python interested me - I had never come across it before and it was interesting for me to get acquainted with something new in the field of programming.
Getting ready to work
So, the choice fell on Python. Now, in order to start writing our first program, we need to make a smartphone friend with this very Python, for which I downloaded and installed Python 1.4.5, and in addition to it a set of modules megaPyModulePack 2.0.1 and PythonScriptShell.
For writing programs, a text editor is required - gritting my teeth had to install the LightText software that I hated to my smartphone.
Well, to move written scripts to the Python folder, I chose the good old X-plore file manager.
All downloaded, all installed, everything works - Python meets us with its console:

')
What do we want?
What do we want from the program? The smallest is the ability to create and save the text entered in UTF-8. From here we draw conclusions about the type of program - a large input field, a menu of a couple of items (New document, Save, Info) and an exit button. Everything.
Knowledge is power
And without this power, we would have nothing to do here. I drew strength from four sources:
-
Book Pankaj Nathani and Bogdan Galiceanu “Python on Symbian”- Articles by Albert Gazetdinov on the website mobi.ru
-
Python 2.6 tutorial on wikibuks- Forum allnokia.ru
Right off the bat
I will not write about how I read background information and what emotions this process has caused in me - yet this is not a novel, so I will immediately turn to the process of creation.
To begin with, we will help the program to make friends with the great and powerful Russian language:
ru=lambda x: x.decode('utf-8')
Now, in order for the program not to upset us with unknown characters, it will be enough to use the ru () function, an example of which you will see very soon.
The next step is to connect the modules we need:
- appuifw (from the application user interface framework) - with the help of this module we will create a simple interface of our program.
- os - work with files, folders and their paths.
- e32 - working with Symbian service functions
So, we connect:
import appuifw, os, e32
Now it would be quite logical to call our future program somehow. Since it does not differ by mega-functional, we will give the corresponding name to it - P (rimitive) Pad.
Let the program name it:
appuifw.app.title = u"PPad"
Since then, the program has found its name. It is displayed at the top of the window instead of the words “Python”. But we will not see it and now I will explain why: I have already said that in this notebook I want to see a large input field. The appuifw module allows us to choose the program body size from three possible:
- normal - the program body will take place between the bottom Functions / Exit buttons and the top of the screen, in which the Program name and signal and battery level indicators are displayed.
- large - only the program body and the Options / Exit buttons will be displayed on the screen.
- full - the program body will occupy the entire screen.
I thought that the most suitable option for us is the size of large:
appuifw.app.screen = "large"
When we have decided on the screen size, I propose to take another step towards creating a notepad - to define the body of the document as a Text object, so that we can enter / output / edit text:
appuifw.app.body = t = appuifw.Text()
Through the variable t we will be able to refer to this object for the entered text and some other requests, for example, with a request to change the text color. By default, the text color is green, which does not satisfy me - with this color I am not very comfortable working with text, so I would prefer green to classic black:
t.color = 0x000000
When you start the program, we will be greeted with an empty text field. Let's make a little greeting there:
t.add(ru(" PPad - ."))
In this example, you can see what the ru () function was created for in the very first line of the program and how it is used.
Now, perhaps, it remains to bring to mind the program menu. In the screenshot you can see two keys: “Functions” (appuifw.app.menu) and “Exit” (appuifw.app.exit_key_handler). When you click on "Exit", the program will instantly close, which is not entirely correct, because with a random press, we can lose all entered data, which cannot be allowed. So let's start fine-tuning with it - let's assign a function to it (let's call it quit), which would ask the user permission:
appuifw.app.exit_key_handler = quit
Well, let's write the function itself:
def quit(): if appuifw.query(ru(" ?"), "query") == 1: appuifw.app.set_exit()
appuifw.query (“Question to user”, “type”) is a window for entering data. There are 7 types - text (for entering text), code (for entering a password), number (for entering a number), float (for entering a real number), date (for entering a date), time (for entering a time), and query ( to display a question with “Ok” or “Cancel” answer options). In our case, we ask if the user wants to exit and if the user really wants, then he clicks “Ok”, to which the function returns 1 and we strongly ask the program to leave us.
After we solved the issue with the exit from the program, it’s time to “brush” the “Functions” key, to which we will assign a menu. Our menu will consist of three points - New / Clear, Save to UTF-8 and Info. Each item is set as a tuple (“Item name”, function performed). Let's create our menu:
appuifw.app.menu = [(ru("/"), ClearDoc), (ru(" UTF-8"), SaveDoc), (ru(""), AboutSoft)]
Now we have to write three functions - ClearDoc, SaveDoc and AboutSoft. Let's go from simple to complex, which means we start with the AboutSoft function:
def AboutSoft(): appuifw.note(ru(" :\nEvil_Penguin \nJOIN_ME "), "info")
The appuifw.note function displays a window with text for a few seconds, which we wanted to see in this function.
The function of creating a new document is too simple to ugliness - all that is required is to clear the screen. This will help us the very variable t:
def ClearDoc(): if appuifw.query(ru(" ?"), "query") == 1: t.clear() t.set_pos(0)
We have already met with the appuifw.query function - with its help we again ask the user if he has the will to create a new document, and if there is one, we clear the field (t.clear ()) and set the cursor to the initial position ( t.set_pos (0)).
The last function remains - the function of saving the document. The function is not complicated, but we will season it with several conditions to make it more interesting.
So, what is the function algorithm?
1. We request the user name for the saved file
2. Check if the file is in the memory of the smartphone
3. If there is no such file, then we boldly write everything to the file.
4. If the file exists, then we ask the user whether to replace the file or not. If the user chooses to replace the file, then, accordingly, we write everything into the file, otherwise we notify that the file has not been saved.
5. If at the request (p.1) the user did not enter a name, but clicked "Cancel", then we notify the user that the file was not saved.
Here is how the function looks live:
def SaveDoc(): filename = appuifw.query(ru(" "), "text") if filename: fullpath = str(filename) + ".txt" fullpath = "c:\\" + fullpath if os.path.exists(fullpath) == 0: filewrite = open(fullpath, 'w') content = t.get().replace(u"\u2029", u"\r\n") encontent = content.encode("UTF-8") filewrite.writelines(encontent) filewrite.close() appuifw.note(ru(" " + fullpath + " !"), "conf") elif os.path.exists(fullpath) == 1: rewritefile = appuifw.query(ru(" ! ?"), "query") if rewritefile == 1: filewrite = open(fullpath, 'w') content = t.get().replace(u"\u2029", u"\r\n") encontent = content.encode("UTF-8") filewrite.writelines(encontent) filewrite.close() appuifw.note(ru(" " + fullpath + " !"), "conf") else: appuifw.note(ru(" !"), "error") else: appuifw.note(ru(" !"), "error")
When writing the function of saving text to a file, I had one problem - the contents were written in one line, and in those places where there should have been a line break, there was a small square. I connected all my hopes in solving this problem with the replacement in the text \ n by \ r \ n before recording, but my hopes were not justified. And I don’t know what I would do if a good person from the forum dimonvideo.ru with the name JOIN_ME didn’t send me a solution to the troubles, which was to replace u "\ u2029" with u "\ r \ n".
Remained the final touch:
lock = e32.Ao_lock() os.abort = lock.signal lock.wait()
This design will help us to ensure that the application does not close immediately after launch.
Well, and perhaps all at the moment.
Summing up
What does our program look like in the long run?
Like thisAnd what does our program look like on a smartphone?
Like this:

Goals
What I wanted: write a simple notebook directly from your smartphone.
What are the goals of this article: to help the newcomers, like me, to get to know some moments in practice?
At last
What next? It would seem that the mission is complete. But no! “Appetite comes with eating,” as we all know. The feeling that you have created something you really need is indescribable. Even if it is something insignificant. Appetite is kindled, there are ideas - it means to be a continuation of this article, because the humble PPad.py will have to become PPad.sis
with whistles and perfections with preference and harlots. And I hope that my optimism from today's bright expectations tomorrow will turn into a fact.
Thanks for attention.