Skip to content

Commit edd678c

Browse files
committed
Add howtostart and helloworld document
1 parent d1f9b49 commit edd678c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1280
-86
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
QPython Getting started
2-
=============
2+
==========================
33
How to start quickly ? Just follow the following steps:
44

5-
* `QPython: How To Start <http://wiki.qpython.org/doc/how-to-start>`_
6-
* `QPython - Quick Start <http://wiki.qpython.org/doc/quick-start>`_
7-
* `Writing "Hello World" <http://wiki.qpython.org/doc/hello-world>`_
5+
.. toctree::
6+
:maxdepth: 2
7+
8+
guide_howtostart
9+
guide_helloworld
810

911

1012
Programming Guide
11-
===================
13+
========================
1214

13-
If you are able to program, you want to know more about how to complex programming through qpython, just follow these steps:
15+
If you you want to know more about how to program through qpython, just follow these steps:
1416

1517

1618
.. toctree::
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Writing "Hello World"
2+
========================
3+
4+
5+
Hello world
6+
----------------
7+
.. image:: ../_static/guide_helloworld_pic1.png
8+
:alt: hello world
9+
10+
Well, after you became a bit more familiar with QPython, let's create our first program in QPython. Obviously, it will be `helloworld.py`. ;)
11+
12+
Start QPython, open editor and enter the following code:
13+
14+
::
15+
16+
import androidhelper
17+
droid = androidhelper.Android()
18+
droid.makeToast('Hello, Username!')
19+
20+
No wonder, it's just similar to any other hello-world program. When executed, it just shows pop-up message on the screen (see screenshot on the top). Anyway, it's a good example of QPython program.
21+
22+
SL4A library
23+
------------
24+
25+
It begins with *import androidhelper* — the most useful module in QPython, which encapsulates almost all interface with Android, available in Python. Any script developed in QPython starts with this statement (at least if it claims to communicate with user). Read more about Python library `here <http://docs.python.org/2.7/library/intro.html>`_ and import statement `here <http://docs.python.org/2.7/reference/simple_stmts.html#import>`_
26+
27+
By the way, if you're going to make your script compatible with SL4A, you should replace the first line with the following code (and use `android` instead `androidhelper` further in the program):
28+
29+
::
30+
31+
try:
32+
import androidhelper as android
33+
except ImportError:
34+
import android
35+
36+
Ok, next we're creating an object `droid` (actually a class), it is necessary to call RPC functions in order to communicate with Android.
37+
38+
And the last line of our code calls such function, `droid.makeToast()`, which shows a small pop-up message (a "toast") on the screen.
39+
40+
Well, let's add some more functionality. Let it ask the user name and greet them.
41+
42+
More samples
43+
---------------
44+
We can display a simple dialog box with the title, prompt, edit field and buttons **Ok** and **Cancel** using `dialogGetInput` call. Replace the last line of your code and save it as `hello1.py`:
45+
46+
::
47+
48+
import androidhelper
49+
droid = androidhelper.Android()
50+
respond = droid.dialogGetInput("Hello", "What is your name?")
51+
52+
Well, I think it should return any respond, any user reaction. That's why I wrote `respond = ...`. But what the call actually returns? Let's check. Just add `print` statement after the last line:
53+
54+
::
55+
56+
import androidhelper
57+
droid = androidhelper.Android()
58+
respond = droid.dialogGetInput("Hello", "What is your name?")
59+
print respond
60+
61+
Then save and run it...
62+
63+
Oops! Nothing printed? Don't worry. Just pull notification bar and you will see "QPython Program Output: hello1.py" — tap it!
64+
65+
66+
As you can see, `droid.dialogGetInput()` returns a JSON object with three fields. We need only one — `result` which contains an actual input from user.
67+
68+
Let's add script's reaction:
69+
70+
::
71+
72+
import androidhelper
73+
droid = androidhelper.Android()
74+
respond = droid.dialogGetInput("Hello", "What is your name?")
75+
print respond
76+
message = 'Hello, %s!' % respond.result
77+
droid.makeToast(message)
78+
79+
Last two lines (1) format the message and (2) show the message to the user in the toast. See `Python docs <http://docs.python.org/2.7/tutorial/inputoutput.html?highlight=format%20operator#old-string-formatting>`_ if you still don't know what `%` means.
80+
81+
Wow! It works! ;)
82+
83+
Now I'm going to add a bit of logic there. Think: what happen if the user clicks **Cancel** button, or clicks **Ok** leaving the input field blank?
84+
85+
You can play with the program checking what contains `respond` variable in every case.
86+
87+
First of all, I want to put text entered by user to a separate variable: `name = respond.result`. Then I'm going to check it, and if it contains any real text, it will be considered as a name and will be used in greeting. Otherwise another message will be shown. Replace fifth line `message = 'Hello, %s!' % respond.result` with the following code:
88+
89+
::
90+
91+
name = respond.result
92+
if name:
93+
message = 'Hello, %s!' % name
94+
else:
95+
message = "Hey! And you're not very polite, %Username%!"
96+
97+
Use **<** and **>** buttons on the toolbar to indent/unindent lines in if-statement (or just use space/backspace keys). You can read more about indentation in Python `here <http://docs.python.org/2.7/tutorial/introduction.html?highlight=indent#first-steps-towards-programming>`_; if-statement described `here <http://docs.python.org/2.7/tutorial/controlflow.html#if-statements>`_.
98+
99+
First of all, we put user input to the variable `name`. Then we check does `name` contain anything? In case the user left the line blank and clicked **Ok**, the return value is empty string `''`. In case of **Cancel** button pressed, the return value is `None`. Both are treated as false in if-statement. So, only if `name` contans anything meaninful, then-statement is executed and greeting "Hello, ...!" shown. In case of empty input the user will see "Hey! And you're not very polite, %Username%!" message.
100+
101+
Ok, here is the whole program:
102+
103+
::
104+
105+
import androidhelper
106+
droid = androidhelper.Android()
107+
respond = droid.dialogGetInput("Hello", "What is your name?")
108+
print respond
109+
name = respond.result
110+
if name:
111+
message = 'Hello, %s!' % name
112+
else:
113+
message = "Hey! And you're not very polite, %Username%!"
114+
droid.makeToast(message)
115+
116+
117+
`Thanks dmych offer the first draft in his blog <http://onetimeblog.logdown.com/posts/2014/01/23/first-program-in-qpython>`_
118+
119+
120+
121+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
QPython: How To Start
2+
========================
3+
Now, I will introduce the QPython's features through it's interfaces.
4+
5+
1. Dashboard
6+
------------------
7+
8+
.. image:: ../_static/guide_howtostart_pic1.png
9+
:alt: QPython start
10+
11+
12+
After you installed QPython, start it in the usual way by tapping its icon in the menu. Screenshot on the top of this post shows what you should see when QPython just started.
13+
14+
**Start button**
15+
16+
By tapping the big button with Python logo in the center of the screen you can
17+
18+
**Launch your local script or project**
19+
20+
*Get script from QR code* (funny brand new way to share and distribute your code, you can create QRCode through `QPython's QRCode generator <http://qpython.com/#qrcode>`_
21+
22+
Now you can install many 3rd libaries ( pure python libraries mainly ) through pip_console.py script.
23+
24+
If you want QPython to run some script of project when you click the start button, you can make it by setting default program in setting activity.
25+
26+
27+
**Developer kit dashboard**
28+
29+
If you swipe to the left instead of tapping, you will see another (second) main screen of QPython *(Pic. 2)*. As for me, it is much more useful and comfortable for developer.
30+
31+
.. image:: ../_static/guide_howtostart_pic2.png
32+
:alt: QPython develop dashboard
33+
34+
35+
Tools available here:
36+
37+
* **Console** — yes, it's regular Python console, feel free to comunicate with interpreter directly
38+
* **Editor** — QPython has a nice text editor integrated with the rest, you can write code and run it without leaving the application
39+
* **My QPython** — here you can find your scripts and projects
40+
* **System** — maintain libraries and components: install and uninstall them
41+
* **Package Index** opens the page `QPyPI <http://qpypi.qpython.org/>`_ in browser allowing to install packages listed there
42+
* **Community** leads to `QPython.org <http://qpython.org/>`_ page. Feel free to join or ask&answer questions in the QPython community.
43+
44+
By long clicking on the console or editor, you have chance to create the shortcut on desktop which allow you enter console or editor directly.
45+
46+
Next, let's see the console and the editor.
47+
48+
2. Console and editor
49+
-------------------------
50+
51+
.. image:: ../_static/guide_howtostart_pic3.png
52+
:alt: QPython console
53+
54+
55+
As I said before, there is an ordinary Python console. Many people usually use it to explore objects' properties, consult about syntax and test their ideas. You can type your commands directly and Python interpreter will execute them. You can open additional consoles by tapping the plus button (1) and usedrop-down list on the upper left corner to switch between consoles (2). To close the console just tap the close button (3).
56+
57+
.. image:: ../_static/guide_howtostart_pic4.png
58+
:alt: QPython notification
59+
60+
61+
Please note, there will be notification in the notification bar unless you explicitly close the console and you always can reach the open console by tapping the notification.
62+
63+
64+
65+
.. image:: ../_static/guide_howtostart_pic5.png
66+
:alt: QPython editor
67+
68+
69+
The editor allows you obviously (hello Cap!) enter and modify text. Here you can develop your scripts, save them and execute. The editor supports Python syntax highlighting and shows line numbers (there is no ability to go to the line by number though). *(above picture)*
70+
71+
When typing, you can easily control indentation level (which is critical for Python code) using two buttons on the toolbar (1). Next buttons on the toolbar are **Save** and **Save As** (2), then goes **Run** (3), **Undo**, **Search**, **Recent Files** and **Settings** buttons. Also there are two buttons on the top: **Open** and **New** (5).
72+
73+
When saving, don't forget to add `.py` estension to the file name since the editor don't do it for you.
74+
75+
3. Programs
76+
--------------------
77+
You can find the scripts or projects in My QPython. My QPython contains the scripts and Projects.
78+
79+
By long clicking on script or project, you have chance to create the shortcut for the script or project. Once you have created the shortcuts on desktop, you can directly run the script or project from desktop.
80+
81+
82+
**Scripts**
83+
Scripts : A single script. The scripts are in the /sdcard/com.hipipal.qpyplus/scripts directory.
84+
If you want your script could be found in My QPython, please upload it to this directory.
85+
86+
When you click the script, you can choose the following actions:
87+
88+
- Run : Run the script
89+
- Open : Edit the script with built-in editor
90+
- Rename : Rename the script
91+
- Delete : Delete the script
92+
93+
**Projects**
94+
Projects : A directory which should contain the main.py as the project's default launch script, and you can put other dependency 3rd libraries or resources in the same directory, if you want your project could be found in My QPython, please upload them into this directory.
95+
96+
When you click on the project, you can choose the following actions:
97+
98+
- Run : run the project
99+
- Open : use it to explore project's resources
100+
- Rename : Rename the project
101+
- Delete : Delete the project
102+
103+
4. Libraries
104+
--------------
105+
106+
By installing 3rd libraries, you can extend your qpython's programming ability quickly. There are some ways to install libraries.
107+
108+
**QPypi**
109+
110+
You can install some pre-built libraries from QPypi, like numpy etc.
111+
112+
**Pip console**
113+
114+
You can install most pure python libraries through pip console.
115+
116+
117+
Besides the two ways above, you could copy libraries into the /sdcard/qpython/lib/python2.7/site-packages in your device.
118+
119+
120+
*Notice:*
121+
Some libraries mixed with c/c++ files could not be install through pip console for the android lacks the compiler environment, you could ask help from qpython developer team.
122+
123+
124+
5. Community
125+
--------------
126+
It will redirect to the QPython.org, including somthe source of this documentation, and there are some qpython user communities' link, many questions of qpython usage or programming could be asked in the community.
127+
128+
129+
130+
131+
`Thanks dmych offer the first draft in his blog <http://onetimeblog.logdown.com/posts/2014/01/22/qpython-how-to-start>`_
132+
133+
134+

docs/_sources/index.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Now, let's GO
7676
.. toctree::
7777
:maxdepth: 2
7878

79-
en/howtostart
79+
en/guide
8080

8181
For Chinese users
8282
---------------

docs/en/callqpyapiinapp.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
<link rel="top" title="QPython 0.9 documentation" href="../index.html"/>
36-
<link rel="up" title="QPython Getting started" href="howtostart.html"/>
36+
<link rel="up" title="QPython Getting started" href="guide.html"/>
3737
<link rel="next" title="How to submit the documentation" href="contributorshowto.html"/>
3838
<link rel="prev" title="Python builtin Libraries" href="sl4aapis.html"/>
3939

@@ -89,8 +89,8 @@
8989

9090

9191
<ul class="current">
92-
<li class="toctree-l1"><a class="reference internal" href="howtostart.html">QPython Getting started</a></li>
93-
<li class="toctree-l1 current"><a class="reference internal" href="howtostart.html#programming-guide">Programming Guide</a><ul class="current">
92+
<li class="toctree-l1"><a class="reference internal" href="guide.html">QPython Getting started</a></li>
93+
<li class="toctree-l1 current"><a class="reference internal" href="guide.html#programming-guide">Programming Guide</a><ul class="current">
9494
<li class="toctree-l2"><a class="reference internal" href="qpyprograms.html">What unique work can QPython do?</a></li>
9595
<li class="toctree-l2"><a class="reference internal" href="qeditor4web.html">Are there more efficient way for developing?</a></li>
9696
<li class="toctree-l2"><a class="reference internal" href="sl4aapis.html">Python builtin Libraries</a></li>
@@ -104,8 +104,8 @@
104104
<li class="toctree-l2"><a class="reference internal" href="#how-to-build-an-independt-apk-from-qpython-scripts">How to build an independt APK from QPython scripts?</a></li>
105105
</ul>
106106
</li>
107-
<li class="toctree-l1"><a class="reference internal" href="howtostart.html#qpython-hackers-guide">QPython Hackers&#8217; Guide</a></li>
108-
<li class="toctree-l1"><a class="reference internal" href="howtostart.html#contributors-guide">Contributors&#8217; Guide</a></li>
107+
<li class="toctree-l1"><a class="reference internal" href="guide.html#qpython-hackers-guide">QPython Hackers&#8217; Guide</a></li>
108+
<li class="toctree-l1"><a class="reference internal" href="guide.html#contributors-guide">Contributors&#8217; Guide</a></li>
109109
</ul>
110110
<ul>
111111
<li class="toctree-l1"><a class="reference internal" href="../zhindex.html">中文用户向导</a></li>
@@ -153,7 +153,7 @@
153153

154154
<li><a href="../index.html">Docs</a> &raquo;</li>
155155

156-
<li><a href="howtostart.html">QPython Getting started</a> &raquo;</li>
156+
<li><a href="guide.html">QPython Getting started</a> &raquo;</li>
157157

158158
<li>How to call QPython script in your application?</li>
159159

docs/en/contributorshowto.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
<link rel="top" title="QPython 0.9 documentation" href="../index.html"/>
36-
<link rel="up" title="QPython Getting started" href="howtostart.html"/>
36+
<link rel="up" title="QPython Getting started" href="guide.html"/>
3737
<link rel="next" title="中文用户向导" href="../zhindex.html"/>
3838
<link rel="prev" title="How to call QPython script in your application?" href="callqpyapiinapp.html"/>
3939

@@ -89,10 +89,10 @@
8989

9090

9191
<ul class="current">
92-
<li class="toctree-l1"><a class="reference internal" href="howtostart.html">QPython Getting started</a></li>
93-
<li class="toctree-l1"><a class="reference internal" href="howtostart.html#programming-guide">Programming Guide</a></li>
94-
<li class="toctree-l1"><a class="reference internal" href="howtostart.html#qpython-hackers-guide">QPython Hackers&#8217; Guide</a></li>
95-
<li class="toctree-l1 current"><a class="reference internal" href="howtostart.html#contributors-guide">Contributors&#8217; Guide</a><ul class="current">
92+
<li class="toctree-l1"><a class="reference internal" href="guide.html">QPython Getting started</a></li>
93+
<li class="toctree-l1"><a class="reference internal" href="guide.html#programming-guide">Programming Guide</a></li>
94+
<li class="toctree-l1"><a class="reference internal" href="guide.html#qpython-hackers-guide">QPython Hackers&#8217; Guide</a></li>
95+
<li class="toctree-l1 current"><a class="reference internal" href="guide.html#contributors-guide">Contributors&#8217; Guide</a><ul class="current">
9696
<li class="toctree-l2 current"><a class="current reference internal" href="#">How to submit the documentation</a></li>
9797
</ul>
9898
</li>
@@ -143,7 +143,7 @@
143143

144144
<li><a href="../index.html">Docs</a> &raquo;</li>
145145

146-
<li><a href="howtostart.html">QPython Getting started</a> &raquo;</li>
146+
<li><a href="guide.html">QPython Getting started</a> &raquo;</li>
147147

148148
<li>How to submit the documentation</li>
149149

0 commit comments

Comments
 (0)