aommaster Posted December 29, 2008 Posted December 29, 2008 Hey everyone!So I have a program written up and I'm stuck on a part which requires a child GUI window, and I'm not exactly sure how to fix this.The GUIOnEventMode is set to on, so I'm using GUICTRLSetOnEvent functions.My program literally has a structure like this:GUI window createdUser adds some filesProgram goes through each file and looks for a required stringProgram produces another window that prompts for the user input based on each and every instance of the found stringThe part in red is where I'm having trouble with.I basically add the files, push a button which calls the search function. The search function successfully finds the required strings that require a user prompt, but I'm not sure on how to do the next part.I can produce the GUI, but I have no way for telling Autoit to wait for a user interaction with the dialog before continuing the loop and producing another dialog box.I have tried:*Changing the oneventmode, but it seems that autoit doesn't like that very much*Adding a while 1 sleep(100) loop in the function that displays the box, however, it seems that I cannot call any of the other guifunctions from that box. It looks like that I can't exit the loop to call the other sub-functions that are required to close that boxSo in summary: I have a child window that will be produced any N times through a loop. How do I tell autoit to wait for the user to either close or press the okay button on that window before continuing the loop that produces this gui again?Thanks everyone!
ChangMinYang Posted December 29, 2008 Posted December 29, 2008 Hey everyone!So I have a program written up and I'm stuck on a part which requires a child GUI window, and I'm not exactly sure how to fix this.The GUIOnEventMode is set to on, so I'm using GUICTRLSetOnEvent functions.My program literally has a structure like this:GUI window createdUser adds some filesProgram goes through each file and looks for a required stringProgram produces another window that prompts for the user input based on each and every instance of the found stringThe part in red is where I'm having trouble with.I basically add the files, push a button which calls the search function. The search function successfully finds the required strings that require a user prompt, but I'm not sure on how to do the next part.I can produce the GUI, but I have no way for telling Autoit to wait for a user interaction with the dialog before continuing the loop and producing another dialog box.I have tried:*Changing the oneventmode, but it seems that autoit doesn't like that very much*Adding a while 1 sleep(100) loop in the function that displays the box, however, it seems that I cannot call any of the other guifunctions from that box. It looks like that I can't exit the loop to call the other sub-functions that are required to close that boxSo in summary: I have a child window that will be produced any N times through a loop. How do I tell autoit to wait for the user to either close or press the okay button on that window before continuing the loop that produces this gui again?Thanks everyone!Introduce to HotKey.How about this?
aommaster Posted December 29, 2008 Author Posted December 29, 2008 Introduce to HotKey.How about this?I was condering having the loop manually incremented by the user (my idea was using another GUI button, say an arrow). But is there no other way of completely automating it?I tried WinWaitClose too, but autoit halts my script, which completely disables any functionality
Moderators SmOke_N Posted December 29, 2008 Moderators Posted December 29, 2008 Might take a look at GUIRegisterMsg() and look at WM_NOTIFY options. Depending on what you want to do, you could setup a specific notification value ... Really depends on what "type" of notification you are trying to receive and when. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
aommaster Posted December 29, 2008 Author Posted December 29, 2008 Post the code and we can help youI can't post the whole code, since it's more than 1000 lines. But below is a condensed version from which you should be able to replicate my problem. expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #Include <String.au3> #Include <File.au3> global $windowtitle="Canned Speech Assistant V0.5 by Aommaster" global $childwin=0 Opt("GUIOnEventMode", 1) $window= GUICreate($windowtitle, 400, 300, -1, -1, BitOr($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $send=guictrlcreatebutton("Send to Post Previewer", 100, 100) GUICtrlSetResizing ( -1, 802) guictrlsetonevent(-1, "sendtopreviewer") guisetstate(@sw_show) while 1 sleep(100) Wend func sendtopreviewer() $file2=fileopen(@scriptdir & "\HJT ~ HJT Speech.txt", 0) $string=fileread($file2) $check=stringinstr($string, "@@@@@") if $check==0 Then msgbox(0, "Check value", $check) else $array=_stringbetween($string, "@@@@@", "@@@@@") $arraysize=ubound($array) for $l=0 to $arraysize -1 $stringtoreplace="@@@@@" & $array[$l] & "@@@@@" $userinput=getuserinput("HJT ~ HJT Speech", $array[$l]) Next EndIf EndFunc func getuserinput($guititle, $defaultvalue) $childWin=GuiCreate($guititle,400,400, -1, -1, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "closechild",$childWin) GuiCtrlCreateEdit($defaultvalue,5,5,390,350,$ES_MULTILINE) $acceptinput=guictrlcreatebutton("Ok", 20, 355) guictrlsetonevent(-1, "acceptinput") $close=guictrlcreatebutton("Cancel", 50, 355) guictrlsetonevent(-1, "closechild") GuiSetState(@sw_show) EndFunc func closechild() guidelete($childwin) Return EndFunc func acceptinput() guidelete($childwin) Return EndFunc func closeclicked() exit EndFunc In addition to this, you'll need one extra file, which I have attached. Place that in the same directory as you are running your script. When you press the button, you'll notice that you get flooded with 4 GUI windows created, one for each of the fields in that text file that need to be editted. I need autoit to wait for the user to either close, press cancel, or press okay on a window before the next one pops up. Thanks!HJT___HJT_Speech.txt
rasim Posted December 31, 2008 Posted December 31, 2008 @aommasterExample:expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <String.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) Global $childWin Global $aChildWindow $window = GUICreate("Test", 400, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $send = GUICtrlCreateButton("Send to Post Previewer", 100, 100) GUICtrlSetResizing(-1, 802) GUICtrlSetOnEvent(-1, "sendtopreviewer") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func sendtopreviewer() $file2 = FileOpen(@ScriptDir & "\HJT ~ HJT Speech.txt", 0) $string = FileRead($file2) FileClose($file2) $check = StringInStr($string, "@@@@@") If $check = 0 Then MsgBox(0, "Check value", $check) Else $array = _StringBetween($string, "@@@@@", "@@@@@") $arraysize = UBound($array) $aChildWindow = $array For $l = 0 To $arraysize - 1 $stringtoreplace = "@@@@@" & $array[$l] & "@@@@@" $userinput = getuserinput("HJT ~ HJT Speech", $array[$l], $l) Next GUISetState(@SW_SHOW, $aChildWindow[0]) EndIf EndFunc ;==>sendtopreviewer Func getuserinput($guititle, $defaultvalue, $iIndex) $aChildWindow[$iIndex] = GUICreate($guititle, 400, 400, -1, -1, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "closechild", $childWin) GUICtrlCreateEdit($defaultvalue, 5, 5, 390, 350, $ES_MULTILINE) $acceptinput = GUICtrlCreateButton("Ok", 20, 355) GUICtrlSetOnEvent(-1, "closechild") $close = GUICtrlCreateButton("Cancel", 50, 355) GUICtrlSetOnEvent(-1, "closechild") EndFunc ;==>getuserinput Func closechild() Local $i For $i = 0 To UBound($aChildWindow) - 1 If $aChildWindow[$i] = @GUI_WinHandle Then GUIDelete($aChildWindow[$i]) $aChildWindow[$i] = 0 If ($i < UBound($aChildWindow) - 1) Then GUISetState(@SW_SHOW, $aChildWindow[$i + 1]) EndIf Next EndFunc ;==>closechild Func closeclicked() Exit EndFunc ;==>closeclicked
aommaster Posted December 31, 2008 Author Posted December 31, 2008 Rasim! That is amazing! It actually fixed my problem completely Thanks so much! I noticed you changed the close child function, but were there any other changes made to the script?
aommaster Posted December 31, 2008 Author Posted December 31, 2008 (edited) Rasim, I've got a couple of questions regarding this code: 1. If I want to have the values from the edit box read and passed on the parent window, in essence, this function: $userinput = getuserinput("HJT ~ HJT Speech", $array[$l], $l) How would I do it? 2.If multiple files are being read in the loop (the example I gave only has one, but in reality, multiple files will be read), how do I change the loop so that only a window from one file is displayed at a time? 3.The else statement is not yet complete. I still have to add a GUICTRLSetData similar to the first if statement. However, this data is based on the user input in the dialog boxes. Will this have a problem on the loop? Edit: Rasim, if you would like to discuss this over PM, where I can send you the whole script source code + compiled version (because of the fileinstalls), let me know. Edited December 31, 2008 by aommaster
rasim Posted January 1, 2009 Posted January 1, 2009 @aommaster If I want to have the values from the edit box read and passed on the parent window, in essence, this function: $userinput = getuserinput("HJT ~ HJT Speech", $array[$l], $l)This? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <String.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) Global $childWin Global $aChildWindow, $aEdit_Child $window = GUICreate("Test", 400, 300, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $cEdit = GUICtrlCreateEdit("", 10, 10, 380, 160) $send = GUICtrlCreateButton("Send to Post Previewer", 11, 246) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUICtrlSetOnEvent(-1, "sendtopreviewer") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func sendtopreviewer() $file2 = FileOpen(@ScriptDir & "\HJT ~ HJT Speech.txt", 0) $string = FileRead($file2) FileClose($file2) $check = StringInStr($string, "@@@@@") If $check = 0 Then MsgBox(0, "Check value", $check) Else $array = _StringBetween($string, "@@@@@", "@@@@@") $arraysize = UBound($array) $aChildWindow = $array $aEdit_Child = $array For $l = 0 To $arraysize - 1 $stringtoreplace = "@@@@@" & $array[$l] & "@@@@@" $userinput = getuserinput("HJT ~ HJT Speech", $array[$l], $l) Next GUISetState(@SW_SHOW, $aChildWindow[0]) EndIf EndFunc ;==>sendtopreviewer Func getuserinput($guititle, $defaultvalue, $iIndex) $aChildWindow[$iIndex] = GUICreate($guititle, 400, 400, -1, -1, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_DataCancel", $childWin) $aEdit_Child[$iIndex] = GUICtrlCreateEdit($defaultvalue, 5, 5, 390, 350, $ES_MULTILINE) GUICtrlCreateButton("Ok", 20, 355) GUICtrlSetOnEvent(-1, "_DataSet") GUICtrlCreateButton("Cancel", 50, 355) GUICtrlSetOnEvent(-1, "_DataCancel") EndFunc ;==>getuserinput Func _DataSet() closechild(1) EndFunc Func _DataCancel() closechild() EndFunc Func closechild($iFlag = 0) Local $i For $i = 0 To UBound($aChildWindow) - 1 If $aChildWindow[$i] = @GUI_WinHandle Then If $iFlag Then GUICtrlSetData($cEdit, GUICtrlRead($aEdit_Child[$i]) & @CRLF, 1) GUIDelete($aChildWindow[$i]) $aChildWindow[$i] = 0 $aEdit_Child[$i] = 0 If ($i < UBound($aChildWindow) - 1) Then GUISetState(@SW_SHOW, $aChildWindow[$i + 1]) EndIf Next EndFunc ;==>closechild Func closeclicked() Exit EndFunc ;==>closeclicked The help file and the practice is your friends
aommaster Posted January 1, 2009 Author Posted January 1, 2009 Hi Rasim! Thank you very much for your help! I was wondering if you could help me solve one more problem. My SendToPreviewer function looks like this: func sendtopreviewer() $lines=_filecountlines(@scriptdir & "\Data\Speechorder.tmp") if $lines==0 Then msgbox(0, "Error", "No speeches to send to previewer. Please add speeches") Else $file=fileopen(@scriptdir & "\Data\Speechorder.tmp", 0) for $k=1 to $lines $line=filereadline($file) $filedata=stringsplit($line, "|") $file2=fileopen($filedata[2], 0) ;msgbox(0, "", $filedata[2]) $string=fileread($file2) $check=stringinstr($string, "@@@@@") if $check==0 Then $tag='[color="#008000"][u]Step ' & $k &':[/u][/color]' $initial=guictrlread($message) guictrlsetdata($message, $initial & $tag & @crlf & $string & @CRLF & @CRLF) else $speechtoedit=$string $array=_stringbetween($string, "@@@@@", "@@@@@") $arraysize=ubound($array) $childwindow=$array $arraypointer=$array for $l=0 to $arraysize -1 ;~ $stringtoreplace="@@@@@" & $array[$l] & "@@@@@" $input=getuserinput($filedata[1], $array[$l], $l) ;~ $tag='[color="#008000"][u]Step ' & $k &':[/u][/color]' ;~ $initial=guictrlread($message) ;~ guictrlsetdata($message, $userinput) Next GUISetState(@SW_SHOW, $ChildWindow[0]) EndIf Next ControlCommand ( $windowtitle, "", $tab, "TabLeft") EndIf EndFunc As you can see from the first if statement, there are multiple files that need to be processed by this program. The problem arises when multiple files satisfy the @@@@@ requirement. Multiple windows pop up and it causes a big problem with arrays and variable naming. Any ideas on how to fix this? Thanks again for your help Rasim!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now