Raspberry BASIC

Recent Posts

Pages: [1] 2 3 ... 10
1
BBC BASIC / Re: BBC BASIC for SDL 2.0 version 1.09a released
« Last post by John Spikowski on January 20, 2020, 02:09:08 AM »
Quote
One valuable side-effect of all these add-ons being themselves coded in BASIC

Couldn't agree more. That is why the C extension modules I write are done in C BASIC.

The reason Nim is attractive is that it's extension are written in Nim.
2
BBC BASIC / Re: BBC BASIC for SDL 2.0 version 1.09a released
« Last post by Richard Russell on January 18, 2020, 08:07:05 PM »
ScriptBasic core hasn't changed since 2005.

For some while my updates have principally been adding to or improving the IDE, libraries, tools and example programs rather than the 'core'.  It's one of the big differences between BBC BASIC for Windows and BBC BASIC for SDL 2.0 of course; in the former the IDE was written in C because at the time (18+ years ago) interpreted BASIC wasn't fast enough for that task.  Now, only the core interpreter needs to be written in assembler code and/or C, everything else (IDE, libraries, tools, utilities) can themselves be written in BASIC, because the performance is acceptable.

One valuable side-effect of all these add-ons being themselves coded in BASIC is that they are automatically CPU and OS-agnostic and will run on all the supported platforms without a build environment (C compiler, linker or whatever) - or the expertise to use it - needing to be available.
3
BBC BASIC / Re: BBC BASIC for SDL 2.0 version 1.09a released
« Last post by John Spikowski on January 18, 2020, 06:16:29 PM »
Great to hear you're approaching production stable status.

ScriptBasic core hasn't changed since 2005.

 If I don't see more members joining the forums I facilitate,  I may put the $130 a month I spend for a AWS server to better use and move everything to GitLab.
4
BBC BASIC / Re: BBC BASIC for SDL 2.0 version 1.09a released
« Last post by Richard Russell on January 18, 2020, 05:21:34 PM »
Glad you're hanging in there keeping BASIC in the forefront.

I'm not sure for how much longer I'll be maintaining the current every-six-weeks (or so) release schedule.  BBC BASIC for SDL 2.0 is getting quite mature now and there's not much that its 'senior' cousin BBC BASIC for Windows can do that BBCSDL can't (apart, obviously, from Windows API-specific things).

One major upgrade which I do hope to achieve is support for the Box2D physics engine (famously behind the Angry Birds franchise) which has been available to BB4W programmers for some years but not yet to BBCSDL programmers.
5
BBC BASIC / Re: BBC BASIC for SDL 2.0 version 1.09a released
« Last post by John Spikowski on January 18, 2020, 08:25:06 AM »
Thanks Richard for the update!

Glad you're hanging in there keeping BASIC in the forefront.
6
BBC BASIC / BBC BASIC for SDL 2.0 version 1.09a released
« Last post by Richard Russell on January 17, 2020, 11:33:56 PM »
I've released version 1.09a of BBC BASIC for SDL 2.0 - the cross-platform programming language for Windows, MacOS, Linux, Raspbian, Android and iOS.  The changes in this version are as follows:

  •   BASIC Interpreter / Run Time Engine

    Worked around a regression in SDL 2.0.10, which caused the fern demo not to run on some platforms.

    Improved compatibility with GCC 4.9.

  •   IDEs and Utilities

    SDLIDE: Added the Memory Usage Monitor (similar to the BB4W equivalent) to the Utilities menu.  Now you can find out how close your program is to running out of memory (or whether you have allocated much more memory than you need!).  The BASIC program must be run in Debug mode for this to work.

  •   Libraries

    Modified dlglib.bbc to improve the responsiveness of the listbox to slow mouse button clicks.

  •   Example Programs

    Updated Ceefax.bbc (and capitalised its name!) to include Weather, Traffic and Local News pages, and to be navigable using an Amazon Fire TV remote.  With the demise of the BBC's digital ('red button') text service at the end of this month, this is my attempt to provide a substitute!  This program also runs in BBC BASIC for Windows if you copy 'Bedstead-ext.otf' into BB4W's LIB directory.

