Posts

Visio Automation: Three Hello World Samples – C#, F#, and IronPython

Saveen Reddy has posted examples of automating Visio from three different languages - C#, F#, IronPython. The code samples are short, and remarkably similar. The examples all do the same thing: launch Visio 2007, create a new doc, and draw a rectangle with the text “Hello World” . Visio Automation: Three Hello World Samples – C#, F#, and IronPython The IronPython is: import sys import clr import System clr.AddReference("Microsoft.Office.Interop.Visio") import Microsoft.Office.Interop.Visio IVisio = Microsoft.Office.Interop.Visio visapp = IVisio.ApplicationClass() doc = visapp.Documents.Add("") page = visapp.ActivePage shape = page.DrawRectangle(1, 1, 5, 4) shape.Text = "Hello World"

i-Dialogue Now Supports Python

i-Dialogue now supports scripting with Python through IronPython. iDialogue is an SaS (Software-as-Service) system integrated with the Salesforce CRM. They call it a 'Customer Experience Management' system (marketing tools). i-Dialogue Now Supports Python Basic Python Demonstration Mike Leach was new to Python, and he likes it: After only a few days of playing with Python, I see now what others have been raving about. Web developers will really enjoy using Python with Dialogue Script: Cleaner code. Easier to read and manage No need for thick IDEs. Too often, an IDE like Eclipse or Visual Studio stands between you and the desired solution. Dialogue Script development is 100% browser-based (yes, it even works in Chrome!) Agile business rules management. Work side-by-side with business users and apply business rules directly in web pages Dynamic typing

Mixing Static and Dynamic Languages

Kevin Hazzard presented at the Philly Code Camp about mixing DLR (Dynamic Language Runtime) based languages with statically typed languages like C#. Mixing Static and Dynamic Languages for Philly Code Camp " The gist of this presentation is that it's possible to mix the Dynamic Language Runtime (DLR) into statically-typed, early-bound languages like C# to make them much more flexible. In this talk, I demonstrated how a ShoppingCart being filled with Products can adjust discount rates based on marketing rules written in an external Domain Specific Language (DSL). In this case, my DSL was really just Python. I chose to use Python because the syntax is so simple and clean. It's so light, it doesn't get in the way. It's not a real DSL, of course, but by injecting .NET objects into a ScriptScope on a ScriptRuntime (all DLR hosting terms), the Python syntax acting on those injected types looks an awful lot like a language for managing product discounts. " Slides and...

GeckoFX (Firefox) WebBrowser Control from IronPython

A Japanese blogger shows off how to use the GeckoFX (Firefox) Windows Forms WebBrowser control from IronPython. This allows you to embed webpages in Windows Forms applications using the Gecko rendering engine. GeckoFX WebBrowser Control from IronPython The example code uses the winforms sample that comes with IronPython: import sys sys.path.append("(IronPythonTutorial") import winforms from System.Windows.Forms import * f = Form() f.Text = "GeckoFX" f.Show() import clr clr.AddReference("Skybound.Gecko.dll") from Skybound.Gecko import * Xpcom.Initialize("(Firefox 3") browser = GeckoWebBrowser() browser.Parent = f browser.Dock = DockStyle.Fill browser.Navigate("about:robots")

Uploading a File with IronPython

An example of uploading a file to a website from IronPython: Uploading a File with IronPython This is an example of a class in IronPython that can upload a file to a web site. This is a port from a codeplex example (except without cookies...but the addition should be trivial). It uses the WebRequest class. Points to note are: 1) the parameter query_string is of type NameValueCollection , 2) the parameter url must be a valid URI (e.g. www.somewebsite.com/somepage), 3) the parameter content_type can be 'multipart/form-data'.

The Chemistry Development Kit and IronPython

The Scientific C# blog looks at using another "mature open source cheminformatics api" from C# and IronPython: The java Chemistry Development Kit . Using the CDK with the .NET Framework and Mono As it is a Java library, using it from .NET is a novel idea... The blog entry shows you how to compile the library for .NET using IKVM , an implementation of Java for .NET. The command line magic to compile CDK for .NET is: ikvmc -assembly:cdk_dotnet -target:library yourcdkjar.jar This produces a .NET assembly. An example of using the library from IronPython: import clr clr.AddReference("cdk_dotnet.dll") clr.AddReference("IKVM.OpenJDK.ClassLibrary.dll") from org.openscience.cdk import Molecule from org.openscience.cdk.smiles import SmilesParser #import the whole package for brevity from org.openscience.cdk.qsar.descriptors.molecular import * from org.openscience.cdk.qsar.result import DoubleResult tpsa = TPSADescriptor() logP = XLogPDescriptor() smiles = SmilesPars...

Why Use IronPython

My boss has a blog ! Even better, he's actually writing entries occasionally. He recently answered a question on the Joel on Software discussion board about whether or not a new company should consider using IronPython: Why Use IronPython? He cites the advantages of IronPython as: All of the .NET libraries are available. UIs look nice. I’ve never seen a pure traditional Python application that looked good, no matter how advanced its functionality. We use a bunch of third-party components - for example, Syncfusion’s Essential Grid - without any problems. Reasonably decent multithreading using the .NET libraries - CPython, the normal Python implementation, has the problem of the Global Interpreter Lock, an implementation choice that makes multithreading dodgy at best. We can build our GUI in Visual Studio, and then generate C# classes for each dialog, and then subclass them from IronPython to add behaviour. (We never need to look at the generated code.) When things go wrong, the CL...

Functional Testing of Desktop Applications

I've published series of articles on the functional testing of GUI applications. It is based on a talk that I gave at PyCon UK . Functional Testing of Desktop Applications The user interface toolkit used for the examples is Windows Forms driven from IronPython. The examples are available for download, and test a small program called "MultiDoc", the example application from chapters 4-7 of IronPython in Action . The techniques and testing patterns used in the articles are not tied to IronPython at all. The topics and principles discussed are relevant to the testing of all desktop applications, whichever framework you are using (almost...). Topics covered include: The why and how of functional testing - including the processes and infrastructure you need around them Basic principles of practical testing Common problems and ways to overcome them

IronPython 2 and the Fifth Assembly

IronPython 2 uses Dynamic Language Runtime expression trees, which have been merged with LINQ expression trees. These have extension methods and IronPython itself also uses extension methods. These need the .NET 3.5 compiler, but if you provide an ' ExtensionAttribute ' type then the compiled assemblies still work with .NET 2 (extension methods are effectively a compiler trick). Unfortunately the ' ExtensionAttribute ' type supplied with IronPython 2 clashes with the version in .NET 3.5 if your project also references the System.Core assembly. The latest release candidate of IronPython solves this problem by providing a fifth assembly. Harry Pierson (DevHawk) gives us the details: The Fifth Assembly The important details are: In IronPython 2.0 Beta 5, there were four DLLs that implement IronPython: IronPython.dll IronPython.Modules.dll Microsoft.Scripting.dll Microsoft.Scripting.Core.dll In our RC1 release, we’ve added “The Fifth Assembly”: Microsoft.Scripting.Extensio...

Oslo's Intellipad Scripted with IronPython

