示例#1
0
文件: Images.py 项目: brodybits/pyjs
class Images(Sink):
    def __init__(self):
        Sink.__init__(self)
        self.curImage=0
        self.image=Image()
        self.loadingImage = Image(self.baseURL() + "images/blanksearching.gif")
        self.nextButton = Image(self.baseURL() + "rembrandt/forward.gif")
        self.prevButton = Image(self.baseURL() + "rembrandt/back.gif")
        self.sImages=["rembrandt/JohannesElison.jpg", "rembrandt/LaMarcheNocturne.jpg", "rembrandt/SelfPortrait1628.jpg", "rembrandt/SelfPortrait1640.jpg", "rembrandt/TheArtistInHisStudio.jpg", "rembrandt/TheReturnOfTheProdigalSon.jpg"]

        for i in range(len(self.sImages)):
            self.sImages[i]=self.baseURL() + self.sImages[i]
        
        self.image.addLoadListener(self)
        self.prevButton.addClickListener(self)
        self.nextButton.addClickListener(self)
        
        topPanel = DockPanel()
        topPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        topPanel.add(self.prevButton, DockPanel.WEST)
        topPanel.add(self.nextButton, DockPanel.EAST)
        topPanel.add(self.loadingImage, DockPanel.CENTER)
        
        panel = VerticalPanel()
        panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        panel.add(HTML("<h2>A Bit of Rembrandt</h2>", True))
        panel.add(topPanel)
        panel.add(self.image)
        
        panel.setWidth("100%")
        self.initWidget(panel)
        self.image.setStyleName("ks-images-Image")
        self.nextButton.setStyleName("ks-images-Button")
        self.prevButton.setStyleName("ks-images-Button")
        
        self.loadImage(0)           

    def onClick(self, sender):
        if sender==self.prevButton:
            self.loadImage(self.curImage - 1)
        elif sender == self.nextButton:
            self.loadImage(self.curImage + 1)

    def onError(self, sender):
        pass

    def onLoad(self, sender=None):
        self.loadingImage.setUrl(self.baseURL() + "images/blanksearching.gif")

    def loadImage(self, index):
        if index < 0:
            index = len(self.sImages) - 1
        elif index > len(self.sImages) - 1:
            index = 0

        self.curImage = index
        self.loadingImage.setUrl(self.baseURL() + "images/searching.gif")
        self.image.setUrl(self.sImages[self.curImage])
示例#2
0
 def prepareImage(self, url):
     img = Image()
     img.__isLoaded = False
     img.addLoadListener(self)
     # normally, event listeners are only set up when the widget
     # is attached to part of the DOM (see Widget.onAttach).  but,
     # in this case, we want a load even _even though_ the Image
     # widget is not yet attached (and quite likely won't be).
     DOM.setEventListener(img.getElement(), img)
     return img
示例#3
0
 def prepareImage(self, url):
     img = Image()
     img.__isLoaded = False
     img.addLoadListener(self)
     # normally, event listeners are only set up when the widget
     # is attached to part of the DOM (see Widget.onAttach).  but,
     # in this case, we want a load even _even though_ the Image
     # widget is not yet attached (and quite likely won't be).
     DOM.setEventListener(img.getElement(), img)
     DOM.sinkEvents(img.getElement(), Event.ONLOAD)
     return img
示例#4
0
class Images(Sink):
    def __init__(self):
        Sink.__init__(self)
        self.curImage = 0
        self.image = Image()
        self.loadingImage = Image(self.baseURL() + "images/blanksearching.gif")
        self.nextButton = Image(self.baseURL() + "rembrandt/forward.gif")
        self.prevButton = Image(self.baseURL() + "rembrandt/back.gif")
        self.sImages = [
            "rembrandt/JohannesElison.jpg", "rembrandt/LaMarcheNocturne.jpg",
            "rembrandt/SelfPortrait1628.jpg", "rembrandt/SelfPortrait1640.jpg",
            "rembrandt/TheArtistInHisStudio.jpg",
            "rembrandt/TheReturnOfTheProdigalSon.jpg"
        ]

        for i in range(len(self.sImages)):
            self.sImages[i] = self.baseURL() + self.sImages[i]

        self.image.addLoadListener(self)
        self.prevButton.addClickListener(self)
        self.nextButton.addClickListener(self)

        topPanel = DockPanel()
        topPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        topPanel.add(self.prevButton, DockPanel.WEST)
        topPanel.add(self.nextButton, DockPanel.EAST)
        topPanel.add(self.loadingImage, DockPanel.CENTER)

        panel = VerticalPanel()
        panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        panel.add(HTML("<h2>A Bit of Rembrandt</h2>", True))
        panel.add(topPanel)
        panel.add(self.image)

        panel.setWidth("100%")
        self.initWidget(panel)
        self.image.setStyleName("ks-images-Image")
        self.nextButton.setStyleName("ks-images-Button")
        self.prevButton.setStyleName("ks-images-Button")

        self.loadImage(0)

    def onClick(self, sender):
        if sender == self.prevButton:
            self.loadImage(self.curImage - 1)
        elif sender == self.nextButton:
            self.loadImage(self.curImage + 1)

    def onError(self, sender):
        pass

    def onLoad(self, sender=None):
        self.loadingImage.setUrl(self.baseURL() + "images/blanksearching.gif")

    def loadImage(self, index):
        if index < 0:
            index = len(self.sImages) - 1
        elif index > len(self.sImages) - 1:
            index = 0

        self.curImage = index
        self.loadingImage.setUrl(self.baseURL() + "images/searching.gif")
        self.image.setUrl(self.sImages[self.curImage])
