Gui.Gettext function

Feature requested and implemented
Post Reply
User avatar
karlkloss
Posts: 359
Joined: Fri Aug 18, 2023 12:21 pm
Location: Local group
Has thanked: 62 times
Been thanked: 86 times

Gui.Gettext function

Post by karlkloss »

Analog to Gui.Settext, I'd like to have a Gui.Gettext function.

Why?

When using the same event for several buttons (in my case for a numpad), it makes it much easier to get the value of the pressed button,
and, after closing the numpad, to transfer the end value to other parts of the program.

As BASIC is neither object oriented, nor has pointers, you have to have some replacements.
User avatar
karlkloss
Posts: 359
Joined: Fri Aug 18, 2023 12:21 pm
Location: Local group
Has thanked: 62 times
Been thanked: 86 times

Re: Gui.Gettext function

Post by karlkloss »

One example:

Here I'm trying to make a popup numpad.
It works, but is somewhat arkward.
I can't give the value back to the calling routine properly. I have the handle of the calling button, but I can only write it's text on the fly, and
I can't read it afterwards, so I need a separate array to store it.

Also, being able to read the text of the buttons of the numpad would adding digits make easier.

And: After closing the numpad, I can only call the subroutine of a fixed page contructor, so In a project with several pages, I would have to repeat the numpad's code for every page, as I can't give the event handler the address of the page it was called from.

Any ideas how to do this more dynamically, without switching to C? References to variables would be nice.

Code: [Local Link Removed for Guests]

' ********** MAIN **********
V1=0
dim results(2)
results(1)=0
results(2)=0
serial2.mode 115200, 1, 3
Print2 "numpadtest starting..."
numpad_value=0
gosub Page0
gui.autorefresh 30,1
wait
' ********* END MAIN *******

' ********* PAGE 0 INIT *****
Page0:   
numpadrunning = 0
GUI.init 50, blue 

but_V1 = gui.button(20,20,100,40,STR$(results(1)),4,0,0,1,black,white,red,red) 'button for 1ms increment
gui.setevent but_V1,1,V1click

but_V2 = gui.button(20,90,100,40,STR$(results(2)),4,0,0,1,black,white,red,red) 'button for 1ms increment
gui.setevent but_V2,1,V2click
Return
'********* PAGE 0 END *******

' ******** V1CLICK **********
V1click: 
If NOT numpadrunning Then
   numpad_limit=6
   numpad_x=150
   numpad_y=40
   numpad_target=but_V1
   resultsindex=1
   Gosub numpad
Endif
while gui.getvalue(but_V1)=1
wend
Return
'******* V1CLICK END *********

'******* V2CLICK *************
V2click: 
If NOT numpadrunning Then
   numpad_limit=5
   numpad_x=150
   numpad_y=40
   numpad_target=but_V2
   resultsindex=2
   Gosub numpad
Endif
while gui.getvalue(but_V2)=1
wend
Return
'******* V2CLICK END **********


'******* NUMPAD INIT ************
numpad:
numpadrunning=1
numpad_value=0
numstr$=""
gui.settext numpad_target, "0"
num_box = GUI.Box(numpad_x, numpad_y, 106, 140, white ,black, red)
num_7 = gui.button(numpad_x+4, numpad_y+4,30,30,"7",3,4,0,10,black,white,red,black)
num_8 = gui.button(numpad_x+38, numpad_y+4,30,30,"8",3,4,0,10,black,white,red,black)
num_9 = gui.button(numpad_x+72, numpad_y+4,30,30,"9",3,4,0,10,black,white,red,black)
num_4 = gui.button(numpad_x+4, numpad_y+38,30,30,"4",3,4,0,10,black,white,red,black)
num_5 = gui.button(numpad_x+38, numpad_y+38,30,30,"5",3,4,0,10,black,white,red,black)
num_6 = gui.button(numpad_x+72, numpad_y+38,30,30,"6",3,4,0,10,black,white,red,black)
num_1 = gui.button(numpad_x+4, numpad_y+72,30,30,"1",3,4,0,10,black,white,red,black)
num_2 = gui.button(numpad_x+38, numpad_y+72,30,30,"2",3,4,0,10,black,white,red,black)
num_3 = gui.button(numpad_x+72, numpad_y+72,30,30,"3",3,4,0,10,black,white,red,black)
num_0 = gui.button(numpad_x+4, numpad_y+106,30,30,"0",3,4,0,10,black,white,red,black)
num_del = gui.button(numpad_x+38, numpad_y+106,30,30,"<",3,4,0,10,black,white,red,black)
num_OK = gui.button(numpad_x+72, numpad_y+106,30,30,"=",3,4,0,10,black,white,red,black)

