[Tutor] Displaying stdio and stdin

Bob Gailer ramrom@earthling.net
Fri Mar 7 19:39:01 2003


--=======1003E63=======
Content-Type: text/plain; x-avg-checked=avg-ok-24A13915; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 08:10 AM 3/7/2003 -0800, vicki@stanfield.net wrote:

>In the application that I am developing, I send
>commands to a device and retrieve the device's
>response. I want to display both what is sent and what
>is retrieved in some kind of widget on the GUI. What is
>generally used for this type of thing. I am able to
>redirect the stdio and stdout to a file, but I am not
>aware of a widget which will display a data stream. Am
>I dreaming? Do I have to build it myself?

Here's a minimal idea of how to do this using Tkinter: create a dialog 
consisting of a Label, and update the Label's text with whatever segment of 
the data stream you want to display. This example uses a static text stream 
and a timer to pace the display. I think you should be able to recode these 
parts to handle your dynamic stream.

from time import sleep
from Tkinter import *
class Dialog(Frame):
   def __init__(self, master=None):
     Frame.__init__(self, master)
     self.pack()
     self.Label = Label(self, width = 25, font = 'arial 8')
     self.Label.after_idle(self.quit) # causes immediate exit from mainloop()
     self.Label.pack({"side": "top"})
     self.mainloop()

if __name__ == '__main__':
   d = Dialog()
   stream = """This is a long stream of text. In the application that I am 
developing, I send
   commands to a device and retrieve the device's response. I want to 
display both what is sent and what
   is retrieved.""".replace('\n',' ')
   for t in range(len(stream)):
     d.Label['text'] = stream[t:t+30]
     d.update()
     sleep(.01)

HTH

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======1003E63=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-24A13915
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.459 / Virus Database: 258 - Release Date: 2/25/2003

--=======1003E63=======--