Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pyodide
Commits
7d19fcd6
Commit
7d19fcd6
authored
Jun 04, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bugs found from examples
parent
6153e635
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
19 deletions
+24
-19
src/hiwire.c
src/hiwire.c
+6
-2
src/jsproxy.c
src/jsproxy.c
+2
-2
src/pyodide.js
src/pyodide.js
+1
-1
src/python.html
src/python.html
+3
-5
src/wasm_backend.py
src/wasm_backend.py
+4
-9
test/test_python.py
test/test_python.py
+8
-0
No files found.
src/hiwire.c
View file @
7d19fcd6
...
...
@@ -54,7 +54,7 @@ EM_JS(int, hiwire_string_utf8, (int ptr), {
});
EM_JS
(
int
,
hiwire_bytes
,
(
int
ptr
,
int
len
),
{
var
bytes
=
new
Uint8Array
(
Module
.
HEAPU8
.
buffer
,
ptr
,
len
);
var
bytes
=
new
Uint8
Clamped
Array
(
Module
.
HEAPU8
.
buffer
,
ptr
,
len
);
return
Module
.
hiwire_new_value
(
bytes
);
});
...
...
@@ -140,9 +140,13 @@ EM_JS(void, hiwire_call_member, (int idobj, int ptrname, int idargs), {
});
EM_JS
(
void
,
hiwire_new
,
(
int
idobj
,
int
idargs
),
{
function
newCall
(
Cls
)
{
return
new
(
Function
.
prototype
.
bind
.
apply
(
Cls
,
arguments
));
}
var
jsobj
=
Module
.
hiwire_get_value
(
idobj
);
var
jsargs
=
Module
.
hiwire_get_value
(
idargs
);
return
Module
.
hiwire_new_value
(
new
(
Function
.
prototype
.
bind
.
apply
(
jsobj
,
jsargs
)));
jsargs
.
unshift
(
jsobj
);
return
Module
.
hiwire_new_value
(
newCall
.
apply
(
newCall
,
jsargs
));
});
EM_JS
(
void
,
hiwire_get_length
,
(
int
idobj
),
{
...
...
src/jsproxy.c
View file @
7d19fcd6
...
...
@@ -79,7 +79,7 @@ static PyObject* JsProxy_Call(PyObject *o, PyObject *args, PyObject *kwargs) {
int
idargs
=
hiwire_array
();
for
(
Py_ssize_t
i
;
i
<
nargs
;
++
i
)
{
for
(
Py_ssize_t
i
=
0
;
i
<
nargs
;
++
i
)
{
int
idarg
=
python2js
(
PyTuple_GET_ITEM
(
args
,
i
));
hiwire_push_array
(
idargs
,
idarg
);
hiwire_decref
(
idarg
);
...
...
@@ -99,7 +99,7 @@ static PyObject* JsProxy_New(PyObject *o, PyObject *args, PyObject *kwargs) {
int
idargs
=
hiwire_array
();
for
(
Py_ssize_t
i
;
i
<
nargs
;
++
i
)
{
for
(
Py_ssize_t
i
=
0
;
i
<
nargs
;
++
i
)
{
int
idarg
=
python2js
(
PyTuple_GET_ITEM
(
args
,
i
));
hiwire_push_array
(
idargs
,
idarg
);
hiwire_decref
(
idarg
);
...
...
src/pyodide.js
View file @
7d19fcd6
...
...
@@ -130,7 +130,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
let
div
=
document
.
createElement
(
'
div
'
);
div
.
className
=
'
rendered_html
'
;
var
element
;
if
(
'
_repr_html_
'
in
val
)
{
if
(
val
.
_repr_html_
!==
undefined
)
{
let
result
=
val
.
_repr_html_
();
if
(
typeof
result
===
'
string
'
)
{
div
.
appendChild
(
new
DOMParser
().
parseFromString
(
...
...
src/python.html
View file @
7d19fcd6
...
...
@@ -118,9 +118,7 @@ For example, say we had the following Python function that we wanted to call fro
%% code {"language":"py"}
# python
def square(x, integer=False):
if integer:
x = int(x)
def square(x):
return x * x
%% md
...
...
@@ -129,14 +127,14 @@ Since calling conventions are a bit different in Python than in Javascript, all
%% js
// javascript
var square = pyodide.pyimport("square")
square(
[2.5], {integer: true}
)
square(
2.5
)
%% md
This is equivalent to the following Python syntax:
%% code {"language":"py"}
# python
square(2.5
, integer=True
)
square(2.5)
%% md
You can also get the attributes of objects in a similar way. Say we had an instance of the following Python custom class:
...
...
src/wasm_backend.py
View file @
7d19fcd6
...
...
@@ -135,7 +135,6 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg):
rubberband
.
setAttribute
(
'tabindex'
,
'0'
)
# Event handlers are added to the canvas "on top", even though most of the
# activity happens in the canvas below.
rubberband
.
addEventListener
(
'click'
,
self
.
onclick
)
rubberband
.
addEventListener
(
'mousemove'
,
self
.
onmousemove
)
rubberband
.
addEventListener
(
'mouseup'
,
self
.
onmouseup
)
rubberband
.
addEventListener
(
'mousedown'
,
self
.
onmousedown
)
...
...
@@ -170,9 +169,9 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg):
canvas
=
self
.
get_element
(
'canvas'
)
image_data
=
ImageData
.
new
(
self
.
buffer_rgba
(),
width
,
height
)
;
ctx
=
canvas
.
getContext
(
"2d"
)
;
ctx
.
putImageData
(
image_data
,
0
,
0
)
;
width
,
height
)
ctx
=
canvas
.
getContext
(
"2d"
)
ctx
.
putImageData
(
image_data
,
0
,
0
)
self
.
_idle_scheduled
=
False
def
draw_idle
(
self
):
...
...
@@ -198,10 +197,6 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg):
button
=
3
return
x
,
y
,
button
def
onclick
(
self
,
event
):
x
,
y
,
button
=
self
.
_convert_mouse_event
(
event
)
self
.
button_click_event
(
x
,
y
,
button
,
guiEvent
=
event
)
def
onmousemove
(
self
,
event
):
x
,
y
,
button
=
self
.
_convert_mouse_event
(
event
)
self
.
motion_notify_event
(
x
,
y
,
guiEvent
=
event
)
...
...
@@ -215,7 +210,7 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg):
self
.
button_press_event
(
x
,
y
,
button
,
guiEvent
=
event
)
def
onmouseenter
(
self
,
event
):
window
.
addEventListener
(
'contextmenu'
,
ignore
)
return
# When the mouse is over the figure, get keyboard focus
self
.
get_element
(
'rubberband'
).
focus
()
self
.
enter_notify_event
(
guiEvent
=
event
)
...
...
test/test_python.py
View file @
7d19fcd6
...
...
@@ -141,6 +141,14 @@ def test_jsproxy(selenium):
"document.body.children[0].tagName"
)
==
'DIV'
assert
selenium
.
run
(
"repr(document)"
)
==
'[object HTMLDocument]'
selenium
.
run_js
(
"window.square = function (x) { return x*x; }"
)
assert
selenium
.
run
(
"from js import square
\
n
"
"square(2)"
)
==
4
assert
selenium
.
run
(
"from js import ImageData
\
n
"
"ImageData.new(64, 64)"
)
def
test_open_url
(
selenium
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment