GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Dec 23, 2014 4:25 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: FileChooser widget
PostPosted: Sun Mar 23, 2014 3:39 pm 
Offline
Familiar Face

Joined: Sun Jul 31, 2011 9:42 pm
Posts: 7
Location: Italy
Hi.
I'm using the file chooser widget with multiple selection for my application.
I'd like the user to be able to choose both files and folders.
Is there any way to do that?
Thanks.


Top
 Profile  
 
 Post subject: Re: FileChooser widget
PostPosted: Sun Mar 30, 2014 9:39 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 799
Location: UK
Hello,

The only options that I can seen from the documentation for GtkFileChooser is :-
- Open file (GTK_FILE_CHOOSER_ACTION_OPEN)
- Save file (GTK_FILE_CHOOSER_ACTION_SAVE)
- Select folder (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
- Create folder (GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)

_________________
E.


Top
 Profile  
 
 Post subject: Re: FileChooser widget
PostPosted: Tue Aug 05, 2014 3:07 am 
Offline

Joined: Mon Aug 04, 2014 1:20 am
Posts: 2
This should get you pretty close to what you need. It's for python, but you should be able to translate it easily enough.

Code:
import gtk

class AltFileChooserDialog(gtk.FileChooserDialog):
    def __init__ (self, currentFolder=None):
        super(AltFileChooserDialog, self).__init__(
                title="Choose a folder or file", parent=None,
                action=gtk.FILE_CHOOSER_ACTION_OPEN,
                buttons= (  gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                            gtk.STOCK_OK, gtk.RESPONSE_OK),
                backend=None)
       
        okButton = self.get_widget_for_response(response_id=gtk.RESPONSE_OK)
   
        if currentFolder is not None:
            self.set_current_folder(currentFolder)

        okButton.connect("pressed", self.on_pressed)
        okButton.connect("activate", self.on_activate)

    def on_pressed(self, button):
        self.on_activate(button)
       
    def on_activate(self, button):
        self.filename = self.get_filename()
        if self.filename is None:
            pass
        else:
            self.response(gtk.RESPONSE_OK)


def getFile(currentFolder=None):
    newDialog = AltFileChooserDialog(currentFolder=currentFolder)
    response = newDialog.run()

    if response == gtk.RESPONSE_OK:
        filename = newDialog.filename
        return filename

    elif response == gtk.RESPONSE_CANCEL:
        return None

    newDialog.destroy()


filename = getFile()
print filename


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group