Supermarket list

Share your advanced PureBasic knowledge/code with the community.
User avatar
minimy
Addict
Addict
Posts: 839
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Supermarket list

Post by minimy »

I was bored that every week to make the purchase I had to edit or write the supermarket list.
I made this for my wife in 20 minutes. This is only possible with purebasic. :lol:
It is a simple but effective shopping list.
Right button show the popup menu.

Updated to version cukilinda!! Now with hearts animation. :lol:

Code: Select all

Now the hearts are in a thread to dont stop!
Supports:
-Add new elements.
-Modify units.
-Edit the element.
-Delete elements.
-Check to include or not in the final list. (copied to clipboard)
-Copy to clipboard. Easy to print or send.
-Maximize and minimize.
-Save and load list items automatically.

🏅Certification suitable for use by spouse. :mrgreen:
Moral: Happy wife, calm husband. :wink:

@sergey: Solved problem pos > 0, thanks sergey! Don't give her ideas!! :lol:
@Denis: Thanks, share the french version please. Merci!
@Infratec: Nice idea, i will do it, But if you prefer to do it yourself, it would be perfect. Thank you very much! (I got many apps create for phones, but hate program for phones, Kotlin... etc, security level out of date and a lot of crazy things. Google drop 20 updates/minute. I am loyal to Purebasic :lol: )

This is an example of the pasted list:

Code: Select all

1 Caja 6 tetrabrick de Leche sin lactosa desnatada
1 Caja 12 botellines de cerveza especial
3 Caja 6 botellas de agua de 1.5L
I think it can also serve other purposes.

Image

Code: Select all

LoadFont(0,"Arial",12)
LoadFont(1,"Segoe UI Emoji",12)

Procedure   save()
  Protected p
  If CreateFile(0,"milistadelacompra")
    For p= 0 To CountGadgetItems(0)-1
      WriteStringN(0,GetGadgetItemText(0,p,0)+"|"+GetGadgetItemText(0,p,1))
    Next p
    CloseFile(0)
  EndIf
EndProcedure
Procedure   load()
  Protected t.s
  ClearGadgetItems(0)
  If ReadFile(0,"milistadelacompra")
    While Eof(0)=0
      t=  ReadString(0)
      If t<>""
        t= ReplaceString(t,"|",Chr(10))
        AddGadgetItem(0,-1, t)
      EndIf
    Wend
    CloseFile(0)
  EndIf
EndProcedure
Procedure   kukilinda(a)
  Protected.s ss="💘"
  Protected t=50, p
  Static Dim c.vector3(50)
  Static Dim a.f(50)
  Static Dim s.f(50)
  Static Dim d.l(50)
  Repeat
  StartVectorDrawing(CanvasVectorOutput(1))
  w= VectorOutputWidth():h=VectorOutputHeight()
  VectorSourceColor(RGBA(255,200,200,255))
  FillVectorOutput()
  cx=w/2:cy=h/2
  For p= 0 To t
    If c(p)\x <= 0 Or c(p)\x >= w Or c(p)\y <= 0 Or c(p)\y >= h
      c(p)\z= Random(30,10):a(p)= Radian(Random(360)):s(p)= Random(50,10)/100:d(p)=RGBA(Random(255),Random(255),Random(255),255)
    EndIf
    c(p)\x= cx + Cos(a(p)) * c(p)\z
    c(p)\y= cy + Sin(a(p)) * c(p)\z
    c(p)\z + s(p)
    VectorSourceColor(d(p))
    VectorFont(FontID(1), c(p)\z / 10)
    MovePathCursor(c(p)\x-(VectorTextWidth(ss)/2),c(p)\y-(VectorTextHeight(ss)/2))
    DrawVectorText(ss)
  Next p
  StopVectorDrawing()
  Delay(1)
  ForEver
EndProcedure

OpenWindow(0,0,0,960,540,"Shopping list - For my little wife, the prettiest!!",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
CanvasGadget(1,0,0,WindowWidth(0),50)
ListIconGadget(0,0,50,WindowWidth(0),WindowHeight(0)-50,"Units",90,#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes)
SetGadgetFont(0,FontID(0))
AddGadgetColumn(0,1,"Article",960)
CreatePopupMenu(0)
MenuItem(0,"Add Item")
MenuItem(1,"Change Item Units")
MenuItem(2,"Delete Item")
MenuItem(3,"Edit the article")
MenuItem(4,"Copy the list to the clipboard")

kuki= CreateThread(@kukilinda(),1)

t1.s="":t2.s="":t.s=""
load()
;{ 
Repeat
ev= WindowEvent()

  Select ev
    Case #PB_Event_Menu
      em= EventMenu()
      Select em
        Case 0
          t1= InputRequester("Add Article","Article Name. Empty cancels","")
          If t1<>""
            t2= InputRequester("Quantity","Number of units.","1")
            t= t2+Chr(10)+t1
            AddGadgetItem(0,-1,t)
          EndIf
        Case 1
          pos= GetGadgetState(0)
          If pos >= 0
            t2= InputRequester("Quantity","Number of units.",GetGadgetItemText(0,pos,0))
            SetGadgetItemText(0,pos,t2,0)
          Else
            MessageRequester("Attention","You must choose the item for which you are going to modify the units, before selecting this option.",#PB_MessageRequester_Info)
          EndIf
        Case 2
          pos= GetGadgetState(0)
          If pos >= 0
            resp=MessageRequester("Delete article","Do you want to delete article?",#PB_MessageRequester_YesNo|#PB_MessageRequester_Warning)
            If resp= #PB_MessageRequester_Yes
              RemoveGadgetItem(0,pos)
            EndIf
          Else
            MessageRequester("Attention","You must choose the item to delete from the list, before selecting this option.",#PB_MessageRequester_Info)
          EndIf
        Case 3
          pos= GetGadgetState(0)
          If pos >= 0
            t1= InputRequester("Add Article","Article Name. Empty cancels","")
            If t1<>""
              SetGadgetItemText(0,pos,t1,1)
            EndIf
          Else
            MessageRequester("Attention","You must choose the item you are going to rename, before selecting this option.",#PB_MessageRequester_Info)
          EndIf
        Case 4
          If CountGadgetItems(0) > 0
            t= ""
            For p= 0 To CountGadgetItems(0)-1
              If GetGadgetItemState(0,p) & #PB_ListIcon_Checked
                t+ GetGadgetItemText(0,p,0)+" "+GetGadgetItemText(0,p,1)+#LF$
              EndIf
            Next p
            SetClipboardText(t)
            MessageRequester("Attention","List copied to clipboard."+#LF$+#LF$+"Use Ctrl+V to paste into another application (mail).",#PB_MessageRequester_Info)
          Else
            MessageRequester("Attention","The list is empty. You must add something.",#PB_MessageRequester_Info)
          EndIf
      EndSelect
    Case #PB_Event_Gadget
      eg=  EventGadget()
      et=    EventType()
      Select eg
        Case 0
          Select et
            Case #PB_EventType_Change
              save()
              
            Case #PB_EventType_RightClick
              DisplayPopupMenu(0,WindowID(0), DesktopMouseX(),DesktopMouseY())
              
          EndSelect
      EndSelect
      
    Case #PB_Event_SizeWindow
      ResizeGadget(0,0,50,WindowWidth(0),WindowHeight(0)-50)
      ResizeGadget(1,0,0,WindowWidth(0),50)
    Case #PB_Event_CloseWindow
      save()
      Break 
  EndSelect
  
;   kk+1:If kk%10=0:kukilinda():EndIf
  Delay(1)
ForEver
KillThread(kuki)
;}
Last edited by minimy on Fri Jan 23, 2026 4:39 pm, edited 1 time in total.
If translation=Error: reply="Sorry, Im Spanish": Endif
Denis
Enthusiast
Enthusiast
Posts: 785
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Supermarket list

Post by Denis »

Hi minimy,

nice idea :D

I will translate it in French for my wife.
A+
Denis
infratec
Always Here
Always Here
Posts: 7774
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Supermarket list

Post by infratec »

Only an idea:

if you have a webserver ... load it in a folder and write a spider basic app for the smartphone.
Sergey
User
User
Posts: 78
Joined: Wed Jan 12, 2022 2:41 pm

Re: Supermarket list

Post by Sergey »

Error in your code
pos= GetGadgetState(0)
If pos > 0
I always use pos <> -1 or pos >= 0
Fix it :wink:

And the wife has own list with more expensive goods
Fur coat, car... :D
User avatar
idle
Always Here
Always Here
Posts: 6168
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Supermarket list

Post by idle »

Funny, maybe I've been doing something wrong all these years since I do the shopping, cooking and cleaning (sometimes without the leaf blower ) but I'm at least banned from the laundry. :lol:
Post Reply