-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsample.html
More file actions
330 lines (328 loc) · 10.7 KB
/
Copy pathsample.html
File metadata and controls
330 lines (328 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<title>A hands-on introduction to Python for beginning programmers</title>
<link rel="stylesheet" type="text/css" href="static/pygments.css" />
<link rel="stylesheet" type="text/css" href="static/style.css" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head><body>
<div class="header doc-header web-show">
<div class="col-sm-offset-2 col-sm-8 index-header">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse">
<span class="sr-only">切换导航</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/index.html" class="logo"><img src="http://www.qpython.org/static/img_logo.png"></a>
</div>
<ul class="header-title collapse navbar-collapse" id="example-navbar-collapse" >
<li>
<a href="http://www.qpython.org/index.html">Home</a>
</li>
<li>
<a href="http://www.qpython.org/document.html">Guide</a>
</li>
<li class="header-phone-selected">
<a href="/index.html" class="header-selected">Course</a>
<span class="header-title-selected"></span>
</li>
<li>
<a href="http://www.aipy.org">AIPY</a>
</li>
<li>
<a target="_blank" href="https://github.com/qpython-android/qpython">Github</a>
</li>
</ul>
<div class="search-box hidden-xs">
<form action="/search.html">
<input type="search" name="q" placeholder="keyword">
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
<button><img src="http://www.qpython.org/static/ic_search.png"></button>
</form>
</div>
</div>
</div>
<main class="contain web-content">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="a-hands-on-introduction-to-python-for-beginning-programmers">
<h1>A hands-on introduction to Python for beginning programmers<a class="headerlink" href="#a-hands-on-introduction-to-python-for-beginning-programmers" title="Permalink to this heading">¶</a></h1>
<p>If you are a new guy to QPython, you should watch the tutorial video and just follow the steps to learn how to run script with QPython</p>
<button data-url="http://www.baidu.com" class="button">Watch Tutorial</button>
<section id="running-with-console">
<h2>Running with Console<a class="headerlink" href="#running-with-console" title="Permalink to this heading">¶</a></h2>
<p>Running QPython’s simple script with console model</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>qpy:2
#qpy:console
#qpy:http://qpython.com/s/qpy-sample.py
class Calculator(object):
#define class to simulate a simple calculator
def __init__ (self):
#start with zero
self.current = 0
def add(self, amount):
#add number to current
self.current += amount
def getCurrent(self):
return self.current
myBuddy = Calculator() # make myBuddy into a Calculator object
myBuddy.add(2) #use myBuddy's new add method derived from the Calculator class
print(myBuddy.getCurrent()) #print myBuddy's current instance variable
</pre></div>
</div>
<button class="button">Run …</button>
</section>
<section id="running-with-kivy">
<h2>Running with Kivy<a class="headerlink" href="#running-with-kivy" title="Permalink to this heading">¶</a></h2>
<p>Running QPython’s script with GUI model ( Kivy library )</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#qpy:2
#qpy:kivy
#qpy:http://qpython.com/s/qpy-guisample.py
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
# display a button with the text : Hello QPython
return Button(text='Hello QPython')
TestApp().run()
</pre></div>
</div>
<button class="button">Run …</button>
</section>
<section id="running-as-web-app">
<h2>Running as Web App<a class="headerlink" href="#running-as-web-app" title="Permalink to this heading">¶</a></h2>
<p>Running Web App with QPython</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#qpy:2
#qpy:webapp:Hello Qpython
#qpy://localhost:8080/hello
"""
This is a sample for qpython webapp
"""
from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
run(host='localhost', port=8080)
</pre></div>
</div>
<button class="button">Run …</button>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</main>
<div class="star-footer">
<img onclick="openPurchase()" src="static/star.jpg">
<div id="praise"><span>0</span> persons have rewarded</div>
</div>
<div class="foo"></div>
<footer class="clearfix fixfooter web-show">
<div class="col-sm-offset-2 col-sm-6 footer-div1">
<div class="footer-block-item">
<span class="footer-item1">Built with Sphinx using a theme provid by QPython.</span>
<span class="footer-item2 visible-xs">Copyight 2017, QPython.</span>
</div>
</div>
<div class="col-sm-2 footer-div2">
<a href="/index.html" class="pull-right"><img src="http://www.qpython.org/static/img_logo.png"></a>
</div>
</footer>
<div id="purchase-box">
<div class="zh-img purchase-img"></div>
<div class="en-img purchase-img">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ST6KWAK8R63JW">
<div class="en-thanks-tit">
<input type="hidden" name="on0" value="Thanks">
Thanks
</div>
<div class="en-thanks-sel">
<select name="os0">
<option value="Reward this course">Reward this course $ 0.99 USD</option>
<option value="Reward this course">Reward this course $ 1.49 USD</option>
<option value="Reward this course">Reward this course $ 1.99 USD</option>
<option value="Reward this course">Reward this course $ 2.99 USD</option>
<option value="Reward this course">Reward this course $ 3.49 USD</option>
</select>
</div>
<input type="hidden" name="currency_code" value="USD">
<input type="image" class="pay_img" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/zh_XC/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
<script>
var milib;
if (milib==undefined) {
var milib = function(){
};
milib.qeditor = function(str){
alert('Please share this page to QPython then run it')
};
milib.getPurchaseNumber = function(str){
//alert('getPurchaseNumber:'+str)
return "10+";
};
milib.a8playVideoFromGW= function(url){
window.open(url)
};
milib.qpylibinstall = function(cat,url,target){
window.open(url)
};
milib.gotoIfPay = function(url, packageId, packageUrl){
window.open(url)
};
} else {
}
function openPurchase() {
//获取标识
var u = window.location.href.split('/')
var s = u[u.length-1].replace('.html', '')
s = u[u.length-2]+'-'+s
if (milib.openPurchaseActivity){
milib.openPurchaseActivity(s)
}else {
if (navigator.language== "zh-CN" || navigator.language== "zh"){
$('.zh-img ').show();
$('.en-img').hide();
}else {
$('.zh-img ').hide();
$('.en-img').show();
}
$('#purchase-box').show();
}
}
$(function() {
$('#purchase-box').click(function() {
$(this).hide();
})
$('.purchase-img').click(function(e) {
e.stopPropagation();
})
})
//按钮事件
function btnEvent(){
var seq = this.getAttribute('target')-2
var a = this.parentElement.getElementsByTagName('pre')
if ( a && a.length > 0){
/**********有代码,调用控制台*************/
var code = a[seq].lastChild.nodeValue
milib.qeditor(code)
}else{
//没有代码,调转
var url = this.getAttribute('data-url');
window.open(url);
}
}
//获取赞赏
function setPraise(){
var u = window.location.href.split('/')
var s = u[u.length-1].replace('.html', '')
s = u[u.length-2]+'-'+s
var i = document.getElementById('praise').getElementsByTagName('span')[0]
var num = milib.getPurchaseNumber(s);
i.innerHTML = num
}
//初始化代码显示
function initCode(){
var prearr = document.getElementsByTagName('pre');
for (var i = 0; i < prearr.length; i++) {
var temp_data = prearr[i].lastChild.nodeValue
//正则处理 lavel5
temp_data = temp_data.replace(/\^2\$/g, spaceString(2));
temp_data = temp_data.replace(/\^4\$/g, spaceString(4));
temp_data = temp_data.replace(/\^6\$/g, spaceString(6));
temp_data = temp_data.replace(/\^8\$/g, spaceString(8));
temp_data = temp_data.replace(/\^10\$/g, spaceString(10));
temp_data = temp_data.replace(/\^12\$/g, spaceString(12));
temp_data = temp_data.replace(/\^16\$/g, spaceString(16));
temp_data = temp_data.replace(/\^20\$/g, spaceString(20));
//set
prearr[i].lastChild.nodeValue = temp_data;
}
}
//产生空格
function spaceString(num){
var v = ''
for (var i = 0; i < num; i++) {
v += ' ';
}
return v;
}
function setSearchHistory (t) {
if (!t)
return;
if (localStorage.course_search_list) {
var list = localStorage.course_search_list.split('%,%');
var i = list.indexOf(t);
if (i !== -1) {
list.splice(i, 1);
list.push(t);
localStorage.course_search_list = list.join('%,%');
}else {
localStorage.course_search_list += '%,%'+t;
}
}else {
localStorage.course_search_list = t;
}
}
window.onload = function(){
setPraise();
initCode();
//将所有的button绑定事件
var b = document.getElementsByTagName('button');
for (var i = 0; i < b.length; i++) {
if (b[i].className=='button') {
b[i].setAttribute('target', i)
b[i].onclick = btnEvent ;
}
}
}
$(function(){
var url = location.href.split('?');
var arg = url[1];
if (!arg){
return;
}
var args = arg.split('&');
for (var i = 0; i < args.length; i++) {
var c = args[i].split('=');
if (c[0]=='form' && c[1] == 'web') {
$('.web-show').css('display','block');
$('.web-content').addClass('margin-header');
}
}
})
$(function() {
$('form').submit(function() {
setSearchHistory($("input[name='q']").val());
})
$('.bodywrapper .body form input').val("");
$($('.bodywrapper .body form input')[0]).attr('placeholder', 'search');
})
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-103260045-3', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>