def generate_directory_chooser(self, option_name, label_text, value=None): """Generate a file chooser button to select a directory.""" label = Label(label_text) directory_chooser = FileChooserEntry( title='Select folder', action=Gtk.FileChooserAction.SELECT_FOLDER, default_path=reverse_expanduser(value)) directory_chooser.entry.connect('changed', self.on_chooser_dir_set, option_name) directory_chooser.set_valign(Gtk.Align.CENTER) label.set_alignment(0.5, 0.5) self.wrapper.pack_start(label, False, False, 0) self.wrapper.pack_start(directory_chooser, True, True, 0) self.option_widget = directory_chooser
def set_location_entry(self, callback, action=None, default_path=None): if action == 'file': action = Gtk.FileChooserAction.OPEN elif action == 'folder': action = Gtk.FileChooserAction.SELECT_FOLDER if self.location_entry: self.location_entry.destroy() self.location_entry = FileChooserEntry(action, default_path) self.location_entry.show_all() if callback: self.location_entry.entry.connect('changed', callback) else: self.install_button.set_visible(False) self.continue_button.show() self.widget_box.pack_start(self.location_entry, False, False, 0)
def set_path_chooser(self, callback_on_changed, action=None, default_path=None): """Display a file/folder chooser.""" if action == 'file': title = 'Select file' action = Gtk.FileChooserAction.OPEN elif action == 'folder': title = 'Select folder' action = Gtk.FileChooserAction.SELECT_FOLDER if self.location_entry: self.location_entry.destroy() self.location_entry = FileChooserEntry(title, action, default_path) self.location_entry.show_all() if callback_on_changed: self.location_entry.entry.connect('changed', callback_on_changed) else: self.install_button.set_visible(False) self.continue_button.connect('clicked', self.on_file_selected) self.continue_button.grab_focus() self.continue_button.show() self.widget_box.pack_start(self.location_entry, False, False, 0)