472,951 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 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 1718

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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...

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.