| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
from fltk import * |
| 29 |
import sys |
| 30 |
|
| 31 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 <Tab> and a wildcard (e.g. <tt>\"Text Files<Tab>*.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 <Tab> characters as needed.<br>\n" |
| 125 |
"Example:<pre>\n" |
| 126 |
"\n" |
| 127 |
" Text<font color=#55f><Ctrl-I></font>*.txt\n" |
| 128 |
" C Files<font color=#55f><Ctrl-I></font>*.{cxx,h,c,cpp}\n" |
| 129 |
" Tars<font color=#55f><Ctrl-I></font>*.{tar,tar.gz}\n" |
| 130 |
" Apps<font color=#55f><Ctrl-I></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 |
|