Raspberry BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - John Spikowski

Pages: 1 [2] 3 4 ... 11
16
Nim / Re: Nim Manual
« on: December 28, 2019, 06:32:51 PM »
I ran into another Nim language reference from MIT that is a good resource.

Nim Language Reference

17
Programming Challenges / Re: GUI Login
« on: December 28, 2019, 06:58:11 AM »
ScriptBasic Update

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
  1. ' ScriptBasic / IUP - Login - JRS
  2.  
  3. IMPORT iup.bas
  4.  
  5. SUB login_clicked
  6.   uid = Iup::GetAttribute(uidtxt,"VALUE")
  7.   IF Iup::GetAttribute(showpwd, "VALUE") = "OFF" THEN
  8.     pwd = Iup::GetAttribute(pwdtxt1,"VALUE")
  9.   ELSE
  10.     pwd = Iup::GetAttribute(pwdtxt2,"VALUE")
  11.   END IF
  12.   IF uid = "John" AND pwd = "Spikowski" THEN
  13.     Iup::Hide errlbl
  14.     Iup::Message "Login",  "Login Successful"
  15.     Iup::ExitLoop = TRUE
  16.   ELSE
  17.     Iup::Show errlbl
  18.     Iup::SetFocus uidtxt
  19.   END IF
  20. END SUB
  21.  
  22. SUB show_password
  23.   IF Iup::GetAttribute(showpwd, "VALUE") = "OFF" THEN
  24.     pwd2 = Iup::GetAttribute(pwdtxt2,"VALUE")
  25.     Iup::SetAttribute pwdtxt1, "VALUE", pwd2
  26.     Iup::SetAttribute zbtxt, "VALUE", "pwdtxt1"
  27.   ELSE
  28.     pwd1 = Iup::GetAttribute(pwdtxt1,"VALUE")
  29.     Iup::SetAttribute pwdtxt2, "VALUE", pwd1
  30.     Iup::SetAttribute zbtxt, "VALUE", "pwdtxt2"
  31.   END IF
  32. END SUB
  33.  
  34. SUB Win_exit
  35.   Iup::ExitLoop = TRUE
  36. END SUB
  37.  
  38. ' *** DIALOG ***
  39. Iup::Open
  40. dlg = Iup::Create("dialog")
  41. Iup::SetAttributes dlg, _
  42.   "TITLE=\"Login\", " & _
  43.   "SIZE=200x200, " & _
  44.   "MAXBOX=NO, " & _
  45.   "MINBOX=NO, " & _
  46.   "RESIZE=NO, " & _
  47.   "DEFAULTENTER=\"loginbut\""
  48.  
  49. ' *** CONTAINER ***
  50. vb = Iup::Create("vbox")
  51.  
  52. ' *** IMAGE ***
  53. hb1 = Iup::Create("hbox")
  54. piclbl = Iup::Create("label")
  55. Iup::SetAttributes piclbl, _
  56.   "IMAGE=\"./login.png\", " & _
  57.   "EXPAND=HORIZONTAL, " & _
  58.   "ALIGNMENT=ACENTER:ATOP"
  59. Iup::Append hb1, piclbl
  60. Iup::Append vb, hb1
  61.  
  62. ' *** ERROR ***
  63. hb2 = Iup::Create("hbox")
  64. errlbl = Iup::Create("label")
  65. Iup::SetAttributes errlbl, _
  66.   "TITLE=\"User ID / Password Incorrect\", " & _
  67.   "FGCOLOR=\"#ff0000\", " & _
  68.   "EXPAND=HORIZONTAL, " & _
  69.   "ALIGNMENT=ACENTER"
  70. Iup::Hide errlbl
  71. Iup::Append hb2, errlbl
  72. Iup::Append vb, hb2
  73.  
  74. ' *** ENTRY ***
  75. hb3 = Iup::Create("hbox")
  76. Iup::SetAttributes hb3, _
  77.   "MARGIN=20x10, " & _
  78.   "GAP=5"
  79. vb1 = Iup::Create("vbox")
  80. Iup::SetAttribute vb1, "GAP", "15"
  81. uidlbl = Iup::Create("label")
  82. Iup::SetAttribute uidlbl, "TITLE", "User ID"
  83. Iup::Append vb1, uidlbl
  84. pwdlbl = Iup::Create("label")
  85. Iup::SetAttribute pwdlbl, "TITLE", "Password"
  86. Iup::Append vb1, pwdlbl
  87. Iup::Append hb3, vb1
  88. vb2 = Iup::Create("vbox")
  89. uidtxt = Iup::Create("text")
  90. Iup::SetAttribute uidtxt, "SIZE", "85x"
  91. Iup::Append vb2, uidtxt
  92. pwdtxt1 = Iup::Create("text")
  93. Iup::SetAttributes pwdtxt1, _
  94.   "PASSWORD=YES, " & _
  95.   "SIZE=85x"
  96. pwdtxt2 = Iup::Create("text")
  97. Iup::SetAttribute pwdtxt2, "SIZE", "85x"
  98. Iup::SetHandle "pwdtxt1", pwdtxt1
  99. Iup::SetHandle "pwdtxt2", pwdtxt2
  100. zbtxt = Iup::Zbox(pwdtxt1, pwdtxt2)
  101. Iup::SetHandle "zbtxt", zbtxt
  102. Iup::Append vb2, zbtxt
  103. Iup::Append hb3, vb2
  104. Iup::Append vb, hb3
  105.  
  106. ' *** SHOW/HIDE ***
  107. hb4 = Iup::Create("hbox")
  108. Iup::SetAttribute hb4, "MARGIN", "35x"
  109. showpwd = Iup::Create("toggle")
  110. Iup::SetAttributes showpwd, _
  111.   "TITLE=\"Show Password?\", " & _
  112.   "CANFOCUS=NO"
  113. Iup::Append hb4, showpwd
  114. Iup::Append vb, hb4
  115.  
  116. ' *** LOGIN ***
  117. hb5 = Iup::Create("hbox")
  118. Iup::SetAttribute hb5, "MARGIN", "40x10"
  119. loginbut = Iup::Create("button")
  120. Iup::SetAttributes loginbut, _
  121.   "TITLE=\"Login\", " & _
  122.   "EXPAND=HORIZONTAL"
  123. Iup::SetHandle "loginbut", loginbut
  124. iup::Append hb5, loginbut
  125. iup::Append vb, hb5
  126.  
  127. ' *** ATTACH CONTAINER ***
  128. iup::Append  dlg, vb
  129.  
  130. ' *** CALLBACKS ***
  131. Iup::SetCallback dlg,"CLOSE_CB",ADDRESS(Win_exit())
  132. Iup::SetCallback loginbut, "ACTION", ADDRESS(login_clicked())
  133. Iup::SetCallback showpwd, "ACTION", ADDRESS(show_password())
  134.  
  135. ' *** PROCESS ***
  136. Iup::Show dlg
  137. Iup::MainLoop
  138. Iup::Close
  139.  


18
Programming Challenges / Re: GUI Login
« on: December 27, 2019, 10:10:53 PM »
8th Update (Jalih submission)

Code: Text
  1. requires gui
  2.  
  3. var gui
  4.  
  5. { guest: "pa$$w0rd!" } constant passwords
  6.  
  7. : authenticate
  8.   "edit1" g:child g:text? passwords swap m:@ nip null? if
  9.     drop
  10.     "lbl0" g:child
  11.     "User not found!" g:text drop
  12.   else
  13.     swap
  14.     "edit2" g:child g:text? rot s:= if
  15.      "Authenticated!" . cr
  16.      bye
  17.     else
  18.       "lbl0" g:child
  19.       "Username and password don't match!" g:text drop
  20.     then
  21.   then ;
  22.  
  23. {
  24.   kind: "win",
  25.   buttons: 0,
  26.   native-title-bar: false,
  27.   title: "Login",
  28.   wide: 520,
  29.   high: 200,
  30.   resizable: false,
  31.   center: true,
  32.   init: ( gui ! ),
  33.   children:
  34.   [
  35.     {
  36.       kind: "box",
  37.       name: "frame",
  38.       bounds: "0, 0, parent.width, parent.height",
  39.       bg: "gray",
  40.       children:
  41.       [
  42.         {
  43.           kind: "image",
  44.           bounds: "parent.left+10, parent.top+10, left+128, top+128",
  45.           img: "8thlogo.png",
  46.           name: "logo"    
  47.         },
  48.         {
  49.           kind: "label",
  50.           fg: "blue",
  51.           font: 20,
  52.           label: "",
  53.           bounds: "logo.right+20, parent.top+10, parent.width-10, top+24 ",
  54.           justify: ["hcenter"],
  55.           name: "lbl0"
  56.         },
  57.         {
  58.           kind: "label",
  59.           label: "Username:",
  60.           bounds: "logo.right+20, lbl0.bottom+20, left+80, top+24 ",
  61.           name: "lbl1"
  62.         },
  63.         {
  64.           kind: "edit",
  65.           bounds: "lbl1.right+10, lbl1.top, parent.width-20, top+24",
  66.           name: "edit1",
  67.           max-text: 32
  68.         },
  69.         {
  70.           kind: "label",
  71.           label: "Password:",
  72.           bounds: "lbl1.left, lbl1.bottom+10, left+80, top+24",
  73.           name: "lbl2"
  74.         },
  75.         {
  76.           kind: "edit",
  77.           bounds: "edit1.left, lbl2.top, parent.width-20, top+24",
  78.           name: "edit2",
  79.           max-text: 32,
  80.           password-char: "*"
  81.         },
  82.         {
  83.           kind: "btn",
  84.           label: "Login",
  85.           bg: "darkgray",
  86.           bounds: "lbl2.left, lbl2.bottom+20, edit2.right, top+30",
  87.           name: "button",
  88.           tooltip: "Login to account",
  89.           click: ' authenticate
  90.         }
  91.       ]
  92.     }
  93.   ]
  94. } var, gui-desc
  95.  
  96. : app:main
  97.   gui-desc @ g:new ;
  98.  

19
Programming Challenges / Re: GUI Login
« on: December 27, 2019, 03:17:03 PM »
C Update (AIR submission)

Code: C
  1. * logon2.c
  2.  *
  3.  * version 1.1
  4.  *
  5.  * GUI Logon Screen Challenge Submission
  6.  * C version, using GTK+-3.0
  7.  *
  8.  * Written by Armando I. Rivera (AIR)
  9.  *
  10.  * Compile:  gcc logon2.c $(pkg-config --libs --cflags gtk+-3.0) -o logon2
  11. */
  12.  
  13.  
  14. #include <gtk/gtk.h>
  15.  
  16. GtkWidget *err_label;
  17.  
  18. void onClick( GtkWidget *widget, gpointer   data ) {
  19.     gchar *stupid_password = "pa$$w0rd!";
  20.     gchar *user_password;
  21.     g_object_get(data,"text",&user_password,NULL);
  22.  
  23.     if (g_strcmp0 (stupid_password,user_password) == 0) {
  24.         g_print("Your are now logged in!\n");
  25.         gtk_main_quit();
  26.     }else{
  27.         gtk_label_set_markup(GTK_LABEL(err_label), "<span color=\"red\" font_desc=\"16.0\">** Invalid Password **</span>");
  28.         g_print("Username or Password is Incorrect!\n");
  29.  
  30.     }
  31. }
  32.  
  33. int main( int argc, char *argv[])
  34. {
  35.     GtkWidget *window, *layout, *image, *btnLogin;
  36.     GtkWidget *lblUser, *lblPass, *txtUser, *txtPass;
  37.  
  38.     gtk_init(&argc, &argv);
  39.    
  40.     layout = gtk_layout_new(NULL, NULL);
  41.  
  42.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  43.     g_object_set(window,
  44.                 "title","Login",
  45.                 "default-width",660,
  46.                 "default-height",370,
  47.                 "resizable",FALSE,
  48.                 "window-position",GTK_WIN_POS_CENTER,
  49.                 "child",layout,
  50.                 "decorated",0,
  51.                 NULL);
  52.  
  53.  
  54.     image = gtk_image_new_from_file("logon.png");
  55.     g_object_set(layout,"child",image,"margin",10,NULL);
  56.    
  57.     lblUser = gtk_label_new("");
  58.     lblPass = gtk_label_new("");
  59.     err_label = gtk_label_new("");
  60.     g_object_set(err_label,"width-request",270,NULL);
  61.    
  62.     gtk_label_set_markup(GTK_LABEL(lblUser), "<span font_desc=\"16.0\">Username:</span>");
  63.     gtk_label_set_markup(GTK_LABEL(lblPass), "<span font_desc=\"16.0\">Password:</span>");
  64.    
  65.     txtUser = gtk_entry_new();
  66.     txtPass = gtk_entry_new();
  67.    
  68.    
  69.     g_object_set(txtPass,"visibility", FALSE,NULL);
  70.    
  71.     btnLogin = gtk_button_new_with_label("Login");
  72.     g_object_set(btnLogin,"width-request",170,NULL);
  73.  
  74.  
  75.     gtk_layout_put(GTK_LAYOUT(layout), lblUser, 330, 112);
  76.     gtk_layout_put(GTK_LAYOUT(layout), lblPass, 330, 162);
  77.     gtk_layout_put(GTK_LAYOUT(layout), txtUser, 460, 110);
  78.     gtk_layout_put(GTK_LAYOUT(layout), txtPass, 460, 160);
  79.     gtk_layout_put(GTK_LAYOUT(layout), btnLogin, 460, 210);
  80.     gtk_layout_put(GTK_LAYOUT(layout), err_label, 300, 16);
  81.  
  82.     g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  83.     g_signal_connect (btnLogin, "clicked", G_CALLBACK (onClick), txtPass);
  84.  
  85.     gtk_widget_show_all(window);
  86.  
  87.     gtk_main();
  88.  
  89.     return 0;
  90. }
  91.  

20
Programming Challenges / Re: GUI Login
« on: December 27, 2019, 03:02:38 AM »
ScriptBasic

Code: Script BASIC
  1. ' ScriptBasic / IUP - Login - JRS
  2.  
  3. IMPORT iup.bas
  4.  
  5. SUB login_clicked
  6.   uid = Iup::GetAttribute(uidtxt,"VALUE")
  7.   pwd = Iup::GetAttribute(pwdtxt,"VALUE")
  8.   IF uid = "John" AND pwd = "Spikowski" THEN
  9.     Iup::Hide(errlbl)
  10.     Iup::Message("Login",  "Login Successful")
  11.     Iup::ExitLoop = TRUE
  12.   ELSE
  13.     Iup::Show(errlbl)
  14.     Iup::SetFocus(uidtxt)
  15.   END IF
  16. END SUB
  17.  
  18. SUB show_password
  19.   showcb = Iup::GetAttribute(showpwd, "VALUE")
  20.   IF showcb = "ON" THEN
  21.     Iup::SetAttribute(pwdtxt, "PASSWORD", "NO")
  22.   ELSE
  23.     Iup::SetAttribute(pwdtxt, "PASSWORD", "YES")
  24.   END IF
  25. END SUB
  26.  
  27. SUB Win_exit
  28.   Iup::ExitLoop = TRUE
  29. END SUB
  30.  
  31. Iup::Open()
  32. dlg = Iup::Create("dialog")
  33. Iup::SetAttributes(dlg, "TITLE=\"Login\", SIZE=200x200")
  34.  
  35. vb = Iup::Create("vbox")
  36. hb1 = Iup::Create("hbox")
  37. piclbl = Iup::Create("label")
  38. Iup::SetAttribute(piclbl, "IMAGE", "./login.png")
  39. Iup::SetAttribute(piclbl, "EXPAND", "HORIZONTAL")
  40. Iup::SetAttribute(piclbl, "ALIGNMENT", "ACENTER:ATOP")
  41. Iup::Append(hb1, piclbl)
  42. Iup::Append(vb, hb1)
  43.  
  44. hb2 = Iup::Create("hbox")
  45. errlbl = Iup::Create("label")
  46. Iup::SetAttribute(errlbl, "TITLE", "User ID / Password Incorrect")
  47. Iup::SetAttribute(errlbl, "FGCOLOR", "#ff0000")
  48. Iup::SetAttribute(errlbl, "EXPAND", "HORIZONTAL")
  49. Iup::SetAttribute(errlbl, "ALIGNMENT", "ACENTER")
  50. Iup::Hide(errlbl)
  51. Iup::Append(hb2, errlbl)
  52. Iup::Append(vb, hb2)
  53.  
  54. hb3 = Iup::Create("hbox")
  55. Iup::SetAttribute(hb3, "MARGIN", "20x10")
  56. Iup::SetAttribute(hb3, "GAP", "5")
  57. vb1 = Iup::Create("vbox")
  58. Iup::SetAttribute(vb1, "GAP", "15")
  59. uidlbl = Iup::Create("label")
  60. Iup::SetAttribute(uidlbl, "TITLE", "User ID")
  61. Iup::Append(vb1, uidlbl)
  62. pwdlbl = Iup::Create("label")
  63. Iup::SetAttribute(pwdlbl, "TITLE", "Password")
  64. Iup::Append(vb1, pwdlbl)
  65. Iup::Append(hb3, vb1)
  66. vb2 = Iup::Create("vbox")
  67. uidtxt = Iup::Create("text")
  68. Iup::SetAttribute(uidtxt, "SIZE", "85x")
  69. Iup::Append(vb2, uidtxt)
  70. pwdtxt = Iup::Create("text")
  71. Iup::SetAttribute(pwdtxt, "PASSWORD", "YES")
  72. Iup::SetAttribute(pwdtxt, "SIZE", "85x")
  73. Iup::Append(vb2, pwdtxt)
  74. Iup::Append(hb3, vb2)
  75. Iup::Append(vb, hb3)
  76.  
  77. hb4 = Iup::Create("hbox")
  78. Iup::SetAttribute(hb4, "MARGIN", "35x")
  79. showpwd = Iup::Create("toggle")
  80. Iup::SetAttribute(showpwd, "TITLE", "Show Password?")
  81. Iup::Append(hb4, showpwd)
  82. Iup::Append(vb, hb4)
  83.  
  84. hb5 = Iup::Create("hbox")
  85. Iup::SetAttribute(hb5, "MARGIN", "40x10")
  86. loginbut = Iup::Create("button")
  87. Iup::SetAttribute(loginbut, "TITLE", "Login")
  88. Iup::SetAttribute(loginbut, "EXPAND", "HORIZONTAL")
  89. iup::Append(hb5, loginbut)
  90. iup::Append(vb, hb5)
  91.  
  92. iup::Append(dlg, vb)
  93.  
  94. Iup::SetCallback(dlg,"CLOSE_CB",ADDRESS(Win_exit()))
  95. Iup::SetCallback(loginbut, "ACTION", ADDRESS(login_clicked()))
  96. Iup::SetCallback(showpwd, "ACTION", ADDRESS(show_password()))
  97.  
  98. Iup::Show(dlg)
  99. Iup::MainLoop()
  100. Iup::Close()
  101.  

