Skip to content

Instantly share code, notes, and snippets.

@Neppord
Created July 17, 2012 18:32
Show Gist options
  • Save Neppord/3131140 to your computer and use it in GitHub Desktop.
Save Neppord/3131140 to your computer and use it in GitHub Desktop.
Pyjaco Discussion
class MyClass:
value = 0
"""jsspace
MyClass.value = 0;
"""
@dxlbnl
Copy link

dxlbnl commented Jul 17, 2012

var mod.PY$o = py(jQuery);
mod.PY$o.PY$__getattr__("click").__call__($c42, $PY.str("foo"));

@chrivers
Copy link

o = py(jQuery);
o.PY$__getattr__("click").__call__($c42, $PY.str("foo"));

@Neppord
Copy link
Author

Neppord commented Jul 17, 2012

py('path.to.jsorpyvar', pyvar) //setting a value from a python typed var
js('path.to.jsorpyvar', jsvar) //setting a value from a javascript typed var
py('path.to.some.var.and.typecast.it.outmaticaly.to.py')

@chrivers
Copy link

  // pure js
  $("#mydiv").click(function() { alert("foo"); }

  // translated
  jq = py(jQuery);
  jq.PY$__call__($PY.str("#mydiv")).PY$__getattr__("click").PY$__call__(py(function() { py(alert).PY$__call__($PY.str("foo")); )};

@Neppord
Copy link
Author

Neppord commented Jul 17, 2012

  // pure js
  $("#mydiv").click(function() { alert("foo"); }

  // translated
  jq = py(jQuery);
  jq.PY$__call__(py("#mydiv")).PY$__getattr__("click").PY$__call__(py(function() { py(alert).PY$__call__($PY.str("foo")); )};

@chrivers
Copy link

var py = function(obj) {
    if (obj && obj.PY$__class__ !== undefined) {
        return obj;
    } else if (typeof obj === 'number') {
        return int(obj);
    } else if (typeof obj === 'string') {
        return str(obj);
    } else if (typeof obj === 'boolean') {
        return bool(obj);
    } else if (obj === undefined || obj === null) {
        return None;
    } else if (obj instanceof Array) {
        var res = list();
        for (var q in obj) {
          res.PY$append(py(obj[q]));
        }
        return res;
    } else {
        var res = dict();
        for (var q in obj) {
            res.PY$__setitem__(str(q), py(obj[q]));
        }
        return res;
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment