Skip to main content

Notice

If you are using a Hotmail or Outlook email address, please change it now, as Microsoft is rejecting all email from our service outright.
Topic: Spider Monkey Panel (foo_spider_monkey_panel) (Read 93438 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #600
I feel that you are talking past each other =)
So, I'll try to sum up all the things that @snotlicker said.

@regor , as it was mentioned above, in quite a few programming languages (and even in RegExp and windows command line) `\` character is used as an escape character or to form a control character. For example, `\n` is a control character for a new line, `\"` - escape the quote character.
Values that can be seen in property dialog have all the escape chars and control chars parsed.

So, in JS (and SMP) it will work like this:
Code: [Select]
window.SetProperty("escape_1", "\"");
console.log(window.GetProperty("escape_1"));  // Logged and displayed in Property dialog as `"`

window.SetProperty("escape_2", "\\");
console.log(window.GetProperty("escape_2"));  // Logged and displayed as `\`

window.SetProperty("path_1", "path\\to\\file.ext");
console.log(window.GetProperty("path_1")); // Logged and displayed as `path\to\file.ext`

window.SetProperty("path_2", "path/to/file.ext");
console.log(window.GetProperty("path_2")); // Logged and displayed as `path/to/file.ext`

window.SetProperty("control_1", "line_1\nline_2");
console.log(window.GetProperty("control_1"));
// Logged as:
// `line_1
// line_2`
// displayed as:
// `line_1line_2`

Thus, path strings in JS code should be either like this `path/to/file.ext` or like this `path\\to\\file.ext` .
Was a bug on my installation. New foobar profile worked right, I reinstalled everything and now works as expected. Have no idea what was going on.. since same lines of code behaved differently on different profiles.

Btw, I have one more doubt. I'm trying to create a playlist manager, like the autoplaylist list on samples but for standard playlists.
Right now I got it like this: There is a monitored folder, the UI loads all files within that folder (playlists), I can open them and they are loaded within foobar, update the file (i.e. save foobar playlist to binded file), rebind playlist and rename (renaming playlist on manager, renames the file itself and the playlist on foobar). All that is working. I only have a problem, I can delete the files using this function from helpers .
Code: [Select]
let app = new ActiveXObject('Shell.Application');
function _recycleFile(file) {
if (_isFile(file)) {
app.NameSpace(10).MoveHere(file);
}
}
But restoring the file becomes a problem. I can not find a way to move files from the bin to the original folder.  I use the Move method with this, something like this
Code: [Select]
let fso = new ActiveXObject('Scripting.FileSystemObject');
let recyclePath = "c:\\$RECYCLE.BIN\\" + app.NameSpace(10) + "\\" + file.FILENAME;
let restorePath = file.PATH;
fso.MoveFile(recyclePath , restorePath );
But files are never moved from the bin. I have tried with that recyclePath which does indeed work on explorer, but not using the move function. So as far as I understand, the path should be right since it works on explorer (?)
"c:\$RECYCLE.BIN\" points to the physical folder, and  "c:\$RECYCLE.BIN\" + app.NameSpace(10) to the virtual one containing all files from any HDD

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #601
I've tried looking through the documentation but I'm not getting any wiser so I thought I'd ask here.

I want to make a button that switches between shuffle track and default playback that works like how the play/pause button in the sample "playback buttons", anyone have any suggestions on how to make it work?

Code: [Select]
			if (plman.PlaybackOrder === 4){
fb.RunMainMenuCommand("Playback/Order/Default");
} else {
fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)");
}
That code worked to switch, thanks a lot.
I have to ask for more help though, sadly. I want to swap icon based on which order is active, how do I add that?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #602
That code worked to switch, thanks a lot.
I have to ask for more help though, sadly. I want to swap icon based on which order is active, how do I add that?

Well, you can use the plman.PlaybackOrder property to write a conditional statement for that, too, much in the same way as above. To keep it simple, if you are using actual images:
Code: [Select]
function on_paint(gr){
let img_path;
if (plman.PlaybackOrder === 4){
img_path = //path to the default icon image
} else {
img_path = //path to the shuffle icon image
}
let img = gdi.Image(img_path)
gr.GdiDrawBitmap(img.CreateRawBitmap(), dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH)
}

If you are using font icon characters the principle is the same.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #603
That code worked to switch, thanks a lot.
I have to ask for more help though, sadly. I want to swap icon based on which order is active, how do I add that?

Well, you can use the plman.PlaybackOrder property to write a conditional statement for that, too, much in the same way as above. To keep it simple, if you are using actual images:
Code: [Select]
function on_paint(gr){
let img_path;
if (plman.PlaybackOrder === 4){
img_path = //path to the default icon image
} else {
img_path = //path to the shuffle icon image
}
let img = gdi.Image(img_path)
gr.GdiDrawBitmap(img.CreateRawBitmap(), dstX, dstY, dstW, dstH, srcX, srcY, srcW, srcH)
}

If you are using font icon characters the principle is the same.

