xref: /trunk/test/odf-validate/fixtures/chart-shapes/make.py (revision 0e16a31d78a652c56c5c0fc79c752f48b9048df9)
1# usage: runpy.sh fixtures/chart-shapes/make.py <port> <out.ods>   (office saving ODF 1.2 Extended)
2# Calc chart with additional shapes (polyline, rectangle, text) in the chart draw page.
3import sys, uno
4from unohelp import connect, desktop, pv
5from com.sun.star.awt import Size, Point, Rectangle
6from com.sun.star.table import CellRangeAddress
7
8port, out = int(sys.argv[1]), sys.argv[2]
9d = desktop(connect(port))
10doc = d.loadComponentFromURL("private:factory/scalc", "_blank", 0, (pv("Hidden", True),))
11sh = doc.Sheets.getByIndex(0)
12for r, (a, b) in enumerate(((1, 2), (2, 4), (3, 3))):
13    sh.getCellByPosition(0, r).Value = a
14    sh.getCellByPosition(1, r).Value = b
15rng = CellRangeAddress(); rng.Sheet = 0; rng.StartColumn = 0; rng.StartRow = 0; rng.EndColumn = 1; rng.EndRow = 2
16r = Rectangle(); r.X = 1000; r.Y = 4000; r.Width = 10000; r.Height = 7000
17sh.Charts.addNewByName("c1", r, (rng,), False, False)
18ch = sh.Charts.getByName("c1").EmbeddedObject
19page = ch.DrawPage
20from com.sun.star.awt import Point as P
21def mk(kind, x, y, w, h):
22    s = ch.createInstance(kind)
23    page.add(s)
24    s.Position = Point(x, y); s.Size = Size(w, h)
25    return s
26pl = mk("com.sun.star.drawing.PolyLineShape", 500, 500, 3000, 1500)
27pl.PolyPolygon = ((P(0, 1500), P(1000, 500), P(3000, 0)),)
28mk("com.sun.star.drawing.RectangleShape", 4000, 500, 2000, 1000).String = "rect"
29mk("com.sun.star.drawing.TextShape", 6500, 500, 2000, 800).String = "note"
30doc.storeToURL(uno.systemPathToFileUrl(out), (pv("FilterName", "calc8"),))
31doc.close(True)
32