This new version may be downloaded, for all the supported platforms, from the usual location.  The GitHub repository has been updated (used to build the MacOS, Raspbian, iOS and 64-bit Linux editions, currently).

Please remember that if you use the Android Application Generator you should download a new APK template to ensure that any updates to the run-time engine are incorporated in your own apps.
7
Programming Challenges / Re: GUI Login
« Last post by John Spikowski on January 03, 2020, 02:38:56 AM »
Nim Update

I had to rename the db_sqlite open/close procs to sqlopen/sqlclose to prevent a naming conflict with niup.

Code: Text
  1. # Nim 1.0.4 / IUP 3.28 - Login - JRS
  2.  
  3. import niup
  4. import niupext
  5. import db_sqlite
  6. import os
  7. import md5
  8.  
  9. var initdb:bool = existsFile("user.db")
  10. let usrdb = sqlopen("user.db", "", "", "")
  11. if initdb == false:
  12.   usrdb.exec(sql"CREATE TABLE user (UserID VARCHAR NOT NULL, Password VARCHAR NOT NULL, CONSTRAINT user_pk PRIMARY KEY (UserID));")
  13.  
  14. var uidtxt,showpwd,pwdtxt1,pwdtxt2,errlbl,zbtxt,newusr,loginbut:PIhandle
  15. var newusr_cb:string
  16.  
  17. proc Init_Form() =
  18.   Hide(errlbl)
  19.   SetAttribute(uidtxt, "VALUE", "")
  20.   SetAttribute(pwdtxt1, "VALUE", "")
  21.   SetAttribute(pwdtxt2, "VALUE", "")
  22.   SetAttribute(showpwd, "VALUE", "OFF")
  23.   SetAttribute(newusr, "VALUE", "OFF")
  24.   SetAttribute(zbtxt, "VALUE", "pwdtxt1")
  25.   SetAttribute(loginbut, "TITLE", "Login")
  26.   newusr_cb = "OFF"
  27.   SetFocus(uidtxt)
  28.  
  29. proc login_clicked(ih:PIhandle):cint {.cdecl.}=
  30.   var uid:cstring
  31.   var pswd:cstring
  32.   uid = GetAttribute(uidtxt,"VALUE")
  33.   if GetAttribute(showpwd, "VALUE") == "OFF":
  34.     pswd = GetAttribute(pwdtxt1,"VALUE")
  35.   else:
  36.     pswd = GetAttribute(pwdtxt2,"VALUE")
  37.   # *** NEW USER ***
  38.   if newusr_cb == "ON":
  39.     if uid != "" and pswd != "":
  40.       let rtnmsg = usrdb.tryInsertId(sql"INSERT INTO user (UserID, Password) VALUES (?, ?)", uid, getMD5($pswd))
  41.       if rtnmsg == -1:
  42.         SetAttribute(errlbl, "TITLE", "Duplicate User ID")
  43.         Show(errlbl)
  44.         SetFocus(uidtxt)
  45.         return IUP_DEFAULT
  46.       Message("Login",  "User Added")
  47.       Init_Form()
  48.       return
  49.     else:
  50.       Show(errlbl)
  51.       SetFocus(uidtxt)
  52.       return IUP_DEFAULT
  53.  
  54.   # *** LOGIN VERIFY ***
  55.   SetAttribute(errlbl, "TITLE", "User ID / Password Incorrect")
  56.   let dbpw = usrdb.getValue(sql"SELECT Password FROM user WHERE UserID=?", uid)
  57.   if dbpw != "":
  58.     if dbpw == getMD5($pswd):
  59.       Hide(errlbl)
  60.       Message("Login",  "Login Successful")
  61.       Init_Form()
  62.       return IUP_DEFAULT
  63.   Show(errlbl)
  64.   SetFocus(uidtxt)
  65.   return IUP_DEFAULT
  66.  
  67. proc show_password(ih:PIhandle; state: bool):cint {.cdecl.}=
  68.   var pwd1,pwd2:cstring
  69.   if state:
  70.     pwd1 = GetAttribute(pwdtxt1,"VALUE")
  71.     SetAttribute(pwdtxt2, "VALUE", pwd1)
  72.     SetAttribute(zbtxt, "VALUE", "pwdtxt2")
  73.   else:
  74.     pwd2 = GetAttribute(pwdtxt2,"VALUE")
  75.     SetAttribute(pwdtxt1, "VALUE", pwd2)
  76.     SetAttribute(zbtxt, "VALUE", "pwdtxt1")
  77.     return IUP_DEFAULT
  78.  
  79. proc new_user(ih:PIhandle; state: bool):cint {.cdecl.}=
  80.   if state:
  81.     newusr_cb = "ON"
  82.     SetAttribute(loginbut, "TITLE", "Add User")
  83.   else:
  84.     newusr_cb = "OFF"
  85.     SetAttribute(loginbut, "TITLE", "Login")
  86.   return IUP_DEFAULT
  87.  
  88. # *** MAIN ***
  89.  
  90. Open()
  91.  
  92. # *** DIALOG ***
  93. var dlg = Create("dialog")
  94. SetAttributes(dlg,
  95.   "TITLE=\"Login\", " &
  96.   "SIZE=200x200, " &
  97.   "MAXBOX=NO, " &
  98.   "MINBOX=NO, " &
  99.   "RESIZE=NO, " &
  100.   "DEFAULTENTER=\"loginbut\"")
  101.  
  102. # *** CONTAINER ***
  103. var vb = Create("vbox")
  104.  
  105. # *** IMAGE ***
  106. var hb1 = Create("hbox")
  107. var piclbl = Create("label")
  108. SetAttributes(piclbl,
  109.   "IMAGE=\"login.png\", " &
  110.   "EXPAND=HORIZONTAL, " &
  111.   "ALIGNMENT=ACENTER:ATOP")
  112. discard Append(hb1, piclbl)
  113. discard Append(vb, hb1)
  114.  
  115. # *** ERROR ***
  116. var hb2 = Create("hbox")
  117. errlbl = Create("label")
  118. SetAttributes(errlbl,
  119.   "TITLE=\"User ID / Password Incorrect\", " &
  120.   "FGCOLOR=\"#ff0000\", " &
  121.   "EXPAND=HORIZONTAL, " &
  122.   "ALIGNMENT=ACENTER")
  123. Hide(errlbl)
  124. discard Append(hb2, errlbl)
  125. discard Append(vb, hb2)
  126.  
  127. # *** ENTRY ***
  128. var hb3 = Create("hbox")
  129. SetAttributes(hb3,
  130.   "MARGIN=20x10, " &
  131.   "GAP=5")
  132. var vb1 = Create("vbox")
  133. SetAttribute(vb1, "GAP", "15")
  134. var uidlbl = Create("label")
  135. SetAttribute(uidlbl, "TITLE", "User ID")
  136. discard Append(vb1, uidlbl)
  137. var pwdlbl = Create("label")
  138. SetAttribute(pwdlbl, "TITLE", "Password")
  139. discard Append(vb1, pwdlbl)
  140. discard Append(hb3, vb1)
  141. var vb2 = Create("vbox")
  142. uidtxt = Create("text")
  143. SetAttribute(uidtxt, "SIZE", "85x")
  144. discard Append(vb2, uidtxt)
  145. pwdtxt1 = Create("text")
  146. SetAttributes(pwdtxt1,
  147.   "PASSWORD=YES, " &
  148.   "SIZE=85x")
  149. pwdtxt2 = Create("text")
  150. SetAttribute(pwdtxt2, "SIZE", "85x")
  151. SetHandle("pwdtxt1", pwdtxt1)
  152. SetHandle("pwdtxt2", pwdtxt2)
  153. zbtxt = Zbox(pwdtxt1, pwdtxt2, nil)
  154. SetHandle("zbtxt", zbtxt)
  155. discard Append(vb2, zbtxt)
  156. discard Append(hb3, vb2)
  157. discard Append(vb, hb3)
  158.  
  159. # *** SHOW/HIDE ***
  160. var hb4 = Create("hbox")
  161. SetAttributes(hb4,
  162.   "MARGIN=35x, " &
  163.   "GAP=40")
  164. showpwd = Create("toggle")
  165. SetAttributes(showpwd,
  166.   "TITLE=\"Show Password\", " &
  167.   "CANFOCUS=NO")
  168. newusr = Create("toggle")
  169. SetAttributes(newusr,
  170.   "TITLE=\"New User\", " &
  171.   "CANFOCUS=NO")
  172. discard Append(hb4, showpwd)
  173. discard Append(hb4, newusr)
  174. discard Append(vb, hb4)
  175.  
  176. # *** LOGIN ***
  177. var hb5 = Create("hbox")
  178. SetAttribute(hb5, "MARGIN", "40x10")
  179. loginbut = Create("button")
  180. SetAttributes(loginbut,
  181.   "TITLE=\"Login\", " &
  182.   "EXPAND=HORIZONTAL")
  183. SetHandle("loginbut", loginbut)
  184. discard Append(hb5, loginbut)
  185. discard Append(vb, hb5)
  186.  
  187. # *** ATTACH CONTAINER ***
  188. discard Append(dlg, vb)
  189.  
  190. # *** CALLBACKS ***
  191. SetCallback(loginbut, "ACTION", login_clicked)
  192. SetCallback(showpwd, "ACTION", show_password)
  193. SetCallback(newusr, "ACTION", new_user)
  194.  
  195. # *** PROCESS ***
  196. Show(dlg)
  197. MainLoop()
  198. sqlclose(usrdb)
  199. Close()
  200.  


