Usage of an GObject inout parameter in python
- From: David Boesner <david boesner gmail com>
- To: python-hackers-list gnome org
- Subject: Usage of an GObject inout parameter in python
- Date: Wed, 22 Apr 2015 10:01:04 +0200
Hi everyone,
I would like to know how to use an inout parameter, that is defined in an GObject method, in python.
The problem, that I am facing is, that python array, which I am passing to the GObject method is
not changed, even though @buffer is an inout paramter. Could anyone please tell me, if I misunderstood
the concept of inout parameters or give me an example, how I can use inout parameters in python?
buffer-manipulation.c/**
* buffer_manipulation_increment:
* @buffer: (inout) (array length=buffer_size) (element-type guint8): The buffer to increment
* @buffer_size: (inout): The size of the buffer
*
* Increment every element of the buffer by one
*/
void buffer_manipulation_increment(guint8** buffer, gsize* buffer_size) {
int i = 0;
for (i = 0; i < *buffer_size; i++)
(*buffer)[i]++;
for (i = 0; i < *buffer_size; i++)
printf("buffer %i %u \n", i , (*buffer)[i]);
}
buffer-manipulation.py#!/usr/bin/python
from gi.repository import Buffer
import numpy as np
b = Buffer.Manipulation()
print "# b.increment"
arr=np.array([1,2,3], int)
print arr
b.increment(arr)
print arr
Output:# b.increment
[1 2 3]
buffer 0 2
buffer 1 3
buffer 2 4
[1 2 3] <--------- NOT CHANGED
I added the files which I wrote as an attachment.
The bindings can be created by calling create-bindings.sh
run.sh sets the necessary variables and runs the
python script
Regards
David
Attachment:
buffer-manipulation.py
Description: Text Data
Attachment:
buffer-manipulation.c
Description: Text Data
Attachment:
create-bindings.sh
Description: Bourne shell script
Attachment:
buffer-manipulation.h
Description: Text Data
Attachment:
run.sh
Description: Bourne shell script
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]