91
Programming Challenges / Re: GUI Login
« on: December 28, 2019, 06:58:11 AM »
ScriptBasic Update
Change Log
Change Log
- Fixed hide/show password
- Skip Show Password? checkbox in ZORDER
- Removed dialog max / min titlebar buttons
- ENTER key clicks the Login button
- Optimize and tidy code.
Code: Script BASIC
- ' ScriptBasic / IUP - Login - JRS
- IMPORT iup.bas
- SUB login_clicked
- uid = Iup::GetAttribute(uidtxt,"VALUE")
- IF Iup::GetAttribute(showpwd, "VALUE") = "OFF" THEN
- pwd = Iup::GetAttribute(pwdtxt1,"VALUE")
- ELSE
- pwd = Iup::GetAttribute(pwdtxt2,"VALUE")
- END IF
- IF uid = "John" AND pwd = "Spikowski" THEN
- Iup::Hide errlbl
- Iup::Message "Login", "Login Successful"
- Iup::ExitLoop = TRUE
- ELSE
- Iup::Show errlbl
- Iup::SetFocus uidtxt
- END IF
- END SUB
- SUB show_password
- IF Iup::GetAttribute(showpwd, "VALUE") = "OFF" THEN
- pwd2 = Iup::GetAttribute(pwdtxt2,"VALUE")
- Iup::SetAttribute pwdtxt1, "VALUE", pwd2
- Iup::SetAttribute zbtxt, "VALUE", "pwdtxt1"
- ELSE
- pwd1 = Iup::GetAttribute(pwdtxt1,"VALUE")
- Iup::SetAttribute pwdtxt2, "VALUE", pwd1
- Iup::SetAttribute zbtxt, "VALUE", "pwdtxt2"
- END IF
- END SUB
- SUB Win_exit
- Iup::ExitLoop = TRUE
- END SUB
- ' *** DIALOG ***
- Iup::Open
- dlg = Iup::Create("dialog")
- Iup::SetAttributes dlg, _
- "TITLE=\"Login\", " & _
- "SIZE=200x200, " & _
- "MAXBOX=NO, " & _
- "MINBOX=NO, " & _
- "RESIZE=NO, " & _
- "DEFAULTENTER=\"loginbut\""
- ' *** CONTAINER ***
- vb = Iup::Create("vbox")
- ' *** IMAGE ***
- hb1 = Iup::Create("hbox")
- piclbl = Iup::Create("label")
- Iup::SetAttributes piclbl, _
- "IMAGE=\"./login.png\", " & _
- "EXPAND=HORIZONTAL, " & _
- "ALIGNMENT=ACENTER:ATOP"
- Iup::Append hb1, piclbl
- Iup::Append vb, hb1
- ' *** ERROR ***
- hb2 = Iup::Create("hbox")
- errlbl = Iup::Create("label")
- Iup::SetAttributes errlbl, _
- "TITLE=\"User ID / Password Incorrect\", " & _
- "FGCOLOR=\"#ff0000\", " & _
- "EXPAND=HORIZONTAL, " & _
- "ALIGNMENT=ACENTER"
- Iup::Hide errlbl
- Iup::Append hb2, errlbl
- Iup::Append vb, hb2
- ' *** ENTRY ***
- hb3 = Iup::Create("hbox")
- Iup::SetAttributes hb3, _
- "MARGIN=20x10, " & _
- "GAP=5"
- vb1 = Iup::Create("vbox")
- Iup::SetAttribute vb1, "GAP", "15"
- uidlbl = Iup::Create("label")
- Iup::SetAttribute uidlbl, "TITLE", "User ID"
- Iup::Append vb1, uidlbl
- pwdlbl = Iup::Create("label")
- Iup::SetAttribute pwdlbl, "TITLE", "Password"
- Iup::Append vb1, pwdlbl
- Iup::Append hb3, vb1
- vb2 = Iup::Create("vbox")
- uidtxt = Iup::Create("text")
- Iup::SetAttribute uidtxt, "SIZE", "85x"
- Iup::Append vb2, uidtxt
- pwdtxt1 = Iup::Create("text")
- Iup::SetAttributes pwdtxt1, _
- "PASSWORD=YES, " & _
- "SIZE=85x"
- pwdtxt2 = Iup::Create("text")
- Iup::SetAttribute pwdtxt2, "SIZE", "85x"
- Iup::SetHandle "pwdtxt1", pwdtxt1
- Iup::SetHandle "pwdtxt2", pwdtxt2
- zbtxt = Iup::Zbox(pwdtxt1, pwdtxt2)
- Iup::SetHandle "zbtxt", zbtxt
- Iup::Append vb2, zbtxt
- Iup::Append hb3, vb2
- Iup::Append vb, hb3
- ' *** SHOW/HIDE ***
- hb4 = Iup::Create("hbox")
- Iup::SetAttribute hb4, "MARGIN", "35x"
- showpwd = Iup::Create("toggle")
- Iup::SetAttributes showpwd, _
- "TITLE=\"Show Password?\", " & _
- "CANFOCUS=NO"
- Iup::Append hb4, showpwd
- Iup::Append vb, hb4
- ' *** LOGIN ***
- hb5 = Iup::Create("hbox")
- Iup::SetAttribute hb5, "MARGIN", "40x10"
- loginbut = Iup::Create("button")
- Iup::SetAttributes loginbut, _
- "TITLE=\"Login\", " & _
- "EXPAND=HORIZONTAL"
- Iup::SetHandle "loginbut", loginbut
- iup::Append hb5, loginbut
- iup::Append vb, hb5
- ' *** ATTACH CONTAINER ***
- iup::Append dlg, vb
- ' *** CALLBACKS ***
- Iup::SetCallback dlg,"CLOSE_CB",ADDRESS(Win_exit())
- Iup::SetCallback loginbut, "ACTION", ADDRESS(login_clicked())
- Iup::SetCallback showpwd, "ACTION", ADDRESS(show_password())
- ' *** PROCESS ***
- Iup::Show dlg
- Iup::MainLoop
- Iup::Close