sugar3.graphics.objectchooser module

STABLE.

class sugar3.graphics.objectchooser.ObjectChooser(parent=None, what_filter=None, filter_type=None, show_preview=False)

Bases: object

UI interface for object choosers.

Object choosers can be used by acivities to allow the user to select objects from the file system or from some other similar source.

Keyword Arguments
  • parent (Gtk.Widget) – the widget calling ObjectChooser

  • what_filter (str) – an activity bundle_id or a generic mime type as defined in sugar3.mime used to determine which objects will be presented in the object chooser

  • filter_type (str) –

    should be one of [None, FILTER_TYPE_GENERIC_MIME, FILTER_TYPE_ACTIVITY, FILTER_TYPE_MIME_BY_ACTIVITY]

    If filter_type is None, the default behavior of the what_filter is applied (for backward compatibility), this option is DEPRECATED.

    If filter_type is FILTER_TYPE_GENERIC_MIME, the what_filter should be a generic mime type defined in mime.py; the object chooser will filter based in the ‘mime_type’ metadata field.

    If filter_type is FILTER_TYPE_ACTIVITY, the what_filter should by an activity bundle_id; the object chooser will filter based in the ‘activity’ metadata field.

    If filter_type is FILTER_TYPE_MIME_BY_ACTIVITY, the what_filter should be an activity bundle_id; the object chooser will filter based on the ‘mime_type’ metadata field and the mime types defined by the activity in the activity.info file.

  • show_preview (bool) – if True will show the preview image asociated with the object in the Journal. This option is only available if filter_type is selected.

Examples

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

chooser = ObjectChooser(parent=self,

what_filter=self.get_bundle_id(), filter_type=FILTER_TYPE_ACTIVITY)

destroy()

Destroys and cleans up (disposes) the object chooser.

get_selected_object()

Gets the object selected using the object chooser.

Returns

object, the object selected

run()

Runs the object chooser and displays it.

Returns

Gtk.ResponseType constant, the response received from displaying the object chooser.

sugar3.graphics.objectchooser.get_preview_pixbuf(preview_data, width=- 1, height=- 1)

Retrive a pixbuf with the content of the preview field

Parameters

metadata (dictionary) – preview data from the metadata dictionary. Can’t be None. Returned from the sugar3.datastore.datastore.DSObject.get_metadata() method.

Keyword Arguments
  • width (int) – the pixbuf width, if is not set,

  • used (the default height will be) –

  • height (int) – the pixbuf width, if is not set,

  • used

Returns

Pixbuf, the generated Pixbuf None, if it could not be created

Example

pixbuf = get_preview_pixbuf(metadata.get(‘preview’, ‘’)) has_preview = pixbuf is not None

if has_preview:

im = Gtk.Image() im.set_from_pixbuf(pixbuf) box.add(im) im.show()