[pygtk] (FileChooserDialog) Save-Overwrite
Andrea Caminiti
a.caminiti at yahoo.com
Thu May 8 03:09:34 WST 2008
hi:
i'm having some troubles trying to figure out how to use the overwrite option.
right now i have a save button that is connected the click button signal to
def save_file. but feel that i'm doing somethingwrong with the overwrite function.
this is the code i'm using.
def save_file(self):
global file
dialog = gtk.FileChooserDialog("Save..",
None,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)
dialog.show()
response = dialog.run()
if response == gtk.RESPONSE_OK:
name = dialog.get_filename()
if file == None and file != name:
file = open(dialog.get_filename(), 'w')
print file
elif file != None and name == file:
dialog.set_do_overwrite_confirmation(True)
dialog.connect("confirm-overwrite", self.confirm_overwrite_callback)
file = open(dialog.get_filename(), 'w')
print file
file.write("something")
dialog.destroy()
elif response == gtk.RESPONSE_CANCEL:
pass
dialog.destroy()
return
def confirm_overwrite_callback(self, widget):
uri = gtk.FileChooserDialog.get_filename()
if is_uri_read_only(uri):
if user_wants_to_replace_read_only_file (uri):
return gtk.FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME
else:
return gtk.FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN
else:
# fall back to the default dialog
return gtk.FILE_CHOOSER_CONFIRMATION_CONFIRM
return
when i try it, an select an existing file, no overwrite dialog was displayed. when i check
the file the previous content was changed for the new one. any idea on what's wrong?
any suggestions?
nrayever
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
More information about the pygtk
mailing list