21
Programming Challenges / Re: GUI Login
« on: December 25, 2019, 11:12:38 PM »
8th (Jalih submission)

Code: Text
  1. requires gui
  2.  
  3. var gui
  4.  
  5. { guest: "pa$$w0rd!" } constant passwords
  6.  
  7. : authenticate
  8.   "edit1" g:child g:text? passwords swap m:@ nip null? if
  9.     "User not found!" . cr
  10.     2drop
  11.   else
  12.     swap
  13.     "edit2" g:child g:text? nip s:= if
  14.       "Authenticated!" . cr
  15.       bye
  16.     else
  17.       "Username and password don't match!" . cr
  18.     then
  19.   then ;
  20.  
  21. {
  22.   kind: "win",
  23.   buttons: 5,
  24.   title: "Login",
  25.   wide: 360,
  26.   high: 160,
  27.   resizable: false,
  28.   bg:"lightgray",
  29.   center: true,
  30.   init: ( gui ! ),
  31.   children:
  32.   [
  33.     {
  34.       kind: "box",
  35.       name: "frame",
  36.       bounds: "10, 10, parent.width-10, parent.height-10",
  37.       bg: "gray",
  38.       children:
  39.       [
  40.         {
  41.           kind: "label",
  42.           label: "Username:",
  43.           bounds: "parent.left, parent.top+10, 80, top+24 ",
  44.           name: "lbl1"
  45.          },
  46.         {
  47.           kind: "edit",
  48.           bounds: "lbl1.right+10, lbl1.top, parent.width-10, top+24",
  49.           name: "edit1",
  50.           max-text: 32
  51.         },
  52.         {
  53.           kind: "label",
  54.           label: "Password:",
  55.           bounds: "lbl1.left, lbl1.bottom+10, 80, top+24 ",
  56.           name: "lbl2"
  57.          },
  58.         {
  59.           kind: "edit",
  60.           bounds: "edit1.left, lbl2.top, parent.width-10, top+24",
  61.           name: "edit2",
  62.           max-text: 32,
  63.           password-char: "*"
  64.         },
  65.         {
  66.           kind: "btn",
  67.           label: "Login",
  68.           bg: "darkgray",
  69.           bounds: "lbl2.left, lbl2.bottom+20, edit2.right, top+30",
  70.           name: "button",
  71.           tooltip: "Login to account",
  72.           click: ' authenticate
  73.         }
  74.       ]
  75.     }
  76.   ]
  77. } var, gui-desc
  78.  
  79. : app:main
  80.   gui-desc @ g:new ;
  81.  

22
Programming Challenges / GUI Login
« on: December 25, 2019, 01:20:47 AM »
This round of the language challenge series is to create a desktop GUI login dialog. Be as creative as you wish. To get things started here is a Python /wx example.

Python WX

