dbus-python の proxy method? を拡張したい??
タイトル、あってるかな???
Python (というかプログラミング全般)の知識が、遅延学習に次ぐ遅延学習で…
ホントに基礎だけでもおさえておかないと厳しいかも
本題
Tomboy をハードに使っていまして、操作は dbus-python を使ったオレオレツールで行っています。
dbus-python + Tomboy の基本操作はこんな感じです。
>>> import dbus >>> bus = dbus.SessionBus() >>> obj = bus.get_object('org.gnome.Tomboy', '/org/gnome/Tomboy/RemoteControl') >>> tomboy = dbus.Interface(obj, 'org.gnome.Tomboy.RemoteControl') >>> >>> tomboy.SearchNotes(u'ほげ', True) dbus.Array([dbus.String(u'note://tomboy/****')], signature=dbus.Signature('s'))
んで、メソッドも充実しているのですが…
よく使う項をまとめて GetNoteURI なるメソッドを追加しようと思い立ったのです(`・ω・´)
よく理解出来ていないけれど __new__ を使って
class dbusTomboy(object): def __new__(self): bus = dbus.SessionBus() obj = bus.get_object('org.gnome.Tomboy', '/org/gnome/Tomboy/RemoteControl') return dbus.Interface(obj, 'org.gnome.Tomboy.RemoteControl') def GetNoteURI(self, NoteTitle): """ ... (略) ... """ pass
しかし、
>>> tomboy = dbusTomboy()
>>> tomboy.GetNoteURI(u'ほげ')
とすると
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "GetNoteURI" with signature "s" on interface "org.gnome.Tomboy.RemoteControl" doesn't exist
と怒られるorz
>>> type(tomboy.SerchNotes) <type 'instance'> >>> print tomboy.SerchNotes.__doc__ A proxy method which will only get called once we have its introspection reply. >>> dir(tomboy) ['__class__', '__dbus_object_path__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_dbus_interface', '_obj', 'bus_name', 'connect_to_signal', 'dbus_interface', 'get_dbus_method', 'object_path', 'proxy_object', 'requested_bus_name']
むむむ
ちょっと単純に考えてたなー。擬似拡張でいいから tomboy.GetNoteURI() を使えるようにしたい。
しかし、何を学べばいいのか分からない(((( ;゚д゚))))