Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions content/lib/pc_py_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var $builtinmodule = function (name) {
// The doc string cannot be added in code as is usually done in Python, so we set it manually here.
mod.__doc__ = "This module provides implemention of the Pencil Code internal functions in Python.";

mod.Window = window
mod.Window = window;

// Sk.builtin.func creates a Python function out of a JS function
mod.addalemon = new Sk.builtin.func(function (data) {
Expand Down Expand Up @@ -149,7 +149,7 @@ var $builtinmodule = function (name) {
if (sprite === Sk.builtin.none.none$) {
return click(function(eventData){
var data = [eventData.x, eventData.y];
Sk.misceval.callsim(func, Sk.ffi.remapToPy(data)); } );
Sk.misceval.callsim(func); } );
}
//return sprite.click( function () { Sk.misceval.callsim(fn); } );
});
Expand Down Expand Up @@ -223,6 +223,13 @@ var $builtinmodule = function (name) {
return sprite.say(Sk.ffi.remapToJs(a));
});

mod.audioplay = new Sk.builtin.func(function (sprite, url) {
Sk.builtin.pyCheckArgs("audioplay", arguments, 2, 2);
var urlplay = new Audio(Sk.ffi.remapToJs(url));

return urlplay.play();

});
// TEXT METHODS /////////////////////////////////////////////////////////
mod.write = new Sk.builtin.func(function (message) {
Sk.builtin.pyCheckArgs("write", arguments, 1, 1);
Expand Down Expand Up @@ -413,7 +420,7 @@ var $builtinmodule = function (name) {
});

mod.fill = new Sk.builtin.func(function (sprite, color) {
Sk.builtin.pyCheckArgs("dot", arguments, 2, 2);
Sk.builtin.pyCheckArgs("fill", arguments, 2, 2);
if (sprite === Sk.builtin.none.none$) {
return fill(Sk.ffi.remapToJs(color));
}
Expand Down Expand Up @@ -447,9 +454,9 @@ var $builtinmodule = function (name) {
mod.drawon = new Sk.builtin.func(function (sprite, canvas) {
Sk.builtin.pyCheckArgs("drawon", arguments, 2, 2);
if (sprite === Sk.builtin.none.none$) {
return drawon(Sk.ffi.remapToJs(canvas));
return drawon(canvas);
}
return sprite.drawon(Sk.ffi.remapToJs(canvas));
return sprite.drawon(canvas);
});

mod.arrow = new Sk.builtin.func(function (sprite, color, size) {
Expand Down Expand Up @@ -477,24 +484,25 @@ var $builtinmodule = function (name) {
});

mod.touches = new Sk.builtin.func(function (sprite, obj) {
Sk.builtin.pyCheckArgs("touches", arguments, 2, 2);
Sk.builtin.pyCheckArgs("touches", arguments, 2, 2);
if (sprite === Sk.builtin.none.none$) {
return Sk.ffi.remapToPy(touches(Sk.ffi.remapToJs(obj)));
}
return Sk.ffi.remapTOPy(sprite.touches(Sk.ffi.remapToJs(obj)));
return Sk.ffi.remapToPy(sprite.touches(Sk.ffi.remapToJs(obj)));
});

mod.inside = new Sk.builtin.func(function (sprite, obj) {
Sk.builtin.pyCheckArgs("inside", arguments, 2, 2);
if(Sk.ffi.remapToJs(obj) == "window")
if(Sk.ffi.remapToJs(obj) == "window"){
if (sprite === Sk.builtin.none.none$) {
return Sk.ffi.remapToPy(inside(window));
}
return Sk.ffi.remapToPy(sprite.inside(window));
}
if (sprite === Sk.builtin.none.none$) {
return Sk.ffi.remap.Py(inside(Sk.ffi.remapToJs(obj)));
return Sk.ffi.remapToPy(inside(obj));
}
return Sk.ffi.remap.Py(sprite.inside(Sk.ffi.remapToJs(obj)));
return Sk.ffi.remapToPy(sprite.inside(obj));
});

//Operators
Expand Down
38 changes: 23 additions & 15 deletions content/lib/pencilcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def jumpxy(self, x, y):
pencilcode_internal.jumpxy(self.jsSpriteObject, x, y)

def pause(self, value):
pencilcode_internal.sleep(self.jsSpriteObject, value)
pencilcode_internal.pause(self.jsSpriteObject, value)

def getxy(self):
return pencilcode_internal.getxy(self.jsSpriteObject)
Expand Down Expand Up @@ -105,7 +105,9 @@ def pd(self):

def box(self, a, b):
pencilcode_internal.box(self.jsSpriteObject,a,b)

def box(self, a):
pencilcode_internal.box(self.jsSpriteObject,a,10)

def grow(self, a):
pencilcode_internal.grow(self.jsSpriteObject,a)

Expand All @@ -124,8 +126,8 @@ def fill(self, color):
def wear(self, name):
pencilcode_internal.wear(self.jsSpriteObject,name)

def drawon(self, path):
pencilcode_internal.drawon(self.jsSpriteObject,path)
def drawon(self, canvas):
pencilcode_internal.drawon(self.jsSpriteObject,canvas.jsSpriteObject)

#def cell(self, rows, columns):
# pencilcode_internal.cell(self.jsSpriteObject, rows, columns)
Expand All @@ -136,13 +138,13 @@ def shown(self):
def hidden(self):
return pencilcode_internal.hidden(self.jsSpriteObject)

def touches(self):
def touches(self, obj):
return pencilcode_internal.touches(self.jsSpriteObject, obj)

def inside(self):
return pencilcode_internal.inside(self.jsSpriteObject, obj)
def inside(self, obj):

return pencilcode_internal.inside(self.jsSpriteObject, obj if obj == window else obj.jsSpriteObject)


####################
## Sound Commands ##
####################
Expand All @@ -159,7 +161,9 @@ def silence(self):
def say(self, a):
pencilcode_internal.say(self.jsSpriteObject, a)


def audioplay(self, url):
player = pencilcode_internal.audioplay(self.jsSpriteObject, url)

# These commands act on the default turtle object (which is not wrapped.).

###################
Expand Down Expand Up @@ -211,7 +215,7 @@ def getxy():
return pencilcode_internal.getxy(None)

def pause(value):
pencilcode_internal.sleep(None, value)
pencilcode_internal.pause(None, value)

##################
## Art Commands ##
Expand Down Expand Up @@ -241,6 +245,9 @@ def pd():
def box(a, b):
pencilcode_internal.box(None,a,b)

def box(a):
pencilcode_internal.box(None,a,10)

def grow(a):
pencilcode_internal.grow(None,a)

Expand All @@ -262,8 +269,8 @@ def fill(color):
def wear(name):
pencilcode_internal.wear(None,name)

def drawon(path):
pencilcode_internal.drawon(None,path)
def drawon(canvas):
pencilcode_internal.drawon(None,canvas.jsSpriteObject)

def shown():
return pencilcode_internal.shown(None)
Expand All @@ -275,8 +282,8 @@ def touches(obj):
return pencilcode_internal.touches(None, obj)

def inside(obj):
return pencilcode_internal.touches(None, obj)

return pencilcode_internal.inside(None, obj if obj == window else obj.jsSpriteObject)
###################
## Text Commands ##
###################
Expand Down Expand Up @@ -341,7 +348,8 @@ def silence():

def say(a):
pencilcode_internal.say(None, a)

def audioplay(url):
pencilcode_internal.audioplay(None, url)
######################
## Control Commands ##
######################
Expand Down
21 changes: 14 additions & 7 deletions content/src/filetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ function wrapTurtle(doc, domain, pragmasOnly, setupScript, instrumenter) {
var originalLanguage = null;
var seeline = '\n\n';
if (meta.type == "text/x-python") {
maintype = "text/x-python"
maintype = 'text/x-python';
seeline = '# Initialization / clearing goes here\n\n';
originalLanguage = 'python'
originalLanguage = 'python';
}
else {
maintype = 'text/coffeescript';
Expand All @@ -208,9 +208,14 @@ function wrapTurtle(doc, domain, pragmasOnly, setupScript, instrumenter) {
// Instruments the code for debugging, always producing javascript.
var newText = instrumenter(text, originalLanguage);
if (newText !== false) {
text = newText;
maintype = 'text/javascript';
instrumented = true;
text = newText;
instrumented = true;
if(originalLanguage == 'python') {
maintype = 'text/x-python';
}
else {
maintype = 'text/javascript';
}
}
}
var mainscript = seeline;
Expand Down Expand Up @@ -384,8 +389,10 @@ function effectiveMeta(input) {
if (meta && meta.type && meta.lib) { return meta; }
meta = (meta && 'object' == typeof meta) ?
JSON.parse(JSON.stringify(meta)) : {};
if(doc && doc.mimeType){
if (doc.mimeType.lastIndexOf('text/x-python', 0) === 0) {
//if(doc && doc.mimeType){
if(doc && doc.mimeType && doc.meta){
//if (doc.mimeType.lastIndexOf('text/x-python', 0) === 0) {
if (doc.meta.type == 'text/x-python') {
meta.type = 'text/x-python';
meta.libs = [{name: 'turtle', src: '//{site}/turtlebits.js'},
{name: 'skulpt.min', src: '//{site}/lib/skulpt.min.js'},
Expand Down
Loading