コード例 #1
0
ファイル: fileUpload.py プロジェクト: Afey/pyjs
class FileUploadDemo(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        self.form = FormPanel()
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)
        self.form.setAction("http://nonexistent.com")
        self.form.setTarget("results")

        vPanel = VerticalPanel()

        hPanel = HorizontalPanel()
        hPanel.setSpacing(5)
        hPanel.add(Label("Upload file:"))

        self.field = FileUpload()
        self.field.setName("file")
        hPanel.add(self.field)

        hPanel.add(Button("Submit", getattr(self, "onBtnClick")))

        vPanel.add(hPanel)

        results = NamedFrame("results")
        vPanel.add(results)

        self.form.add(vPanel)
        self.add(self.form)


    def onBtnClick(self, event):
        self.form.submit()
コード例 #2
0
ファイル: fileUpload.py プロジェクト: minghuascode/pyj
class FileUploadDemo(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        self.form = FormPanel()
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)
        self.form.setAction("http://nonexistent.com")
        self.form.setTarget("results")

        vPanel = VerticalPanel()

        hPanel = HorizontalPanel()
        hPanel.setSpacing(5)
        hPanel.add(Label("Upload file:"))

        self.field = FileUpload()
        self.field.setName("file")
        hPanel.add(self.field)

        hPanel.add(Button("Submit", getattr(self, "onBtnClick")))

        vPanel.add(hPanel)

        results = NamedFrame("results")
        vPanel.add(results)

        self.form.add(vPanel)
        self.add(self.form)

    def onBtnClick(self, event):
        self.form.submit()
コード例 #3
0
class HiddenDemo(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        self.form = FormPanel()
        self.form.setAction("http://google.com/search")
        self.form.setTarget("results")

        panel = VerticalPanel()
        panel.add(Hidden("q", "python pyjamas"))
        panel.add(Button("Search", getattr(self, "onBtnClick")))

        results = NamedFrame("results")
        panel.add(results)

        self.form.add(panel)
        self.add(self.form)

    def onBtnClick(self, event):
        self.form.submit()
コード例 #4
0
ファイル: hidden.py プロジェクト: Afey/pyjs
class HiddenDemo(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        self.form = FormPanel()
        self.form.setAction("http://google.com/search")
        self.form.setTarget("results")

        panel = VerticalPanel()
        panel.add(Hidden("q", "python pyjamas"))
        panel.add(Button("Search", getattr(self, "onBtnClick")))

        results = NamedFrame("results")
        panel.add(results)

        self.form.add(panel)
        self.add(self.form)


    def onBtnClick(self, event):
        self.form.submit()
コード例 #5
0
ファイル: Upload.py プロジェクト: brodybits/pyjs
class FileUploadPanel(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        self.form = FormPanel()
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)
        self.url =  "http://localhost/pyjamas_upload_demo"
        self.form.setAction(self.url)
        self.form.setTarget("results")

        vPanel = VerticalPanel()

        hPanel = HorizontalPanel()
        hPanel.setSpacing(5)
        hPanel.add(Label("Upload file:"))

        self.field = FileUpload()
        self.field.setName("file")
        hPanel.add(self.field)

        hPanel.add(Button("Submit", getattr(self, "onBtnClick")))
        vPanel.add(hPanel)
        
        self.simple = CheckBox("Simple mode?  ")
        #self.simple.setChecked(True)
        vPanel.add(self.simple)
        self.progress = Label('0%')

        results = NamedFrame("results")
        vPanel.add(results)
        vPanel.add(self.progress)

        self.form.add(vPanel)
        self.add(self.form)

    def onBtnClick(self, event):
        self.progress.setText('0%')
        if self.simple.isChecked():
            self.form.submit()
        else:
            if AsyncUpload.is_old_browser():
                Window.alert("Hmmm, your browser doesn't support this.")
            else:
                el = self.field.getElement()
                files = getattr(el, 'files')
                #TODO implement loop for multiple file uploads 
                file = JS("@{{files}}[0]") #otherwise pyjs thinks it's a string?
                AsyncUpload.asyncUpload(self.url, file, self)

    def onload(self, status):
        self.progress.setText('100%')

    def onerror(self, status):
        Window.alert("oh noes we got an " + str(status))

    def onprogress(self, loaded, total):
        if self.progress.getText() == '100%': return
        progress = (loaded / total)
        p = int(progress * 100)
        self.progress.setText(str(p) + '%')
コード例 #6
0
class FileUploadPanel(SimplePanel):
    def __init__(self):
        SimplePanel.__init__(self)

        self.form = FormPanel()
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)
        self.url = "http://localhost/pyjamas_upload_demo"
        self.form.setAction(self.url)
        self.form.setTarget("results")

        vPanel = VerticalPanel()

        hPanel = HorizontalPanel()
        hPanel.setSpacing(5)
        hPanel.add(Label("Upload file:"))

        self.field = FileUpload()
        self.field.setName("file")
        hPanel.add(self.field)

        hPanel.add(Button("Submit", getattr(self, "onBtnClick")))
        vPanel.add(hPanel)

        self.simple = CheckBox("Simple mode?  ")
        #self.simple.setChecked(True)
        vPanel.add(self.simple)
        self.progress = Label('0%')

        results = NamedFrame("results")
        vPanel.add(results)
        vPanel.add(self.progress)

        self.form.add(vPanel)
        self.add(self.form)

    def onBtnClick(self, event):
        self.progress.setText('0%')
        if self.simple.isChecked():
            self.form.submit()
        else:
            if AsyncUpload.is_old_browser():
                Window.alert("Hmmm, your browser doesn't support this.")
            else:
                el = self.field.getElement()
                files = getattr(el, 'files')
                #TODO implement loop for multiple file uploads
                file = JS(
                    "@{{files}}[0]")  #otherwise pyjs thinks it's a string?
                AsyncUpload.asyncUpload(self.url, file, self)

    def onload(self, status):
        self.progress.setText('100%')

    def onerror(self, status):
        Window.alert("oh noes we got an " + str(status))

    def onprogress(self, loaded, total):
        if self.progress.getText() == '100%': return
        progress = (loaded / total)
        p = int(progress * 100)
        self.progress.setText(str(p) + '%')