Example #1
0
    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)
Example #2
0
    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)
Example #3
0
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()
Example #4
0
 def draw(self):
     Popup.draw(self)
     
     namePanel = HorizontalPanel()
     #namePanel.add(Label('Crie um arquivo'))     
     if self.title == 'Abrir':
         self.enableOkButton(False)
         namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;"">
         Abra o arquivo salvo, copie<br>e cole aqui o conteudo:</div>"""))  
         
         self.field = FileUpload()
         self.field.setName('file')
         self.field.setID('files')
         self.center.add(self.field)        
         element = self.field.getElement()   
         
         JS("""function handleFileSelect(evt) {@{{self}}.enableOkButton(evt.target.files[0]!=null);} 
         @{{element}}.addEventListener('change', handleFileSelect, false);""")
         
         
         #http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
     else:
         namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;"">
         Crie um arquivo txt e copie<br>e cole o conteudo a seguir:</div>"""))   
                  
         self.textBox = TextBox()
         self.textBox.setStyleAttribute('marginLeft', 10)
         namePanel.add(self.textBox)
         self.center.add(namePanel)
         
         self.textBox.addInputListener(self)    
         self.onInput()
Example #5
0
    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)
Example #6
0
    def __init__(self,app):
        self.app=app

        self.form = FormPanel()
        self.form.setEncoding("multipart/form-data")
        self.form.setMethod("post")
        
        self.msg = HTML("<b>Uploading</b>")
        self.table = FlexTable()
        self.table.setText(0,0, "Problem")
        self.table.setText(1,0, "Language")
        self.table.setText(2,0, "Program File")
        self.table.setText(3,0, "Program source")
        self.problem = ListBox()
        self.problem.insertItem("Detect",-1,-1)
        self.problem.setName("problem")
        self.table.setWidget(0,1,self.problem)
        
        self.lang = ListBox()
        self.lang.insertItem("Detect","",-1)
        self.lang.insertItem("C/C++","cc",-1)
        self.lang.insertItem("Java","Java",-1)
        self.lang.insertItem("Python","Python",-1)
        self.lang.setName("lang")
        self.table.setWidget(1,1,self.lang)
        self.cookie = Hidden()
        self.cookie.setName("cookie")
        self.table.setWidget(5,0,self.cookie)

        self.file = FileUpload()
        self.file.setName("file");
        self.table.setWidget(2,1,self.file)
        
        self.source = TextArea()
        self.source.setName("source")
        self.source.setWidth("600");
        self.source.setHeight("400");
        self.source.setText("""//$$problem: 1$$
//$$language: cc$$
#include <unistd.h>
#include <stdio.h>
int main() {
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d\\n",a+b);
  return 0;
}""")
        self.source.addChangeListener(self.onChange)
        self.table.setWidget(3,1,self.source)

        self.button = Button("Submit",self)
        self.table.setWidget(4,1, self.button)
        self.table.setWidget(5,1, self.msg)
        self.msg.setVisible(False)
        self.form.setWidget(self.table)
        self.form.setAction("../upload.py/submit")

        self.form.addFormHandler(self)
    def get_upload_panel(self):
        # Create a FormPanel and point it at a service.
        self.form = FormPanel()
        self.form.setAction("/upload")

        # Add an event handler to the form.
        handler = UploadFormHandler()
        handler.form = self.form
        self.form.addFormHandler(handler)

        # Because we're going to add a FileUpload widget, we'll need to set the
        # form to use the POST method, and multipart MIME encoding.
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)

        panel = VerticalPanel()
        panel.setSpacing(8)
        panel.setStyleName("panel") # same name as in OpenPowerSystem.css.
        self.form.setWidget(panel)

        info = HTML(r'Upload CIM RDF/XML instance file.')
        panel.add(info)

        # Create a list box for choice of profile.
        self.profiles = [("UCTE (CIM 14)", "ucte"),
                         ("CPSM (CIM13)", "cpsm"),
                         ("CDPSM (CIM 14)", "cdpsm"),
                         ("Dynamics (CIM 14)", "dynamics")]
        self.profile = ListBox(VisibleItemCount=1)
        self.profile.setName("profileType")
        for n, v in self.profiles:
            self.profile.addItem(n, v)
        panel.add(self.profile)

        # Create a FileUpload widget.
        rdfxml_file = FileUpload()
        rdfxml_file.setName("uploadFormElement")
        panel.add(rdfxml_file)

        # Add a 'submit' button.
        upload = Button("Upload", handler)
        panel.add(upload)

        return self.form
