I dont get that brython works with method with object in the argument

83 views
Skip to first unread message

Francisco J. Navarro

unread,
Jul 11, 2015, 6:21:21 PM7/11/15
to bry...@googlegroups.com
Hello. I dont get that brython works with method with object in the argument

for example this link http://blogs.msdn.com/b/eternalcoding/archive/2013/06/28/babylon-js-how-to-load-a-babylon-file-produced-with-blender.aspx if I construct it with brython I get error when I try to import the babylon file.

My constructor is this method:

def loadscene(babylon, meshes, path, engine, tasks):
load = JSConstructor(babylon.SceneLoader.Load)
load(meshes, path, engine, tasks)
 
and I call this method with this way:

def scenefile(self):
meshes = ""
path = "../assets/balltingo.babylon"
def tasks_scene(balltingo):
def create_scene(balltingo):
def start_scene(balltingo):
balltingo.render()
self.engine.runRenderLoop(start_scene)
balltingo.executeWhenReady(create_scene)
Scene.loadscene(self.babylon, meshes, path, self.engine, tasks_scene, progress=None)

balltingo is the object argument.

If there is someone that can import a babylon scene with brython constructions, please explain me that
Sorry for my bad english

Kiko

unread,
Jul 12, 2015, 5:23:14 AM7/12/15
to bry...@googlegroups.com
I think you need to make babylon available to the brython namespace.

In the first lines of your python script include:

from browser import window

babylon = window.babylon

Please if this does not work include your complete script to try to
reproduce your errors.
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/3814564f-34a5-4618-abb9-9ab3ac519fdc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Steve Waterbury

unread,
Jul 14, 2015, 2:20:42 PM7/14/15
to bry...@googlegroups.com
First, thanks for all your work on Brython -- it's really great!
(Especially for those of us who get hives from trying to
write javascript! ;)

I need a powerful grid widget and there are several native
js candidates, of which the one I'm experimenting with first
is SlickGrid: https://github.com/mleibman/SlickGrid/wiki
(The SlickGrid project is currently on hold, but even so
its current functionality is quite impressive.)

I'm in the process of converting the SlickGrid examples to
brython. I've attached my code for the second example,
which I now have working. It demonstrates cell formatters.
The attached files are:

* sg2.html ..... the original SlickGrid example 2
* sg2b.html .... html file for the Brython version
* sgex2.py ..... python script for " "

As you can see from the python code, I reimplemented the
formatter functions (which are used in the 'columns' data
structure, which gets passed to the Slick.Grid constructor
function) in python -- that part was trivial but I only
did it after trying and failing at using the js
'Slick.Formatters...' functions.

The two ways I tried using the Slick.Formatters
functions were:

(1) Just insert them from the 'window.Slick.Formatters...'
namespace and hope brython does the right thing ...
in that case I get a js stack trace and:
"Traceback (most recent call last):
RuntimeError: TypeError: klass is undefined"

(2) Use JSConstructor on them (even though they are not
constructors! ;) -- this at least does not give an error,
but the functions don't work (cells are not formatted).

Do you know of any way that the SlickGrid formatter
functions could be used directly -- i.e., without having
to reimplement them as python functions? Those functions
are extremely simple, but I'd like to know in case I
encounter more complex functions that would require real
work to reimplement.

Thanks,
Steve
sg2.html
sg2b.html
sgex2.py

Billy Earney

unread,
Jul 14, 2015, 2:46:12 PM7/14/15
to bry...@googlegroups.com
Steve,

This is just a guess, but try using JSObject.

Maybe something like:

from browser import window
from javascript import JSObject

_formatters = JSObject(window.Slick.Formatters)


Billy

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Steve Waterbury

unread,
Jul 14, 2015, 2:55:09 PM7/14/15
to bry...@googlegroups.com
Worth a try, but didn't work -- same result as not using
anything. The syntax I used was:

bPercentCompleteBar = JSObject(window.Slick.Formatters.PercentCompleteBar)

... which yielded the same
"RuntimeError: TypeError: klass is undefined"
error.

Steve
> <mailto:brython%2Bunsu...@googlegroups.com>.
> To post to this group, send email to bry...@googlegroups.com
> <mailto:bry...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/55A552F6.50008%40pangalactic.us.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to brython+u...@googlegroups.com
> <mailto:brython+u...@googlegroups.com>.
> To post to this group, send email to bry...@googlegroups.com
> <mailto:bry...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/CAB1ii-fBrmWzD7Ec-oGwxsPHwmH2A4fOKnLHW1XmNz%3Dnu03bHQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/brython/CAB1ii-fBrmWzD7Ec-oGwxsPHwmH2A4fOKnLHW1XmNz%3Dnu03bHQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Billy Earney

