几周来,我一直在用头撞墙,为使用 Gestalt 的 IronPython Silverlight 应用程序组合最小的 HTML,正如 Jimmy Schementi 在此处开创的那样:http://www.silverlight.net/learn/advanced-techniques/dynamic-languages/dynamic-languages-in-silverlight在这里:http://ironpython.net/browser/gettingstarted.html
但是我很难加载一个可以执行任何操作的应用程序。每次我将我自己的任何脚本放入示例中时,Silverlight 应用程序要么加载失败,要么在其对象中不显示任何内容。我想拥有 HTML 基础,以便我可以开始访问 Silverlight 库并开始为我的应用程序编码/测试图形。 (但我还不能到达那里。)
根据他的示例,我将以下 HTML 放在一起,它调用我的 visual.py - 一个 python 文件,它应该能够通过访问 Silverlight 库来完成 XAML 文件所做的一切。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
html, body { height: 100%; overflow: auto; }
body { padding: 0; margin: 0; }
#silverlightControlHost { height: 90%; text-align: center; }
</style>
<script type="text/javascript">
window.DLR = {settings: {windowless: 'true'}}
</script>
<script type="text/javascript" src="http://gestalt.ironpython.net/dlr-latest.js"></script>
<title>webcam-mic</title>
</head>
<body>
<script type="application/python" src="visual.py" id="python" width="100%" height="100%""></script>
</body>
</html>
但这行不通。它调用的 .py 文件具有:(也取自其他地方的有效 IronPython 示例)
from System.Windows import Application, Thickness
from System.Windows.Controls import (
Button, Orientation, TextBlock,
StackPanel, TextBox
)
from System.Windows.Input import Key
root = StackPanel(Width=500,Height=500)
textblock = TextBlock()
textblock.Margin = Thickness(20)
textblock.FontSize = 18
textblock.Text = 'Stuff goes here'
root.Children.Add(textblock)
panel = StackPanel()
panel.Margin = Thickness(20)
panel.Orientation = Orientation.Horizontal
button = Button()
button.Content = 'Push Me'
button.FontSize = 18
button.Margin = Thickness(10)
textbox = TextBox()
textbox.Text = "Type stuff here..."
textbox.FontSize = 18
textbox.Margin = Thickness(10)
textbox.Width = 200
#textbox.Watermark = 'Type Something Here'
def onClick(s, e):
textblock.Text = textbox.Text
textbox.Text = ""
def onKeyDown(sender, e):
if e.Key == Key.Enter:
e.Handled = True
onClick(None, None)
button.Click += onClick
textbox.KeyDown += onKeyDown
panel.Children.Add(button)
panel.Children.Add(textbox)
root.Children.Add(panel)
Application.Current.RootVisual = root
我需要哪些额外的组件? (dlr.js 的版本有问题吗?我的脚本标签?Silverlight 的版本?)我所需要的只是生成全屏 Silverlight 应用程序所需的代码,该应用程序从 python 文件中获取所有控件和图形。到目前为止,我所做的一切都没有奏效。我正在运行带有 Silverlight 4.0 的 Firefox。
最佳答案
感谢 Lukas Cenovsky 的建议和来自 here 的提示: ,我使用 sdl-sdk 创建了一个与 IronPython-2.7\Silverlight\script
中的模板非常相似的模板,并使用 Chiron 和 Mono 创建了一个 .xap 文件。我认为 Gestalt 可以避免使用 Chiron 创建 .xap 的需要,但无论如何都行得通。谢谢大家!
为了将来引用,创建 .xap 的终端命令类似于:mono/path/to/Chiron.exe/d:directory_with_pyfile/z:name.xap
关于html - 我怎样才能完全用 python 编写 IronPython Silverlight 应用程序,HTML 中最少的必要组件是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8276795/