Debian Codegraph @

fltk/test/native-filechooser.py

raw symbols SCIP
1
2 #
3 # "$Id: file_chooser.py 495 2013-03-30 09:39:45Z andreasheld $"
4 #
5 # File chooser test program for pyFLTK the Python bindings
6 # for the Fast Light Tool Kit (FLTK).
7 #
8 # FLTK copyright 1998-1999 by Bill Spitzak and others.
9 # pyFLTK copyright 2003 by Andreas Held and others.
10 #
11 # This library is free software you can redistribute it and/or
12 # modify it under the terms of the GNU Library General Public
13 # License, version 2.0 as published by the Free Software Foundation.
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 "[email protected]".
26 #
27
28 from fltk import *
29 import sys
30
31 # globals
32 TERMINAL_HEIGHT = 120
33 fc = None
34 filter = None
35 files = None
36 relative = ""
37
38 def PickFile_CB(widget):
39 global G_filename
40 global G_tty
41 # Create native chooser
42 native = Fl_Native_File_Chooser()
43 native.title("Pick a file")
44 native.directory(G_filename.value())
45 native.type(Fl_Native_File_Chooser.BROWSE_FILE)
46 # Show native chooser
47 status = native.show()
48 if status == -1:
49 G_tty.printf("ERROR: %s\n", native.errmsg())
50 elif status == 1:
51 G_tty.printf("*** CANCEL\n")
52 fl_beep()
53 else:
54 if native.filename():
55 G_filename.value(native.filename())
56 G_tty.printf("filename='%s'\n"%native.filename())
57 else:
58 G_filename.value("NULL");
59 G_tty.printf("dirname='(null)'\n")
60
61 def PickDir_CB(widget):
62 global G_filename
63 global G_tty
64 # Create native chooser
65 native = Fl_Native_File_Chooser()
66 native.title("Pick a directory")
67 native.directory(G_filename.value())
68 native.type(Fl_Native_File_Chooser.BROWSE_DIRECTORY)
69 # Show native chooser
70 status = native.show()
71 if status == -1:
72 G_tty.printf("ERROR: %s\n", native.errmsg())
73 elif status == 1:
74 G_tty.printf("*** CANCEL\n")
75 fl_beep()
76 else:
77 if native.filename():
78 G_filename.value(native.filename())
79 G_tty.printf("dirname='%s'\n"%native.filename())
80 else:
81 G_filename.value("NULL");
82 G_tty.printf("dirname='(null)'\n")
83
84
85 if __name__=='__main__':
86 global G_filename
87 argn = 1
88
89 Fl_File_Icon.load_system_icons()
90
91 win = Fl_Window(640, 400+TERMINAL_HEIGHT, "Native File Chooser Test")
92 win.size_range(win.w(), win.h(), 0, 0)
93 win.begin()
94
95 G_tty = Fl_Terminal(0,400,win.w(),TERMINAL_HEIGHT)
96 x = 80
97 y = 10
98 G_filename = Fl_Input(x, y, win.w()-80-10, 25, "Filename")
99 G_filename.value(".")
100 G_filename.tooltip("Default filename")
101
102 y += G_filename.h() + 10
103 G_filter = Fl_Multiline_Input(x, y, G_filename.w(), 100, "Filter")
104 G_filter.value("Text\t*.txt\n"
105 "C Files\t*.{cxx,h,c,cpp}\n"
106 "Tars\t*.{tar,tar.gz}\n"
107 "Apps\t*.app")
108 G_filter.tooltip("Filter to be used for browser.\n"
109 "An empty string may be used.\n")
110
111 y += G_filter.h() + 10
112 view = Fl_Help_View(x, y, G_filename.w(), 200)
113 view.box(FL_FLAT_BOX)
114 view.color(win.color())
115 #define TAB "<Tab>"
116 view.textfont(FL_HELVETICA)
117 view.textsize(10)
118 view.value("The Filter can be one or more filter patterns, one per line.\n"
119 "Patterns can be:<ul>\n"
120 " <li>A single wildcard (e.g. <tt>\"*.txt\"</tt>)</li>\n"
121 " <li>Multiple wildcards (e.g. <tt>\"*.{cxx,h,H}\"</tt>)</li>\n"
122 " <li>A descriptive name followed by a &lt;Tab&gt; and a wildcard (e.g. <tt>\"Text Files&lt;Tab&gt;*.txt\"</tt>)</li>\n"
123 "</ul>\n"
124 "In the above \"Filter\" field, you can use <b><font color=#55f face=Courier>Ctrl-I</font></b> to enter &lt;Tab&gt; characters as needed.<br>\n"
125 "Example:<pre>\n"
126 "\n"
127 " Text<font color=#55f>&lt;Ctrl-I&gt;</font>*.txt\n"
128 " C Files<font color=#55f>&lt;Ctrl-I&gt;</font>*.{cxx,h,c,cpp}\n"
129 " Tars<font color=#55f>&lt;Ctrl-I&gt;</font>*.{tar,tar.gz}\n"
130 " Apps<font color=#55f>&lt;Ctrl-I&gt;</font>*.app\n"
131 "</pre>\n")
132
133 but = Fl_Button(win.w()-x-10, win.h()-TERMINAL_HEIGHT-25-10, 80, 25, "Pick File")
134 but.callback(PickFile_CB)
135
136 butdir = Fl_Button(but.x()-x-10, win.h()-TERMINAL_HEIGHT-25-10, 80, 25, "Pick Dir")
137 butdir.callback(PickDir_CB)
138
139 win.resizable(G_filter)
140
141 win.end()
142 win.show()
143
144 Fl.run()
145
146
147