AutoHotkey Community

It is currently May 25th, 2012, 11:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: February 9th, 2005, 10:11 am 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
Problem: The variable returned by checkbox/radio is a 0/1 value, but to initialize it you must use the "checked" option. Disabling GUI elements also requires using the "disabled" option. I would like a way to do both of these with a simple 0/1 value too.

It can be done with a few lines of code like this...

Code:
If MySetting
  Checked=Checked
Else
  Checked=

If MySettingEnabled
  Disabled=
Else
  Disabled=Disabled

GUI,Add,Checkbox,x10 y30 vMySetting %Checked% %Disabled%,Checkbox for my setting


but what I would prefer are options (perhaps I for Initialize, E for enable) which can be followed by a 0/1 value. This would allow the above in a single line of code...

Code:
GUI,Add,Checkbox,x10 y30 vMySetting i%MySetting% e%MySettingEnabled%,Checkbox for my setting


The same initialize syntax chould be valid for any GUI element that can have a default value (eg. edit) even though they can also be initialized via the third parameter.

As a simpler alternative, perhaps just add options Checked0/Checked1 and Disabled0/Disabled1? This would work like this...

Code:
GUI,Add,Checkbox,x10 y30 vMySetting Checked%MySetting% Disabled%MySettingDisabled%,Checkbox for my setting


What do you think?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2005, 6:41 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Those are some good ideas; they point out shortcomings that should definitely be fixed. I've added them to the to-do list.

The "Gui Add" command was designed under the expectation that it would be used only once for each control, each time a script is launched. I failed to anticipate that people would want to use "Gui Destroy" fairly often.

By the way, there it is also planned to someday have a "Gui Clear" command which resets all controls to some starting default.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: oops...
PostPosted: February 9th, 2005, 11:02 pm 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
Hi Chris,

What I am doing is creating a GUI for settings in my script. It basically works like this...

1. Read some settings from the registry (0/1 values)

2. Display a GUI with checkboxes initialized to show the the current settings. Some settings may be disabled depending A_IsAdmin or other settings.

3. If OK button is clicked, write the (possibly changed) settings back to the registry

It all works as it is, I just like tidier code :-)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2005, 2:27 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks, your usage is another good reason to add this capability.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2005, 10:55 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This has been added to today's release:
Quote:
Improved "Checked", "Disabled", and "Hidden" to recognize an optional 1 or 0 suffix. Example: Gui, Add, Checkbox, Enabled%Enable?% Checked%Checked?%.
Thanks for explaining why it's so useful.

Quote:
The same initialize syntax chould be valid for any GUI element that can have a default value (eg. edit) even though they can also be initialized via the third parameter.
It wouldn't be workable for most things because options can't have spaces in them (since spaces are used to separate the options).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2005, 11:41 am 
Offline

Joined: April 23rd, 2004, 4:38 am
Posts: 34
Location: Adelaide, South Australia
Thanks Chris,
It all works as expected and simplifies my script considerably. :-)


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 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