Curses Textpad: "_curses.error: setupterm: could not find terminal" - python

I'm making a Python program on a MacBook using the curses.textpad module. Here's my complete code:
import curses
from curses.textpad import Textbox, rectangle
def editor(stdscr):
stdscr.addstr(0, 0, "Type something: (hit Ctrl-G to exit)")
editor = curses.newwin(5, 30, 2, 1)
rectangle(stdscr, 1, 0, 1 + 5 + 1, 1 + 30 + 1)
stdscr.refresh()
box = Textbox(editor)
box.edit()
message = box.gather()
print(message)
text = curses.wrapper(editor)
print("Here's what you typed:")
print(text)
It keeps giving me this error whenever I try to run it:
Traceback (most recent call last):
File "/Users/Donoru/Desktop/editor/main.py", line 17, in <module>
text = curses.wrapper(editor)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/curses/__init__.py", line 84, in wrapper
stdscr = initscr()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/curses/__init__.py", line 29, in initscr
setupterm(term=_os.environ.get("TERM", "unknown"),
_curses.error: setupterm: could not find terminal
How can I fix this?

Related

how to export WBlock by using pyautocad

hi all i have this problem when i try to export object through WBlock what is wrong there i'm try to do simple python work (note: i'm beginners :D) .. any help
from pyautocad import Autocad, APoint,utils
import win32com.client
AutoCAD = win32com.client.dynamic.Dispatch("AutoCAD.Application")
acad = Autocad(create_if_not_exists = False)
acad.Visible=True
doc = AutoCAD.ActiveDocument
layersList = doc.Layers
for l in layersList:
object = acad.iter_objects()
if l.name == "0":
pass
else:
for o in object:
if o.ObjectName == "AcDbText":
SelectionSet = doc.SelectionSets.Item(o.ObjectName).Name
directoryN = "C:\\Temp\\{}_{}.dwg".format(l.name,o.TextString)
doc.WBlock(directoryN,SelectionSet)
here what i Get
AcDbText
Traceback (most recent call last):
File "C:/Temp/Exporter.py", line 23, in <module>
doc.WBlock(directoryN,SelectionSet)
File "<COMObject <unknown>>", line 2, in WBlock
pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 2)
thanks
i'm try to export every text as WBlock

pygame: Unable to forward songs with .wav extension

When I try to forward a song with .wav extension in pygame , I get an error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\default\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:\Users\default\PycharmProjects\pythonProject1\main.py", line 14, in forward
pygame.mixer.music.play(start = forwarded_pos)
pygame.error: Position not implemented for music type
Here's the code:
from tkinter import *
import pygame
root = Tk()
pygame.init()
def play():
pygame.mixer.music.load("test.wav")
pygame.mixer.music.play()
def forward():
forwarded_pos = pygame.mixer.music.get_pos() + 10
pygame.mixer.music.load("test.wav")
pygame.mixer.music.play(start = forwarded_pos)
play_button = Button(root , text = "Play song" , command = play)
play_button.grid(row = 0 , column = 0)
forward_button = Button(root , text = "Forward song" , command = forward)
forward_button.grid(row = 1 , column = 0 , pady = 10)
mainloop()
As I was continuously getting that error , I tried this:
def forward():
forwarded_pos = pygame.mixer.music.get_pos() + 10
pygame.mixer.music.set_pos(forwarded_pos)
But when I did that, I keep getting another error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\default\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
return self.func(*args)
File "C:\Users\default\PycharmProjects\pythonProject1\main.py", line 13, in forward
pygame.mixer.music.set_pos(forwarded_pos)
pygame.error: set_pos unsupported for this codec
Is there any way to fix this problem?
I think forwarding is not supported in .wav format , so fixing this problem with any other format(except .mp3) will also be ok.
Get_pos and set_pos are triggering the same errors for me. You actually don't need them as you can assign the forwarded_pos when you start playing the music as follows. This doesn't seem to work for .wav but it does for .ogg and .mp3 formats.
import pygame
from os import path
pygame.init()
pygame.mixer.init()
snd_dir = path.join(path.dirname(__file__), "snd")
song = path.join(snd_dir, 'song_name.ogg')
forwarded_pos = 22
mixer = pygame.mixer.music
mixer.load(song)
mixer.play(-1, forwarded_pos)
# doesn't work for wav sounds types
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)

python sys.exit() error builtins.SystemExit:

import sys
def main():
keystr = input("Enter the Key: ")
key = int(keystr)
if (key <=0) or (key>=25):
print("The key is out of range")
sys.exit()
When I want to terminate with input of key (<= 0 or >= 25), there is an error messgae.
The key is out of rangeTraceback (most recent call last):
File "C:/Users/USER/Desktop/caesarRefactored.py", line 38, in <module>
main()
File "C:/Users/USER/Desktop/caesarRefactored.py", line 11, in <module>
sys.exit()
builtins.SystemExit:
How can I fix it?
I'm running this on wing idle, the error shows. If on the terminal, it works just fine.

Unobvious error in python-sfml short example

Getting started with python-sfml. This code
import sfml
window = sfml.RenderWindow(sfml.VideoMode(640, 480), "FooBar")
try:
texture = sfml.Texture.from_file("brick_002.jpg")
sprite = sfml.Sprite(texture)
font = sfml.Font.from_file("arial.ttf")
text = sfml.Text("Math Rocks!")
except IOError:
exit(1)
while window.is_open:
for event in window.events:
if type(event) is sfml.CloseEvent:
window.close()
window.clear()
window.draw(sprite)
window.draw(text)
window.display()
and getting this mistake:
Traceback (most recent call last):
File "sfml.py", line 1, in <module>
import sfml
File "/home/montreal/projects/foo/sfml/sfml.py", line 4, in <module>
window = sfml.RenderWindow(sfml.VideoMode(640, 480), "FooBar")
AttributeError: 'module' object has no attribute 'RenderWindow'
But in interpreter everyting works fine (I can create window, add texture and close it). What can be wrong?

Ncurses start.color() issue

Hello all I am working with ncurses (my first time working with a cli) and I keep getting this error
Traceback (most recent call last):
File "cursesDemo1.py", line 5, in <module>
screen.start_color()
AttributeError: start_color
Here is my code:
import curses
import time
screen = curses.initscr()
screen.start_color()
def maketextbox(h,w,y,x,value="",deco=None,underlineChr=curses.ACS_HLINE,textColorpair=0,decoColorpair=0):
nw = curses.newwin(h,w,y,x)
txtbox = curses.textpad.Textbox(nw)
if deco=="frame":
screen.attron(decoColorpair)
curses.textpad.rectangle(screen,y-1,x-1,y+h,x+w)
screen.attroff(decoColorpair)
elif deco=="underline":
screen.hline(y+1,x,underlineChr,w,decoColorpair)
nw.addstr(0,0,value,textColorpair)
nw.attron(textColorpair)
screen.refresh()
return txtbox
try:
screen.border(0)
box1 = curses.newwin(22, 50, 3, 5)
box1.box()
box2 = curses.newwin(22, 50, 3, 65)
box2.box()
box3 = maketextbox(1,40, 10,20,"foo",deco="underline",textColorpair=curses.color_pair (0),decoColorpair=curses.color_pair(1))
textInput = box3.edit()
It has more errors when I take start_color() out can anyone please advise as to a better course of action? Thanks!!!!
Check manual on curses and be sure to call right methods on right objects.
curses.initscr() Initialize the library. Return a WindowObject which
represents the whole screen.
So, curses.initscr() returns WindowObject but start_color() is in curses module itself. You ought to init colors this way
curses.start_color()

Categories

Resources