Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:57:08+00:00 2026-05-27T22:57:08+00:00

Sometimes I need to call a gtk/gobject function that only exists in C, but

  • 0

Sometimes I need to call a gtk/gobject function that only exists in C, but returns an object that has a python wrapper. Previously I used a solution based on ctypes that worked well:

http://faq.pygtk.org/index.py?req=show&file=faq23.041.htp

Now that I swiched from PyGtk (“import gtk”) to GObject-introspection (“from gi.repository import Gtk”), what can I use instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:57:08+00:00Added an answer on May 27, 2026 at 10:57 pm

    The _PyGObject_API interface has changed at some point. I needed to drop the register_sinkfunc function. The following works:

    from gi.repository import Gio, GLib
    import gi
    import ctypes
    
    class _PyGObject_Functions(ctypes.Structure):
       _fields_ = [
           ('register_class',
            ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p,
                              ctypes.c_int, ctypes.py_object,
                              ctypes.py_object)),
           ('register_wrapper',
            ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.py_object)),
           ('lookup_class',
            ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_int)),
           ('newgobj',
            ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_void_p)),
           ]
    
    class PyGObjectCPAI(object):
       def __init__(self):
           PyCObject_AsVoidPtr = ctypes.pythonapi.PyCObject_AsVoidPtr
           PyCObject_AsVoidPtr.restype = ctypes.c_void_p
           PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
           addr = PyCObject_AsVoidPtr(ctypes.py_object(
               gi._gobject._PyGObject_API))
           self._api = _PyGObject_Functions.from_address(addr)
    
       def pygobject_new(self, addr):
           return self._api.newgobj(addr)
    
    capi = PyGObjectCPAI()
    

    To get an object from a pointer:

    obj = capi.pygobject_new(pointer)
    

    to get a pointer from a (g)object:

    pointer = hash(obj)
    

    I have to add, in my case this didn’t help me solve my actual problem. I was trying to interface with dconf, but dconf returns values of type GVariant, which does not inherit from GObject. It seems PyGI/GObject unfortunately does not expose the neccessary functions to turn a C (*GVariant) into a Python GLib.Variant. I guess it’s of those times when you have to throw away your initial approach and try something different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call a library function that sometimes won't terminate within a given
For diagnostic purposes I sometimes need to store the call stack that lead to
Sometimes I need to provide a Context object to call specific functions, such as
I notice sometimes with my parent/child objects or many-to-many relationships, I need to call
I am using Entity Framework 4.1 and do sometimes need to call stored procedures.
Sometimes I have need to call namespace and class the same. For example, SomeProject.Compiler
Sometimes, you may need to call a 'login' url, passing in some sort of
I have an Entity. And sometimes I need this object also contains some value,
I've an UISlider on my app and I need sometimes to update not only
I have an object pool, and I need to call a delegate method OnFree(),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.