refactored button javascripts
[pyside-example-qml-signalslot:qml-signalslot.git] / webviews_statemachine / demo_webservice.py
1 # -*- coding: utf-8 -*-
2 import logging
3 logger = logging.getLogger(__name__)
4
5 class DemoWebService(object):
6     """in real world this would come from a web server."""
7
8     @staticmethod
9     def remote_control():
10         # load JavaScript
11         f = open("demos/coolclock.js")
12         js = f.read()
13         f.close()
14         return """
15         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
16         <html>
17         <head>
18             <script type="text/javascript">"""+js+"""</script>
19             <style content="text/css">
20             body {
21             font-family: 'gill sans';
22             }
23             input {
24             cursor: pointer;
25             border-radius: 0.4em;
26                 display: inline-block;
27                 padding: 0.2em;
28                 font-weight:bold;
29                 text-shadow: 1px 1px 1px rgba(255,255,255,0.5);
30                 border: 3px double rgba(100,77,242,0.5);;
31                 -webkit-box-shadow: 0.2em 0.1em rgba(128,57,242,0.5);
32             background-image: -webkit-gradient(linear, left top, left bottom, from(#2a9ee2), to(#7acee2),color-stop(0.4, #7acee8));
33             }
34             input.selected {
35             background: red;
36             text-decoration: blink;
37             }
38             </style>
39             <script type="text/javascript">
40             function button_onclicked(name) {
41                 console.log('This call in WebKit');
42                 this.className += 'selected';
43                 window.qml.qmlCall(name);
44             }
45             </script>
46         </head>
47         <body onload="CoolClock.findAndCreateClocks()">
48             <canvas class="CoolClock::60" style="margin-bottom: 1em;"></canvas>
49             <p>
50             <input id="spread_btn" type="button" value="spread" onclick="button_onclicked('spread')" />
51             <input id="kaleidoscope_btn" type="button" value="kaleidoscope" onclick="button_onclicked('kaleidoscope')" />
52             <input id="nebula_btn" type="button" value="nebula" onclick="button_onclicked('nebula')" />
53             </p>
54             <p>
55             The buttons are just regular HTML &lt;input&gt; elements. The clock is a &lt;canvas&gt; element.
56             </p>
57         </body>
58         </html>
59         """
60
61     @staticmethod
62     def spread():
63         return "demos/spread.html"
64     
65     @staticmethod
66     def kaleidoscope():
67         return "demos/kaleidoscope.html"
68     
69     @staticmethod
70     def nebula():
71         return "demos/nebula.html"