简体   繁体   中英

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

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. I want to have the HTML foundation so that I can begin accessing the Silverlight libraries and start coding/testing graphics for my app. (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.

<!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)

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. So far, nothing I've put together has worked. I'm running Firefox with Silverlight 4.0.

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. I thought that Gestalt would obviate the need for using Chiron to create a .xap, but whatever works. 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

How are you serving the HTML file? Any HTML file with references must be served from a web-server, not the file-system, so no file:// URLs.

You can also use Chiron to produce your own .xap file. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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