Ironpython Studio
This is a two-part question. Dumb technical request and broader request for my maybe wrong approach to learning to do some things in a language I'm new to.
I'm just playing around with a few Python GUI libraries (mostly wxPython and IronPython) for some work I'm going to do on an open source application just to improve my skills, etc.
Throughout the day, I am a fairly standard C # bod running with a fairly common MS-based toolbox, and I am looking at Python to give me a new perspective. So using Ironpython Studio probably changes a little (okay, a lot). It doesn't seem to matter, because no matter how hard it tries to look like a Visual Studio project, etc. There's one simple behavior that I'm probably too dumb to implement.
those. How do I keep my forms in nice separate code files like the C # monkey I've always been and still call them apart? I've tried importing the form to be called into the main form, but I just can't seem to get the form to be recognized as anything other than an object. The new form is a form object in its own code file, I import clr. I am trying to call the Show method. It is not right?
I have tried several (in my opinion unlikely) ways to work around this, but the problem seems insoluble. This is something I just can't see, or it would actually be more appropriate for me to change the way I think of my GUI to match Python (in which case I can switch to wxPython which seemed more accessible from Pythonic point of view) instead of trying to look at Python from Visual Studio shell security?
In the end, it was even easier.
I tried to call the subformat like this:
f = frmSubform ()
f.Show ()
But I really needed to do it this way
f = frmSubform ()
Form.Show (f)
Form.ShowDialog (f) also worked; in an interactive format, of course.
Simple enough mistake, but while you don't know, well, you don't know.
I'm not sure if at this stage I understand why it works, it works, but I'm sure that I will learn from experience.
I don't fully understand the problem. You can definitely define a subclass System.Windows.Forms.Form
in IronPython in one module and then import the subclass of the form in another module:
# in form.py
from System.Windows.Forms import Form, Button, MessageBox
class TrivialForm(Form):
def __init__(self):
button = Button(Parent=self, Text='Click!')
button.Click += self.show_message
def show_message(self, sender, args):
MessageBox.Show('Stop that!')
# in main.py
import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Application
from form import TrivialForm
if __name__ == '__main__':
f = TrivialForm()
Application.Run(f)
Wouldn't IronPython Studio's developer / code generator let you structure your code? (I've never used it.)
source to share