简体   繁体   English

调整终端大小时,Python 会诅咒窗口闪烁

[英]Python curses window flickering when resizing terminal

This is my first post on stack overflow so I hope I'm doing it properly.这是我关于堆栈溢出的第一篇文章,所以我希望我做得正确。

I am currently working on a Terminal User Interface for python applications .我目前正在为 python 应用程序开发终端用户界面 I know that there are many ready-to-use libraries such as npyscreen out there, but I wantend to create one as programming excercice.我知道有许多现成的库,例如 npyscreen,但我想创建一个作为编程练习。 In particular, I wanted to to play with some architectural patterns to learn them.特别是,我想玩一些架构模式来学习它们。

All that said, I'm currently facing several problems with python curses library , that I'm using as low level interface to the terminal.综上所述,我目前面临着python curses library 的几个问题,我将其用作终端的低级接口。

The problems arise when I try to resize my terminal.当我尝试调整终端大小时会出现问题。 As you can see from the code (see below), I handle the terminal resizing in the main loop, invoking the getmaxyx()() method of my curses window and redrawing what is on the screen accordingly.正如您从代码中看到的(见下文),我在主循环中处理终端调整大小,调用我的 Curses 窗口的 getmaxyx()() 方法并相应地重绘屏幕上的内容。

The problem is that the screen seems to flicker when I try to resize the terminal.问题是当我尝试调整终端大小时,屏幕似乎在闪烁。

Moreover, my "curses application" works fine on MacOS but totally crashes on windows (even after installing windows curses).此外,我的“curses 应用程序”在 MacOS 上运行良好,但在 windows完全崩溃(即使在安装 windows 诅咒之后)。

To handle that I tried to re-write the low-level interfice by using the blessed library.为了解决这个问题,我尝试使用受祝福的库重写低级接口。 It solved the windows crashing problem , but the flickering still remains.解决了windows崩溃问题,但闪烁仍然存在。

I can not figure out what the problem is.我无法弄清楚问题是什么。

Fore those wishing to help me, here follows the github page of the project: Terminal GUI on GitHub对于那些希望帮助我的人,这里是该项目的github 页面GitHub 上的终端 GUI

Thank you in advance.先感谢您。

With curses , there's (at least) 3 things to look for:使用curses ,(至少)有 3 件事需要寻找:

  • ncurses can handle SIGWINCH (PDCurses may not) ncurses 可以处理SIGWINCH (PDCurses 可能不能)

  • some Python configurations interfere with ncurses receiving SIGWINCH .一些 Python 配置会干扰 ncurses 接收SIGWINCH If your program never receives KEY_RESIZE (which it's not checking for...), then it's time to file a bug report for Python to get that fixed.如果您的程序从未收到KEY_RESIZE (它没有检查......),那么是时候为 Python 提交错误报告以修复它。

  • some programs don't actively read keyboard input (and if KEY_RESIZE isn't read , ncurses won't update the screensize. That would make the program crash.某些程序不会主动读取键盘输入(如果未读取KEY_RESIZE ,则 ncurses 不会更新KEY_RESIZE大小。这会使程序崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM