146
❘
CHAPTER 8
Creating WindoWs Forms appliCations
properties when your application will see even moderate use by those with special physical needs.
Obviously, you don’t add precisely the same code to your IronPython application that the Visual
Designer adds to the C# or Visual Basic.NET application, but the Visual Designer file provides enough
insight to make the transition to IronPython work with relative ease.
Performing Quick Form Tests
You’ll want to see your form from time to time, before you’ve written the rest of the application code.
Fortunately, you’re using IronPython, so you have the interpreter at your disposal. The following steps
outline a quick way to see what your form looks like.
1.
Start the interpreter (
IPY.EXE
) in the directory that contains the form code.
2.
Type
from frmMain import *
and press Enter. This step imports the form into the inter-
preter for testing.
3.
Type
TestForm = frmMain()
and press Enter. This step instantiates a copy of
frmMain
that
you’ll use for testing.
4.
Type
TestForm.InitializeComponent()
and press Enter. In this step, you execute the code
used to create and configure the controls within the form.
5.
Type
TestForm.ShowDialog()
and press Enter. At this point, you see the dialog box appear
onscreen, just as you’d normally see it when executed from the application. However, you see
just the dialog box and its controls. The dialog box is pretty much non-functional because
you don’t have any event handlers in place.
6.
After you finish viewing the dialog box, click Cancel or the close button. This act
closes the dialog box. You’ll see a dialog result value as part of the output, as shown
in Figure 8-4.
FIguRE 8-4:
This output shows a typical form-viewing session in the interpreter.
Even though this technique is a little limited, it does give you a view of your form so that you can
easily fix any problems. You must repeat the entire process every time you want to test changes
to the form. The act of importing the form code means that you won’t see any changes within the
interpreter until you import the form code again. In short, if you make changes and don’t see them
during testing, it’s probably because you didn’t exit the interpreter and start over.
548592c08.indd 146
2/24/10 12:48:09 PM
www.finebook.ir
Do'stlaringiz bilan baham: |