简体   繁体   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?

I've been banging my head against to wall for weeks to put together the minimal HTML for an IronPython Silverlight application that uses Gestalt, as pioneered by Jimmy Schementi here: http://www.silverlight.net/learn/advanced-techniques/dynamic-languages/dynamic-languages-in-silverlight and here: http://ironpython.net/browser/gettingstarted.html 几个星期以来,我一直在敲打墙壁,为使用Gestalt的IronPython Silverlight应用程序整理最小的HTML,这是Jimmy Schementi在这里开创的: http//www.silverlight.net/learn/advanced-techniques/动态语言/动态语言在Silverlight和这里: http//ironpython.net/browser/gettingstarted.html

But I'm having a hard time loading an application that does anything. 但是我很难加载一个可以做任何事情的应用程序。 Every time I put into the examples any script of my own, the Silverlight application either fails to load, or shows nothing in its object. 每次我将自己的脚本放入示例中时,Silverlight应用程序要么无法加载,要么在其对象中不显示任何内容。 I want to have the HTML foundation so that I can begin accessing the Silverlight libraries and start coding/testing graphics for my app. 我想拥有HTML基础,以便我可以开始访问Silverlight库并开始编写/测试我的应用程序的图形。 (But I can't get there yet.) (但我还没到达那里。)

Taking from his examples, I've put together the following HTML, which calls my visual.py - a python file that should be able to do everything that a XAML file does by accessing the Silverlight libraries. 从他的例子中,我把以下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>

But this doesn't work. 但这不起作用。 The .py file it calls has: (also taken from working IronPython examples from elsewhere) 它调用的.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

What additional components do I need? 我还需要哪些其他组件? (Is the problem with the version of dlr.js? My script tags? Version of Silverlight?) All I need is the necessary code to produce a full screen Silverlight app that takes all of its controls and graphics from a python file. (dlr.js版本的问题是什么?我的脚本标签?Silverlight的版本?)我需要的是生成全屏Silverlight应用程序的必要代码,该应用程序从python文件中获取其所有控件和图形。 So far, nothing I've put together has worked. 到目前为止,我所做的一切都没有奏效。 I'm running Firefox with Silverlight 4.0. 我正在使用Silverlight 4.0运行Firefox。

Thanks to Lukas Cenovsky's suggestion and the tips from here : , I used the sdl-sdk to create a template much like the template in IronPython-2.7\\Silverlight\\script and created a .xap file with Chiron and Mono. 感谢Lukas Cenovsky的建议和来自这里的提示:我使用sdl-sdk创建了一个模板,就像IronPython-2.7\\Silverlight\\script的模板一样,并使用Chiron和Mono创建了一个.xap文件。 I thought that Gestalt would obviate the need for using Chiron to create a .xap, but whatever works. 我认为Gestalt可以避免使用Chiron创建.xap的必要性,但无论如何都有效。 Thanks, all! 谢谢,全部!

For future reference, the Terminal command to create a .xap is something like: mono /path/to/Chiron.exe /d:directory_with_pyfile /z:name.xap 为了将来参考,创建.xap的Terminal命令类似于: mono /path/to/Chiron.exe /d:directory_with_pyfile /z:name.xap

How are you serving the HTML file? 你是如何服务HTML文件的? Any HTML file with references must be served from a web-server, not the file-system, so no file:// URLs. 任何带引用的HTML文件都必须从Web服务器而不是文件系统提供,因此没有file:// URL。

You can also use Chiron to produce your own .xap file. 您还可以使用Chiron生成自己的.xap文件。 Then the XAP file can be served from any web-server you want, but if you want any reasonable dev experience you'll have to use "Chiron.exe /w" as your web-server. 然后可以从您想要的任何Web服务器提供XAP文件,但是如果您需要任何合理的开发经验,则必须使用“Chiron.exe / w”作为您的Web服务器。

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

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