[Ironpython-users] Run a WPF application written in IronPython on the client computer without the install IronPython

sepatan at sibmail.com sepatan at sibmail.com
Mon Mar 19 10:44:38 CET 2012


Thank you, Matt Ward :).
 It worked :)). You're a real expert.
 Just one more thing, a window appears and then disappears. I guess,
because the console is closed.
 Maybe after the text of the program in primer.py something else should be?

from avalon import *
import calculator
w = Window()
w.Title = "My Avalon Application"
w.Content = LoadXaml("calc.xaml")
calculator.enliven(w)
w.Show()
??????????????????????????????????

> If you use the /target:winexe with pyc.py it will add the STAThread
> attribute to your main method. That should fix the exception.
>
> In the C# console app you can add the STAThread attribute to the main
> method:
>
>     class Program
>     {
>         [STAThread]
>         static void Main(string[] args)
>         {
>
> On 19 March 2012 08:17,  <sepatan at sibmail.com> wrote:
>> I have a need to run a WPF application written in IronPython on the
>> client
>> without installing IronPython.
>> В Technology to try to debug a standard example of WPF
>> .\IronPython-2.7.2.1\Tutorial.
>> В Baseline data:
>>
>> 1) The computer is not installed IronPython. From IronPython-2.7.2.1.zip
>> (download program) extracted in C:\IronPython
>>
>> 2) Create a C:\IronPython subdirectory pyc_d.
>>
>> 3) In the C:\IronPython\pyc_d created a file primer.py:
>>
>> from avalon import *
>> import calculator
>> w = Window()
>> w.Title = "My Avalon Application"
>> w.Content = LoadXaml("calc.xaml")
>> calculator.enliven(w)
>> w.Show()
>>
>> 4)pyc_d contains:
>>
>> IronPython.dll
>> IronPython.Modules.dll
>> IronPython.Wpf.dll
>> Microsoft.Scripting.dll
>>
>> avalon.py
>> Calc.xaml
>> calculator.py
>> primer.py
>> pyc.py
>>
>> 5) Run ipy.exe, sequentially enter commands from the primer.py, it works
>> :).
>>
>> 6) Next:
>> c:\IronPython\ipy.exe pyc.py /main:primer.py /target:exe /platform:x86
>> /standalone
>> I get primer.exe (4,09 РњР‘).
>>
>> 7) Run from the console, I get:
>> C:\IronPython\pyc_d>primer.exe
>>
>> An unhandled exception: System.InvalidOperationException: The calling
>> thread must be STA, because many UI components require this.
>> В  РІ
>> Microsoft.Scripting.Interpreter.NewInstruction.Run(InterpretedFrame
>> frame)
>> В  РІ Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame
>> frame)
>> В  РІ Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0
>> arg0, T1 arg1, T2 arg2)
>> В
...............................................................................
>> В All is not enumerate
>>
>> It seems to do everything correctly. I take an example from the
>> Tutorial,
>> the files from the Tutorial, to be going smoothly, but ... What is the
>> problem?
>>
>> 8)Try another option. Make a thin client in C #.
>> В Create a console C # project, and Program.cs:
>>
>> using System;
>> using IronPython.Hosting;
>> using Microsoft.Scripting.Hosting;
>> using System.Reflection;
>> using System.IO;
>>
>> namespace ConsoleApplication1
>> {
>>      class Program
        {
>>            static void Main(string[] args)
>>            {
>>                  string path = Assembly.GetExecutingAssembly().Location;
>>                  string dir = Directory.GetParent(path).FullName;
>>
>>                  ScriptEngine engine = Python.CreateEngine();
>>                  ScriptSource source =
>> engine.CreateScriptSourceFromFile(Path.Combine(dir, args[0]));
>>                  CompiledCode compiled = source.Compile();
>>                  ScriptScope scope = engine.CreateScope();
>>                  compiled.Execute(scope);
>>           }
>>      }
>> }
>>
>> 9) run:
>> C:\IronPython\pyc_d>ConsoleApplication1.exe primer.py
>>
>> the same result: (Unhandled exception: System.InvalidOperationException:
>> The calling thread must be STA, because many UI components require
>> this.)
>> В What is the problem?
>> В Are there any experts who can create learning (from Tutorial) WPF
>> application and run it on a machine without installing IronPython from
>> the console?
>> В Thank you.)



More information about the Ironpython-users mailing list