[Tutor] Python in HTML

Orri Ganel singingxduck at gmail.com
Sat May 21 23:22:44 CEST 2005


Alan G wrote:

> The problem lies not on the server but on the client.
> JavaScript support is embedded in every popular browser so it just
> works, but none of them know about python. Even if they did it would
> require the user to have Python installed, which you can't assume.
>
> It is possible to embed python in web pages on Windows and IE, using
> ActiveX scripting (Now called WSH) and the winall package includes a
> script to activate it. However that will still require the end users
> to have Python installed and the WSH feature for Python turned on
> - quite unlikely outside a closed user community.
>
> So sadly its back to JavaScript I'm afraid. OTOH I didn't find
> JavaScript
> to be too terrible, what kind of problems are you having?
>
> PS
> I couldn't reply to the original message because it had beebn
> digitally signed. Please don't do that when posting to public mailing
> lists folks! (Well, not if you want a reply!)
>
> Alan G
> Author of the Learn to Program web tutor
> http://www.freenetpages.co.uk/hp/alan.gauld

Well, my problems in particular have been getting a bit of code to work 
at all, and when working, get it to behave as it should.  It's really a 
trivial bit of code.  All it does is control the behavior of a 
'darkplayer' - a javscript mp3 player - for an online journal.  The 
specific bit of code I'm having trouble with is the part that selects a 
random song from the playlist.  To make sure every song is selected at 
least once, i tried to copy the playlist and have it choose songs from 
the copy, removing each song as it is played, and refilling the copy 
when it is empty.  The code follows (apologies in advance for tabbing 
issues as it was edited in notepad):

<object id=darkplayer 
codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 
type=application/x-oleobject height=0 standby="Loading Microsoft Windows 
Media Player components..." width=0 
classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95>
<PARAM NAME VALUE>
<PARAM NAME="ShowControls" VALUE="0">
<PARAM NAME="ShowStatusBar" VALUE="0">
<PARAM NAME="ShowDisplay" VALUE="0">
<PARAM NAME="DefaultFrame" VALUE="Slide">
<PARAM NAME="Autostart" VALUE="1">
<PARAM NAME="Loop" VALUE="False">
</object>
<form name=form>
<p style="text-align: center">
<select style="FONT-SIZE: 8pt; BACKGROUND:#FFFFFF; WIDTH: 302; COLOR: 
#00000; font-face: verdana;" name=playlist size=1>
<option value="0">song names here (removed to save space/time)</option>


</select><br>
<input TYPE="BUTTON" NAME="darkplay" VALUE="play" 
OnClick="play(document.forms['form'].playlist);playstate=0;">
<input TYPE="BUTTON" NAME="darkpause" VALUE="pause" 
OnClick="document.darkplayer.pause(); playstate=1;">

<input TYPE="BUTTON" NAME="darkstop" VALUE="stop" 
OnClick="document.darkplayer.stop(); playstate=2;">
<input TYPE="BUTTON" NAME="random" VALUE="random" 
OnClick="randsong();play(document.forms['form'].playlist);">
</p></form>


<script language="JavaScript">
<!--
var playstate = 0;
shuffle = 1;  // set to 0 to always play first song in list
                 // set to 1 to randomly choose the first song to play
                 // www.xanga.com/singing_duck
                 // unlimited songs, just copy and paste the song line 
and change the number
songs=new Array();
songs[0]="url of songs here (removed to save time/space)"
playable = new Array();
for (i = 0; i < songs.length; i++)
{
playable[i] = songs[i];
}

function index(ar, text)
{
for (var ind = 0; ind < ar.length; ind++)
{
if (ar[ind] == text)
{
return ind;
}
}
return -1;
};
function randsong() {
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
       rnd.seed = (rnd.seed*9301+49297) % 233280;
       return rnd.seed/(233280.0);
};
function rand(number) {
       return Math.ceil(rnd()*number);
};
if (playable.length == 0)
{
for (var index = 0; index < songs.length; playable++)
{
playable[index] = songs[index];
}
}
var randsg = rand(playable.length);
document.darkplayer.FileName = playable[randsg];
document.darkplayer.scr = playable[randsg];
document.forms['form'].playlist.options[index(songs, 
playable[randsg])].selected = true;
playable.splice(randsg, 1);
};
if (shuffle == 1) {
randsong();
}
function play(list) {
if (playstate == 1 && songs[list.options[list.selectedIndex].value] == 
document.darkplayer.FileName) {
 document.darkplayer.Play();
} else {
var snum = list.options[list.selectedIndex].value
document.darkplayer.FileName = songs[snum];
document.darkplayer.scr = songs[snum];
}
playstate = 1;
};
//-->
 </script>


-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.



More information about the Tutor mailing list