Hi all,
i've a problem with threads and wx. Here's the scenario:
ida_client.py - simple create the GUI object and enter in main loop
gui.py - here there's the GUI created with wxGlade
net.py - the network thread
queue.py - the queue object:
class MyQueue(Queue.Queue):
pass
myQueue = MyQueue(0)
The network thread will be lauched with user click on "login" button:
def LOGIN_OnClick(self, event): # on LOGIN Click
# Crea il THREAD della classe NET
w =
NetThread(self.text_ctrl_1.GetLineText(0),self.text_ctrl_2.GetLineText(0))
w.start()
It start a connection to remote host using asyncore module.
class NetThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
# Inizia Connessione
...
# Loop del socket
asyncore.loop()
The myQueue object was uset to share messages between GUI and NET threads.
- From NET thread all work in the following way (net.py):
class IDA_Client(asyncore.dispatcher):
def __init__(self, host):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect( (host, 8890) )
....
def handle_error(self):
myQueue.put(301)
wx.WakeUpIdle()
self.close()
in gui.py:
def OnIdle(self,event):
while myQueue.qsize():
try:
msg = myQueue.get(0)
print "myQueue.get -> %d" % msg
if((msg > 299) and (msg < 400)):
wdl = wx.MessageDialog(self,'Error','',wx.ICON_EXCLAMATION
wx.OK)
event.Skip()
except Queue.Empty:
pass
and the messages putted on queue will be successufully delivered to the gui
client. But if i want to send messages from GUI to NET thread ? There's a
method to call a procedure periodically ? I have tried wxTimer but without
success 'cause want a pointer to the wx system.
Someone can help me ?
Tnx ! Oz
- --
Taxes are not levied for the benefit of the taxed.