Repository: pyscript/pyscript

Issue:
Antigravity example is broken after stdout/display changes
### Checklist

- [X] I added a descriptive title
- [X] I searched for other issues and couldn't find a solution or duplication
- [X] I already searched in Google and didn't find any good information or help

### What happened?

After the changes related to stdout/err and display, the antigravity example is broken. It currently fails with the following error:

```
Traceback (most recent call last):
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435, in eval_code
    .run(globals, locals)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304, in run
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 1, in <module>
  File "/home/pyodide/antigravity.py", line 44, in <module>
    _auto = Antigravity(append=True)
  File "/home/pyodide/antigravity.py", line 14, in __init__
    target = target or sys.stdout._out
AttributeError: '_io.TextIOWrapper' object has no attribute '_out'
```

This is due to the fact that we are not custom changing `sys.stdout` the same way.  

It seems like the best option here would be to implement the right `_repr_` method but would love to hear @philippjfr on this

**NOTE: ** goes without saying that we should add a test as well :)

### What browsers are you seeing the problem on? (if applicable)

_No response_

### Console info

_No response_

### Additional Context

_No response_


Discussion:
> **NOTE: ** goes without saying that we should add a test as well :)

what is not tested is broken ;)

Resolving patch:
diff --git a/examples/antigravity.py b/examples/antigravity.py
--- a/examples/antigravity.py
+++ b/examples/antigravity.py
@@ -1,5 +1,4 @@
 import random
-import sys
 
 from js import DOMParser, document, setInterval
 from pyodide.ffi import create_proxy
@@ -11,9 +10,10 @@ class Antigravity:
     url = "./antigravity.svg"
 
     def __init__(self, target=None, interval=10, append=True, fly=False):
-        target = target or sys.stdout._out
         self.target = (
-            document.getElementById(target) if isinstance(target, str) else target
+            document.getElementById(target)
+            if isinstance(target, str)
+            else document.body
         )
         doc = DOMParser.new().parseFromString(
             open_url(self.url).read(), "image/svg+xml"


Test patch:
diff --git a/pyscriptjs/tests/integration/test_zz_examples.py b/pyscriptjs/tests/integration/test_zz_examples.py
--- a/pyscriptjs/tests/integration/test_zz_examples.py
+++ b/pyscriptjs/tests/integration/test_zz_examples.py
@@ -95,6 +95,29 @@ def test_altair(self):
         assert save_as_png_link.is_visible()
         assert see_source_link.is_visible()
 
+    def test_antigravity(self):
+        self.goto("examples/antigravity.html")
+        self.wait_for_pyscript()
+        assert self.page.title() == "Antigravity"
+
+        # confirm that svg added to page
+        wait_for_render(self.page, "*", '<svg.*id="svg8".*>')
+
+        # Get svg layer of flying character
+        char = self.page.wait_for_selector("#python")
+        assert char is not None
+
+        # check that character moves in negative-y direction over time
+        ycoord_pattern = r"translate\(-?\d*\.\d*,\s(?P<ycoord>-?[\d.]+)\)"
+        starting_y_coord = float(
+            re.match(ycoord_pattern, char.get_attribute("transform")).group("ycoord")
+        )
+        time.sleep(2)
+        later_y_coord = float(
+            re.match(ycoord_pattern, char.get_attribute("transform")).group("ycoord")
+        )
+        assert later_y_coord < starting_y_coord
+
     def test_bokeh(self):
         # XXX improve this test
         self.goto("examples/bokeh.html")