1#
2# "$Id: file_chooser.py 495 2013-03-30 09:39:45Z andreasheld $"
3#
4# File chooser test program for pyFLTK the Python bindings
5# for the Fast Light Tool Kit (FLTK).
6#
7# FLTK copyright 1998-1999 by Bill Spitzak and others.
8# pyFLTK copyright 2003 by Andreas Held and others.
9#
10# This library is free software you can redistribute it and/or
11# modify it under the terms of the GNU Library General Public
12# License as published by the Free Software Foundation either
13# version 2 of the License, or (at your option) any later version.
14#
15# This library is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18# Library General Public License for more details.
19#
20# You should have received a copy of the GNU Library General Public
21# License along with this library if not, write to the Free Software
22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23# USA.
24#
25# Please report all bugs and problems to "pyfltk-user@lists.sourceforge.net".
26#
27
28from fltk import *
29import sys
30
31# globals
32fc = None
33filter = None
34files = None
35relative = ""
36
37def close_callback(ptr):
38	sys.exit(0)
39
40def create_callback(ptr):
41	global fc
42	fc.type(fc.type() ^ Fl_File_Chooser.CREATE)
43
44def dir_callback(ptr):
45	global fc
46	fc.type(fc.type() ^ Fl_File_Chooser.DIRECTORY)
47
48def fc_callback(ptr):
49	global fc
50	#fc = Fl_File_Chooser(ptr)
51	filename = fc.value()
52	print("    filename = ", filename)
53
54def multi_callback(ptr):
55	global fc
56	fc.type(fc.type() ^ Fl_File_Chooser.MULTI)
57
58def pdf_check(name, header, headerlen):
59	return None
60
61def ps_check(name, header, headerlen):
62	return None
63
64def show_callback(ptr):
65	global fc
66	global filter
67	global relative
68	global files
69	#fc.show()
70
71	if filter.value() != None:
72		#fc.filter(filter.value())
73		fc.filter("*.*")
74
75	fc.show()
76
77	while fc.visible():
78		Fl.wait()
79
80	count = fc.count()
81	#print "count = ", count
82	#if count > 1:
83	#	files.clear()
84	#	i = 0
85	#	if fc.value(i) != None:
86	#	    (status, relative) = fl_filename_relative(relative, 1024, fc.value(i))
87	#	    files.add(relative, None)
88	#	files.redraw()
89	if count > 0:
90		files.clear()
91		i = 1;
92		while i <= count:
93			if fc.value(i) != None:
94			   (status,relative) = fl_filename_relative(relative, 1024, fc.value(i))
95			   files.add(relative, Fl_File_Icon.find(fc.value(i),Fl_File_Icon.PLAIN))
96			i = i+1
97		files.redraw()
98
99
100# Make the file chooser...
101#Fl.scheme(0)
102Fl_File_Icon.load_system_icons()
103filter_string="*.*"
104
105fc = Fl_File_Chooser(".", "*", Fl_File_Chooser.SINGLE, "Fl_File_Chooser Test");
106#fc = Fl_File_Chooser("", filter_string, Fl_File_Chooser.SINGLE, "Fl_File_Chooser Test")
107fc.callback(fc_callback)
108fc.preview(0)
109
110# Register the PS and PDF image types...
111#Fl_Shared_Image.add_handler(pdf_check)
112#Fl_Shared_Image.add_handler(ps_check)
113
114
115#make the main window
116window = Fl_Window(400, 200, "File Chooser Test")
117filter = Fl_Input(50, 10, 310, 25, "Filter:")
118filter.value(filter_string)
119#filter.value("PDF Files (*.pdf)\t"
120#                  "PostScript Files (*.ps)\t"
121#		  "Image Files (*.{bmp,gif,jpg,png})\t"
122#		  "C/C++ Source Files (*.{c,C,cc,cpp,cxx})")
123
124b1 = Fl_Button(365, 10, 25, 25, "Test")
125b1.labelcolor(FL_YELLOW);
126b1.callback(show_callback);
127
128icon   = Fl_File_Icon.find(".", Fl_File_Icon.DIRECTORY)
129#print "icon = ", icon
130if icon != None:
131	icon.label(b1);
132
133b2 = Fl_Light_Button(50, 45, 80, 25, "MULTI")
134b2.callback(multi_callback)
135
136b3 = Fl_Light_Button(140, 45, 90, 25, "CREATE")
137b3.callback(create_callback);
138
139b4 = Fl_Light_Button(240, 45, 115, 25, "DIRECTORY")
140b4.callback(dir_callback);
141
142files = Fl_File_Browser(50, 80, 340, 75, "Files:")
143files.align(FL_ALIGN_LEFT);
144
145b5 = Fl_Button(340, 165, 50, 25, "Close")
146b5.callback(close_callback)
147
148window.resizable(files)
149window.end()
150window.show()
151
152Fl.run()
153
154
155
156