Lino Website

Documentation · Modules · adamo · Examples

forms2.py

We add a third button that pops up another non-modal form. Buttons are now laid out horizontally.

from lino.forms import Form

class PrivacyForm(Form):
    
    """\

(imagine our privacy statement here)

Note that this form is not modal,
so you don't need to close it if you want to continue registering.
"""
    
    title = "Privacy statement"
    
    def layout(self,panel):
        panel.okButton()
        
class MyForm(Form):
    
    title = "The First Lino Form"

    def layout(self,panel):
    
        panel.label("""\
Please enter your personal data.
Don't worry about your privacy.
You can trust us.
    """)
        self.firstName = panel.entry(label="First name")
        self.name = panel.entry(label="Name")
        panel.formButton(PrivacyForm())
        panel.okButton()
        panel.cancelButton()

    def ok(self):
        if not self.firstName.getValue():
            self.notice("First name is mandatory")
            return
        if not self.name.getValue():
            self.notice("Name is mandatory")
            return
        self.message(
            "Hello %s %s. Thank you for registering.",
            self.firstName.getValue(),
            self.name.getValue())
        self.close()
        
    def cancel(self):
        if self.confirm("This will end our relation. Are you sure?"):
            self.close()

if __name__ == '__main__':
    MyForm().main()

forms2a.jpg forms2b.jpg

Refering articles:

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:23:37