Code: Python
  1. import wx
  2.  
  3. ########################################################################
  4. class LoginDialog(wx.Dialog):
  5.     """
  6.    Class to define login dialog
  7.    """
  8.  
  9.     #----------------------------------------------------------------------
  10.     def __init__(self):
  11.         """Constructor"""
  12.         wx.Dialog.__init__(self, None, title="Login")
  13.         self.logged_in = False
  14.  
  15.         # user info
  16.         user_sizer = wx.BoxSizer(wx.HORIZONTAL)
  17.  
  18.         user_lbl = wx.StaticText(self, label="Username:")
  19.         user_sizer.Add(user_lbl, 0, wx.ALL|wx.CENTER, 5)
  20.         self.user = wx.TextCtrl(self)
  21.         user_sizer.Add(self.user, 0, wx.ALL, 5)
  22.  
  23.         # pass info
  24.         p_sizer = wx.BoxSizer(wx.HORIZONTAL)
  25.  
  26.         p_lbl = wx.StaticText(self, label="Password:")
  27.         p_sizer.Add(p_lbl, 0, wx.ALL|wx.CENTER, 5)
  28.         self.password = wx.TextCtrl(self, style=wx.TE_PASSWORD|wx.TE_PROCESS_ENTER)
  29.         self.password.Bind(wx.EVT_TEXT_ENTER, self.onLogin)
  30.         p_sizer.Add(self.password, 0, wx.ALL, 5)
  31.  
  32.         main_sizer = wx.BoxSizer(wx.VERTICAL)
  33.         main_sizer.Add(user_sizer, 0, wx.ALL, 5)
  34.         main_sizer.Add(p_sizer, 0, wx.ALL, 5)
  35.  
  36.         btn = wx.Button(self, label="Login")
  37.         btn.Bind(wx.EVT_BUTTON, self.onLogin)
  38.         main_sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
  39.  
  40.         self.SetSizer(main_sizer)
  41.  
  42.     #----------------------------------------------------------------------
  43.     def onLogin(self, event):
  44.         """
  45.        Check credentials and login
  46.        """
  47.         stupid_password = "pa$$w0rd!"
  48.         user_password = self.password.GetValue()
  49.         if user_password == stupid_password:
  50.             print ("You are now logged in!")
  51.             self.logged_in = True
  52.             self.Close()
  53.         else:
  54.             print ("Username or password is incorrect!")
  55.  
  56. ########################################################################
  57. class MyPanel(wx.Panel):
  58.     """"""
  59.  
  60.     #----------------------------------------------------------------------
  61.     def __init__(self, parent):
  62.         """Constructor"""
  63.         wx.Panel.__init__(self, parent)
  64.  
  65.  
  66. ########################################################################
  67. class MainFrame(wx.Frame):
  68.     """"""
  69.  
  70.     #----------------------------------------------------------------------
  71.     def __init__(self):
  72.         """Constructor"""
  73.         wx.Frame.__init__(self, None, title="Main App")
  74.         panel = MyPanel(self)
  75.  
  76.         # Ask user to login
  77.         dlg = LoginDialog()
  78.         dlg.ShowModal()
  79.         authenticated = dlg.logged_in
  80.         if not authenticated:
  81.             self.Close()
  82.  
  83.         self.Show()
  84.  
  85. if __name__ == "__main__":
  86.     app = wx.App(False)
  87.     frame = MainFrame()
  88.     app.MainLoop()
  89.  


23
Nim / Re: Nim IUP
« on: December 25, 2019, 12:19:01 AM »
You will be able to show off your GUI tricks with the next round of the language challenge. I'll post a ScriptBasic / IUP login dialog as a template for the challenge.

24
Nim / Re: Nim IUP
« on: December 24, 2019, 10:51:20 AM »
I wanted to try a more direct approach to interfacing with an external library. I'm using the definitions from the niup interface file.


I might just roll my own IUP import file using niup as a guide.

Code: Text
  1. # Nim IUP Direct
  2.  
  3. const
  4.   libiupSONAME = "libiup.so"
  5.   IUP_CLOSE* = -3
  6.   IUP_CENTER* = cint(0x0000FFFF)
  7.  
  8. type
  9.   Ihandle = object
  10.   PIhandle* = ptr Ihandle
  11.   Icallback* = proc (a1: PIhandle): cint {.cdecl.}
  12.  
  13. proc btn_exit_cb(ih:PIhandle):cint {.cdecl.}=
  14.   return IUP_CLOSE
  15.  
  16. proc Open*(argc: var cint; argv: ptr cstringArray): cint {.cdecl, importc: "IupOpen", dynlib: libiupSONAME, discardable.}
  17. proc Button*(title: cstring; action: cstring): PIhandle {.cdecl, importc: "IupButton", dynlib: libiupSONAME.}
  18. proc Label*(title: cstring): PIhandle {.cdecl, importc: "IupLabel", dynlib: libiupSONAME.}
  19. proc Vbox*(child: PIhandle): PIhandle {.varargs, cdecl, importc: "IupVbox", dynlib: libiupSONAME.}
  20. proc Dialog*(child: PIhandle): PIhandle {.cdecl, importc: "IupDialog", dynlib: libiupSONAME.}
  21. proc SetAttribute*(ih: PIhandle; name: cstring; value: cstring) {.cdecl, importc: "IupSetAttribute", dynlib: libiupSONAME.}
  22. proc SetCallback*(ih: PIhandle; name: cstring; `func`: Icallback): Icallback {.cdecl, importc: "IupSetCallback", dynlib: libiupSONAME, discardable.}
  23. proc ShowXY*(ih: PIhandle; x: cint; y: cint): cint {.cdecl, importc: "IupShowXY", dynlib: libiupSONAME, discardable.}
  24. proc MainLoop*(): cint {.cdecl, importc: "IupMainLoop", dynlib: libiupSONAME, discardable.}
  25. proc Close*() {.cdecl, importc: "IupClose", dynlib: libiupSONAME.}
  26.  
  27.  
  28. var dlg, button, label, vbox: PIhandle
  29. var argc:cint
  30. var argv:ptr cstringArray
  31.  
  32. Open(argc, argv)
  33.  
  34. label =  Label("Hello world from IUP.")
  35. button = Button("OK", nil)
  36.  
  37. vbox = Vbox(label, button, nil)
  38. SetAttribute(vbox, "ALIGNMENT", "ACENTER")
  39. SetAttribute(vbox, "GAP", "10")
  40. SetAttribute(vbox, "MARGIN", "10x10")
  41.  
  42. dlg = Dialog(vbox)
  43. SetAttribute(dlg, "TITLE", "Ubuntu RPi")
  44.  
  45. SetCallback(button, "ACTION", btn_exit_cb)
  46.  
  47. ShowXY(dlg, IUP_CENTER, IUP_CENTER)
  48.  
  49. MainLoop()
  50.  
  51. Close()
  52.  