Example #8
0
    def get_upload_panel(self):
        # Create a FormPanel and point it at a service.
        self.form = FormPanel()
        self.form.setAction("/upload")

        # Add an event handler to the form.
        handler = UploadFormHandler()
        handler.form = self.form
        self.form.addFormHandler(handler)

        # Because we're going to add a FileUpload widget, we'll need to set the
        # form to use the POST method, and multipart MIME encoding.
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)

        panel = VerticalPanel()
        panel.setSpacing(8)
        panel.setStyleName("panel")  # same name as in OpenPowerSystem.css.
        self.form.setWidget(panel)

        info = HTML(r'Upload CIM RDF/XML instance file.')
        panel.add(info)

        # Create a list box for choice of profile.
        self.profiles = [("UCTE (CIM 14)", "ucte"), ("CPSM (CIM13)", "cpsm"),
                         ("CDPSM (CIM 14)", "cdpsm"),
                         ("Dynamics (CIM 14)", "dynamics")]
        self.profile = ListBox(VisibleItemCount=1)
        self.profile.setName("profileType")
        for n, v in self.profiles:
            self.profile.addItem(n, v)
        panel.add(self.profile)

        # Create a FileUpload widget.
        rdfxml_file = FileUpload()
        rdfxml_file.setName("uploadFormElement")
        panel.add(rdfxml_file)

        # Add a 'submit' button.
        upload = Button("Upload", handler)
        panel.add(upload)

        return self.form
Example #9
0
    def onModuleLoad(self):
        # Create a FormPanel and point it at a service.
        self.form = FormPanel()
        self.form.setAction("/chat-service/test/")

        # Because we're going to add a FileUpload widget, we'll need to set the
        # form to use the POST method, and multipart MIME encoding.
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)

        # Create a panel to hold all of the form widgets.
        panel = VerticalPanel()
        self.form.setWidget(panel)

        # Create a TextBox, giving it a name so that it will be submitted.
        self.tb = TextBox()
        self.tb.setName("textBoxFormElement")
        panel.add(self.tb)

        # Create a ListBox, giving it a name and some values to be associated with
        # its options.
        lb = ListBox()
        lb.setName("listBoxFormElement")
        lb.addItem("foo", "fooValue")
        lb.addItem("bar", "barValue")
        lb.addItem("baz", "bazValue")
        panel.add(lb)

        # Create a FileUpload widget.
        upload = FileUpload()
        upload.setName("uploadFormElement")
        panel.add(upload)

        # Add a 'submit' button.
        panel.add(Button("Submit", self))

        # Add an event handler to the form.
        self.form.addFormHandler(self)

        RootPanel().add(self.form)
Example #10
0
    def onModuleLoad(self):
        # Create a FormPanel and point it at a service.
        self.form = FormPanel()
        self.form.setAction("/chat-service/test/")

        # Because we're going to add a FileUpload widget, we'll need to set the
        # form to use the POST method, and multipart MIME encoding.
        self.form.setEncoding(FormPanel.ENCODING_MULTIPART)
        self.form.setMethod(FormPanel.METHOD_POST)

        # Create a panel to hold all of the form widgets.
        panel = VerticalPanel()
        self.form.setWidget(panel)

        # Create a TextBox, giving it a name so that it will be submitted.
        self.tb = TextBox()
        self.tb.setName("textBoxFormElement")
        panel.add(self.tb)

        # Create a ListBox, giving it a name and some values to be associated with
        # its options.
        lb = ListBox()
        lb.setName("listBoxFormElement")
        lb.addItem("foo", "fooValue")
        lb.addItem("bar", "barValue")
        lb.addItem("baz", "bazValue")
        panel.add(lb)

        # Create a FileUpload widget.
        upload = FileUpload()
        upload.setName("uploadFormElement")
        panel.add(upload)

        # Add a 'submit' button.
        panel.add(Button("Submit", self))

        # Add an event handler to the form.
        self.form.addFormHandler(self)

        RootPanel().add(self.form)
