Skip to main content

Topic: WSH Panel Mod script discussion/help (Read 845511 times) previous topic - next topic

0 Members and 3 Guests are viewing this topic.
  • icedtea
  • [*][*]
WSH Panel Mod script discussion/help
Reply #150
Tom I am trying to implement your suggestion but image switching isn't working for me
Code: [Select]
image_path = fb.FoobarPath + "\\scripts\\images\\";
play_image = gdi.Image(image_path + "play.png");
pause_image = gdi.Image (image_path + "pause.png");
display_image = play_image;

function on_playback_new_track(){
   display_image = pause_image;
   window.Repaint();
}
function on_playback_pause() {
   display_image = play_image;
   window.Repaint();
}

function on_playback_starting(){
   display_image = pause_image;
   window.Repaint();
}

function on_paint(gr) {
   gr.DrawImage(display_image, 0, 0, 32, 28, 0, 0, 32, 28, 0, 255);
}

on starting playback I get pause.png OK
on pausing playback I get play.png OK
on resuming playback I get play.png Not OK should be pause.png

What am I doing wrong?
  • Last Edit: 31 January, 2010, 01:17:17 PM by icedtea

  • TomBarlow
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #151
Hi, on_playback_pause() is called when playback is either paused or unpaused, so you need to alternate between the play and pause images there, like this.

Code: [Select]
image_path = fb.FoobarPath + "\\scripts\\images\\";
play_image = gdi.Image(image_path + "play.png");
pause_image = gdi.Image (image_path + "pause.png");
display_image = play_image;

function on_playback_stop(){
    display_image = play_image;
    window.Repaint();
}
function on_playback_pause(is_paused) {
    display_image = is_paused?play_image:pause_image;
    window.Repaint();
}

function on_playback_starting(cmd, is_paused){
    display_image = is_paused?play_image:pause_image;
    window.Repaint();
}

function on_paint(gr) {
    gr.DrawImage(display_image, 0, 0, 32, 28, 0, 0, 32, 28, 0, 255);
}

WSH Panel Mod script discussion/help
Reply #152
Very short code
But why do you create a context menu with the default context menu entries only?
You could delete the whole on_mouse_rbtn_up() section.

I uploaded an old version accidentally. 

The current version refreshes the displayed lyrics.

  • icedtea
  • [*][*]
WSH Panel Mod script discussion/help
Reply #153
Thanks Tom
I got everything else to work but lost hover somehow in the process. That is the only thing left and I would appreciate the help
Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_path%scripts\tooltip_buttons.js"
// ==/PREPROCESSOR==

var image_path = fb.FoobarPath + "\\scripts\\images\\";
var play_image = image_path + "play.png";
var pause_image = image_path + "pause.png";
var previous_image = image_path + "previous.png";
var next_image =  image_path + "next.png";
var display_image = play_image;
var bw = 32;
var bh = 28;
var window_color = RGB(240,240,240);
var dui = window.InstanceType
var top_margin = 2;
var left_margin = 4;
window.MinWidth = window.MaxWidth = 104;
window.MinHeight = window.MaxHeight = bh + 4;

function RGB(r,g,b) {
return (0xff000000|(r<<16)|(g<<8)|(b));
}

function on_playback_stop(){
   display_image = play_image;
   window.Repaint();
}
function on_playback_pause(is_paused) {
   display_image = is_paused?play_image:pause_image;
   window.Repaint();
}

function on_playback_starting(cmd, is_paused){
   display_image = is_paused?play_image:pause_image;
   window.Repaint();
}

function on_size() {
   ww = window.Width;
   wh = window.Height;
}

function on_paint(gr) {
   Buttons = {
       but1: new Button(left_margin,top_margin,bw,bh, {normal: previous_image, hover: image_path + "previous_h.png"}, function(){fb.Prev();}, "Previous"),
    but2: new Button(bw + left_margin,top_margin,bw,bh, {normal: display_image, hover: image_path + "play_h.png"}, function(){fb.PlayOrPause();}, "Play/Pause"),
    but3: new Button((bw*2) + left_margin,top_margin,bw,bh, {normal: next_image, hover: image_path + "next_h.png"}, function(){fb.Next();}, "Next")
       }
   gr.FillSolidRect(0, 0, ww, wh, window_color);
buttonsDraw(gr);
}

tooltip_buttons.js is from marc2003's examples

  • TomBarlow
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #154
Have a look under on_paint where the buttons are defined, there is a line starting with "but2: new button..." - there is a bit inside there that looks like this: {normal: display_image, hover: image_path + "play_h.png"}, you need to change that to {normal: display_image, hover: display_image_h} for example and then change display_image_h at the same time you change display_image.

  • icedtea
  • [*][*]
