[Twisted-Python] wxPython integration solution

Matthew Sherborne miracle at slingshot.co.nz
Wed Jul 7 20:35:18 EDT 2004

Hi All,

I've posted a solution for wx - twisted integration. Based on Itamars 
suggestions of two threads.

It's very easy to use.

To call a twisted method from wx thread just do:
   netCall(someTwistedThing, myParam, kword1=x, kword2=1)

It returns a deferred, that will be calledback and erredback safely in 
the wx thread.

Same for calling gui stuff from a twisted thread.
  guiCall(someGuiThing, (p1, p2))

or even easier create an interlayer object:
from twisted.protocols.basic import LineReceiver

class Gui2Net(LineReceiver):
    def send(self, someData):
    send = makeNetSafe(send)

In this example an instance of GuiNet can be used safely by the gui 
thread, it can send data, just like if it was a normal twisted call; it 
will return a deferred. "makeNetSafe" means make this net call safe to 
be called from the gui.

There is also a "makeGuiSafe" call, but I haven't tested it.

You can still use the wrapper object in your test cases if you dont have 
a gui. If no TwistedThread is instansiated netCall and makeNetSafe just 
pass through.

Comments appreciated.

Matthew Sherborne
Sherborne International Ltd

More information about the Twisted-Python mailing list