I don't know specifically how using QVariant could change the behavior: I'm
always using sip api version 2 also with Python 2 and Qt4 for everything,
as I find it's much more simpler and usable since it automatically converts
python types without using .toPyObject(). Note that, by using sip v2 for
everything, QtCore will not wrap QVariant nor QString/QStringList (the
latter is the default for Py3). You can specify the C++ signature type
using quotes, though, such as pyqtSignal(['QString', 'QVariant']), which
can be useful where you don't have full control over the slots, like in
designer plugins.
That said, as you might know, "object" is a much broader specification for
the object type, meaning that it includes any kind of new-style python
subclass ("object", indeed), including any PyQt wrapper. It can be useful
when you want to emit signals using complex parameters (such as object
references), but, in your case, QVariant should be enough.
Maurizio
2018-09-06 9:29 GMT+02:00 J Barchan <jnbarchan at gmail.com>:
>>> On 5 September 2018 at 18:38, Maurizio Berti <maurizio.berti at gmail.com>
> wrote:
>>> First of all, if anyone here has access to the documentation pages of
>> PyQt, please read this (expecially the third point).
>>>>>> I do not know your exact user case, so it's hard to give you specific
>> suggestions, but here's what I'd do.
>>>> 1. do not give any signature to the signal at all:
>>>> notifyProgress = QtCore.pyqtSignal(object, object)
>>>> This allows you to use None for both arguments, but I'm not familiar with
>> typing in methods for python 3 (to be fair, I didn't even know about it
>> until yesterday, as I mainly use Python2). I did a quick test and it seems
>> to work fine, though.
>>>> 2. use a single parameter that will be sent as a tuple, and unpack it
>> within the method:
>>>> notifyProgress = QtCore.pyqtSignal(object)
>> def updateProgress(self, *args):
>> val, text = args
>>>> [...]
>>>> self.notifyProgress.emit((None, "Some text"))
>> self.notifyProgress.emit((i / 2, None))
>>>> 3. use an overloaded signal and two separate slots. This is something I
>> was struggling for a lot of time and (thanks to you! :-D) I finally found
>> out how it works, as it is *not* explained exhaustively in the
>> documentation. Also, I think that's what you were referring to.
>> As we know, signals can be connected "in two ways" (I'm referring to
>> new-style connections). Normally, you can go by simply connecting the slot
>> and eventually decorating that slot with the signature you are interested
>> in; decoration is usually not strictly required, as slot that are
>> processing invalid data are somewhat "ignored": I always thought it as some
>> kind of try/except mechanism, if at some point within the method something
>> wrong happens, the error is ignored but no exception is thrown; of course,
>> using a decorated slot avoids unnecessary computation for wrong signature
>> arguments.
>> Sometimes, though, it's better if not necessary to connect the slot to
>> the specific signature: self.somesignal[signature].connect(slot).
>> What the documentation forgets to explain is that the same _has_ to be
>> done when emitting custom overloaded signals if you are not using the
>> default signature (the first argument).
>>>> #in this case, "str" is the default signature
>> notifyProgress = QtCore.pyqtSignal([str], [int])
>>>> [...]
>> #the default signature can be omitted
>> self.notifyProgress.connect(self.updateProgressString)
>> self.notifyProgress[int].connect(self.updateProgressInt)
>> [...]
>>>> @QtCore.pyqtSlot(str)
>> def updateProgressString(self, text):
>> [...]
>>>> @QtCore.pyqtSlot(int)
>> def updateProgressInt(self, val):
>> [...]
>>>> [...]
>>>> #again, the default signature can be omitted
>> self.notifyProgress.emit("Some text")
>> #now, *THIS*!
>> self.notifyProgress[int].emit(5)
>>>> I really think that this is something the documentation should *not*
>> miss. I understand that from the C++ point of view it's pretty obvious that
>> a signal is emitted according to its argument type signature, but this is
>> not that obvious for a common Python programmer.
>>>> Obviously, in the last case there's a small drawback: you can't pass None
>> as argument, as it will be converted to the typed signature, giving you an
>> empty string or that infamous random 32bit integer. I don't think it would
>> be an issue in your case, but it is something to keep in mind anyway.
>>>>>> I hope this helps... it helped me :-)
>>>> Maurizio
>>>> 2018-09-05 12:33 GMT+02:00 J Barchan <jnbarchan at gmail.com>:
>>>>>>>>>>> On 5 September 2018 at 09:11, J Barchan <jnbarchan at gmail.com> wrote:
>>>>>>>>>>>>>>> On 4 September 2018 at 18:08, Maurizio Berti <maurizio.berti at gmail.com>
>>>> wrote:
>>>>>>>>> You are defining a specific signature in the signal:
>>>>>>>>>> QtCore.pyqtSignal(int, str)
>>>>>>>>>> this means that, despite the types you set in the method (which Qt
>>>>> doesn't know anything of also, as you didn't use the Slot decorator),
>>>>> whenever you emit a None (which is a NoneType, not int, nor str) Qt will
>>>>> try to "translate" it to the valid signature you assigned.
>>>>>>>>>> I don't know exactly why the int is that a high number (always high
>>>>> and always random), but this probably makes sense for some C++ type
>>>>> signature, as it seems to me that the number is always 32bit long and, in
>>>>> my case, always negative.
>>>>>>>>>> Anyway, if you really need to send None, you can use the generic
>>>>> "object" signature in the signal definition, or, in your case, just go with
>>>>> this, assuming the progress will never use negative numbers.
>>>>>>>>>> def updateProgress(self, val: int=-1, text: str=''):
>>>>> if val is >= 0:
>>>>> self.progressBar.pb.setValue(val)
>>>>> if text:
>>>>> self.progressBar.label.setText(text)
>>>>>>>>>> and then emit the text signal using -1 for val.
>>>>>>>>>> Maurizio
>>>>>>>>>>>>>>> 2018-09-04 18:16 GMT+02:00 J Barchan <jnbarchan at gmail.com>:
>>>>>>>>>>> PyQt5.7. I am having trouble `emit()`ing a signal and receiving its
>>>>>> arguments correctly. I have read http://pyqt.sourceforge.net/Do
>>>>>> cs/PyQt5/signals_slots.html carefully.
>>>>>>>>>>>> *Declaration*:
>>>>>>>>>>>> # class variable for "notifyProgress" signal, for displaying a
>>>>>> progressbar
>>>>>> notifyProgress = QtCore.pyqtSignal(int, str)
>>>>>>>>>>>> *Initialisation*:
>>>>>>>>>>>> self.notifyProgress.connect(self.updateProgress)
>>>>>>>>>>>> *Slot*:
>>>>>>>>>>>> def updateProgress(self, val: int, text: str):
>>>>>> # slot for self.notifyProgress
>>>>>> # eprpayrequestfunctions.runEpr() calls this to indicate
>>>>>> progress
>>>>>> # if it passes an integer it's the desired value for the
>>>>>> progressbar
>>>>>> # if it passes a string it's the desired value for the label
>>>>>> if val is not None:
>>>>>> self.progressBar.pb.setValue(val)
>>>>>> if text is not None:
>>>>>> self.progressBar.label.setText(text)
>>>>>>>>>>>> *Signals*:
>>>>>>>>>>>> 1. notifyProgress.emit(None, "Some text")
>>>>>>>>>>>> 2. notifyProgress.emit(i / 2, None)
>>>>>>>>>>>> *Behaviour in slot*:
>>>>>>>>>>>> The problem is the passing of None from emit():
>>>>>>>>>>>> 1. val arrives in slot as 1261196128.
>>>>>>>>>>>> 2. text arrives in slot as '' (empty string).
>>>>>>>>>>>> *Questions*:
>>>>>>>>>>>> - Where is this behaviour for None as an emit() parameter
>>>>>> documented?
>>>>>> - What is the correct/best way for handling this correctly/easily?
>>>>>>>>>>>>>>>>>> --
>>>>>> Kindest,
>>>>>> Jonathan
>>>>>>>>>>>> _______________________________________________
>>>>>> PyQt mailing list PyQt at riverbankcomputing.com>>>>>>/mailman/listinfo/pyqt>>>>>>>>>>>>>>>>>>>>>>>>>> --
>>>>> 脠 difficile avere una convinzione precisa quando si parla delle
>>>>> ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi
>>>>> http://www.jidesk.net
>>>>>>>>>>>>> I'm OK with the val: int=-1, but not with the text: str=''. An int of
>>>> -1 is happily an invalid value for me, butt the trouble is a str of ''
>>>> is perfectly legal, and will be used :(
>>>>>>>> (which Qt doesn't know anything of also, as you didn't use the Slot
>>>>> decorator),
>>>>>>>>>>>>> I don't mind adding a slot decorator if that would help. But
>>>> presumably it would not here, as you're saying my None value does not
>>>> match the type correctly anyway, right?
>>>>>>>> I did consider making it so there is only one parameter, and the type (
>>>> int or str) indicates which of the two paths to follow in the slot. I
>>>> followed http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html
>>>> carefully where it describes"The following code demonstrates the connection
>>>> of overloaded signals:" but I couldn't get it to work: it *always*
>>>> called the first/default overload, regardless of the parameter type ... :(
>>>>>>>> I'm now thinking: could I cut my losses and pass (and receive?) a
>>>> single parameter as an explicit QVariant (which we don't usually use
>>>> from PyQt), so that a single receiver slot can correctly see the original
>>>> type --- would that work/be advisable?
>>>>>>>>>>>> --
>>>> Kindest,
>>>> Jonathan
>>>>>>>>>> OK, I gave QVariant (single parameter) a try. *All* I had to was:
>>>>>> 1. Declare signal as:
>>>>>> QtCore.pyqtSignal(QVariant)
>>>>>> 2. Write slot like:
>>>>>> def updateProgress(self, val):
>>> if type(val) is int or type(val) is float:
>>> self.progressBar.pb.setValue(val)
>>> elif type(val) is str:
>>> self.progressBar.label.setText(val)
>>>>>> 3. And then it works correctly with both emitter types (without caller
>>> bothering with QVariant), like:
>>>>>> notifyProgress.emit(50)
>>> notifyProgress.emit("Finishing...")
>>>>>> Is there any reason I should *not* be doing this, because it seems
>>> perfect to me?
>>>>>>>>>>>> --
>>> Kindest,
>>> Jonathan
>>>>>>>>>>> --
>> 脠 difficile avere una convinzione precisa quando si parla delle ragioni
>> del cuore. - "Sostiene Pereira", Antonio Tabucchi
>> http://www.jidesk.net
>>>> Hi Maurizio,
>> First, thank you for your time on this matter.
>> I think the bit you identified which I would not have tried is the
> (non-documented) need to invoke the non-default overload via
> #now, *THIS*!
> self.notifyProgress[int].emit(5)
> But I would still welcome your comment on my last post? There I said I
> have solved the whole thing very simply, just by using
>> QtCore.pyqtSignal(QVariant)
>> as my signal declaration. To be clear: although I originally asked for
> two separate parameters or overloads for the string versus the int, in my
> case I am quite content with one at a time (calling code tends *either*
> to pass the int *or* the string, it doesn't need both in one call).
>> My problem then was the type for the parameter, to cater for either str or
> int. I chose QVariant, and it works fine for me. Your suggestion seems
> to be object (I don't know what that maps to in C++). Do you think it
> makes any difference if I stick with my choice?
>> Thanks.
>> --
> Kindest,
> Jonathan
>
--
脠 difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/pyqt/attachments/20180906/df6a411d/attachment-0001.html>
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 0018fsmingjiang.com.cn www.mwtv.org.cn daiy2.com.cn serverparts.com.cn www.delongds.com.cn ningque.com.cn yltit.com.cn njw.net.cn wnbus.com.cn www.xsbntime.com.cn