简体   繁体   English

Python-Curses:如何使用inch方法获取字符的属性

[英]Python - Curses : how to use the inch method to get the attribute of a character

I am learning python and curses. 我正在学习python和curses。 I am at a point where I want to be able to tell if a specific character is either A_BOLD, A_DIM or A_REVERSE etc... So I could eventually change its attribute accordingly (using for example window.chgat(attr)). 我现在想知道某个特定字符是A_BOLD,A_DIM还是A_REVERSE等。因此,我最终可以相应地更改其属性(例如使用window.chgat(attr))。

But I do not know how to retrieve this information. 但我不知道如何检索此信息。

According to the documentation: 根据文档:

window.inch([y, x])¶ window.inch([y,x])¶

Return the character at the given position in the window. 返回窗口中给定位置的字符。 The bottom 8 bits are the character proper, and upper bits are the attributes. 最低的8位是适当的字符,较高的位是属性。

I understand that the information about the character attribute is incorporated within the result from inch and as a matter of fact, printing the character obtained displays it with its attributes as well. 我了解到有关字符属性的信息并入英寸的结果中,事实上,打印获得的字符也会显示其属性。

But Im not fluent enough in computer speak to understand how to use this. 但是我的计算机语言不够流利,无法理解如何使用它。 How do I get and interpret those upper bit?... What should I do, say, to check if the character is printed in bold or not? 我如何获得并解释这些高位?...我应该怎么做才能检查字符是否以粗体显示?

You need to use bitwise operators (eg & ) 您需要使用按位运算符(例如&

attrs = window.inch([y, x])
ch = chr(attrs & 0xFF)
isbold = bool(attrs & curses.A_BOLD)

etc 等等

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

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