Draw Direct Shape Area Color
The ooodev.format.draw.direct.area.Color
class is used to modify the values seen in Fig. 834 of a shape.
Setup
from __future__ import annotations
import uno
from ooodev.format.draw.direct.area import Color as ShapeColor
from ooodev.utils.color import StandardColor
from ooodev.office.draw import Draw
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Draw.create_draw_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
GUI.zoom(GUI.ZoomEnum.ZOOM_75_PERCENT)
slide = Draw.get_slide(doc)
width = 36
height = 36
x = int(width / 2)
y = int(height / 2) + 20
rec = Draw.draw_rectangle(slide=slide, x=x, y=y, width=width, height=height)
style = ShapeColor(color=StandardColor.GREEN_LIGHT2)
style.apply(rec)
f_style = ShapeColor.from_obj(rec)
assert f_style.prop_color == style.prop_color
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
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.draw.direct.area import Color as ShapeColor
# ... other code
rec = Draw.draw_rectangle(slide=slide, x=x, y=y, width=width, height=height)
style = ShapeColor(color=StandardColor.GREEN_LIGHT2)
style.apply(rec)
The results of the setting the shape color can be seen in Fig. 835.
Get Shape Color
We can get the color of the shape by using the ShapeColor.from_obj()
method.
from ooodev.format.draw.direct.area import Color as ShapeColor
# ... other code
# get the color from the shape
f_style = ShapeColor.from_obj(rec)
# assert the color is the same
assert f_style.prop_color == style.prop_color