Ironpython application
Un article de WikiSigPlus.
voir C#application,Script Python
Sommaire |
[modifier]
variable environnement
il faut importer les dll suivantes pour utiliser wpf
wpf dans silverligth
- dll:Microsoft.Scripting.Silverlight.dll Microsoft.Scripting.ExtensionAttribute.dll Microsoft.Scripting.Core.dll Microsoft.Scripting.dll IronPython.Modules.dll IronPython.dll
- localisation:
wpf dans microsoft
- dll:PresentationCore.dll, PresentationFramework.dll, System.dll, WindowsBase.dll, UIAutomationProvider.dll, UIAutomationTypes.dll.
- localisation: C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\*.dll
le namespace est le même pour wpf et silverligh
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
'silverlight
- contient un fichier xaml commencant par UserControl suivit de canvas
- utilise System.Windows.Controls.Usercontrol ( System.Windows.dll )
WPF
- contient un fichier xaml commencant par Window suivi de StackPanel
ASP.NET'
- contient un fichier xaml
utilise System.Web.UI.UserControl
Le fichier .xaml.cs a pour nom de class le nom de fichier défini dans *.xaml x:class="" et contient une classe qui extend le nom de la première balise du fichier *.xaml ( USerControl)
InitializeComponent():
- appelle le méthode statique System.Windows.Application.LoadComponent()
- LoadComponent est une instance de XamlParser dont la fonction ProcessXamlNode() est passé a la classe BamlRecordWriter.
- InitializeComponent est une methode de System.Windows.Markup.IComponentConnector interface implémenté par Window/UserControls.
[modifier]
compilation
> # compiler.py
> from IronPython.Hosting import PythonCompiler
> from System.Collections.Generic import List
> sources = List[str]()
> sources.Add('hello.py')
> outfile = 'hello.exe'
> compiler = PythonCompiler(sources, outfile)
> compiler.Compile()
[modifier]
application console
dans window xp=> ipy.exe -X:TabCompletion -X:ColorfulConsole -X:ExceptionDetail dans mono=> mono ipy.exe -X:TabCompletion -X:ColorfulConsole -X:ExceptionDetail
import clr
clr.AddReference("System.Windows.Forms")
from System.IO import *
from System.Windows.Forms import *
class test:
def __init__(self, num):
if (num == 1):
self.Member1 = 'a'
else:
self.Name = 'b'
>>>v=test(1)
>>>dir(v)
['Member1','__doc__','__init__','__module__']]
[modifier]
application graphique non wpf
si un fichier contient l'extension py il peut contenir du code pour ironpyhton ou pyhton
shell ip
>>>import clr
>>>clr.AddReference("System.Windows.Forms")
>>>from System.IO import *
>>>from System.Windows.Forms import *
>>>a=Form()
>>>a.Text="Hello"
>>>a.Close()
test.py
clr.AddReference("System.Windows.Forms")
from System.IO import *
from System.Windows.Forms import *
class FormV1(Form):
def __init__(self):
self.Text = 'Hello World'
a=FormV1("Hello")
execution
ipy test.py
compilation : va créer les fichiers ( exe et pdb) au niveau du répertoire conteant test.py ( besoin de procs.exe)
ipy.exe -O -X:SaveAssemblies c:\test\test.py
IP pour manifold import clr
clr.AddReference("System.Windows.Forms")
from System.IO import *
from System.Windows.Forms import *
class FormV1(Form):
def __init__(self):
self.Text = 'Hello World'
def Main():
Application.Run(FormV1())
[modifier]
applet silverlight
[modifier]
application ASP
[modifier]
application ASP .NET
[modifier]
application WPF
[modifier]
