Skip to content

Commit 3107206

Browse files
committed
Add how to run QPython script in my application
1 parent beb57f9 commit 3107206

File tree

12 files changed

+439
-7
lines changed

12 files changed

+439
-7
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
How to run QPython script in your application ?
2+
===========================================
3+
You could call QPython to run some script or python code in your app
4+
5+
::
6+
7+
String extPlgPlusName = "org.qpython.qpy"; // QPython package name
8+
Intent intent = new Intent();
9+
intent.setClassName(extPlgPlusName, "org.qpython.qpylib.MPyApi");
10+
intent.setAction(extPlgPlusName + ".action.MPyApi");
11+
12+
Bundle mBundle = new Bundle();
13+
mBundle.putString("app", "myappid");
14+
mBundle.putString("act", "onPyApi");
15+
mBundle.putString("flag", "onQPyExec"); // any String flag you may use in your context
16+
mBundle.putString("param", ""); // param String param you may use in your context
17+
18+
/*
19+
* The String Python code, you can put your py file in res or raw or intenet, so that you can get it the same way, which can make it scalable
20+
*/
21+
String code = "#qpy:console\n" +
22+
"try:\n" +
23+
" import androidhelper\n" +
24+
"\n" +
25+
" droid = androidhelper.Android()\n" +
26+
" line = droid.dialogGetInput()\n" +
27+
" s = 'Hello %s' % line.result\n" +
28+
" droid.makeToast(s)\n" +
29+
"except:\n" +
30+
" print(\"Hello, Please update to newest QPython version from (http://play.qpython.com/qrcode-python.html) to use this feature\")\n");
31+
32+
33+
mBundle.putString("pycode", code);
34+
intent.putExtras(mBundle);
35+
36+
startActivityForResult(intent, SCRIPT_EXEC_PY);
37+
38+
...
39+
40+
41+
// Deal with the result callback by qpython
42+
@Override
43+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
44+
if (requestCode == SCRIPT_EXEC_PY) {
45+
if (data!=null) {
46+
Bundle bundle = data.getExtras();
47+
String flag = bundle.getString("flag");
48+
String param = bundle.getString("param");
49+
String result = bundle.getString("result"); // Result your Pycode generate
50+
Toast.makeText(this, "onQPyExec: return ("+result+")", Toast.LENGTH_SHORT).show();
51+
} else {
52+
Toast.makeText(this, "onQPyExec: data is null", Toast.LENGTH_SHORT).show();
53+
54+
}
55+
}
56+
}
57+
58+
59+
60+
61+
`You can see this sample project <https://github.com/qpython-android/app-call-qpython-api>`_

docs/_sources/en/howtostart.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ Programming Guide
3131

3232
qeditor4web
3333
sl4aapis
34+
callqpyapiinapp

docs/en/callqpyapiinapp.html

Lines changed: 300 additions & 0 deletions
Large diffs are not rendered by default.

docs/en/howtostart.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<li class="toctree-l2"><a class="reference internal" href="qeditor4web.html">Programming from phone/tablet</a></li>
9999
<li class="toctree-l2"><a class="reference internal" href="qeditor4web.html#how-to-programming-from-browser">How to programming from browser</a></li>
100100
<li class="toctree-l2"><a class="reference internal" href="sl4aapis.html">SL4A APIs</a></li>
101+
<li class="toctree-l2"><a class="reference internal" href="callqpyapiinapp.html">How to run QPython script in your application ?</a></li>
101102
</ul>
102103
</li>
103104
</ul>
@@ -209,6 +210,7 @@ <h1>Programming Guide<a class="headerlink" href="#programming-guide" title="Perm
209210
<li class="toctree-l2"><a class="reference internal" href="sl4aapis.html#other-sl4a-apis">Other SL4A APIs</a></li>
210211
</ul>
211212
</li>
213+
<li class="toctree-l1"><a class="reference internal" href="callqpyapiinapp.html">How to run QPython script in your application ?</a></li>
212214
</ul>
213215
</div>
214216
</div>

docs/en/qeditor4web.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<li class="toctree-l2 current"><a class="current reference internal" href="#">Programming from phone/tablet</a></li>
9595
<li class="toctree-l2"><a class="reference internal" href="#how-to-programming-from-browser">How to programming from browser</a></li>
9696
<li class="toctree-l2"><a class="reference internal" href="sl4aapis.html">SL4A APIs</a></li>
97+
<li class="toctree-l2"><a class="reference internal" href="callqpyapiinapp.html">How to run QPython script in your application ?</a></li>
9798
</ul>
9899
</li>
99100
</ul>

