Draw Direct Shape Area Hatch
The ooodev.format.draw.direct.area.Hatch
class is used to modify the values seen in Fig. 838 of a shape.
Setup
from __future__ import annotations
import uno
from ooodev.format.draw.direct.area import Hatch as ShapeHatch
from ooodev.format.draw.direct.area import PresetHatchKind
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 = ShapeHatch.from_preset(preset=PresetHatchKind.GREEN_30_DEGREES)
style.apply(rec)
f_style = ShapeHatch.from_obj(rec)
assert f_style
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
raise SystemExit(main())
Fig. 838 Area Hatch dialog
Add a hatch to the shape
Adding a hatch for the shape is done by using the ShapeGradient
class.
The ShapeGradient
class has a method from_preset()
takes a preset
as a parameter.
The PresetHatchKind
class is used to get the preset of the hatch.
from ooodev.format.draw.direct.area import Hatch as ShapeHatch
from ooodev.format.draw.direct.area import PresetHatchKind
# ... other code
rec = Draw.draw_rectangle(slide=slide, x=x, y=y, width=width, height=height)
style = ShapeHatch.from_preset(preset=PresetHatchKind.GREEN_30_DEGREES)
style.apply(rec)
The results of the setting the shape hatch can be seen in Fig. 839.
Fig. 839 Shape with hatch
Get Shape Hatch
We can get the hatch of the shape by using the ShapeHatch.from_obj()
method.
from ooodev.format.draw.direct.area import Hatch as ShapeHatch
# ... other code
# get the hatch from the shape
f_style = ShapeHatch.from_obj(rec)
assert f_style