banging head against sys.stdin and tkinter on win32 
Author Message
 banging head against sys.stdin and tkinter on win32

thump thump thump

    A few weeks ago I decided to try to become more proficient in python by
writing a plain vanilla GUI app that interfaces with a serial port. Turns
out to have been pretty straightforward and everything is now at least
working, if not working the way I want it to. The program is a single
Tkinter text widget in its own thread to display everything that is read
from the serial port, another thread to read from that port, and one more
thread to continuously read input from the user. I don't need to process any
input from the user, just send it straight to the device attached to the
serial port.
    So far no problem. I've been using a while 1 loop and msvcrt to poll for
any keystrokes, but this keeps a console window open and all commands must
be typed in that window. I'd like to 86 the console and just have all
input/output done on the display window (I'm familiar with the .pyw filename
trick, won't work, msvcrt need that console window to function). This is
where the headbanging thing happens.
    I've tried wrapping the window in a class and defining a read method in
order to redirect sys.stdin - no joy, msvcrt just wants to use a console
window no matter what. I used an Entry widget for a while, but the number of
bind statements was prohibitively long, and would all need to be changed if
I tried to communicate with a different type of device. Input and raw_input
don't really apply here since I need to work on a character by character
basis and not wait for \n to terminate a string.
    Am I even on the right track here? I'll gladly RTFM if someone will
point me to where an appropriate FM is. For that matter, where is the source
code for msvcrt? There is no file with that name in my Python path (or
anywhere else), yet I have to import it as a module.

Best,
Dave

-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.*-*-*.com/ - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----



Sat, 29 May 2004 14:44:56 GMT  
 banging head against sys.stdin and tkinter on win32

Quote:
> thump thump thump

>     A few weeks ago I decided to try to become more proficient in Python
by
> writing a plain vanilla GUI app that interfaces with a serial port. Turns
> out to have been pretty straightforward and everything is now at least
> working, if not working the way I want it to. The program is a single
> Tkinter text widget in its own thread to display everything that is read
> from the serial port, another thread to read from that port, and one more
> thread to continuously read input from the user. I don't need to process
any
> input from the user, just send it straight to the device attached to the
> serial port.
>     So far no problem. I've been using a while 1 loop and msvcrt to poll
for
> any keystrokes, but this keeps a console window open and all commands must
> be typed in that window. I'd like to 86 the console and just have all
> input/output done on the display window (I'm familiar with the .pyw
filename
> trick, won't work, msvcrt need that console window to function). This is
> where the headbanging thing happens.
>     I've tried wrapping the window in a class and defining a read method
in
> order to redirect sys.stdin - no joy, msvcrt just wants to use a console
> window no matter what. I used an Entry widget for a while, but the number
of
> bind statements was prohibitively long, and would all need to be changed
if
> I tried to communicate with a different type of device. Input and
raw_input
> don't really apply here since I need to work on a character by character
> basis and not wait for \n to terminate a string.
>     Am I even on the right track here? I'll gladly RTFM if someone will
> point me to where an appropriate FM is. For that matter, where is the
source
> code for msvcrt? There is no file with that name in my Python path (or
> anywhere else), yet I have to import it as a module.

> Best,
> Dave

You're not on the right track. Now that that's taken care of :-)...

msvcrt is an extension module written in C (actually, it just provides
Python interfaces to a bunch of functions in the MS C Runtime library), so
that's why there's no source code. It's in the Python source distribution if
you're really interested. The function in question is actually a Win32
CONSOLE function, and so it needs a console to work. Thus, redirecting stdin
won't help.

The right way to handle this problem is what you were doing - use an entry
widget (or whatever they call it in TK) - trap the events as the buffer
changes and send out the keystrokes to the serial port. Unfortunately I
haven't touched Python GUI programming in a LONG time, so I can't help you
with the bindings, sorry.

-Chris



Sat, 29 May 2004 16:26:20 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Simple regex that has me banging my head against a wall

2. Help! banging my head against Attributes

3. using sys.stdin.raw_input and sys.stdin.readline together in a platform independent way

4. non-blocking sys.stdin.read() on win32?

5. Chosing between sys.argv and sys.stdin

6. Beating my head against the wall, ISE style

7. Mark Hammond..pls see Help! Banging my head against Attributes

8. To bang or not to bang

9. how to link python against static sys libs?

10. sys.stdin.readlines() in 2.2a ?

11. sys.stdin.read() HELP!

12. reusing sys.stdin?

 

 
Powered by phpBB® Forum Software