繁体   English   中英

如何完全在python中编写IronPython Silverlight应用程序,HTML中最小的必要组件是什么?

[英]How can I code an IronPython Silverlight application entirely in python, and what are the minimal necessary components in the HTML?

几个星期以来,我一直在敲打墙壁,为使用Gestalt的IronPython Silverlight应用程序整理最小的HTML,这是Jimmy Schementi在这里开创的: http//www.silverlight.net/learn/advanced-techniques/动态语言/动态语言在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的建议和来自这里的提示:我使用sdl-sdk创建了一个模板,就像IronPython-2.7\\Silverlight\\script的模板一样,并使用Chiron和Mono创建了一个.xap文件。 我认为Gestalt可以避免使用Chiron创建.xap的必要性,但无论如何都有效。 谢谢,全部!

为了将来参考,创建.xap的Terminal命令类似于: mono /path/to/Chiron.exe /d:directory_with_pyfile /z:name.xap

你是如何服务HTML文件的? 任何带引用的HTML文件都必须从Web服务器而不是文件系统提供,因此没有file:// URL。

您还可以使用Chiron生成自己的.xap文件。 然后可以从您想要的任何Web服务器提供XAP文件,但是如果您需要任何合理的开发经验,则必须使用“Chiron.exe / w”作为您的Web服务器。

暂无
暂无

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

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