GNOME Bugzilla – Bug 356011
gnome.ui.master_client() returns None.
Last modified: 2006-09-15 21:14:14 UTC
We're working on Orca, a Python based screen reader [1], which is in GNOME 2.16. We have a bug [2], where we want to be able to automatically log the user out, if we've just enabled the "accessibility" Gconf flag on the desktop. Gnopernicus (the previous GNOME screen reader written in C) did this with: ... if (response_id == GTK_RESPONSE_YES) { GnomeClient *client = gnome_master_client (); if (client) gnome_client_request_save (client, GNOME_SAVE_GLOBAL, TRUE, GNOME_INTERACT_ANY, FALSE, TRUE); return TRUE; } ... (See about line 572 in .../gnopernicus/gnopi/gnopi.c [3]) We've tried doing what we think is the Python equivalent of this: import gnome.ui ... client = gnome.ui.master_client() client.request_save(gnome.ui.SAVE_GLOBAL, # Save style True, # Shutdown gnome.ui.INTERACT_ANY, # Allow user interaction False, # Fast True) # All apps save state but could not get the master_client() method to return a non-null value. See comment #1 in bug #340849.
Created attachment 72812 [details] Standalone Python script that reproduces the problem. bug_340849.py is a small Python script that reproduces the problem we are seeing. To run this script, merely type 'python bug_340849.py' in a terminal window. To reproduce the problem we are seeing, follow these steps: 0. Make sure you have accessibility turned on: If it's not turned on, you will need to do: System->Preferences->Assistive Technology Preferences Tick the "Enable Assistive Technologies" checkbox Then click on Close. Then logout and log back in. 1. Run the attached standalone python application in a gnome-terminal window. 2. Press F11. This will call the getMasterClient() routine, that in turn will call: import gnome.ui client = gnome.ui.master_client() Notice that this returns None. 3. Press the F12 function key to terminate this script.
The Python wrapper is: static PyObject * _wrap_gnome_master_client(PyObject *self) { GnomeClient *ret; ret = gnome_master_client(); /* pygobject_new handles NULL checking */ return pygobject_new((GObject *)ret); } It has no apparent bug. Reassigning to libgnomeui. [ Possibly you are just mis-using the API. Could it be that you need to create a normal client and call client.connect_to_session_manager() first? ]
Do you (or the libgnome python wrapper) call gnome_program_init with a module list including GNOME_CLIENT_MODULE or LIBGNOMEUI_MODULE ?
In python, calling gnome.program_init() after importing gnome.ui at least once does that.
The testcase doesn't call this function, so there's no gnome client. -> INVALID
Okay, thanks for the pointers. I'm not doing the gnome.program.init() call, so you are right, this is NOTABUG or INVALID. Before you go away, I'd like to know what I should be doing exactly though. What change to I have to make to the small attached script to get this working? It'll be in the getMasterClient() routine, and will be something like: def getMasterClient(): print "getMasterClient called:" import gnome import gnome.ui gnome.program_init('orca', '1.0', LIBGNOMEUI_MODULE) client = gnome.ui.master_client() print "getMasterClient: client: ", client I tried that and got: Traceback (most recent call last):
+ Trace 72417
return self.callback(event)
getMasterClient()
gnome.program_init('orca', '1.0', LIBGNOMEUI_MODULE)
so what should 'LIBGNOMEUI_MODULE' really be? A secondary question, is where is the documentation for all these gnome python bindings? I'm really stumbling in the dark here. Thanks.
Never mind. I goggled and found an example: def getMasterClient(): print "getMasterClient called:" import gnome import gnome.ui program = gnome.init('orca', '1.0', gnome.libgnome_module_info_get(), sys.argv, []) print "program: ", program client = gnome.ui.master_client() print "getMasterClient: client: ", client
(In reply to comment #7) > program = gnome.init('orca', '1.0', gnome.libgnome_module_info_get(), > sys.argv, []) You could simplify this to > program = gnome.init('orca', '1.0') with the same effect.
Cool. Thanks!