Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

tk_getOpenFile - Multiple files extension for UNIX?

Status
Not open for further replies.

smugindividual

Programmer
Apr 14, 2003
104
US
Does anyone know the location of an extension that will allow for multiple file openings at one time. I know that this works for 8.3 on the Macs and for all platforms in 8.4. Unfortunatly I am stuck with 8.3.

Thanks in advance
 
Um, could you describe your requirements a bit more? If all you're doing is opening files, Tcl has never had a limit (besides that imposed by your operating system) on the number of files that it can have open simultaneously. Just keep opening the files as needed, storing the file IDs returned by open into separate variables. Then use the appropriate file ID to interact with each file.

Code:
# Open a file for reading
set fid1 [open file1.txt r]

# Open a second file for reading
set fid2 [open file2.txt r]

# Open a third file for writing (truncating it
# if it already exists).

set fid3 [open file3.txt w]

# Read the first line from file1.txt
gets $fid1 line1

# Read the first line from file2.txt
gets $fid2 line2

# Write the lines into file3.txt

puts $fid3 $line1
puts $fid3 $line2

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Using tk_getOpenFile command allows the user to select a file from a list and choose to open it. Looks like what would show if you picked "Open" from a windows menu. The command only allows for marking one file at a time(in tcl 8.3 unless on a Mac platform). It has been changed in 8.4 so that getOpenFile works as i have described it. Obviously a oversight. I wanted to know if there was a trick to get around it or if there were any locations to find a widget to do what I am asking. I am stuck with 8.3.

It would be nice to have the end user open the files he/she needs by writting their own tcl scripts but unfortunatly their skills are limited to holding the ctrl key and selecting mutiple files from a list.
 
Oops, sorry. I read the message body, but forgot to read the subject line.

Well, if you want to go with the native file selection dialogs, you're stuck. As you identified, the -multiple option wasn't added until 8.4. But if you're willing to go with a non-native dialog, you can manage it.

On platforms where there isn't a native file selection dialog (basically, Unix in most cases), Tcl creates its own in pure Tcl/Tk code. That code is contained in the Tk library files. If your Tcl installation directory is $INSTALL, you'll find them in $INSTALL/lib/tkX.X. The procedure that displays the file open dialog is ::tk::dialog::file, and it's contained in the file tkfbox.tcl. However, it uses other Tk library procedures defined in several other files (dialog.tcl among them). I've not had time to work out all the dependencies.

Anyway, the upshot is that you should be able to copy that code from a 8.4 distribution and use it in a 8.3 environment. I've not had time to scan through the code to determine if there are any 8.4 dependencies, but I suspect that there aren't for the file dialogs. For a little more information on this subject (though probably not all that applicable to your case), you might want to check out
If you don't want to take that approach, I suppose you could "roll your own" based on a listbox widget.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top