wx.Frame event handler problems
nrmn
nrmn_ncjs at yahoo.com
Mon Aug 20 19:41:56 EDT 2007
i have a function (event handler) inside a wx.Frame subclass which reads 2 kinds of data (differentiated by a prefix char) from a file and updates the text on the UI.
def onStartParsing(self, event):
file = open('data.txt','r')
while 1:
input = file.readline().strip('\r\n')
try:
if input[0] == '-': # data A
self.data_A_display.SetLabel(input.strip('-'))
wx.Yield()
elif input[0] == '+': # data B
self.data_B_display.SetLabel(input.strip('+'))
wx.Yield()
except IndexError: # EOF
file.close()
break
what i'd like to do is, if i click a button or an item in a menu, it will send the input variable to another pc through sockets. i am lost at how to 'update' the function such that it would look something like this:
# after a user has clicked a button
def onStartParsing(self, event):
file = open('data.txt','r')
sock_a = socket(AF_INET,SOCK_DGRAM)
sock_a.bind(ADDR)
while 1:
input = file.readline().strip('\r\n')
sock_a.sendto('%s' % input, ADDR)
try:
if input[0] == '-': # data A
self.data_A_display.SetLabel(input.strip('-'))
wx.Yield()
elif input[0] == '+': # data B
self.data_B_display.SetLabel(input.strip('+'))
wx.Yield()
except IndexError: # EOF
file.close()
break
another solution i thought was to create another event handler that contains the following body above, but it should terminate/stop running the while loop in the original onStartParsing event-handler. problem is i don't know how.
other solutions, suggestions are very much welcome.
-norman ancajas
---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070820/e0f4ddc2/attachment.html>
More information about the Python-list
mailing list