filechoose logic
This commit is contained in:
parent
0e9e4f4bde
commit
364091ce2d
1 changed files with 46 additions and 0 deletions
46
adstreme/glade/filechooser.py
Normal file
46
adstreme/glade/filechooser.py
Normal 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
|
||||
|
Loading…
Reference in a new issue