Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38233

Re: Detecting a click on the turtle screen when the turtle isn't doing anything?

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Detecting a click on the turtle screen when the turtle isn't doing anything?
Date 2013-02-05 16:54 -0500
Organization > Bestiaria Support Staff <
References <5id7u9x7rd.ln2@news.ducksburg.com> <e348u9x18o.ln2@news.ducksburg.com>
Newsgroups comp.lang.python
Message-ID <mailman.1389.1360101284.2939.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, 05 Feb 2013 19:45:18 +0000, Adam Funk <a24061@ducksburg.com>
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/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-05 13:20 +0000
  Re: Detecting a click on the turtle screen when the turtle isn't doing anything? woooee@gmail.com - 2013-02-05 10:08 -0800
    Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-05 19:58 +0000
      Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Dave Angel <d@davea.name> - 2013-02-05 16:55 -0500
        Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-06 21:46 +0000
  Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-05 19:45 +0000
    Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-05 16:54 -0500
      Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-06 21:52 +0000

csiph-web