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 

Dynamic GUI, with a user defined 'check box' grid:

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



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Fri Mar 06, 2009 9:25 pm    Post subject: Dynamic GUI, with a user defined 'check box' grid: Reply with quote

I am trying to find some terms or a starting point for a new idea I am working on. I've looked around under using a number of terms/words without luck. What is this called, where should I start looking?


Idea:

I want to make my GUI display a grid of check boxes- after a user has made a number of pre-set choises. The width and hight of the grid are variables, depending on if/else statments and math rules. So in one instance the GUI could have 4 columns and 2 rows, then next 7 columns and 5 rows, Depending on other variables and user input.

Code:

something like:


NewGUI.ahk
____________________________________
________|__1__|__2__|__3__|__4__|__5__|
Item-1  | [X] | [_]  | [_] | [_] | [_] |
Item-2  | [X] | [X]  | [_] | [_] | [_] |
Item-3  | [_] | [X]  | [X] | [X] | [_] |
--------------------------------------------------



The User would basically select how many columns and rows they would 'need' by answering the correct lines of questions, and the checks should populate based off of user_input where needed. If they only need 2 rows, 5 columns, then that is all that should appear.


I had to change the var names and stuff for security reasons, the real GUI does not deal with cars. All of the choices and math code are not in yet, but I wanted to see if it is even possible to have a check box grid populate on a new GUI page, before wasting too muc more time. I would like to output with some boxes checked and others unchecked depending on all of the above information.

I am working with this kind of code as an example:
Code:


#SingleInstance FORCE
#UseHook
Hotkey, Pause, EarlyTerm

Gui, Show, w330 h65
Gui, Add, Button, x15 y15 w90 h30 gNewCar, New Car
Gui, Add, Button, x120 y15 w90 h30 gUsedCar, Used Car
Gui, Add, Button, x220 y15 w90 h30 gRental, Rental
return


NewCar:
Gui, Submit
Gui, 2:+resize
Gui, 2:Show, w250 h150
Gui, 2:Add, Text, x10 y10, Please select which the customer wants:
Gui, 2:Add, GroupBox, r3 x15 y35 w200, A, B or C:
Gui, 2:Add, Checkbox, xp+10 yp+15 v1, Customer wants a 4 door
Gui, 2:Add, Checkbox, v2, Customer wants a 2 door
Gui, 2:Add, Checkbox, v3, Customer wants a truck/van
Gui, 2:Add, Button, x15 y120 w40 h25 gNext, Next
return


UsedCar:
Gui, Submit
Gui, 3:Show, w330 h200
Gui, 3:Add, Text, x10 y10, TEST TEST TEST
return


Rental:
Gui, Submit
Gui, 4:show, w330 h250
Gui, 4:Add, Text, x10 y10, TSET TEST TSET
return


Next:
Gui, 5:+resize
Gui, Submit, NoHide

   GuiControl, , 1, %1%
   GuiControl, , 2, %2%
   GuiControl, , 3, %3%


If(1=1 && 2=0 && 3=0)
{
   
   Gui, Submit
   Gui, 6:Show, w250 h150
   Gui, 6:Add, Text, x10 y10, Select a Make or Model:
   Gui, 6:Add, DropDownList, w150 vMake Choose1, Select Make Model:|Ford|Honda|Chevy|BMW|Other
   Gui, 6:Add, Text, x10 y60, How Many Extra Tires does the cust need?`nNot Including outlet the 4 on the car:
   Gui, 6:Add, Edit, VTires yp+35 w60 Limit2
   
}
else if(1=0 && 2=1 && 3=0)
{
   
      Gui, Submit
   Gui, 6:Show, w250 h150
   Gui, 6:Add, Text, x10 y10, Select a Make or Model:
   Gui, 6:Add, DropDownList, w150 vMake Choose1, Select Make Model:|Ford|Honda|Chevy|BMW|Other
   Gui, 6:Add, Text, x10 y60, How Many Extra Tires does the cust need?`nNot Including outlet the 4 on the car:
   Gui, 6:Add, Edit, VTires yp+35 w60 Limit2
   
}

else if(1=0 && 2=0 && 3=1)
{
   MsgBox, else
}
else if(1=1 && 2=1 && 3=0)
{
   MsgBox, else
}
else if(1=0 && 2=1 && 3=1)
{
   MsgBox, else
}
else if(1=1 && 2=0 && 3=1)
{
   MsgBox, else
}
else if(1=1 && 2=1 && 3=1)
{
   MsgBox, else

   }
else
{
   MsgBox, Please select a check box
}
return

return


EarlyTerm:
ExitApp


return            ;Main return






As always, i'm not asking anyone to do this for me, but I cant think of any other terms to search under that would suit this need.
Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 194
Location: China/ Canada

PostPosted: Fri Mar 06, 2009 10:16 pm    Post subject: Reply with quote

Code:
Random,, A_TickCount
Loop, 3
{
 Random, c, 0, 1
 Gui, Add, Checkbox, Checked%c%
}
Gui, Show
return

_________________
Sakurako ^_^
Back to top
View user's profile Send private message Visit poster's website
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Fri Mar 06, 2009 10:28 pm    Post subject: Reply with quote

I'm not sure you'll find anything like this pre-made. You'll need to thoroughly read the GUI section of the Help file to understand how to script it. Here's an example to get you started.
Code:
#SingleInstance force
#NoEnv

Gui, Add, Text,,Rows:
Gui, Add, Edit
Gui, Add, UpDown, Range1-7 vR
Gui, Add, Text, ym, Columns:
Gui, Add, Edit
Gui, Add, UpDown, Range1-7 vC
Gui, Add, Button, xm w75 Default, OK

Gui, Show,,Checkbox Grid
return
GuiClose:
ExitApp

ButtonOK:
Gui, Submit
Loop,% R*C
{
 Random, A_Check, 0, 1
 Gui, 2:Add, Checkbox, %A_Margin% Checked%A_Check% vBox%A_Index% gCB
 A_Margin := Mod(A_Index,R) ? "":"ym"
}
Gui, 2:Show
return

2GuiClose:
Gui, 2:Destroy
Gui, 1:Show
return

CB:
MsgBox, You just clicked %A_GuiControl%.
return


Last edited by jaco0646 on Fri Mar 06, 2009 10:29 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Fri Mar 06, 2009 10:29 pm    Post subject: Reply with quote

Thank you for the reply, but I am not sure I understand the example.

In the "Loop, 3", is the '3' able to be a user defined variable, through the GUI?
Also, why is tickcount being used if all of the data regarding the check-box-grid, is user defined also?


The GUI first asks 'How many rooms', this will determine how many columns aprear. User enters 1 for one room, and only 1 column apprears, or the user can enter 7 for 7 rooms.

The rows are the items installed in the rooms themselves, also selected through questions. No need to install an item in a room when it is not needed. Does the customer want Lightbulbs, sockets, outlets, carpet, other items. So as you select WHAT items the want, and you know how many rooms to put them in...

As in:

Code:

Install the following in the following rooms:
____________|Room1|Room2|Room3|
Light switch|-yes-|-yes-|--no--|
Outlet Cover|--no-|-yes-|-yes-|
Light bulbs |-no--|-no--|-no--|
Something   |-yes-|-yes-|-yes-|
Another     |-no--|-no--|-no--|

Basically, I want to print out a work order.  What goes into what room.  I do not need/want this to be printed out, the GUI can just display the grid

Back to top
View user's profile Send private message
Sakurako



Joined: 10 May 2007
Posts: 194
Location: China/ Canada

PostPosted: Sat Mar 07, 2009 11:06 am    Post subject: Reply with quote

Code:
Gui, Add, Edit, vENum gECheck Limit1 Number
Gui, Show
return

ECheck:
GuiControlGet, ENum
Gui, Destroy
Loop %ENum%
{
 c := A_Index
 Gui, Add, Checkbox, % "v" c "_1" (A_Index = 1 ? "" : " ys") " section", %c%_1
 Loop, 3
 {
  ANum := A_Index + 1
  Gui, Add, Checkbox, v%c%_%ANum% xs, %c%_%ANum%
 }
}
Gui, Show
return

_________________
Sakurako ^_^
Back to top
View user's profile Send private message Visit poster's website
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Sat Mar 07, 2009 2:35 pm    Post subject: Reply with quote

Very nice, Thank you jaco0646 and Sakurako, I will play around with these and show you what I have when its up.
Back to top
View user's profile Send private message
Deep-Silence



Joined: 24 Apr 2009
Posts: 87

PostPosted: Sun Jan 10, 2010 1:23 am    Post subject: Reply with quote

Hi Sakurako,
First of all, thanks for your code.
I am also new at dynamic GUIs similar to those you've made here.
i would like to understand what you just did. So can you please explain how
the code works and what each Gui Add CHeckbox-line does?

i would really appreciate that,
Thank You
Deep-Silence

BTW, (My Try)

Code:

Gui, Add, Edit, vENum gECheck Limit1 Number ;Adds the edit to get the userinput
Gui, Show ; shows the gui
return

ECheck: ;action for gECheck
GuiControlGet, ENum ;gets the Userinput
Gui, Destroy ;destroys the gui

Loop %ENum% ;repeats the action within this brakes %ENum%
{
 c := A_Index ;defines Variable c to get the value of %A_Index%
 Gui, Add, Checkbox, % "v" c "_1" (A_Index = 1 ? "" : " ys") " section", %c%_1 ; Adds the First Line of x lines
 Loop, 3 ;does the same for the following 3 lines
 {
  ANum := A_Index + 1 ;Defines ANum for each horizontal line
  Gui, Add, Checkbox, v%c%_%ANum% xs, %c%_%ANum% ;and adds its Checkboxes
 }
}
Gui, Show ;Shows the final GUI
return


Would be nice if you can explain the GUI, Add, Checkbox, lines...
Smile



Sakurako wrote:
Code:
Gui, Add, Edit, vENum gECheck Limit1 Number
Gui, Show
return

ECheck:
GuiControlGet, ENum
Gui, Destroy
Loop %ENum%
{
 c := A_Index
 Gui, Add, Checkbox, % "v" c "_1" (A_Index = 1 ? "" : " ys") " section", %c%_1
 Loop, 3
 {
  ANum := A_Index + 1
  Gui, Add, Checkbox, v%c%_%ANum% xs, %c%_%ANum%
 }
}
Gui, Show
return
Back to top
View user's profile Send private message
Display posts from previous:   
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