3
# This demonstration script prompts the user to select a file.#
4
# widget demo prompts the user to select a file (called by 'widget')
8
if defined?($filebox_demo) && $filebox_demo
13
# demo toplevel widget
14
$filebox_demo = TkToplevel.new {|w|
15
title("File Selection Dialogs")
21
TkLabel.new($filebox_demo,'font'=>$font,'wraplength'=>'4i','justify'=>'left',
22
'text'=>"Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog.").pack('side'=>'top')
25
TkFrame.new($filebox_demo) {|frame|
29
tmppath = $filebox_demo
33
}.pack('side'=>'left', 'expand'=>'yes')
37
command proc{showCode 'filebox'}
38
}.pack('side'=>'left', 'expand'=>'yes')
39
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
42
['open', 'save'].each{|type|
43
TkFrame.new($filebox_demo) {|f|
44
TkLabel.new(f, 'text'=>"Select a file to #{type}: ", 'anchor'=>'e')\
47
TkEntry.new(f, 'width'=>20) {|e|
48
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x')
50
TkButton.new(f, 'text'=>'Browse ...',
51
'command'=>proc{fileDialog $filebox_demo,e,type})\
55
pack('fill'=>'x', 'padx'=>'1c', 'pady'=>3)
59
$tk_strictMotif = TkVarAccess.new('tk_strictMotif')
60
if ($tk_platform['platform'] == 'unix')
61
TkCheckButton.new($filebox_demo,
62
'text'=>'Use Motif Style Dialog',
63
'variable'=>$tk_strictMotif,
64
'onvalue'=>1, 'offvalue'=>0 ).pack('anchor'=>'c')
67
def fileDialog(w,ent,operation)
68
# Type names Extension(s) Mac File Type(s)
70
#--------------------------------------------------------
72
['Text files', ['.txt','.doc'] ],
73
['Text files', [], 'TEXT' ],
74
['Ruby Scripts', ['.rb'], 'TEXT' ],
75
['Tcl Scripts', ['.tcl'], 'TEXT' ],
76
['C Source Files', ['.c','.h'] ],
77
['All Source Files', ['.rb','.tcl','.c','.h'] ],
78
['Image Files', ['.gif'] ],
79
['Image Files', ['.jpeg','.jpg'] ],
80
['Image Files', [], ['GIFF','JPEG']],
84
if operation == 'open'
85
file = Tk.getOpenFile('filetypes'=>types, 'parent'=>w)
87
file = Tk.getSaveFile('filetypes'=>types, 'parent'=>w,
88
'initialfile'=>'Untitled',
89
'defaultextension'=>'.txt')