I am trying to make a function that gets an inputted string and returns it with a random colour. (The random colour is defined earlier)
print(Fore.randomColour + inputVariable)
Whenever I try something along those lines, I end up with the error:
AttributeError: 'AnsiFore' object has no attribute 'randomColour'
I have tried using getattr, but I still couldn't get it to work. Any help will be much appreciated. Thanks.
You can make a list with your defined colors and then pick it randomly.
import random
bcolors = ['\033[95m','\033[94m','\033[92m','\033[93m','\033[91m','\033[1m']
print (random.choice(bcolors) + "random color" + '\033[0m')
where '\033[0m' means reset
In my applications i need a font that can have romanian diacritics, so i found a times.ttf file that has them, my problem now is that i can't use italic, bold or boldItalic from it.
Here's my code:
registerFont(TTFont('Times_new', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=0))
registerFont(TTFont('Times_new-Bold', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=1))
registerFont(TTFont('Times_new-Italic', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=2))
registerFont(TTFont('Times_new-BoldItalic', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=3))
registerFontFamily('Times_new', normal='Times_new', bold='Times_new-B', italic='Times_new-I',
boldItalic='Times_new-BI')
styles.add(ParagraphStyle(name="Times", fontName='Times_new'))
styles.add(ParagraphStyle(name="Times-indent-italic", fontName='Times_new-I'))
styles.add(ParagraphStyle(name="Times-center", fontName='Times_new-BI'))
styles.add(ParagraphStyle(name="Times-BoldItalic", fontName='Times_new-BI'))
For example:
If i write
p_text = "Hello"
report.append(Paragraph(p_text, styles["Times-indent-italic"]))
report.append(Spacer(1, 5))
It will write it just like this: Hello, when i expect it like this: Hello. Basically whatever font option i want to use it will use the normal font. Any ideea what i can do?
Are you sure you're referencing the correct filenames? On my system, all the variants are in their own TTF file:
$ locate times | grep ttf
/usr/local/share/fonts/webfonts/times.ttf
/usr/local/share/fonts/webfonts/timesbd.ttf
/usr/local/share/fonts/webfonts/timesbi.ttf
/usr/local/share/fonts/webfonts/timesi.ttf
I see that you only reference 'times.ttf'. Maybe your code should read:
registerFont(TTFont('Times_new', '/usr/share/fonts/truetype/msttcorefonts/times.ttf', subfontIndex=0))
registerFont(TTFont('Times_new-Bold', '/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf', subfontIndex=1))
registerFont(TTFont('Times_new-Italic', '/usr/share/fonts/truetype/msttcorefonts/timesi.ttf', subfontIndex=2))
registerFont(TTFont('Times_new-BoldItalic', '/usr/share/fonts/truetype/msttcorefonts/timesbi.ttf', subfontIndex=3))
Is it possible to get a list of colors used in a plot?
Consider this example:
line1 = ax1.plot(x1,y1)
line2 = ax1.plot(x2,y2)
I now how to set the color
plt.setp(line1,'color','red')
plt.setp(line2,'color','red')
but is there a way how to learn what color has been used? plt.getp(line1,'color') does not work and complains that
AttributeError: 'list' object has no attribute 'get_color'
OK, found an answer: The plot() call returns a list of lines. The correct way to query the color is
print line1[0].get_color()
I am using CKEditor (v3.6.4) and try to find out how to change the palettes for Text Color and Background Color separately.
I found config.colorButton_colors in the docs which allows me to define the color palette. However, this palette is assigned to both, text and background.
How can I have two different palettes?
The best and easy way is, Include required plugin at the download time or link below
Ckeditor Builder
Yes its actually possible. Just dont pick colors from the config but rather do the following in colorbutton/plugin.js:
var textColors = '1ABC9C,2ECC71,3498DB,9B59B6,4E5F70,F1C40F,' +
'16A085,27AE60,2980B9,8E44AD,2C3E50,F39C12,' +
'E67E22,E74C3C,ECF0F1,95A5A6,DDD,FFF,' +
'D35400,C0392B,BDC3C7,7F8C8D,999,000';
var backgroundColors = 'cee8fe,b1d7ff,c7d3f3,dfd6eb,e4cafe,ffbbff,ffbfd2,ff9999,ffdeb3,ffefb0,f4f98a,ffffbb,d3f1a1,bbffbb,bbffff,a6e3dc,c1ebc7,eddec9,f2ebd3,d3eaf2,e1eff3,ffbe61,ffdc61,e1f29d';
var colors = (type == 'back') ? backgroundColors.split(',') : textColors.split(',');
You can't do that because the color palette is defined for the text color and background.
CKEDITOR.config.colorButton_colors =
'000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +
'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +
'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +
'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +
'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';
Or you can change the Text Color plugin :)
What I'd like to do is something like the following:
"define our language struct variables with their default syntax color values
let s:procedural_fg = "Red"
let s:declarative_fg = "Blue"
let s:string_fg = "DarkGray"
...
"Now the actual highlighting directives based on the groups defined elsewhere
hi cyLoops guifg=s:procedural_fg
hi cyConstants guifg=s:declarative_fg
hi cyString guifg=s:string_fg
but VIM won't let me set the guifg values this way ("Error: Cannot allocate color s:procedural_fg" ... and so forth for each variable name). I'd like to define the syntax highlighting this way so that it can be dynamically altered by changing the local variable values and then refreshing the buffer (or whatever it would take to make the new color values apply).
Can this be done in a VIM syntax script? If so, how?
I've already tried several variations:
"define our language struct variables with their default syntax color values
let s:procedural_fg = Red
let s:declarative_fg = Blue
let s:string_fg = DarkGray
...
"Now the actual highlighting directives based on the groups defined elsewhere
hi cyLoops guifg=s:procedural_fg
hi cyConstants guifg=s:declarative_fg
hi cyString guifg=s:string_fg
and
"define our language struct variables with their default syntax color values
let s:procedural_fg = v:Red
let s:declarative_fg = v:Blue
let s:string_fg = v:DarkGray
...
"Now the actual highlighting directives based on the groups defined elsewhere
hi cyLoops guifg=s:procedural_fg
hi cyConstants guifg=s:declarative_fg
hi cyString guifg=s:string_fg
which leads to an error complaining that Red, Blue etc. or v:Red, v:Blue etc. are undefined and/or invalid expressions.
thanks,
CCJ
Use :exec, which is to Vim what eval is to Perl or bash shell:
:exec 'hi cyLoops guifg=' . s:procedural_fg