PageRenderTime 512ms CodeModel.GetById 210ms app.highlight 130ms RepoModel.GetById 170ms app.codeStats 0ms

/examples/kitchensink/Images.py

http://pyjamas.googlecode.com/
Python | 64 lines | 51 code | 13 blank | 0 comment | 4 complexity | 34e709b31552520ff9cba372a0222500 MD5 | raw file
 1from Sink import Sink, SinkInfo
 2from ui import DockPanel, Image, VerticalPanel, HasAlignment, HTML
 3
 4class Images(Sink):
 5    def __init__(self):
 6        self.curImage=0
 7        self.image=Image()
 8        self.loadingImage = Image(self.baseURL() + "images/blanksearching.gif")
 9        self.nextButton = Image(self.baseURL() + "rembrandt/forward.gif")
10        self.prevButton = Image(self.baseURL() + "rembrandt/back.gif")
11        self.sImages=["rembrandt/JohannesElison.jpg", "rembrandt/LaMarcheNocturne.jpg", "rembrandt/SelfPortrait1628.jpg", "rembrandt/SelfPortrait1640.jpg", "rembrandt/TheArtistInHisStudio.jpg", "rembrandt/TheReturnOfTheProdigalSon.jpg"]
12
13        for i in range(len(self.sImages)):
14            self.sImages[i]=self.baseURL() + self.sImages[i]
15        
16        self.image.addLoadListener(self)
17        self.prevButton.addClickListener(self)
18        self.nextButton.addClickListener(self)
19        
20        topPanel = DockPanel()
21        topPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
22        topPanel.add(self.prevButton, DockPanel.WEST)
23        topPanel.add(self.nextButton, DockPanel.EAST)
24        topPanel.add(self.loadingImage, DockPanel.CENTER)
25        
26        panel = VerticalPanel()
27        panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
28        panel.add(HTML("<h2>A Bit of Rembrandt</h2>", True))
29        panel.add(topPanel)
30        panel.add(self.image)
31        
32        panel.setWidth("100%")
33        self.initWidget(panel)
34        self.image.setStyleName("ks-images-Image")
35        self.nextButton.setStyleName("ks-images-Button")
36        self.prevButton.setStyleName("ks-images-Button")
37        
38        self.loadImage(0)           
39
40    def onClick(self, sender):
41        if sender==self.prevButton:
42            self.loadImage(self.curImage - 1)
43        elif sender == self.nextButton:
44            self.loadImage(self.curImage + 1)
45
46    def onError(self, sender):
47        pass
48
49    def onLoad(self, sender):
50        self.loadingImage.setUrl(self.baseURL() + "images/blanksearching.gif")
51
52    def loadImage(self, index):
53        if index < 0:
54            index = len(self.sImages) - 1
55        elif index > len(self.sImages) - 1:
56            index = 0
57
58        self.curImage = index
59        self.loadingImage.setUrl(self.baseURL() + "images/searching.gif")
60        self.image.setUrl(self.sImages[self.curImage])
61
62def init():
63    text="This page demonstrates GWT's support for images.  Notice in particular how it uses the image's onLoad event to display a 'wait spinner' between the back and forward buttons."
64    return SinkInfo("Images", text, Images)