domingo, julio 21, 2013

Sugar programming: Improvements in ObjectChooser

A few little improvement will be available for activity programmers in Sugar 0.100. Some are related with the ObjectChoooser.

The first is a more powerful filter. Previously, you could select one of the generic type of files defined (Text,Image, Audio, Video, Link) or a activity id. The generic types were defined as a collection of mime types, the user can't modify. In the case of filter by activity, the ObjectChooser will show all the objects opened or created by the activity. The election of what filter type use was automatic, then the programmer could do:

chooser = ObjectChooser(self._activity, what_filter='Image')


chooser = ObjectChooser(self._activity, what_filter=.get_bundle_id())

This was simple but had problems. Some activities can open file types with mime types different to the generic defined types, by example, the Text files supported by Read activity were different than the Text files supported by Write activity. Jukebox activity can open Audio & Video files, but ObjectChooser can open only one type at time. There are a few variations of TurtleArt activities, and all can open the same files.

We decided improve this in two ways:
* Add a new filter mode, where the developer can select the activity id, and the ObjectChooser will filter all the objects with mime types than the activity can open (Sugar knows what mime types can open the activity because is defined in the file)
* The developer now should select explicitly the filter type, instead of let the ObjectChooser guess. In this way we can add more filter types in the future too.

Now the call to the ObjectChooser can be:

            chooser = ObjectChooser(parent=self,
            chooser = ObjectChooser(parent=self,

In this case, Read activity will open all the objects defined in the file.
The except is for compatibility with old versions of Sugar.

Another case should be:

        chooser = ObjectChooser(self._activity, what_filter='Image',

returning all the Image files, or:

            chooser = ObjectChooser(parent=self,

to get all the objects created or edited by the activity.

Another improvement is the posibility of display the previews in the objects, specially useful when the user need select one image from the Journal to use in a activity, like in Paint,Write, Fototoon or Memorize.

        chooser = ObjectChooser(self._activity, what_filter='Image',

Will show something like this:

Finally, ObjectChooser startup time was improved. 
These are only part of the changes available soon in Sugar 0.100, stay tuned. 
Publicar un comentario