From a23a2ae0a29e8a2f85d9f56af1a4e579e89dd108 Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Sun, 13 Sep 2020 23:47:27 +0800 Subject: [PATCH 1/6] better pybuf_enabled detection --- python/taichi/lang/shell.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/taichi/lang/shell.py b/python/taichi/lang/shell.py index e63bcd8453d20..c259ef3cf6dab 100644 --- a/python/taichi/lang/shell.py +++ b/python/taichi/lang/shell.py @@ -15,7 +15,8 @@ _env_enable_pybuf = os.environ.get('TI_ENABLE_PYBUF', '1') if not _env_enable_pybuf or int(_env_enable_pybuf): # When using in Jupyter / IDLE, the sys.stdout will be their wrapped ones. - pybuf_enabled = type(sys.stdout).__name__ != 'TextIOWrapper' + # While sys.__stdout__ should always be the raw console stdout. + pybuf_enabled = sys.stdout != sys.__stdout__ from .core import taichi_lang_core taichi_lang_core.toggle_python_print_buffer(pybuf_enabled) From 404dbe0d72f67cce7a7e11c7b5bef818922125c1 Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Sun, 13 Sep 2020 23:55:28 +0800 Subject: [PATCH 2/6] add GUI.__del__ to close on variable dereference --- python/taichi/misc/gui.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/taichi/misc/gui.py b/python/taichi/misc/gui.py index a23b5a9ecf5b7..b7c20f48913bc 100644 --- a/python/taichi/misc/gui.py +++ b/python/taichi/misc/gui.py @@ -59,6 +59,9 @@ def __enter__(self): def __exit__(self, type, val, tb): self.close() + def __del__(self): + self.close() + def close(self): self.core = None # dereference to call GUI::~GUI() From d902d259dc14938db83ac5db0e09678ca3f0358c Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Mon, 14 Sep 2020 00:22:47 +0800 Subject: [PATCH 3/6] fix win32 not destroying window --- taichi/gui/win32.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/taichi/gui/win32.cpp b/taichi/gui/win32.cpp index 26540fecf4faa..2cf7750a9c462 100644 --- a/taichi/gui/win32.cpp +++ b/taichi/gui/win32.cpp @@ -223,6 +223,7 @@ GUI::~GUI() { if (show_gui) { std::free(data); DeleteDC(src); + DestroyWindow(hwnd); gui_from_hwnd.erase(hwnd); } } From 8d53f0bff50b965365a79d9d9df6d314a0ea0625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BA=8E=E6=96=8C?= <1931127624@qq.com> Date: Mon, 14 Sep 2020 13:17:53 +0800 Subject: [PATCH 4/6] [skip ci] Update python/taichi/lang/shell.py --- python/taichi/lang/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/taichi/lang/shell.py b/python/taichi/lang/shell.py index c259ef3cf6dab..71b6010b236c6 100644 --- a/python/taichi/lang/shell.py +++ b/python/taichi/lang/shell.py @@ -16,7 +16,7 @@ if not _env_enable_pybuf or int(_env_enable_pybuf): # When using in Jupyter / IDLE, the sys.stdout will be their wrapped ones. # While sys.__stdout__ should always be the raw console stdout. - pybuf_enabled = sys.stdout != sys.__stdout__ + pybuf_enabled = sys.stdout is not sys.__stdout__ from .core import taichi_lang_core taichi_lang_core.toggle_python_print_buffer(pybuf_enabled) From 1d8809221c733448d0d6a865352e8a6c4e723c2f Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Fri, 18 Sep 2020 16:33:58 +0800 Subject: [PATCH 5/6] nit --- python/taichi/misc/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/taichi/misc/gui.py b/python/taichi/misc/gui.py index b7c20f48913bc..607f6fe4c923e 100644 --- a/python/taichi/misc/gui.py +++ b/python/taichi/misc/gui.py @@ -345,7 +345,7 @@ def text(self, content, pos, font_size=15, color=0xFFFFFF): color = ti.core_vec(r, g, b, 1) self.canvas.text(content, pos, font_size, color) - def _make_field_base(gui, w, h, bound): + def _make_field_base(self, w, h, bound): x = np.linspace(bound / w, 1 - bound / w, w) y = np.linspace(bound / h, 1 - bound / h, h) base = np.array(np.meshgrid(x, y)) From 2021dbd48b4357467d1788fd8a950a08c6bba5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E4=BA=8E=E6=96=8C?= <1931127624@qq.com> Date: Wed, 23 Sep 2020 07:47:00 +0800 Subject: [PATCH 6/6] [skip ci] Update python/taichi/misc/gui.py --- python/taichi/misc/gui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/taichi/misc/gui.py b/python/taichi/misc/gui.py index 607f6fe4c923e..68e66cec10e87 100644 --- a/python/taichi/misc/gui.py +++ b/python/taichi/misc/gui.py @@ -345,7 +345,8 @@ def text(self, content, pos, font_size=15, color=0xFFFFFF): color = ti.core_vec(r, g, b, 1) self.canvas.text(content, pos, font_size, color) - def _make_field_base(self, w, h, bound): + @staticmethod + def _make_field_base(w, h, bound): x = np.linspace(bound / w, 1 - bound / w, w) y = np.linspace(bound / h, 1 - bound / h, h) base = np.array(np.meshgrid(x, y))