Write Modify Paragraph Transparency
The ooodev.format.writer.modify.para.transparency.Transparency
and ooodev.format.writer.modify.para.transparency.Gradient
classes are used to modify the transparency values seen in Fig. 1107 of a paragraph style.
Default Paragraph Transparency Style Dialog
Setup
General function used to run these examples.
import uno
from ooodev.format.writer.modify.para.transparency import Transparency, Gradient
from ooodev.format.writer.modify.para.transparency import GradientStyle, IntensityRange
from ooodev.format.writer.modify.para import StyleParaKind
from ooodev.format.writer.modify.para.area import Color as StyleAreaColor
from ooodev.utils.color import StandardColor
from ooodev.write import Write, WriteDoc, ZoomKind
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(Lo.ConnectPipe()):
doc = WriteDoc(Write.create_doc())
doc.set_visible()
Lo.delay(300)
doc.zoom(ZoomKind.ENTIRE_PAGE)
para_kind = StyleParaKind.STANDARD
para_color_style = StyleAreaColor(color=StandardColor.BLUE_LIGHT2, style_name=para_kind)
para_transparency_style = Transparency(value=52, style_name=para_kind)
doc.apply_styles(para_color_style, para_transparency_style)
style_obj = Transparency.from_style(doc=doc.component, style_name=para_kind)
assert style_obj.prop_style_name == str(para_kind)
Lo.delay(1_000)
doc.close_doc()
return 0
if __name__ == "__main__":
raise SystemExit(main())
Transparency
Setting Transparency
Note that we first set a color for the paragraph style. This is because the transparency is not visible unless there is a color.
# ... other code
para_kind = StyleParaKind.STANDARD
para_color_style = StyleAreaColor(color=StandardColor.BLUE_LIGHT2, style_name=para_kind)
para_transparency_style = Transparency(value=52, style_name=para_kind)
doc.apply_styles(para_color_style, para_transparency_style)
Style results.
Getting transparency from a style
# ... other code
style_obj = Transparency.from_style(doc=doc.component, style_name=para_kind)
assert style_obj.prop_style_name == str(para_kind)
Gradient
Setting Gradient
Note that we first set a color for the paragraph style. This is because the gradient is not visible unless there is a color.
# ... other code
para_kind = StyleParaKind.STANDARD
para_color_style = StyleAreaColor(color=StandardColor.BLUE_LIGHT2, style_name=para_kind)
para_gradient_style = Gradient(
style=GradientStyle.LINEAR,
angle=45,
border=22,
grad_intensity=IntensityRange(0, 100),
style_name=para_kind,
)
doc.apply_styles(para_color_style, para_gradient_style)
Style results.
Getting gradient from a style
# ... other code
style_obj = Gradient.from_style(doc=doc.component, style_name=para_kind)
assert style_obj.prop_style_name == str(para_kind)