Advertisement
BigWhale

Gtk3 FileChooser Bug?

Jan 14th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. from gi.repository import Gtk
  5.  
  6. #
  7. # Make sure you point TARGET_DIR to an empty directory
  8. # file_one.txt will be successfully created.
  9. # When second dialog opens it will have file_one.txt in the
  10. # input field instead of file_two.txt as set with set_current_filename()
  11. #
  12.  
  13. TARGET_DIR="~/Videos"
  14.  
  15. class app(Gtk.Window):
  16.   def __init__(self):
  17.     Gtk.Window.__init__(self, title="Testink, testink, ...")
  18.     self.show_all()
  19.  
  20.     (foo, bar) = self.dialog("First", "file_one.txt")
  21.  
  22.     if bar == Gtk.ResponseType.OK:
  23.       folder = foo.get_current_folder()
  24.       fn = foo.get_filename()
  25.       print "FOL", folder, "FN", fn
  26.       filepath = os.path.join(foo.get_current_folder(),
  27.                               foo.get_filename())
  28.       f = open(filepath, "w+")
  29.       f.write("BigW Was Here\n")
  30.       f.close()
  31.     foo.destroy()
  32.  
  33.     (foo, bar) = self.dialog("Second", "file_two.txt")
  34.  
  35.     if bar == Gtk.ResponseType.OK:
  36.       filepath = os.path.join(foo.get_current_folder(),
  37.                               foo.get_filename())
  38.       f = open(filepath, "w+")
  39.       f.write("BigW Was Here, for the second time!\n")
  40.       f.close()
  41.     foo.destroy()
  42.  
  43.   def dialog(self, title, filename):
  44.     dlg = Gtk.FileChooserDialog(title, None, Gtk.FileChooserAction.SAVE,
  45.                                 (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
  46.                                 "Save", Gtk.ResponseType.OK))
  47.  
  48.     dlg.set_current_name(filename)
  49.     dlg.set_do_overwrite_confirmation(True)
  50.     path = os.path.expanduser(TARGET_DIR)
  51.     dlg.set_current_folder(path)
  52.     dlg.show_all()
  53.     result = dlg.run()
  54.     return dlg, result
  55.  
  56. ap = app()
  57. ap.show_all()
  58. ap.connect("delete-event", Gtk.main_quit)
  59. Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement