Greetings, my master.<br><br>I&#39;m writing a game based on curses.<br><br>I have my own screen object and several child objects to handle sub windows with e.g. menues, board/map/views and log outputs. All user input is done with 
screen.getch and later sent to the dynamic menu for selecting menu points.<br><br>My imidiate problem is when I select &quot;Quit&quot; from the menu, I need to send the string back to the caller/parent class for evaluation.
<br><br>Later I will need to design all the menues and the related methods, other sub windows in different threads for individual updates. But first I need a working UI.<br><br>Off topic: I must say that I&#39;m amazed by this tutor thing. To really have my &quot;own&quot; tutor in this new programming language I&#39;m learning, is kinda blowing my mind. I hope I can repay the python community some day when I&#39;m smart enough. :-)
<br><br>Thanks in advance<br><br>/karneevor<br><br><div class="gmail_quote">On Dec 29, 2007 6:39 PM, Alan Gauld &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d"><br>&quot;Michael Bernhard Arp Sørensen&quot; &lt;<a href="mailto:michaelarpsorensen@stevnstrup.dk">michaelarpsorensen@stevnstrup.dk</a>&gt;<br></div>wrote<br><div class="Ih2E3d"><br>&gt; I want to learn about callbacks because we use it at work in our
<br>&gt; software.<br><br></div>Can you be more specific about what you want to know. Callbacks are<br>used in many different ways from event handling methods in a GUI<br>to network programming to simulating synchronous protocols over
<br>an asynchronous connection.<br><div class="Ih2E3d"><br>&gt; I there a short &quot;hello world&quot;-like version of a callback example?<br><br></div>See almost any GUI tutorial.<br>The recent thread &quot;Closing GUI program&quot; had the following example
<br>from Michael Goldwasser<br><br>#-------------------------------------------<br>from Tkinter import Tk,Label<br><br>def onClose():<br> &nbsp; &nbsp;root.destroy() &nbsp; # stops the main loop and interpreter<br><br>root = Tk()<br>root.protocol
(&quot;WM_DELETE_WINDOW&quot;, onClose) &nbsp;# handle event when window<br>is closed by user<br>z = Label(root, text=&quot;Hello World!&quot;)<br>z.grid()<br>root.mainloop()<br>#-------------------------------------------<br>
<br><br>In this example the onClose() event handler is a callback function.<br><br>The folowing pseusdo code shows how the principle can be used for<br>asynchronous network programming:<br><br>waiting = {} &nbsp; &nbsp; # list of objects awaiting responses
<br>id = 0<br><br>def sendToServer(msg, callback)<br> &nbsp; &nbsp; &nbsp; msgSent = prepareMessage(msg)<br> &nbsp; &nbsp; &nbsp; id = server.send(msgSent)<br> &nbsp; &nbsp; &nbsp; waiting[id] = (msg, callback)<br><br>def func1()<br> &nbsp; &nbsp; msg = prepareData()<br> &nbsp; &nbsp; sendToServer(msg, func1_cont)
<br><br>def func1_cont(original, result)<br> &nbsp; &nbsp; x,y,z = result.getValues()<br> &nbsp; &nbsp; processData(x,y,z,original.p,original.q)<br><br>while server.listen()<br> &nbsp; &nbsp; &nbsp;msg = server.recv()<br> &nbsp; &nbsp; &nbsp;id = msg.getID()<br> &nbsp; &nbsp; &nbsp;oldMessage = waiting[id][0]
<br> &nbsp; &nbsp; &nbsp;callback = &nbsp;waiting[id][1]<br> &nbsp; &nbsp; &nbsp;callback(oldmessage, msg)<br> &nbsp; &nbsp; &nbsp;del(waiting[id])<br><br>In this example we can think of the main application calling func.<br>func1 needs to send a message to a server and process the response
<br>but the server has an asynchronous protocol so we split the function<br>into func1 and func1_cont at the point of calling the server. Then<br>when the server send us the response we pull the stored state out<br>of the dictionary and combine it with the server data to complete
<br>the func1 processing via the func1_cont callback.<br><br>In practice we&#39;d probably store the date/time with the transaction<br>data so that we can check for timeouts etc in a separate thread...<br><br>The important thing with all callbacks is that you match up the
<br>data expected by the callback with the data actually available<br>at the point of calling it. In this case we take the architectural<br>decision to pass callback functions the old and new data structures.<br>We could alternatively have passed the transaction id and let the
<br>callback retrieve (and delete) the data from the waiting list.<br><br>I hope that all makes sense.<br><font color="#888888"><br>--<br>Alan Gauld<br>Author of the Learn to Program web site<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld" target="_blank">
http://www.freenetpages.co.uk/hp/alan.gauld</a><br></font><div><div></div><div class="Wj3C7c"><br><br>_______________________________________________<br>Tutor maillist &nbsp;- &nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org
</a><br><a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br></div></div></blockquote></div><br><br clear="all"><br>-- <br>Med venlig hilsen/Kind regards
<br><br>Michael B. Arp Sørensen<br>Programmør / BOFH<br>I am /root and if you see me laughing you better have a backup.