by Paul Stovell via Paul Stovell on 10/7/2009 12:16:53 PM
Sheldon is a WPF command line control, and code to integrate it with IronPython. It's designed as a sample that demonstrates how a WPF application might be made scriptable:
This sample was created to pitch an idea to a client about enabling a macro system in their application. Users might be able to make use of functions like OpenAccount("ACME"), ExecuteJob("SalesForecast2009"), and so on. Using the Command Pattern, commands could be written to an Output window in the application while the user uses the UI - that could be used as a learning tool for learning the command line.
OpenAccount("ACME")
ExecuteJob("SalesForecast2009")
The demo application shows how object models can be shared between your application and scripting environment. In C#, I set up an AutomationContext, which is made available to IronPython:
public class AutomationContext { public ApplicationDefinition Application { get; set; } public IScriptingContext ScriptingContext { get; set; } public void Exit() { Environment.Exit(0); } }
Then in IronPython, I create a friendly "API" that users can consume:
def GetWindow(name): return automation_context.Application.MainWindow def Clear(): automation_context.ScriptingContext.Clear() def Exit(): automation_context.Exit()
The ScriptingContext is an object that manages the execution and rendering of scripts, which the command line control can hook into. Multiple controls can talk to a single scripting context - here's a custom shell (I simply overrode the style and control template of the Shell control):
ScriptingContext
You can download the code here:
Original Post: Sheldon
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.