Read DBusActionGroup immediatly after creating it

Hi all:

I’m using a Gio.DBusActionGroup() to read some data from a program into another every time it changed (by using the ‘action-state-changed’ signal). The problem is that I also need to get the initial values, but when I do that just after having created the Gio.DBusActionGroup() it returns NULL. I have to use a GLib.timeout_add() to wait a little bit and only then do the read, which is quite ugly.

The documentation says to use DBusActionGroup.list_actions() first, but it returns an empty string if done immediately after creating the DBusActionGroup(); but if I wait with the GLib.timeout_add(), then it does return the right value.

Is there a way of adding a callback to know when the DBusActionGroup() is ready?

EDIT: I also tried to create the DBusActionGroup in the ‘startup’ phase of the Gtk.Application() and try to read the data in the ‘activate’ phase, but with no luck.

Thanks.

You should connect your signals (eg. action-added, action-state-changed) and then call Gio.ActionGroup.list_actions() and ignore the result.

When Gio.DBusActionGroup's call to org.gtk.Actions.DescribeAll returns it will start emitting signals and you will know the interface is ready.

I already do that. The point is that I want to read the “initial value” too, not only the changes (because this will change sometimes, not continually), and there is the problem: it doesn’t matter if I have previously called list_actions() or not, calling get_action_state() without a delay returns NULL.

If you want to do that, you’ll just have to make a synchronous call to the DBus interface yourself.

The initialization of Gio.DBusActionGroup is asynchronous, so if you don’t want to wait for the initial action-added signal to be emitted you’ll just have to make a blocking call to eg. org.gtk.Actions.Describe for the GAction that you want.

1 Like

Oh! Now I understand! It is ‘action-added’ the signal that I need! You mean that it is what notifies when an action is available and I can read it!

Thanks!!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.