Script help

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Script help

Post by Bex » Sun Oct 22, 2006 11:49 am

Hi,

I'm working on a script which creates a node. I want to add SDB.UI.Menu_Pop_Tree menu item which only is enabled if my new node (or its subnode) is selected. Is that possible? If it is, how do i do it?

I also want to add a Menu_Pop_TrackList menu which only is enabled if tracks from my nodes above is selected. Gues it's kind of same solution to the problem above.

I have searched the forum but without finding a solution...


I also wonder what these TreeNodeEvents are supposed to be used to:
- OnExecMenuItem
- OnExecTrackMenuItem
- OnShowMenuItem
- OnShowTrackMenuItem
They all have ItemIndex as parameter.
But what ItemIndex?
Actually, what is ItemIndex?


Help!
/Bex
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Location: Belgium
Contact:

Post by Steegy » Sun Oct 22, 2006 4:17 pm

Bex wrote:...I want to add SDB.UI.Menu_Pop_Tree menu item which only is enabled if my new node (or its subnode) is selected....
You're not the only scripter wanting this (I officially know 4): http://www.mediamonkey.com/forum/viewto ... 8404#38404

I'll let an other scripter answer your 2nd question as I can't help very much (I try the events I think I need before using them in a script).

Cheers
Steegy
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex » Sun Oct 22, 2006 4:39 pm

Ok thanks Steegy. I hope Jiri add this function in next version.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex » Sun Oct 22, 2006 6:21 pm

I actually solved it! :D :D
At least I think I did. I involved the OnChangedSelection event to change the visibility of the menu.

It seems to work just fine. Do anyone see any potential errors/drawbacks?

Here's what I did:

Code: Select all

' Example code to on how make own menu entries Visible/Not Visible based on what node is selected
Sub onstartup 
  Dim Tree : Set Tree = SDB.MainTree
  Dim Node : Set Node = Tree.CreateNode
  Node.Caption = "Test Node"
  Node.IconIndex = 47
  Node.CustomNodeId = 1111 'Must not already exist
  Tree.AddNode Tree.Node_Library, Node, 1
  
' Add a menu entry to the Pop tree menu in main window
  Dim mnu
  Set Mnu = SDB.UI.AddMenuItem( SDB.UI.Menu_Pop_Tree , -1, 1)
  Mnu.Caption = "&Test Menu"
  Mnu.IconIndex = 9
  Mnu.UseScript=Script.ScriptPath
  
  Script.RegisterEvent SDB, "OnChangedSelection", "FixMnuVisible"
  
  SDB.Objects("Mnu") = Mnu
  SDB.Objects("Mnu").Visible = False
end sub

sub FixMnuVisible
  dim myNode
  Set myNode = SDB.MainTree.CurrentNode
  if myNode.CustomNodeId = 1111 Then
     SDB.Objects("Mnu").Visible = True
  else
     SDB.Objects("Mnu").Visible = False
  end if
End sub
Edit: code edited
Last edited by Bex on Mon Oct 23, 2006 9:13 am, edited 1 time in total.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Location: Belgium
Contact:

Post by Steegy » Sun Oct 22, 2006 7:43 pm

If that works (it looks good), then we must have overlooked the fact that this new event OnChangedSelection solves this problem :lol: :oops:
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Mon Oct 23, 2006 3:38 am

I would recommend using CustomNodeId instead of NodeType as the custom properties are designed for this kind of thing. Great workaround! I've used this method with toolbar buttons but it never occurred to me to try it with popup menu items! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex » Mon Oct 23, 2006 5:07 am

Thanks guys!
But if you create a popup menu item which you want to display in a regular node then you need to use NodeType, don't you? (e.g. psyxonovas merge playlists)
Must have missed that script with the toolbar workaround, which is it?
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Mon Oct 23, 2006 5:47 am

It's not been released because it is a custom script someone has requested, and it's not finished yet.

It's probably ok to use NodeType, but as this value is used internally it's not something I'd change myself, as I don't know what internall it is used for.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm
Location: Belgium
Contact:

Post by Steegy » Mon Oct 23, 2006 6:13 am

Trixmoto is right. Maybe CustomNodeID is better.

Here's how NodeType is used: http://home.tiscali.be/ruben.castelein/ ... eTypes.txt (e.g. good to recognise Custom Nodes).
So if you use NodeType, make sure it's > 255.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex » Mon Oct 23, 2006 7:05 am

Yes, it's probably better to use CustomNodeID on custom nodes but to id regular nodes you must use NodeType because they dont have a CustomNodeID, do they?

I've already studied your great map of NodeType values (along with the other helpfull tips on the script resource page) but thanks anyway! :D


Another thing. Has any of you used OnNodeDragDrop in a script which I can study?
Pablo has used it in Magic Nodes but I have problems to understand how that script is working :oops:
I still have a lot to learn with vbscript, as you can see in my messy codes, so I greatfully receive any tips/help I can get! :D
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex » Mon Oct 23, 2006 9:11 am

Ok guys, I can confirm that it is a very bad idea to assign a NodeType value to a custom nodes since it gives strange unwanted behaviour to the node...
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Mon Oct 23, 2006 10:42 am

I feared it might! :-?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Post Reply