简体   繁体   中英

IronPython and Nodebox in C#

My plan:

I'm trying to setup my C# project to communicate with Nodebox to call a certain function which populates a graph and draws it in a new window.

Current situation: [fixed... see Update2]

I have already included all python-modules needed, but im still getting a

Library 'GL' not found

it seems that the pyglet module needs a reference to GL/gl.h , but can't find it due to IronPython behaviour.

Requirement:

The project needs to stay as small as possible without installing new packages. Thats why i have copied all my modules into the project-folder and would like to keep it that or a similar way.

My question:

Is there a certain workaround for my problem or a fix for the library-folder missmatch. Have read some articles about Tao-Opengl and OpenTK but can't find a good solution.

Update1:

Updated my sourcecode with a small pyglet window-rendering example. Problem is in pyglet and referenced c-Objects. How do i include them in my c# project to be called? No idea so far... experimenting alittle now. Keeping you updated.

SampleCode C#:

ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptEngine engine = Python.GetEngine(runtime);

ScriptSource source = engine.CreateScriptSourceFromFile("test.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);

SampleCode Python (test.py):

from nodebox.graphics import *
from nodebox.graphics.physics import Vector, Boid, Flock, Obstacle

flock = Flock(50, x=-50, y=-50, width=700, height=400)
flock.sight(80)

def draw(canvas):
    canvas.clear()
    flock.update(separation=0.4, cohesion=0.6, alignment=0.1, teleport=True)
    for boid in flock:
        push()
        translate(boid.x, boid.y)
        scale(0.5 + boid.depth)
        rotate(boid.heading)
        arrow(0, 0, 15)
        pop()

canvas.size = 600, 300

def main(canvas):
    canvas.run(draw)

Update2:

Line 139 [pyglet/lib.py] sys.platform is not win32... there was the error. Fixed it by just using the line:

from pyglet.gl.lib_wgl import link_GL, link_GLU, link_WGL

Now the following Error:

'module' object has no attribute '_getframe'

Kind of a pain to fix it. Updating with results...

Update3:

Fixed by adding following line right after first line in C#-Code:

setup.Options["Frames"] = true;

Current Problem:

No module named unicodedata , but in Python26/DLLs is only a *.pyd file`. So.. how do i implement it now?!

Update4:

Fixed by surfing: link text and adding unicodedata.py and '.pyd to C# Projectfolder.

Current Problem:

'libGL.so not found'... guys.. im almost giving up on nodebox for C#.. to be continued

Update5:

i gave up :/ workaround: c# communicating with nodebox over xml and filesystemwatchers. Not optimal, but case solved.

-X:Frames enables the frames option as runtime (it slows code down a little to have access to the Python frames all the time).

To enable frames when hosting you just need to do:

ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(new Dictionary<string, object>() {
    { "Frames", true }
});

Instead of the null that you're passing now. That's just creating a new dictionary for the options dictionary w/ the contents "Frames" set to true. You can set other options in there as well and in general the -X:Name option is the same here as it is for the command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM