나는 상위 클래스를 확장 상위 클래스와 클래스를 가지고 있지만, 자식 클래스의 거의 모든 방법은 (재 구현하지 않고 상속을 사용하여) 최고 수준에서, 그래서 자식 클래스의 메소드가없는, 어떻게 각 하위 클래스 (dbus 경로의 일부로 각 하위 클래스의 이름 포함)에 대해 dbus로 내보낼 수 있습니까?확장 클래스에서 dbus를 사용하여 내보내는 방법은 Python에서 상속 된 메서드입니까?
Window (main class)
|--WindowOne (child class)
|--WindowTwo
|--WindowThree
DBUS에 대한 나의 인터페이스는 com.example.MyInterface
내가 사용하여 각 자식 클래스 접근하고 싶습니다 : 명확히하기 위해
나는 예제 코드를 표시합니다, 내 수업 구조는 com.example.MyInterface.WindowOne
를하고, 각 하위 클래스 I에 대한 com.example.MyInterface.WindowOne.show
및 com.example.MyInterface.WindowOne.destroy
과 같은 기본 클래스의 상속 된 메서드를 비롯하여 메서드에 액세스하려고합니다. 이 코드에서
show()
및
destroy()
가 'WindowOne'에서 다시 구현되지는 '창'클래스와 자식 클래스의 WindowOne '를 확장하지만,이 코드에서 나는를 넣어 방법
show()
문제를 설명하기 위해, 나는 일에 코드를 얻는 방법이 있었다, 나는 다시 선언 자식 클래스의 방법
show()
을하지만,이 나쁜 것 같다.
큰 문제는 아마도입니다 : @dbus.service.method('com.example.MyInterface.WindowOne')
클래스 (자식 클래스이 경우) : 데코레이터를 사용하는 몇 가지 방법이있다?
테스트 소스 코드 : 일부 실험 후
# 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()
나는 장식과 DBUS 너무 잘 모르겠지만, 왜 당신은'__init__' 기능을 장식과에 공급되는'name'을 사용하지 않는? – deinonychusaur
은 아마 당신이 무엇을 의미하는지 이해하지 않는,하지만 난에 __init__''에 줄을 변경하려고 '. com.example.MyInterface''self.busName = dbus.service.BusName (+ self.name, 버스 = dbus.SessionBus())',이 버스는 이름 버스를 바꾼다. 내 보낸 메소드는 com.example.MyInterface.WindowOne와 같은 완전한 이름을 가진 적절한 데코레이터를 가질 필요가있다. self.name은 내부에서 작동하지 않는다. 데코레이터 : ( – Msum
나는 전에 깨닫지 못했던 또 다른 문제 인 com.example.MyInterface를 알아 냈습니다.WindowOne'은이 클래스의 한 객체가 인스턴스화 된 경우에만 사용할 수 있습니다. 그러나이 작업은 기본 창에서 발생하기 때문에 다른 창은 여전히 dbus에서 사용할 수 없습니다. 나는 더 나은 해결책으로 생각할 것이다. 어떤 도움이라도 환영받을 것이다. 감사. – Msum