mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 22:00:33 +05:00
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import netgen
|
|
|
|
def StartGUI():
|
|
from tkinter import Tk
|
|
try:
|
|
# the GUI tries to load ngsolve.tcl (which loads ngsolve shared libraries)
|
|
# BUT might fail to load dependencies (like mkl), these are handled by the
|
|
# ngsolve __init__.py script, so import ngsolve from python already here
|
|
import ngsolve
|
|
except:
|
|
pass
|
|
|
|
global win
|
|
win = Tk()
|
|
win.tk.eval('lappend ::auto_path ' + netgen._netgen_lib_dir)
|
|
win.tk.eval('lappend ::auto_path ' + netgen._netgen_bin_dir)
|
|
# load with absolute path to avoid issues on MacOS
|
|
win.tk.eval('load "'+netgen._netgen_lib_dir.replace('\\','/')+'/libgui[info sharedlibextension]" gui')
|
|
win.tk.eval( netgen.libngpy._meshing._ngscript)
|
|
|
|
|
|
if not netgen.libngpy._meshing._netgen_executable_started:
|
|
import os
|
|
if not "NETGEN_DOCUMENTATION_RST_FORMAT" in os.environ:
|
|
StartGUI()
|
|
|
|
def Snapshot(w,h, filename=None):
|
|
netgen.Redraw(blocking=True)
|
|
import numpy
|
|
image = netgen.libngpy.Snapshot(w, h)
|
|
image = numpy.array(image, dtype=numpy.uint8).reshape(h, w, 3)
|
|
image = image[::-1,:,:]
|
|
if filename:
|
|
import PIL.Image
|
|
im = PIL.Image.fromarray(image)
|
|
im.save(filename)
|
|
return image
|