WSH Panel Mod script discussion/help
Reply #155
Have a look under on_paint where the buttons are defined, there is a line starting with "but2: new button..." - there is a bit inside there that looks like this: {normal: display_image, hover: image_path + "play_h.png"}, you need to change that to {normal: display_image, hover: display_image_h} for example and then change display_image_h at the same time you change display_image.

That is not the problem hover images aren't shown at all even when they are defined and that included the static previous and next buttons. I suspect there is something in tooltip_buttons.js that is causing it but I cannot wrap my head around that script.

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #156
the original tooltip button code is by T.P Wang and tedgo. i don't understand it that well either.

i'll try and work it out from what Tom posted.

in the meantime, i've updated my samples. they've all had their options updated to be accessible from the context menu only. no more script editing should be needed (one exception is setting the image size and margins for buttons).

http://cid-649d3bfeaf541fbb.skydrive.live....ide/samples.zip

samples include

rating script by NEMO7538
simple seekbar
simple biography
playback buttons
web links (myspace, youtube, lastfm)
3 in 1 artwork panel
-the first is a straight replacement for the default art panel. it always prefers embedded album art if it exists. it then falls back on the usual display options set in the foobar preferences.
-last.fm artist art panel. can download multiple images from last.fm and cycle through them. it must be triggered manually using the context menu
-cycle folder option. can cycle through images in a folder at 5, 10 or 20 second intervals

so no instructions needed really. just extract the scripts folder into your foobar directory. add panels and import the samples you want and right click them to see the various options.

EDIT: in the unlikely event someone downloaded this between 1:35-150pm today, please download it again. i didn't update the zip with my newest files. 
  • Last Edit: 01 February, 2010, 09:18:23 AM by marc2003

  • tedgo
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #157
@icedtea
Don't create the buttons in on_paint(), that's all

EDIT:
I rewrote your script (should work now)
Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_path%scripts\tooltip_buttons.js"
// ==/PREPROCESSOR==

var image_path = fb.FoobarPath + "\\scripts\\images\\";
var play_image = {normal: image_path + "play.png", hover: image_path + "play_h.png"};
var pause_image = {normal: image_path + "pause.png", hover: image_path + "play_h.png"};
var previous_image = {normal: image_path + "previous.png", hover: image_path + "previous_h.png"};
var next_image =  {normal: image_path + "next.png", hover: image_path + "next_h.png"};
var bw = 32;
var bh = 28;
var window_color = RGB(240,240,240);
var dui = window.InstanceType;
var top_margin = 2;
var left_margin = 4;
window.MinWidth = window.MaxWidth = 104;
window.MinHeight = window.MaxHeight = bh + 4;

function RGB(r,g,b) {
return (0xff000000|(r<<16)|(g<<8)|(b));
}

function on_playback_stop(){
   Buttons.but2.alterImage(genPPImageSrc());
   Buttons.but2.repaint();
}

function on_playback_pause(state) {
   Buttons.but2.alterImage(genPPImageSrc());
   Buttons.but2.repaint();
}

function on_playback_starting(){
   Buttons.but2.alterImage(genPPImageSrc());
   Buttons.but2.repaint();
}

function on_size() {
   ww = window.Width;
   wh = window.Height;
}

function on_paint(gr) {
   gr.FillSolidRect(0, 0, ww, wh, window_color);
buttonsDraw(gr);
}

function genPPImageSrc() {
return (fb.IsPlaying && !fb.IsPaused) ? pause_image : play_image;
}

Buttons = {
   but1: new Button(left_margin,top_margin,bw,bh, previous_image, function(){fb.Prev();}, "Previous"),
   but2: new Button(bw + left_margin,top_margin,bw,bh, genPPImageSrc(), function(){fb.PlayOrPause();}, "Play/Pause"),
   but3: new Button((bw*2) + left_margin,top_margin,bw,bh, next_image, function(){fb.Next();}, "Next")
}

You need this tooltip_buttons.js for this: http://pastebin.de/3644
(has some additional lines to repaint the play/pause button only)
  • Last Edit: 01 February, 2010, 10:30:23 AM by tedgo

  • icedtea
  • [*][*]
WSH Panel Mod script discussion/help
Reply #158
thanks tego! I will try to understand it if I can

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #159
this post is aimed at people who are happy enough writing their own scripts.

this little snippet allows you to present the user with a text input box, save this text and use it in your scripts.



javascript doesn't have a text input box but vbscript does so i found this code online to do the work. it has to be saved in an external file and we can call it using WshShell.Run.

