def start(): try: global app app = Application() app.Startup += on_startup app.Run() finally: clr.SetCommandDispatcher(None)
def start(): try: global app app = Application() app.Startup += on_startup app.ShutdownMode = ShutdownMode.OnExplicitShutdown app.Run() finally: clr.SetCommandDispatcher(None)
def thread_proc(): try: global dispatcher global are # Create the dummy control, and show then hide it to get Windows Forms # to initialize it. dispatcher = Form(Size=Size(0, 0)) dispatcher.Show() dispatcher.Hide() # Signal that the thread running thread_proc is ready for the main # thread to send input to it. are.Set() # Start the message loop. Application.Run() finally: # In case thread_proc's thread dies, restore the default IronPython # console execution behavior. clr.SetCommandDispatcher(None)
clr.SetCommandDispatcher(None) # If dispatcher is set, then assume that UI issues are already taken care of. currentDispatcher = clr.GetCurrentRuntime().GetLanguage( PythonContext).GetCommandDispatcher() if currentDispatcher is None: if Application.Current is None: dispatcher = None else: dispatcher = Application.Current.Dispatcher if dispatcher is None: t = Thread(ThreadStart(start)) t.IsBackground = True t.ApartmentState = ApartmentState.STA t.Start() are.WaitOne() else: clr.SetCommandDispatcher(currentDispatcher) def DispatchConsoleCommand(consoleCommand): if consoleCommand: dispatcher.Invoke(DispatcherPriority.Normal, consoleCommand) def dispatch(function): dispatcher.Invoke(DispatcherPriority.Normal, CallTarget0(function)) if currentDispatcher is None: clr.SetCommandDispatcher(DispatchConsoleCommand)
dispatcher = Form(Size=Size(0, 0)) dispatcher.Show() dispatcher.Hide() # Signal that the thread running thread_proc is ready for the main # thread to send input to it. are.Set() # Start the message loop. Application.Run() finally: # In case thread_proc's thread dies, restore the default IronPython # console execution behavior. clr.SetCommandDispatcher(None) def DispatchConsoleCommand(consoleCommand): if consoleCommand: # consoleCommand is a delegate for a dynamic method that embodies the # input expression from the user. Run it on the other thread. dispatcher.Invoke(consoleCommand) else: Application.Exit() t = Thread(ThreadStart(thread_proc)) t.IsBackground = True t.Start() # Don't establish the alternative input execution behavior until the other # thread is ready. Note, 'are' starts out unsignalled. are.WaitOne() clr.SetCommandDispatcher(DispatchConsoleCommand)