Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: JScript Panel script discussion/help (Read 392951 times) previous topic - next topic
0 Members and 6 Guests are viewing this topic.

Re: JScript Panel script discussion/help

Reply #500
I encountered a error about WSH Cover Panel scripts running inside the new JScript. I can't fix this error (line: 1984). Who can fix it? please. Code is too long, it is in Skins.7z.
Code: [Select]
// ==PREPROCESSOR=====================================
// @name "WSH Cover Panel"
// @version "2.0.1"
// @author "Jensen"
// @email "jensen-yg@163.com"
// ==/PREPROCESSOR====================================

//ThisPanelsName =  "WSHCoverPanel";
//===================================
// Flags, used by Menu -----------------
var MF_STRING = 0x00000000;
var MF_DISABLED = 0x00000002;
var MF_CHECKED = 0x00000008;

Re: JScript Panel script discussion/help

Reply #501
I'm trying to create a simple menu button but I can't figure out how to display a "pressed" image that appears while the contextmenu popup is open. The default button only has normal and hover states, and no matter what I try I can't seem to swap the normal image for the pressed one on-the-fly. Any help would be much appreciated.
Your code is ...uhm... to put it lightly ... it's bad. I don't even know where to start...

This code:
Code: [Select]
if(pressed == true)
    imgP = img1;
else
    imgP = img2;
Executes only once, so your imgP won't change after script initialization. But that wouldn't have worked anyway, since 'button' object has it's images initialized on creation.


Re: JScript Panel script discussion/help

Reply #502
@ColdChemical, I've updated the code. You can change the images and remove the background colour I added - I just used them fr contrast.

Code: [Select]
// ==PREPROCESSOR==
// @name "MainMenuManager All-In-One"
// @author "YBStone / T.P Wang / marc2003"
// @import "%fb2k_component_path%docs\flags.txt"
// @import "%fb2k_component_path%docs\helpers.txt"
// ==/PREPROCESSOR==

var tooltip = window.CreateTooltip();
var b = new buttons();

var normal_img = fb.ComponentPath + "samples\\complete\\images\\misc\\menu white.png";
var hover_img = fb.ComponentPath + "samples\\complete\\images\\misc\\menu black.png";

b.update = function (pressed) {
    this.buttons.menu = new button(0, 0, 60, 60, {normal : pressed ? hover_img : normal_img, hover: hover_img},function () { menu(); }, "");
    window.Repaint();
}
b.update();

function on_paint(gr) {
    gr.FillSolidRect(0, 0, window.Width, window.Height, RGB(255, 0, 0));
b.paint(gr);
}

function on_mouse_move(x, y) {
b.move(x, y);
}

function on_mouse_lbtn_up(x, y) {
    b.lbtn_up(x, y);
}

function on_mouse_leave(x, y) {
b.leave();
}