first of you need my modified version of the script from that link. save this as "input.wsf" in your "scripts" directory...

Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1"?>
<job id="IncludeExample">
<script language="VBScript">
<![CDATA[
Function WSHInputBox(Message, Title, Value)
WSHInputBox = InputBox(Message, Title, Value)
End Function
]]>
</script>
<script language="JScript">
<![CDATA[
args = WScript.Arguments;
var WshShell = WScript.CreateObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
try {
ts = fso.OpenTextFile(args(2), 1, false, -1);
s = ts.ReadLine();
ts.close();
} catch(e) {
s = ''
}
var result = WSHInputBox(args(1), args(0), s);
if (result != null) {
try {
ts = fso.OpenTextFile(args(2), 2, true, -1);
ts.WriteLine(result);
ts.close();
} catch(e) {
Wscript.Echo("Error saving data!");
}
}
]]>
</script>
</job>

this is the script to go in your panel. i'm pretty crap at explaining things so i hope the comments make some sort of sense. it's pretty simple really....

Code: [Select]
var DT_CENTER = 0x00000001;
var DT_VCENTER = 0x00000004;
var DT_WORDBREAK = 0x00000010;
var DT_CALCRECT = 0x00000400;
var DT_NOPREFIX = 0x00000800;

function RGB(r,g,b) {
return (0xff000000|(r<<16)|(g<<8)|(b));
}

function text_input_box(title, message, filename) {
WshShell.Run("\"" + wsf + "\" \"" + title + "\" \"" + message + "\" \"" + filename + "\"", 0, true);
return read(filename);
}

function read(fn) {
try {
var f = fso.OpenTextFile(fn, 1, false, -1);
var s = f.Readline();
f.Close()
return s;
} catch(e) {
return '';
}
}

///////this is the bit you'll want to customise for your own usage//////

var WshShell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var wsf = fb.FoobarPath + "scripts\\input.wsf";
//need to be somewhere with "write" access
var settings_path = fb.ProfilePath + "text_input_settings\\";
if(!fso.FolderExists(settings_path)) fso.CreateFolder(settings_path);

//each variable you want to use needs an associated file.
//the input box saves input to this file and then WSH panel mod can read it.
g_text_file = settings_path + "g_text";
//check to see if a value already exists and use it
g_text = read(g_text_file);

//now we a need a function to trigger our input
function on_mouse_lbtn_up(x, y) {
   //the text_input box will read the file and present the current value as the default text.
   //when you click ok, the external script will then save the result to the text file
   //wsh panel mod can then read this updated file and return the new value
   //in this simple example, it will just be updating the display using window.Repaint().
   g_text = text_input_box("Message Title", "Enter some text:", g_text_file);
   window.Repaint();
}

function on_size() {
   ww = window.Width;
   wh = window.Height;
}

function on_paint(gr) {
   gr.FillSolidRect(0, 0, ww, wh, RGB(255,255,255));
   gr.GdiDrawText(g_text, gdi.Font("Segoe UI", 16), RGB(0,0,0), 0, 0, ww, wh, DT_VCENTER | DT_CENTER | DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX);
}
  • Last Edit: 02 February, 2010, 01:12:47 AM by marc2003

  • icedtea
  • [*][*]
WSH Panel Mod script discussion/help
Reply #160
marc2003 is it possible to get a wikipedia image for the links? better yet a template where we can create similar icons.
Thanks

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #161
i just got those images from google image search. try it yourself....  (there wasn't a wikipedia icon in the pack that i used)
  • Last Edit: 02 February, 2010, 03:59:50 AM by marc2003

  • icedtea
  • [*][*]
WSH Panel Mod script discussion/help
Reply #162
marc2003 whenever you get the time please consider making a button to switch playback modes i.e. shuffle, default etc
Thanks

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #163
there's already one in T.P's samples i think.

the samples are on the same download page as the component.
  • Last Edit: 04 February, 2010, 07:35:09 AM by marc2003

WSH Panel Mod script discussion/help
Reply #164
Hello there, fellow alien cats!

I've been experimenting with WSH Panel Mod (DUI) for quite a while now but there's still something I'd like to have in my config but can't manage to script. Well, about that... I should mention that I have nearly no clue of scripting whatsoever. All I did before was copy&paste-ing and changing some numeric values. ^^

So here's what I wanna do:  I want a heart-shaped love button like I’ve seen in marc2003’s or carmenm’s configs. But it should work without LastFM. I aleady used NEMO7538's rating buttons and created a column named "Loved" that displays a heart when a track has a 5-rating.

But for  several reasons I don’t wanna handle it this way. One of them is that you’re not able to uncheck a “loved” song (I could only give it a <5rating). So, I’d love to see a script that can either

1) create a rating-tag and fills it with the value 5
or
2) create a %loved%-tags (by using customdb i.e.).

I’d be really really grateful for any helping hand! =)

WSH Panel Mod script discussion/help
Reply #165
is it appropriate to make requests here?
i'm no coder, and the scripting for this panel, whatever it is, flies straight over my head.

