mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 21:40:33 +05:00
allow webgui also without ipywidgets installed
This commit is contained in:
parent
bd5751b26b
commit
a2b22bdaf8
@ -3,15 +3,30 @@ import numpy as np
|
|||||||
from time import time
|
from time import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import webgui_jupyter_widgets
|
try:
|
||||||
from webgui_jupyter_widgets import BaseWebGuiScene, encodeData, WebGuiDocuWidget
|
import webgui_jupyter_widgets
|
||||||
import webgui_jupyter_widgets.widget as wg
|
from webgui_jupyter_widgets import BaseWebGuiScene, WebGuiDocuWidget
|
||||||
|
import webgui_jupyter_widgets.widget as wg
|
||||||
|
except ImportError:
|
||||||
|
wg = None
|
||||||
|
|
||||||
|
def encodeData( data, dtype=None, encoding='b64' ):
|
||||||
|
import numpy as np
|
||||||
|
from base64 import b64encode
|
||||||
|
dtype = dtype or data.dtype
|
||||||
|
values = np.array(data.flatten(), dtype=dtype)
|
||||||
|
if encoding=='b64':
|
||||||
|
return b64encode(values).decode("ascii")
|
||||||
|
elif encoding=='binary':
|
||||||
|
return values.tobytes()
|
||||||
|
else:
|
||||||
|
raise RuntimeError("unknown encoding" + str(encoding))
|
||||||
|
|
||||||
from packaging.version import parse
|
from packaging.version import parse
|
||||||
|
|
||||||
import netgen.meshing as ng
|
import netgen.meshing as ng
|
||||||
|
|
||||||
if parse(webgui_jupyter_widgets.__version__) >= parse("0.2.18"):
|
if wg is not None and parse(webgui_jupyter_widgets.__version__) >= parse("0.2.18"):
|
||||||
_default_width = None
|
_default_width = None
|
||||||
_default_height = None
|
_default_height = None
|
||||||
else:
|
else:
|
||||||
@ -199,8 +214,8 @@ def GetData(mesh, args, kwargs):
|
|||||||
d[name] = pnew
|
d[name] = pnew
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
base = object if wg is None else BaseWebGuiScene
|
||||||
class WebGLScene(BaseWebGuiScene):
|
class WebGLScene(base):
|
||||||
def __init__(self, obj, args=[], kwargs={}):
|
def __init__(self, obj, args=[], kwargs={}):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.args = args
|
self.args = args
|
||||||
@ -351,7 +366,7 @@ def Draw(obj, *args, **kwargs):
|
|||||||
kwargs_with_defaults.update(kwargs)
|
kwargs_with_defaults.update(kwargs)
|
||||||
|
|
||||||
scene = WebGLScene(obj, args, kwargs_with_defaults)
|
scene = WebGLScene(obj, args, kwargs_with_defaults)
|
||||||
if wg._IN_IPYTHON:
|
if wg is not None and wg._IN_IPYTHON:
|
||||||
if wg._IN_GOOGLE_COLAB:
|
if wg._IN_GOOGLE_COLAB:
|
||||||
from IPython.display import display, HTML
|
from IPython.display import display, HTML
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user