Hi Michael,

Thank you for the info.  Sounds like an interesting technique that I will 
explore in the future once I actually have a copy of IronPython in Action in my 
hands to help guide me.

I would also like to thank you for taking the time and effort to write the book 
and share your knowledge and experience with us newbies. :)

Cheers,
-- Leo

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Michael Foord
Sent: 2009?10?7? 14:43
To: Discussion of IronPython
Subject: Re: [IronPython] Issue with using multiple forms in IronPython

Leonides Saguisag wrote:
> Hi Dino,
>
> Thanks for the awesome advice!  I got it to work after I removed those pesky 
> "class WindowsApplication" declarations.
>
> I am not all too clear on what you mean by making a base form in C# and then 
> inheriting that.  Is that discussed in the IronPython in Action book?  I 
> haven't picked up a copy of the book yet, hoping to do so within the week.
>
>   

It is covered in IronPython in Action yes.

Basically use Visual Studio (Express) but generating C# instead of IronPython. 
Make the compiled dll part of your IronPython project, add a reference to it 
and import the generated Form classes. You can then subclass these from 
IronPython.

Michael

> XAML sounds interesting but due to time constraints I will continue to work 
> with WinForms for the app that I am working on.
>
> Thanks for your help!
>
> Cheers,
> -- Leo
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Dino Viehland
> Sent: 2009?10?7? 13:50
> To: Discussion of IronPython
> Subject: Re: [IronPython] Issue with using multiple forms in 
> IronPython
>
> The problem here is really that IronPython Studio is really weird and is 
> trying to create namespaces where none exist.  So if you removed the class 
> WindowsApplication... everywhere or if you changed the namespace names so the 
> 2 files had distinct "namespaces" it would work.  But you won't get the two 
> separate classes to be merged into one namespace.
>
> I personally would suggest going w/ Michael Foord's recommendation of making 
> a base winforms class in the designer w/ C# and then just inheriting from 
> that in IronPython rather than using IronPython Studio's forms support.
>
> Alternately I think XAML is probably the future as far as IronPython IDEs go. 
>  W/ XAML none of the UI needs to be represented with code.
>
>
>   
>> -----Original Message-----
>> From: [email protected] [mailto:users- 
>> [email protected]] On Behalf Of Leonides Saguisag
>> Sent: Wednesday, October 07, 2009 1:36 PM
>> To: '[email protected]'
>> Subject: [IronPython] Issue with using multiple forms in IronPython
>>
>> I am trying to create a simple app which has two forms.  Form1 
>> contains a button which, when clicked, should display Form2 as a 
>> dialog.  Here is the source code (developed using IronPython Studio):
>>
>> ### Program.py ###
>> from System import *
>> from System.Windows.Forms import *
>> from Form1 import *
>>
>> class WindowsApplication80: # namespace
>>
>>     @staticmethod
>>     def RealEntryPoint():
>>         Application.EnableVisualStyles()
>>         Application.Run(WindowsApplication8.Form1())
>>
>> if __name__ == "Program":
>>     WindowsApplication80.RealEntryPoint();
>> ### end of Program.py ###
>>
>> ### Form1.py ###
>> import System
>> from System.Windows.Forms import *
>> from System.ComponentModel import *
>> from System.Drawing import *
>> from clr import *
>> from Form2 import *
>> class WindowsApplication8: # namespace
>>
>>     class Form1(System.Windows.Forms.Form):
>>         """type(_button1) == System.Windows.Forms.Button, 
>> type(_form2) == System.Windows.Forms.Form"""
>>         __slots__ = ['_button1', '_form2']
>>         def __init__(self):
>>             self.InitializeComponent()
>>
>>         @accepts(Self(), bool)
>>         @returns(None)
>>         def Dispose(self, disposing):
>>
>>
>>
>>             super(type(self), self).Dispose(disposing)
>>
>>         @returns(None)
>>         def InitializeComponent(self):
>>             self._button1 = System.Windows.Forms.Button()
>>             self.SuspendLayout()
>>             #
>>             # button1
>>             #
>>             self._button1.Location = System.Drawing.Point(96, 78)
>>             self._button1.Name = 'button1'
>>             self._button1.Size = System.Drawing.Size(75, 23)
>>             self._button1.TabIndex = 0
>>             self._button1.Text = 'button1'
>>             self._button1.UseVisualStyleBackColor = True
>>             self._button1.Click += self._button1_Click
>>             #
>>             # Form1
>>             #
>>             self.ClientSize = System.Drawing.Size(292, 273)
>>             self.Controls.Add(self._button1)
>>             self.Name = 'Form1'
>>             self.Text = 'Form1'
>>             self.ResumeLayout(False)
>>
>>         @accepts(Self(), System.Object, System.EventArgs)
>>         @returns(None)
>>         def _button1_Click(self, sender, e):
>>             self._form2 = WindowsApplication8.Form2()
>>             ShowDialog(self._form2)
>> ### end of Form1.py ###
>>
>> ### Form2.py ###
>> import System
>> from System.Windows.Forms import *
>> from System.ComponentModel import *
>> from System.Drawing import *
>> from clr import *
>> class WindowsApplication8: # namespace
>>
>>     class Form2(System.Windows.Forms.Form):
>>         __slots__ = []
>>         def __init__(self):
>>
>>             self.InitializeComponent()
>>
>>         @accepts(Self(), bool)
>>         @returns(None)
>>         def Dispose(self, disposing):
>>
>>
>>
>>             super(type(self), self).Dispose(disposing)
>>
>>         @returns(None)
>>         def InitializeComponent(self):
>>             self.SuspendLayout()
>>             #
>>             # Form2
>>             #
>>             self.ClientSize = System.Drawing.Size(292, 273)
>>             self.Name = 'Form2'
>>             self.Text = 'Form2'
>>             self.Load += self._Form2_Load
>>             self.ResumeLayout(False)
>> ### end of Form2.py ###
>>
>> The issue is that when I click on button1 on Form1, the debugger 
>> stops in the _button1_Click method, on the following line:
>>
>>      self._form2 = WindowsApplication8.Form2()
>>
>> Here is the exception detail:
>> ### Start of exception detail ###
>> IronPython.Runtime.Exceptions.PythonNameErrorException was unhandled 
>> by user code
>>   Message="name 'Form2' not defined"
>>   Source="IronPython"
>>   StackTrace:
>>        at
>> IronPython.Runtime.Operations.Ops.CheckInitializedOrBuiltin(Object
>> o, ICallerContext context, String name)
>>        at Form1._button1_Click$f630(FunctionEnvironment8Dictionary
>> $env, Object self, Object sender, Object e) in Form1.py:line 49
>>        at IronPython.Runtime.Calls.Function3.Call(ICallerContext
>> context, Object arg0, Object arg1, Object arg2)
>>        at IronPython.Runtime.Calls.Function3.Call(ICallerContext
>> context, Object[] args)
>>        at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args)
>>        at
>> IronPython.Modules.ClrModule.ReturnChecker.RuntimeChecker.Call(Object[] args)
>>        at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args)
>>        at
>> IronPython.Modules.ClrModule.ArgChecker.RuntimeChecker.Call(Object[]
>> args)
>>        at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args)
>>        at
>> IronPython.Runtime.Types.ReflectedEvent.EventDispatcher.Call(Object[] args)
>>        at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args)
>>        at IronPython.Runtime.Operations.Ops.Call(Object func, Object 
>> arg0, Object arg1)
>>        at System.Void(Object, EventArgs)##51(Object , Object , EventArgs )
>>        at System.Windows.Forms.Control.OnClick(EventArgs e)
>>        at System.Windows.Forms.Button.OnClick(EventArgs e)
>>        at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
>>        at System.Windows.Forms.Control.WmMouseUp(Message& m, 
>> MouseButtons button, Int32 clicks)
>>        at System.Windows.Forms.Control.WndProc(Message& m)
>>        at System.Windows.Forms.ButtonBase.WndProc(Message& m)
>>        at System.Windows.Forms.Button.WndProc(Message& m)
>>        at
>> System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
>> m)
>>        at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& 
>> m)
>>        at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
>> hWnd,
>> Int32 msg, IntPtr wparam, IntPtr lparam)
>>        at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
>>        at
>> System.Windows.Forms.Application.ComponentManager.System.Windows.Form
>> s
>> .UnsafeN
>> ativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
>> dwComponentID, Int32 reason, Int32 pvLoopData)
>>        at
>> System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(In
>> t
>> 32
>> reason, ApplicationContext context)
>>        at
>> System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
>> reason, ApplicationContext context)
>>        at System.Windows.Forms.Application.Run(Form mainForm)
>>        at Run##60(Object )
>>        at IronPython.Runtime.Calls.FastCallable1.Call(ICallerContext
>> context, Object arg0)
>>        at IronPython.Runtime.Calls.FastCallable1.Call(ICallerContext
>> context, Object[] args)
>>        at
>> IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext
>> context, Object[] args)
>>        at
>> IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext
>> context, CallType callType, Object[] args)
>>        at
>> IronPython.Compiler.MethodBinder.TargetSet.Call1(ICallerContext
>> context, Object arg0)
>>        at
>> IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerConte
>> x
>> t
>> context, Object arg0)
>>        at 
>> IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext
>> context, Object arg0)
>>        at
>> IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext
>> context, Object func, Object arg0)
>>        at Program.RealEntryPoint$f634(FunctionEnvironment4Dictionary
>> $env) in Program.py:line 10
>>        at IronPython.Runtime.Calls.Function0.Call(ICallerContext context)
>>        at
>> IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext
>> context, Object func)
>>        at Program.Initialize() in Program.py:line 13
>>        at
>> IronPython.Runtime.Operations.Ops.ExecuteCompiled(InitializeModule
>> init)
>>   InnerException:
>> ### End of exception detail ###
>>
>> I am stumped as to why it thinks Form2 is not defined.
>>
>> Just to add, all of the files are all located in the same folder:
>> WindowsApplication8\Form1.py
>> WindowsApplication8\Form1.resx
>> WindowsApplication8\Form2.py
>> WindowsApplication8\Form2.resx
>> WindowsApplication8\Program.py
>>
>> I would greatly appreciate any insight anyone can provide.
>>
>> Thanks,
>> -- Leo
>> _______________________________________________
>> 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
> _______________________________________________
> Users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


_______________________________________________
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

Reply via email to