> In theory you should be able to use QDBusArgument but I've not tested
> it - I've always struggled to find test cases.
Maybe the little server app appended below will help. Using dbus-send, I
can exercise the 'name' property and 'echo' method, as well as the
introspection interface:
# Call 'echo' method
dbus-send --print-reply --dest=com.example.dbus /com/example/dbus \
com.example.dbus.echo string:Hello
# Exercise introspection interface
dbus-send --print-reply --dest=com.example.dbus /com/example/dbus \
org.freedesktop.DBus.Introspectable.Introspect
# Get the 'name' property
dbus-send --print-reply --dest=com.example.dbus /com/example/dbus \
org.freedesktop.DBus.Properties.Get string:com.example.dbus string:name
# Set 'name'
dbus-send --print-reply --dest=com.example.dbus /com/example/dbus \
org.freedesktop.DBus.Properties.Set string:com.example.dbus \
string:name variant:string:MyNewName
# Call 'setPosition' method
dbus-send --print-reply --dest=com.example.dbus /com/example/dbus \
com.example.dbus.setPosition double:1.0 double:2.0 double:3.0
Unfortunately for me, attempts to call setPosition() result in:
Error org.freedesktop.DBus.Error.UnknownMethod: No such method
'setPosition' in interface 'com.example.dbus' at object path
'/com/example/dbus' (signature 'ddd')
I suppose this makes sense, but I was hoping there might be a
workaround. It would be really great to be able to write a PyQt-based
implementation of *any* D-Bus specification. That way, I could mock out
any arbitrary server's functionality for testing.
For now, it looks like structs aren't supported? I'd be willing to help
add that support if it seems doable, but I'm not sure where to start, or
what the effort level might be. (I can probably spend about 20 hours on
it without getting into too much trouble...)
----------
from PyQt4 import QtDBus
from PyQt4.QtCore import (QCoreApplication, QObject, Q_CLASSINFO, pyqtSlot,
pyqtProperty)
from PyQt4.QtDBus import QDBusArgument, QDBusConnection, QDBusAbstractAdaptor
class MyServer(QObject):
def __init__(self):
QObject.__init__(self)
self.__dbusAdaptor = ServerAdaptor(self)
self.__name = 'myname'
def echo(self, value):
return'Received: {0}'.format(value)
@property
def name(self):
return self.__name
@name.setter
def name(self, value):
self.__name = value
class ServerAdaptor(QDBusAbstractAdaptor):
Q_CLASSINFO("D-Bus Interface", "com.example.dbus")
Q_CLASSINFO("D-Bus Introspection",
' <interface name="com.example.dbus">\n'
' <property name="name" type="s" access="readwrite"/>\n'
' <method name="echo">\n'
' <arg direction="in" type="s" name="phrase"/>\n'
' <arg direction="out" type="s" name="echoed"/>\n'
' </method>\n'
' <method name="setPosition">\n'
' <arg direction="in" type="(ddd)" name="pos"/>\n'
' </method>\n'
' </interface>\n')
def __init__(self, parent):
super().__init__(parent)
@pyqtSlot(str, result=str)
def echo(self, phrase):
return self.parent().echo(phrase)
@pyqtSlot(QDBusArgument)
def setPosition(self, pos):
print("How can I call this function?")
@pyqtProperty(str)
def name(self):
return self.parent().name
@name.setter
def name(self, value):
self.parent().name = value
def start():
app = QCoreApplication([])
bus = QDBusConnection.sessionBus()
server = MyServer()
bus.registerObject('/com/example/dbus', server)
bus.registerService('com.example.dbus')
app.exec()
if __name__ == '__main__':
start()
On Mon, Aug 6, 2012 at 5:23 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Mon, 6 Aug 2012 13:59:08 -0400, Evade Flow <evadeflow at gmail.com> wrote:
>> On Mon, Aug 6, 2012 at 1:03 PM, Phil Thompson
>> <phil at riverbankcomputing.com> wrote:
>>> On Mon, 6 Aug 2012 12:49:21 -0400, Evade Flow <evadeflow at gmail.com>
>>> wrote:
>>>> On Mon, Aug 6, 2012 at 12:29 PM, Phil Thompson
>>>> <phil at riverbankcomputing.com> wrote:
>>>>> On Mon, 6 Aug 2012 12:15:44 -0400, Evade Flow <evadeflow at gmail.com>
>>>>> wrote:
>>>>>> I'm trying to write a PyQt4-based mock object for a C++ app exposed
>>> over
>>>>>> D-Bus with the following interface:
>>>>>>>>>>>> Q_CLASSINFO("D-Bus Interface", "com.acme.Audio.Control")
>>>>>> Q_CLASSINFO("D-Bus Introspection",
>>>>>> ' <interface name="com.acme.Audio.Control">\n'
>>>>>> ' <method name="echo">\n'
>>>>>> ' <arg direction="in" type="s" name="phrase"/>\n'
>>>>>> ' <arg direction="out" type="s" name="echoed"/>\n'
>>>>>> ' </method>\n'
>>>>>> ' <method name="setParams">\n'
>>>>>> ' <arg direction="out" type="(i)" name="error"/>\n'
>>>>>> ' <arg direction="in" type="a(iiiii)"
>>>>>> name="audioSourceParameter"/>\n'
>>>>>> ' <annotation value="QVector<AudioSourceParameters>"
>>>>>> name="com.trolltech.QtDBus.QtTypeName.In0"/>\n'
>>>>>> ' <annotation value="Errors::ErrorCode"
>>>>>> name="com.trolltech.QtDBus.QtTypeName.Out0"/>\n'
>>>>>> ' </method>\n'
>>>>>> ' </interface>\n')
>>>>>>>>>>>> It's unclear to me how how the setParams() function should be
>>> decorated.
>>>>>> For the echo() function, I have:
>>>>>>>>>>>> @pyqtSlot(str, result=str)
>>>>>> def echo(self, phrase):
>>>>>> return self.parent().echo(phrase)
>>>>>>>>>>>> But what should I put for setParams()? I was tempted to write:
>>>>>>>>>>>> @pyqtSlot('a(iiiii)', result='(i)')
>>>>>> def setParams(self, volume):
>>>>>> return self.parent().echo(phrase)
>>>>>>>>>>>> But this results in:
>>>>>>>>>>>> TypeError: C++ type 'a(iiiii)' is not supported as a pyqtSlot type
>>>>>> argument type
>>>>>>>>>>>> So... how does one expose a function to D-Bus that accepts an array
> of
>>>>>> structs, each containing 5 ints?
>>>>>>>>>> What would be the C++ signature? Try that as a string.
>>>>>>>>>> Phil
>>>>>>>> The C++ signature is:
>>>>>>>> void setParams(QList<AudioSourceParameters> audioSourceParameters,
>>>> Errors::ErrorCode &error);
>>>>>>>> where AudioSourceParameters is defined as:
>>>>>>>> struct AudioSourceParameters
>>>> {
>>>> int volume;
>>>> int balance;
>>>> int fader;
>>>> int fadein;
>>>> int fadeout;
>>>> };
>>>>>>>> The C++ code sets things up with:
>>>>>>>> Q_DECLARE_METATYPE(QList<AudioSourceParameters>);
>>>>>>>> and:
>>>>>>>> qDBusRegisterMetaType<AudioSourceParameters>();
>>>> qDBusRegisterMetaType<QList<AudioSourceParameters> >();
>>>>>>>> The introspection XML (presumably output by qdbuscpp2xml) shows this
> as
>>>> 'a(iiiii)'. That's what the client app (the one I'm trying to provide
> a
>>>> mock server for) is expecting to see.
>>>>>>>> Any ideas how to make this work with PyQt?
>>>>>> You probably can't using the QtDBus module because PyQt doesn't know
>>> anything about AudioSourceParameters.
>>>>>> You should be able to use the standard Python dbus module which will
>>> bypass the Qt conversions.
>>>>>> Phil
>>>> What clients expect is 'a(iiiii)', so the convenience type declared in
>> the C++ server I'm trying to mock out shouldn't matter for my purposes
>> (should it?)
>>>> It makes sense that PyQt wouldn't know anything about
>> 'AudioSourceParameters', but can it handle 'a(iiiii)'? Or are D-Bus
>> arrays and structs (and arrays-of-structs) not supported?
>>>> I've seen a few PyQt code examples that use QDBusArgument to marshal
>> arbitrary arguments, but I haven't seen any examples where complex
>> objects are demarshalled.
>>>> This seems fine:
>>>> @pyqtSlot('QList<int>')
>> def func(self, args):
>> pass
>> Because QList<int> is explicitly supported by PyQt.
>>> but this:
>>>> @pyqtSlot('QList<QList<int> >')
>> def func(self, args):
>> pass
>>>> results in:
>>>> File "fake_hifi_audio.py", line 44, in HifiAudioServerAdaptor
>> @pyqtSlot('QList<QList<int> >')
>> TypeError: C++ type 'QList<QList<int> >' is not supported as a
>> pyqtSlot type argument type
>> Because QList<QList<int> > isn't supported.
>>> If arrays of structs aren't supported, is there some way I can get the
>> thing that clients send as 'a(iiiii)' into a QDBusArgument variable and
>> demarshal it manually? PyQt's DBus bindings are *so* much better than
>> the standard python dbus module that I shudder at the thought of having
>> to go back to it... `:-}
>> In theory you should be able to use QDBusArgument but I've not tested it -
> I've always struggled to find test cases.
>> Phil
More information about the PyQt
mailing list
‘She has never mentioned her father to me. Was he—well, the sort of man whom the County Club would not have blackballed?’ "We walked by the side of our teams or behind the wagons, we slept on the ground at night, we did our own cooking, we washed our knives by sticking them into the ground rapidly a few times, and we washed our plates with sand and wisps of grass. When we stopped, we arranged our wagons in a circle, and thus formed a 'corral,' or yard, where we drove our oxen to yoke them up. And the corral was often very useful as a fort, or camp, for defending ourselves against the Indians. Do you see that little hollow down there?" he asked, pointing to a depression in the ground a short distance to the right of the train. "Well, in that hollow our wagon-train was kept three days and nights by the Indians. Three days and nights they stayed around, and made several attacks. Two of our men were killed and three were wounded by their arrows, and others had narrow escapes. One arrow hit me on the throat, but I was saved by the knot of my neckerchief, and the point only tore the skin a little. Since that time I have always had a fondness for large neckties. I don't know how many of the Indians we killed, as they carried off their dead and wounded, to save them from being scalped. Next to getting the scalps of their enemies, the most important thing with the Indians is to save their own. We had several fights during our journey, but that one was the worst. Once a little party of us were surrounded in a small 'wallow,' and had a tough time to defend ourselves successfully. Luckily for us, the Indians had no fire-arms then, and their bows and arrows were no match for our rifles. Nowadays they are well armed, but there are[Pg 41] not so many of them, and they are not inclined to trouble the railway trains. They used to do a great deal of mischief in the old times, and many a poor fellow has been killed by them." As dusk came on nearly the whole population of Maastricht, with all their temporary guests, formed an endless procession and went to invoke God's mercy by the Virgin Mary's intercession. They went to Our Lady's Church, in which stands the miraculous statue of Sancta Maria Stella Maris. The procession filled all the principal streets and squares of the town. I took my stand at the corner of the Vrijthof, where all marched past me, men, women, and children, all praying aloud, with loud voices beseeching: "Our Lady, Star of the Sea, pray for us ... pray for us ... pray for us ...!" It had not occurred to her for some hours after Mrs. Campbell had told her of Landor's death that she was free now to give herself to Cairness. She had gasped, indeed, when she did remember it, and had put the thought away, angrily and self-reproachfully. But it returned now, and she felt that she might cling to it. She had been grateful, and she had been faithful, too.[Pg 286] She remembered only that Landor had been kind to her, and forgot that for the last two years she had borne with much harsh coldness, and with a sort of contempt which she felt in her unanalyzing mind to have been entirely unmerited. Gradually she raised herself until she sat quite erect by the side of the mound, the old exultation of her half-wild girlhood shining in her face as she planned the future, which only a few minutes before had seemed so hopeless. After he had gloated over Sergeant Ramsey, Shorty got his men into the road ready to start. Si placed himself in front of the squad and deliberately loaded his musket in their sight. Shorty took his place in the rear, and gave out: The groups about each gun thinned out, as the shrieking fragments of shell mowed down man after man, but the rapidity of the fire did not slacken in the least. One of the Lieutenants turned and motioned with his saber to the riders seated on their horses in the line of limbers under the cover of the slope. One rider sprang from each team and ran up to take the place of men who had fallen. "As long as there's men and women in the world, the men 'ull be top and the women bottom." Then, in the house, the little girls were useful. Mrs. Backfield was not so energetic as she used to be. She had never been a robust woman, and though her husband's care had kept her well and strong, her frame was not equal to Reuben's demands; after fourteen years' hard labour, she suffered from rheumatism, which though seldom acute, was inclined to make her stiff and slow. It was here that Caro and Tilly came in, and Reuben began to appreciate his girls. After all, girls were needed in a house—and as for young men and marriage, their father could easily see that such follies did not spoil their usefulness or take them from him. Caro and Tilly helped their grandmother in all sorts of ways—they dusted, they watched pots, they shelled peas and peeled potatoes, they darned house-linen, they could even make a bed between them. HoME一级毛片视频免费公开
ENTER NUMBET 0018pxzxbz.com.cn www.b011.com.cn daiy77.com.cn xuelutong.com.cn falv315.com.cn wxiaov.com.cn cfnl432.com.cn opsstack.com.cn www.cnspring.net.cn hpbus.com.cn