Hi,
I am assuming that the winforms your code imports at the top is the winforms.py
that we include with our tutorial. If that is indeed the case, it may very well
be the cause of the hang you are seeing.
The winforms.py does a bit more than just import the System.Windows.Forms
assemblies. It also creates another thread that the code interactively typed at
the console will run on. The reason is that the console thread is suspended,
waiting for input and cannot process messages for the window application which
is being interactively built. Therefore the winforms.py launches new thread
that the interactive code will execute on.
Once you run your code as a script, you are likely to hit problems. One reason
for the hang I can see from the top of my head is that the thread created by
winforms.py depends on the console exiting to exit its message loop so it may
cause your app to stay up and running/limping :).
The solution is to not import winforms.py and only use the following code at
the top of your script (taken from winforms.py)
import clr
clr.AddReferenceByPartialName("System.Windows.Forms")
clr.AddReferenceByPartialName("System.Drawing")
Martin
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paparipote .
Sent: Monday, February 20, 2006 3:20 PM
To: [email protected]
Subject: [IronPython] Screen inhibited when running a .py program that uses
ShowDialog
To demonstrate this please:
1) invoke ironpythonconsole from DOS prompt
2) Copy and paste the next code (it is inoffensive):
import winforms
from System.Windows.Forms import *
from System.Drawing import *
def ShowFiles(multiSel=1, title="Select a File to select"):
fd = OpenFileDialog()
fd.Multiselect = multiSel
fd.Title = title
if fd.ShowDialog() == DialogResult.OK:
return (0, fd.FileNames)
else:
msg = 'Selection of file(s) was cancelled.'
MessageBox.Show(msg)
return (1, msg)
if __name__ == '__main__':
res = ShowFiles(title="Select files to show")
if res[0] == 0:
for i in res[1]:
print i
MessageBox.Show("Successful show")
3) In the File dialog window Select one or more files and press OK or
cancel.
4) All finishes well, ¿ok?
Now, save the code in a file (for example cat.py)
1) From a Dos command prompt type: ironpythonconsole cat.py and press
return.
2) Do the same actions as above.
3) After finishing the script with a windows message box, does not it keep
hanged?' Please, confirm me that? Thanks.
Best regards.
_________________________________________________________________
Las mejores tiendas, los precios mas bajos, entregas en todo el mundo,
YupiMSN Compras: http://latam.msn.com/compras/
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com