xref: /trunk/test/odf-validate/fixtures/t14/note_fill.py (revision 6b2d5951b6f750f12f3c118ea054624213dc0fa7)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22# usage: runpy.sh fixtures/t14/note_fill.py <port> make|resave|edit <outdir>
23# make:   writes <outdir>/note-src.ods, a sheet with a cell note, in the office's current save mode.
24# resave: loads note-src.ods and stores it again as note-resaved-<tag>.ods WITHOUT changing the sheet (Calc then keeps the stream
25#         of the loaded sheet and only registers the note styles from the source, see ScXMLExport::_ExportAutoStyles_).
26# edit:   like resave but changes a cell first, as the control (the sheet is exported from the model).
27import os, sys
28import uno
29from unohelp import FILTERS, connect, desktop, pv
30
31port, phase, out = int(sys.argv[1]), sys.argv[2], os.path.abspath(sys.argv[3])
32tag = sys.argv[4] if len(sys.argv) > 4 else "x"
33os.makedirs(out, exist_ok=True)
34desk = desktop(connect(port))
35src = os.path.join(out, "note-src.ods")
36url = uno.systemPathToFileUrl
37if phase == "make":
38    doc = desk.loadComponentFromURL("private:factory/scalc", "_blank", 0, (pv("Hidden", True),))
39    sh = doc.Sheets.getByIndex(0)
40    sh.getCellByPosition(0, 0).setString("with note")
41    sh.getCellByPosition(1, 2).setString("second note")
42    for col, row, text in ((0, 0, "First note"), (1, 2, "Second note")):
43        addr = sh.getCellByPosition(col, row).CellAddress
44        sh.Annotations.insertNew(addr, text)
45    for i in range(sh.Annotations.Count):
46        an = sh.Annotations.getByIndex(i)
47        print("note", i, "visible", an.IsVisible, "caption fill", an.AnnotationShape.FillStyle.value, an.AnnotationShape.FillColor)
48    if os.path.exists(src):
49        os.remove(src)
50    doc.storeToURL(url(src), (pv("FilterName", FILTERS["ods"]), pv("Overwrite", True)))
51    doc.close(True)
52else:
53    doc = desk.loadComponentFromURL(url(src), "_blank", 0, (pv("Hidden", True),))
54    if phase == "edit":
55        doc.Sheets.getByIndex(0).getCellByPosition(3, 5).setString("changed")
56    dst = os.path.join(out, "note-%s-%s.ods" % (phase, tag))
57    if os.path.exists(dst):
58        os.remove(dst)
59    doc.storeToURL(url(dst), (pv("FilterName", FILTERS["ods"]), pv("Overwrite", True)))
60    doc.close(True)
61    print("stored", dst)
62