The Microsoft PDC conference is in full swing and there are various pieces of IronPython / Dynamic Language Runtime related news adding to the backlog of things I need to post. (C# 4 becoming a dynamic language through the DLR, preview of IronPython integration in Visual Studio 10 and so on.) One interesting snippet is that the Intellipad tool, part of the Oslo framework, is scripted with IronPython. Oslo is a modelling platform " that aim to significantly simplify designing, building, managing and scaling service-oriented and composite applications that can span from the enterprise to the Internet ". It includes a new declarative language called "M" " for working with data and building domain models ". UPDATE: Martin Fowler has a new blog entry covering Oslo in more depth . Intellipad is inspired by Emacs, and in fact had the codename "Emacs.NET". It is user scripted with IronPython instead of Lisp. Online material is hard to find, but this p...

IronPython 2 RC1 Released

IronPython 2.0 Release Candidate 1 has just been released. IronPython 2 is the version of IronPython that is built on the Dynamic Language Runtime, and targets Python 2.5. Along with the new release candidate the team notes: If no major issues with the RC are reported, we hope to ship the final 2.0 release in around a month’s time. Anyone planning to move to 2.0 please try the RC and let us know of any issues you find. IronPython 2 RC1 Release Notes Download IronPython 2 RC1 Python Standard Library Not Included in the msi Installer As well as fixing around 40 bugs (making more than 500 bug reports that have been closed since IronPython 2 went into alpha), there are a few new things in this release. Firstly, the MSI installer now has an option to ngen (pre-JIT) the installed binaries. Ngen’ing the dlls gives a significant startup performance boost. The option is turned off by default but if no issues are reported, it will be enabled by default in a future release. The last couple of be...

Pumping Iron Talk

This Saturday Harry Pierson (Program Manager for IronPython) is giving a talk on Dynamic Languages on .NET at the Southern California Code Camp Community: Pumping Iron: Dynamic Languages on .NET (Calling it SoCal makes me think of William Gibson, but there you go.) 10:00 AM - Saturday, October 25, 2008 IronRuby | IronPython | DLR As you may know, Microsoft is developing IronPython and IronRuby, .NET implementations of the popular open-source programming languages Python and Ruby. While it’s clear that Microsoft wants to attract existing Python and Ruby developers to .NET, the role of IronPython and IronRuby for existing .NET developers is less clear. What value is there for a .NET developer in learning IronPython? What are the tradeoffs between IronRuby and a more traditional .NET language like C# or VB? Harry Pierson, new PM for IronPython, will discuss where dynamic . languages fit in the.NET developers toolbox.

Crack .NET: Runtime Debugging & Scripting Tool

Crack.NET is a runtime debugging and scripting tool that gives you access to the internals of any .NET desktop application running on your computer. Crack.NET allows you to walk the managed heap of another .NET application, inspect all kinds of values on objects, and even manipulate those objects via IronPython scripts. Crack .NET Homepage Download from Codeplex Article on Crack .NET (word document) Once you find an object or type that you're interested in, you can manipulate it, and others, by writing and executing an IronPython script. Crack.NET was built against version 1.1.2 of IronPython.DLL and IronMath.DLL.

IronScheme turns One

1.0 Beta 1 that is. Yesterday IronScheme 1.0 Beta 1 was released. IronScheme is a rewrite of IronLisp, and aims to be an R6RS conforming implementation of Scheme based on the Microsoft Dynamic Language Runtime. This new language implementation allows you to write .NET applications in Scheme or embed Scheme as a scripting language. It also opens up the possibility of Python and Scheme (and other dynamic languages) interoperating through the DLR. This release includes a Visual Studio (SP1) plugin and is the creation of the author of the Open Source .NET xacc ide which has Scheme support. IronScheme From the 1.0 Beta 1 release notes : Notably lacking for R6RS call/cc only supports outward continuations Differences all raise's are continuable in the sense they can be caught no tail calls in dynamic-wind Extras a generic load procedure for toplevel R6RS files many extras procedures and macros in (ironscheme) library, mostly provided by psyntax syntactic CLR integration, automatic conve...

IronPython Updates

I've got a backlog of links to post; normal service will be resumed shortly... In the meantime here a few snippets that may be of interest. Through the ' Pyc ' compiler sample, which uses ' clr.CompileModules ' under the hood, IronPython 2 can compile Python code to binary assemblies. These assemblies can be ngen'd (pre-JITed) making imports roughly three times as fast as from a Python sourcecode file. This is great because IronPython import performance is sloooow... In the latest beta (2 beta 5) compiling packages was broken, meaning that we couldn't build and test a binary distribution of Resolver One running on IronPython 2. This problem was supposed to have been fixed in the latest codeplex source code drop , so today I tested it out. The first thing I had to do was build IronPython 2 from sources on a machine that has .NET 3.5 installed, but not Visual Studio 2008. It took me a while to find precisely the right magic command line invocation to build in ...

Compiling the DLR for Silverlight and IronPython with Silverlight RC0

Silverlight Release Candidate 0 is out, this means that the old versions of IronPython and the Dynamic Language Runtime don't work with the new version. Silverlight includes a cut down version of the .NET framework called the Core-CLR. IronPython and DLR have to be compiled against the Core-CLR assemblies for the version of Silverlight you are targeting. But IronPython is Open Source, so you can just compile it against the new Silverlight assemblies right? Jimmy Schementi explains: Compiling the DLR, IronRuby, and IronPython for ANY version of Silverlight " Of course! Everything should just work, since there were no major breaking changes in Silverlight that affect the DLR between Beta2 and RC0. So, you hacked up the csproj files to point at mscorlib.dll, system.dll, etc in the new Silverlight install directory (C:\Program Files\Microsoft Silverlight\2.0.30923.0), compile, and it builds fine. Then you try to run an app ... " Next you need to make a simple change to your d...

OpenBabel from IronPython

Noel O'Blog reports on the recent OpenBabel release that explicitly supports IronPython. OpenBabel, IronPython and ADME filtering OpenBabel is: " a chemical toolbox designed to speak the many languages of chemical data. It's an open, collaborative project allowing anyone to search, convert, analyze, or store data from molecular modeling, chemistry, solid-state materials, biochemistry, or related areas. " The OBDotNet release comes with instructions on how to use it from IronPython: First of all, unzip the OBDotNet distribution, and set the environment variable BABEL_DATADIR to point to the data folder contained within. If running IronPython in the unzipped OBDotNet folder, you can use the following to initialise OBDotNet: >>> import clr >>> clr.AddReference("OBDotNet") Otherwise, you need to need to: (1) add the OBDotNet distribution folder to the PATH environment variable (2) include the full path to the OBDotNet.dll when adding the ...

Unit Testing in Python

The "Test Driven Developer", a .NET developer, has been using IronPython - and is " having a good time testing code with its built-in unit test framework ". He posts some example code with tests using the unittest module: Unit Testing in Python " This example should illustrate that we can write some unit tests for our Python code fairly easily and quickly. It's nice to have a built-in framework for unit testing. There is also a "doctest" module available for doing more like system testing. "

IronPython Talks to Google AppEngine

Joseph Jude has continued his experimenting with his time tracking tool and getting a desktop application (written in IronPython of course) - a time tracking tool - to use google authentication via the AppEngine. IronPython Talks to Google AppEngine He has made a new release of the client side tool, with configuration details to talk to his appspot application (the desktop tool can be used standalone without communicating with the server): " I had the idea of having a server which will act as a centralized data repository - laptop/desktop tool, mobile tool should send data to the server and data will be analyzed in the server. " " Next steps? Incorporate with Google Charts to provide some neat analytics reports, so that it really becomes an useful tool. "

Spider Python: Some Notes on IronPython

Some person on the internet has been learning IronPython. In order to learn IronPython he has ported a simple web spider (from a language called Retlang ) and posted the Python code: Spider Python: Some Notes on IronPython He is normally a C# developer (but he has tried Boo). He has also posted some notes on his first impressions of Python: Python list comprehensions can do the same as LINQ for simple cases, but LINQ is much more powerful, and it supports deferred execution, while list comprehensions are evaluated greedily. (Ed: generator expressions are evaluated lazily in Python) Every description of the python syntax I ever see emphasizes the fact you don't need to put in braces. Pity they don't spend more time telling you that you have to put in colons, that would actually be useful knowledge. This really bit me when I learnt boo, which is syntactically very similar. IronPython 1.0 targets CPython 2.4. This sounds fine until you realize that this was released in 2004. A...