Is there a way to process inputs during a dialog?

Discuss GUI programming with the RapaGUI plugin here
Post Reply
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Is there a way to process inputs during a dialog?

Post by amyren »

I use the RapaGUI example Dialogs as an example for my question.

What I want to do is to change and update the content of one input field based on the input from another field.
Eg. run the Dialogs.hws example and press the Add button.
Eg. if the user enters OSLO in the field labeled City, then the Zip field would update to 0010.
And later it editing the entry the zip field would change into 5200 if City is changed to BERGEN.

Is this possible to do on the go while the dialog is open?
User avatar
Redlion
Posts: 96
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: Is there a way to process inputs during a dialog?

Post by Redlion »

HI,

I had this problem before, took me a while to find the code. I'm sure there is a better way but this worked for me.

Best to load your postcode data from a file, so its easier to update/change.

Code: Select all

/*** Make sure we have at least Hollywood 9.0! ****************************************************/
@VERSION 9,0

/*** Enable DPI-awareness so that our GUI looks sharp even on high DPI monitors *******************/
@OPTIONS {DPIAware = True}

/*** This script requires the RapaGUI plugin ******************************************************/
@REQUIRE "RapaGUI"

/*** Information about this app *******************************************************************/
@APPTITLE "Simple Dialogue Test"
@APPAUTHOR "Leo den Hollander"

EscapeQuit(True)

/*** Dim Array Setup *****************************************************************************/
Dim PostCode[9][2]

PostCode[1][1] = "Perth"
PostCode[2][1] = "Darwin"
PostCode[3][1] = "Brisbane"
PostCode[4][1] = "Sydney"
PostCode[5][1] = "Melbourne"
PostCode[6][1] = "Adelaide"

PostCode[1][2] = "6000"
PostCode[2][2] = "0000"
PostCode[3][2] = "4000"
PostCode[4][2] = "2000"
PostCode[5][2] = "3000"
PostCode[6][2] = "5000"

/*** Our XML GUI definition ***********************************************************************/
moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app" useicons="true">
  <window id="win" title=" DIALOGUE TEST" width="600" height="480" notify="closerequest">
    <vgroup>
       <vspace height="5"/>
       <text align="center">\33b DIALOGUE POSTCODE TEST </text>
       <vspace height="5"/>
       <hgroup>
            <rectangle/>
            <button id="dl_message"> Post Code </button>
            <rectangle/>
            <button id="quit"> QUIT </button>
            <rectangle/>
        </hgroup>
    </vgroup>
  </window>
   
</application>
]])


Function FindPostCode(City$)
PostNumber = 0
  For t = 1 to 6
   If PostCode[t][1] = City$
      PostNumber$ = PostCode[t][2] 
   Endif
  Next
EndFunction

/*** Handler for all incoming events **************************************************************/
Function p_EventFunc(msg)
    Switch msg.action
      Case "RapaGUI":
        Switch msg.attribute
          Case "Pressed":
            Switch msg.id
              Case "dl_message"
                Message$, len = FileToString(Appdir$ .. "testdlg.xml")
                moai.CreateDialog(Message$, "win")  
                moai.DoMethod("testdlg", "showmodal")

              Case "quit"
                End

              Case "dl_ok"
                moai.DoMethod("testdlg", "endmodal", 0)

            Endswitch

          Case "Selected":
            Switch msg.id
              Case "towns"
                City$ = msg.triggervalue
                FindPostCode(City$)
                moai.set("code", "text", PostNumber$)
            
            endswitch

          Case "CloseRequest":
            End           
       
        EndSwitch
    EndSwitch
EndFunction

/*** listen to these events! *********************************************************************/
InstallEventHandler({RapaGUI = p_EventFunc})

/*** main loop! **********************************************************************************/
Repeat
  WaitEvent
Forever
and the dialogue

Code: Select all

<dialog id="testdlg" title=" CODE TEST " margin="1" sizegadget="false" closegadget="false" width="300">
    <vgroup color="#FFAF70">
        <vspace height="5"/>
        <text align="center">\33b POSTCODE TEST </text>
        <vspace height="5"/>
        <vgroup>
            <combobox id="towns" notify="Selected">
              <item>Perth</item>
              <item>Darwin</item>
              <item>Brisbane</item>
              <item>Sydney</item>
              <item>Melbourne</item>
              <item>Hobart</item>
              <item>Adelaide</item>
            </combobox>
        </vgroup>
        <vspace height="5"/>
          <text id="code" frame="1"></text>
        <vspace height="5"/>
        <hline/>
        <vspace height="1"/>
        <hgroup>
            <rectangle/>
            <button id="dl_ok"> OK </button>
            <rectangle/>
        </hgroup>
        <vspace height="5"/>
   </vgroup>
</dialog>
Cheers
Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Is there a way to process inputs during a dialog?

Post by amyren »

Thanks for your suggerstion, unfortunately I could not use your solution in my program.
I just used the zip code as an example for my question, but I need to process the input diffently.

But your example with that pop-up windows made me realize I could just as well use a regular systemrequest to get the input and then process it before the dialog opens.
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is there a way to process inputs during a dialog?

Post by plouf »

What exaclg loking for ?
Redlion example shows that
A) you can check dialog gadgets same as window ones
B) script do not stop running when a dialog opens
C) you need to activate notify for the gadget you need to check
Maybe a acknowlwdge is better for you ? But also "text" notify will send in every character..
D) with moai.get and moai.set you can read and write gadget content..

isnt that looking for ?
Or whats diffirent?
Christos
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Is there a way to process inputs during a dialog?

Post by amyren »

Thanks for pointing this out, you are right ofcourse.
Its just my limitied understanding of how RapaGui works that prevented me from seing it the first time.

I'll try to explain what I was trying to do.
In my local community we have this annual skiing event uphill a mountain that has been going on since 1979.
All contenders that have ever been participating is being registered is one list. Then another annual list, is being made to keep track of contenders in the current year.

My program have two listviews, namely "lv" (all contenders) and "lv2" (current year contenders)
Registering new contenders happens in the top listview ("lv") and the current year contenter list is made by copying entries from "lv" to "lv2"
There is one text field named "deltatt" which contains the information on which year each contender have been participating. The text is added in the following format: "2021-2022-2023-2024"
Another field "kommentar" which contains free text.
"lv2" have also a few additional fields which is added in this copy process, one of these is "klasse" which is restricted to the letters T, R or B
T (tour) and R (race) means they will race all the way up the mountain, while the B (childrens) will not. The "deltatt" field is also used to count how many years each person have been on that mountain, so it should only be updated for the T and R category.
For the B category a note should be added to the "kommentar" field, eg. "Barnerenn_2024."

The dialog I was asking about is this copy dialog where I copy from "lv" to "lv2", where I wanted to update these two fields "deltatt" and "kommentar" according to what was entered in the "klasse".

Now, after re-reading Redlions code I was able to make this work as described above, and the fields get updated instantly as I was looking for.
But I see now that it would need some more work. If the wrong letter was entered in the "klasse" fields then the changes to the other fields needs to be undone when changing the entry. The other thing I must rethink is that the same copy dialog is also used for editing entries in the "lv2" and I might want a different behaviour here.
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Is there a way to process inputs during a dialog?

Post by plouf »

no need for "appologies" :) thats a community forum and talking/developing is what for

btw you can force "klasse" with Textentry.Accept to accpet ONLY TRB letters
Christos
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Is there a way to process inputs during a dialog?

Post by amyren »

Thanks again.
I actually already had that accept option set to take TRBtrb only. I was thinking in the case the person is registered as T or R first, but then it turns out it should be B. So when changing it to B the text "-2024" must be removed from the "deltatt" field and instead add the note to "kommentar" field (or vice versa)
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Is there a way to process inputs during a dialog?

Post by amyren »

I got it all working, but now I want to change the "Klasse" into a Choice entry.
How do I then set up notify correctly?
I tried the following code, but it does not work. The first debugprint does not get triggered.

I added this under EventFunc (RapaGUI section)

Code: Select all

Case "Choice":
	Debugprint("test choice notify")
	Switch msg.id
	Case "Klasse"
		DebugPrint(moai.Get("Klasse", "active"))
		DebugPrint(moai.DoMethod("Klasse", "GetEntry", "Active"))
	EndSwitch
Then in the xml file:

Code: Select all

<choice id="Klasse" tooltip="Trim, Racer eller Barnerenn" notify="active">
	<item>T</item>
	<item>R</item>
	<item>B</item>
</choice>
amyren
Posts: 361
Joined: Thu May 02, 2019 11:53 am

Re: Is there a way to process inputs during a dialog?

Post by amyren »

Figured it out.
Obviously the notify must match the case so I need to use notify="Active" in the xml file and put my Case "Klasse" under the Case "Active" section.
Post Reply