-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilechooser.py
34 lines (27 loc) · 966 Bytes
/
filechooser.py
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
29
30
31
32
33
34
#!/usr/bin/env python
# example filechooser.py
import pygtk
pygtk.require('2.0')
import gtk
import os
# Check for new pygtk: this is new class in PyGtk 2.4
if gtk.pygtk_version < (2,3,90):
print "PyGtk 2.3.90 or later required for this example"
raise SystemExit
dialog = gtk.FileChooserDialog("Open..",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
dialog.set_current_folder(os.path.join(os.environ.get("HOME"),'Documents'))
filter = gtk.FileFilter()
filter.set_name("All pdf files")
filter.add_pattern("*.pdf")
dialog.add_filter(filter)
response = dialog.run()
if response == gtk.RESPONSE_OK:
print dialog.get_filename()
elif response == gtk.RESPONSE_CANCEL:
print 'Closed, no files selected'
dialog.destroy()