Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'ignored': 0.07; '__init__': 0.09; 'filename': 0.09; 'filenames': 0.09; 'filenames:': 0.09; 'guys!': 0.09; 'label,': 0.09; 'skip:# 30': 0.09; 'thread': 0.14; '16.': 0.16; 'comments:': 0.16; 'dirnames,': 0.16; 'dirpath,': 0.16; 'self.root': 0.16; 'str)': 0.16; 'there?': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'header:User- Agent:1': 0.23; 'received:65.55.116': 0.24; 'text.': 0.24; 'looks': 0.24; 'class.': 0.26; 'this:': 0.26; 'updating': 0.26; 'meeting': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'sets': 0.30; "i'm": 0.30; 'work.': 0.31; 'code': 0.31; "skip:' 10": 0.31; 'dialog': 0.31; 'object.': 0.31; 'prints': 0.31; 'skip:q 20': 0.31; 'subject:some': 0.31; 'class': 0.32; 'this.': 0.32; 'created': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'etc': 0.35; 'but': 0.35; 'object,': 0.36; 'next': 0.36; 'shows': 0.36; 'hi,': 0.36; 'conditions.': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'to:addr:python.org': 0.39; 'here': 0.66; 'between': 0.67; '11.': 0.74; 'slot,': 0.84; 'sorry.': 0.91 X-EIP: [Pbe2wjrsdkRLGpL81z1qk1RQzVPbqEid] X-Originating-Email: [naruto0.1@live.cn] Date: Mon, 5 Aug 2013 09:37:46 +0800 From: Jack User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: In pyqt, some signals seems not work well References: <51FE9B88.8090706@swing.be> In-Reply-To: <51FE9B88.8090706@swing.be> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 05 Aug 2013 01:37:54.0411 (UTC) FILETIME=[67D1FBB0:01CE917C] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 96 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375666745 news.xs4all.nl 15902 [2001:888:2000:d::a6]:38777 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51945 On 2013/8/5 2:20=2C Vincent Vande Vyvre wrote: > Le 04/08/2013 18:06=2C Jacknaruto a =C3=A9crit : >> Hi=2C Guys! >> >> I created a thread class based QThread=2C and defined some signals to=20 >> update UI through main thread. >> >> the UI used a stackedWidget=2Csomeone page named 'progressPage' have a=20 >> progressBar and a Label=2C the next page named 'resultsPage' shows=20 >> results(some Labels). >> >> When the window showed progressPage=2C my code that updates progressBar= =20 >> was well=2C but the updating resultsPage's labels signals seems ignored= =20 >> by main thread.(I guess=2C because I added some prints in the slot=2C it= =20 >> wasn't printed) >> >> the code like this: >> >> 1. class worker(QtCore.QThread): >> 2. sig_jump_finish_page =3D QtCore.pyqtSignal() >> 3. sig_set_label_text =3D QtCore.pyqtSignal(str=2C str) >> 4. sig_set_progress_value =3D QtCore.pyqtSignal(int) >> 5. >> >> 6. for dirpath=2C dirnames=2C filenames in os.walk(self.root): >> 7. for filename in filenames: >> 8. self.sig_set_label_text.emit('current'=2C self.current()) # work wel= l >> 9. # so something >> 10. >> >> 11. #self.dialog.set_found(str(self.found())) # work well >> 12. #self.dialog.set_all(str(self.total())) # work well >> 13. self.sig_set_label_text.emit('found'=2C str(self.found())) # :( >> 14. self.sig_set_label_text.emit('all'=2C str(self.total())) # :( >> 15. >> >> 16. self.sig_jump_finish_page.emit() >> >> >> So I have to update UI directly in the thread(comments Line 11-12=20 >> shows)=2C it looks work well. >> >> I found the difference between line 8 and line 13-14 is line 8=20 >> manipulates current page -progressPage=2C line 13-14 manipulates next=20 >> page -resultsPage. >> >> Is some wrongs in there? >> >> >> >> >> > Have a look at my comments: > > class worker(QtCore.QThread): > sig_jump_finish_page =3D QtCore.pyqtSignal() > sig_set_label_text =3D QtCore.pyqtSignal(str=2C str) > sig_set_progress_value =3D QtCore.pyqtSignal(int) > I'm sorry. In run() function the code below > for dirpath=2C dirnames=2C filenames in os.walk(self.root): # What is=20 > 'self' here ? self is current object=2C isn't it? self.root is a path which the=20 user will specify. > for filename in filenames: > self.sig_set_label_text.emit('current'=2C self.current()) # where is=20 > 'current' ? > # so something self.current() is a getter=2C it just returns a member that shows the= =20 path of the current work. > > #self.dialog.set_found(str(self.found())) # What is self=2C and dialog=2C= =20 > and found ? the main thread is a dialog object. self.dialog was assigned the dialog object in the __init__ of=20 worker class. self.found() is a getter also=2C it returns the number of meeting the= =20 conditions. self.total() means like this. > #self.dialog.set_all(str(self.total())) # ... > self.sig_set_label_text.emit('found'=2C str(self.found())) # again ? > self.sig_set_label_text.emit('all'=2C str(self.total())) # etc > > self.sig_jump_finish_page.emit() > dialog.set_all() and so on just sets the widget's text. My English is poor=2C I hopeyou will excuse me.