Jump to content
Sign in to follow this  
grandim

Problem with multiple guis

Recommended Posts

grandim

I have a script that works on its own but will not work if its included into another script with its own gui.

Here's the code that works on its own

Global $button

OtherScript()

Func OtherScript()
        UnrelatedFunction()
        MakeAChoice()
        AnotherUnrelatedFunction()
endfunc

Func MakeAChoice()
    $Gui2 = GUICreate("Please make your choice", 200, 100)
    $ButtonA = GUICtrlCreateButton("A", 20, 50, 60)
    $ButtonB = GUICtrlCreateButton("B", 90, 50, 60)
    GUISetState(@SW_SHOW)
    GUICtrlSetOnEvent($ButtonA , "ButtonTypeA")
    GUICtrlSetOnEvent($ButtonB, "ButtonTypeB")
    While $button = ""
        Sleep(50)
    WEnd
    GUIDelete($Gui2)
    Return
EndFunc

Func ButtonTypeA()
    $button = "A"
EndFunc

Func ButtonTypeB()
    $button = "B"
EndFunc

And this is what calls it in the other gui

$GoToOtherScript = GUICtrlCreateMenuItem("OtherScript", $toolsmenu)
GUICtrlSetOnEvent($GoToOtherScript , "OtherScript")

Running the script in autoit debugger shows the script idling in the while loop(never entering a button function), and entering in GUIonchangeRegister whenever I click the a button. I tried to user GuiSwitch() and various changes on the loop but I alway get the same results.

Edited by grandim

Share this post


Link to post
Share on other sites
martin

What you have shown looks ok except that you do not have

Opt("GuiOnEventMode",1)

Maybe that is the problem.

Welcome to the AutoIt forums grandim :mellow:

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
grandim

What you have shown looks ok except that you do not have

Opt("GuiOnEventMode",1)

Maybe that is the problem.

Welcome to the AutoIt forums grandim :mellow:

Thanks,

Opt("GuiOnEventMode",1) is set at the top of both files so that shouldn't be the issue.

Share this post


Link to post
Share on other sites
martin

Thanks,

Opt("GuiOnEventMode",1) is set at the top of both files so that shouldn't be the issue.

I should have noticed before but in my defence you have made it a little difficult by not posting some code we can run. This is what I think you are doing;

clicking a menu item: that causes an event which runs the function OtherScript: in that function you do various things including setting new events when a button is clicked.

It won't work because events are queued and the event for the button won't be actioned untill you return from OtherScript.

This is what I think you need to do-

;some code to create the first gui
$GoToOtherScript = GUICtrlCreateMenuItem("OtherScript", $toolsmenu)
GUICtrlSetOnEvent($GoToOtherScript , "OtherScriptA")

; other stuff
Global $CallOther = False
while 1;your idle loop

 if $CallOther then
 $CallOther = False
 OtherScript()
 endif
wend


Func OtherScriptA()
 $CallOther = True
EndFunc
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.