what i'd like to see is a config that divides its host panel into 9 equal areas - basically a 3x3 grid. each area is filled with a solid colour.
each area is also assigned a number, 1-9, based on the layout of a standard keypad (1 bottom-left and 9 top-right).
clicking on a coloured box sends the box's number to the %mood% tag of the currently playing track.

the whole idea is that the horizontal axis represents tempo, and the vertical axis is mood. mimicking the layout of a keypad would make it work well with global hotkeys.
it would also be easy to implement each track's 'color' into a CUI playlist view, and you could build great autoplaylists based on the values.

i really have no idea how difficult this would be to implement, but if anyone is inclined to put it together, i think people would find it useful!

inspired by:
http://www.crayonroom.com/moody.php


  • ojdo
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #166
is it appropriate to make requests here?
i'm no coder, and the scripting for this panel, whatever it is, flies straight over my head.

You are lucky, I just coded such a panel with a 5x5 grid. It is available as a ready theme for DUI in this ZIP file on openaudio.eu (link is at the bottom of the page). It is configured to set the tags %valence% (sad to happy) and %arousal% (calm to active) on a scale from -2 to 2.

I also added tagging scripts for foo_masstag to "move" a track's rating in this grid with 4 keyboard shortcuts (I use the keys W,A,S,D).

This is how a portable installation looks after loading the theme:
  • Last Edit: 05 February, 2010, 10:48:23 AM by ojdo

WSH Panel Mod script discussion/help
Reply #167
ojdo, that is tremendous! it integrates perfectly with my CUI config.
now i just have to build a massive playlist column script to show each track's color

thanks for sharing. i am very lucky indeed!

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #168
@catchyfourwordphrase, i've made you a script. it's totally separate from the rating script so just use that as usual.

you'll need the latest version of my samples zip.

http://cid-649d3bfeaf541fbb.skydrive.live....ide/samples.zip

it contains updates since my last post (plus i've fixed the ratings panel to let you customise the background colour)

now you'll need to configure customdb. on the "fields" page, create a new field called "LOVE". set the "name" and "display" as this. for the "key", you should select "custom" and add

%artist%,%title%

now restart foobar. now go to the "actions" page and add these 2 actions

Code: [Select]
Display: Love
Field: LOVE
Update: ContextMenu
Set Value: 1


Code: [Select]
Display: Unlove
Field: LOVE
Update: ContextMenu->Erase


now add a panel and download this code

http://pastebin.com/f7baf0174

use a tag named %love% in your playlist to display a heart if it equals 1.

  • Last Edit: 05 February, 2010, 12:27:20 PM by marc2003

WSH Panel Mod script discussion/help
Reply #169
http://cid-649d3bfeaf541fbb.skydrive.live....ide/samples.zip


In single every sctipt of yours i got error
"Cant create object" in common.js on line 237

Code: [Select]
var WshShell = new ActiveXObject("WScript.Shell");


did i missed somthing so much mandatary that it wasnt even in readme?

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #170
file>preferences>tools>wsh panel mod>uncheck "safe mode". restart foobar.

i keep meaning to make some proper documentation but i never quite get around to it.

WSH Panel Mod script discussion/help
Reply #171
file>preferences>tools>wsh panel mod>uncheck "safe mode". restart foobar.

i keep meaning to make some proper documentation but i never quite get around to it.


solved. thx for swift response.

WSH Panel Mod script discussion/help
Reply #172
Thanks a ton, marc2003!! 
Worked like a charm...at least until foobar decided to crash several times because of customdb. It's kind of weird - I've been running fb2k with four dockable panels (one of them is a chronflow panel in nearly fullscreen) and haven't experienced any crashes at all but as soon as I want to add a tiny little heart to my screen, foobar goes bananas 
But nevertheless, thanks again for helping me out. Members like you are one of the reasons why I love foobar and its community so much.

Well, is there any work around to get along with foo_customdb's buggyness? If not, I'd be totally happy with a heart button which generates a 5 in the %rating%-tag and can also erase it. Right now, I'm trying to change your script to do so but the only result was the lovely "ping" sound of a script error 
So, sorry to bother you again, but could you please help me again with this?

  • marc2003
  • [*][*][*][*][*]
WSH Panel Mod script discussion/help
Reply #173
i experienced a few crashes with foo_customdb during my very first hour of use. and i think it's related to the default fields/actions being triggered during playback. because as soon as i removed them all and just used my own settings, i've not had a single problem. i've been using it for pushing on 2 months now with my last.fm script and it's behaved perfectly.

so try removing all the defaults and leave just your own settings - make sure you restart foobar when done.
  • Last Edit: 05 February, 2010, 02:57:31 PM by marc2003

WSH Panel Mod script discussion/help
Reply #174
For me it seems like this actually did the trick, no crash so far. 
So, thanks again!