I am trying to use Pyjamas to display an image (among other things), and I have just been unable to get it to work. I am able to create a Canvas object, have it load the images, but when I try to set the image object as an attribute of the Canvas object, I get an error saying the canvas object doesn't have such an attribute. Here is my code below. It will run, and create the canvas object correctly (I can do other stuff like fill in a rectangle), but the image just will not display:
class ScreenCanvas(GWTCanvas):
def __init__(self,w,h):
GWTCanvas.__init__(self,w,h)
self.width = w
self.height = h
loadImages(['images/field.jpg','images/earth.png'], self )
def onImagesLoaded(self, imagesHandles):
self.field = imagesHandles[0]
self.earth = imagesHandles[1]
if hasattr(self,'earth'):
self.setFillStyle(Color.Color('#111'))
self.fillRect(0,0,self.width,self.height)
self.drawImage(self.earth,12,12)
def draw_earth(self):
self.drawImage(self.earth)
pyjd.setup("public/ProjectileSim.html")
c = ScreenCanvas(4000, 4000)
#c.draw()
c.draw_earth()
panel = FocusPanel(Widget = c)
RootPanel().add(panel)
panel.setFocus(True)
pyjd.run()
The draw_earth method throws an error saying that I have no "earth" attribute for the canvas object, but if I just use onImagesLoaded to try and draw the object, I do not get a missing attribute error, but instead the image simply won't show up.
Apologies if pyjamas is not a very common way to do this. I would be open to alternative methods to display graphics using canvas. I am trying to do more than display images, but I have just been stuck on this problem. Anyway, thanks for your time reading this
Aucun commentaire:
Enregistrer un commentaire