ubuntu@rpi4b:~/guilc/nim-dev$ scriba showdb.sb
John   -   0b7efaa91a48ccd6c1dd58e3d69ea1a0
AIR   -   4de6ff4050222c488aa16286c39a605b
ubuntu@rpi4b:~/guilc/nim-dev$


Note: The screenshots are the same as the latest ScriptBasic submission.

8
Programming Challenges / Re: GUI Login
« Last post by jalih on January 01, 2020, 04:11:06 PM »
Here is a updated 8th login dialog with database support for retrieving stored user data.

I currently generate 32 byte random buffer from the cryptographically strong random source and convert it to hex string for the salt. Key for user chosen password is generated with PBKDF2 algorithm using previously randomly generated salt and 10000 iterations as parameters. Username, key and salt is then stored into database.

Code: [Select]
requires gui

var userdb

defer: auth

{
  kind: "edit",
  bounds: "edit1.left, lbl2.top, parent.width-20, top+24",
  name: "edit2",
  max-text: 32,
  password-char: "*",
  return-pressed: ' auth ,
  text-changed: ( "lbl0" g:child "" g:text drop )
} g:new constant edit2-hide-passwd

{
  kind: "edit",
  bounds: "edit1.left, lbl2.top, parent.width-20, top+24",
  name: "edit2",
  max-text: 32,
  password-char: "",
  return-pressed: ' auth ,
  text-changed: ( "lbl0" g:child "" g:text drop )
} g:new constant edit2-show-passwd

