Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (59 sloc) 2.328 kb
642156e add raphael examples from juergen schackmann
Luke Leighton authored
1
2 import pyjd
3 from pyjamas.ui.RootPanel import RootPanel
4 from pyjamas.ui.TabPanel import TabPanel
5 from pyjamas.ui.SimplePanel import SimplePanel
6 from pyjamas.ui.HorizontalPanel import HorizontalPanel
7 from pyjamas.ui.Label import Label
8 from pyjamas.ui.HTML import HTML
9 from pyjamas.ui import HasAlignment
10 from pyjamas.raphael.raphael import Raphael,DOCK_CONNECTION
2f217fd Peter Bittner logging: migrated all references from pyjamas.log -> pyjamas.logging
bittner authored
11 from pyjamas import DOM
642156e add raphael examples from juergen schackmann
Luke Leighton authored
12
13
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
14 class Graffle(SimplePanel):
642156e add raphael examples from juergen schackmann
Luke Leighton authored
15 def __init__(self,width=600,height=300):
16 SimplePanel.__init__(self)
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
17 self.canvas = Raphael(width,height)
642156e add raphael examples from juergen schackmann
Luke Leighton authored
18 self.add(self.canvas)
19 def draw(self):
20 self.circle1=self.canvas.circle(50,50,25)
21 self.circle1.setAttr('fill','#000')
22 self.circle1.setAttrs({'cursor':'move','opacity':0.6})
23 self.circle1.drag(self._move_circle,start,up)
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
24
642156e add raphael examples from juergen schackmann
Luke Leighton authored
25 self.circle2=self.canvas.circle(150,100,25)
26 self.circle2.setAttr('fill','#000')
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
27 self.circle2.setAttrs({'cursor':'move','opacity':0.6})
642156e add raphael examples from juergen schackmann
Luke Leighton authored
28 self.circle2.drag(self._move_circle,start,up)
29
30 self.rect1=self.canvas.rect(200,100,30,30)
31 self.rect1.setAttr('fill','#000')
32 self.rect1.drag(self._move_rect,start,up)
33
34 self.rect2=self.canvas.rect(200,150,30,30)
35 self.rect2.setAttr('fill','#000')
36 self.rect2.drag(self._move_rect,start,up)
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
37
38 def connect(self):
642156e add raphael examples from juergen schackmann
Luke Leighton authored
39 line={'stroke':'#fff','stroke-width':3}
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
40 bg={'stroke': '#000', 'stroke-width':5}
41 self.connection_rect=self.canvas.connection(self.rect1,self.rect2,line=line,bg=bg)
642156e add raphael examples from juergen schackmann
Luke Leighton authored
42
a7f5008 Added missing CSS to Raphael example
Schackmann@.(none) authored
43 line={'stroke':'#fff','stroke-width':3}
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
44 bg={'stroke': '#000', 'stroke-width':5}
45 self.connection_circle=self.canvas.connection(self.circle1,self.circle2,line=line,bg=bg,cp1=DOCK_CONNECTION.EAST,cp2=DOCK_CONNECTION.WEST)
46
642156e add raphael examples from juergen schackmann
Luke Leighton authored
47 def _move_rect(self,obj,dx,dy,x,y):
48 obj.translate(dx-obj.dx,dy-obj.dy)
49 obj.dx=dx
50 obj.dy=dy
51 self.connection_rect.draw()
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
52
642156e add raphael examples from juergen schackmann
Luke Leighton authored
53 def _move_circle(self,obj,dx,dy,x,y):
54 obj.translate(dx-obj.dx,dy-obj.dy)
55 obj.dx=dx
56 obj.dy=dy
57 self.connection_circle.draw()
58
59
60 def start(obj,x,y):
61 obj.dx=0
62 obj.dy=0
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
63
2651eb8 Billy Earney fixed raphael examples, which were causing run time errors
earney authored
64 def up(obj, event):
642156e add raphael examples from juergen schackmann
Luke Leighton authored
65 pass
66
64eff55 C Anthony Risinger find * -name '*.py' | xargs sed -i -r 's,\s+$,,'
xtfxme authored
67 if __name__ == "__main__":
a7f5008 Added missing CSS to Raphael example
Schackmann@.(none) authored
68 pyjd.setup("public/graffle.html")
69 graffle=Graffle()
642156e add raphael examples from juergen schackmann
Luke Leighton authored
70 RootPanel().add(graffle)
71 graffle.draw()
a7f5008 Added missing CSS to Raphael example
Schackmann@.(none) authored
72 graffle.connect()
642156e add raphael examples from juergen schackmann
Luke Leighton authored
73 pyjd.run()
Something went wrong with that request. Please try again.