Example #11
0
class UploadProblemTab(EntityTab):
    def __init__(self,app):
        EntityTab.__init__(self, app)
        self.form = FormPanel()
        self.form.setEncoding("multipart/form-data")
        self.form.setMethod("post")
        self.table = FlexTable()
        self.table.setText(0,0,"Problem archive")
        self.file = FileUpload()
        self.file.setName("file");
        self.table.setWidget(0,1,self.file)
        self.form.setWidget(self.table)
        self.button = Button("Submit",self)
        self.table.setWidget(1,1, self.button)
        self.msg = HTML("<b>Uploading</b>")
        self.msg.setVisible(False)
        self.cookie = Hidden()
        self.cookie.setName("cookie")
        self.table.setWidget(2,0, self.cookie)
        self.table.setWidget(2,1, self.msg)
        self.form.setWidget(self.table)
        self.form.setAction("../upload.py/problem")
        self.add("Upload new problem")

    def onSubmitComplete(self,event):
        self.msg.setVisible(False)

    def onSubmit(self,evt):
        self.msg.setVisible(True)
        
    def onClick(self,evt):
        if self.app.cookie == None:
            self.app.login()
        else:
            self.cookie.setValue(self.app.cookie)
            self.form.submit()
        
    def getRoot(self):
        return self.form
Example #12
0
 def __init__(self,app):
     EntityTab.__init__(self, app)
     self.form = FormPanel()
     self.form.setEncoding("multipart/form-data")
     self.form.setMethod("post")
     self.table = FlexTable()
     self.table.setText(0,0,"Problem archive")
     self.file = FileUpload()
     self.file.setName("file");
     self.table.setWidget(0,1,self.file)
     self.form.setWidget(self.table)
     self.button = Button("Submit",self)
     self.table.setWidget(1,1, self.button)
     self.msg = HTML("<b>Uploading</b>")
     self.msg.setVisible(False)
     self.cookie = Hidden()
     self.cookie.setName("cookie")
     self.table.setWidget(2,0, self.cookie)
     self.table.setWidget(2,1, self.msg)
     self.form.setWidget(self.table)
     self.form.setAction("../upload.py/problem")
     self.add("Upload new problem")
Example #13
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) + '%')
Example #14
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) + '%')
Example #15
0
    def __init__(self, left = 50, top = 50, fileLocation = None):
        global has_getAsText
        try:
            DialogBox.__init__(self, modal = False)
            self.filename = None
            self.data = None

            self.setPopupPosition(left, top)
            self.dockPanel = DockPanel()
            self.dockPanel.setSpacing(4)
            self.setText("File Open")

            if not fileLocation is None:
                msg = HTML("Loading file...", True)
                self.dockPanel.add(msg, DockPanel.NORTH)
                location =  fileLocation
                if fileLocation.find("://") < 0:
                    base = Window.getLocation().getHref()
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    base = sep.join(base.split(sep)[:-1]) + sep
                    location = base + fileLocation
                self.iframe = Frame(location)
                self.dockPanel.add(self.iframe, DockPanel.CENTER)
            else:
                msg = HTML("Choose a file", True)

                self.browseFile = FileUpload()
                elem = self.browseFile.getElement()
                if False and has_getAsText and hasattr(elem, 'files'):
                    self.iframe = None
                    self.files = elem.files
                    self.dockPanel.add(self.browseFile, DockPanel.CENTER)
                else:
                    self.browseFile = None
                    self.files = None
                    base = '' + doc().location
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    if not base.lower()[:5] == "file:":
                        base = "file:///C:/"
                        msg = HTML("You'll have to place the application on a local file system, otherwise the browser forbids access.", True)
                    else:
                        base = sep.join(base.split(sep)[:-1]) + sep
                    self.iframe = Frame(base)
                    self.dockPanel.add(self.iframe, DockPanel.CENTER)
                self.dockPanel.add(msg, DockPanel.NORTH)

            if self.iframe:
                self.iframe.setWidth("36em")
            hpanel = HorizontalPanel()
            self.openBtn = Button("Open", self.onClickOpen)
            hpanel.add(self.openBtn)
            self.cancelBtn = Button("Cancel", self.onClickCancel)
            hpanel.add(self.cancelBtn)
            self.dockPanel.add(hpanel, DockPanel.SOUTH)

            self.setWidget(self.dockPanel)
        except:
            raise
