Listing Show Dialog function displaying Rename TabDialog and returning result

def ShowDialog(name, rename):

Takes same arguments as dialog

Showdialog

dialog = RenameTabDialog(name, rename) result = dialog.ShowDialog() dialog.Close()

if result == DialogResult.OK:

return dialog. textBox. Text <1- Sets Return return None

When ShowDialog is called, it displays the dialog. The elegant result can be seen in figure 6.4—note the padding around the buttons! If the user selects OK (or hits the Enter key), then the function returns the text from the text box; otherwise, it returns None.

Inspecting the controls after the dialog has returned is one way of retrieving the values the user has selected on the dialog. An alternative approach would be to define (and wire up to the buttons) onAccept and onClose methods, which can set attributes or data structures on the dialog representing the user choices. THE RENAMECOMMAND

With the dialog in place, you need a command to use it. This command can go in tab-commands.py, and is also very simple—as you can see in listing 6.12. It uses the current-PageTitle property you added to the tab controller and the ShowDialog function.

Was this article helpful?

0 0

Post a comment