Hey, there are two ways to do this that I can think of off the top of my head. One is using gio.content_type_guess<https://developer.gnome.org/pygobject/2.28/gio-functions.html#function-gio--content-type-guess>, the other (and likely slower albeit more accurate) way would be to use a gio.File instance like so:
file_ = gio.File(filename) info = file_.query_info("standard::content-type") or equivalently info = file_.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) mimetype = info.get_content_type() Regards. On Wed, Sep 25, 2013 at 12:04 AM, Giuseppe Penone <gius...@gmail.com> wrote: > Hi, > I'm using gtk.FileChooserDialog with a filter to display only "text/plain" > files and this works fine: > > filter = gtk.FileFilter() > filter.add_mime_type("text/plain") > chooser.add_filter(filter) > > But if I need to check if a file is of this mime type, using python module > mimetypes is not so good in detecting the proper mime type. > > Is it possible somehow to use gtk.FileChooser engine to retrieve files > with a mime type in a directory without going through the dialog? > > I tried to do it without running the dialog and just doing: > > ... > chooser.add_filter(filter) > chooser.set_current_folder(foldername) > chooser.select_all() > print chooser.get_filenames() > > but I always get an empty list, it seems that without chooser.run() it > doesn't work, unfortunately I cannot instantiate just a gtk.FileChooser() > > Cheers, > Giuseppe. > > > _______________________________________________ > pygtk mailing list pygtk@daa.com.au > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://faq.pygtk.org/ >
_______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/