Write Direct Shape Area Color
The ooodev.format.writer.direct.shape.area.Color
class is used to modify the values seen in Fig. 834 of a shape.
Setup
import uno
from ooodev.format.writer.direct.shape.area import Color as ShapeColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.office.write import Write
from ooodev.office.draw import Draw
from ooodev.utils.color import StandardColor
def main() -> int:
"""Main Entry Point"""
with Lo.Loader(Lo.ConnectPipe()):
doc = Write.create_doc()
GUI.set_visible(doc=doc)
Lo.delay(300)
GUI.zoom(GUI.ZoomEnum.ENTIRE_PAGE)
style = ShapeColor(color=StandardColor.GREEN_LIGHT2)
page = Write.get_draw_page(doc)
rect = Draw.draw_rectangle(slide=page, x=10, y=10, width=100, height=100)
style.apply(rect)
page.add(rect)
f_style = ShapeColor.from_obj(rect)
assert f_style.prop_color == style.prop_color
Lo.delay(1_000)
Lo.close_doc(doc)
if __name__ == "__main__":
raise SystemExit(main())
Fill Shape Color
Add a fill color to the shape
Adding a fill color to the shape is done by using the ShapeColor
class.
The ShapeColor
class takes a color
as a parameter.
The StandardColor
class is used to set the color of the shape.
from ooodev.format.writer.direct.shape.area import Color as ShapeColor
# ... other code
style = ShapeColor(color=StandardColor.GREEN_LIGHT2)
# get the page
page = Write.get_draw_page(doc)
# draw a rectangle
rect = Draw.draw_rectangle(slide=page, x=10, y=10, width=100, height=100)
# apply the style
style.apply(rect)
# add the rectangle to the page
page.add(rect)
The results of the setting the shape color can be seen in Fig. 1003.
Get Shape Color
We can get the color of the shape by using the ShapeColor.from_obj()
method.
from ooodev.format.writer.direct.shape.area import Color as ShapeColor
# ... other code
# get the color from the shape
f_style = ShapeColor.from_obj(rect)
# assert the color is the same
assert f_style.prop_color == style.prop_color