sugar4.graphics.objectchooser

STABLE.

Attributes

J_DBUS_SERVICE

J_DBUS_INTERFACE

J_DBUS_PATH

FILTER_TYPE_MIME_BY_ACTIVITY

FILTER_TYPE_GENERIC_MIME

FILTER_TYPE_ACTIVITY

Classes

ObjectChooser

UI interface for object choosers.

Functions

get_preview_pixbuf(preview_data[, width, height])

Retrieve a pixbuf with the content of the preview field

Module Contents

sugar4.graphics.objectchooser.J_DBUS_SERVICE = 'org.laptop.Journal'[source]
sugar4.graphics.objectchooser.J_DBUS_INTERFACE = 'org.laptop.Journal'[source]
sugar4.graphics.objectchooser.J_DBUS_PATH = '/org/laptop/Journal'[source]
sugar4.graphics.objectchooser.FILTER_TYPE_MIME_BY_ACTIVITY = 'mime_by_activity'[source]
sugar4.graphics.objectchooser.FILTER_TYPE_GENERIC_MIME = 'generic_mime'[source]
sugar4.graphics.objectchooser.FILTER_TYPE_ACTIVITY = 'activity'[source]
sugar4.graphics.objectchooser.get_preview_pixbuf(preview_data, width=-1, height=-1)[source]

Retrieve a pixbuf with the content of the preview field

Parameters:

preview_data (bytes) – preview data from the metadata dictionary. Can’t be None. Returned from the sugar4.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 height, if is not set,

  • used

Returns:

the generated Pixbuf None: if it could not be created

Return type:

GdkPixbuf.Pixbuf

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.append(im) im.show()

class sugar4.graphics.objectchooser.ObjectChooser(parent=None, what_filter=None, filter_type=None, show_preview=False)[source]

Bases: object

UI interface for object choosers.

Object choosers can be used by activities 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 sugar4.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 associated 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)

run()[source]

Runs the object chooser and displays it.

Returns:

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

get_selected_object()[source]

Gets the object selected using the object chooser.

Returns:

the object selected

Return type:

object

destroy()[source]

Destroys and cleans up (disposes) the object chooser.