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.d ebug", 'a')
f.write(time.ct ime() + " : " + str + '\n')
f.close()
class Menu:
def __init__(self, title="Consarn Menu"):
self.title = string.center(s tring.strip(tit le), _X)
self.items = []; self.label_widt h = 0; self.linked = False
def link(self):
y = 1; idx = 0; screen = 0
x = range(2, _X-self.label_widt h+1, self.label_widt h+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_STANDO UT
while True:
scr.clear()
scr.addnstr(0, 0, self.title, _X, curses.A_STANDO UT)
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_RIGH T : item["right"],
curses.KEY_LEFT : item["left"],
curses.KEY_PPAG E : 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_STANDO UT
scr.addnstr(ite m["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.ES C == c:
return
def add_item(self, item_label):
self.items.appe nd({"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_widt h = max(len(item_la bel), self.label_widt h)
self.linked = False
def delete_item(sel f, item):
if item in self.items:
self.items.remo ve(item); self.linked = False
def IO(self):
curses.wrapper( self._io)
def test():
import string
import random
print "Initializi ng the Consarn Demo..."
random.seed()
population = string.ascii_le tters+string.di gits+string.pun ctuation
# max_width = random.randint( 1, _X-1)
for max_width in range(1, _X-1):
m = Menu(title="ROW S=%d COLS=%d R=%d" % (_Y, _X, max_width))
for x in range(0, 400):
width = random.randint( 1, max_width)
s = random.sample(p opulation, width)
label = ""
for c in s: label += c
m.add_item(labe l)
m.IO()
del(m)
def test1():
print "Initializi ng Debug Test..."
m = Menu(title="ROW S=%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()) 0 1773 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 (or does unittest
write to stderr?)
The curses part of the program seems to affect unittest's writing of the
report. The screen is not what the report expects, so a lot of
information is in the wrong place after the program exits. (I actually...
|
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 use of the curses package for writing a Python script
with curses?
|
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 cannot be compiled
configure: WARNING: curses.h: check for missing prerequisite headers?
configure: WARNING: curses.h: see the Autoconf documentation
configure: WARNING: curses.h: section "Present But Cannot Be Compiled"
configure: WARNING:...
|
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
#
# Brick & Ball in Python
# by Jerry Fleming <jerryfleming@etang.com>
|
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 version of curses in
/usr/lib, so I downloaded and installed ncurses 5.5, both using default
settings and using --with-shared. When the curses module is linked against
libcurses.so I get some strange error about acs32map being undefined (which...
| |
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 ..................................
Check for something else ..........................
"""
|
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 ncurses. But as far as I can tell,
it is not available for Python on Windows?
Is there a workaround? Or are there alternative libraries that might
be used instead of (n)curses? I know I can use (n)curses on *nix and
console on Windows etc., but...
|
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 correctly on UTF-8 enabled
console. I googled around and got an impression that the reason for
this problem is that python is linked with libcurses library instead
of libcursesw. The latter one is said to be able to solve this
problem. Has anybody...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |