[英]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.