: alternator \ a -- a[0]
  a:shift dup >r
  a:push drop r> ;

[ ` edit2-show-passwd ` , ` edit2-hide-passwd ` ] ' alternator curry: next-state

\ auth states
0 constant NOT-FOUND
1 constant USER-PASSWD-MATCH
2 constant USER-PASSWD-FAIL

: auth-from-db \ id passwd -- state
  s:len 0 n:= if
    2drop
    USER-PASSWD-FAIL
    ;;
  then
  >r >r
  userdb @ "by-id" r> 1 a:close db:bind-exec[]
  a:len 0 n:> if
    a:open
    "salt" m:@ r> swap 10000 cr:genkey
    swap "key" m:@ nip b:= if
      USER-PASSWD-MATCH
    else
      USER-PASSWD-FAIL
    then
  else
    drop
    rdrop
    NOT-FOUND
  then
  nip ;

: authenticate
  "edit2" g:child g:text? >r
  "edit1" g:child g:text? r> auth-from-db

   [ ( "lbl0" g:child "User not found!" g:text ) ,
     ( "Authenticated!" . cr bye ) ,
     ( "lbl0" g:child "User and password don't match!" g:text )  ] swap
   caseof drop ;

' authenticate w:is auth

: init
  "mytest.db" f:slurp "No database" thrownull
  db:open
  \ make a prepared statement
  "SELECT * FROM user WHERE id=? LIMIT 1" "by-id" db:prep-name
  userdb ! "edit1" g:child g:focus  ;

{
  kind: "win",
  buttons: 5,
  native-title-bar: false,
  title: "Login",
  wide: 520,
  high: 220,
  resizable: false,
  center: true,
  init: ' init ,
  children:
  [
    {
      kind: "box",
      name: "frame",
      bounds: "0, 0, parent.width, parent.height",
      bg: "gray",
      children:
      [
        {
          kind: "image",
          bounds: "parent.left+10, parent.top+10, left+128, top+128",
          img: "8thlogo.png",
          name: "logo"
        },
        {
          kind: "label",
          fg: "red",
          font: 20,
          label: "",
          bounds: "logo.right+20, parent.top+10, parent.width-10, top+24 ",
          justify: ["hcenter"],
          name: "lbl0"
        },
        {
          kind: "label",
          label: "Username:",
          bounds: "logo.right+20, lbl0.bottom+20, left+80, top+24 ",
          name: "lbl1"
        },
        {
          kind: "edit",
          bounds: "lbl1.right+10, lbl1.top, parent.width-20, top+24",
          name: "edit1",
          max-text: 32,
          return-pressed: ( "edit2" g:child g:focus drop ),
          text-changed: ( "lbl0" g:child "" g:text drop )
        },
        {
          kind: "label",
          label: "Password:",
          bounds: "lbl1.left, lbl1.bottom+10, left+80, top+24",
          name: "lbl2"
        },
        {
          kind: "edit",
          bounds: "edit1.left, lbl2.top, parent.width-20, top+24",
          name: "edit2",
          max-text: 32,
          password-char: "*",
          return-pressed: ' authenticate ,
          text-changed: ( "lbl0" g:child "" g:text drop )
        },
        {
          kind: "toggle",
          label: "Show password",
          adjustwidth: true,
          bounds: "edit1.left, lbl2.bottom+20, left+100, top+24",
          name: "toggle",
          click: ( "edit2" g:child g:text? >r "frame" g:child "edit2" g:-child next-state g:+child "edit2" g:child r> g:text drop )
        },
        {
          kind: "btn",
          label: "Login",
          bg: "darkgray",
          bounds: "lbl2.left, lbl2.bottom+60, edit1.right, top+30",
          name: "button",
          tooltip: "Login to account",
          click: ' authenticate
        }
      ]
    }
  ]
} g:new var, gui

: app:main
  ( userdb @ db:close ) onexit ;

I currently manually generate user database with the following piece of 8th code:
Code: [Select]
"Creating a database and adding data:\n" .

\ remove previous db:
"mytest.db" f:rm

\ open a database:
"mytest.db" db:open "Could not create database" thrownull nip

\ create a table
"CREATE TABLE user (id PRIMARY KEY, key, salt)" db:exec

\ make a prepared statement
"INSERT INTO user VALUES (?, ?, ?);" "insert" db:prep-name

: build-params  \ id passwd -- a
  cr:uuid >r
  r@ 10000 cr:genkey
  r>
  3 a:close ;

\ insert into table using a parameterized statement
\ You could use t:err? to get map of error information
"insert" "jalih" "pa$$w0rd!" build-params null db:bind-exec
"insert" "guest" "guest" build-params null db:bind-exec
"insert" "john" "hard-passwd" build-params null db:bind-exec
"insert" "air" "crack-this" build-params null db:bind-exec

