<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:'times new roman', 'new york', times, serif;font-size:12pt"><div>Adam and Phil, thanks for your time. I think I almost understand--but, I still have some confusion.</div><div><br></div><div>Adam, if I follow your suggestion, then parents must really know their children well in order for signalling to work. Which can be the case sometimes. But, what I would like is:</div><div><br></div><div>B generates a custom event (rather than a signal). Upon that event, C can take an action. I think it would be cleaner if neither B nor C required the mediation of A. Why do this? Suppose A has 15 distinct children that need to be triggered upon a signal from B? Or, suppose the heirarchy changes so that instead we have:</div><div><br></div><div><br></div><div>
A</div><div> / \</div><div> B D</div><div> / \</div><div> C E</div><div> \</div><div> F</div><div>Now, if a method in C still needs to be triggered based on something that happens in B, then code in A has to be rewritten, along with new code added to D.
Suppose that I create a new window F that also needs to be triggered by something in B? </div><div><br></div><div>Whereas the essential relationship (communication wise) is still fundamentally between B and C. </div><div>So, it sounds like the signal slot pattern is not the way I want to go, because unless I directly connect B and C then the communication pathway is fragile. </div><div><br></div><div>But, if I generate an EVENT (sorry for the language sloppiness earlier) B, it will go up to A and disappear, unless I propagate it down to the leaves (which could be dangerous). So, the question is, whether or not there's a common bus/dispatcher in which B can put some information and whoever wants to be triggered by it, can?</div><div><br></div><div><br></div><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><br><div style="font-family:arial, helvetica, sans-serif;font-size:13px"><font size="2"
face="Tahoma"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Adam W. <awasilenko@gmail.com><br><b><span style="font-weight: bold;">Cc:</span></b> pyqt@riverbankcomputing.com<br><b><span style="font-weight: bold;">Sent:</span></b> Friday, September 4, 2009 7:53:17 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [PyQt] A simple question about signals and slots<br></font><br>
I keep forgetting to CC the newsgroup...<br><br>Anyway, I think you're still melting the two terms together.<br><br>> what I'm asking is if there's a mechanism in pyqt to emit an event in B<br><br>What you want to do is connect the signal from B to slot C, and signal<br>C to slot B in the namespace of A, not in the namespace of B and C.<br>This is the way its done in all the examples in Summerfield's book.<br>The only event you need to worry about is if there is no signal for<br>move (which I don't think there is), then you need to use an event<br>handler to make your own signal.<br><br>> which can be detected in C....<br><br>Signals are not "detected". After you connect a signal to a slot, and<br>said signal is emitted, the slot immediately gets called. There is no<br>listening needed.<br><br>I hope that makes some sort of sense. If not I can try to rephrase it.<br><br>- Adam<br><br>On Fri, Sep 4, 2009 at 7:32 PM, William<<a
ymailto="mailto:abecedarian314159@yahoo.com" href="mailto:abecedarian314159@yahoo.com">abecedarian314159@yahoo.com</a>> wrote:<br>> You are correct, what I want is an event. For example, the user does an<br>> action in one window (for example, moving a rectangle around) and when they<br>> are done, it emits an event<br>> (for example,<br>> self.emit(SIGNAL("rectangleMoved"),'moved')<br>> )<br>> , which another window can listen for and when it detects the event, can act<br>> (for example, update a plot). I can do this if the window is higher in the<br>> heirarchy for example if window A in my diagram acts upon an event generated<br>> by B, what I don't know is a clean way for C to receive events generated by<br>> A. I could directly connect things in B and C, but tight coupling seems<br>> likely to lead to less maintainable code. I could let the event pass up to<br>> A and then have
A connect down to C, but having "god" classes also seems<br>> like a step away from the road to maintainability. So, what I'm asking is<br>> if there's a mechanism in pyqt to emit an event in B, which can be detected<br>> in C....<br>> Thanks,<br>> William<br>> ________________________________<br>> From: Adam W. <<a ymailto="mailto:awasilenko@gmail.com" href="mailto:awasilenko@gmail.com">awasilenko@gmail.com</a>><br>> To: William <<a ymailto="mailto:abecedarian314159@yahoo.com" href="mailto:abecedarian314159@yahoo.com">abecedarian314159@yahoo.com</a>><br>> Sent: Friday, September 4, 2009 7:17:35 PM<br>> Subject: Re: [PyQt] A simple question about signals and slots<br>><br>> If B and C are under the same namespace as A, you can connect Signals<br>> with one of these:<br>> s.connect(w, SIGNAL("signalSignature"), functionName)<br>> s.connect(w, SIGNAL("signalSignature"),
instance.methodName)<br>> s.connect(w, SIGNAL("signalSignature"), instance, SLOT("slotSignature"))<br>> where s and w are QObjects with s usually being self (in your example<br>> the A object), and w the object whose signal you want to connect.<br>><br>> But I think you're confusing the signals and slots with events and<br>> event handlers.<br>><br>> Paraphrasing from Mark Summerfield's book: Qt has two communication<br>> mechanisms: a low-level event-handling mechanism which is similar to<br>> those provided by all other GUI libraries, and a high-level mechanism<br>> which Trolltech have coined "signals and slots". Every QObject<br>> supports some predefined signals/slots. You can create your own<br>> signals and slots too. If you need an even that is not available as a<br>> signal, like capturing a keypress, then you need to use events.<br>><br>> If a signal is not connected to a slot
of function, thats the end of<br>> the road for it. However its unhandled events that climb the parent<br>> latter till it eventually hits top window and is discarded.<br>><br>> Hope that helps,<br>> - Adam<br>><br>> On Fri, Sep 4, 2009 at 6:38 PM, William<<a ymailto="mailto:abecedarian314159@yahoo.com" href="mailto:abecedarian314159@yahoo.com">abecedarian314159@yahoo.com</a>> wrote:<br>>> Hi! I have what I hope is a simple question about signals and slots. As<br>>> I<br>>> understand it,<br>>> if events aren't acted upon, then they propogate upwards. But suppose you<br>>> have something like this:<br>>> A<br>>> / \<br>>> B C<br>>><br>>> Where B and C are children of A. How does B send a signal to C? I'd like<br>>> to keep B and C decoupled<br>>> (for example, B and C
could be dockwidgets, or even other main windows).<br>>> Is there something like <a target="_blank" href="http://wx.py">wx.py</a>.dispatcher?<br>>><br>>> Thanks,<br>>> William<br>>><br>>> _______________________________________________<br>>> PyQt mailing list <a ymailto="mailto:PyQt@riverbankcomputing.com" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br><span>>> <a target="_blank" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></span><br>>><br>><br>><br><br>_______________________________________________<br>PyQt mailing list <a ymailto="mailto:PyQt@riverbankcomputing.com" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br><a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt"
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></div></div><div style="position:fixed"></div></div><br>
</body></html>