[IronPython] Newbie questions & comments

Edward K. Ream edreamleo at charter.net
Tue Dec 6 07:28:46 PST 2005


> > Are you trying to import the "winforms.py" that is part of the tutorial?
> > [snip]

Running my batch file from the Tutorial directory does indeed make winforms 
available.  Thanks!

Alas, winforms itself does not work properly when started inside my batch 
file.  The window freezes. Here is the contents of my batch file:

cd c:\prog\IronPython-0.9.5\Tutorial
..\bin\IronPythonConsole c:\prog\leoCVS\leo\test\ironPythonTest.py

Here is the contents of the test file that freezes:

[starts]
print 'Let the wild rumpus start!'

import winforms
from System.Windows.Forms import *
from System.Drawing import *

def click(*args): print args

f = System.Windows.Forms.Form()
f.Click += click
f.Show()

print 'done'
[ends]

The window appears and 'done' is printed immediately.  However, clicking in 
the window brings up the XP "This program is not responding" window. It 
seems that the following code in winforms.py is not working as expected:

t = Thread(thread_proc)
t.Start()

Here is another attempt:

[starts]
print 'Let the wild rumpus start!'

import sys
import System
sys.LoadAssemblyByName("System.Windows.Forms")
sys.LoadAssemblyByName("System.Drawing")

def click(*args): print args

f = System.Windows.Forms.Form()
f.Click += click
f.Show()

print 'done'
[ends]

In this case the window appears (very fleetingly, I think), and the 'done' 
message appears and that's all.  Presumably this is 'correct': the code 
wasn't run in a separate thread.

Consider the Windows Forms tutorial at:

http://samples.gotdotnet.com/quickstart/winforms/

The c# code is:

namespace Microsoft.Samples.WinForms.Cs.SimpleHelloWorld {
    using System;
    using System.Windows.Forms;

    public class SimpleHelloWorld : Form {

        [STAThread]
        public static int Main(string[] args) {
            Application.Run(new SimpleHelloWorld());
            return 0;
        }

        public SimpleHelloWorld() {
            this.Text = "Hello World";
        }
    }
}

Obviously, something involving threads is happening, but a newbie isn't 
going to know how to do this in IronPython.  BTW, I assume eventually there 
will be a Python tab for all these examples :-)

So from my mostly ignorant viewpoint it appears that:

- there is a problem with the thread code in winforms.py

- the IronPython tutorial doesn't tell how to run a Hello World IronPython 
program from a batch file.

Any help would be appreciated.  Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edreamleo at charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
-------------------------------------------------------------------- 




More information about the users mailing list