docs/en/sl4aapis.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
<link rel="top" title="QPython 0.9 documentation" href="../index.html"/>
3636
<link rel="up" title="How to start" href="howtostart.html"/>
37-
<link rel="next" title="如何开始" href="../zh/howtostart.html"/>
37+
<link rel="next" title="How to run QPython script in your application ?" href="callqpyapiinapp.html"/>
3838
<link rel="prev" title="Programming from phone/tablet" href="qeditor4web.html"/>
3939

4040

@@ -102,6 +102,7 @@
102102
<li class="toctree-l3"><a class="reference internal" href="#other-sl4a-apis">Other SL4A APIs</a></li>
103103
</ul>
104104
</li>
105+
<li class="toctree-l2"><a class="reference internal" href="callqpyapiinapp.html">How to run QPython script in your application ?</a></li>
105106
</ul>
106107
</li>
107108
</ul>
@@ -322,7 +323,7 @@ <h2>Other SL4A APIs<a class="headerlink" href="#other-sl4a-apis" title="Permalin
322323

323324
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
324325

325-
<a href="../zh/howtostart.html" class="btn btn-neutral float-right" title="如何开始" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
326+
<a href="callqpyapiinapp.html" class="btn btn-neutral float-right" title="How to run QPython script in your application ?" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
326327

327328

328329
<a href="qeditor4web.html" class="btn btn-neutral" title="Programming from phone/tablet" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ <h2>QPython Getting started<a class="headerlink" href="#qpython-getting-started"
179179
<li class="toctree-l2"><a class="reference internal" href="en/qeditor4web.html">Programming from phone/tablet</a></li>
180180
<li class="toctree-l2"><a class="reference internal" href="en/qeditor4web.html#how-to-programming-from-browser">How to programming from browser</a></li>
181181
<li class="toctree-l2"><a class="reference internal" href="en/sl4aapis.html">SL4A APIs</a></li>
182+
<li class="toctree-l2"><a class="reference internal" href="en/callqpyapiinapp.html">How to run QPython script in your application ?</a></li>
182183
</ul>
183184
</li>
184185
</ul>

docs/objects.inv

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
# Project: QPython
33
# Version: 0.9
44
# The remainder of this file is compressed using zlib.
5-
xڭ�AN�0E�9�l�
6-
���B%Ԋ�`=���%�l���[�\.����I��@j�h��?c�W\��#������ !��1#˖�y�"+H�S��gd ���T����x.@R<�/0��X��*̄R�M�vCn� �r����p��٭�"L���Nj8F;q��PT� EP��T���A�WZ��{����m�XЖ��"֩ԛF�g#7�%VUJ�����n;�V�F���4*fsM)�Rس0�Xy5�v�Z�Y8����ƋQ �qQ�%�P�@S�������֮[�;��X�g6A枀u�X� �G^J����e�i�NS����AGI��k�1�~��E�1�e��Fͭޞ�>_WO���{Qe`
5+
xڭ��J1���#z�"��E� �U�=O7�n ��ɬu=�WϾ�����}��Vݢ`�[��2H�*�Z�q�׏�vw�#
6+
3Wm]�6�6��F0]D��z.�Y]�N�k�J��l�
7+
ͽ0����㥆N[K~�9�q�����R�tP-ώit�i<�y�8o����<�<�}N�&�v d�pF�N�&+������rU�k��A��8�N�,�5 �qUa����?�^;m���Cl5z���tJLG8zY�)�����"��}7Ƽ@~Q�~,
8+
m3��\��7�����k���Q+��=�B���V�M�npDf
9+
̫M����|��\�t\�I��:��@ 9}���Z�JR��f��:s�q:bU�� �>��DS����������[B�M���^'/w������

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/zh/howtostart.html

Lines changed: 2 additions & 2 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="prev" title="SL4A APIs" href="../en/sl4aapis.html"/>
36+
<link rel="prev" title="How to run QPython script in your application ?" href="../en/callqpyapiinapp.html"/>
3737

3838

3939
<script src="../static/js/modernizr.min.js"></script>
@@ -191,7 +191,7 @@ <h1>编程向导<a class="headerlink" href="#id4" title="Permalink to this headl
191191
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
192192

193193

194-
<a href="../en/sl4aapis.html" class="btn btn-neutral" title="SL4A APIs" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
194+
<a href="../en/callqpyapiinapp.html" class="btn btn-neutral" title="How to run QPython script in your application ?" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
195195

196196
</div>
197197

0 commit comments

Comments
 (0)