Possible to register events on My Computer and other nodes?

To get bugs in the current release fixed, please report them here.

Moderator: Gurus

Possible to register events on My Computer and other nodes?

Postby simonbrads » Thu Feb 02, 2012 3:31 pm

Hi all,

Is it possible to register events on things like the My Computer node? More specifically, its children, but I can't seem to get anything to work except nodes I've created myself. For example:

Code: Select all
    Dim mainTree : Set mainTree = SDB.MainTree
    Dim myComputer : Set myComputer = mainTree.Node_MyComputer
    myComputer.Expanded = True
    Dim node : Set node = mainTree.FirstChildNode(myComputer) ' C:\
    node.UseScript = Script.ScriptPath
    Script.RegisterEvent node, "OnNodeFocused", "OnNodeFocused"

But the callback never happens. :( I'm also unable to add nodes under My Computer (I don't need to -- just testing what works!), so I wonder if the whole thing is "locked"?

Thanks a lot for any assistance!

Cheers,
Simon
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Re: Possible to register events on My Computer and other nod

Postby LoveSoldier » Fri Feb 03, 2012 2:20 am

Code: Select all
Sub OnStartup
    Dim mainTree : Set mainTree = SDB.MainTree
    Dim myComputer : Set myComputer = mainTree.Node_MyComputer
    myComputer.Expanded = True
    Dim node : Set node = mainTree.FirstChildNode(myComputer) ' C:\
    node.UseScript = Script.ScriptPath
    Script.RegisterEvent node, "OnNodeFocused", "Node_Is_Focused"
End Sub

Function Node_Is_Focused(node)
    MsgBox("Focused")
End Function
LoveSoldier
 

Re: Possible to register events on My Computer and other nod

Postby simonbrads » Fri Feb 03, 2012 4:52 am

Thanks for the response, LoveSoldier! That's pretty much what I did. It didn't work.

Then I received an e-mail notification about MM 4.0.3.1469. I upgraded -- and now it works! I hadn't upgraded on this machine since 4.0.0.1460, so I guess there was a bug that's been fixed somewhere in the last nine releases. :)

Cheers,
Simon
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Re: Possible to register events on My Computer and other nod

Postby simonbrads » Fri Feb 03, 2012 5:44 am

OK, this is totally weird. It wasn't a bug that's been fixed. It's now not working again!

If I run the MM installer and check the "Start MediaMonkey" box at the end, then the script works -- for that invokation of MM.

If I then stop MM and restart it, the script no longer works! What in the world is going on? What's different about the way the MM installer launches MM and launching it from the Start menu, taskbar, command line, etc?!
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Unable to register events on nodes at startup

Postby simonbrads » Fri Feb 03, 2012 5:53 am

I have an auto script that I thought wasn't working (although I was pretty sure the code was correct -- I'd pared it down to the bare minimum). All it does is register an "OnNodeFocused" event for a child of the MyComputer node ("C:\", for example).

This morning, I upgraded to MM 4.0.3.1469. At the end of the installation, I checked the "Start MediaMonkey" box. Guess what? The event fired! I assumed build 1469 had fixed a bug that was causing my script to fail.

A while later, I closed and restarted MM. Guess what? My script didn't work again!

What on Earth is different about the way in which the installer starts MM and the way it's invoked from the Start menu, the taskbar, the command line, etc?!

Thanks,
Simon

P.S. The script also adds a menu item, and that part of it works always -- so it's definitely being loaded/run.
Last edited by Lowlander on Fri Feb 03, 2012 12:06 pm, edited 1 time in total.
Reason: Merged with existing topic
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Re: Auto script ONLY working immediately after installation!

Postby simonbrads » Fri Feb 03, 2012 7:46 am

To provide a partial answer to my own question:

After much investigation, I don't believe there's any difference in the way the installer runs MediaMonkey.

However, what I did notice is that, first run after an installation (whether via checking "Launch MediaMonkey" or otherwise), I have two nodes under My Computer labelled "C:\ [Hard Drive]". My code registers an event for the first of these only. On subsequent runs, only the second of these appears in the tree. (They're slightly different, visually: the first/top node does not display the track info column headers; the second node does.)

I've added "MsgBox node.Path" (where node is the first child of My Computer) to my test code, and it displays "C:\" for all invocations (the first after an installation and subsequent ones).

The implication is that, during startup/initialization, that C:\ node is present (it's there for my code to register an event against), but it disappears from the tree before the UI is displayed.

I believe there's a bug here. Whether the bug is in the way the tree nodes are created (and destroyed) during startup, or if the normal startup procedure is correct (and the bug is only during the initial run), I'm not sure.

Anyway, I believe I can work around it by looping through the child nodes and registering an event for each. This is assuming that both nodes are available at startup -- I'll test this in a moment.

Cheers,
Simon
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Re: Auto script ONLY working immediately after installation!

Postby simonbrads » Fri Feb 03, 2012 8:17 am

OK, it's worse than that. The first time MM is run (btw, I just uninstalled it completely and reinstalled), this works; subsequent times, it does not.

Code: Select all
Sub OnStartup
    Dim mainTree : Set mainTree = SDB.MainTree
    Dim myComputer : Set myComputer = mainTree.Node_MyComputer
    myComputer.Expanded = True
    Dim node : Set node = mainTree.FirstChildNode(myComputer)

    While node.Path <> ""
        node.UseScript = Script.ScriptPath
        Script.RegisterEvent node, "OnNodeFocused", "Node_Is_Focused"
        Set node = mainTree.NextNode(node)
    Wend
End Sub

Function Node_Is_Focused(node)
    MsgBox node.Path & "Focused"
End Function
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Re: Auto script ONLY working immediately after installation!

Postby simonbrads » Fri Feb 03, 2012 8:25 am

If I run this code post-startup (e.g., from a menu item I've added), then it registers the events successfully.

I believe what's happening is that, at startup, my script does register the events -- but the nodes under My Computer are subsequently destroyed and re-created for some reason. (But not on the very first run after installation!)

I guess it's going to need one of the developers to confirm how the startup procedure works!
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am

Unable to register events on nodes at startup

Postby simonbrads » Fri Feb 03, 2012 8:38 am

The full details of this issue are available in this thread.

However, it boils down to the fact that it's impossible to register events on some/most nodes (in particular, I've been trying to use My Computer's child nodes) at startup. For example, the following code fails if run from OnStartup, but it works if triggered post-startup (e.g., from a menu item).

Code: Select all
Sub OnStartup ' Or some other name, if called from menu item.
    Dim mainTree : Set mainTree = SDB.MainTree
    Dim myComputer : Set myComputer = mainTree.Node_MyComputer
    myComputer.Expanded = True
    Dim node : Set node = mainTree.FirstChildNode(myComputer)

    While node.Path <> ""
        node.UseScript = Script.ScriptPath
        Script.RegisterEvent node, "OnNodeFocused", "Node_Is_Focused"
        Set node = mainTree.NextNode(node)
    Wend
End Sub

Function Node_Is_Focused(node)
    MsgBox node.Path & "Focused"
End Function

What appears to be happening is that, at startup, my script does register the events -- but the nodes under My Computer are subsequently destroyed and re-created for some reason. Strangely, this does not appear to be the case on the very first run after installation -- for that instance only, I get duplicate nodes!
Last edited by Lowlander on Fri Feb 03, 2012 10:55 am, edited 1 time in total.
Reason: Merged with existing topic
simonbrads
 
Posts: 46
Joined: Mon Mar 08, 2010 2:15 am


Return to Bug Reports (mmw)

Who is online

Users browsing this forum: No registered users and 5 guests