Example #16
0
class FileOpenDlg(DialogBox):

    files = None

    def __init__(self, left = 50, top = 50, fileLocation = None):
        global has_getAsText
        try:
            DialogBox.__init__(self, modal = False)
            self.filename = None
            self.data = None

            self.setPopupPosition(left, top)
            self.dockPanel = DockPanel()
            self.dockPanel.setSpacing(4)
            self.setText("File Open")

            if not fileLocation is None:
                msg = HTML("Loading file...", True)
                self.dockPanel.add(msg, DockPanel.NORTH)
                location =  fileLocation
                if fileLocation.find("://") < 0:
                    base = Window.getLocation().getHref()
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    base = sep.join(base.split(sep)[:-1]) + sep
                    location = base + fileLocation
                self.iframe = Frame(location)
                self.dockPanel.add(self.iframe, DockPanel.CENTER)
            else:
                msg = HTML("Choose a file", True)

                self.browseFile = FileUpload()
                elem = self.browseFile.getElement()
                if False and has_getAsText and hasattr(elem, 'files'):
                    self.iframe = None
                    self.files = elem.files
                    self.dockPanel.add(self.browseFile, DockPanel.CENTER)
                else:
                    self.browseFile = None
                    self.files = None
                    base = '' + doc().location
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    if not base.lower()[:5] == "file:":
                        base = "file:///C:/"
                        msg = HTML("You'll have to place the application on a local file system, otherwise the browser forbids access.", True)
                    else:
                        base = sep.join(base.split(sep)[:-1]) + sep
                    self.iframe = Frame(base)
                    self.dockPanel.add(self.iframe, DockPanel.CENTER)
                self.dockPanel.add(msg, DockPanel.NORTH)

            if self.iframe:
                self.iframe.setWidth("36em")
            hpanel = HorizontalPanel()
            self.openBtn = Button("Open", self.onClickOpen)
            hpanel.add(self.openBtn)
            self.cancelBtn = Button("Cancel", self.onClickCancel)
            hpanel.add(self.cancelBtn)
            self.dockPanel.add(hpanel, DockPanel.SOUTH)

            self.setWidget(self.dockPanel)
        except:
            raise

    def onClickCancel(self, sender):
        self.hide()

    def onClickOpen(self, sender):
        global has_getAsText
        data = None
        filename = None
        if self.files:
            if self.files.length == 0:
                return
            if self.files.length > 1:
                alert("Cannot open more than one file")
                return
            file = self.files.item(0)
            filename = file.fileName
            try:
                data = file.getAsText("")
            except AttributeError, e:
                has_getAsText = False
                alert("Sorry. cannot retrieve file in this browser.\nTry again.")
        else:
