AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fundamental GUI question

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Mon Apr 25, 2005 5:32 pm    Post subject: Fundamental GUI question Reply with quote

Though I posted this, buried in another topic, I am posting here because answer might benefit other new GUI function users too.

I have some "parent" script, that is mean to, at certain times, gosub to my GUI form and get some data (so the gui-form should be isolated and consolidated in one subroutine. ie

Code:
; -----
; beginning of script
..
..
gosub form_input_routine
..
; do other things when returned.
msgbox, I have returned
..
.. ----
..
form_input_routine:
gui, add, ... whatever
gui, add, ... whatever
gui, add, ... whatever
gui, show
gui, submit
return

guiclose:
guiescape:
return



My problem is that this displays the form but the returns to the main script before the user is finished with the form. How do I make my gui-forms work such that they do not continue processing the script until the form is complete.

In other words - the main part of the script calls and shows the GUI-form but then just continues right away with the message "I have returned" - when I don't want to return from the gosub until the form has been filled out or closed.

What's the secret to getting the script to do this ?

Thanks!
Back to top
View user's profile Send private message
TeknoMusicMan



Joined: 14 Apr 2005
Posts: 188
Location: Wisconsin, USA

PostPosted: Mon Apr 25, 2005 5:38 pm    Post subject: Reply with quote

you need to make a button that executes Gui, Submit.

take gui, submit out from where it currently is

The way you have it coded right now, the scrip is adding the 3 "whatevers" to the form then showing the form then imediatly after that submiting the form. So you need to make a button

Gui, add, button, gSubmit, Finished

then have a sub called Submit with gui, submit in it

Submit:
{
Gui, Submit
return
}
_________________

"Make it idiot-proof, and someone will make a better idiot."
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Mon Apr 25, 2005 5:52 pm    Post subject: Reply with quote

try this
Code:
; do things before.

gosub form_input_routine

; do other things when returned.

loop
   ifequal running,, break

msgbox, I have returned
exitapp

form_input_routine:
Gui Add, Button,, OK
gui, show
running = 1
return

buttonOK:
gui, submit
; do something
running =
return

guiclose:
guiescape:
running =
return
You might want to sleep a little in the loop, but the standard batch line delay should be OK.
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Mon Apr 25, 2005 6:06 pm    Post subject: Didn't help Reply with quote

Please someone tell me there is a more elegant solution than these kinds of workarounds. I cannot believe that one has to go through all this just to make sure the form completes before returning back to the "parent" part of the script.

(FYI - my real code indeed does have a button at the bottom, with a label that goes to a submit routine ... but this does not keep the form up!)

Incidentally, this is the another source of astonishment, that I always need a button ... ie .. that I cannot have a "form" that submits when the user presses enter. This is the subject of another recent thread (that elicited several interesting workarounds). But I would think that these two issues are rather fundamental and should not need kludgy workarounds.

I am sure there is some basic syntax or other lack of understanding on my part (or hoping).

Thanks!


Laszlo wrote:
try this
Code:
; do things before.

gosub form_input_routine

; do other things when returned.

loop
   ifequal running,, break

msgbox, I have returned
exitapp

form_input_routine:
Gui Add, Button,, OK
gui, show
running = 1
return

buttonOK:
gui, submit
; do something
running =
return

guiclose:
guiescape:
running =
return
You might want to sleep a little in the loop, but the standard batch line delay should be OK.
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Mon Apr 25, 2005 6:17 pm    Post subject: More info Reply with quote

FYI ... to clarify (I am trying not to post a lot of specific gui code yet, in order to keep things simple)
--- my script looks like

Code:
gui, add (s) ... text/combos etc
..

gui, Add, Button, OK

gui, show
Return

ButtonOK:
msgbox, got here!
Gui, Submit, NoHide
return


The entire form appears briefly and the disappears, as the routine returns back. It never reaches the msgbox (nor do I ever have a chance to use the form. It's as if ahk runs right over the button command.

Insights?
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Mon Apr 25, 2005 6:44 pm    Post subject: Reply with quote

GUI is a new thread, spun off from the main line of your script, with its independent life. Most of the time this is what you want. Especially, if you bring it up in response to a HotKey. InputBox is the sequential variant, though less flexible than a GUI. You could also store the window ID in a variable after the GUI is shown, and WinWaitClose in the main line of the script. It is only two extra lines of codes. Why is it so bad?
Code:
; do things before.

gosub form_input_routine

; do other things when returned.

winwaitclose ahk_id %GuiID% ; 1st extra line

msgbox, I have returned
exitapp

form_input_routine:
Gui Add, Button,, OK
gui, show
winget GuiID, ID, A         ; 2nd extra line
return

buttonOK:
gui, submit
; do something
return

guiclose:
guiescape:
return


Last edited by Laszlo on Mon Apr 25, 2005 6:49 pm; edited 1 time in total
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Mon Apr 25, 2005 6:44 pm    Post subject: OK - Simplified Reply with quote

OK - sanity check for me ...
Below is a little snip of some code I have ... am I wrong or should this stop and ask me for a Price ... ?
when I run it ... it displays the form and goes to the msgbox and exits without ever letting me input data.

Code:

Gui, Add, Text, , Price
Gui, Add, Edit, vPrice
gui, add, button, , &OK
Gui, Show
MSGBOX, Got here
Return


what did I miss?
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4078
Location: Pittsburgh

PostPosted: Mon Apr 25, 2005 6:55 pm    Post subject: Reply with quote

As I said, the GUI lives as another thread, the main line of your script goes on in its own world. You really want InputBox here, or the extra two lines from my previous posting.
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Mon Apr 25, 2005 6:59 pm    Post subject: Reply with quote

Your solution seems to work, so I am happy. For the record - what I find counterintuitive is that the "new thread" scenario - is generally not how the rest of ahk scripting works. Not that it is bad ... but since most of the other functions don't rely on this useful technique, you sort of have to glue them together with a little duct tape (my visual description of these workarounds). But I'm happy it works, and also just love ahk so I can't really complain.

And thanks all - this board is an amazing resource - with very supportive and responsive members.



Laszlo wrote:
GUI is a new thread, spun off from the main line of your script, with its independent life. Most of the time this is what you want. Especially, if you bring it up in response to a HotKey. InputBox is the sequential variant, though less flexible than a GUI. You could also store the window ID in a variable after the GUI is shown, and WinWaitClose in the main line of the script. It is only two extra lines of codes. Why is it so bad?
Code:
; do things before.

gosub form_input_routine

; do other things when returned.

winwaitclose ahk_id %GuiID% ; 1st extra line

msgbox, I have returned
exitapp

form_input_routine:
Gui Add, Button,, OK
gui, show
winget GuiID, ID, A         ; 2nd extra line
return

buttonOK:
gui, submit
; do something
return

guiclose:
guiescape:
return
Back to top
View user's profile Send private message
cornell2



Joined: 18 Mar 2005
Posts: 166

PostPosted: Mon Apr 25, 2005 7:01 pm    Post subject: Reply with quote

Laszlo wrote:
As I said, the GUI lives as another thread, the main line of your script goes on in its own world. You really want InputBox here, or the extra two lines from my previous posting.


FYI - I actually have a pretty complex form with combo dropdowns, radio buttons etc .. so your solution is the best so far.
Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group