0

I'm trying to learn Python UniCurses so I can use it in a project I'm working on.

Here is what I'm using:

  • Python 2.7
  • Visual Studio 2013
  • Python Tools for Visual Studio 2013

I installed the necessary items, UniCurses and PDCurses. And it seems to work just fine from the Python interpreter and IDLE. But not in Visual Studio...

I kept receiving an error saying that the pdcurses.dll was missing. So I decided to copy the PDCurses files into the root of my project. That seemed to resolve the missing pdcurses.dll error.

However, UniCurses still isn't working correctly. When I try to use any of the UniCurses functions I get an AttributeError: 'c_void_p' object has no attribute 'TheAttribute'. This is happening with every UniCurses function except for when I first init the object: stdscr = unicurses.initscr()

So I started looking into some tutorials to make sure I installed everything correctly. I followed instructions from the UniCurses README on GitHub: https://www.youtube.com/watch?v=6u2D-P-zuno and this installation tutorial on YouTube: https://www.youtube.com/watch?v=6u2D-P-zuno and I still can't get it to work.

I did find a post on here that was somewhat similar to my problem but doesn't really help with my issue. You can check that out here: (Python Unicurses) stdscr not passing between files?

Does anyone have an idea of what I'm doing wrong? I've spent hours searching for a solution but nothing is working.

Any assistance is greatly appreciated. Thank you!

Community
  • 1
  • 1
CM-Dev
  • 373
  • 1
  • 5
  • 15

1 Answers1

0

I figured it out! Unfortunately for me, I was too focused on following the examples in the tutorials that I overlooked the underlying issue. I should have caught on when I found the similar post on here (link included in my question), but I was thinking the problem I was encountering was different.

Basically, I thought UniCurses and/or PDCurses was setup incorrectly and in turn causing the methods to not be accessible. Which was not the case. Instead, the code in tutorial I was following is actually accessing the methods incorrectly (don't know why it was working for them, maybe an older version?).

Here is an example:

import unicurses

# Init screen object
stdscr = unicurses.initscr()

# Incorrect way to access methods:
stdscr.addstr('Hello World!')

# Correct way to access methods:
unicurses.addstr('Hello World!')

or

from unicurses import *

# Init screen object
stdscr = initscr()

# Incorrect way to access methods:
stdscr.addstr('Hello World!')

# Correct way to access methods:
addstr('Hello World!')

I didn't really catch on to the issue until I found this UniCurses installation test script online:

# Script to test the installation of UniCurses
from unicurses import *

stdscr = initscr() # initializes the standard screen
addstr('Hello World!\n')
addch(ord('A') | A_BOLD)
addstr(' single bold letter\n')
attron(A_BOLD) # Turns on attribute
addstr('\n\nBold string')
attroff(A_BOLD)
addstr("\nNot bold now")
mvaddch(7, 10, 66); #B at row 7, col 10
addstr(' - single letter at row 7, col 10')

start_color()
init_pair(1, COLOR_RED, COLOR_GREEN) # Specifies foreground and background pair 1
init_pair(2, COLOR_YELLOW, COLOR_RED)

attron(COLOR_PAIR(1))
mvaddstr(15, 12, 'Red on green at row 15, col 12')
attroff(COLOR_PAIR(1))

attron(COLOR_PAIR(2))
addstr('\n\nYellow on red')
addstr('\n\nPress up arrow!')
attroff(COLOR_PAIR(2))

cbreak() # Gets raw key inputs but allows CRTL+C to work
keypad(stdscr, True)  # Get arrow keys etc.
noecho() # Do not display automatically characters for key presses
a = getch() # Gets the key code
if a == KEY_UP:
    beep()
    clear()
    addstr('Beep! Any key to quit.')
a = getch()

(source: http://www.pp4s.co.uk/main/tu-python-unicurses.html)

I hope this will be of some use to others running into this problem. I'm definitely kicking myself for not catching on sooner.

CM-Dev
  • 373
  • 1
  • 5
  • 15