[sugar] filtering result of an object chooser

Tomeu Vizoso tomeu
Tue Mar 4 05:10:21 EST 2008


On Mon, Mar 3, 2008 at 11:14 PM, Erik Blankinship <erikb at mediamods.com> wrote:
> > On 2/29/08, Erik Blankinship <erikb at mediamods.com> wrote:
> > > 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
> > >
> >
> >
> > Unfortunately, this code (and the identical code in the Browse activity)
> when run in jhbuild always returns this path: "."
> >
> > Is this expected behavior?  Is this problem unique to jhbuild?  Is there
> something I should to differently?
>
>
> Trying a few different objects reveals that I can pick Write files (.odt)
> and Image files (.png), but not Video files (.ogg) -- those come back as "."

Any info in the logs?

Just tried in jhbuild from Abiword with an ogg file, and it got this file path:

/home/tomeu/.sugar/default/data/fc7be60e-de25-494c-ad48-b9d5c5629ca8(1)

Tomeu



More information about the Sugar-devel mailing list