I have a top class and classes that extend the top class, but almost all methods from the child classes are from the top class (using inheritance, without reimplementation), so I don't have the methods in the child classes, how could I export them with dbus for each child class (with the name of each child class as part of dbus path)?
I will show a example code for clarify, my class structure is:
Window (main class)
|--WindowOne (child class)
|--WindowTwo
|--WindowThree
My interface for dbus is com.example.MyInterface
and I would like to access each child class using: com.example.MyInterface.WindowOne
, and for each child class I would like to access the methods, inclusive the inherited methods from the main class, like com.example.MyInterface.WindowOne.show
and com.example.MyInterface.WindowOne.destroy
.
In this code, I extend the child class 'WindowOne' with the 'Window' class, the methods show()
and destroy()
in the 'Window' are not re-implemented in 'WindowOne', but in this code I put the method show()
to explain the problem, the way I get the code to work was this, I re-declare the method show()
in child class, but this seems bad.
The big question maybe is: There is some way to use the decorator: @dbus.service.method('com.example.MyInterface.WindowOne')
for classes (child classes in this case)?
The test source code:
# interface imports
from gi.repository import Gtk
# dbus imports
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
# Main window class
class Window(dbus.service.Object):
def __init__(self, gladeFilePath, name):
# ... inicialization
self.name = name
self.busName = dbus.service.BusName('com.example.MyInterface.', bus=dbus.SessionBus())
dbus.service.Object.__init__(self, self.busName, '/com/example/MyInterface/' + self.name)
def show(self):
self.window.show_all()
def destroy(self):
Gtk.main_quit()
# Child window class
class WindowOne(Window):
def __init__(self, gladeFilePath):
Window.__init__(self, gladeFilePath, "WindowOne")
@dbus.service.method('com.example.MyInterface.WindowOne')
def show(self):
self.window.show_all()
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
gladeFilePath = "/etc/interface.glade"
windowOne = WindowOne(gladeFilePath)
Gtk.main()