gui.setevent num_1, 1, numclick
gui.setevent num_2, 1, numclick
gui.setevent num_3, 1, numclick
gui.setevent num_4, 1, numclick
gui.setevent num_5, 1, numclick
gui.setevent num_6, 1, numclick
gui.setevent num_7, 1, numclick
gui.setevent num_8, 1, numclick
gui.setevent num_9, 1, numclick
gui.setevent num_0, 1, numclick
gui.setevent num_del, 1, numclick
gui.setevent num_OK, 1, numclick
Print2 "Numpad started"
Return
'*********** NUMPAD END **********

'********** NUMCLICK *************
numclick:
num_target = Gui.Target
Select Case num_target
  Case num_0: numstr$=numstr$+"0"
  Case num_1: numstr$=numstr$+"1"    
  Case num_2: numstr$=numstr$+"2"
  Case num_3: numstr$=numstr$+"3"
  Case num_4: numstr$=numstr$+"4"    
  Case num_5: numstr$=numstr$+"5"
  Case num_6: numstr$=numstr$+"6"
  Case num_7: numstr$=numstr$+"7"    
  Case num_8: numstr$=numstr$+"8"
  Case num_9: numstr$=numstr$+"9"
  Case num_0: numstr$=numstr$+"0"    
  Case num_del: If len (numstr$)>0 Then numstr$=left$(numstr$,len(numstr$)-1)
  Case num_OK: 
     numpadrunning=0
     results(resultsindex)=numpad_value
     Gosub Page0
End Select      

If numpadrunning Then
   If len(numstr$) > numpad_limit Then numstr$=left$(numstr$,len(numstr$)-1)
   Print2 numstr$
   numpad_value = val(numstr$)
   numstr$=STR$(numpad_value)
   gui.settext numpad_target, numstr$
   while gui.getvalue(num_target)=1
   wend
End If
Return
'******** NUMCLICK END ********

User avatar
cicciocb
Site Admin
Posts: 3233
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 645 times
Been thanked: 2276 times
Contact:

Re: Gui.Gettext function

Post by cicciocb »

I think that what you are looking for already exists for the VGA
[Local Link Removed for Guests]

(This is the same for the [Local Link Removed for Guests]:-)
User avatar
karlkloss
Posts: 359
Joined: Fri Aug 18, 2023 12:21 pm
Location: Local group
Has thanked: 62 times
Been thanked: 86 times

Re: Gui.Gettext function

Post by karlkloss »

Tbh, I don't care about the VGA gui, I'm looking for something that I can use to build easy and cheap user interfaces for the various half-finished projects I have lying around.
Like that SI5351 based frequency generator, that uses a rubidium frequency standard as reference.

But anyway, is there a possibility to tell a subroutine who called it, and what to call when it closes?
Like an addressof (subroutinelabel) function, and a gosub address?

Also, it would be nice to have a sort of dynamic overlay, that you can call and that appears on top of the current screen, with all elements inside existing only in it's context, and that self-destructs when closed and redraws the host screen.
User avatar
cicciocb
Site Admin
Posts: 3233
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 645 times
Been thanked: 2276 times
Contact:

Re: Gui.Gettext function

Post by cicciocb »

Unfortunately Basic is not C :-)
bugs
Posts: 192
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 91 times
Been thanked: 76 times

Re: Gui.Gettext function

Post by bugs »

One of its many advantages... :)
User avatar
karlkloss
Posts: 359
Joined: Fri Aug 18, 2023 12:21 pm
Location: Local group
Has thanked: 62 times
Been thanked: 86 times

Re: Gui.Gettext function

Post by karlkloss »

Well, building a dynamic GUI in standard BASIC seems like a very dumb idea.

Maybe I will switch to Micropython and LVGL.
bugs
Posts: 192
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 91 times
Been thanked: 76 times

Re: Gui.Gettext function

Post by bugs »

Well - I coded a complete PCB CAD design program (given an Orcad netlist etc for input) with full features - using Microsoft Visual Basic.
Why not - it was the language I had used since the 6800 was born.
User avatar
cicciocb
Site Admin
Posts: 3233
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 645 times
Been thanked: 2276 times
Contact:

Re: Gui.Gettext function

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Dec 09, 2024 5:53 pm Well, building a dynamic GUI in standard BASIC seems like a very dumb idea.

Maybe I will switch to Micropython and LVGL.
No, it is probably not a dumb idea ... it is probably just a questions of methods.
User avatar
karlkloss
Posts: 359
Joined: Fri Aug 18, 2023 12:21 pm
Location: Local group
Has thanked: 62 times
Been thanked: 86 times

Re: Gui.Gettext function

Post by karlkloss »

You could write us an onscreen keyboard :D
Post Reply