function menu() {
var basemenu = window.CreatePopupMenu();
var contextman = fb.CreateContextMenuManager();
contextman.InitNowPlaying();

var child1 = window.CreatePopupMenu(); //File
var child2 = window.CreatePopupMenu(); //Edit
var child3 = window.CreatePopupMenu(); //View
var child4 = window.CreatePopupMenu(); //Playback
var child5 = window.CreatePopupMenu(); //Library
var child6 = window.CreatePopupMenu(); //Help
var child7 = window.CreatePopupMenu(); //Now playing
    var child8 = window.CreatePopupMenu(); //cherry test
    var child9 = window.CreatePopupMenu(); //apple test

var menuman1 = fb.CreateMainMenuManager();
var menuman2 = fb.CreateMainMenuManager();
var menuman3 = fb.CreateMainMenuManager();
var menuman4 = fb.CreateMainMenuManager();
var menuman5 = fb.CreateMainMenuManager();
var menuman6 = fb.CreateMainMenuManager();

// MF_STRING is defined in docs\flags.txt
child1.AppendTo(basemenu, MF_STRING, "File");
child2.AppendTo(basemenu, MF_STRING, "Edit");
child3.AppendTo(basemenu, MF_STRING, "View");
child4.AppendTo(basemenu, MF_STRING, "Playback");
child5.AppendTo(basemenu, MF_STRING, "Library");
child6.AppendTo(basemenu, MF_STRING, "Help");
child7.AppendTo(basemenu, MF_STRING, "Now Playing");
    basemenu.AppendMenuSeparator();
    child8.AppendTo(basemenu, MF_STRING, "CHERRY");
        child8.AppendMenuItem(MF_STRING, 7501, "cherries in my mouth [Console]");
        child8.AppendMenuItem(MF_STRING, 7502, "cherries in my hand [Open]");
    basemenu.AppendMenuItem(MF_STRING, 8000, "Preferences (Apple)");

menuman1.Init("file");
menuman2.Init("edit");
menuman3.Init("View");
menuman4.Init("playback");
menuman5.Init("library");
menuman6.Init("help");

menuman1.BuildMenu(child1, 1, 200);
menuman2.BuildMenu(child2, 201, 200);
menuman3.BuildMenu(child3, 401, 300);
menuman4.BuildMenu(child4, 601, 300);
menuman5.BuildMenu(child5, 901, 300);
menuman6.BuildMenu(child6, 1201, 100);

contextman.InitNowPlaying();
contextman.BuildMenu(child7, 1301, -100);
  
    var menuY = b.buttons.menu.h + b.buttons.menu.y + 4;
   
    b.update(true);
ret = basemenu.TrackPopupMenu(b.buttons.menu.x, menuY);
    b.update();
   
switch (true) {
case(ret >= 1 && ret < 201):
menuman1.ExecuteByID(ret - 1);
break;

case (ret >= 201 && ret < 401):
menuman2.ExecuteByID(ret - 201);
break;

case (ret >= 401 && ret < 601):
menuman3.ExecuteByID(ret - 401);
break;

case (ret >= 601 && ret < 901):
menuman4.ExecuteByID(ret - 601);
break;

case (ret >= 901 && ret < 1201):
menuman5.ExecuteByID(ret - 901);
break;

case (ret >= 1201 && ret < 1301):
menuman6.ExecuteByID(ret - 1201);
break;

case (ret >= 1301 && ret < 2000):     //case (ret >= 1301):
contextman.ExecuteByID(ret - 1301);
break;
      
    case (ret == 7501):
        fb.RunMainMenuCommand("View/Console");
        break;
    case (ret == 7502):
        fb.RunMainMenuCommand("File/Open...");
        break;
    case (ret == 8000):
        fb.RunMainMenuCommand("File/Preferences");
        break;
}

basemenu.Dispose();
contextman.Dispose();
menuman1.Dispose();
menuman2.Dispose();
menuman3.Dispose();
menuman4.Dispose();
menuman5.Dispose();
menuman6.Dispose();
}

@always.beta - that script loads fine for me. Behaviour seems buggy but it doesn't crash.

Re: JScript Panel script discussion/help

Reply #503
@always.beta - that script loads fine for me. Behaviour seems buggy but it doesn't crash.
Use jscript_panel-v1.2.0.1, after a few seconds, it crashes. Please, need your help. Use WSH 1.5.6, it works. But I don't want to install two components, only jscript_panel is enough.

Code: [Select]
JScript Panel (WSH Cover Panel v2.0.1 by Jensen)
JavaScript 运行时错误:
类型不匹配
File: <main>
Line: 1984, Col: 13
<source text only available at compile time>

Re: JScript Panel script discussion/help

Reply #504
Top: JScript Panel v1.2.0.1 - cover disappears when I click something but doesn't crash - gif is 15 seconds...
Bottom WSH Panel Mod v1.5.6 - works fine???




 

Re: JScript Panel script discussion/help

Reply #505
Bottom WSH Panel Mod v1.5.6 - works fine???
Sorry, do not use it for a long time, I made a mistake. WSH Panel Mod v1.5.6 needs other DLL files. WSH Panel Mod Plus works fine.
Top: JScript Panel v1.2.0.1,  gif is 53 seconds.
Bottom: WSH Panel Plus

Re: JScript Panel script discussion/help

Reply #506
edit: The proper fix is to remove the on_metadb_changed callback at line 2370...

Code: [Select]
function on_metadb_changed(metadb, fromhook) {
    MainController.Refresh(true, metadb);
}

This function never ran in WSH panel because it needs these directives set in the preprocessor section but they are missing in this script.

Code: [Select]
// @feature "v1.4"
// @feature "watch-metadb"

If you were to add them , it would crash just like JScript Panel.



Re: JScript Panel script discussion/help

Reply #507
edit: I thought it was a bug in the component but it's not. Phew!

Re: JScript Panel script discussion/help

Reply #508
edit: The proper fix is to remove the on_metadb_changed callback at line 2370...
I removed  the on_metadb_changed callback at line 2370, need to manually refresh to display the picture.

The WSH Cover Panel script is included in the Shutter configuration, it works fine with wsh_v1.5.6 in the original configuration.
Shutter
  —— by Jensen (coding) & dReamxis (design)
>FB_Shutter_v1.1_U(Original version): based on wsh panel mod v1.5.6 & foo_ui_hacks.dll+dsound.dll+AutoItX3.dll+dynwrapx.dll
>FB_Shutter_v1.1_U+(Modified a little, may have bugs): based on wsh panel mod plus v1.5.7.4, without foo_ui_hacks.dll+dsound.dll+AutoItX3.dll+dynwrapx.dll. Replace WSH Lyric with ESLyric. Replace Albumlist with Library Tree.
>ShutterIcon: specifically designed for the shutter.
>Wsh-splitter_by_jensen(Original version): based on wsh panel mod v1.5.6 & foo_ui_hacks.dll+dsound.dll+AutoItX3.dll+dynwrapx.dll. Use Chinese to write the interface description. Looking for a good translator.
Download!

Re: JScript Panel script discussion/help

Reply #509
Your code is ...uhm... to put it lightly ... it's bad. I don't even know where to start...
That's not at all surprising to hear haha. I'm a complete novice when it comes to jscript. Despite my attempts at dissecting marc's samples and reading through online documentation, I haven't had much luck in figuring out how to do a lot of things. If there's some resource, guide, or tutorial that might help me become more proficient I would love to know about it. I'm not sure how much, if at all, this component's implementation of jscript differs from more typical environments.

@ColdChemical, I've updated the code. You can change the images and remove the background colour I added - I just used them fr contrast.
Thank you for the help, though what I'm really after is a third button state in addition to normal and hover. Ideally I'd like to have this third button-state image appear whenever the context popup menu is open (similar to the way the Windows start menu button behaves). If there's no way for the jscript panel to "know" when the popup disappears, then I suppose this wouldn't be possible.
<3

Re: JScript Panel script discussion/help

Reply #510
The WSH Cover Panel script is included in the Shutter configuration, it works fine with wsh_v1.5.6 in the original configuration.

I explained why it worked.

edit: changing my reason!!  :))

It's because on_metadb_changed function always get passed a handle list by JScript Panel. WSH panel mod and variants would do the same IF they had the preprocessors added that I mentioned. The function inside expects a handle, not a handle list and that's why it doesn't work. You can restore the function but modify it slightly...

Code: [Select]
function on_metadb_changed() {
    MainController.Refresh(true); //this function still works if you omit it
}

@ColdChemical - not really possible. Button constructors with a down state typically only support a down image while you hold the mouse key down until you release it again. With a menu, you release the button immediately after pressing and the menu stays open until you click something again. There is no clever way of doing this other than the hack I already posted.


Re: JScript Panel script discussion/help

Reply #511
I could probably script something to do it but the track changes may not be entirely seamless. I'll test and report back.

edit: I tried it and it was fine for me but YMMV.

Requires WSH panel mod or JScript panel. You can find the latter via the link in my signature.

Code: [Select]
var t = tracks_to_skip();

function on_playback_new_track() {
var handle = fb.GetNowPlaying();
if (!handle)
return;
var p = handle.Path.toLowerCase();
for (var i = 0; i < t.length; i++) {
if (t[i] == p)
return fb.Next();
}
}

function tracks_to_skip() {
var a = [];
for (var i = 0; i < plman.PlaylistCount; i++) {
if (playlist_name_is_skip(i)) {
var items = plman.GetPlaylistItems(i);
for (var j = 0; j < items.Count; j++) {
a.push(items.Item(j).Path.toLowerCase());
}
}
}
return a;
}

function playlist_name_is_skip(idx) {
return plman.GetPlaylistName(idx).toLowerCase() == "skip";
}

function on_playlist_items_added(p) {
if (playlist_name_is_skip(p))
t = tracks_to_skip();
}

function on_playlist_items_removed(p) {
if (playlist_name_is_skip(p))
t = tracks_to_skip();
}

So this has worked great all this time but I've come across an issue with a track named similarly to another. I have an album where I've split the last track into two tracks since the second half is basically a spoken word segment. I'm wanting to skip the second split track but it continues to be played automatically.

The original title tag is named Mortal Man. The title tags of the split are named Mortal Man [part 1] and Mortal Man [part 2], and the original, unedited track from which these were split from has been hidden in File Explorer so it doesn't appear in fb2k. Apart from that title tag change the only other differences between the tracks are the track numbers (I increased the track number counter by one for the second split), and the filenames (which have been updated with the track number and title tag changes). The Total Tracks tags of all tracks remain the same.

Any idea why the second split track is being played and not skipped, despite appearing in the Skip playlist?

Re: JScript Panel script discussion/help

Reply #512
Tags are irrelevant. The script only checks the full file path.

Re: JScript Panel script discussion/help

Reply #513
Tags are irrelevant. The script only checks the full file path.

Have any thoughts on why the second split track wouldn't be detected in that case, given it has a different filename?

