I am writing a program that uses curses and threading. I am working on
displaying a clock in the upper right hand corner of the screen. I
have only one thread at the moment, that gets the time and displays it
in curses. To make it easier to debug right now, the program starts
curses in a try: clause then starts the thread which runs for 10
iterations displaying the time every second. Then the thread exits,
and the program is supposed to run the finally: clause to clean up the
terminal. I also have set curs_set(0) so the cursor is invisible. What
happens is that everything starts fine but the cursor is visible. It
runs for the 10 seconds then quits without restoring the terminal to
working order. I am trying this on a Fedora 4 computer have also tried
it on a Fedora 8 one with same results. I have tried searching but
Google doesn't find anything using both curses and threading. The only
thing I can find regarding both is that curses seems to block when
waiting for input, but I do not have any input yet. Below is what I
have right now:

#! /usr/bin/env python
import curses
import threading
import time
class cadtime(threading.Thread):
        def run(self):
                x=0
                while x<10:
                        cadtimevl=time.strftime("%d %b  %H:%M:
%S",time.localtime())
                        leng=len(cadtimevl)
                        stdscr.addstr(0,width-leng-1,cadtimevl)
                        stdscr.refresh()
                        x=x+1
                        time.sleep(1)
                return
try:
        stdscr=curses.initscr()
        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        curses.start_color()
        curses.curs_set(0)
        width=curses.COLS-1

        cadtime().start()

finally:
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()

I can't figure out why the cursor still shows and why they terminal is
screwed up afterward because the finally: should catch any failures
and reset the terminal.

-Brett
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to