I think I'm too dumb for this, the current thing I use is this:
Code: [Select]
buttons.buttons.shuffle = new _button(2, 2, 32, 32, {normal : 'buttons\\Menu.png'}, (x, y) => { if (plman.PlaybackOrder === 4){ fb.RunMainMenuCommand("Playback/Order/Default"); } else { fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)"); } }, 'Shuffle');

Maybe I should just look for another skin that has this function and see how they did it because I can't figure this out. When I add the function I get image is null.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #604
I think I'm too dumb for this, the current thing I use is this:
Code: [Select]
buttons.buttons.shuffle = new _button(2, 2, 32, 32, {normal : 'buttons\\Menu.png'}, (x, y) => { if (plman.PlaybackOrder === 4){ fb.RunMainMenuCommand("Playback/Order/Default"); } else { fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)"); } }, 'Shuffle');

Maybe I should just look for another skin that has this function and see how they did it because I can't figure this out. When I add the function I get image is null.

I see, you're editing marc's script! I thought you were writing your own code. That makes it a little more complicated because you need to look at the code of at least three different scripts to understand where and how to edit (playback buttons, helpers and panel I think). I don't use it and I'm not familiar with it, but in that line of code you posted, the button image is likely passed by the fith argument of the _button() function, which is an object:
Code: [Select]
{normal : 'buttons\\Menu.png'}
So first of all you need to have the required image files in the buttons folder and than you could try replacing "menu" with a variable and assign that variable the appropriate value with the conditional statement I suggested in the previous post. You could write the conditional statement in the on_playback_order_changed() callback, for example. But really, I would need to have a better look at the scripts before suggesting anything.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #605
I think I'm too dumb for this, the current thing I use is this:
Code: [Select]
buttons.buttons.shuffle = new _button(2, 2, 32, 32, {normal : 'buttons\\Menu.png'}, (x, y) => { if (plman.PlaybackOrder === 4){ fb.RunMainMenuCommand("Playback/Order/Default"); } else { fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)"); } }, 'Shuffle');

Maybe I should just look for another skin that has this function and see how they did it because I can't figure this out. When I add the function I get image is null.

I see, you're editing marc's script! I thought you were writing your own code. That makes it a little more complicated because you need to look at the code of at least three different scripts to understand where and how to edit (playback buttons, helpers and panel I think). I don't use it and I'm not familiar with it, but in that line of code you posted, the button image is likely passed by the fith argument of the _button() function, which is an object:
Code: [Select]
{normal : 'buttons\\Menu.png'}
So first of all you need to have the required image files in the buttons folder and than you could try replacing "menu" with a variable and assign that variable the appropriate value with the conditional statement I suggested in the previous post. You could write the conditional statement in the on_playback_order_changed() callback, for example. But really, I would need to have a better look at the scripts before suggesting anything.
So you recommend I start from scratch instead?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #606
So you recommend I start from scratch instead?

I encourage anyone to write their own rather than hacking other people's scripts, unless they are fairly simple and straightforward standalone scripts. But good coders usually don't have standalone scripts, but more complex systems which are hard to edit without breaking something. Nevertheless, meanwhile I had a look at the scripts and something easy you could try is editing the line of code you posted as follows:

Code: [Select]
buttons.buttons.shuffle = new _button(2, 2, 32, 32, {normal : plman.PlaybackOrder === 4 ? 'buttons\\deafult.png' : 'buttons\\shuffle.png'}, (x, y) => { if (plman.PlaybackOrder === 4){ fb.RunMainMenuCommand("Playback/Order/Default"); } else { fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)"); } }, 'Shuffle');

Than add the following:
Code: [Select]
function on_playback_order_changed(){
buttons.update();
window.Repaint();
}

Of course this works if you have a "shuffle.png" and "default.png" file in the buttons folder.

I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #607
P.S.
While we are at it, you can use the ternary operator ('?' and ':') for the conditional statement of the command as well:

Code: [Select]
buttons.buttons.shuffle = new _button(2, 2, 32, 32, {normal : plman.PlaybackOrder === 4 ? 'buttons\\deafult.png' : 'buttons\\shuffle.png'}, (x, y) => plman.PlaybackOrder === 4 ? fb.RunMainMenuCommand("Playback/Order/Default") : fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)"), 'shuffle');
I'm late

 

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #608
P.S.
While we are at it, you can use the ternary operator ('?' and ':') for the conditional statement of the command as well:

Code: [Select]
buttons.buttons.shuffle = new _button(2, 2, 32, 32, {normal : plman.PlaybackOrder === 4 ? 'buttons\\deafult.png' : 'buttons\\shuffle.png'}, (x, y) => plman.PlaybackOrder === 4 ? fb.RunMainMenuCommand("Playback/Order/Default") : fb.RunMainMenuCommand("Playback/Order/Shuffle (tracks)"), 'shuffle');

Works just the way I want it, thanks for your help :)

This is how I made it look, top right corner, greyed out when not enabled:

 
SimplePortal 1.0.0 RC1 © 2008-2021