示例#5
0
class kMeans(Algorithm):
    def __init__(self):
        Algorithm.__init__(self)
        self.MLAlgorithmService = MLAlgorithmService(self)
        self.image = Image(self.baseURL() +
                           "services/kMeansPictures/lenna.png",
                           Width="320px",
                           Height="360px")
        self.resultImage = Image("", Width="320px", Height="360px")
        self.loadingImage = Image(self.baseURL() + "images/blanksearching.gif")
        self.calculateButton = Button("RUN", self.onButtonClick)
        self.log = Button("SHOW LOG", self.openLogFile)
        self.log.setEnabled(False)

        self.image.addLoadListener(self)

        topPanel = DockPanel()
        topPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        topPanel.add(self.calculateButton, DockPanel.WEST)
        topPanel.add(self.loadingImage, DockPanel.CENTER)
        topPanel.add(self.log, DockPanel.EAST)

        panel = DockPanel()
        panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        panel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        #panel.add(HTML("<h2>Image compression</h2>", True))
        panel.add(topPanel, DockPanel.NORTH)
        panel.add(self.image, DockPanel.WEST)
        panel.add(self.resultImage, DockPanel.EAST)

        panel.setWidth("100%")
        self.initWidget(panel)
        self.image.setStyleName("ks-images-Image")
        self.calculateButton.setStyleName("ks-images-Button")

        self.loadImage("picturem.png")

    def onButtonClick(self, sender):
        Window.alert("Starting image compression...")
        self.MLAlgorithmService.callMethod("lenna.png")

    def onError(self, sender):
        pass

    def onLoad(self, sender=None):
        self.loadingImage.setUrl(self.baseURL() + "images/blanksearching.gif")

    def loadImage(self, picture):
        self.loadingImage.setUrl(self.baseURL() + "images/searching.gif")
        self.image.setUrl(self.baseURL() + "services/kMeansPictures/lenna.png")
        self.resultImage.setUrl(self.baseURL() +
                                "services/kMeansPictures/lenna.png")
        self.resultImage.setUrl(self.baseURL() + "services/kMeansPictures/" +
                                picture)

    def onImageClicked(self):
        Window.alert("picture!")

    def openLogFile(self, sender):
        ###TODO: make logging output
        fileLocation = self.baseURL() + "services/contactjson.txt"
        dlg = FileOpenDlg(fileLocation=fileLocation)
        dlg.show()

    def showStatus(self, msg):
        Window.alert(msg)
示例#6
0
class kMeans(Algorithm):
    def __init__(self):
        Algorithm.__init__(self)
	self.MLAlgorithmService = MLAlgorithmService(self)
        self.image=Image(self.baseURL() + "services/kMeansPictures/lenna.png",Width="320px", Height="360px")
        self.resultImage=Image("",Width="320px", Height="360px")
        self.loadingImage = Image(self.baseURL() + "images/blanksearching.gif")
        self.calculateButton = Button("RUN", self.onButtonClick)
        self.log = Button("SHOW LOG", self.openLogFile)
        self.log.setEnabled(False)

        self.image.addLoadListener(self)
        
        topPanel = DockPanel()
        topPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        topPanel.add(self.calculateButton, DockPanel.WEST)
        topPanel.add(self.loadingImage, DockPanel.CENTER)
        topPanel.add(self.log, DockPanel.EAST)
        
        panel = DockPanel()
        panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        panel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
        #panel.add(HTML("<h2>Image compression</h2>", True))
        panel.add(topPanel, DockPanel.NORTH)
        panel.add(self.image, DockPanel.WEST)
        panel.add(self.resultImage, DockPanel.EAST)
        
        panel.setWidth("100%")
        self.initWidget(panel)
        self.image.setStyleName("ks-images-Image")
        self.calculateButton.setStyleName("ks-images-Button")
        
        self.loadImage("picturem.png")

    def onButtonClick(self, sender):
        Window.alert("Starting image compression...")
        self.MLAlgorithmService.callMethod("lenna.png")


    def onError(self, sender):
        pass

    def onLoad(self, sender=None):
        self.loadingImage.setUrl(self.baseURL() + "images/blanksearching.gif")

    def loadImage(self, picture):
        self.loadingImage.setUrl(self.baseURL() + "images/searching.gif")
        self.image.setUrl(self.baseURL() + "services/kMeansPictures/lenna.png")
        self.resultImage.setUrl(self.baseURL() + "services/kMeansPictures/lenna.png")
        self.resultImage.setUrl(self.baseURL() + "services/kMeansPictures/" + picture)

    def onImageClicked(self):
        Window.alert("picture!")

    def openLogFile(self, sender):
###TODO: make logging output
        fileLocation = self.baseURL() + "services/contactjson.txt"
        dlg = FileOpenDlg(fileLocation=fileLocation)
        dlg.show()

    def showStatus(self, msg):
        Window.alert(msg)