filechoose logic

This commit is contained in:
age 2006-04-06 22:03:18 +00:00
parent 0e9e4f4bde
commit 364091ce2d

View file

@ -0,0 +1,46 @@
#!/usr/bin/env python
class FileChooserDialog:
'does what it sounds like ;)'
def __init__(self):
return
def getfilename(self):
'returns name of the choosen file or empty string'
import gtk
# der Filedialog ist erst ab pygtk2.4 drin
if gtk.pygtk_version < (2,3,90):
print "Du brauchst mindestens PyGtk 2.3.90"
raise SystemExit
dialog = gtk.FileChooserDialog("Datei oeffnen..",
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)
filter = gtk.FileFilter()
filter.set_name("Alle Dateien")
filter.add_pattern("*")
dialog.add_filter(filter)
filter = gtk.FileFilter()
filter.set_name("Text")
filter.add_mime_type("text/txt")
filter.add_mime_type("text/asc")
filter.add_pattern("*.txt")
filter.add_pattern("*.asc")
dialog.add_filter(filter)
response = dialog.run()
if response == gtk.RESPONSE_OK:
filename = dialog.get_filename()
#print "hier haste den Dateinamen: ", filename
elif response == gtk.RESPONSE_CANCEL:
#print "die feige sau bricht einfach ab.."
filename = ""
dialog.destroy()
return filename