python - Controlling a C# Winforms GUI with IronPython -
Then I created Winforms GUI using C # in Visual Studio, but I am working for this project , Because I have code written in Python I'm hoping to write in the "engine" python (for portability), and after that I have an application interface that I can swap.
I compiled the C # project for a .dl, and able to import classes into an IronPython script and start the GUI right.
The problem is that running a GUI stops the execution of the Python script unless I put it in a separate thread. However, if I put the GUI in a different thread and try to use the original python thread to change state information, then I get an exception about modifying the control with a different thread.
Is there a good way to communicate with the UI thread or what I am trying to do is there a way to accomplish this?
GUI C # driver:
public class program {Private station main window window; [STAThread] static zero main () {Program.RunGUI (); } Public Fixed Zero RunGUI () {Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault (wrong); Window = new main window (); Application.Run (window); } Public static Zero Setwest (Game State State) {window.State = state; }}
and Python Script:
import clr clr.AddReferenceToFile ("TG.Model.dll") clr.AddReferenceToFile ("TG.UI .dl ") imported from TG.Model Import Game TG.UI import import import import time to DEF main (): print" Hello! "State = GameState () print state. CharacterName print dir thread.start_new_thread (Program.RunGUI, ()) # Program.RunGUI () time.sleep (2) program .custetate (state) raw_input () if __name__ == "__main__": main () < / Code> Put the call after the program in an event handler .UNGUI () < / Code>.
C #:
public static zero RunGUI (EventHandler onLoad) {... window = new MainWindow (); Window. Load + = onload; Application.Run (window); Window. Load - = Onload; Python: def download (sender, args): time.sleep (2) program .SetState (state) raw_input () DIF Main (): ... program. RUNGUI (ONELD)
Comments
Post a Comment