Debian Codegraph @

fltk/test/file_chooser.py

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