C# 中的 IronPython 和 Nodebox
我的计划:
我正在尝试设置我的 C# 项目来与 Nodebox 进行通信,以调用某个函数来填充图形并将其绘制在新窗口中。
当前情况:[已修复...参见 Update2]
我已经包含了所需的所有 python 模块,但我仍然收到
找不到库“GL”
似乎 pyglet
模块需要对 GL/gl.h
的引用,但由于找不到它IronPython 行为。
要求:
项目需要保持尽可能小,而不安装新的软件包。这就是为什么我将所有模块复制到项目文件夹中并希望保留它或类似的方式。
我的问题:
是否有针对我的问题的特定解决方法或修复库文件夹不匹配的问题。 读过一些关于 Tao-Opengl
和 OpenTK
的文章,但找不到好的解决方案。
更新1:
用一个小的 pyglet 窗口渲染示例更新了我的源代码。问题出在 pyglet 和引用的 c 对象中。我如何将它们包含在我的 C# 项目中以供调用?到目前为止还不知道......现在尝试一下。让您随时了解最新情况。
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);
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)
更新 2:
第 139 行 [pyglet/lib.py] sys.platform 不是 win32...出现错误。只需使用以下行即可修复它:
from pyglet.gl.lib_wgl import link_GL, link_GLU, link_WGL
现在出现以下错误:
'module' object has no attribute '_getframe'
修复它有点痛苦。更新结果...
Update3:
通过在 C# 代码第一行之后添加以下行来修复:
setup.Options["Frames"] = true;
当前问题:
没有名为 unicodedata 的模块
,但在 Python26/DLLs
中只是一个 *.pyd
文件`。那么..我现在该如何实施呢?
Update4:
通过冲浪修复:链接文本 并添加 unicodedata.py
和 < code>'.pyd 到 C# 项目文件夹。
当前问题:
'libGL.so 找不到'...伙计们..我几乎要放弃 C# 的 Nodebox 了..待续
Update5:
我放弃了 :/解决方法:c# 通过 xml 和 filesystemwatchers 与 nodebox 通信。不是最优的,但案例已解决。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-X:Frames 启用框架选项作为运行时(它会稍微减慢代码以始终访问 Python 框架)。
要在托管时启用框架,您只需要执行以下操作:
而不是您现在传递的 null 。这只是为选项字典创建一个新字典,并将内容“Frames”设置为 true。您还可以在其中设置其他选项,一般来说,这里的 -X:Name 选项与命令行中的选项相同。
-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:
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.