Page 1 of 1

blocking actions when window opens

Posted: Sun Jan 13, 2008 6:30 pm
by dhouston
I'm relatively new to PB and am very much a novice with Linux. I am writing a cross-platform application that will interface with an embedded device that, in turn, interfaces with some 50-75 devices via RS232, RS485, wireless, I/O pins, etc. Currently it is about 5000 lines and has 16 windows, each with it's own event handling procedure. I've been writing it under Windows, where I'm much more experienced having used VB for years. I have used API calls only where there was no alternative. Yesterday, I tried my code under Linux and was very impressed that it only required about 15 minutes of editing to get it to run. My compliments to the chefs.

I'll be 66 in a few days and have 3 serious health problems for which I take about 30 pills daily - lifting them to my mouth is my only exercise. Some of the meds affect short term memory and mental acuity so RTFM is not very useful advice - I eat dessert first these days.

One window tracks the device configuration. It has about 50 OptionGadgets, CheckboxGadgets, SpinGadgets, etc. When this window opens, the current gadget states are taken from a preference file. When changes are made, flags are set to prompt the user to download the changes to the device and update the preference file when the window is closed. I do not want the initial changes that occur when the window opens to set these flags. Under Windows, this is not a problem as the associated window events procedure doesn't appear to be activated until after the window open procedure completes. This is not the case under Linux - the initial changes do set the flags.

How can I interlock this so the flags are only set when the user makes changes by manually clicking the gadgets?

Posted: Tue Jan 15, 2008 2:29 pm
by walker
... all you have to do is a simple

Code: Select all

While WindowEvent(): Wend
after setting your gadget states (before entering the repeat loop)
see the example... the debug doesn't appear when opening the window.. (remove the line While WindowEvent():Wend and see the difference.... debugger must be enabled)

Code: Select all

Procedure open_window_0()
OpenWindow(0,0,0,500,300,"test")

If CreateGadgetList(WindowID(0))
    OptionGadget(0,10,10,100,20,"option1")
    CheckBoxGadget(1,10,40,100,20,"check1")
    CheckBoxGadget(2,10,70,100,20,"check2")
EndIf   
EndProcedure
Procedure mpc()
    CallDebugger
EndProcedure

open_window_0()
SetGadgetState(1,#True)

While WindowEvent():Wend;- <<<< remove this line to see the difference

Repeat
    event=WaitWindowEvent()
    If event=#PB_Event_CloseWindow
        quit=1
    EndIf   
    If Event=#PB_Event_Gadget
            Select EventGadget()
                Case 0
                
                Case 1
                    Debug "--"
                Case 2
                
            EndSelect   
        EndIf    
Until quit=1 
End 
(hope i did not misunderstand your intention...)

Posted: Tue Jan 15, 2008 2:35 pm
by dhouston
Perhaps my question wasn't clear.

Using Windows/VB there is the same problem. As a form loads, any changes to checkboxes, radio buttons, etc. trigger event procedures. It's simple to block them using a form level variable. I set loading True as one of the first lines in the FormLoad procedure and set it False as the last line. In the various event procedures, I use

Code: Select all

If loading Then ExitSub
Using Windows/PB there appears to be no problem. No events appear to be triggered during the procedure that opens the window and initializes the parameters.

Using Linux/PB, the events are triggered during the initialization. The only solution I've found is to read the preference file in the event handler and only set the flags when the data disagrees with what's in the preferences file. This seems slow and cumbersome so I'd like to find a more elegant solution if there is one.

Posted: Tue Jan 15, 2008 4:43 pm
by walker
well, there is (afaik) no similar function in PB... the events were triggrerd and all you can do is to catch all events after doing your initialisation... that is what the line
While WindowEvnt():Wend
does...
All events occured till this point were processed (and no action is taken) and you only receive events when you click on a gadget... (and this line does not hurt when running the same code on Windows)

Posted: Tue Jan 15, 2008 5:24 pm
by dhouston
Thanks.

My second post was made before your first response showed up. I'll give your suggestion a try - I think you understood exactly what I was asking even though I may not have made it clear at first.

I'm finding that I have to make modifications due to different default font sizes, styles, etc. so having slightly different code for Windows and Linux is not a major problem.

Posted: Tue Jan 15, 2008 5:58 pm
by dhouston
That seems to work once I figured out just where to put it in my code. I had to modify my code for launching the window. And it is certainly elegant. Thanks, again.

Code: Select all

    Case #PB_Event_Menu
      Select EventMenu()
        Case #MENU_CFG
          If Not OpenWindowCFG()
            MessageRequester("Error", "Unable to open Configuration Window")
          Else
            While WindowEvent():Wend  ;HERE IT IS!!!!!!!!!!!!!!!
          EndIf
Now, I just have to remove all the brute force code I wrote yesterday which used the preference file.

Posted: Wed Jan 16, 2008 12:48 pm
by walker
:D