AutoHotkey Community

It is currently May 27th, 2012, 3:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: May 16th, 2010, 11:30 pm 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
This is a first attempt at GUI. The purpose is to format homework assignments consistently. It includes two input box calls (page number and problem number) which populate the GUI, and then allow extra formatting.

I would be glad to have the code critiqued, but I am really asking about the script structure.

What I am hoping for is a good explanation of how GUI scripts interact with main resident scripts. I would like to know what strategies others use so that ExitApp doesn't close down the entire program. Do people use functions? Or does everyone do what I did, which is call a non-resident script from the main script?

I have a main script with many includes, which are application specific. I am not going to post this, suffice it to say that the includes work.

In one of the includes, random_ideas.ahk, is my GUI call. It's called /ass; because it generates homework assignment structures and follows with a semicolon.

My question is: is what I do a sensible way to set up a GUI that I only need on Sundays? (It does work.) Could or should I incorporate it into the main script as a function?

Here's all of the code (first the call from random_ideas.ahk)::

Code:
::/ass;::
run,F:\my documents\AHK\gui_assignment.ahk
winwaitactive,Assignment
WinWaitClose,Assignment
sleep,500
sendinput,;{space}
return


Basically I am running the GUI as a separate program because of ExitApp.

Here's the GUI:
Code:
#SingleInstance

Gui, Add, Radio, vRgroup Checked, None
Gui, Add, Radio, , &Lesson
Gui, Add, Radio, , &Assignment
Gui, Add, Radio, , &Skills
Gui, Add, Radio, , &OB
Gui, Add, Radio, , &RB
gui, add, text,, Page:
gui, add, edit, vPage
gui, add, checkbox, vProblem, &Problem
gui, add, text, , Num
gui, add, edit, vNum
inputbox, Page2, Page?
GuiControl,, Page, %Page2%
inputbox, Num2, Problem Numbers?
if(Num2<>""){
   guicontrol,,Problem,1
}
GuiControl,, Num, %Num2%
Gui, Add, Button, default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Add, Button, , Cancel  ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Show,, Assignment
return  ; End of auto-execute section. The script is idle until the user does something.

GuiClose:
ButtonOK:
Gui, Submit  ; Save the input from the user to each control's associated variable.
var_holder = P %Page%
if(Rgroup=1){
var_holder2 = %var_holder%
}
if(Rgroup=2){
var_holder2 = Lesson %var_holder%
}
if(Rgroup=3){
var_holder2 = Assignment %var_holder%
}
if(Rgroup=4){
var_holder2 = Skills %var_holder%
}
if(Rgroup=5){
var_holder2 = OB %var_holder%
}
if(Rgroup=6){
var_holder2 = RB %var_holder%
}
if(Problem = 0){
var_holder3 = %var_holder2%
}
if(Problem = 1){
   var_holder3 = %var_holder2%: %Num%
}

sendinput, %var_holder3%
ExitApp

ButtonCancel:
GuiEscape:
ExitApp


Last edited by gunns256 on May 17th, 2010, 4:13 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Bump, Re-explanation
PostPosted: May 17th, 2010, 3:59 pm 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
Bump, Revised request for information.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2010, 4:10 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I use Gui, Destroy in place of ExitApp. There's often spirited debate about this issue here but I personally care little about it; my main script at my place of work spans 7000+ lines to automate 22 programs, I have no desire to maintain the existence of 14 additional GUI windows for purposes of coding excellence. It's quick and easy and not likely to present problems down the line.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2010, 4:10 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
If you had the Gui in the main script you could replace
Code:
sendinput, %var_holder3%
ExitApp

with
Code:
sendinput, %var_holder3%
Return

as this will cause the script to return to it's dormant mode and await another input, much like your line
Quote:
End of auto-execute section. The script is idle until the user does something.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 17th, 2010, 4:15 pm 
Offline

Joined: October 25th, 2009, 6:10 pm
Posts: 17
Thank you. I will experiment with these.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, rbrtryn and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group