Listing Using the dialog created in Visual Studio with Iron Python

import clr clr.AddReference('RenameTabDialog') clr.AddReference('System.Windows.Forms')

from RenameTabDialog import RenameTabDialogBase

10 IronPython uses reflection to discover members. Marking them as protected or private only makes them less convenient to access; it doesn't truly hide them from the determined programmer.

11 If you subclass a .NET class, protected members are public, so you can still access them from outside the class. You can't access protected members on a non-Python subclass.

from System.Windows.Forms import DialogResult class RenameTabDialog(RenameTabDialogBase):


title = "Name Tab" if rename:

title = "Rename Tab" self.Text = title self.textBox.Text = name

As the external API is the same as the hand-coded dialog, the ShowDialog function can remain unchanged.

Although this example of using Visual Studio used a dialog created with the forms designer, you've actually created a class library and imported it into IronPython. This is how easy it is to extend IronPython from other .NET languages, a subject we look into in more detail later in the book.

We've just about made it through our three new commands. You've created commands that can remove pages and rename pages, and written the infrastructure code to support them. In this section, you created a dialog for naming and renaming tab pages, using the forms designer from Visual Studio. In the next section, which introduces a command to add new pages, you get to reuse this dialog.

0 0

Post a comment