7 # -------------------------------------------------------------------------
8 class _PyGObject_Functions(ctypes.Structure):
9 """GObject <-> Python mapping from http://faq.pygtk.org/index.py?req=show&file=faq23.041.htp"""
12 ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p,
13 ctypes.c_int, ctypes.py_object,
16 ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.py_object)),
18 ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_void_p)),
20 ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_int)),
22 ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_void_p)),
26 # -------------------------------------------------------------------------
27 class PyGObjectCAPI(object):
28 """GObject <-> Python mapping from http://faq.pygtk.org/index.py?req=show&file=faq23.041.htp"""
31 addr = ctypes.pythonapi.PyCObject_AsVoidPtr(
32 ctypes.py_object(gobject._PyGObject_API))
33 self._api = _PyGObject_Functions.from_address(addr)
35 def pygobject_new(self, addr):
36 return self._api.newgobj(addr)
39 # -------------------------------------------------------------------------
40 class GList(Structure):
41 """GList representation and convenience functions, based on Java's Iterable.
43 Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
44 Released under the Artistic Licence."""
47 # -----------------------------------------------------------------------
49 def new(clazz, ptr = None):
50 """Return a reference to an empty, or valid, GList at the
51 given pointer address."""
54 return cast(c_void_p(ptr), POINTER(GList)).contents
59 # -----------------------------------------------------------------------
60 _fields_ = [('_data', c_void_p),
64 _ptr = None # Initialises to before the list for `while(has_next)...'
67 # -----------------------------------------------------------------------
69 """Rewind the iterable to the start of the list."""
73 # -----------------------------------------------------------------------
75 """Return True if the list has an item on which next can be called."""
77 return (not self._ptr and self._data) or (self._ptr and self._ptr._next)
80 # -----------------------------------------------------------------------
81 def next(self, as_a = None):
82 """Move the pointer on to the next item in the list and return its value, or
83 raise an exception if already on the last."""
85 if self._ptr and not self._ptr._next:
86 raise Exception("IndexOutOfBounds")
88 self._ptr = self._ptr and cast(self._ptr._next, POINTER(GList)).contents or self
89 if not self._ptr._data:
92 return cast(self._ptr._data, POINTER(as_a)).contents
94 return self._ptr._data
97 # -----------------------------------------------------------------------
99 """Set the data in the current position in the list."""
104 self._ptr._data = cast(value, c_void_p);
108 # -----------------------------------------------------------------------
110 """Add a new entry on to the end of the list, ready to be "set"."""
113 while self.has_next():
120 new._prev = addressof(self._ptr)
121 self._ptr._next = addressof(new)
125 # -------------------------------------------------------------------------
126 class EContactPhoto_inlined(Structure):
127 _fields_ = [('mime_type', c_char_p),
131 class EContactPhoto_data(Union):
132 _fields_ = [('inlined', EContactPhoto_inlined),
135 class EContactPhoto(Structure):
136 _fields_ = [('type', c_int),
137 ('data', EContactPhoto_data)]
139 class EContactDate(Structure):
140 _fields_ = [('year', c_uint),
144 # -------------------------------------------------------------------------
145 class EVCardAttribute(Structure):
146 _fields_ = [('group', c_char_p),
148 ('params', POINTER(GList)),
149 ('values', POINTER(GList)),]
155 return self.values.contents