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.


Topics - John Spikowski

Pages: [1] 2
1
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.  


2
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$


3
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.

4
General Discussion / Ubuntu 64 RPI 4B
« on: December 15, 2019, 08:08:16 AM »
On AIR's lead, I was able to  install Ubuntu server 19.10.1 on my RPi 4B 4GB. I then installed the Unity Desktop. This is so cool to run what I have on my laptop  on my RPi.

It seems to run well.

I said 5 years ago that I was done with 32 bit Linux. That was until the Raspberry Pi came along. I'm done with hobby Raspbian 32 and relieved I'm running on a commercial grade supported 64 bit OS.

5
FreeBasic / FreeBasic RPi Install
« on: December 15, 2019, 01:19:34 AM »
Here is the install instructions for installing FreeBasic on the Raspberry Pi.

Quote
wget http://users.freebasic-portal.de/stw/builds/linux-armv7a-hf-debian/freebasic.deb
wget http://users.freebasic-portal.de/stw/builds/freebasic-headers.deb
sudo dpkg -i freebasic.deb
sudo dpkg -i freebasic-headers.deb
apt-get update
apt-get install -f

6
Nim / Nim SB
« on: December 11, 2019, 05:38:36 PM »
I'm working on embedding ScriptBasic into Nim. Basically it's a port of the SBT extension module as Nim extension. This will allow the full functionality of SB and its extensions to be available to Nim dynamically at runtime.

@AIR - I may need some help creating the Nim interface if you have time.

7
Nim / Nim Introduction
« on: December 07, 2019, 04:25:35 AM »
I was able to get the IUP distribution I built for the RPi and Nim to  work together. A "Hello Nim" of sorts.

Code: Text
  1. import iup
  2.  
  3. proc btn_click(ih:PIhandle):cint {.cdecl.}=
  4.     iup.message("Popup", "You clicked the button!")
  5.  
  6. discard iup.open(nil, nil)
  7.  
  8. var btn = iup.button("Click me!", nil)
  9. discard iup.setCallback(btn, "ACTION", cast[ICallback](btn_click))
  10.  
  11. var dlg = iup.dialog(iup.vbox(btn, nil))
  12. iup.setAttribute(dlg, "TITLE", "iupTabs")
  13.  
  14. discard iup.showXY(dlg, IUP_CENTER, IUP_CENTER)
  15. discard iup.mainLoop()
  16.  
  17. iup.close()
  18.  


pi@RPi4B:~/pui/iup-master/examples $ nim c -d:release callbacks.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: system [Processing]
Hint: callbacks [Processing]
Hint: iup [Processing]
CC: iup_callbacks
CC: stdlib_system
CC: stdlib_iup
Hint:  [Link]
Hint: operation successful (13356 lines compiled; 4.586 sec total; 10.758MiB peakmem; Release Build) [SuccessX]
pi@RPi4B:~/pui/iup-master/examples $ ls -l
total 72
-rwxr-xr-x 1 pi pi 59180 Dec  6 20:17 callbacks
-rw-r--r-- 1 pi pi   413 Nov  4 02:39 callbacks.nim
-rw-r--r-- 1 pi pi   576 Nov  4 02:39 menu.nim
-rw-r--r-- 1 pi pi  1023 Nov  4 02:39 tabs.nim
pi@RPi4B:~/pui/iup-master/examples $ ./callbacks


8
Translators / Universal Language Translator
« on: December 06, 2019, 05:09:31 AM »
Hi Brian,

Thanks for joining us on the forum.

With your language translation skills have you thought of fostering a universal programming language translator project? Something like Google translate but for programming languages.

As you can see from the string / array language challenge the syntax isn't that different between them. I would like to hear your thoughts on the challenges that might be ahead.

9
General Discussion / RPI Forum
« on: December 03, 2019, 04:40:04 PM »
Quote
I don't know if John is still following this thread or not, but if he is, thanks for finding that note. Those pages covered the mathematics so I could proceed directly to the software engineering needed to write an efficient program. It also helped to look at the sample code included in the post.

@ejolson,

Glad it helped! Wish you were here.

10
General Discussion / MS Rust
« on: December 02, 2019, 06:52:49 PM »

11
Programming Challenges / SALC Rasbian 32
« on: November 28, 2019, 05:03:24 AM »
I 'm going to take this challenge one more round and add a string and array  to the mix.

FYI:  This site is a forum and not my blog. Without contributing members it will soon become dormant. It only takes a minute to register. It's okay to be a member of multiple forums and I'm pretty sure the RPi moderators won't ban you if you appear here.

12
ScriptBasic / Upcoming Projects
« on: November 26, 2019, 08:56:05 PM »
This is a list of projects I'm working on with ScriptBasic.

  • C array extension module using Judy as a base.
  • IUP callback support improvements.
  • RPI Tank integration with SB and WiringPi.
  • OT (Windows) - Farm Sim development.

13
General Discussion / gcc optimization on the RPi
« on: November 24, 2019, 10:46:16 PM »
Quote from: ejolson@RPi
The PC results are interesting because the native optimization setting in gcc results in an executable that runs an astonishing 20 percent slower.

That is motivation enough for me to reconfigure ScriptBasic's build scripts to use these settings rather than the default O3.

14
Programming Challenges / One Mil Dash
« on: November 24, 2019, 09:22:52 PM »
ScriptBasic

Code: Script BASIC
  1. ' ScriptBasic - 1mil.sb
  2.  
  3. accum = 0
  4. milvar = 1000000
  5.  
  6. FOR x = 1 TO 1000000
  7.   accum += 1
  8.   milvar -= 1
  9.   IF accum = milvar THEN PRINT "Middle\n"
  10. NEXT
  11. PRINT "Plus:  ",accum,"\n"
  12. PRINT "Minus: ",milvar,"\n"
  13.  


pi@RPi4B:~/sbrt/examples $ /usr/bin/time scriba 1mil.sb
Middle
Plus:  1000000
Minus: 0
2.18user 0.00system 0:02.21elapsed 99%CPU (0avgtext+0avgdata 1972maxresident)k
520inputs+0outputs (1major+108minor)pagefaults 0swaps
pi@RPi4B:~/sbrt/examples $

15
General Discussion / RPi 4 Update
« on: November 24, 2019, 06:12:52 PM »
I updated my RPi 4 OS and now the default file browse opens and closes immediately. I ended up removing it and installing Nautilus. I replaced the default text editor with gedit.

Pages: [1] 2