python-openxml / python-docx

Create and modify Word documents with Python
MIT License
4.59k stars 1.13k forks source link

AttributeError: 'ColorFormat' object has no attribute 'brightness' when using a theme color #665

Open ProgrammerMatt opened 5 years ago

ProgrammerMatt commented 5 years ago

the documentation suggests I should be able to increase or decrease brightness of font when using a theme color:

https://python-docx.readthedocs.io/en/latest/dev/analysis/features/text/font-color.html?highlight=brightness

here is the code in question: obj_charstyle2 = obj_styles.add_style('AddressStyle', WD_STYLE_TYPE.CHARACTER) obj_font2 = obj_charstyle2.font obj_font2.size = Pt(10) obj_font2.name = 'Lucida Calligraphy' obj_font2.color.theme_color = MSO_THEME_COLOR.ACCENT_6 obj_font2.color.brightness = -0.5

scanny commented 5 years ago

@ProgrammerMatt the page you linked to is a design document, which in this case has not yet been fully implemented. You can see the same operation at work in the python-pptx package here: https://github.com/scanny/python-pptx/blob/master/pptx/dml/color.py#L35 . and in more detail here:
https://github.com/scanny/python-pptx/blob/master/pptx/dml/color.py#L130:L152 .
if you want to take a crack at adding it locally for your own use.