I am working with GTK in Python. I noticed that it is easy to SAVE AS but for some reason I cannot just SAVE a file. I thought I'd set it up to check if it was saved at all and then SAVE but for some reason it restarts the function over and over w/o saving the value of filename. The thing that is killing me is this feels like a beginner mistake. somehow I have forgotten to keep the value after the function has been run. I hope this makes sense.
def SaveFile(filename):
chooser = gtk.FileChooserDialog("Save File...", None,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
filename = chooser.get_filename()
if filename == None:
response = chooser.run()
if response == gtk.RESPONSE_OK:
filename = chooser.get_filename()
chooser.destroy()
wbuffer = textview.get_buffer()
text = wbuffer.get_text(wbuffer.get_start_iter(), wbuffer.get_end_iter())
openfile = open(filename,"w")
openfile.write(text)
openfile.close()
print filename, "this is the first part"
return filename
else:
chooser.destroy()
elif filename != None:
wbuffer = textview.get_buffer()
text = wbuffer.get_text(wbuffer.get_start_iter(), wbuffer.get_end_iter())
openfile = open(filename,"w")
openfile.write(text)
openfile.close()
print filename, "made it this far"
return filename
else:
chooser.destroy()
return filename