Attribute BOLD doesn't seem to work in my curses
I use something like this: screen.addstr(text, color_pair(1) | A_BOLD), but it doesn't seem to work.. However, A_REVERSE and all others attribute does work!
In fact, I'm trying to print something in white, but the COLOR_WHITE prints it gray.. and after a while of searching, it seems that printing it gray + BOLD makes it!
Any helps would be greatly appreciated.
Asked by: Elian879 | Posted: 27-01-2022
Answer 1
Here's an example code (Python 2.6, Linux):
#!/usr/bin/env python
from itertools import cycle
import curses, contextlib, time
@contextlib.contextmanager
def curses_screen():
"""Contextmanager's version of curses.wrapper()."""
try:
stdscr=curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)
try: curses.start_color()
except: pass
yield stdscr
finally:
stdscr.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
if __name__=="__main__":
with curses_screen() as stdscr:
c = curses.A_BOLD
if curses.has_colors():
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
c |= curses.color_pair(1)
curses.curs_set(0) # make cursor invisible
y, x = stdscr.getmaxyx()
for col in cycle((c, curses.A_BOLD)):
stdscr.erase()
stdscr.addstr(y//2, x//2, 'abc', col)
stdscr.refresh()
time.sleep(1)
All seems to be working.
Answered by: Emily985 | Posted: 28-02-2022Answer 2
I tried this: screen.addstr(text, curses.color_pair(1) | curses.A_BOLD)
and it worked!
So just add curses.
and it should do the trick.
Of course at the beginning use: import curses
Similar questions
python - Why aren't all the names in dir(x) valid for attribute access?
Why would a coder stuff things into __dict__ that can't be used for attribute access? For example, in my Plone instance, dir(portal) includes index_html, but portal.index_html raises AttributeError. This is also true for the __class__ attribute of Products.ZCatalog.Catalog.mybrains. Is there a good reason why dir() can't be trusted?
I need a regex for the href attribute for an mp3 file url in python
Based on a previous stack overflow question and contribution by cgoldberg, I came up with this regex using the python re module:
import re
urls = re.finditer('http://(.*?).mp3', htmlcode)
The variable urls is an iterable object and I can use a loop to access each mp3 file url individually if there is more than one :
for url in urls:
mp3fileurl = url.group(0)
python - Attribute Cache in Django - What's the point?
I was just looking over EveryBlock's source code and I noticed this code in the alerts/models.py code:
def _get_user(self):
if not hasattr(self, '_user_cache'):
from ebpub.accounts.models import User
try:
self._user_cache = User.objects.get(id=self.user_id)
except User.DoesNotExist:
self._user_cache = None
return self._user_cache
user = propert...
python - How do I get a value node moved up to be an attribute of its parent node?
What do I need to change so the Name node under FieldRef is an attribute of FieldRef, and not a child node?
Suds currently generates the following soap:
<ns0:query>
<ns0:Where>
<ns0:Eq>
<ns0:FieldRef>
<ns0:Name>_ows_ID</ns0:Name>
</ns0:FieldRef>
<ns0:Value>66</ns0:Value>
</ns0:Eq>
</ns0:Where>
<...
python - how to define a widget in a model attribute
Simply, I write:
# forms.py
class NoteForm(ModelForm):
def __init__(self, *args, **kwargs):
super(NoteForm, self).__init__(*args, **kwargs)
#add attributes to html-field-tag:
self.fields['content'].widget.attrs['rows'] = 3
self.fields['title'].widget.attrs['size'] = 20
class Meta:
model = Note
fields = ('title','content')
To add or modify some attributes to the HT...
python - Getting certain attribute value using XPath
From the following HTML snippet:
<link rel="index" href="/index.php" />
<link rel="contents" href="/getdata.php" />
<link rel="copyright" href="/blabla.php" />
<link rel="shortcut icon" href="/img/all/favicon.ico" />
I'm trying to get the href value of the link tag with rel value = "shortcut icon", I'm trying to achieve that us...
python class attribute
i have a question about class attribute in python.
class base :
def __init__ (self):
pass
derived_val = 1
t1 = base()
t2 = base()
t2.derived_val +=1
t2.__class__.derived_val +=2
print t2.derived_val # its value is 2
print t2.__class__.derived_val # its value is 3
The results are different. I also use id() function to find t2.derived_val
In Python is it bad to create an attribute called 'id'?
I know that there's a function called id so I wouldn't create a function or a variable called id, but what about an attribute on an object?
python - django none type object has no attribute status
I get the following error from Django:
NoneType object has no attribute status_code
Here's a copy of the output from the log:
Environment:
Request Method: GET
Request URL: http://192.168.2.206:8080/institutes_admin/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',...
python - Django ORM: Filter by extra attribute
I want to filter some database objects by a concatenated string.
The normal SQL query would be:
SELECT concat(firstName, ' ', name) FROM person WHERE CONCAT(firstName, ' ', name) LIKE "a%";
In the model, I have created a manager called PersonObjects:
class PersonObjects(Manager):
attrs = {
'fullName': "CONCAT(firstName, ' ', name)"
}
def get...
python - How to assign a new class attribute via __dict__?
I want to assign a class attribute via a string object - but how?
Example:
class test(object):
pass
a = test()
test.value = 5
a.value
# -> 5
test.__dict__['value']
# -> 5
# BUT:
attr_name = 'next_value'
test.__dict__[attr_name] = 10
# -> 'dictproxy' object does not support item assignment
python - Why aren't all the names in dir(x) valid for attribute access?
Why would a coder stuff things into __dict__ that can't be used for attribute access? For example, in my Plone instance, dir(portal) includes index_html, but portal.index_html raises AttributeError. This is also true for the __class__ attribute of Products.ZCatalog.Catalog.mybrains. Is there a good reason why dir() can't be trusted?
django - Python "property object has no attribute" Exception
confirmation = property(_get_confirmation, _set_confirmation)
confirmation.short_description = "Confirmation"
When I try the above I get an Exception I don't quite understand:
AttributeError: 'property' object has no attribute 'short_description'
This was an
python - Sorting a list of objects by attribute
This question already has answers here:
I need a regex for the href attribute for an mp3 file url in python
Based on a previous stack overflow question and contribution by cgoldberg, I came up with this regex using the python re module:
import re
urls = re.finditer('http://(.*?).mp3', htmlcode)
The variable urls is an iterable object and I can use a loop to access each mp3 file url individually if there is more than one :
for url in urls:
mp3fileurl = url.group(0)
python - Share objects with file handle attribute between processes
I have a question about shared resource with file handle between processes.
Here is my test code:
from multiprocessing import Process,Lock,freeze_support,Queue
import tempfile
#from cStringIO import StringIO
class File():
def __init__(self):
self.temp = tempfile.TemporaryFile()
#print self.temp
def read(self):
print "reading!!!"
s = "huanghao is a good boy !!"
...
How can I get the order of an element attribute list using Python xml.sax?
How can I get the order of an element attribute list? It's not totally necessary for the final processing, but it's nice to:
in a filter, not to gratuitously reorder the attribute list
while debugging, print the data in the same order as it appears in the input
Here's my current attribute processor which does a dictionary-like pass over the attributes.
cl...
python - How do I store multiple values in a single attribute
I don't know if I'm thinking of this the right way, and perhaps somebody will set me straight.
Let's say I have a models.py that contains this:
class Order(models.Model):
customer = models.foreignKey(Customer)
total = models.charField(max_length=10)
has_shipped = models.booleanField()
class Product(models.Model):
sku = models.charField(max_length=30)
price = models.charField(max_length=10...
python - How to test if a class attribute is an instance method
In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object.
hasattr returns true regardless of whether the attribute is an instance method or not.
Any suggestions?
For example:
class Test(object):
testdata = 123
def testmetho...
python - Attribute Cache in Django - What's the point?
I was just looking over EveryBlock's source code and I noticed this code in the alerts/models.py code:
def _get_user(self):
if not hasattr(self, '_user_cache'):
from ebpub.accounts.models import User
try:
self._user_cache = User.objects.get(id=self.user_id)
except User.DoesNotExist:
self._user_cache = None
return self._user_cache
user = propert...
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python