Jump to content

button (setonevent)


Recommended Posts

for a combo box in another script i had this format:

$i = GUICtrlCreateCombo ("Check Setting", 10,10,200,25)
GUICtrlSetData(-1,"Push Setting|Remove Setting","Check Setting")

$btn = GUICtrlCreateButton("OK", 225, 8, 50)

While 1
case $btn
If GUICtrlRead($i) = "Check Setting" Then
   Check_Setting()
EndIf
If GUICtrlRead($i) = "Push Setting" Then
    Push_Setting()
EndIf
If GUICtrlRead($i) = "Remove Setting" Then
    Remove_Setting()
EndIf
Wend

how can i convert this to a setonevent type (accounting for the multiple options)

i tried:

$OK_btn = GUICtrlCreateButton("OK", 225, 8, 50)
SetOnEvent($OK_btn, GuiCtrlRead($i), 1, $ParamByVal, $asset)

but it didnt work.

Link to comment
Share on other sites

if I understand your question, what I think you want is:

turn on the AutoIt GUI OnEvent option...

opt(GUIOnEventMode,1)

then...

GUICtrlSetOnEvent($OK_btn,"functionname")

func functionname()
     do stuff
endfunc
Link to comment
Share on other sites

i cant use select case bc im using setonevent throughout the rest of the script

I'm not really sure how that's relevant... in your original script, the case was in a while loop that served as the main program function which runs all the time reading the combo control...

but this way, your main prog loop can simply sleep()

while 1
   sleep(10)
wend

and the button event will run the function that checks the combobox

func functionname()
     select
     case $btn
           If GUICtrlRead($i) = "Check Setting" Then
                Check_Setting()
           EndIf
           If GUICtrlRead($i) = "Push Setting" Then
                Push_Setting()
           EndIf
           If GUICtrlRead($i) = "Remove Setting" Then
                Remove_Setting()
           EndIf
     endselect
endfunc

unless I'm missing something...

Edited by k3v
Link to comment
Share on other sites

I'm not really sure how that's relevant... in your original script, the case was in a while loop that served as the main program function which runs all the time reading the combo control...

but this way, your main prog loop can simply sleep()

while 1
   sleep(10)
wend

and the button event will run the function that checks the combobox

func functionname()
     case $btn
           If GUICtrlRead($i) = "Check Setting" Then
                Check_Setting()
           EndIf
           If GUICtrlRead($i) = "Push Setting" Then
                Push_Setting()
           EndIf
           If GUICtrlRead($i) = "Remove Setting" Then
                Remove_Setting()
           EndIf
endfunc

unless I'm missing something...

You are.

The case statement will throw an error because it's not enclosed in a switch statement. It's not required anyway since you are calling the function from the buttons OnEvent.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You have a push button for every asset displayed on a page at a time. Events are associated with each button, and these events are refreshed whenever the page is changed. Each button has a context menu which is also refreshed with the relevant events when the page is changed.

If you only have one button there is no way to know which asset you want. You need to add another menuitem in the context menu for the buttons. Do that in CreateMenus. Then in updateBtnIcons add the event with the asset as a parameter just the same as you have for the other menuitems.

(Give the variable used for the Combo a more complex name than $i, say $CmbOptionChoices or something meaningful.)

In CreateMenu add a new menuitem

$Btn_context_item[$i][20] = GUICtrlCreateMenuItem("Something to show in menu", $get_menu);if 20 is the next element to use!!!

In UpdateBtnIcons add a new line

SetOnEvent($Btn_context_item[$i][20] , "HandleCombChoice",1,$ParambyVal,$ $PC_Btns[$X][1])

Then, for the function that is called by the new context menu item do something like this

Func HandleCombChoice($asset)

 switch GuiCtrlRead($CmbOptionChoices )
 Case "rabbits"
    RabbitFunc($asset)
     
 Case "elephants"
   ElephantFunc($asset)
   
 endswitch

endfunc

OR, perhaps more simply

Func HandleCombChoice($asset)

 Call(GuiCtrlRead($CmbOptionChoices) ,$asset)

endfunc
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.
Link to comment
Share on other sites

ahh so they're going to show up in the createmenu.

hmm might as well just set a create_menu

exclusion variable

then

sub items to that.. might be better actually

whats the limit i have with context items? and what about setonevents?

thanks martin!!!

You have a push button for every asset displayed on a page at a time. Events are associated with each button, and these events are refreshed whenever the page is changed. Each button has a context menu which is also refreshed with the relevant events when the page is changed.

If you only have one button there is no way to know which asset you want. You need to add another menuitem in the context menu for the buttons. Do that in CreateMenus. Then in updateBtnIcons add the event with the asset as a parameter just the same as you have for the other menuitems.

(Give the variable used for the Combo a more complex name than $i, say $CmbOptionChoices or something meaningful.)

In CreateMenu add a new menuitem

$Btn_context_item[$i][20] = GUICtrlCreateMenuItem("Something to show in menu", $get_menu);if 20 is the next element to use!!!

In UpdateBtnIcons add a new line

SetOnEvent($Btn_context_item[$i][20] , "HandleCombChoice",1,$ParambyVal,$ $PC_Btns[$X][1])

Then, for the function that is called by the new context menu item do something like this

Func HandleCombChoice($asset)

 switch GuiCtrlRead($CmbOptionChoices )
 Case "rabbits"
    RabbitFunc($asset)
     
 Case "elephants"
   ElephantFunc($asset)
   
 endswitch

endfunc

OR, perhaps more simply

Func HandleCombChoice($asset)

 Call(GuiCtrlRead($CmbOptionChoices) ,$asset)

endfunc
Edited by gcue
Link to comment
Share on other sites

ahh so they're going to show up in the createmenu.

hmm might as well just set a create_menu

exclusion variable

then

sub items to that.. might be better actually

whats the limit i have with context items? and what about setonevents?

thanks martin!!!

The number of context menu items is currently set to a maximum of 29. If you need to increase it change the line

Global $Btn_context_item[25][30];24 buttons with up to 29 context menu items.

Since the menu items are only created once it might be easier from a maintenance point of view to move that line to the beginning of the function CreateMenus. If you do move the line then make sure you keep it as Global.

If you want to avoid having to change the declaration when you add menu items then you need a little function something like this

AddMenuItem($Btn_context_item,$i,$ItemNumber,"Text for menu item",$Btn_context)

and in there you could deal with setting the array size as needed. Maybe something for the future as 30 is probably enough for the moment.

The number of controls you can use with SetOnEvents, and the number of functions that can be called is not limited. If you add more then the array used to hold the info is automatically expanded as needed.

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...