Exemple #1
0
class AccessionByName(Composite):
	def __init__(self):
		self.form = FormPanel()
		self.form.setAction("/Accession/searchByName/")
		
		# 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.
		vpanel = VerticalPanel()
		self.form.setWidget(vpanel)
		
		self.colour_input = AutoCompleteByURLTextBox('/Accession/autoComplete')
		
		hpanel = HorizontalPanel()
		hpanel.add(HTML("Enter an ecotype name: "))
		hpanel.add(self.colour_input)

		hpanel.setSpacing(8)
		# Add a 'submit' button.
		hpanel.add(Button("Submit", self))

		vpanel.add(hpanel)
		
		# Add an event handler to the form.
		self.form.addFormHandler(self)
		
		self.setWidget(self.form)
		

	def onShow(self):
		#self.colour_input.setFocus(True)
		return
class FormPanelExample:
    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)

    def onClick(self, sender):
        self.form.submit()

    def onSubmitComplete(self, event):
        # When the form submission is successfully completed, this event is
        # fired. Assuming the service returned a response of type text/plain,
        # we can get the result text here (see the FormPanel documentation for
        # further explanation).
        Window.alert(event.getResults())

    def onSubmit(self, event):
        # This event is fired just before the form is submitted. We can take
        # this opportunity to perform validation.
        if self.tb.getText().length == 0:
            Window.alert("The text box must not be empty")
            event.setCancelled(True)
Exemple #3
0
class FormPanelExample:
    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)

    def onClick(self, sender):
        self.form.submit()

    def onSubmitComplete(self, event):
        # When the form submission is successfully completed, this event is
        # fired. Assuming the service returned a response of type text/plain,
        # we can get the result text here (see the FormPanel documentation for
        # further explanation).
        Window.alert(event.getResults())

    def onSubmit(self, event):
        # This event is fired just before the form is submitted. We can take
        # this opportunity to perform validation.
        if (len(self.tb.getText()) == 0):
            Window.alert("The text box must not be empty")
            event.setCancelled(True)
class OpenPowerSystem:
    """ Defines the main panel for OpenPowerSystem.
    """

    def __init__(self):
        """ Constructs a new OpenPowerSystem instance.
        """
        self.TEXT_WAITING = "Waiting for response..."
        self.TEXT_ERROR = "Server Error"

        self.base_panel = HorizontalPanel()

        self.tab_panel = TabPanel()
        self.tab_panel.add(self.get_upload_panel(), "Upload")
#        self.tab_panel.add(self.get_home_panel(), "OpenPowerSystem")
#        self.tab_panel.add(self.get_map_panel(), "Map")
#        self.tab_panel.add(self.get_edit_panel(), "Edit")
        self.tab_panel.selectTab(0)

        self.base_panel.add(self.tab_panel)

        RootPanel().add(self.base_panel)


    def get_home_panel(self):
        panel = VerticalPanel()

        title = HTML("""OpenPowerSystem""")
        panel.add(title)

        subtitle = HTML("""The Open Power System data repository.""")
        panel.add(subtitle)

        return panel


#    def get_map_panel(self):
#        panel = VerticalPanel()
#
#        self.map = OpenMap(Width="900px", Height="900px")
#        panel.add(self.map)
#
#        self.wms = OpenWMSLayer("OpenLayers WMS",
#            "http://labs.metacarta.com/wms/vmap0", layers="basic")
#        self.map.addLayer(self.wms)
#
#        return panel


#    def get_edit_panel(self):
#        edit_page = edit_panel.EditPanel()
#        return edit_page.panel


    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
