Gdk.Clipboard

g GObject.Object GObject.Object Gdk.Clipboard Gdk.Clipboard GObject.Object->Gdk.Clipboard

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

get_content ()

get_display ()

get_formats ()

is_local ()

read_async (mime_types, io_priority, cancellable, callback, *user_data)

read_finish (result)

read_text_async (cancellable, callback, *user_data)

read_text_finish (result)

read_texture_async (cancellable, callback, *user_data)

read_texture_finish (result)

read_value_async (type, io_priority, cancellable, callback, *user_data)

read_value_finish (result)

set (value)

set_content (provider)

store_async (io_priority, cancellable, callback, *user_data)

store_finish (result)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

content

Gdk.ContentProvider

r/en

display

Gdk.Display

r/w/co/en

formats

Gdk.ContentFormats

r/en

local

bool

r/en

Signals

Inherited:

GObject.Object (1)

Name

Short Description

changed

Emitted when the clipboard changes ownership.

Fields

Inherited:

GObject.Object (1)

Class Details

class Gdk.Clipboard(**kwargs)
Bases:

GObject.Object

Abstract:

No

The GdkClipboard object represents data shared between applications or inside an application.

To get a GdkClipboard object, use [method`Gdk`.Display.get_clipboard] or [method`Gdk`.Display.get_primary_clipboard]. You can find out about the data that is currently available in a clipboard using [method`Gdk`.Clipboard.get_formats].

To make text or image data available in a clipboard, use [method`Gdk`.Clipboard.set_text] or [method`Gdk`.Clipboard.set_texture]. For other data, you can use [method`Gdk`.Clipboard.set_content], which takes a [class`Gdk`.ContentProvider] object.

To read textual or image data from a clipboard, use [method`Gdk`.Clipboard.read_text_async] or [method`Gdk`.Clipboard.read_texture_async]. For other data, use [method`Gdk`.Clipboard.read_async], which provides a GInputStream object.

get_content()[source]
Returns:

The content of a clipboard if the clipboard does not maintain any content

Return type:

Gdk.ContentProvider or None

Returns the GdkContentProvider currently set on self.

If the self is empty or its contents are not owned by the current process, None will be returned.

get_display()[source]
Returns:

a GdkDisplay

Return type:

Gdk.Display

Gets the GdkDisplay that the clipboard was created for.

get_formats()[source]
Returns:

The formats of the clipboard

Return type:

Gdk.ContentFormats

Gets the formats that the clipboard can provide its current contents in.

is_local()[source]
Returns:

True if the clipboard is local

Return type:

bool

Returns if the clipboard is local.

A clipboard is considered local if it was last claimed by the running application.

Note that [method`Gdk`.Clipboard.get_content] may return None even on a local clipboard. In this case the clipboard is empty.

read_async(mime_types, io_priority, cancellable, callback, *user_data)[source]
Parameters:
  • mime_types ([str]) – a None-terminated array of mime types to choose from

  • io_priority (int) – the I/O priority of the request

  • cancellable (Gio.Cancellable or None) – optional GCancellable object

  • callback (Gio.AsyncReadyCallback or None) – callback to call when the request is satisfied

  • user_data (object or None) – the data to pass to callback function

Asynchronously requests an input stream to read the self's contents from.

When the operation is finished callback will be called. You must then call [method`Gdk`.Clipboard.read_finish] to get the result of the operation.

The clipboard will choose the most suitable mime type from the given list to fulfill the request, preferring the ones listed first.

read_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

a GInputStream

out_mime_type:

location to store the chosen mime type

Return type:

(Gio.InputStream or None, out_mime_type: str)

Finishes an asynchronous clipboard read.

See [method`Gdk`.Clipboard.read_async].

read_text_async(cancellable, callback, *user_data)[source]
Parameters:

Asynchronously request the self contents converted to a string.

When the operation is finished callback will be called. You must then call [method`Gdk`.Clipboard.read_text_finish] to get the result.

This is a simple wrapper around [method`Gdk`.Clipboard.read_value_async]. Use that function or [method`Gdk`.Clipboard.read_async] directly if you need more control over the operation.

read_text_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

a new string

Return type:

str or None

Finishes an asynchronous clipboard read.

See [method`Gdk`.Clipboard.read_text_async].

read_texture_async(cancellable, callback, *user_data)[source]
Parameters:

Asynchronously request the self contents converted to a GdkPixbuf.

When the operation is finished callback will be called. You must then call [method`Gdk`.Clipboard.read_texture_finish] to get the result.

This is a simple wrapper around [method`Gdk`.Clipboard.read_value_async]. Use that function or [method`Gdk`.Clipboard.read_async] directly if you need more control over the operation.

read_texture_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

a new GdkTexture

Return type:

Gdk.Texture or None

Finishes an asynchronous clipboard read.

See [method`Gdk`.Clipboard.read_texture_async].

read_value_async(type, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously request the self contents converted to the given type.

When the operation is finished callback will be called. You must then call [method`Gdk`.Clipboard.read_value_finish] to get the resulting GValue.

For local clipboard contents that are available in the given GType, the value will be copied directly. Otherwise, GDK will try to use [func`content_deserialize_async`] to convert the clipboard’s data.

read_value_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

a GValue containing the result.

Return type:

GObject.Value

Finishes an asynchronous clipboard read.

See [method`Gdk`.Clipboard.read_value_async].

set(value)[source]
Parameters:

value (GObject.Value) – a GValue to set

Sets the self to contain the given value.

set_content(provider)[source]
Parameters:

provider (Gdk.ContentProvider or None) – the new contents of self or None to clear the clipboard

Returns:

True if setting the clipboard succeeded

Return type:

bool

Sets a new content provider on self.

The clipboard will claim the GdkDisplay’s resources and advertise these new contents to other applications.

In the rare case of a failure, this function will return False. The clipboard will then continue reporting its old contents and ignore provider.

If the contents are read by either an external application or the self's read functions, self will select the best format to transfer the contents and then request that format from provider.

store_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously instructs the self to store its contents remotely.

If the clipboard is not local, this function does nothing but report success.

The callback must call [method`Gdk`.Clipboard.store_finish].

The purpose of this call is to preserve clipboard contents beyond the lifetime of an application, so this function is typically called on exit. Depending on the platform, the functionality may not be available unless a “clipboard manager” is running.

This function is called automatically when a GtkApplication is shut down, so you likely don’t need to call it.

store_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a GAsyncResult

Raises:

GLib.Error

Returns:

True if storing was successful.

Return type:

bool

Finishes an asynchronous clipboard store.

See [method`Gdk`.Clipboard.store_async].

Signal Details

Gdk.Clipboard.signals.changed(clipboard)
Signal Name:

changed

Flags:

RUN_LAST

Parameters:

clipboard (Gdk.Clipboard) – The object which received the signal

Emitted when the clipboard changes ownership.

Property Details

Gdk.Clipboard.props.content
Name:

content

Type:

Gdk.ContentProvider

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

The GdkContentProvider or None if the clipboard is empty or contents are provided otherwise.

Gdk.Clipboard.props.display
Name:

display

Type:

Gdk.Display

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY, EXPLICIT_NOTIFY

The GdkDisplay that the clipboard belongs to.

Gdk.Clipboard.props.formats
Name:

formats

Type:

Gdk.ContentFormats

Default Value:

None

Flags:

READABLE, EXPLICIT_NOTIFY

The possible formats that the clipboard can provide its data in.

Gdk.Clipboard.props.local
Name:

local

Type:

bool

Default Value:

True

Flags:

READABLE, EXPLICIT_NOTIFY

True if the contents of the clipboard are owned by this process.