[sugar] filtering result of an object chooser

Erik Blankinship erikb
Fri Feb 29 19:02:44 EST 2008


Is there a way to filter the mime types of the objects presented with an
object chooser (e.g., only png)?  Here is some sample code I am using:

import gtk
import shutil
from sugar.graphics.objectchooser import ObjectChooser

class FilePicker:

    def __init__(self):
        pass

    def show(self):
        title = None
        parent = None
        file = None
        chooser = ObjectChooser(title, parent, gtk.DIALOG_MODAL |
gtk.DIALOG_DESTROY_WITH_PARENT)
        try:
            result = chooser.run()
            if result == gtk.RESPONSE_ACCEPT:
                jobject = chooser.get_selected_object()
                if jobject and jobject.file_path:
                    ext = os.path.splitext(jobject.file_path)[1]
                    f, new_temp = tempfile.mkstemp(ext)
                    del f

                    global _temp_files_to_clean
                    _temp_files_to_clean.append(new_temp)
                    shutil.copy(jobject.file_path, new_temp)

                    file = new_temp
        finally:
            chooser.destroy()
            del chooser

        return file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.laptop.org/pipermail/sugar/attachments/20080229/742408c7/attachment.htm 



More information about the Sugar-devel mailing list