I've been trying to learn Curses (Unicurses since I'm on Windows) and have been following a tutorial, but I've gotten stuck. I am running into this error message:
D:\Python34>python ./project/cursed.py
Traceback (most recent call last):
File "./project/cursed.py", line 35, in <module>
main()
File "./project/cursed.py", line 20, in main
obj_player = Player(stdscr, "@")
File "D:\Python34\project\cursedplayer.py", line 10, in __init__
self.max_x = stdscr.getmaxyx()[1] - 1
AttributeError: 'c_void_p' object has no attribute 'getmaxyx'
What I can glean from that is something is going wrong when trying to get the stdscr variable between the two files. Here is the file that has the function I'm trying to call:
from unicurses import *
from cursedfunction import *
class Player:
def __init__(self, stdscr, body, fg = None, bg = None, attr = None):
self.max_x = stdscr.getmaxyx()[1] - 1
self.max_y = stdscr.getmaxyx()[0] - 1
self.x = self.max_x / 2
self.y = self.max_y / 2
self.body = body
del stdscr
#create player
self.window = newwin(1, 1, self.y, self.x)
waddstr(self.window, self.body)
self.panel = new_panel(self.window)
self.fg = fg
self.bg = bg
self.color = 0
self.attr = attr
if (fg != None) and (bg != None):
self.set_colors(fg, bg)
self.show_changes()
def set_colors(self, fg, bg):
self.color = make_color(fg, bg)
self.fg = fg
self.bg = bg
waddstr( self.window, self.body, color_pair(self.color) + self.attr)
self.show_changes()
def show_changes(self):
update_panels()
doupdate()
Here is the main file that's calling the function defined in cursedplayer.py:
from unicurses import *
from cursedfunction import *
from cursedplayer import *
#lines is 80
#columns is 25
def main():
stdscr = initscr()
if not has_colors():
print("You need colors to run!")
return 0
start_color()
noecho()
curs_set(False)
keypad(stdscr, True)
obj_player = Player(stdscr, "@")
update_panels()
doupdate()
running = True
while running:
key = getch()
if key == 27:
running = False
break
endwin()
if (__name__ == "__main__"):
main()
I'd appreciate any help. I've been searching around but haven't found anything relevant to my problem. I can't proceed with the curses tutorial I'm following because of this error. Thank you for reading.
(cursedfunction.py isn't included because it doesn't have any relevant info, just a function that makes colors)
Ah! I am very dumb. The error message was giving me all the info I need -- specifically, that stdscr didn't have a function called 'getmaxyx'. I was inputting the command wrong!
Going from this:
To this:
...was able to pass the information in a format that I needed. Why it worked in the tutorial I don't know, but I blame black magic.