Exemple #5
0
class Index:
    def onModuleLoad(self):
        
        self.remote_py = MyBlogService()
        
        # Create a FormPanel and point it at a service.
        self.form = FormPanel()
        
        # Create a panel to hold all of the form widgets.
        vp=VerticalPanel(BorderWidth=0,HorizontalAlignment=HasAlignment.ALIGN_CENTER,VerticalAlignment=HasAlignment.ALIGN_MIDDLE,Width="100%",Height="150px")
        self.form.setWidget(vp)
        
        header=HTML("<h2>LOGIN TO YOUR ACCOUNT</h2>")
        part1=header
              
        # Create a TextBox, giving it a name so that it will be submitted.
        self.userName = TextBox()
        self.userName.setName("userNameFormElement")
        self.userName.setPlaceholder("User Name")
        part2=self.userName
        
        self.password = PasswordTextBox()
        self.password.setName("passwordFormElement")
        self.password.setPlaceholder("Password")
        part3=self.password
        
        self.errorInfoLabel = Label()
        self.errorInfoLabel.setStyleName('error-info')
        part4=self.errorInfoLabel
        part4.setStyleName("errorlabel")
        
         # Add a 'submit' button.
        hpanel = HorizontalPanel(BorderWidth=0,HorizontalAlignment=HasAlignment.ALIGN_CENTER,VerticalAlignment=HasAlignment.ALIGN_MIDDLE,Width="100%",Height="50px")
        
        partb=Button("Login", self)
        partb.setStyleName('btn')
        
        image=Label("Don''t have account? Sign up")
        anchor = Anchor(Widget=image, Href='/signup.html')
        parta=anchor
        
             
        hpanel.add(partb)
        hpanel.add(parta)
       
        part5=hpanel 
        part5.setStyleName("hpanel")
        
        vp.add(part1)
        vp.add(part2)
        vp.add(part3)
        vp.add(part4)
        vp.add(part5)
        vp.setStyleName("signup")
        
        # Add an event handler to the form.
        self.form.addFormHandler(self)
        RootPanel().add(self.form)
    
    def onClick(self, sender):
        if (len(self.userName.getText()) == 0 or len(self.password.getText()) == 0):
            self.errorInfoLabel.setText("Username or Password required")
        else:
            self.errorInfoLabel.setText('')
            self.authenticateUser()
 
    def authenticateUser(self):
        self.remote_py.callMethod('authenticateUser', [self.userName.getText(), self.password.getText()], self)
        
    def onRemoteResponse(self, response, requestInfo):
        self.errorInfoLabel.setText('')
        d = datetime.date.today() + datetime.timedelta(days=1)
        setCookie("LoggedInUser", response, d, path='/')
        loggedInUser = json.loads(response)
        if loggedInUser["is_superuser"] == True:
            Window.setLocation("/admin.html")
        else:
            Window.setLocation("/home.html")
        

    def onRemoteError(self, code, error_dict, requestInfo):
        if code == 401:
            self.errorInfoLabel.setText("Invalid Credentials. Please try again.")
