1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dan Shafer">
<title>File Dialog</title>
<meta name="generator" content="Namo WebEditor v5.0(Trial)">
</head>
<body>
<h1>File Dialog</h1>
<img src="images/dialogsfig7.png" alt="Find Dialog Sample"
width="563" height="344">
<br>
<h2> </h2>
<h2>Creating the Dialog</h2>
<p> Create a File Dialog by calling dialog.fileDialog with the arguments
shown in the following table.</p>
<table cellpadding="2" cellspacing="2" border="1" width="50%">
<tbody>
<tr>
<td valign="top"><b>Argument</b><br>
</td>
<td valign="top"><b>Data type/notes</b><br>
</td>
</tr>
<tr>
<td valign="top">self<br>
</td>
<td valign="top">the window (background) that is the parent for
the dialog<br>
</td>
</tr>
<tr>
<td valign="top">message<br>
</td>
<td valign="top">quoted string defining the title for the dialog
</td>
</tr>
<tr>
<td valign="top">
<p>path</p>
</td>
<td valign="top">
<p>quoted string defining the default path to be used for the dialog</p>
</td>
</tr>
<tr>
<td valign="top">
<p>fileName</p>
</td>
<td valign="top">
<p>quoted string defining a file name to be used typically in saving
a file</p>
</td>
</tr>
<tr>
<td valign="top">filter<br>
</td>
<td valign="top">quoted string containing the pattern to be used to identify
files to be shown to the user by default when the File Dialog opens. The
dialog above was created with a pattern of "*.py." A more complex example
is shown below.<br>
</td>
</tr>
<tr>
<td valign="top">
<p>OPTIONAL style</p>
</td>
<td valign="top">
<p>A boolean logic expression containing one or more pre-defined
window style constants that define how the window will look and
behave.</p>
</td>
</tr>
</tbody>
</table>
<br>
<b>Example:<br>
<br>
</b>The above dialog was created with this line of code:<br>
<br>
<code>result = dialog.fileDialog(self, 'Open', '', '', wildcard )</code><br>
<code><br>
</code>after setting the variable wildcard to the string "*.py".<br>
<br>
To open a File Dialog showing all JPEG and GIF files in the current directory,
you would first set the wildcard string to "JPG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF
files (*.gif)|*.gif|All Files (*.*)|*.*" and then use the above line to open
the File Dialog.<br>
<p>The optional style argument in dialog.fileDialog is generally not used when
opening a File dialog to save a document because its default settings -- wx.OPEN
| wx.MULTIPLE -- is the generally accepted norm for such dialogs. In creating
dialogs for <i>saving</i> files, on the other hand, it is often useful to define
a variable (here called "aStyle") which defines more fully how the
save process will be managed. For example:</p>
<p>aStyle = wx.SAVE | wx.HIDE_READONLY | wx.OVERWRITE_PROMPT</p>
<p>will create a file save dialog (rather than the default file open), in which
read-only files are not shown and an attempt to overwrite an existing file is
confirmed with a prompt dialog.</p>
<h2>Interacting With the Dialog</h2>
The fileDialog component returns its values, stored as attributes
of an instance of the DialogResults class called "results" returned by all PythonCard dialogs.
These results are as shown in the following table.<br>
<br>
<table cellpadding="2" cellspacing="2" border="1" width="50%">
<tbody>
<tr>
<td valign="top"><b>Name of value</b><br>
</td>
<td valign="top"><b>Description</b><br>
</td>
</tr>
<tr>
<td valign="top">accepted<br>
</td>
<td valign="top">True = user clicked OK<br>
False = user clicked Cancel<br>
</td>
</tr>
<tr>
<td valign="top">paths<br>
</td>
<td valign="top">list of strings containing the full pathnames
to all files selected by the user<br>
</td>
</tr>
</tbody>
</table>
<br>
<b>Example:<br>
<br>
</b>The sample dialog shown at the top of this page returns the following
results:<br>
<br>
accepted: True<br>
paths: ['C:\\pycode\\PythonCard\\setup.py']<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>
|