unread,
Jul 14, 2015, 2:59:14 PM7/14/15
to bry...@googlegroups.com
try

_formatters = JSObject(window.Slick.Formatters)
_formatters.PercentCompletBar(args go here)

If my memory servies, I think JSObject is expecting an object and not a function as its argument.  Not sure this will fix your issue, but the above works for me most of the time.

To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/55A55B08.209%40pangalactic.us.

Steve Waterbury

unread,
Jul 14, 2015, 3:11:45 PM7/14/15
to bry...@googlegroups.com
You are probably right that JSObject is expecting an object,
but in that case JSObject is not going to help here, because the
formatters are passed into the Slick.Grid constructor as
_functions_ not as _objects_. If you want to experiment,
have at it -- you have my code.

Steve
> <mailto:wate...@pangalactic.us
> <mailto:brython%2Bunsu...@googlegroups.com
> <mailto:brython%252Buns...@googlegroups.com>>.
> To post to this group, send email to
> bry...@googlegroups.com <mailto:bry...@googlegroups.com>
> <mailto:bry...@googlegroups.com
> <mailto:bry...@googlegroups.com>>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/55A552F6.50008%40pangalactic.us.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "brython" group.
> To unsubscribe from this group and stop receiving emails from
> it, send
> an email to brython+u...@googlegroups.com
> <mailto:brython%2Bunsu...@googlegroups.com>
> <mailto:brython+u...@googlegroups.com
> <mailto:brython%2Bunsu...@googlegroups.com>>.
> To post to this group, send email to bry...@googlegroups.com
> <mailto:bry...@googlegroups.com>
> <mailto:bry...@googlegroups.com <mailto:bry...@googlegroups.com>>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/CAB1ii-fBrmWzD7Ec-oGwxsPHwmH2A4fOKnLHW1XmNz%3Dnu03bHQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/brython/CAB1ii-fBrmWzD7Ec-oGwxsPHwmH2A4fOKnLHW1XmNz%3Dnu03bHQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "brython" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to brython+u...@googlegroups.com
> <mailto:brython%2Bunsu...@googlegroups.com>.
> To post to this group, send email to bry...@googlegroups.com
> <mailto:bry...@googlegroups.com>.
> To view this discussion on the web visit
> --
> You received this message because you are subscribed to the Google
> Groups "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to brython+u...@googlegroups.com
> <mailto:brython+u...@googlegroups.com>.
> To post to this group, send email to bry...@googlegroups.com
> <mailto:bry...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/CAB1ii-exq_gzY93XtSwQwrOHc9rP9AzYuQCYLjXr9gTAOLZmpg%40mail.gmail.com
> <https://groups.google.com/d/msgid/brython/CAB1ii-exq_gzY93XtSwQwrOHc9rP9AzYuQCYLjXr9gTAOLZmpg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Pierre Quentel

unread,
Jul 15, 2015, 3:01:10 AM7/15/15
to bry...@googlegroups.com, wate...@pangalactic.us
Steve,

Thanks for reporting the isse. I could reproduce the problem, and it is caused by a bug in the conversion from Python objects to Javascript.

More precisely, the problem happens with the attribute "formatter" of the objects stored in list "columns". When it is set to an attribute of Slick.Formatters, this attribute is a Javascript function, transformed into a Python function.

In the Brython code, when the constructor Slick.Grid is called by

Grid = javascript.JSConstructor(window.Slick.Grid)
grid = Grid("#myGrid", data, columns, options)


 the list "column" is internally tranformed back into a Javascript array, but the attribute "formatter" of the objects in the list was not tranformed back into the original Javascript function.

The bug is fixed in commit 6fd174b65ef422c660404b7b401ab400f9ca1739. I attach a version of sg2_brython.html that works on my PC (you will probably have to adapt some urls), and I send you the lastest version of brython_dist.js by mail so you can test if it works.

By the way, explicitely using JSObject in Brython code is not useful : getting a reference to an object by window.NameOfJavascriptObject already returns an instance of JSObject.
sg2_brython.html

Kiko

unread,
Jul 15, 2015, 3:15:21 AM7/15/15
to bry...@googlegroups.com, wate...@pangalactic.us

By the way, explicitely using JSObject in Brython code is not useful : getting a reference to an object by window.NameOfJavascriptObject already returns an instance of JSObject.

Should JSObject be deprecated and docs updated?

Pierre Quentel

unread,
Jul 15, 2015, 3:59:38 AM7/15/15
to bry...@googlegroups.com, kikoco...@gmail.com, wate...@pangalactic.us


