Hey Joe, since you're using Django you could try django-mediagenerator (an asset manager) to compile your Python source to JS - standalone without the GWT-like Pyjamas libraries. See here for an intro: http://www.allbuttonspressed.com/blog/django/2010/11/Offline-HTML5-canvas-app-in-Python-with-django-mediagenerator-Part-1-pyjs
I don't maintain that project, anymore, but it could still be useful for what you want to do. As described in the post above, there's a pyjs filter in mediagenerator which automatically tracks your client-side Python files for changes and automatically recompiles them when necessary. You might have to update the pyjs filter to work with the latest pyjs version, but that should be relatively easy. The performance of pyjs is not bad and you can set compilation flags such that you have the best compromise between performance and Python support. Cheers, Waldemar On Friday, June 15, 2012 12:33:56 AM UTC+2, Joe Ryan wrote: > > Hi, > > Hope I'm mailing the right place. I'm hoping to use pyjs in a project of > mine but there's still some questions I have that I'm a bit confused about. > > First, to give you an idea of where I'm coming from and what my needs are: > I'm working on an open source webgame engine for Python in Django. The > engine is designed for tile-based games (games like civ, dungeon crawl > stone soup, or puzzles), with an emphasis on allowing multiplayer play. A > key feature of the engine is that it will do automatic lag compensation by > automagically mirroring the game command code (a file with a bunch of > python functions) and database locally (django models; the models interface > is handled seperately but any custom methods need to be translated) on the > client side, and then syncing with the server via ajax. In both cases, the > functions in question consist mostly of fetching data from the database, > manipulating it, and storing it back. The "fetching" and "storing" parts > are handled separately; our concern here is only with the manipulation > part. > > Our current attempt to do this uses the empythoned project ( > https://github.com/replit/empythoned) to run python in the browser, which > is actually Cpython compiled into javascript by emscripten and run in a web > worker. This works really great actually, with a flawless local emulation > of python, except that... its far too slow. An empty loop over a range of > 30k will take about a half a second on a decent machine. =[ So, its > nowhere near as extensible as we'd like. > > So, our next hope is pyjs. The idea here is instead of mirroring the > python game code on the client side directly, we'll translate it into > javascript instead. However, I'm at a loss of not only how to evaluate > this possibility but even where to begin, lol. > > As far as I can tell, the pyjs project has both a python->javascript > translator as well as some sort of widget interface compatible with GWT. > The docs say that the translator is stand-alone, but all documentation > examples seem to use the widget stuff. (we have our own UI already set up > built with jQuery that we're happy with, so we're only interested in the > python -> javascript translation part of pyjs). Something called > 'pyjampiler' seems to be for stand-alone translation, but there is no > documentation (that I can find) for it. I can not get the one from the > github to work, although I was able to compile the example in this older > version of pyjampiler I found here: > http://www.smallbulb.net/pyjampilerHowever, this one seems critically out of > date compared to the one in the > github. > > So, my questions: > > 1.) Can I infact use the pyjs translator stand-alone without the widget > stuff? If so, how do I use it? Do I do it with pyjampiler or some other > way? > > 2.) How good is the translator? Is it basically production-ready, or are > there some issues? I could help fix the issues if there are any significant > ones beyond what I found on the Migration guide wiki page. (the limitations > there being perfectly fine with me - my real worst fear is getting > complaints about games that function correctly without lag compensation > turned on but then are bugged (or can't compile) with it turned on.) > > 3.) How interfacable with normal javascript is the output of pyjs? Can I, > for instance, construct an array with a simple for loop: > > var a = new Array(); for (var i=0; i<10; i++) { a[i] = i; } > > and then pass that directly to a function that was created with pyjs? I'm > guessing not, but is there some kind of interface that will translate a > javascript object to a pyjs javascript object (even via JSON is fine)? > > Anyways, apologies if I missed the answer to any of this in the docs > somewhere, but I would really appreciate any help you got! > > Thanks, > Joe >
