Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import sys
- from gi.repository import Gtk
- #
- # Make sure you point TARGET_DIR to an empty directory
- # file_one.txt will be successfully created.
- # When second dialog opens it will have file_one.txt in the
- # input field instead of file_two.txt as set with set_current_filename()
- #
- TARGET_DIR="~/Videos"
- class app(Gtk.Window):
- def __init__(self):
- Gtk.Window.__init__(self, title="Testink, testink, ...")
- self.show_all()
- (foo, bar) = self.dialog("First", "file_one.txt")
- if bar == Gtk.ResponseType.OK:
- folder = foo.get_current_folder()
- fn = foo.get_filename()
- print "FOL", folder, "FN", fn
- filepath = os.path.join(foo.get_current_folder(),
- foo.get_filename())
- f = open(filepath, "w+")
- f.write("BigW Was Here\n")
- f.close()
- foo.destroy()
- (foo, bar) = self.dialog("Second", "file_two.txt")
- if bar == Gtk.ResponseType.OK:
- filepath = os.path.join(foo.get_current_folder(),
- foo.get_filename())
- f = open(filepath, "w+")
- f.write("BigW Was Here, for the second time!\n")
- f.close()
- foo.destroy()
- def dialog(self, title, filename):
- dlg = Gtk.FileChooserDialog(title, None, Gtk.FileChooserAction.SAVE,
- (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
- "Save", Gtk.ResponseType.OK))
- dlg.set_current_name(filename)
- dlg.set_do_overwrite_confirmation(True)
- path = os.path.expanduser(TARGET_DIR)
- dlg.set_current_folder(path)
- dlg.show_all()
- result = dlg.run()
- return dlg, result
- ap = app()
- ap.show_all()
- ap.connect("delete-event", Gtk.main_quit)
- Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement