paul1149 Posted February 5, 2010 Share Posted February 5, 2010 I've got a script that I use to clean up and capitalize file names. It's useful for downloaded videos.The structure is basically:various declarationscall a GUI dialog that asks where the file is and gives the option to exit: _Dialog()define the various string functions: Func DoStuff ()define the GUI: _Dialog ()define GUI functions: OnYes() etc...The script currently needs to be fired for each file. I would like to query the user with the dialog again, and hen either fire the script again or exit. But wherever I put another _Dialog() call, the dialog does appear but it's inert, with no functionality. The script is paused and must be manually exited.Can someone tell me generally what I'm missing here? I can post the code if necessary.Thanks,p. Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
kaotkbliss Posted February 5, 2010 Share Posted February 5, 2010 posting your code would help in finding the problem.. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
paul1149 Posted February 5, 2010 Author Share Posted February 5, 2010 posting your code would help in finding the problem.. Here you go. Thanks. expandcollapse popup#include <StringTitleCase.au3> #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: pb 5/09 Script Function: 1. select target filename in file manager. 2. fire script 4. script will invoke Title Case and remove underscores, doublespaces, flashgot verbiage from filename 5. Note: If OnNo is chosen, previous active window might need to be the file manager. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here AutoItSetOption("sendkeydelay", 10) AutoItSetOption("WinTitleMatchMode", 2) ;where is file? Use ONE of the two following locations. #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $ExitID Global $Location Local $x Local $Title_In _Dialog() Func DoStuff () WinWaitActive($Location) Send("{F2}") Send("^x") $x = ClipGet() $x = StringReplace ($x, "_", " ") $x = StringReplace ($x, " attachment filename video", "") $x = StringReplace ($x, " videoplayback", "") $x = StringReplace ($x, " ", " ") $Title_In = StringLower ($x) $x=_StringTitleCase($Title_In) ClipPut($x) Send("^v") Send("{ENTER}") Send("{Down}") ;_Dialog () EndFunc Func _Dialog() Local $YesID, $NoID GUICreate("Custom Msgbox", 210, 80) GUICtrlCreateLabel("Is File on Desktop?", 10, 10) $YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20) GUICtrlSetOnEvent($YesID, "OnYes") $NoID = GUICtrlCreateButton("No", 80, 50, 50, 20) GUICtrlSetOnEvent($NoID, "OnNo") $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUICtrlSetOnEvent($ExitID, "OnExit") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") ; Set accelerators for y and n and esc Dim $AccelKeys[3][2]=[["y", $YesID], ["n", $NoID], ["{ESC}", $ExitID]] GUISetAccelerators($AccelKeys) GUISetState() ; display the GUI While 1 Sleep(1000) WEnd EndFunc ;==>_Main ;--------------- Functions --------------- Func OnYes() $Location = "Desktop" GUIDelete(); DoStuff() Exit EndFunc ;==>OnYes Func OnNo() $Location = "C:\" GUIDelete(); DoStuff() Exit EndFunc ;==>OnNo Func OnExit() Exit EndFunc ;==>OnExit Exit Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 5, 2010 Moderators Share Posted February 5, 2010 paul1149,The main problem was that you had your While...WEnd loop in the wrong place. You need it the main part of the script so that all your functions return there - having it in a function means that the function never ends and can cause problems, as you discovered. Another tip - if you want to reuse a GUI, try creating it just the once and then Hide/Show it as required. Take a look at this - which I think does what you want:expandcollapse popup#include <StringTitleCase.au3> #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: pb 5/09 Script Function: 1. select target filename in file manager. 2. fire script 4. script will invoke Title Case and remove underscores, doublespaces, flashgot verbiage from filename 5. Note: If OnNo is chosen, previous active window might need to be the file manager. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here AutoItSetOption("sendkeydelay", 10) AutoItSetOption("WinTitleMatchMode", 2) ;where is file? Use ONE of the two following locations. #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $hGUI Global $ExitID Global $Location Local $x ; These 2 are Global because of their position - all you do with Local is get Au3Check to fire an error Local $Title_In ; Create the GUI just the once and then hide/show it as necessary _Dialog() ; This is where you want the loop!!!!! While 1 Sleep(10) WEnd Func DoStuff () MsgBox(0,"Function", "Doing Stuff") ; put your code here EndFunc Func _Dialog() Local $YesID, $NoID $hGUI = GUICreate("Custom Msgbox", 210, 80) GUICtrlCreateLabel("Is File on Desktop?", 10, 10) $YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20) GUICtrlSetOnEvent($YesID, "OnYes") $NoID = GUICtrlCreateButton("No", 80, 50, 50, 20) GUICtrlSetOnEvent($NoID, "OnNo") $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) GUICtrlSetOnEvent($ExitID, "OnExit") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") ; Set accelerators for y and n and esc Dim $AccelKeys[3][2]=[["y", $YesID], ["n", $NoID], ["{ESC}", $ExitID]] GUISetAccelerators($AccelKeys) GUISetState() ; display the GUI ; You do NOT want the loop here!!!!!!!!!!!!!!!!! ;While 1 ; Sleep(1000) ;WEnd EndFunc ;==>_Main ;--------------- Functions --------------- Func OnYes() $Location = "Desktop" ; Hide the GUI, do not delete it GUISetState(@SW_HIDE, $hGUI) ;GUIDelete(); DoStuff() ; And now show it again rather than create a new one GUISetState(@SW_SHOW, $hGUI) ;Exit EndFunc ;==>OnYes Func OnNo() $Location = "C:\" GUISetState(@SW_HIDE, $hGUI) ;GUIDelete(); DoStuff() GUISetState(@SW_SHOW, $hGUI) ;Exit EndFunc ;==>OnNo Func OnExit() Exit EndFunc ;==>OnExitI hope everything is clear - please ask if not. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
paul1149 Posted February 5, 2010 Author Share Posted February 5, 2010 M23 - a quick, but sincere thanks for the effort put forth. I'll give it a try and examine what you did, then get back later today. p. Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
paul1149 Posted February 5, 2010 Author Share Posted February 5, 2010 Melba, that's working great. Thanks much. Also, thanks for the very clear comments you added, to clue me into what you were doing. The Show/Hide option seems a better way to do it than to recreate each time. May I ask, what exactly does the While statement actually do here? Thanks again, p. Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 5, 2010 Moderators Share Posted February 5, 2010 paul1149,Have you tried removing it and running the script? That is the idle loop that keeps the whole script active - if you do not have it, the script just........ends. While on the subject of While...WEnd idle loops, in OnEvent mode it is vital to put a Sleep(10) in the loop or your CPU starts running at 100%. If you are using MessageLoop mode, then the GUIGetMsg() command sorts that out for you automatically while waiting for messages to arrive.Look in the Help file under <GUI Reference> for more details.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
paul1149 Posted February 5, 2010 Author Share Posted February 5, 2010 Yes, I knew it was vital to the script, but I don't have a good mental picture of why. In any case, thanks much again. p. Behold, I will allure her, I will lead her into the wilderness and speak tenderly to her - Ho. 2.14 Link to comment Share on other sites More sharing options...
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