Jump to content

GUICtrlSetOnEvent does nothing


Recommended Posts

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.

#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()
EndFunc

mplayerwin() 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

  • Moderators

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 by Melba23
I need another click for some functions! :D

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Again, the rest of the code is at http://code.google.com/p/jtvmgr/source/browse/#git%2Fsrc

I 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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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. :sweating:

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 Gude
How 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

  • Moderators

SwooshyCueb,

AdmiralAlkex has just beaten me to it. Do you understand the problem? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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.7z

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.

SwooshyCueb,

AdmiralAlkex has just beaten me to it. Do you understand the problem? :huh:

M23

Doesn'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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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...... :whistle:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...