25
ScriptBasic / Re: IUP GUI Toolkit
« on: December 24, 2019, 08:39:22 AM »
This is the ScriptBasic IUP Online Dictionary running under Ubuntu 64 on the RPi 4B.

Code: Script BASIC
  1. IMPORT iup.bas
  2.  
  3. servers[0]="dict.org"
  4. servers[1]="dict1.us.dict.org"
  5. servers[2]="all.dict.org"
  6.  
  7. about="""This is a Demo
  8. of the IUP GUI Binding
  9. for Scriptbasic"""
  10.  
  11. ' Initialize IUP
  12. Iup::Open()
  13.  
  14. ' Create main window
  15.  
  16. win = Iup::Create("dialog")
  17.   Iup::SetAttributes(win, "TITLE=\"ScriptBasic IUP Online Dictionary\", SIZE=500x300")
  18.   Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))
  19.  
  20. ' Create container to house ALL GUI objects
  21.  
  22. vbox = Iup::Create("vbox")
  23.   Iup::SetAttributes(vbox, "MARGIN=10x10")
  24.  
  25. ' Create server panel
  26.  
  27. topBox = Iup::Create("hbox")
  28.   Iup::SetAttributes(topBox, "GAP=10")
  29.   Iup::Append(vbox, topBox)
  30. serverFrame = Iup::Create("frame")
  31.   Iup::SetAttributes(serverFrame, "TITLE=Servers, EXPAND=YES")
  32.   Iup::Append(topBox, serverFrame)
  33. serverBox = Iup::Create("hbox")
  34.   Iup::SetAttributes(serverBox, "GAP=5")
  35.   Iup::Append(serverFrame, serverBox)
  36. serverCombo = Iup::Create("list")
  37.   Iup::SetAttributes(serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")
  38.   Iup::Append(serverBox, serverCombo)
  39.   Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))
  40. btnFetch = Iup::Create("button")
  41.   Iup::SetAttributes(btnFetch, "TITLE=Fetch, SIZE = 50x")
  42.   Iup::Append(serverBox, btnFetch)
  43.   Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked()))
  44.  
  45. ' Create control panel
  46.  
  47. controlFrame = Iup::Create("frame")
  48.   Iup::SetAttributes(controlFrame, "TITLE=Controls")
  49.   Iup::Append(topBox, controlFrame)
  50. controlBox = Iup::Create("hbox")
  51.   Iup::SetAttributes(controlBox, "GAP=5")
  52.   Iup::Append(controlFrame, controlBox)
  53. btnAbout = Iup::Create("button")
  54.   Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  55.   Iup::Append(controlBox, btnAbout)
  56.   Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
  57. btnClear = Iup::Create("button")
  58.   Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")
  59.   Iup::Append(controlBox, btnClear)
  60.   Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
  61. btnExit = Iup::Create("button")
  62.   Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")
  63.   Iup::Append(controlBox, btnExit)
  64.   Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))
  65.  
  66. ' Create dictionary panel
  67.  
  68. dictFrame = Iup::Create("frame")
  69.   Iup::SetAttributes(dictFrame, "TITLE=Dictionaries")
  70.   Iup::Append(vbox, dictFrame)
  71. serverList = Iup::Create("list")
  72.   Iup::SetAttributes(serverList, "EXPAND=YES, VISIBLELINES=1")
  73.   Iup::Append(dictFrame, serverList)
  74.   Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected()))
  75.  
  76. ' Create text part
  77.  
  78. transFrame = IUP::Create("frame")
  79.   Iup::SetAttributes(transFrame, "TITLE=Translation")
  80.   Iup::Append(vbox, transFrame)
  81. text = Iup::Create("text")
  82.   Iup::SetAttributes(text, "MULTILINE=YES, EXPAND=YES")
  83.   Iup::Append(transFrame, text)
  84.  
  85. ' Create entry and search button
  86.  
  87. bottomBox = Iup::Create("hbox")
  88.   Iup::SetAttributes(bottomBox, "GAP=10")
  89.   Iup::Append(vbox, bottomBox)
  90. label = Iup::Create("label")
  91.   Iup::SetAttributes(label, "TITLE=\"Enter Word to Search For:\", SIZE=x12")
  92.   Iup::Append(bottomBox, label)
  93. entry = Iup::Create("text")
  94.   Iup::SetAttributes(entry, "EXPAND=HORIZONTAL")
  95.   Iup::Append(bottomBox, entry)
  96. btnSearch = Iup::Create("button")
  97.   Iup::SetAttributes(btnSearch,"TITLE=Search, SIZE=50x")
  98.   Iup::Append(bottomBox, btnSearch)
  99.   Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))
  100. chkAll = Iup::Create("toggle")
  101.   Iup::SetAttributes(chkAll, "TITLE=ALL, SIZE=x12")
  102.   Iup::Append(bottomBox, chkAll)
  103. chkUTF = Iup::Create("toggle")
  104.   Iup::SetAttributes(chkUTF, "TITLE=UTF-8, SIZE=x12")
  105.   Iup::Append(bottomBox, chkUTF)
  106.  
  107. ' Add the main GUI container to the Window
  108.  
  109. Iup::Append(win, vbox)
  110.  
  111. ' Setup dialog defaults
  112.  
  113. Iup::Show(win)
  114. Iup::SetFocus(btnFetch)
  115. FOR i = 0 TO UBOUND(servers)
  116.   Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])
  117. NEXT
  118. Iup::SetAttribute(serverCombo, "VALUE", "1")
  119. Iup::Update(serverCombo)
  120. server_selection = servers[0]
  121.  
  122. ' Main processing loop
  123.  
  124. Iup::MainLoop()
  125. Iup::Close()
  126. END
  127.  
  128. ' Callback routines
  129.  
  130. SUB Win_exit
  131.   Iup::ExitLoop = TRUE
  132. END SUB
  133.  
  134. SUB btnAbout_clicked
  135.   Iup::Message("ABOUT", about)
  136. END SUB
  137.  
  138. SUB serverCombo_selected
  139.   server_selection = Iup::GetListText()
  140. END SUB
  141.  
  142. SUB serverList_selected
  143.   whichDictionary = Iup::GetListText()
  144. END SUB
  145.  
  146. SUB btnFetch_clicked
  147.   LOCAL dat, total, count
  148.   ON ERROR GOTO G_NetError
  149.   OPEN server_selection & ":2628" FOR SOCKET AS #1
  150.   PRINT#1,"SHOW DB\n"
  151.   LINE INPUT#1, dat
  152.   LINE INPUT#1, dat
  153.   count = 0
  154.   WHILE LEFT(dat, 1) <> "."
  155.     LINE INPUT#1, dat
  156.     IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
  157.     count+=1
  158.   WEND
  159.   PRINT#1,"QUIT\n"
  160.   CLOSE(#1)
  161.   FOR cnt = 0 TO count - 2
  162.     Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])
  163.   NEXT
  164.   Iup::SetAttribute(serverList, "VALUE", "1")
  165.   Iup::Update(serverCombo)
  166.   whichDictionary = total[0]
  167.   EXIT SUB
  168.  
  169.   G_NetError:
  170.   PRINT "Server ",server_selection," not available. (",ERROR,")\n"
  171. END SUB
  172.  
  173. SUB btnClear_clicked
  174.   Iup::ClearList(serverList)
  175.   Iup::SetAttribute(text, "VALUE", "")
  176.   Iup::SetAttribute(entry, "VALUE", "")
  177. END SUB
  178.  
  179. SUB btnSearch_clicked
  180.   LOCAL dict, dat, total, info
  181.   IUP::SetAttribute(text, "VALUE","Fetching....")
  182.   ON ERROR GOTO L_NetError
  183.   dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  184.   OPEN server_selection & ":2628" FOR SOCKET AS 1
  185.   IF Iup::GetAttribute(chkAll, "VALUE") THEN
  186.     PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"
  187.   ELSE
  188.     PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"
  189.   END IF
  190.   REPEAT
  191.     LINE INPUT#1, dat
  192.     IF LEFT(dat, 3) = "151" THEN
  193.       total$ &= "------------------------------\r\n"
  194.       total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))
  195.       total$ &= "------------------------------\r\n"
  196.       REPEAT
  197.         LINE INPUT#1, info
  198.         info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
  199.         IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
  200.       UNTIL LEFT(info, 1) = "."
  201.       total &= "\n"
  202.     END IF
  203.   UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  204.   PRINT#1,"QUIT\n"
  205.   CLOSE(#1)
  206.   IF LEFT(dat, 3) = "552" THEN
  207.     total = "No match found."
  208.   ELSE IF LEFT(dat, 3) = "501" THEN
  209.     total = "Select a dictionary first!"
  210.   ELSE IF LEFT(dat, 3) = "550" THEN
  211.     total = "Invalid database!"
  212.   END IF
  213.   Iup::SetAttribute(text, "VALUE", total)
  214. EXIT SUB
  215.  
  216. L_NetError:
  217.   dat[0] = "Could not lookup word! (" & ERROR & ")"
  218.   Iup::SetAttribute(text, "VALUE", dat)
  219. END SUB
  220.  

26
Nim / Nim IUP
« on: December 23, 2019, 08:51:56 PM »
This is a Nim version of the ScriptBasic iup3buttons example.

Code: Text
  1. # IUP Button / Event Example
  2.  
  3. import iup
  4.  
  5. proc Btn1_clicked(ih:PIhandle):cint {.cdecl.}=
  6.   echo "BUTTON 1 Event"
  7.  
  8. proc Btn2_clicked(ih:PIhandle):cint {.cdecl.}=
  9.   echo "BUTTON 2 Event"
  10.  
  11. proc Btn3_clicked(ih:PIhandle):cint {.cdecl.}=
  12.   echo "BUTTON 3 Event"
  13.  
  14. discard iup.open(nil, nil)
  15. var win = iup.dialog(nil)
  16. discard iup.setAttributes(win, "TITLE=\"Test Dialog\", SIZE=300x")
  17. var horzbox = iup.hbox(nil)
  18. discard iup.setAttributes(horzbox, "GAP=5")
  19. var btn1 = iup.button("", nil)
  20. discard iup.setAttributes(btn1, "TITLE=Button1, EXPAND=HORIZONTAL")
  21. var btn2 = iup.button("", nil)
  22. discard iup.setAttributes(btn2, "TITLE=Button2, EXPAND=HORIZONTAL")
  23. var btn3 = iup.button("", nil)
  24. discard iup.setAttributes(btn3, "TITLE=Button3, EXPAND=HORIZONTAL")
  25. iup.append(horzbox, btn1)
  26. iup.append(horzbox, btn2)
  27. iup.append(horzbox, btn3)
  28. iup.append(win, horzbox)
  29. discard iup.setCallback(btn1, "ACTION", cast[ICallback](Btn1_clicked))
  30. discard iup.setCallback(btn2, "ACTION", cast[ICallback](Btn2_clicked))
  31. discard iup.setCallback(btn3, "ACTION", cast[ICallback](Btn3_clicked))
  32. discard iup.show(win)
  33. discard iup.mainLoop()
  34. iup.close()
  35.  


ubuntu@rpi4b:~/repo/Nim/examples$ ./iup3buttons
BUTTON 1 Event
BUTTON 2 Event
BUTTON 3 Event
ubuntu@rpi4b:~/repo/Nim/examples$


27
ScriptBasic / Re: IUP GUI Toolkit
« on: December 23, 2019, 05:31:26 AM »
I was able to get the ScriptBasic IUP extension module built under Ubuntu 64 on the RPI 4B.

Code: Script BASIC
  1. ' IUP Button / Event Example
  2.  
  3. IMPORT iup.bas
  4.  
  5. SUB Btn1_clicked
  6.   PRINT "BUTTON 1 Event\n"
  7. END SUB
  8.  
  9. SUB Btn2_clicked
  10.   PRINT "BUTTON 2 Event\n"
  11. END SUB
  12.  
  13. SUB Btn3_clicked
  14.   PRINT "BUTTON 3 Event\n"
  15. END SUB
  16.  
  17. SUB Win_exit
  18.   Iup::ExitLoop = TRUE
  19. END SUB
  20.  
  21. Iup::Open()
  22. win = Iup::Create("dialog")
  23. Iup::SetAttributes(win, "TITLE=\"Test Dialog\", SIZE=300x")
  24. horzbox = Iup::Create("hbox")
  25. Iup::SetAttributes(horzbox, "GAP=5")
  26. btn1 = Iup::Create("button")
  27. Iup::SetAttributes(btn1, "TITLE=Button1, EXPAND=HORIZONTAL")
  28. btn2 = Iup::Create("button")
  29. Iup::SetAttributes(btn2, "TITLE=Button2, EXPAND=HORIZONTAL")
  30. btn3 = Iup::Create("button")
  31. Iup::SetAttributes(btn3, "TITLE=Button3, EXPAND=HORIZONTAL")
  32. Iup::Append(horzbox, btn1)
  33. Iup::Append(horzbox, btn2)
  34. Iup::Append(horzbox, btn3)
  35. Iup::Append(win, horzbox)
  36. Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))
  37. Iup::SetCallback(btn1,"ACTION",ADDRESS(Btn1_clicked()))
  38. Iup::SetCallback(btn2,"ACTION",ADDRESS(Btn2_clicked()))
  39. Iup::SetCallback(btn3,"ACTION",ADDRESS(Btn3_clicked()))
  40. Iup::Show(win)
  41. Iup::MainLoop()
  42. Iup::Close()
  43.  


