Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'implements': 0.07; 'exits': 0.09; 'itself,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; 'thread': 0.11; 'value.': 0.15; '"global"': 0.16; '(x,': 0.16; 'adam': 0.16; 'blocks': 0.16; 'callback)': 0.16; 'dislike': 0.16; 'echo': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Detecting': 0.16; 'subject:screen': 0.16; 'subject:turtle': 0.16; 'subject:when': 0.16; 'threading': 0.16; 'y):': 0.16; 'feb': 0.19; 'import': 0.21; 'sets': 0.23; 'header:X -Complaints-To:1': 0.28; 'performing': 0.30; 'function': 0.30; 'url:home': 0.33; 'to:addr:python-list': 0.33; 'changed': 0.34; 'false': 0.35; 'subject:?': 0.35; 'add': 0.36; 'received:org': 0.36; "i'll": 0.36; 'test': 0.36; 'charset:us-ascii': 0.36; 'busy': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'within': 0.64; '2013': 0.84; 'subject:anything': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Date: Tue, 05 Feb 2013 16:54:22 -0500 Organization: > Bestiaria Support Staff < References: <5id7u9x7rd.ln2@news.ducksburg.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-22-149.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360101284 news.xs4all.nl 6886 [2001:888:2000:d::a6]:43733 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38233 On Tue, 05 Feb 2013 19:45:18 +0000, Adam Funk declaimed the following in gmane.comp.python.general: > > > > #v+ > > waiting = False > > > > def clicked(x, y): > > global waiting > > print('clicked at %f %f' % (x,y)) > > waiting = False > > return > > > > def wait_for_click(s): > > global waiting > > waiting = True > > s.listen() > > while waiting: > > time.sleep(1) > > return > > I'll echo the "Ugh" about the use of global AND ADD a dislike of the busy loop that only exits if some other return sets a value. If the busy loop were performing some action that changed the test state within the loop itself, okay... -=-=-=- import threading evtFlag = threading.Event() def clicked(x, y): print("clicked at %f %f" % (x, y)) evtFlag.set() #don't need "global" as not binding to the name evtFlag #don't need "return" as falling off the end of the function # implements return def wait_for_clicks(s): evtFlag.clear() s.listen() evtFlag.wait() #don't need "global" or "return" #don't need busy loop; .wait() blocks until some other thread # (GUI callback) sets the Event -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/