Sheldon

You are looking at revision 2 of this page, which may be out of date. View the latest version.

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:

A screenshot of Sheldon

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.

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):

A custom shell style and template

You can download the code here:

Last revised: 13 Dec, 2009 07:27 AM History
You are looking at revision 2 of this page, which may be out of date. View the latest version.

Discussion

Jiho
Jiho
15 Oct, 2009 03:00 PM

When I try to run the demo, I get an error:

"The image format is unrecognized."

19 Oct, 2009 03:16 PM

Very nice! Great demo app.

20 Oct, 2009 05:20 PM

I've got the same FileFormatException here.

13 Nov, 2009 07:22 AM

Jiho and Dean, you may get that exception on Windows XP due to the window icon being used - it's a known WPF bug. I've changed it to use an icon that is compatible with XP - give it a try.

Your Comments

Used for your gravatar. Will not be public.

Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.

Preview