1
2
3
4
5
6
7
8
9
10
11
12 from pyjamas import DOM
13 from pyjamas.ui.Image import Image
14 from pyjamas.ui.FocusWidget import FocusWidget
15 from pyjamas.ui import Event
16 from pyjamas.ui import MouseListener
17 from pyjamas.ui import KeyboardListener
18 from pyjamas.ui import Focus
19 from pyjamas.ui import FocusListener
20
21 from __pyjamas__ import JS
22
24 - def __init__(self, Width=0, Height=0, **kwargs):
25 if not kwargs.has_key('StyleName'):
26 kwargs['StyleName'] = 'gwt-Canvas'
27 kwargs['Width'] = Width
28 kwargs['Height'] = Height
29
30 self.context = None
31
32 focusable = Focus.createFocusable()
33 self.canvas = DOM.createElement("canvas")
34 DOM.appendChild(focusable, self.canvas)
35 FocusWidget.__init__(self, focusable, **kwargs)
36
37 self.init()
38
39 self.context.fillStyle = "black"
40 self.context.strokeStyle = "black"
41
45
49
50 - def getContext(self):
52
55
57 el = self.getElement().firstChild
58 ctx = el.getContext("2d")
59
60 """
61 ctx._createPattern = ctx.createPattern
62 ctx.createPattern = function(img, rep) {
63 if (!(img instanceof Image)) img = img.getElement();
64 return self._createPattern(img, rep)
65 }
66
67 ctx._drawImage = ctx.drawImage
68 ctx.drawImage = function() {
69 var a=arguments
70 if (!(a[0] instanceof Image)) a[0] = a[0].getElement()
71 if (a.length==9) return self._drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
72 else if (a.length==5) return self._drawImage(a[0], a[1], a[2], a[3], a[4])
73 return self._drawImage(a[0], a[1], a[2])
74 }
75 """
76 self.context = ctx
77
79 - def __init__(self, url="", load_listener = None):
84
87
88
91 self.wait_list = []
92 self.loadListeners = []
93
94 if listener:
95 self.addLoadListener(listener)
96
97 - def add(self, sender):
100
102 self.loadListeners.append(listener)
103
105 if len(self.wait_list):
106 return False
107 return True
108
110 for listener in self.loadListeners:
111 listener.onError(sender)
112
114 self.wait_list.remove(sender)
115
116 if self.isLoaded():
117 for listener in self.loadListeners:
118 listener.onLoad(self)
119