Permalink
Browse files

add clock widget based on SVG canvas

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@176 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
1 parent 45b47a2 commit 094571cebf27b9146af62bdd17d879b8b1a8e3db lkcl committed Jan 4, 2009
View
7 examples/widgets/README
@@ -0,0 +1,7 @@
+This is a port of Google's Hello example.
+
+To build, run ./build.sh or:
+
+ ../../builder/build.py Hello.py
+
+and then open output/Hello.html in a web browser.
View
12 examples/widgets/Widgets.html
@@ -0,0 +1,12 @@
+<html>
+ <head>
+ <meta name="pygwt:module" content="Widgets">
+ <link rel='stylesheet' href='Widgets.css'>
+
+ <title>Widgets</title>
+ </head>
+ <body bgcolor="white">
+ <script language="javascript" src="pygwt.js"></script>
+ </body>
+</html>
+
View
114 examples/widgets/Widgets.py
@@ -0,0 +1,114 @@
+from pyjamas.ui import Button, RootPanel
+from pyjamas import Window
+from pyjamas.ui import Image, HTML, VerticalPanel, HorizontalPanel
+from Canvas import Canvas, CanvasImage, ImageLoadListener
+from pyjamas.Timer import Timer
+from math import floor, cos, sin
+
+
+class Widgets:
+ def onModuleLoad(self):
+
+ self.solar = SolarCanvas()
+
+ RootPanel().add(self.solar)
+ self.onShow()
+
+ def onShow(self):
+ self.solar.isActive = True
+ self.solar.onTimer()
+
+ def onHide(self):
+ self.solar.isActive = False
+
+
+class SolarCanvas(Canvas):
+ def __init__(self):
+ Canvas.__init__(self, 300, 300)
+ self.sun = CanvasImage('images/Clock.png')
+ self.moon = CanvasImage('images/moon.png')
+ self.earth = CanvasImage('images/earth.png')
+
+ self.loader = ImageLoadListener()
+ self.loader.add(self.sun)
+ self.loader.add(self.moon)
+ self.loader.add(self.earth)
+
+ self.isActive = True
+ self.onTimer()
+
+ def onTimer(self):
+ if not self.isActive:
+ return
+
+ Timer(1000, self)
+ self.draw()
+
+ def getTimeSeconds(self):
+ JS("""
+ var x = new Date();
+ return x.getSeconds();
+ """)
+
+ def getTimeMinutes(self):
+ JS("""
+ var x = new Date();
+ return x.getMinutes();
+ """)
+
+ def getTimeHours(self):
+ JS("""
+ var x = new Date();
+ return x.getHours();
+ """)
+
+ def getTimeMilliseconds(self):
+ JS("""
+ var x = new Date();
+ return x.getMilliseconds();
+ """)
+
+ def draw(self):
+ pi = 3.14159265358979323
+ if not self.loader.isLoaded():
+ return
+
+ self.context.globalCompositeOperation = 'destination-over'
+
+ # clear canvas
+ self.context.clearRect(0,0,100,100)
+
+ self.context.save()
+ self.context.fillStyle = 'rgba(0,0,0,0.4)'
+ self.context.strokeStyle = 'rgba(0,153,255,0.4)'
+ self.context.translate(50,50)
+
+ secs = self.getTimeSeconds()
+ mins = (self.getTimeMinutes() * 60) + secs
+ hours = (self.getTimeHours() * 3600) + mins
+ mins = mins / 60.0
+ hours = hours / 3600.0
+
+ # Seconds
+ self.context.save()
+ self.context.fillStyle = 'rgba(255,0,0,0.4)'
+ self.context.rotate( ((2*pi)/60)*secs + pi)
+ self.context.fillRect(-1,-1,2,38)
+ self.context.restore()
+
+ # Minutes
+ self.context.save()
+ self.context.rotate( ((2*pi)/60)*mins + pi)
+ self.context.fillRect(-1,-1,3,35)
+ self.context.restore()
+
+ # Hours
+ self.context.save()
+ self.context.rotate( ((2*pi)/60)*hours + pi)
+ self.context.fillRect(-2,-2,4,20)
+ self.context.restore()
+
+ self.context.restore()
+
+ self.context.drawImage(self.sun,0,0)
+
View
1 examples/widgets/build.sh
@@ -0,0 +1 @@
+python ../../builder/build.py Widgets.py
View
7 examples/widgets/public/Widgets.css
@@ -0,0 +1,7 @@
+.teststyle {
+ font-size: 200%;
+ margin: 20px;
+ padding: 20px;
+
+}
+
View
BIN examples/widgets/public/images/Clock.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 094571c

Please sign in to comment.