Example #17
0
class PopupOpenState(Popup):
        
    def __init__(self, okClick, cancelClick, title='Abrir', options=CONFIRM_CANCEL):
        Popup.__init__(self, title, okClick, cancelClick, options)
        
    def draw(self):
        Popup.draw(self)
        
        namePanel = HorizontalPanel()
        #namePanel.add(Label('Crie um arquivo'))     
        if self.title == 'Abrir':
            self.enableOkButton(False)
            namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;"">
            Abra o arquivo salvo, copie<br>e cole aqui o conteudo:</div>"""))  
            
            self.field = FileUpload()
            self.field.setName('file')
            self.field.setID('files')
            self.center.add(self.field)        
            element = self.field.getElement()   
            
            JS("""function handleFileSelect(evt) {@{{self}}.enableOkButton(evt.target.files[0]!=null);} 
            @{{element}}.addEventListener('change', handleFileSelect, false);""")
            
            
            #http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
        else:
            namePanel.add(HTML("""<div class=""gwt-Label"" style=""white-space: normal;"">
            Crie um arquivo txt e copie<br>e cole o conteudo a seguir:</div>"""))   
                     
            self.textBox = TextBox()
            self.textBox.setStyleAttribute('marginLeft', 10)
            namePanel.add(self.textBox)
            self.center.add(namePanel)
            
            self.textBox.addInputListener(self)    
            self.onInput()
            
    def enableOkButton(self, enable):
        if enable: self.okButton.removeStyleName('disabled')
        else: self.okButton.addStyleName('disabled')
        
    def onInput(self, sender):
        self.enableOkButton(self.textBox.getText().count(' ') != len(self.textBox.getText()))
        
    def myOkClick(self):
        if 'disabled' not in self.okButton.getStyleName():
            Popup.myOkClick(self)
            if self.okClick is not None:
                if self.title == 'Abrir':
                    files = getattr(self.field.getElement(), 'files')  
                    file = JS("@{{files}}[0]")
                    if  file:              
                        JS("""var reader = new FileReader();
                        reader.onload = function(e) {@{{self}}.okClick(e.target.result);}
                        reader.readAsBinaryString(@{{file}});""")                                 
                        #self.okClick(str)                        
                else:
                    self.okClick(self.textBox.getText())
                    
    def myCancelClick(self):
        Popup.myCancelClick(self)
        if self.cancelClick is not None: self.cancelClick()
            
    def show(self):
        Popup.show(self)
        if self.title != 'Abrir': self.textBox.setFocus(True)
        else:
            pass
Example #18
0
 def onChange(self, src):
     if self.source.getText():
         self.file = FileUpload()
         self.file.setName("file");
         self.table.setWidget(2,1,self.file)
Example #19
0
class FileOpenDlg(DialogBox):

    files = None

    def __init__(self, left=50, top=50, fileLocation=None):
        global has_getAsText
        try:
            DialogBox.__init__(self, modal=False)

            self.setPopupPosition(left, top)
            self.dockPanel = DockPanel()
            self.dockPanel.setSpacing(4)
            self.setText("File Open")

            if not fileLocation is None:
                msg = HTML("Loading file...", True)
                self.dockPanel.add(msg, DockPanel.NORTH)
                location = fileLocation
                if fileLocation.find("://") < 0:
                    base = Window.getLocation().getHref()
                    print base
                    if base.find("/") >= 0:
                        sep = "/"
                    else:
                        sep = "\\"
                    base = sep.join(base.split(sep)[:-1]) + sep
                    location = base + fileLocation
                self.iframe = Frame(location)
                self.dockPanel.add(self.iframe, DockPanel.CENTER)
            else:
                msg = HTML("Choose a file", True)

                self.browseFile = FileUpload()
                elem = self.browseFile.getElement()
                if False and has_getAsText and hasattr(elem, "files"):
                    self.iframe = None
                    self.files = elem.files
                    self.dockPanel.add(self.browseFile, DockPanel.CENTER)
                else:
                    self.browseFile = None
                    self.files = None
                    base = "" + doc().location
                    if base.find("/") >= 0:
                        sep = "/"
                    else:
                        sep = "\\"
                    if not base.lower()[:5] == "file:":
                        base = "file:///C:/"
                        msg = HTML(
                            "You'll have to place the application on a local file system, otherwise the browser forbids access.",
                            True,
                        )
                    else:
                        base = sep.join(base.split(sep)[:-1]) + sep
                    self.iframe = Frame(base)
                    self.dockPanel.add(self.iframe, DockPanel.CENTER)
                self.dockPanel.add(msg, DockPanel.NORTH)

            if self.iframe:
                self.iframe.setWidth("36em")
            hpanel = HorizontalPanel()
            self.openBtn = Button("Open", self)
            hpanel.add(self.openBtn)
            self.cancelBtn = Button("Cancel", self)
            hpanel.add(self.cancelBtn)
            self.dockPanel.add(hpanel, DockPanel.SOUTH)

            self.setWidget(self.dockPanel)
        except:
            raise

    def onClick(self, sender):
        global has_getAsText
        if sender == self.cancelBtn:
            self.hide()
        elif sender == self.openBtn:
            data = None
            filename = None
            if self.files:
                if self.files.length == 0:
                    return
                if self.files.length > 1:
                    alert("Cannot open more than one file")
                    return
                file = self.files.item(0)
                filename = file.fileName
                try:
                    data = file.getAsText("")
                except AttributeError, e:
                    has_getAsText = False
                    alert("Sorry. cannot retrieve file in this browser.\nTry again.")
            else:
                elem = self.iframe.getElement()
                # On firefox, this runs into:
                #   Permission denied to get property Window.document
                # when the file is not in the current domain
                body = elem.contentWindow.document.body
                try:
                    filename = "" + elem.contentWindow.location
                except:
                    filename = None
                if body.childNodes.length == 1:
                    data = "" + body.childNodes.item(0).innerHTML
                else:
                    data = "" + body.innerHTML
            self.hide()
            if data:
                self.mediator.sendNotification(Notification.FILE_LOADED, (filename, data))
Example #20
0
class FileOpenDlg(DialogBox):

    files = None

    def __init__(self, left=50, top=50, fileLocation=None):
        global has_getAsText
        try:
            DialogBox.__init__(self, modal=False)
            self.filename = None
            self.data = None

            self.setPopupPosition(left, top)
            self.dockPanel = DockPanel()
            self.dockPanel.setSpacing(4)
            self.setText("File Open")

            if not fileLocation is None:
                msg = HTML("Loading file...", True)
                self.dockPanel.add(msg, DockPanel.NORTH)
                location = fileLocation
                if fileLocation.find("://") < 0:
                    base = Window.getLocation().getHref()
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    base = sep.join(base.split(sep)[:-1]) + sep
                    location = base + fileLocation
                self.iframe = Frame(location)
                self.dockPanel.add(self.iframe, DockPanel.CENTER)
            else:
                msg = HTML("Choose a file", True)

                self.browseFile = FileUpload()
                elem = self.browseFile.getElement()
                if False and has_getAsText and hasattr(elem, 'files'):
                    self.iframe = None
                    self.files = elem.files
                    self.dockPanel.add(self.browseFile, DockPanel.CENTER)
                else:
                    self.browseFile = None
                    self.files = None
                    base = '' + doc().location
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    if not base.lower()[:5] == "file:":
                        base = "file:///C:/"
                        msg = HTML(
                            "You'll have to place the application on a local file system, otherwise the browser forbids access.",
                            True)
                    else:
                        base = sep.join(base.split(sep)[:-1]) + sep
                    self.iframe = Frame(base)
                    self.dockPanel.add(self.iframe, DockPanel.CENTER)
                self.dockPanel.add(msg, DockPanel.NORTH)

            if self.iframe:
                self.iframe.setWidth("36em")
            hpanel = HorizontalPanel()
            self.openBtn = Button("Open", self.onClickOpen)
            hpanel.add(self.openBtn)
            self.cancelBtn = Button("Cancel", self.onClickCancel)
            hpanel.add(self.cancelBtn)
            self.dockPanel.add(hpanel, DockPanel.SOUTH)

            self.setWidget(self.dockPanel)
        except:
            raise

    def onClickCancel(self, sender):
        self.hide()

    def onClickOpen(self, sender):
        global has_getAsText
        data = None
        filename = None
        if self.files:
            if self.files.length == 0:
                return
            if self.files.length > 1:
                alert("Cannot open more than one file")
                return
            file = self.files.item(0)
            filename = file.fileName
            try:
                data = file.getAsText("")
            except AttributeError, e:
                has_getAsText = False
                alert(
                    "Sorry. cannot retrieve file in this browser.\nTry again.")
        else:
Example #21
0
    def __init__(self, left=50, top=50, fileLocation=None):
        global has_getAsText
        try:
            DialogBox.__init__(self, modal=False)
            self.filename = None
            self.data = None

            self.setPopupPosition(left, top)
            self.dockPanel = DockPanel()
            self.dockPanel.setSpacing(4)
            self.setText("File Open")

            if not fileLocation is None:
                msg = HTML("Loading file...", True)
                self.dockPanel.add(msg, DockPanel.NORTH)
                location = fileLocation
                if fileLocation.find("://") < 0:
                    base = Window.getLocation().getHref()
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    base = sep.join(base.split(sep)[:-1]) + sep
                    location = base + fileLocation
                self.iframe = Frame(location)
                self.dockPanel.add(self.iframe, DockPanel.CENTER)
            else:
                msg = HTML("Choose a file", True)

                self.browseFile = FileUpload()
                elem = self.browseFile.getElement()
                if False and has_getAsText and hasattr(elem, 'files'):
                    self.iframe = None
                    self.files = elem.files
                    self.dockPanel.add(self.browseFile, DockPanel.CENTER)
                else:
                    self.browseFile = None
                    self.files = None
                    base = '' + doc().location
                    if base.find('/') >= 0:
                        sep = '/'
                    else:
                        sep = '\\'
                    if not base.lower()[:5] == "file:":
                        base = "file:///C:/"
                        msg = HTML(
                            "You'll have to place the application on a local file system, otherwise the browser forbids access.",
                            True)
                    else:
                        base = sep.join(base.split(sep)[:-1]) + sep
                    self.iframe = Frame(base)
                    self.dockPanel.add(self.iframe, DockPanel.CENTER)
                self.dockPanel.add(msg, DockPanel.NORTH)

            if self.iframe:
                self.iframe.setWidth("36em")
            hpanel = HorizontalPanel()
            self.openBtn = Button("Open", self.onClickOpen)
            hpanel.add(self.openBtn)
            self.cancelBtn = Button("Cancel", self.onClickCancel)
            hpanel.add(self.cancelBtn)
            self.dockPanel.add(hpanel, DockPanel.SOUTH)

            self.setWidget(self.dockPanel)
        except:
            raise