python-curses

Write an UTF8 character to the last position of the screen with Python curses

我是研究僧i 提交于 2019-12-25 08:21:08
问题 How to write a UTF8 character to the last position (bottom right) of the screen with Python's curses module? The task might look straight forward at first, but it isn't. First of all, Python 2.x is incapable of outputting UTF-8 using curses, so we'll assume Python 3.x here. There are two obvious candidates for doing it: screen.insch(lines - 1, columns - 1, u"\u00a9") This gives an OverflowError: byte doesn't fit in chtype . Bummer. What about: screen.addch(lines - 1, columns - 1, u"\u00a9")

How to extend the curses window class in Python3?

梦想与她 提交于 2019-12-23 04:49:07
问题 I would like to extend the curses built-in window class that is created by calling curses.newwin() . However, I am hard-pressed to find out the actual name of that class that should replace the ¿newwin? placeholder below. #!/usr/bin/python3 import curses class Window(curses.¿newwin?): def __init__(self, title, h, w, y, x): super().__init__(h, w, y, x) self.box() self.hline(2, 1, curses.ACS_HLINE, w-2) self.addstr(1, 2, title) self.refresh() def main(screen): top_win = Window('Top window', 6,

Terminating a process breaks python curses

牧云@^-^@ 提交于 2019-12-21 06:35:21
问题 Using python multiprocessing and curses, it appears that terminating a Process interferes with curses display. For example, in the following code, why does terminating the process stops curses from displaying the text ? (pressing b after pressing a) More precisely, it seems that not only the string "hello" is not displayed anymore but also the whole curses window. import curses from multiprocessing import Process from time import sleep def display(stdscr): stdscr.clear() curses.newwin(0,0)

Unable to install curses (python/windows 10)

老子叫甜甜 提交于 2019-12-13 11:00:10
问题 I have tried to use python -m pip install windows-curses and the error that shows up is: ERROR: Could not find a version that satisfies the requirement windows-curses (from versions: none) I have also tried the method provided by this answer and the same error shows up in my terminal window. How can I install Curses for Python/Windows 10 on my machine? 回答1: What's your Python version? This library works on 2.7 and 3.5+. I have installed here without problems. I have tested in 3.6 and 3.7 and

Bug with refresh in python curses

两盒软妹~` 提交于 2019-12-13 04:55:19
问题 I'm writing a program in curses and sometimes happens that if I leave the program opened and I use other terminal tabs for a while, when I go using the program again it seems like it has refreshed something and something has disappeared... I cannot show pics or screenshots because I haven't understood yet well when and how it happens... Is there a way to prevent or fix this? 回答1: screen.getch reads from stdscr , and if it refreshes (due to any change on the screen), will overwrite boxes . You

python curses remote debugging pdevd error in setupterm

你。 提交于 2019-12-12 06:14:57
问题 Is it possible to debug a curse program remotely in PyCharm? How to set it up? I followed the PyCharm 4.0.8 instruction, added this to the " EXAMPLE.py " from " npyscreen-4.8.7 ". import pydevd pydevd.settrace('localhost', port=8899, stdoutToServer=False, stderrToServer=True) And always it runs into an error in " setupterm ": $ PYTHONPATH=~/bin/pycharm-debug.egg python EXAMPLE.py Traceback (most recent call last): File "EXAMPLE.py", line 34, in <module> App.run() File "/home/.../npyscreen-4.8

Python curses - textpad.Textbox() keyboard input not working with German umlauts

ε祈祈猫儿з 提交于 2019-12-10 17:45:25
问题 I'm trying to use the curses textpad.Textbox() function for text input. Everything is working fine so far, however, some keys don't get recognized, including the section sign (§) and all German umlauts (ä/ö/ü). I guess it's somehow related to the text encoding, but I have no idea how to fix this. My German keyboard layout works perfectly fine with input() . Here is some minimal example: import curses import curses.textpad as textpad try: stdtscr = curses.initscr() curses.cbreak() stdtscr

I need an example of overlapping curses windows using panels in python

寵の児 提交于 2019-12-10 11:14:48
问题 I'm looking for an example on how to use curses.panel to maintain overlapping windows. 回答1: I found this one here https://mail.python.org/pipermail/python-list/2001-April/105015.html . It moves one panel around the screen, below another panel. from time import sleep import curses, curses.panel def make_panel(h,l, y,x, str): win = curses.newwin(h,l, y,x) win.erase() win.box() win.addstr(2, 2, str) panel = curses.panel.new_panel(win) return win, panel def test(stdscr): try: curses.curs_set(0)

Python3 + Curses: How to press “q” for ending program immediately?

放肆的年华 提交于 2019-12-07 07:42:56
问题 When I run the following sample code and press just "q", it'll ends properly, but if I pressed any other characters "for instance many breaks and a lot of other characters" and then press "q" it'll not exit, how can I solve this? import curses, time def main(sc): sc.nodelay(1) while True: sc.addstr(1, 1, time.strftime("%H:%M:%S")) sc.refresh() if sc.getch() == ord('q'): break time.sleep(1) if __name__=='__main__': curses.wrapper(main) 回答1: Pressing other keys cause time.sleep(1) call, you

Python curses not displaying colors, whereas C ncurses works fine

喜你入骨 提交于 2019-12-06 16:17:47
问题 I can't seem to get the Python curses module to display colors, whereas the ncurses C library works fine. Here is a simple script that should work: import curses def main(stdscr): if not curses.has_colors(): raise stdscr.addstr("Hello world\n", curses.color_pair(curses.COLOR_RED)) stdscr.addstr("Press any key to exit.\n") stdscr.refresh() while stdscr.getch() == -1: pass if __name__ == '__main__': curses.wrapper(main) I can only see "Press any key to exit.". I know "Hello world" is being