Autore Topic: gb.dbus e signal  (Letto 250 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
gb.dbus e signal
« il: 26 Giugno 2015, 15:54:01 »
Riporto questo messaggio di Minisini:


" 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<-------------------------------------------------------------------


Codice: gambas [Seleziona]
' 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
"
« Ultima modifica: 26 Giugno 2015, 15:57:18 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »