Mailing List Archive

createfilehandler, how to use it with Tk?
I have to communicate a tk front end with another modules.
And I'm trying:
... tk-inter code

class lectora:
def __init__(self):
from socket import *
HOST = '' # The remote host
PORT = 50008 # The same port as used by the server
self.s = socket(AF_INET, SOCK_STREAM)
self.s.connect(HOST, PORT)
self.s.send('Hello, world')

def el_socket(self, handle, event):
pass
#data = handle.recv(1024)

def close(self):
self.s.close()
print 'Received', `data`

l = lectora()

tk_mask = _tkinter.READABLE

_tkinter.createfilehandler(l.s, tk_mask, l.el_socket )

test = Test()
test.mainloop()

But this segfaults. :(

I've been browsing fnorb example of use of createfilehandler
, but it's as complex as hell.
has anyone a simple,straightforward example of it?

Thanks


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
createfilehandler, how to use it with Tk? [ In reply to ]
algaba@my-deja.com wrote:
> I have to communicate a tk front end with another modules.
> And I'm trying:
> I've been browsing fnorb example of use of createfilehandler
> but it's as complex as hell.
> has anyone a simple,straightforward example of it?

forget about createfilehandler. use asyncore/asynchat instead:
http://www.python.org/doc/current/lib/module-asyncore.html

to use them under Tk, you can use a
simple polling scheme:

import asyncore

class myApp:
def __init__(self, master):
self.master = master

...

self.poll()

# issue a HTTP request (see handbook example)
http_client("www.python.org", "/")

def poll(self):
# keep the server up and running
try:
asyncore.poll(0.05)
self.master.after(100, self.poll)
except:
pass # error in network callback

...

</F>
createfilehandler, how to use it with Tk? [ In reply to ]
In article <012c01bed77a$d562b370$f29b12c2@secret.pythonware.com>,
"Fredrik Lundh" <fredrik@pythonware.com> wrote:
> algaba@my-deja.com wrote:
> > I have to communicate a tk front end with another modules.
> > And I'm trying:

> forget about createfilehandler. use asyncore/asynchat instead:
> http://www.python.org/doc/current/lib/module-asyncore.html
>
> to use them under Tk, you can use a
> simple polling scheme:
>
> asyncore.poll(0.05)
> self.master.after(100, self.poll)
> except:
> pass # error in network callback
>
> ...
>
asyncore is a new module ? I can't find it in my python 1.5.1

Anyway, thanks.
And... what's the difference between this and a simple
loop with time.sleep(0.001), ... a bit of more freedom?
Thanks


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
createfilehandler, how to use it with Tk? [ In reply to ]
algaba@my-deja.com wrote:
> asyncore is a new module ? I can't find it in my python 1.5.1

then why are you using 1.5.1? ;-)

asyncore and friends are shipped with 1.5.2,
but you can get a stand-alone distribution from
http://www.nightmare.com/software.html

</F>