Exemple #6
0
class Signup:
    def onModuleLoad(self):
        self.form = FormPanel()
        self.remote_py = MyBlogService()

        self.form.setAction("/index.html")

        vp = VerticalPanel(BorderWidth=0,
                           HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                           VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                           Width="100%",
                           Height="150px")
        self.form.setWidget(vp)

        header = HTML(
            "<h2>CREATE MY ACCOUNT</h2><h3>Welcome to signup form</h3>")
        part1 = header

        hpn = HorizontalPanel(BorderWidth=0,
                              HorizontalAlignment=HasAlignment.ALIGN_LEFT,
                              VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                              Width="92%",
                              Height="60px")

        self.fname = TextBox()
        self.fname.setName("fname")
        self.fname.setPlaceholder("First Name")
        hpn.add(self.fname)

        self.lname = TextBox()
        self.lname.setName("lname")
        self.lname.setPlaceholder("Last Name")
        hpn.add(self.lname)
        hpn.setCellWidth(self.fname, "70%")
        hpn.setCellWidth(self.lname, "30%")
        part2 = hpn

        self.uname = TextBox()
        self.uname.setName("uname")
        self.uname.setPlaceholder("User Name")
        part3 = self.uname

        self.password = PasswordTextBox()
        self.password.setName("passsignup")
        self.password.setPlaceholder("Choose a password")
        part4 = self.password

        self.rpassword = PasswordTextBox()
        self.rpassword.setName("rpasssignup")
        self.rpassword.setPlaceholder("Confirm your password")
        part5 = self.rpassword

        self.email = TextBox()
        self.email.setName("emailsignup")
        self.email.setPlaceholder("Enter your email address ")
        part6 = self.email

        self.errorlabel = Label()
        self.errorlabel.setStyleName("errorlabel")
        part7 = self.errorlabel

        hpanel = HorizontalPanel(BorderWidth=0,
                                 HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                                 VerticalAlignment=HasAlignment.ALIGN_MIDDLE,
                                 Width="100%",
                                 Height="50px")

        partb = Button("Signup", self)
        partb.setStyleName('btn')
        image = Label("Already have account! Sign in")
        anchor = Anchor(Widget=image, Href='/index.html')
        parta = anchor

        hpanel.add(partb)
        hpanel.add(parta)
        hpanel.setStyleName("hpanel")

        part8 = hpanel

        vp.add(part1)
        vp.add(part2)
        vp.add(part3)
        vp.add(part4)
        vp.add(part5)
        vp.add(part6)
        vp.add(part7)
        vp.add(part8)

        vp.setCellHeight(part1, "5%")
        vp.setCellHeight(part2, "10%")
        vp.setCellHeight(part3, "10%")
        vp.setCellHeight(part4, "10%")
        vp.setCellHeight(part5, "10%")
        vp.setCellHeight(part6, "10%")
        vp.setCellHeight(part7, "10%")
        vp.setCellHeight(part8, "10%")

        vp.setStyleName("signup")

        self.form.addFormHandler(self)
        RootPanel().add(self.form)

    def onClick(self, sender):
        add = self.email.getText()
        match = re.match(
            '^[a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$',
            add)
        if (len(self.fname.getText()) == 0 or len(self.lname.getText()) == 0):
            self.errorlabel.setText("First Name or Last name can't be empty ")
        elif (len(self.uname.getText()) == 0):
            self.errorlabel.setText("Username can't be empty ")
        elif (len(self.password.getText()) == 0):
            self.errorlabel.setText("Password can't be empty ")

        elif (len(self.rpassword.getText()) == 0):
            self.errorlabel.setText("confirm your password")
        elif ((self.password.getText() != self.rpassword.getText())):
            self.errorlabel.setText("Password should be same!")
        elif match == None:
            self.errorlabel.setText("invalid email")
        else:
            self.errorlabel.setText('')
            self.createUser()

    def onSubmitComplete(self, event):
        Window.alert(event.getResults())

    def createUser(self):
        self.remote_py.callMethod('createUser', [
            self.fname.getText(),
            self.lname.getText(),
            self.uname.getText(),
            self.email.getText(),
            self.password.getText()
        ], self)

    def onRemoteResponse(self, response, requestInfo):
        self.errorlabel.setText('')
        Window.alert("Signed up successfully. Please login.")
        Window.setLocation("/index.html")

    def onRemoteError(self, code, error_dict, requestInfo):
        if code == 500:
            self.errorlabel.setText("user name already exists .")
Exemple #7
0
class SubmitTab:
    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 onChange(self, src):
        if self.source.getText():
            self.file = FileUpload()
            self.file.setName("file");
            self.table.setWidget(2,1,self.file)

    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
Exemple #8
0
class OpenPowerSystem:
    """ Defines the main panel for OpenPowerSystem.
    """
    def __init__(self):
        """ Constructs a new OpenPowerSystem instance.
        """
        self.TEXT_WAITING = "Waiting for response..."
        self.TEXT_ERROR = "Server Error"

        self.base_panel = HorizontalPanel()

        self.tab_panel = TabPanel()
        self.tab_panel.add(self.get_upload_panel(), "Upload")
        #        self.tab_panel.add(self.get_home_panel(), "OpenPowerSystem")
        #        self.tab_panel.add(self.get_map_panel(), "Map")
        #        self.tab_panel.add(self.get_edit_panel(), "Edit")
        self.tab_panel.selectTab(0)

        self.base_panel.add(self.tab_panel)

        RootPanel().add(self.base_panel)

    def get_home_panel(self):
        panel = VerticalPanel()

        title = HTML("""OpenPowerSystem""")
        panel.add(title)

        subtitle = HTML("""The Open Power System data repository.""")
        panel.add(subtitle)

        return panel

#    def get_map_panel(self):
#        panel = VerticalPanel()
#
#        self.map = OpenMap(Width="900px", Height="900px")
#        panel.add(self.map)
#
#        self.wms = OpenWMSLayer("OpenLayers WMS",
#            "http://labs.metacarta.com/wms/vmap0", layers="basic")
#        self.map.addLayer(self.wms)
#
#        return panel

#    def get_edit_panel(self):
#        edit_page = edit_panel.EditPanel()
#        return edit_page.panel

    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