[Pythonmac-SIG] Threading and FrameWork.Application

Pieter Claerhout Pieter.Claerhout@Creo.com
Fri, 5 Apr 2002 00:18:05 +0200


Hi all,

I'm trying to wrap the module xmlrpclibServer, which is downloadable from
http://mrken.net/code/xml-rpc/xmlrpcServer.py. The most simple thing of
course is to just use the BuildApplication utility to make a standalone
version of it, and you're done.

Unfortunately, I want to add an about box, and I also want to add the menu
File with the option Quit. I got so far that I came up with the following
piece of code:

<code>
import threading
import FrameWork
import EasyDialogs
import xmlrpcServer

class DaemonMac(FrameWork.Application):

    def __init__(self):
        FrameWork.Application.__init__(self)
        self.MyRPCServer = threading.Thread(target=xmlrpcServer._main)
        self.MyRPCServer.start()
        self.mainloop()

    def makeusermenus(self):
        self.filemenu = m = FrameWork.Menu(self.menubar, "File")
        self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)

    def quit(self, *args):
        self._quit()

if __name__ == '__main__':
    DaemonMac()
</code>

I tried to use the threading module to start the XML RPC server in a
different thread (xmlrpcServer itself also is a threaded piece of code), but
that seems to conflict with the mainloop. If you start this application, it
starts the thread, starts the mainloop and stays in there, once you finish
the mainloop, the thread continues.

Is there an easy way to wrap Python scripts like this in a macintosh
application? If not, what options should I look at? If so, how should I do
it? My guess is that I should hack it somewhere in the mainloop, but I'm not
sure how and I don't know where I should start looking.

Hope someone can help here.

Thanks,



Pieter