ubuntu@rpi4b:~/sbrt/examples$ scriba iup3buttons.sb
BUTTON 1 Event
BUTTON 2 Event
BUTTON 3 Event
ubuntu@rpi4b:~/sbrt/examples$


28
Nim / Nim Manual
« on: December 23, 2019, 01:44:54 AM »
This is a link to the Nim Manual.

It's a good resouce to get started with Nim.

29
Programming Challenges / Re: SALC Ubuntu 64
« on: December 21, 2019, 08:32:48 AM »
Current results of the Ubuntu 64 bit and Rasbain 32 bit String Array Language Challenge on the RPi 4B 4GB,


30
Programming Challenges / Re: SALC Ubuntu 64
« on: December 21, 2019, 08:22:20 AM »
Rust (Ubuntu 64 RPi 4B 4GB)

Code: Text
  1. // Rust - 1mil4 - AIR
  2.  
  3. fn main() {
  4.     let mut s = "".to_string();
  5.     let mut t = "".to_string();
  6.     let mut a = [0;1000001];
  7.  
  8.     for x in 0..1000001 {
  9.         a[x] = x;
  10.         let b   = ( x%26 ) as u8;
  11.         let c = ( b+65 ) as char;
  12.         s.push( c );
  13.         if s.len() == 26 {
  14.             let reversed: String = s.chars().rev().collect();
  15.             t.push_str( &reversed );
  16.             s.clear();
  17.         }
  18.     }
  19.     println!( "r LEN: {}",  t.len() );
  20.     println!( "Front: {}",  &t[..26] );
  21.     println!( "Back:  {}",  &t[t.len()-26..]);
  22.     println!( "UBVal: {}",  a[1000000] );
  23.  
  24. }
  25.  


riveraa@rpi:~/Projects/rust/1mil3$ rustc -O mil64.rs

riveraa@rpi:~/Projects/rust/1mil3$ timex ./mil64
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.02user 0.01system 0:00.04elapsed 100%CPU (0avgtext+0avgdata 10440maxresident)k
0inputs+0outputs (0major+2371minor)pagefaults 0swaps


Pages: 1 [2] 3 4 ... 11