1getOpenFile(3)        User Contributed Perl Documentation       getOpenFile(3)
2
3
4

NAME

6       Tk::getOpenFile - pop up a dialog box for the user to select a file to
7       open.
8

SYNOPSIS

10           $widget->getOpenFile(?-option=>value, ...>?)
11
12           $widget->getSaveFile(?-option=>value, ...>?)
13

DESCRIPTION

15       The methods getOpenFile and getSaveFile pop up a dialog box for the
16       user to select a file to open or save.
17
18       The getOpenFile method is usually associated with the Open command in
19       the File menu.  Its purpose is for the user to select an existing file
20       only.  If the user enters an non-existent file, the dialog box gives
21       the user an error prompt and requires the user to give an alternative
22       selection. If an application allows the user to create new files, it
23       should do so by providing a separate New menu command.
24
25       The getSaveFile method is usually associated with the Save as command
26       in the File menu. If the user enters a file that already exists, the
27       dialog box prompts the user for confirmation whether the existing file
28       should be overwritten or not.
29
30       If the user selects a file, both getOpenFile and getSaveFile return the
31       full pathname of this file. If the user cancels the operation, both
32       commands return an undefined value.
33
34       The following option-value pairs are possible as command line arguments
35       to these two commands:
36
37       -defaultextension => extension
38           Specifies a string that will be appended to the filename if the
39           user enters a filename without an extension. The default value is
40           the empty string, which means no extension will be appended to the
41           filename in any case. This option is ignored on the Macintosh
42           platform, which does not require extensions to filenames, and the
43           UNIX implementation guesses reasonable values  for  this from the
44           -filetypes option when this is not supplied.
45
46       -filetypes => [filePattern ?, ...?]
47           If a File types listbox exists in the file dialog on the particular
48           platform, this option gives the filetypes in this listbox. When the
49           user choose a filetype in the listbox, only the files of that type
50           are listed. If this option is unspecified, or if it is set to the
51           empty list, or if the File types listbox is not supported by the
52           particular platform then all files are listed regardless of their
53           types. See "SPECIFYING FILE PATTERNS" below for a discussion on the
54           contents of filePatterns.
55
56       -initialdir => directory
57           Specifies that the files in directory should be displayed when the
58           dialog pops up. If this parameter is not specified, then the files
59           in the current working directory are displayed.  This option may
60           not always work on the Macintosh.  This is not a bug.  Rather, the
61           General Controls control panel on the Mac allows the end user to
62           override the application default directory.
63
64       -initialfile => filename
65           Specifies a filename to be displayed in the dialog when it pops up.
66           This option is ignored by the getOpenFile method.
67
68       -multiple
69           Allows the user to choose multiple files from the Open dialog.  On
70           the Macintosh, this is only available when Navigation Services are
71           installed.
72
73       -message => string
74           Specifies a message to include in the client area of the dialog.
75           This is only available on the Macintosh, and only when Navigation
76           Services are installed.
77
78       -title => titleString
79           Specifies a string to display as the title of the dialog box. If
80           this option is not specified, then a default title is displayed.
81           This option is ignored on the Macintosh platform.
82

SPECIFYING FILE PATTERNS

84       The filePatterns given by the -filetypes option are a list of file
85       patterns. Each file pattern is a list of the form
86
87        typeName [extension ?extension ...?] ?[macType ?macType ...?]?
88
89       typeName is the name of the file type described by this file pattern
90       and is the text string that appears in the File types listbox.
91       extension is a file extension for this file pattern.  macType is a
92       four-character Macintosh file type. The list of macTypes is optional
93       and may be omitted for applications that do not need to execute on the
94       Macintosh platform.
95
96       Several file patterns may have the same typeName, in which case they
97       refer to the same file type and share the same entry in the listbox.
98       When the user selects an entry in the listbox, all the files that match
99       at least one of the file patterns corresponding to that entry are
100       listed. Usually, each file pattern corresponds to a distinct type of
101       file. The use of more than one file patterns for one type of file is
102       necessary on the Macintosh platform only.
103
104       On the Macintosh platform, a file matches a file pattern if its name
105       matches at least one of the extension(s) AND it belongs to at least one
106       of the macType(s) of the file pattern. For example, the C Source Files
107       file pattern in the sample code matches with files that have a \.c
108       extension AND belong to the macType TEXT. To use the OR rule instead,
109       you can use two file patterns, one with the extensions only and the
110       other with the macType only. The GIF Files file type in the sample code
111       matches files that EITHER have a \.gif extension OR belong to the
112       macType GIFF.
113
114       On the Unix and Windows platforms, a file matches a file pattern if its
115       name matches at at least one of the extension(s) of the file pattern.
116       The macTypes are ignored.
117

SPECIFYING EXTENSIONS

119       On the Unix and Macintosh platforms, extensions are matched using glob-
120       style pattern matching. On the Windows platforms, extensions are
121       matched by the underlying operating system. The types of possible
122       extensions are: (1) the special extension * matches any file; (2) the
123       special extension "" matches any files that do not have an extension
124       (i.e., the filename contains no full stop character); (3) any character
125       string that does not contain any wild card characters (* and ?).
126
127       Due to the different pattern matching rules on the various platforms,
128       to ensure portability, wild card characters are not allowed in the
129       extensions, except as in the special extension *. Extensions without a
130       full stop character (e.g, ~) are allowed but may not work on all
131       platforms.
132

CAVEATS

134       See "CAVEATS" in Tk::chooseDirectory.
135

EXAMPLE

137        my $types = [
138            ['Text Files',       ['.txt', '.text']],
139            ['TCL Scripts',      '.tcl'           ],
140            ['C Source Files',   '.c',      'TEXT'],
141            ['GIF Files',        '.gif',          ],
142            ['GIF Files',        '',        'GIFF'],
143            ['All Files',        '*',             ],
144        ];
145        my $filename = $widget->getOpenFile(-filetypes=>$types);
146
147        if ($filename ne "") {
148            # Open the file ...
149        }
150

SEE ALSO

152       Tk::FBox, Tk::FileSelect
153

KEYWORDS

155       file selection dialog
156
157
158
159perl v5.38.0                      2023-07-21                    getOpenFile(3)
Impressum