python-curses

Which $TERM to use to have both 256 colors and mouse move events in python curses?

為{幸葍}努か 提交于 2020-04-06 08:09:18
问题 Currently if I set the TERM environment variable to 'xterm-1003' I can get mouse move events but I get crappy colors and curses.can_change_color() == False os.environ['TERM'] = 'xterm-1003' ... curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION) ... while True: event = screen.getch() if event == curses.KEY_MOUSE: # I get nice events whenever I move the mouse (no click required) _, mx, my, _, _ = curses.getmouse() and if I set the TERM env var to 'xterm-256color' I get a

Text added to New window is not visible in Curses

给你一囗甜甜゛ 提交于 2020-01-15 18:22:51
问题 I am trying to add a window and a text in this window with curses using this and this: window.addstr("This is a text in a window") Code: class View: def __init__(self, ): self.stdscr = curses.initscr() curses.noecho() curses.cbreak() self.stdscr.keypad(True) # ----------------- self.add_window_and_str() self.add_str() # ----------------- self.stdscr.getkey() curses.endwin() def add_str(self): #just text in standart screen self.stdscr.addstr("test") self.stdscr.refresh() def add_window_and_str

Text added to New window is not visible in Curses

回眸只為那壹抹淺笑 提交于 2020-01-15 18:16:09
问题 I am trying to add a window and a text in this window with curses using this and this: window.addstr("This is a text in a window") Code: class View: def __init__(self, ): self.stdscr = curses.initscr() curses.noecho() curses.cbreak() self.stdscr.keypad(True) # ----------------- self.add_window_and_str() self.add_str() # ----------------- self.stdscr.getkey() curses.endwin() def add_str(self): #just text in standart screen self.stdscr.addstr("test") self.stdscr.refresh() def add_window_and_str

how to enable mouse movement events in python-curses

只愿长相守 提交于 2020-01-15 05:13:08
问题 I want to detect mouse movement events with python-curses. I don't know how to enable these events. I tried to enable all mouse-events as follows: stdscr = curses.initscr() curses.mousemask(curses.REPORT_MOUSE_POSITION | curses.ALL_MOUSE_EVENTS) while True: c = stdscr.getch() if c == curses.KEY_MOUSE: id, x, y, z, bstate = curses.getmouse() stdscr.addstr(curses.LINES-2, 0, "x: " + str(x)) stdscr.addstr(curses.LINES-1, 0, "y: " + str(y)) stdscr.refresh() if c == ord('q'): break curses.endwin()

Standard keys functions in curses module

浪尽此生 提交于 2020-01-13 14:57:51
问题 Have a simple program: import curses import time window = curses.initscr() curses.cbreak() window.nodelay(True) while True: key = window.getch() if key != -1: print key time.sleep(0.01) curses.endwin() How can i turn on mode that doesn't ignore standart Enter, Backspace and Arrows keys functions? or only the way is to add all special characters to elif: if event == curses.KEY_DOWN: #key down function I'm trying modes curses.raw() and other, but there no effect... Please add example if you can

ImportError: No module named '_curses' when trying to import blessings

ぐ巨炮叔叔 提交于 2020-01-12 04:20:09
问题 I am trying to run this: from blessings import Terminal t = Terminal() print (t.bold('Hi there!')) print (t.bold_red_on_bright_green('It hurts my eyes!')) with t.location(0, t.height - 1): print ('This is at the bottom.') Which is the first example here: https://pypi.python.org/pypi/blessings. However, I get this error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\�����\AppData\Local\Programs\Python\Python35- 32\lib\site-packages\blessings\__init__.py"

Python ncurses: Doesn't show screen until first key-press, even though refresh is first

徘徊边缘 提交于 2020-01-04 06:54:19
问题 The code below lets you walk around a small grid on the screen using the arrow keys putting "." where you've explored or been next to. Even though I have my refresh before the first getch (to get a key-stroke) the screen doesn't first display anything until you've moved off your starting position. Shouldn't the addstr followed by refresh immediately show and then the getch waits after that? I even tried adding a stdscr.refresh(), but that didn't help either. How do I get the screen to refresh

Formatting text to fit within a box in Python/Curses

三世轮回 提交于 2020-01-03 02:56:20
问题 Please advise someone how to fix a text panel in curses? My bad result ----- Panel ------ | Lorem ipsum dol or sit amet consec tet uer metus nec eu C urabitur elei fen. | | | ------------------ I want the result ----- Panel ------ | Lorem ipsum do | | lor sit amet | | consectet uer | | metus nec eu C | | urabitur | | eleifen. | ------------------ 回答1: Try with this: from __future__ import division #You don't need this in Python3 from math import * string =

Why does the escape key have a delay in Python curses?

你。 提交于 2020-01-02 01:01:13
问题 In the Python curses module, I have observed that there is a roughly 1-second delay between pressing the esc key and getch() returning. This delay does not seem to occur for other keys. Why does this happen and what can I do about it? Test case: import curses import time def get_delay(window, key): while True: start = time.time() ch = window.getch() end = time.time() if ch == key: return end-start def main(stdscr): stdscr.clear() stdscr.nodelay(1) stdscr.addstr("Press ESC") esc_delay = get

How to make a scrolling menu in python-curses

纵然是瞬间 提交于 2019-12-28 06:50:11
问题 There is a way to make a scrolling menu in python-curses? I have a list of records that I got from a query in sqlite3 and I have to show them in a box but they are more than the max number of rows: can I make a little menu to show them all without making curses crashing? 回答1: This code allows you to create a little menu in a box from a list of strings. You can also use this code getting the list of strings from a sqlite query or from a csv file. To edit the max number of rows of the menu you