Sign in to follow this  
Followers 0
Mic

autoit data binding e.g. $myArray[3] to $myButton.text?

5 posts in this topic

Is it possible to bind data to controls, where the displayed text of a button or label is grabbed from a variable or array and when that data changes the control is updated? tia.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can look into an adlibregister, to continually check the text of the button vs the new text...change when required.

Or, in your loop, do the checks:

Global $iCounter = 0
Global $sButton1Prefix = "Button1Text"
Global $sButton2Prefix = "Button2Text"
Global $aButtons[2][2]=[[$sButton1Prefix & $iCounter,""],[$sButton2Prefix & $iCounter,""]]
#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $msg
    $h = GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 2)
    $aButtons[0][1] = GUICtrlCreateButton($aButtons[0][0], 10, 30, 100)
    $aButtons[1][1] = GUICtrlCreateButton($aButtons[1][0], 0, -1)

    GUISetState() ; will display an  dialog box with 2 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect

        Sleep(1000)
        $iCounter+=1
        ; something chnages the array...just manually doing so now
        $aButtons[0][0] = $sButton1Prefix & $iCounter
        $aButtons[1][0] = $sButton2Prefix & $iCounter

        If Not (ControlGetText($h,"",$aButtons[0][1]) = $aButtons[0][0]) Then ControlSetText($h,"",$aButtons[0][1], $aButtons[0][0])
        If Not (ControlGetText($h,"",$aButtons[1][1]) = $aButtons[1][0]) Then ControlSetText($h,"",$aButtons[1][1], $aButtons[1][0])

    WEnd
EndFunc   ;==>Example

adlibregister route:

Global $iCounter = 0
Global $sButton1Prefix = "Button1Text"
Global $sButton2Prefix = "Button2Text"
Global $aButtons[2][2]=[[$sButton1Prefix & $iCounter,""],[$sButton2Prefix & $iCounter,""]]
#include <GUIConstantsEx.au3>

AdlibRegister("changebuttonArrayText",5000)
AdlibRegister("checkbuttonTextagainstArray",200)
Example()


Func Example()
    Local $msg
    Global $h = GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 2)
    $aButtons[0][1] = GUICtrlCreateButton($aButtons[0][0], 10, 30, 100)
    $aButtons[1][1] = GUICtrlCreateButton($aButtons[1][0], 0, -1)

    GUISetState() ; will display an  dialog box with 2 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>Example

Func changebuttonArrayText()
    $iCounter+=1
    ; something chnages the array...just manually doing so now
    $aButtons[0][0] = $sButton1Prefix & $iCounter
    $aButtons[1][0] = $sButton2Prefix & $iCounter
EndFunc

Func checkbuttonTextagainstArray()
    ; something chnages the array...just manually doing so now
    If Not (ControlGetText($h,"",$aButtons[0][1]) = $aButtons[0][0]) Then ControlSetText($h,"",$aButtons[0][1], $aButtons[0][0])
    If Not (ControlGetText($h,"",$aButtons[1][1]) = $aButtons[1][0]) Then ControlSetText($h,"",$aButtons[1][1], $aButtons[1][0])
EndFunc
Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Ah I thought ... the manual method :-) .... but of course the "automatic" 2-way data binding in Flex ActionScript and ExtJS javascript just means that somebody has already written the code :-) Thanks for the info.

Share this post


Link to post
Share on other sites

Mic,

An alternative...

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
; *** End added by AutoIt3Wrapper ***

#AutoIt3Wrapper_Add_Constants=n

local $aButtonText = [ _
                        'My Button', _
                        'Your Button', _
                        'The Button', _
                        'A Button', _
                        'Button', _
                        'What Button?']

local $gui010   =   guicreate('Click the Button',250,50)
local $aSize    =   wingetclientsize($gui010)
local $btn010   =   guictrlcreatebutton($aButtonText[random(0,ubound($aButtonText)-1,1)],20,$aSize[1]-40,$aSize[0]-40,20,$ss_sunken)
                    guisetstate()

local $sButtonSave = guictrlread($btn010)

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $btn010
            $sButtonSave = $aButtonText[random(0,ubound($aButtonText)-1,1)]
            while guictrlread($btn010) = $sButtonSave
                $sButtonSave = $aButtonText[random(0,ubound($aButtonText)-1,1)]
            wend
            guictrlsetdata($btn010,$sButtonSave)
    EndSwitch
WEnd

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Mic,

Goofing around with the idea of "binding" a control to a variable...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>

#AutoIt3Wrapper_Add_Constants=n

local $aNames = ['Tom','Dick','Harry','Joe','Aggamemnon']

local $lbl010_text = 'My Label', $btn010_text = 'My Button', $chk010_text = 'My Checkbox', $ret

local $gui010   =   guicreate('Control Text Binder',300,300)
local $lbl010   =   guictrlcreatelabel('',20,20,200,20,bitor($ss_sunken,$ss_center))
local $btn010   =   guictrlcreatebutton('',20,50,200,20)
local $chk010   =   GUICtrlCreateCheckbox('',20,80,200,20)
                    guisetstate()

local $aBinder = [['','']]

_Bind($lbl010,'lbl010_text')
_Bind($btn010,'btn010_text')
_Bind($chk010,'chk010_text')

adlibregister('Chk_Bind')

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch

    assign($aBinder[random(0,ubound($aBinder) - 1,1)][1],$aNames[random(0,ubound($aNames) - 1,1)])

WEnd

func _Bind($ctl,$str)
    if $aBinder[ubound($aBinder)-1][0] <> '' then redim $aBinder[ubound($aBinder)+1][2]
    $aBinder[ubound($aBinder) - 1][0] = $ctl
    $aBinder[ubound($aBinder) - 1][1] = $str
endfunc

func Chk_Bind()
    for $1 = 0 to ubound($aBinder) - 1
        if guictrlread($aBinder[$1][0]) = eval($aBinder[$1][1]) then ContinueLoop
        guictrlsetdata($aBinder[$1][0],eval($aBinder[$1][1]))
    next
endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0