[Gambas-user] gb.dbus and signals

Benoît Minisini gambas at ...1...
Fri Jun 26 13:35:37 CEST 2015


Hi,

In revision #7146 I have added to the gb.dbus component the ability to 
raise signals.

How does it work?

All events defined in your DBusObject become DBus signals.

The name of the event must be the name of the interface where all dots 
are replaced by underscore, followed by an underscore and the name of 
the signal. If the event is for the default interface, just the signal 
name is enough.

Don't forget to add the interface name when calling the Register() method.

To actually raise the signal on a specific bus, you don't use the RAISE 
instruction, but the DBus.Session.Raise() or the DBus.System.Raise() method.

That method takes 3 arguments :
- The DBus object.
- The signal name, which is the event name where "_" are replaced by ".".
- An optional array of signal arguments.

Signal arguments and event signature must match, otherwise I don't know 
what happens. :-)

A little dummy example:

--8<-------------------------------------------------------------------

' Gambas class file

Inherits DBusObject

Event org_freedesktop_StatusNotifierItem_IconChanged
Event org_freedesktop_StatusNotifierItem_NewStatus(sStatus As String)

Property Read org_freedesktop_StatusNotifierItem_Category As String

Public Sub org_freedesktop_StatusNotifierItem_Activate(X As Integer, Y 
As Integer)

End

Private Function org_freedesktop_StatusNotifierItem_Category_Read() As 
String

End

...

Public Sub Main()

   DBus.Session.Register(hObject, "/StatusNotifierItem", 
["org.freedesktop.StatusNotifierItem"])
   ' This is needed at the moment so that the current application is 
visible under different names
   DBus.Session._RequestName("org.freedesktop.StatusNotifierItem-" & 
CStr(Application.Handle) & "-1", True)

   DBus.Session.Raise(hObject, 
"org.freedesktop.StatusNotifierItem.IconChanged")
   DBus.Session.Raise(hObject, 
"org.freedesktop.StatusNotifierItem.NewStatus", ["Chuck!"])

   Wait 1

   DBus.Session.Unregister(hObject)

End

--8<-------------------------------------------------------------------

I'm currently creating a gb.form.statusicon component that will allow to 
use the new system tray protocol (but not the old one!)

Regards,

-- 
Benoît Minisini




More information about the User mailing list