# DEMO
htmlPy 可以利用 HTML 构建 C/S 端应用
# main.py
import htmlPy
import os
from backendInterface import BackEnd
app = htmlPy.AppGUI(title=u"Sample application")
app.maximized = False
app.template_path = os.path.abspath(".")
app.static_path = os.path.abspath(".")
be = BackEnd()
be.app = app
app.bind(be)
app.template = ("index.html", {})
app.start()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# backendInterface.py
import htmlPy
import json
class BackEnd(htmlPy.Object):
# @htmlPy.Slot(arg1_type, arg2_type, ..., result=return_type)
@htmlPy.Slot(str, result=str)
def say_hello_world(self,arg1):
print("say_hello_world"+arg1)
# self.app.html = "Hello, world"
return "123"
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# index.html
<html>
<body>
[ Click to say "Hello, world" ](BackEnd.say_hello_world)
</body>
<script>
setTimeout(function() {
var r = BackEnd.say_hello_world("233333");
alert(r);
}, 1000);
</script>
</html>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11