\ and close the database
"All done!\n" .
db:close
bye
9
Programming Challenges / Re: GUI Login
« Last post by John Spikowski on December 31, 2019, 10:15:55 PM »
ScriptBasic Update

This version adds Jalih's suggestion of maintaining a database of UserID and Password (encrypted) as an extension to the base challenge.

Change Log
  • Added check for duplicate UserID's. 12/31
  • Fixed MD5 hex string to be a constant 32 bytes. 12/31
  • Reset error message to login error after a duplicate user add. 1/1

Code: Script BASIC
  1. ' ScriptBasic / IUP - Login - JRS
  2.  
  3. IMPORT iup.bas
  4. IMPORT sqlite.bas
  5. DECLARE SUB MD5 ALIAS "md5fun" LIB "t"
  6.  
  7. initdb = FILELEN("user.db")
  8. usrdb = sqlite::open("user.db")
  9. IF initdb = 0 THEN
  10.   sqlite::execute(usrdb,"CREATE TABLE user (" & _
  11.     "UserID VARCHAR NOT NULL, " & _
  12.     "Password VARCHAR NOT NULL, " & _
  13.     "CONSTRAINT user_pk PRIMARY KEY (UserID));")
  14. END IF
  15.  
  16. SUB login_clicked
  17.   uid = Iup::GetAttribute(uidtxt,"VALUE")
  18.   IF Iup::GetAttribute(showpwd, "VALUE") = "OFF" THEN
  19.     pwd = Iup::GetAttribute(pwdtxt1,"VALUE")
  20.   ELSE
  21.     pwd = Iup::GetAttribute(pwdtxt2,"VALUE")
  22.   END IF
  23.   ' *** NEW USER ***
  24.  IF newusr_cb = "ON" THEN
  25.     IF uid <> "" AND pwd <> "" THEN
  26.       rtnmsg = sqlite::execute(usrdb,"INSERT INTO user VALUES ('" & uid & "', '" & MD5STR(pwd) & "');")
  27.       IF rtnmsg = 19 THEN
  28.         Iup::SetAttribute errlbl, "TITLE", "Duplicate User ID"
  29.         Iup::Show errlbl
  30.         Iup::SetFocus uidtxt
  31.         EXIT SUB
  32.       END IF
  33.       Iup::Message "Login",  "User Added"
  34.       GOSUB Init_Form
  35.       EXIT SUB
  36.     ELSE
  37.       Iup::Show errlbl
  38.       Iup::SetFocus uidtxt
  39.       EXIT SUB
  40.     END IF
  41.   END IF
  42.   ' *** LOGIN VERIFY ***
  43.  Iup::SetAttribute errlbl, "TITLE", "User ID / Password Incorrect"
  44.   stmt = sqlite::query(usrdb,"SELECT Password FROM user WHERE UserID = '" & uid & "';")
  45.   IF sqlite::row(stmt) = sqlite::SQLITE3_ROW THEN
  46.     sqlite::fetchhash(stmt, col)
  47.     IF col{"Password"} = MD5STR(pwd) THEN
  48.       Iup::Hide errlbl
  49.       Iup::Message "Login",  "Login Successful"
  50.       GOSUB Init_Form
  51.       EXIT SUB
  52.     END IF
  53.   END IF
  54.   Iup::Show errlbl
  55.   Iup::SetFocus uidtxt
  56.   EXIT SUB
  57.   Init_Form:
  58.     Iup::Hide errlbl
  59.     Iup::SetAttribute uidtxt, "VALUE", ""
  60.     Iup::SetAttribute pwdtxt1, "VALUE", ""
  61.     Iup::SetAttribute pwdtxt2, "VALUE", ""
  62.     Iup::SetAttribute showpwd, "VALUE", "OFF"
  63.     Iup::SetAttribute newusr, "VALUE", "OFF"
  64.     Iup::SetAttribute zbtxt, "VALUE", "pwdtxt1"
  65.     Iup::SetAttribute loginbut, "TITLE", "Login"
  66.     newusr_cb = "OFF"
  67.     Iup::SetFocus uidtxt
  68.   RETURN
  69. END SUB
  70.  
  71. FUNCTION MD5STR(txtstr)
  72.   LOCAL tmpstr, hexstr, x
  73.   tmpstr = MD5(txtstr)
  74.   FOR x = 1 TO 16
  75.     hexstr &= RIGHT("0" & HEX(ASC(MID(tmpstr, x, 1))), 2)
  76.   NEXT
  77.   MD5STR = hexstr
  78. END FUNCTION
  79.  
  80. SUB show_password
  81.   IF Iup::GetAttribute(showpwd, "VALUE") = "OFF" THEN
  82.     pwd2 = Iup::GetAttribute(pwdtxt2,"VALUE")
  83.     Iup::SetAttribute pwdtxt1, "VALUE", pwd2
  84.     Iup::SetAttribute zbtxt, "VALUE", "pwdtxt1"
  85.   ELSE
  86.     pwd1 = Iup::GetAttribute(pwdtxt1,"VALUE")
  87.     Iup::SetAttribute pwdtxt2, "VALUE", pwd1
  88.     Iup::SetAttribute zbtxt, "VALUE", "pwdtxt2"
  89.   END IF
  90. END SUB
  91.  
  92. SUB new_user
  93.   newusr_cb =Iup::GetAttribute(newusr, "VALUE")
  94.   IF newusr_cb = "ON" THEN
  95.     Iup::SetAttribute loginbut, "TITLE", "Add User"
  96.   ELSE
  97.     Iup::SetAttribute loginbut, "TITLE", "Login"
  98.   END IF
  99. END SUB  
  100.  
  101. SUB Win_exit
  102.   Iup::ExitLoop = TRUE
  103. END SUB
  104.  
  105. ' *** DIALOG ***
  106. Iup::Open
  107. dlg = Iup::Create("dialog")
  108. Iup::SetAttributes dlg, _
  109.   "TITLE=\"Login\", " & _
  110.   "SIZE=200x200, " & _
  111.   "MAXBOX=NO, " & _
  112.   "MINBOX=NO, " & _
  113.   "RESIZE=NO, " & _
  114.   "DEFAULTENTER=\"loginbut\""
  115.  
  116. ' *** CONTAINER ***
  117. vb = Iup::Create("vbox")
  118.  
  119. ' *** IMAGE ***
  120. hb1 = Iup::Create("hbox")
  121. piclbl = Iup::Create("label")
  122. Iup::SetAttributes piclbl, _
  123.   "IMAGE=\"./login.png\", " & _
  124.   "EXPAND=HORIZONTAL, " & _
  125.   "ALIGNMENT=ACENTER:ATOP"
  126. Iup::Append hb1, piclbl
  127. Iup::Append vb, hb1
  128.  
  129. ' *** ERROR ***
  130. hb2 = Iup::Create("hbox")
  131. errlbl = Iup::Create("label")
  132. Iup::SetAttributes errlbl, _
  133.   "TITLE=\"User ID / Password Incorrect\", " & _
  134.   "FGCOLOR=\"#ff0000\", " & _
  135.   "EXPAND=HORIZONTAL, " & _
  136.   "ALIGNMENT=ACENTER"
  137. Iup::Hide errlbl
  138. Iup::Append hb2, errlbl
  139. Iup::Append vb, hb2
  140.  
  141. ' *** ENTRY ***
  142. hb3 = Iup::Create("hbox")
  143. Iup::SetAttributes hb3, _
  144.   "MARGIN=20x10, " & _
  145.   "GAP=5"
  146. vb1 = Iup::Create("vbox")
  147. Iup::SetAttribute vb1, "GAP", "15"
  148. uidlbl = Iup::Create("label")
  149. Iup::SetAttribute uidlbl, "TITLE", "User ID"
  150. Iup::Append vb1, uidlbl
  151. pwdlbl = Iup::Create("label")
  152. Iup::SetAttribute pwdlbl, "TITLE", "Password"
  153. Iup::Append vb1, pwdlbl
  154. Iup::Append hb3, vb1
  155. vb2 = Iup::Create("vbox")
  156. uidtxt = Iup::Create("text")
  157. Iup::SetAttribute uidtxt, "SIZE", "85x"
  158. Iup::Append vb2, uidtxt
  159. pwdtxt1 = Iup::Create("text")
  160. Iup::SetAttributes pwdtxt1, _
  161.   "PASSWORD=YES, " & _
  162.   "SIZE=85x"
  163. pwdtxt2 = Iup::Create("text")
  164. Iup::SetAttribute pwdtxt2, "SIZE", "85x"
  165. Iup::SetHandle "pwdtxt1", pwdtxt1
  166. Iup::SetHandle "pwdtxt2", pwdtxt2
  167. zbtxt = Iup::Zbox(pwdtxt1, pwdtxt2)
  168. Iup::SetHandle "zbtxt", zbtxt
  169. Iup::Append vb2, zbtxt
  170. Iup::Append hb3, vb2
  171. Iup::Append vb, hb3
  172.  
  173. ' *** SHOW/HIDE ***
  174. hb4 = Iup::Create("hbox")
  175. Iup::SetAttributes hb4, _
  176.  "MARGIN=35x, " & _
  177.  "GAP=40"
  178. showpwd = Iup::Create("toggle")
  179. Iup::SetAttributes showpwd, _
  180.   "TITLE=\"Show Password\", " & _
  181.   "CANFOCUS=NO"
  182. newusr = Iup::Create("toggle")
  183. Iup::SetAttributes newusr, _
  184.   "TITLE=\"New User\", " & _
  185.   "CANFOCUS=NO"
  186. Iup::Append hb4, showpwd
  187. Iup::Append hb4, newusr
  188. Iup::Append vb, hb4
  189.  
  190. ' *** LOGIN ***
  191. hb5 = Iup::Create("hbox")
  192. Iup::SetAttribute hb5, "MARGIN", "40x10"
  193. loginbut = Iup::Create("button")
  194. Iup::SetAttributes loginbut, _
  195.   "TITLE=\"Login\", " & _
  196.   "EXPAND=HORIZONTAL"
  197. Iup::SetHandle "loginbut", loginbut
  198. iup::Append hb5, loginbut
  199. iup::Append vb, hb5
  200.  
  201. ' *** ATTACH CONTAINER ***
  202. iup::Append  dlg, vb
  203.  
  204. ' *** CALLBACKS ***
  205. Iup::SetCallback dlg,"CLOSE_CB",ADDRESS(Win_exit())
  206. Iup::SetCallback loginbut, "ACTION", ADDRESS(login_clicked())
  207. Iup::SetCallback showpwd, "ACTION", ADDRESS(show_password())
  208. Iup::SetCallback newusr, "ACTION", ADDRESS(new_user())
  209.  
  210. ' *** PROCESS ***
  211. ' Iup::Show(Iup::LayoutDialog(dlg))
  212. Iup::Show(dlg)
  213. Iup::MainLoop
  214. Iup::Close
  215. sqlite::Close(usrdb)
  216.  


ubuntu@rpi4b:~/guilc/sb-dev$ scriba showdb.sb
John  -  FAF43E604E6A820CAAAB88BF7E2328C7
AIR   -  99B69173F38EB9F24FA4C05B4BE47CD7
Jalih -  78020D21C627349463D88142DC51F9B9
Peter -  0C5213856A47300D1E6D30CA00FAFFC1
ubuntu@rpi4b:~/guilc/sb-dev$



10
Programming Challenges / Re: GUI Login
« Last post by John Spikowski on December 31, 2019, 03:03:38 AM »
It turns out my .bmp image needed to be 24 bit color depth. The conversion from .png to .bmp didn't maintain the transparency of the background.

I also learned how to create Windows executables rather than default console apps.

nim --app:gui c login.nim

I'm going to start a thread on AllBASIC for the Windows / Nim / IUP direction. Maybe Mike will show some interest.



Pages: [1] 2 3 ... 10