Le mercredi 15 juillet 2015 09:15:21 UTC+2, kiko (on pybonacci) a écrit :


By the way, explicitely using JSObject in Brython code is not useful : getting a reference to an object by window.NameOfJavascriptObject already returns an instance of JSObject.

Should JSObject be deprecated and docs updated?
The documentation of the javascript module already says :
Warning : This class is normally not used directly. Getting a reference to a Javascript object with window.js_obj returns an instance of JSObject
but you are right, this is not clear enough yet. It would be better to mention JSObject as a class only used internally, and remove the paragraph currently attached to it (which is already explained in the page "Using Javascript objects and libraries" anyway)

Steve Waterbury

unread,
Jul 15, 2015, 10:29:43 AM7/15/15
to bry...@googlegroups.com
Exactly. But as I say, it did work if I wrote the same function in
python and passed it in ... but I'm glad that won't be necessary now! ;)

> The bug is fixed in commit 6fd174b65ef422c660404b7b401ab400f9ca1739. I
> attach a version of sg2_brython.html that works on my PC (you will
> probably have to adapt some urls), and I send you the lastest version of
> brython_dist.js by mail so you can test if it works.
>
> By the way, explicitely using JSObject in Brython code is not useful :
> getting a reference to an object by window.NameOfJavascriptObject
> already returns an instance of JSObject.

Yes, that was what I gathered from the documentation, which is
why I thought it might be a bug.

Thanks for the new version of bryon (brython_dist.js) -- that does
indeed fix the bug!

It is a great relief that this aspect of brython works, so js API
functions will not have to be reimplemented! :)

Cheers,
Steve
Message has been deleted

Francisco J. Navarro

unread,
Jul 19, 2015, 6:33:46 AM7/19/15
to bry...@googlegroups.com
This is my scripts

my module babylonjs in site-package from brython

from browser import window
from javascript import JSConstructor


class Scene:

@staticmethod
def startbabylon():
babylon = window.BABYLON
return babylon

@staticmethod
def enginec(babylon, canvas):
enginec = JSConstructor(babylon.Engine)
engine = enginec(canvas, True)
return engine

@staticmethod
def scenec(babylon, engine):
scenec = JSConstructor(babylon.Scene)
scene = scenec(engine)
return scene

@staticmethod
def vector3c(babylon):
vector3 = JSConstructor(babylon)
return vector3

@staticmethod
def vector3zeroc(babylon):
vector3zero = JSConstructor(babylon.Vector3.Zero)
return vector3zero

@staticmethod
def freecamerac(babylon, name, position, scene):
camerac = JSConstructor(babylon.FreeCamera)
camera = camerac(name, position, scene)
return camera

@staticmethod
def hemic(babylon, name, position, scene):
hemic = JSConstructor(babylon.HemisphericLight)
hemi = hemic(name, position, scene)
return hemi

@staticmethod
def loadscene(babylon, meshes, path, engine, tasks, progress):
load = JSConstructor(babylon.SceneLoader.Load)
load(meshes, path, engine, tasks, progress)

and this is my script in my proyect:

Balltingo.py

from browser import document as doc
from babylonjs import Scene
from javascript import JSConstructor


class Balltingo:
def __init__(self):
self.canvas = doc['renderCanvas']
self.babylon = Scene.startbabylon()
self.engine = Scene.enginec(self.babylon, self.canvas)
self.scene = Scene.scenec(self.babylon, self.engine)


def scenefile(self):
meshes = ""
path = "../assets/balltingo.babylon"
def tasks_scene(balltingo):
def create_scene(balltingo):
def start_scene(balltingo):
balltingo.render()
self.engine.runRenderLoop(start_scene)
balltingo.executeWhenReady(create_scene)
Scene.loadscene(self.babylon, meshes, path, self.engine, tasks_scene, progress=None)

    def run(self):
self.scenefile()

game = Balltingo()
game.run()

I get this error: Cannot read property 'push' of undefined

I have problem when try import babylon scene (see javascript function here to import babylon scene http://blogs.msdn.com/b/eternalcoding/archive/2013/06/28/babylon-js-how-to-load-a-babylon-file-produced-with-blender.aspx)
I don't have problem if I do this with javascript or coffescript.

How can resolve the problem with brython?

Thanks

Kiko

unread,
Jul 20, 2015, 3:28:55 AM7/20/15
to bry...@googlegroups.com
I'm on holidays without a computer.

Maybe others can help you in the meantime.
> <http://blogs.msdn.com/b/eternalcoding/archive/2013/06/28/babylon-js-how-to-load-a-babylon-file-produced-with-blender.aspx>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/afe4ec1d-e521-49a6-964e-24131a54f06a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages