简体   繁体   English

C#中的IronPython和Nodebox

[英]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. 我正在尝试设置我的C#项目与Nodebox通信以调用某个函数,该函数填充图形并在新窗口中绘制它。

Current situation: [fixed... see Update2] 现状:[修复...见Update2]

I have already included all python-modules needed, but im still getting a 我已经包含了所有需要的python-modules,但我仍然得到了

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. 似乎pyglet模块需要引用GL/gl.h ,但由于IronPython行为而无法找到它。

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. 已经阅读了一些关于Tao-OpenglOpenTK文章,但找不到一个好的解决方案。

Update1: UPDATE1:

Updated my sourcecode with a small pyglet window-rendering example. 使用一个小的pyglet窗口渲染示例更新了我的源代码。 Problem is in pyglet and referenced c-Objects. 问题出在pyglet和引用的c-Objects中。 How do i include them in my c# project to be called? 我如何将它们包含在我要调用的c#项目中? No idea so far... experimenting alittle now. 到目前为止还不知道......现在正在试验。 Keeping you updated. 保持更新。

SampleCode C#: 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): 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: UPDATE2:

Line 139 [pyglet/lib.py] sys.platform is not win32... there was the error. 第139行[pyglet / lib.py] sys.platform不是win32 ...有错误。 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: UPDATE3:

Fixed by adding following line right after first line in C#-Code: 通过在C#-Code中的第一行之后添加以下行来修复:

setup.Options["Frames"] = true;

Current Problem: 当前问题:

No module named unicodedata , but in Python26/DLLs is only a *.pyd file`. No module named unicodedata ,但在Python26/DLLs中只是一个*.pyd `。 So.. how do i implement it now?! 那么..我现在如何实现它?!

Update4: UPDATE4:

Fixed by surfing: link text and adding unicodedata.py and '.pyd to C# Projectfolder. 通过冲浪修复: 链接文本并将unicodedata.py'.pyd添加到C#Projectfolder。

Current Problem: 当前问题:

'libGL.so not found'... guys.. im almost giving up on nodebox for C#.. to be continued 'libGL.so not found'...伙计们...我几乎放弃了节点盒的C#..继续

Update5: Update5:

i gave up :/ workaround: c# communicating with nodebox over xml and filesystemwatchers. 我放弃了:/ workaround:c#通过xml和filesystemwatchers与nodebox进行通信。 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). -X:Frames使frame选项成为运行时(它会使代码慢一点,以便始终可以访问Python帧)。

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. 而不是你现在传递的null。 That's just creating a new dictionary for the options dictionary w/ the contents "Frames" set to true. 这只是为选项字典创建一个新的字典,其内容“Frames”设置为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. 您也可以在其中设置其他选项,通常-X:Name选项与命令行相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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