The split tracks appear as the following (artist and album removed here for brevity, though there's no Unicode in the path fwiw):

16 - Mortal Man [part 1].flac
17 - Mortal Man [part 2].flac <- track I'd like to skip

Tested and found the [part 1] track is correctly skipped, just not the second part of the split track.

Update: found that removing the track from the Skip playlist then re-adding it by dragging it into the playlist again fixed the issue. Strange but at least I know what to try next time.

Re: JScript Panel script discussion/help

Reply #514
You can restore the function but modify it slightly...
On play a new track, still can not automatically refresh the cover, need to manually refresh or about 20 seconds automatically display the cover of the new track. I might not understand what you say, just copy and paste, thanks for the Guide, I will continue to use the old version.

Re: JScript Panel script discussion/help

Reply #515
Strange but at least I know what to try next time.

Well I can't really explain that. I added timers and found it can parse 2000 tracks in 0.007 seconds so the chances of you manually doing something quicker than it can catch up seems unlikely. However, I did find removing the playlist named skip didn't update the list of items to skip so you should add this to the end of the script...

Code: [Select]
function on_playlists_changed() {
    t = tracks_to_skip();
}

edit: I've updated it so it takes subsong in to account should you have any cuesheets or tracks with multiple chapters. The old script would skip all tracks sharing the same path. I guess all your tracks are single otherwise you would have complained but it's something I should have added originally. It also spams the console with how long it takes to parse the items..

Code: [Select]
var t = tracks_to_skip();

function on_playback_new_track() {
var handle = fb.GetNowPlaying();
if (!handle)
return;
var p = handle.Path.toLowerCase() + "|" + handle.Subsong;
for (var i = 0; i < t.length; i++) {
if (t[i] == p)
return fb.Next();
}
}

function tracks_to_skip() {
var a = [];
for (var i = 0; i < plman.PlaylistCount; i++) {
if (playlist_name_is_skip(i)) {
var b = new Date().getTime();
var items = plman.GetPlaylistItems(i);
for (var j = 0; j < items.Count; j++) {
a.push(items.Item(j).Path.toLowerCase() + "|" + items.Item(j).Subsong);
}
items.Dispose();
var c = new Date().getTime();
fb.trace("Found a playlist named skip - parsing " + a.length + " items took " + ((c - b) / 1000) + " seconds.");
}
}
return a;
}

function playlist_name_is_skip(idx) {
return plman.GetPlaylistName(idx).toLowerCase() == "skip";
}

function on_playlist_items_added(p) {
if (playlist_name_is_skip(p))
t = tracks_to_skip();
}

function on_playlist_items_removed(p) {
if (playlist_name_is_skip(p))
t = tracks_to_skip();
}

function on_playlists_changed() {
t = tracks_to_skip();
}

another edit: I suppose there is a possibility of a track being missed (not skipped) if you send a track to a new playlist and it begins playback immediately. I guess that could happen while the list is being updated. A workaround would be to be to update the list every time a new track begins but that seems a bit overkill for most cases.






Re: JScript Panel script discussion/help

Reply #518
The code inside both components is identical for on_playback_new_track.
Embarrassed,  :-[ ,forgive my poor English. I mean, after modify the code as you said, when I play a new track, still can not automatically refresh the cover, need to manually refresh or about 20 seconds automatically display the cover of the new track.

Re: JScript Panel script discussion/help

Reply #519
My previous post wasn't any kind of explanation for why it doesn't work for you. It was a simple statement of fact saying that the component works in exactly the same way when a new track begins.

Also, it works fine for me.... this gif is quite large though (12MB)..

http://imgur.com/Ut0bYbt

Re: JScript Panel script discussion/help

Reply #520
Also, it works fine for me...
My cover panel still can't be displayed immediately. In jscript_panel, on_metadb_changed and on_selection_changed return metadb values are not normal.
https://1drv.ms/i/s!AnFvs7Iqm0IrgdwWZLaNe1H7bYrMnA
Another question, can you fix the JSSP to allow it to support the 'Prefences>Display>Selection viewers'?

Re: JScript Panel script discussion/help

Reply #521
I need a little help with a script problem I have. How can I modify the replay gain data for a track from within a script?

Thanks in advance for your time.


Re: JScript Panel script discussion/help

Reply #523
@marc2003. Thanks for your quick answer. At least I didn't waste too much time trying to find a way to modify the ReplayGain data!

I have another problem.  I've recently downloaded some tracks with their Read-only flag set. This obviosly causes several file update functions to fail. Is there a way to, ideally remove the read-only flag, or at least detect it with utils.FileTest (possible additional mode)?

Re: JScript Panel script discussion/help

Reply #524
You can use the WshShell ActiveX object to run external commands.

edit: using fso as below is better