Python API to EasyForm

In [ ]:
from beakerx import *
In [ ]:
f = EasyForm("Form and Run")
f.addTextField("first")
f.addTextField("last")
f['first'] = "First"
f['last'] = "Last"
f.addButton("Go!", tag="run")
f
In [ ]:
"Good morning " + f["first"] + " " + f["last"]
In [ ]:
f['last'][::-1] + '...' + f['first']
In [ ]:
f['first'] = 'Beaker'
f['last'] = 'Berzelius'
In [ ]:
h = EasyForm(title="Form and Run")

h.addTextField("first", width=10)
h.addTextField("default")
h.addTextArea("Text Area 1", height=5, width=20)
h.addTextArea("Text Area 2")
h.addTextArea("Text Area 3", height=10)
h.addTextArea("Text Area 4",width=20)
h
In [ ]:
g2 = EasyForm("Field Types")
options = ["a", "b", "c", "d", "e", "f"]
g2.addList("List Single", options, multi=False)
g2.addList("List Two Row", options, rows=2)
g2
In [ ]:
f['last']+ ", "+f['first']
In [ ]:
f['last'] = "new Value"
In [ ]:
f['first'] = "new Value2"
In [ ]:
# All Kinds of Fields

g = EasyForm("Field Types")
g.addTextField("Short Text Field", width=10)
g.addTextField("Text Field")
g.addTextArea("Text Area")
g.addTextArea("Tall Text Area", 10, 5)
g.addCheckBox("Check Box")
options = ["a", "b", "c", "d"]
g.addComboBox("Combo Box", options)
g.addComboBox("Combo Box editable", options, editable=True)

g.addList("List", options)
g.addList("List Single", options, multi=False)
g.addList("List Two Row", options, rows=2)

g.addCheckBoxes("Check Boxes", options)
g.addCheckBoxes("Check Boxes H", options, orientation=EasyForm.HORIZONTAL)

g.addRadioButtons("Radio Buttons", options)
g.addRadioButtons("Radio Buttons H", options, orientation=EasyForm.HORIZONTAL)

g.addDatePicker("Date")

g.addButton("Go!", tag="run2")
g
In [ ]:
result = dict()
for child in g:
    result[child] = g[child]

result
In [ ]:
gdp = EasyForm("Field Types")
gdp.addDatePicker("Date")
gdp
In [ ]:
gdp['Date']
In [ ]:
f.put("first", "Micheal")
f.put("last", "Fox")
# Read values from form
firstName = f.get("first")
lastName = f.get("last")

print("Good morning " + firstName + " " + lastName)
In [ ]:
f = EasyForm("actionPerformed demo")
f.addTextField("first")
f['first'] = "First"
b = f.addButton("Action!")
b.actionPerformed = lambda: print("clicked "+f["first"])
f
In [ ]:
import operator

f1 = EasyForm("OnInit and OnChange")
f1.addTextField("first", width=15)
f1.addTextField("last", width=15)\
    .onInit(lambda: operator.setitem(f1, 'last', "setinit1"))\
    .onChange(lambda text: operator.setitem(f1, 'first', text + ' extra'))

button = f1.addButton("action", "action_button")
button.actionPerformed = lambda: operator.setitem(f1, 'last', 'action done')
f1

Default Values and placeholder

In [ ]:
f3c = EasyForm("form3")
f3c = EasyForm("form3")
f3c.addTextArea("Default Value", value = "Initial value")
f3c.addTextArea("Place Holder", placeholder = "Put here some text")
f3c.addCheckBox("Default Checked", value = True)
f3c
In [ ]:
result = dict()
for child in f3c:
    result[child] = f3c[child]

result