473,418 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Serious Python/Curses Wierdness

The appended program freaks python 2.2 & 2.3 completely out. To
reproduce the wierdness: i) copy the source to a file called
consarn.py ii) $ python consarn.py; iii) the program is now doing a
getch(); iv) hit a key; v) the program locks up, the interptreter is
now munching on the CPU; vi) kill the interpreter from another shell;
vii) scratch head and wonder why neither of the mutually exclusive
clauses in the _io() member function have written any output via dbg()
calls to the consarn.debug file.

This has simply got to be a major problem with the interpreter and/or
the curses module(s).

__rcsid__ = "$Id: consarn.py,v 1.10 2004/09/17 22:43:30 mqa Exp
zma0472 $"

import string, curses, curses.ascii, time

(_Y, _X) = (24, 80)

def dbg(str):
f = open("consarn.debug", 'a')
f.write(time.ctime() + " : " + str + '\n')
f.close()

class Menu:
def __init__(self, title="Consarn Menu"):
self.title = string.center(string.strip(title), _X)
self.items = []; self.label_width = 0; self.linked = False

def link(self):
y = 1; idx = 0; screen = 0
x = range(2, _X-self.label_width+1, self.label_width+2)
up = left = ppage = top = self.items[0]
for i in self.items:
i["up"] = up; i["down"] = i; i["up"]["down"] = i; up = i
i["right"] = i["left"] = i["npage"] = i
if idx > 0: i["left"] = left
i["left"]["right"] = i; i["ppage"] = ppage
i["screen"] = screen; i["y"] = y; i["x"] = x[idx]
if _Y-1 == y:
y = 1; left = top
if len(x)-1 == idx:
idx = 0; ppage = i; screen += 1
else:
idx += 1
else:
if 1 == y: top = i
y += 1; left = left["down"]
self.linked = True

f = open("link.out", 'w')
for i in self.items:
f.write("%s:\n" % i["label"])
f.write(" up = " + i["up"]["label"] + '\n')
f.write(" down = " + i["down"]["label"] + '\n')
f.write(" right = " + i["right"]["label"] + '\n')
f.write(" left = " + i["left"]["label"] + '\n')
f.write(" npage = " + i["npage"]["label"] + '\n')
f.write(" ppage = " + i["ppage"]["label"] + '\n')
f.write(" x = " + str(i["x"]) + '\n')
f.write(" y = " + str(i["y"]) + '\n')
f.write(" screen = " + str(i["screen"]) + '\n')
f.close()

def _io(self, scr):
if not self.linked: self.link(); scr.keypad(1); #
curses.curs_set(0);
item = self.items[0]; item["attributes"] = curses.A_STANDOUT
while True:
scr.clear()
scr.addnstr(0, 0, self.title, _X, curses.A_STANDOUT)
for i in [j for j in self.items if j["screen"] ==
item["screen"]]:
scr.addnstr(i["y"], i["x"], i["label"], _X,
i["attributes"])
scr.refresh()
while True:
m = { curses.KEY_DOWN : item["down"],
curses.KEY_UP : item["up"],
curses.KEY_RIGHT : item["right"],
curses.KEY_LEFT : item["left"],
curses.KEY_PPAGE : item["ppage"] }
c = scr.getch(); dbg("c = scr.getch()")
if c in m.keys():
if c in m.keys():
dbg("if c in m.keys():")
if m[c] != item:
dbg(" if m[c] != item:")
item["attributes"] = curses.A_NORMAL
m[c]["attributes"] = curses.A_STANDOUT
scr.addnstr(item["y"], item["x"],
item["label"], _X,

item["attributes"])
scr.addnstr(m[c]["y"], m[c]["x"],
m[c]["label"], _X,

m[c]["attributes"])
if item["screen"] == m[c]["screen"]:
item = m[c]; scr.refresh()
else:
item = m[c]; break
else:
dbg("Inside else")
elif curses.ascii.ESC == c:
return

def add_item(self, item_label):
self.items.append({"label" : item_label, "up" : None, "down" :
None,
"left" : None, "right" : None, "ppage" :
None,
"npage" : None, "x" : None, "y" : None,
"screen" : None, "attributes" :
curses.A_NORMAL})
self.label_width = max(len(item_label), self.label_width)
self.linked = False

def delete_item(self, item):
if item in self.items:
self.items.remove(item); self.linked = False

def IO(self):
curses.wrapper(self._io)

def test():
import string
import random

print "Initializing the Consarn Demo..."
random.seed()
population = string.ascii_letters+string.digits+string.punctuat ion
# max_width = random.randint(1, _X-1)
for max_width in range(1, _X-1):
m = Menu(title="ROWS=%d COLS=%d R=%d" % (_Y, _X, max_width))
for x in range(0, 400):
width = random.randint(1, max_width)
s = random.sample(population, width)
label = ""
for c in s: label += c
m.add_item(label)
m.IO()
del(m)

def test1():
print "Initializing Debug Test..."
m = Menu(title="ROWS=%d COLS=%d" % (_Y, _X))
f = open("debug", 'w')
f.write("Create start = " + time.ctime() + '\n')
for x in range(0, 40):
m.add_item(str(x))
f.write("Create end = " + time.ctime() + '\n')
f.close()
m.IO()
del(m)

if "__main__" == __name__:
curses.wrapper(test1())
Jul 18 '05 #1
0 1746

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian | last post by:
Hello; I'm writing a program with curses in python and having a bit of trouble understanding how to use unittest. So far, I have used testing successfully -- as long as the report goes to stdout...
2
by: Konrad Koller | last post by:
import curses produces the ImportError: No module named _curses ("from _curses import *" in line 15 in __init__.py) Of course imp.find_module ("_curses") reports the same error. How can I make...
9
by: David Bear | last post by:
I need python 2.3. I have freebsd 4.10-releng. when configuring python I received the following: ../configure --prefix=/home/webenv > config-results configure: WARNING: curses.h: present but...
1
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
3
by: skip | last post by:
I'm having no success building the curses module on Solaris 8 (yes, I know it's ancient - advancing the state-of-the-art is not yet an option) for Python 2.4. Sun provides an apparently ancient...
3
by: Maxim Veksler | last post by:
Hi list, I'm working on writing sanity check script, and for aesthetic reasons I would like the output be in the formatted like the gentoo init script output, that is: """ Check for something...
15
by: pinkfloydhomer | last post by:
I need to develop a cross-platform text-mode application. I would like to do it in Python and I would like to use a mature text-mode library for the UI stuff. The obvious choice, I thought, was...
1
by: shrek2099 | last post by:
Hi All, Recently I ran into a problem with UTF-8 surrport when using curses library in python 2.5 in Fedora 7. I found out that the program using curses cannot print out unicode characters...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.