SwooshyCueb Posted July 30, 2012 Share Posted July 30, 2012 I have a bit of a unique problem.I am making a rather large program using AutoIt, and thus my code is spread out across eleven files. I have it hosted at http://code.google.com/p/jtvmgr/source/browse/#git%2Fsrc but the particular problem I'm having is in the player.au3 file.expandcollapse popup#cs This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ce Func mplayerwin() dependprompt() Opt("GUIOnEventMode", 1) $u32 = DllOpen("user32.dll") $v = _GUICtrlListView_GetSelectionMark($vidlisthnd) + 1 Global $playergui = GUICreate("Video Player (" & $archive[$v][11] & ")", 640, 520, -1, -1, BitOR($WS_CAPTION,$WS_MINIMIZEBOX,$WS_THICKFRAME,$WS_CLIPCHILDREN,$WS_MAXIMIZEBOX), $WS_EX_WINDOWEDGE, $listwindow) $playerpos = WinGetPos($playergui) $mplabel = GUICtrlCreateLabel("",0,0,640,480) Global $mplayerp = Run('"' & $pd & '\mplayer.exe" -slave -vo gl2 -wid ' & Number(GUICtrlGetHandle($mplabel)) & ' "' & $archive[$v][7] & '"', $pd, @SW_HIDE, $STDIN_CHILD+$STDOUT_CHILD+$STDERR_CHILD) Global $seek = GUICtrlCreateSlider(40, 488, 560, 25, BitOR($TBS_TOP,$TBS_LEFT,$TBS_BOTH,$TBS_NOTICKS)) Global $hseek = GUICtrlGetHandle($seek) GUICtrlSendMsg($seek, "TBM_SETRANGEMIN", 0, 0) GUICtrlSendMsg($seek, "TBM_SETRANGEMAX", 0, 100) Global $mpause = GUICtrlCreateButton("", 8, 488, 25, 25, $BS_BITMAP) _ResourceSetImageToCtrl($mpause, "PAUSE.PNG") Global $isplaying = 1 Global $mmute = GUICtrlCreateButton("", 608, 488, 25, 25, $BS_BITMAP) _ResourceSetImageToCtrl($mmute, "UNMUTED.PNG") GUISetOnEvent($GUI_EVENT_CLOSE, "killplayer") GUICtrlSetOnEvent($mmute, "togglemute") GUICtrlSetOnEvent($mpause, "playpause") GUICtrlSetOnEvent($seek, "seek") GUISetState(@SW_SHOW, $playergui) GUISetState(@SW_DISABLE, $listwindow) GUISetState(@SW_ENABLE, $playergui) While $ps = 0 getpos() Sleep($stddelay) WEnd EndFunc Func togglemute() If $muted = 1 Then StdinWrite($mplayerp, "mute 0" & @LF) _ResourceSetImageToCtrl($mmute, "UNMUTED.PNG") $muted = 0 Else StdinWrite($mplayerp, "mute 1" & @LF) _ResourceSetImageToCtrl($mmute, "MUTED.PNG") $muted = 1 EndIf EndFunc Func playpause() StdinWrite($mplayerp, "pause" & @LF) If $isplaying = 1 Then _ResourceSetImageToCtrl($mpause, "PLAY.PNG") $isplaying = 0 Else _ResourceSetImageToCtrl($mpause, "PAUSE.PNG") $isplaying = 1 EndIf EndFunc Func killplayer() GUISetState(@SW_HIDE, $playergui) GUIDelete($playergui) ProcessClose($mplayerp) DllClose($u32) GUISwitch($listwindow) GUISetState(@SW_ENABLE) WinActivate($listwindow) $ps = 1 EndFunc Func getpos() StdinWrite($mplayerp, "get_property percent_pos" & @LF) $mpo = StdoutRead($mplayerp) If StringInStr($mpo, "ANS_percent_pos=") And _IsPressed(01, $u32) = 0 Then $seekar = _StringBetween($mpo, "ANS_percent_pos=", @CRLF) GUICtrlSetData($seek, StringStripWS($seekar[0], 7)) EndIf EndFunc Func seek() StdinWrite($mplayerp, "seek " & GUICtrlRead($seek) & " 1" & @LF) getpos() EndFuncmplayerwin() is called from another GUICtrlOnEvent from the main GUI, $listwindow, which is created in listgui() in gui.au3. The OnEvent code works fine in every window but the one in mplayerwin(). Nothing happens on attempting to close the window, click a button, or drag the slider.Can someone help me with this? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 30, 2012 Moderators Share Posted July 30, 2012 (edited) SwooshyCueb,Almost impossible to say with such a short piece of code, but I do see that you are declaring variables in Global Scope within the mplayerwin function. This is not good coding practice and can lead to multiple variables with the same name - and then you find that a variable does not hold what you think it does. Incidentally, why split your script into so many files? If you use the #region/#endregion directives in SciTE you can collapse whole sections into a single line - I have a 4500+ line script which displays in 17 lines and it takes only 3 clicks to open any function within it. M23 Edited July 30, 2012 by Melba23 I need another click for some functions! :D 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...
SwooshyCueb Posted July 30, 2012 Author Share Posted July 30, 2012 Again, the rest of the code is at http://code.google.com/p/jtvmgr/source/browse/#git%2FsrcI didn't want to make a HUEG post, so I didn't include all the code. Though, if you'd prefer that I did post all my code anyway, I will. I don't plan on keeping it updated here, though.I don't think I have any variable conflicts, but I'm working on getting those Globals out of the functions.As for using separate files, It's just a preference I have. I prefer switching between tabs to traversing folds. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 30, 2012 Moderators Share Posted July 30, 2012 SwooshyCueb, You might like multiple files, but I do not. Sorry, but I am not spending my own valuable (to me at least ) time downloading them all from that repository - nor copy/pasting them if you put them in a post. If you would like me to help, please attach them all in a single zip. 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...
SwooshyCueb Posted July 30, 2012 Author Share Posted July 30, 2012 Okedok, here ya go: https://dl.dropbox.com/u/27169171/src.7z Thanks in advance Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2012 Moderators Share Posted July 31, 2012 SwooshyCueb, That has really confirmed my preference for all the script in a single file - searching for dependencies across several files is damn near impossible when you do not know the structure of the code. Looking for the function called by an OnEvent call takes more effort that I would be prepared to make. I have tried to follow the code and nothing jumps out at me as to why your GUI does not work - let me play with it a while. Part of the problem is that I do not have half the includes nor the software (and have no intention of installing it either!) so actually running the script is impossible. I will see if I can strip the code down and reproduce the problem. 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...
SwooshyCueb Posted July 31, 2012 Author Share Posted July 31, 2012 Thank you! You're awesome for doing this, by the way. Link to comment Share on other sites More sharing options...
BrewManNH Posted July 31, 2012 Share Posted July 31, 2012 First thing I would do is to move ALL global variable declarations out of the individual functions and put them first thing in your script. The second thing I would do is run Tidy on them, it's considered good coding practice to put your functions at the end of the script and not at the beginning of it. The way the gui.au3 file is written, if you tidy it, you get undeclared variable errors because you declared them as Global in another function. Then, I would move/remove all of the Opt("GUIOnEvenMode", 1) statements to your first script, you have that in there 3 times in 3 different includes, that's overkill. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted July 31, 2012 Share Posted July 31, 2012 mplayerwin has a loop so it never ends, hence AutoIt can never get to the next event in the queue. You must remove the loop. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2012 Moderators Share Posted July 31, 2012 SwooshyCueb, AdmiralAlkex has just beaten me to it. Do you understand the problem? 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...
SwooshyCueb Posted July 31, 2012 Author Share Posted July 31, 2012 First thing I would do is to move ALL global variable declarations out of the individual functions and put them first thing in your script. The second thing I would do is run Tidy on them, it's considered good coding practice to put your functions at the end of the script and not at the beginning of it. The way the gui.au3 file is written, if you tidy it, you get undeclared variable errors because you declared them as Global in another function. Then, I would move/remove all of the Opt("GUIOnEvenMode", 1) statements to your first script, you have that in there 3 times in 3 different includes, that's overkill.Done! Here's the updated source: https://dl.dropbox.com/u/27169171/JTVmgr0.2.9.0.7zmplayerwin has a loop so it never ends, hence AutoIt can never get to the next event in the queue. You must remove the loop.SwooshyCueb,AdmiralAlkex has just beaten me to it. Do you understand the problem? M23Doesn't GUIOnEventMode interrupt the loop when an event with an associated function occurs? I have killplayer() set $ps to 1, which should break the loop once the player window is closed. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2012 Moderators Share Posted July 31, 2012 SwooshyCueb,Doesn't GUIOnEventMode interrupt the loop when an event with an associated function occurs?No, but lots of people think it does, which is why I asked the question. Only 1 function can be run at the same time so you always need to return to the main idle loop if you want another function to be run. You were staying in the loop within the mplayerwin function and so blocking all subsequent OnEvent calls as the function never ended. Take a look at the Interrupting a running function tutorial in the Wiki - it explains all this in some detail for both MessageLoop and OnEvent modes. And please come back and ask again if anything is still unclear. 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...
SwooshyCueb Posted July 31, 2012 Author Share Posted July 31, 2012 You've been a great help. Many thanks to all of you. I do believe you guys will get a mention in the Readme or about dialog box.If you want to follow this project, it's hosted over at http://code.google.com/p/jtvmgr/ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2012 Moderators Share Posted July 31, 2012 SwooshyCueb, Delighted we could help. Now if we can only get you to change your coding method to make it easier for us the next time you call...... 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...
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