[Libreoffice-commits] core.git: scripting/examples

2022-10-07 Thread Rafael Lima (via logerrit)
 scripting/examples/python/InsertText.py |7 +++
 1 file changed, 7 insertions(+)

New commits:
commit 84e9a0056967d5c641ec63bf6a4dc6c0f2798e3d
Author: Rafael Lima 
AuthorDate: Thu Sep 22 16:08:11 2022 +0200
Commit: Hossein 
CommitDate: Fri Oct 7 15:13:27 2022 +0200

tdf#151076 Create callable Python script using InsertText

As reported by the user, if you go to Tools - Macro - Run Macro and select 
the InsertText macro (under Application Macros), you'll get an error.

The reason for this is that the InsertText macro is not meant to be called 
from the Macro Selector since it requires 1 positional argument.

Therefore, this patch creates a simple callable Python macro that uses the 
InsertText funcion, so that this error message no longer happens.

Change-Id: I63f766795bda2d2ae1b95a7c0d8110f41f9fbea2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140384
Tested-by: Jenkins
Tested-by: Hossein 
Reviewed-by: Hossein 

diff --git a/scripting/examples/python/InsertText.py 
b/scripting/examples/python/InsertText.py
index 801b8190860a..d68d538cb5f6 100644
--- a/scripting/examples/python/InsertText.py
+++ b/scripting/examples/python/InsertText.py
@@ -63,3 +63,10 @@ def InsertText(text):
 xSelectionSupplier.select(xTextRange)
 
 i += 1
+
+def InsertHello(event=None):
+# Calls the InsertText function to insert the "Hello" string
+InsertText("Hello")
+
+# Make InsertHello visible by the Macro Selector
+g_exportedScripts = (InsertHello, )


[Libreoffice-commits] core.git: scripting/examples sw/source tools/qa

2021-11-24 Thread Andrea Gelmini (via logerrit)
 scripting/examples/beanshell/Writer/InsertTable.bsh |2 +-
 sw/source/core/doc/docredln.cxx |2 +-
 tools/qa/cppunit/test_urlobj.cxx|2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit ec5788d893e3939bd1d911575a974674f2142b8b
Author: Andrea Gelmini 
AuthorDate: Wed Nov 24 12:17:18 2021 +0100
Commit: Julien Nabet 
CommitDate: Wed Nov 24 18:08:38 2021 +0100

Fix typos and translations

Change-Id: Ic358f008e09718b6f726a55edfe3a3f78bba2942
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125728
Reviewed-by: Julien Nabet 
Tested-by: Jenkins

diff --git a/scripting/examples/beanshell/Writer/InsertTable.bsh 
b/scripting/examples/beanshell/Writer/InsertTable.bsh
index 5117dc1e9363..099c45e6806f 100644
--- a/scripting/examples/beanshell/Writer/InsertTable.bsh
+++ b/scripting/examples/beanshell/Writer/InsertTable.bsh
@@ -22,7 +22,7 @@ if ( oDoc == null )
 XMultiServiceFactory xDocMSF = (XMultiServiceFactory) 
UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc);
 Object oTab = xDocMSF.createInstance("com.sun.star.text.TextTable");
 XTextTable xTextTable = 
(XTextTable)UnoRuntime.queryInterface(XTextTable.class, oTab);
-xTextTable.initialize(4,3); //vier Reihen, drei Spalten
+xTextTable.initialize(4,3); // four rows, three columns
 xTextContent = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, 
xTextTable);
 
 xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index d911ecb85d53..28d7295fe344 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -841,7 +841,7 @@ bool SwRedlineTable::isMoved( size_type rPos ) const
 bDeletePairPaM = true;
 }
 
-// pair at tracked moving: same text by trimming terminatin white 
spaces
+// pair at tracked moving: same text by trimming trailing white spaces
 if ( abs(pPaM->GetText().getLength() - 
pPairPaM->GetText().getLength()) <= 2 &&
 sTrimmed == pPairPaM->GetText().trim() )
 {
diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx
index be605d53d6df..a335701c5cab 100644
--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -295,7 +295,7 @@ namespace tools_urlobj
 }
 
 void testChangeScheme() {
-INetURLObject obj("unkonwn://example.com/foo/bar");
+INetURLObject obj("unknown://example.com/foo/bar");
 CPPUNIT_ASSERT(!obj.HasError());
 obj.changeScheme(INetProtocol::Http);
 CPPUNIT_ASSERT_EQUAL(


[Libreoffice-commits] core.git: scripting/examples scripting/Package_ScriptsBeanShell.mk

2021-11-23 Thread Samuel Mehrbrodt (via logerrit)
 scripting/Package_ScriptsBeanShell.mk |   12 
 scripting/examples/beanshell/Calc/CopyRange.bsh   |   39 ++
 scripting/examples/beanshell/Calc/FixView.bsh |   34 
 scripting/examples/beanshell/Calc/InsertSheet.bsh |   25 
 scripting/examples/beanshell/Calc/ProtectSheet.bsh|   30 ++
 scripting/examples/beanshell/Calc/SelectCell.bsh  |   30 ++
 scripting/examples/beanshell/Calc/parcel-descriptor.xml   |2 
 scripting/examples/beanshell/Writer/ChangeFont.bsh|   36 
 scripting/examples/beanshell/Writer/ChangeParaAdjust.bsh  |   37 +
 scripting/examples/beanshell/Writer/InsertTable.bsh   |   32 +++
 scripting/examples/beanshell/Writer/InsertText.bsh|   28 ++
 scripting/examples/beanshell/Writer/SetText.bsh   |   21 +++
 scripting/examples/beanshell/Writer/parcel-descriptor.xml |2 
 13 files changed, 328 insertions(+)

New commits:
commit acd820a47e90ceb9404f05dbc9f6c040bd7a9fee
Author: Samuel Mehrbrodt 
AuthorDate: Tue Nov 23 09:43:35 2021 +0100
Commit: Samuel Mehrbrodt 
CommitDate: Tue Nov 23 11:11:50 2021 +0100

Add more beanshell samples

For Writer & Calc

Change-Id: I85815acf11b750ec76d138ff8fe72cc4791e9038
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125689
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 

diff --git a/scripting/Package_ScriptsBeanShell.mk 
b/scripting/Package_ScriptsBeanShell.mk
index 212888e602a0..5b7cf42d3b46 100644
--- a/scripting/Package_ScriptsBeanShell.mk
+++ b/scripting/Package_ScriptsBeanShell.mk
@@ -10,6 +10,12 @@
 $(eval $(call 
gb_Package_Package,scripting_ScriptsBeanShell,$(SRCDIR)/scripting/examples))
 
 $(eval $(call 
gb_Package_add_files_with_dir,scripting_ScriptsBeanShell,$(LIBO_SHARE_FOLDER)/Scripts,\
+   beanshell/Calc/CopyRange.bsh \
+   beanshell/Calc/FixView.bsh \
+   beanshell/Calc/InsertSheet.bsh \
+   beanshell/Calc/parcel-descriptor.xml \
+   beanshell/Calc/ProtectSheet.bsh \
+   beanshell/Calc/SelectCell.bsh \
beanshell/Capitalise/capitalise.bsh \
beanshell/Capitalise/parcel-descriptor.xml \
beanshell/HelloWorld/helloworld.bsh \
@@ -22,6 +28,12 @@ $(eval $(call 
gb_Package_add_files_with_dir,scripting_ScriptsBeanShell,$(LIBO_SH
beanshell/MemoryUsage/parcel-descriptor.xml \
beanshell/WordCount/parcel-descriptor.xml \
beanshell/WordCount/wordcount.bsh \
+   beanshell/Writer/ChangeFont.bsh \
+   beanshell/Writer/ChangeParaAdjust.bsh \
+   beanshell/Writer/InsertTable.bsh \
+   beanshell/Writer/InsertText.bsh \
+   beanshell/Writer/parcel-descriptor.xml \
+   beanshell/Writer/SetText.bsh \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/scripting/examples/beanshell/Calc/CopyRange.bsh 
b/scripting/examples/beanshell/Calc/CopyRange.bsh
new file mode 100644
index ..d1e7a49f1b43
--- /dev/null
+++ b/scripting/examples/beanshell/Calc/CopyRange.bsh
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XModel;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.sheet.XCellAddressable;
+import com.sun.star.sheet.XCellRangeAddressable;
+import com.sun.star.table.CellAddress;
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.sheet.XCellRangeMovement;
+
+oDoc = 
UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
+if ( oDoc == null )
+oDoc = XSCRIPTCONTEXT.getDocument();
+
+XSpreadsheetDocument xDoc = (XSpreadsheetDocument) 
UnoRuntime.queryInterface(XSpreadsheetDocument.class,oDoc);
+XSpreadsheets xSheets = xDoc.getSheets();
+XIndexAccess xSheetsIA = UnoRuntime.queryInterface(XIndexAccess.class, 
xSheets);
+XSpreadsheet xSheet = 
UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, 
xSheetsIA.getByIndex(0));
+
+XCellRangeAddressable xAddr1 = 
UnoRuntime.queryInterface(XCellRangeAddressable.class, 
xSheet.getCellRangeByName("A1:A10") );
+CellRangeAddress source = xAddr1.getRangeAddress();
+
+XCellAddressable xAddr2 = UnoRuntime.queryInterface(XCellAddressable.class, 
xSheet.getCellRangeByName("B1").getCellByPosition( 0, 0 ) );
+CellAddress target = xAddr2.getCellAddress();
+
+XCellRangeMovement xCRM = UnoRuntime.queryInterface(XCellRangeMovement.class, 
xSheet);
+xCRM.copyRange(target, source);
+
+return 0;
diff --git a/scripting/examples/beanshell/Calc/FixView.bsh 
b/scripting/examples/beanshell/Calc/FixView.bsh
new file mode 100644
index 0

[Libreoffice-commits] core.git: scripting/examples

2021-01-01 Thread Andrea Gelmini (via logerrit)
 scripting/examples/python/NamedRanges.py  |6 +++---
 scripting/examples/python/SetCellColor.py |2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 9c5f2dc85d0af714058ffc84d86ebc7d5c4dd6a7
Author: Andrea Gelmini 
AuthorDate: Fri Jan 1 16:23:29 2021 +0100
Commit: Julien Nabet 
CommitDate: Fri Jan 1 22:31:36 2021 +0100

Fix typos

Change-Id: I085ff68b4550468eb163d88978c81d8b5335e6ab
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108561
Tested-by: Jenkins
Reviewed-by: Julien Nabet 

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
index f4d4d32a1e05..5a28e2b5da57 100644
--- a/scripting/examples/python/NamedRanges.py
+++ b/scripting/examples/python/NamedRanges.py
@@ -54,7 +54,7 @@ def NamedRanges():
 smgr = ctx.ServiceManager
 desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
 
-# Create a blank spreadsheet document, instead of damanging the existing 
document.
+# Create a blank spreadsheet document, instead of damaging the existing 
document.
 doc = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, 
())
 
 # Create a new sheet to store our output information
@@ -114,11 +114,11 @@ def NamedRanges():
 infoSheet.getCellRangeByName("A8").String = "Sum of test_range1:"
 infoSheet.getCellRangeByName("B8").Formula = "=SUM(test_range1)"
 
-# Calcualte sum of test_range2
+# Calculate sum of test_range2
 infoSheet.getCellRangeByName("A9").String = "Sum of test_range2:"
 infoSheet.getCellRangeByName("B9").Formula = "=SUM(test_range2)"
 
-# Calcualte the difference between the two ranges
+# Calculate the difference between the two ranges
 infoSheet.getCellRangeByName("A10").String = "sum(test_range2) - 
sum(test_range1):"
 infoSheet.getCellRangeByName("B10").Formula = "=B9-B8"
 
diff --git a/scripting/examples/python/SetCellColor.py 
b/scripting/examples/python/SetCellColor.py
index 22d86edbbeff..7319d621dd1a 100644
--- a/scripting/examples/python/SetCellColor.py
+++ b/scripting/examples/python/SetCellColor.py
@@ -38,7 +38,7 @@ def SetCellColor():
 
 # Call the above helper function to set color (in hex number).
 # To get the hex number:
-#1. go to Calc, click toolbar dropdown "Background Color" > Custome 
Color;
+#1. go to Calc, click toolbar dropdown "Background Color" > Custom 
Color;
 #2. Pick a color, copy the hex number and prefix it with "0x".
 _SetCellColor(sheet, "C3:C21",0x4021c9)
 _SetCellColor(sheet, "D18:E21",   0x4021c9)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2020-12-31 Thread Kevin Suo (via logerrit)
 scripting/examples/python/NamedRanges.py |   10 --
 1 file changed, 10 deletions(-)

New commits:
commit 6b57cfb71a9546c32c03848751181b2db4f47176
Author: Kevin Suo 
AuthorDate: Thu Dec 31 21:49:19 2020 +0800
Commit: Noel Grandin 
CommitDate: Fri Jan 1 07:37:47 2021 +0100

tdf#128463: Revert the change to license information

per comment by Tor Lillqvist in:
https://bugs.documentfoundation.org/show_bug.cgi?id=128463#c18

The Apache part of the license was added by commit
8c9cc54bd7b6f3ba723d7a42ccc6a5372a80f970 due to misunderstanding.

Change-Id: I861e7b13e1900de9287c768a4da8740fdb2e517f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108537
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
index f307d9644ffd..f4d4d32a1e05 100644
--- a/scripting/examples/python/NamedRanges.py
+++ b/scripting/examples/python/NamedRanges.py
@@ -5,16 +5,6 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
-# This file incorporates work covered by the following license notice:
-#
-#   Licensed to the Apache Software Foundation (ASF) under one or more
-#   contributor license agreements. See the NOTICE file distributed
-#   with this work for additional information regarding copyright
-#   ownership. The ASF licenses this file to you under the Apache
-#   License, Version 2.0 (the "License"); you may not use this file
-#   except in compliance with the License. You may obtain a copy of
-#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-#
 import uno
 from com.sun.star.container import NoSuchElementException
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2020-12-30 Thread Kevin Suo (via logerrit)
 scripting/examples/python/NamedRanges.py |  174 ++-
 1 file changed, 127 insertions(+), 47 deletions(-)

New commits:
commit 8c9cc54bd7b6f3ba723d7a42ccc6a5372a80f970
Author: Kevin Suo 
AuthorDate: Thu Dec 31 10:46:45 2020 +0800
Commit: Noel Grandin 
CommitDate: Thu Dec 31 08:47:32 2020 +0100

tdf#128463: Rewrite NamedRanges.py to make it work when run from UI

This commit:
1. Updated the license header;
2. Added docstrings and notes to help the users to understand the API and 
code.
3. Make the code to create a new sheet named "data", define named ranges in 
it,
   modify the named range, define another named range, fill values in the 
cells
   related to the named ranges, the calcualte sum of each named range, and 
also
   calculate the difference between the two named ranges. The results are 
stored
   in the sheet named "information".
4. Cell alignment and background color methods are also used in this 
example.
5. Only show the parent function in the UI.

Change-Id: Iba6111dc3754f054deeb0baf902dbff1eb3bfa2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108530
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
index 0e47cb406745..f307d9644ffd 100644
--- a/scripting/examples/python/NamedRanges.py
+++ b/scripting/examples/python/NamedRanges.py
@@ -1,4 +1,3 @@
-# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
 #
 # This file is part of the LibreOffice project.
 #
@@ -6,59 +5,140 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
-
-import traceback
+# This file incorporates work covered by the following license notice:
+#
+#   Licensed to the Apache Software Foundation (ASF) under one or more
+#   contributor license agreements. See the NOTICE file distributed
+#   with this work for additional information regarding copyright
+#   ownership. The ASF licenses this file to you under the Apache
+#   License, Version 2.0 (the "License"); you may not use this file
+#   except in compliance with the License. You may obtain a copy of
+#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
 import uno
+from com.sun.star.container import NoSuchElementException
+
+def DefineNamedRange(doc, SheetName, rangeName, rangeReference):
+"""Defines a new named range. If the named range exists in the document, 
then
+update the rangeReference.
 
+Example: DefineNamedRange(doc, "Sheet1", "test_range", '$A$1:$F$14').
 
-def GetNamedRanges():
-"""Returns a list of the named ranges in the document.
+API Reference:
+
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1sheet_1_1XNamedRanges.html
 """
+aName = rangeName
+# make sure the sheet name starts with "$"
+sheetName = "$" + SheetName.replace("$", "")
+aContent = sheetName + "." + rangeReference
+
 try:
-desktop = XSCRIPTCONTEXT.getDesktop()
-model = desktop.getCurrentComponent()
-rangeNames = model.NamedRanges.ElementNames
-result = []
-for i in rangeNames:
-range = model.NamedRanges.getByName(i).Content
-result.append((i, range))
-return result
-except Exception as e:
-print("Caught Exception: " + str(e))
-tb = e.__traceback__
-traceback.print_tb(tb)
-return None
-
-
-def DefineNamedRange(sheet, x0, y0, width, height, name):
-"""Defines a new (or replaces an existing) named range on a sheet,
-using zero-based absolute coordinates
-"""
-desktop = XSCRIPTCONTEXT.getDesktop()
-model = desktop.getCurrentComponent()
-# FIXME: Is there some Python-callable API to turn a row and column into 
an A1 string?
-# This obviously works only for the first 26 columns.
-abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-content = "$" + sheet + "." + "$" + \
-abc[x0: x0+1] + "$" + str(y0+1) + ":" + "$" + abc[x0+width -
-  1: x0+width] + "$" + 
str(y0+height)
-position = uno.createUnoStruct('com.sun.star.table.CellAddress')
-position.Sheet = 0
-position.Column = 0
-position.Row = 0
-model.NamedRanges.addNewByName(name, content, position, 0)
-return None
+# If the named range exists, then update it
+doc.NamedRanges.getByName(rangeName)
+update = True
+except NoSuchElementException:
+update = False
 
+if update:
+doc.NamedRanges.getByName(rangeName).setContent(aContent)
+else:
+aPosition = uno.createUnoStruct('com.sun.star.table.CellAddress')
+sheet = doc.Sheets.getByName(SheetName)
+# the index of the sheet in the doc, 0-based
+aPosition.Sheet = sheet.getRangeAddress().Sheet
+
+addressObj = sheet.getCe

[Libreoffice-commits] core.git: scripting/examples

2020-12-30 Thread Kevin Suo (via logerrit)
 scripting/examples/python/SetCellColor.py |   47 +++---
 1 file changed, 31 insertions(+), 16 deletions(-)

New commits:
commit 97d51446052acb5465c7ebe0ba3ce4d4570d25b0
Author: Kevin Suo 
AuthorDate: Thu Dec 31 10:28:38 2020 +0800
Commit: Noel Grandin 
CommitDate: Thu Dec 31 08:46:15 2020 +0100

tdf#128463: Make SetCellColor python example actually do sth

The previous one, when run from within the application, gives a
runtime exception.

This commit rewrites this example to:
1. Hide the private function from the UI;
2. Create a new blank Calc file instead of operating directly in the 
existing file;
3. Set cell colors to draw a "LO" picture in the sheet.
4. Added docstrings and API reference links.

Change-Id: I120a3ede0629a5657fec18f1b0909dfc4bc7ad1c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104720
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/scripting/examples/python/SetCellColor.py 
b/scripting/examples/python/SetCellColor.py
index 4229d9914f6a..22d86edbbeff 100644
--- a/scripting/examples/python/SetCellColor.py
+++ b/scripting/examples/python/SetCellColor.py
@@ -15,24 +15,39 @@
 #   except in compliance with the License. You may obtain a copy of
 #   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 #
+import uno
 
-def SetCellColor(x, y, color):
-"""Sets the background of the cell at (x,y) (zero-based column and row
-   indices, for example (2,3) == C4) on the first sheet and
-   returns the contents of the cell as a string.
-"""
-# Get the doc from the scripting context which is made available to
-# all scripts.
-desktop = XSCRIPTCONTEXT.getDesktop()
-model = desktop.getCurrentComponent()
+def _SetCellColor(sheet, cellRange, color):
+"""Sets the background of 'cellRange' in 'sheet', to 'color'."""
+# 
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1table_1_1XCellRange.html#a92c77dc3025ac50d55bf31bc80ab118f
+cells = sheet.getCellRangeByName(cellRange)
 
-# Check whether there's already an opened document.
-if not hasattr(model, "Sheets"):
-return ""
+# 
https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1table_1_1CellProperties.html
+cells.CellBackColor = color
 
-sheet = model.Sheets.Sheet1
-cell = sheet.getCellByPosition(x, y)
+def SetCellColor():
+ctx = uno.getComponentContext()
+smgr = ctx.ServiceManager
+desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
 
-cell.CellBackColor = color
+# Create a blank spreadsheet document, instead of operating on the 
existing one
+doc = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, 
())
 
-return cell.String
+# Select the first sheet in the spreadsheet (0-index based).
+sheet = doc.Sheets[0]
+
+# Call the above helper function to set color (in hex number).
+# To get the hex number:
+#1. go to Calc, click toolbar dropdown "Background Color" > Custome 
Color;
+#2. Pick a color, copy the hex number and prefix it with "0x".
+_SetCellColor(sheet, "C3:C21",0x4021c9)
+_SetCellColor(sheet, "D18:E21",   0x4021c9)
+_SetCellColor(sheet, "G3:G21",0x4021c9)
+_SetCellColor(sheet, "H3:I5", 0x4021c9)
+_SetCellColor(sheet, "I6:I21",0x4021c9)
+_SetCellColor(sheet, "H19:H21",   0x4021c9)
+
+# You should get a nice "LO" in the spreadsheet!
+
+# Only the specified function will show in the Tools > Macro > Organize Macro 
dialog:
+g_exportedScripts = (SetCellColor,)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples scripting/Package_ScriptsPython.mk

2020-10-10 Thread Kevin Suo (via logerrit)
 scripting/Package_ScriptsPython.mk |2 
 scripting/examples/python/Capitalise.py|  102 +++--
 scripting/examples/python/HelloWorld.py|   25 ++-
 scripting/examples/python/InsertText.py|   46 +++--
 scripting/examples/python/NamedRanges.py   |7 
 scripting/examples/python/SetCellColor.py  |   27 +++
 scripting/examples/python/TableSample.py   |  131 +
 scripting/examples/python/pythonSamples/TableSample.py |  116 ---
 8 files changed, 264 insertions(+), 192 deletions(-)

New commits:
commit 5fb0e0f68bc9d37d43e0782b903919630852904c
Author: Kevin Suo 
AuthorDate: Sat Oct 10 14:43:55 2020 +0800
Commit: Thorsten Behrens 
CommitDate: Sat Oct 10 14:11:27 2020 +0200

Improve example python code in scripting.

* Modified the code to be more pythonic.
* If "len(theString) == 0", then "not theString" evaluates to True.
* "theString[0].isupper()" and "theString[1].isupper()" can be combined.
* Remove unused imported string module
* Wrap long lines
* run autopep8 to prettify
* ...

Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104136
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/scripting/Package_ScriptsPython.mk 
b/scripting/Package_ScriptsPython.mk
index 0c48839ca42d..9d401d38349b 100644
--- a/scripting/Package_ScriptsPython.mk
+++ b/scripting/Package_ScriptsPython.mk
@@ -15,7 +15,7 @@ $(eval $(call 
gb_Package_add_files_with_dir,scripting_ScriptsPython,$(LIBO_SHARE
python/InsertText.py \
python/NamedRanges.py \
python/SetCellColor.py \
-   python/pythonSamples/TableSample.py \
+   python/TableSample.py \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/scripting/examples/python/Capitalise.py 
b/scripting/examples/python/Capitalise.py
index 05e82a37ad32..64d29a51343a 100644
--- a/scripting/examples/python/Capitalise.py
+++ b/scripting/examples/python/Capitalise.py
@@ -16,61 +16,77 @@
 #   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 #
 
-# helper function
-def getNewString( theString ) :
-if( not theString or len(theString) ==0) :
+def getNewString(theString):
+"""helper function
+"""
+if (not theString):
 return ""
+
 # should we tokenize on "."?
-if theString[0].isupper() and len(theString)>=2 and theString[1].isupper() 
:
-# first two chars are UC => first UC, rest LC
-newString=theString[0:1].upper() + theString[1:].lower();
+if len(theString) >= 2 and theString[:2].isupper():
+# first two chars are UC => first UC, rest LC
+newString = theString[0].upper() + theString[1:].lower()
+
 elif theString[0].isupper():
-# first char UC => all to LC
-newString=theString.lower()
-else: # all to UC.
-newString=theString.upper()
-return newString;
+# first char UC => all to LC
+newString = theString.lower()
+
+else:
+# all to UC.
+newString = theString.upper()
 
-def capitalisePython( ): 
-"""Change the case of a selection, or current word from upper case, to 
first char upper case, to all lower case to upper case..."""
-import string
+return newString
 
+
+def capitalisePython():
+"""Change the case of the selected or current word(s).
+If at least the first two characters are "UPpercase, then it is changed
+to first char "Uppercase".
+If the first character is "Uppercase", then it is changed to
+all "lowercase".
+Otherwise, all are changed to "UPPERCASE".
+"""
 # The context variable is of type XScriptContext and is available to
 # all BeanShell scripts executed by the Script Framework
 xModel = XSCRIPTCONTEXT.getDocument()
 
-#the writer controller impl supports the css.view.XSelectionSupplier 
interface
+# the writer controller impl supports the css.view.XSelectionSupplier
+# interface
 xSelectionSupplier = xModel.getCurrentController()
 
-#see section 7.5.1 of developers' guide
+# see section 7.5.1 of developers' guide
 xIndexAccess = xSelectionSupplier.getSelection()
-count = xIndexAccess.getCount();
-if(count>=1):  #ie we have a selection
-i=0
-while i < count :
-xTextRange = xIndexAccess.getByIndex(i);
-#print "string: " + xTextRange.getString();
-theString = xTextRange.getString();
-if len(theString)==0 :
-# sadly we can have a selection where nothing is selected
-# in this case we get the XWordCursor and make a selection!
-xText = xTextRange.getText();
-xWordCursor = xText.createTextCursorByRange(xTextRange);
-if not xWordCursor.isStartOfWord():
-xWordCursor.gotoStartOfWord(False);
-xWordCursor.got

[Libreoffice-commits] core.git: scripting/examples

2019-06-05 Thread Ashod Nakashian (via logerrit)
 scripting/examples/python/InsertText.py |   61 
 1 file changed, 61 insertions(+)

New commits:
commit c7c188c745ff054f5ba1e7939a4fa7ec92be9708
Author: Ashod Nakashian 
AuthorDate: Fri Jul 27 00:18:09 2018 -0400
Commit: Jan Holesovsky 
CommitDate: Wed Jun 5 11:28:37 2019 +0200

python: add sample python script to insert/replace text

Change-Id: Idde3cd22ecc1f1bd34f7519acedc85584ed2deaf
Reviewed-on: https://gerrit.libreoffice.org/58160
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 
Reviewed-on: https://gerrit.libreoffice.org/73477
Tested-by: Jenkins

diff --git a/scripting/examples/python/InsertText.py 
b/scripting/examples/python/InsertText.py
new file mode 100644
index ..e04874d52b0a
--- /dev/null
+++ b/scripting/examples/python/InsertText.py
@@ -0,0 +1,61 @@
+# HelloWorld python script for the scripting framework
+
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+#   Licensed to the Apache Software Foundation (ASF) under one or more
+#   contributor license agreements. See the NOTICE file distributed
+#   with this work for additional information regarding copyright
+#   ownership. The ASF licenses this file to you under the Apache
+#   License, Version 2.0 (the "License"); you may not use this file
+#   except in compliance with the License. You may obtain a copy of
+#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+def InsertText(text):
+"""Inserts the argument string into the current document.
+   If there is a selection, the selection is replaced by it."""
+
+# Get the doc from the scripting context which is made available to all 
scripts
+desktop = XSCRIPTCONTEXT.getDesktop()
+model = desktop.getCurrentComponent()
+
+# Check whether there's already an opened document.
+if not hasattr(model, "Text"):
+return
+
+# The context variable is of type XScriptContext and is available to
+# all BeanShell scripts executed by the Script Framework
+xModel = XSCRIPTCONTEXT.getDocument()
+
+#the writer controller impl supports the css.view.XSelectionSupplier 
interface
+xSelectionSupplier = xModel.getCurrentController()
+
+#see section 7.5.1 of developers' guide
+xIndexAccess = xSelectionSupplier.getSelection()
+count = xIndexAccess.getCount();
+if count >= 1:  #ie we have a selection
+i = 0
+
+while i < count:
+xTextRange = xIndexAccess.getByIndex(i);
+theString = xTextRange.getString();
+if not len(theString):
+# Nothing really selected; just insert.
+xText = xTextRange.getText();
+xWordCursor = xText.createTextCursorByRange(xTextRange);
+xWordCursor.setString(text);
+xSelectionSupplier.select(xWordCursor);
+else:
+# Replace the selection.
+xTextRange.setString(text);
+xSelectionSupplier.select(xTextRange);
+
+i += 1
+
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: scripting/examples scripting/java

2019-02-18 Thread Libreoffice Gerrit user
 scripting/examples/beanshell/Highlight/ButtonPressHandler.bsh| 
   2 +-
 scripting/java/com/sun/star/script/framework/provider/beanshell/template.bsh | 
   2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 9fe1eefe256c30ea6bb207d4068e815ebdc04efe
Author: Samuel Mehrbrodt 
AuthorDate: Mon Feb 18 08:19:23 2019 +0100
Commit: Samuel Mehrbrodt 
CommitDate: Mon Feb 18 09:22:07 2019 +0100

Fix product name

Change-Id: I35ac8f6ad54c7990bd5fb24dc0a30ebb8e1e8254
Reviewed-on: https://gerrit.libreoffice.org/67949
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 

diff --git a/scripting/examples/beanshell/Highlight/ButtonPressHandler.bsh 
b/scripting/examples/beanshell/Highlight/ButtonPressHandler.bsh
index d9c8ee32ccc3..ac6efacce5d3 100644
--- a/scripting/examples/beanshell/Highlight/ButtonPressHandler.bsh
+++ b/scripting/examples/beanshell/Highlight/ButtonPressHandler.bsh
@@ -119,5 +119,5 @@ else
 replaceable.replaceAll(descriptor);
 }
 
-// BeanShell OpenOffice.org scripts should always return 0
+// BeanShell scripts in LibreOffice should always return 0
 return 0;
diff --git 
a/scripting/java/com/sun/star/script/framework/provider/beanshell/template.bsh 
b/scripting/java/com/sun/star/script/framework/provider/beanshell/template.bsh
index a0c49a2e240c..3bf6d22a3c47 100644
--- 
a/scripting/java/com/sun/star/script/framework/provider/beanshell/template.bsh
+++ 
b/scripting/java/com/sun/star/script/framework/provider/beanshell/template.bsh
@@ -61,5 +61,5 @@ xText = xTextDoc.getText();
 xTextRange = xText.getEnd();
 xTextRange.setString( "Hello World (in BeanShell)" );
 
-// BeanShell OpenOffice.org scripts should always return 0
+// BeanShell scripts in LibreOffice should always return 0
 return 0;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: scripting/examples

2018-12-09 Thread Libreoffice Gerrit user
 scripting/examples/beanshell/WordCount/wordcount.bsh |   69 +--
 1 file changed, 35 insertions(+), 34 deletions(-)

New commits:
commit 207045ae594753691f1bfd130177cc6abeb08a06
Author: Matthias Seidel 
AuthorDate: Fri Dec 7 23:54:02 2018 +
Commit: Caolán McNamara 
CommitDate: Sun Dec 9 21:56:19 2018 +0100

Fixed typo, deleted whitespace

(cherry picked from commit 31df7841adbd74c9f32cc5cfce86c148d365e01f)

Change-Id: I0f7575544f24142cf27edd4002c09b316f679367
Reviewed-on: https://gerrit.libreoffice.org/64850
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/scripting/examples/beanshell/WordCount/wordcount.bsh 
b/scripting/examples/beanshell/WordCount/wordcount.bsh
index 5772343b7b33..b068d8a7d374 100644
--- a/scripting/examples/beanshell/WordCount/wordcount.bsh
+++ b/scripting/examples/beanshell/WordCount/wordcount.bsh
@@ -15,7 +15,8 @@
  *   except in compliance with the License. You may obtain a copy of
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
-// Provides a word count of the selected text in A Writer document.
+
+//Provides a word count of the selected text in a Writer document.
 import com.sun.star.uno.UnoRuntime;
 import com.sun.star.frame.XModel;
 import com.sun.star.view.XSelectionSupplier;
@@ -26,55 +27,55 @@ import com.sun.star.script.provider.XScriptContext;
 
 // display the count in a Swing dialog
 void doDisplay(numWords) {
-wordsLabel = new JLabel("Word count = " + numWords);
-closeButton = new JButton("Close");
-frame = new JFrame("Word Count");
-closeButton.addActionListener(new ActionListener() {
-actionPerformed(ActionEvent e) {
-frame.setVisible(false);
-}
-});
-frame.getContentPane().setLayout(new BorderLayout());
-frame.getContentPane().add(wordsLabel, BorderLayout.CENTER);
-frame.getContentPane().add(closeButton, BorderLayout.SOUTH);
-frame.pack();
-frame.setSize(190,90);
-frame.setLocation(430,430);
-frame.setVisible(true);
+   wordsLabel = new JLabel("Word count = " + numWords);
+   closeButton = new JButton("Close");
+   frame = new JFrame("Word Count");
+   closeButton.addActionListener(new ActionListener() {
+   actionPerformed(ActionEvent e) {
+   frame.setVisible(false);
+   }
+   });
+   frame.getContentPane().setLayout(new BorderLayout());
+   frame.getContentPane().add(wordsLabel, BorderLayout.CENTER);
+   frame.getContentPane().add(closeButton, BorderLayout.SOUTH);
+   frame.pack();
+   frame.setSize(190,90);
+   frame.setLocation(430,430);
+   frame.setVisible(true);
 }
 
 int wordcount() {
 
-result = 0;
+   result = 0;
 
-// iterate through each of the selections
-count = xIndexAccess.getCount();
-for(i=0;ihttps://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2018-05-09 Thread Tor Lillqvist
 scripting/examples/python/NamedRanges.py |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 79fa6ac73caeae089d255c6b8629075364b4a477
Author: Tor Lillqvist 
Date:   Wed May 9 15:11:20 2018 +0300

Use the . separator between sheet name and cell range instead of ! to match 
UI

Also put a dollar in front of the sheet name.

Change-Id: I93d610dad8ad085718b0fe389e460b588939e5d2

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
index b699f286fc26..34307ae8440c 100644
--- a/scripting/examples/python/NamedRanges.py
+++ b/scripting/examples/python/NamedRanges.py
@@ -37,7 +37,7 @@ def DefineNamedRange(sheet, x0, y0, width, height, name):
 # FIXME: Is there some Python-callable API to turn a row and column into 
an A1 string?
 # This obviously works only for the first 26 columns.
 abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-content = sheet +"!" + "$" + abc[x0 : x0+1] + "$" + str(y0+1) + ":" + "$" 
+ abc[x0+width-1 : x0+width] + "$" + str(y0+height)
+content = "$" + sheet + "." + "$" + abc[x0 : x0+1] + "$" + str(y0+1) + ":" 
+ "$" + abc[x0+width-1 : x0+width] + "$" + str(y0+height)
 position = uno.createUnoStruct('com.sun.star.table.CellAddress')
 position.Sheet = 0
 position.Column = 0
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2018-03-28 Thread Tor Lillqvist
 scripting/examples/python/NamedRanges.py |   11 +++
 1 file changed, 11 insertions(+)

New commits:
commit 850b401ebad13d20481f3ed01990c8070a33f6f1
Author: Tor Lillqvist 
Date:   Wed Mar 28 17:02:28 2018 +0300

Add mode lines and license blurb

Change-Id: Ifc319e6954665b71f8a98d6ec849a71bbf2b7318

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
index 812cabb583e0..b699f286fc26 100644
--- a/scripting/examples/python/NamedRanges.py
+++ b/scripting/examples/python/NamedRanges.py
@@ -1,3 +1,12 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
 import traceback
 import uno
 
@@ -46,3 +55,5 @@ def DeleteNamedRange(name):
 tb = e.__traceback__
 traceback.print_tb(tb)
 return None
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2018-03-28 Thread Tor Lillqvist
 scripting/examples/python/NamedRanges.py |   11 +++
 1 file changed, 11 insertions(+)

New commits:
commit f21e341d0fbfb39f7d5d976f89f00f844e201576
Author: Tor Lillqvist 
Date:   Wed Mar 28 16:52:28 2018 +0300

Add DeleteNamedRange function

Change-Id: I081614cb34aee704c9162f58c78dbaa6a350d30b

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
index abdef141f397..812cabb583e0 100644
--- a/scripting/examples/python/NamedRanges.py
+++ b/scripting/examples/python/NamedRanges.py
@@ -35,3 +35,14 @@ def DefineNamedRange(sheet, x0, y0, width, height, name):
 position.Row = 0
 model.NamedRanges.addNewByName(name, content, position, 0)
 return None
+
+def DeleteNamedRange(name):
+try:
+desktop = XSCRIPTCONTEXT.getDesktop()
+model = desktop.getCurrentComponent()
+model.NamedRanges.removeByName(name)
+except Exception as e:
+print("Caught Exception: " + str(e))
+tb = e.__traceback__
+traceback.print_tb(tb)
+return None
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2018-03-27 Thread Tor Lillqvist
 scripting/examples/python/NamedRanges.py |   37 +++
 1 file changed, 37 insertions(+)

New commits:
commit e32b4c8a079e4b51b1028d2467b872ff5b8cdd3a
Author: Tor Lillqvist 
Date:   Fri Jan 19 18:00:46 2018 +0200

Add another sample Python script, to handle named ranges in spreadsheets

Change-Id: Ibe11ab2c3513a05b9aec574602b24df70270908c
Reviewed-on: https://gerrit.libreoffice.org/51968
Tested-by: Jenkins 
Reviewed-by: Tor Lillqvist 

diff --git a/scripting/examples/python/NamedRanges.py 
b/scripting/examples/python/NamedRanges.py
new file mode 100644
index ..abdef141f397
--- /dev/null
+++ b/scripting/examples/python/NamedRanges.py
@@ -0,0 +1,37 @@
+import traceback
+import uno
+
+def GetNamedRanges():
+"""Returns a list of the named ranges in the document.
+"""
+try:
+desktop = XSCRIPTCONTEXT.getDesktop()
+model = desktop.getCurrentComponent()
+rangeNames = model.NamedRanges.ElementNames
+result = []
+for i in rangeNames:
+range = model.NamedRanges.getByName(i).Content
+result.append((i, range))
+return result
+except Exception as e:
+print("Caught Exception: " + str(e))
+tb = e.__traceback__
+traceback.print_tb(tb)
+return None
+
+def DefineNamedRange(sheet, x0, y0, width, height, name):
+"""Defines a new (or replaces an existing) named range on a sheet,
+using zero-based absolute coordinates
+"""
+desktop = XSCRIPTCONTEXT.getDesktop()
+model = desktop.getCurrentComponent()
+# FIXME: Is there some Python-callable API to turn a row and column into 
an A1 string?
+# This obviously works only for the first 26 columns.
+abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+content = sheet +"!" + "$" + abc[x0 : x0+1] + "$" + str(y0+1) + ":" + "$" 
+ abc[x0+width-1 : x0+width] + "$" + str(y0+height)
+position = uno.createUnoStruct('com.sun.star.table.CellAddress')
+position.Sheet = 0
+position.Column = 0
+position.Row = 0
+model.NamedRanges.addNewByName(name, content, position, 0)
+return None
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples scripting/Package_ScriptsPython.mk

2018-03-27 Thread Tor Lillqvist
 scripting/Package_ScriptsPython.mk|1 +
 scripting/examples/python/SetCellColor.py |   15 +++
 2 files changed, 16 insertions(+)

New commits:
commit aa27a25d152ab70f60fedcea3bd4cd99d68103a0
Author: Tor Lillqvist 
Date:   Thu Jan 18 18:27:50 2018 +0200

Add another sample Python script

Change-Id: I542a8b36a097d8961dc76fdcc3d25a3d7b6eb526
Reviewed-on: https://gerrit.libreoffice.org/51966
Tested-by: Jenkins 
Reviewed-by: Tor Lillqvist 

diff --git a/scripting/Package_ScriptsPython.mk 
b/scripting/Package_ScriptsPython.mk
index 1d0de559bd20..8cc8a85472ff 100644
--- a/scripting/Package_ScriptsPython.mk
+++ b/scripting/Package_ScriptsPython.mk
@@ -12,6 +12,7 @@ $(eval $(call 
gb_Package_Package,scripting_ScriptsPython,$(SRCDIR)/scripting/exa
 $(eval $(call 
gb_Package_add_files_with_dir,scripting_ScriptsPython,$(LIBO_SHARE_FOLDER)/Scripts,\
python/Capitalise.py \
python/HelloWorld.py \
+   python/SetCellColor.py \
python/pythonSamples/TableSample.py \
 ))
 
diff --git a/scripting/examples/python/SetCellColor.py 
b/scripting/examples/python/SetCellColor.py
new file mode 100644
index ..743a6daa948b
--- /dev/null
+++ b/scripting/examples/python/SetCellColor.py
@@ -0,0 +1,15 @@
+def SetCellColor(x, y, color):
+"""Sets the background of the cell at (x,y) (zero-based column and row
+   indices, for example (2,3) == C4) on the first sheet and
+   returns the contents of the cell as a string.
+"""
+#get the doc from the scripting context which is made available to all 
scripts
+desktop = XSCRIPTCONTEXT.getDesktop()
+model = desktop.getCurrentComponent()
+#check whether there's already an opened document
+if not hasattr(model, "Sheets"):
+return ""
+sheet = model.Sheets.Sheet1
+cell = sheet.getCellByPosition(x, y)
+cell.CellBackColor = color
+return cell.String
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples scripting/source

2018-01-24 Thread Miklos Vajna
 scripting/examples/python/Capitalise.py|2 ++
 scripting/examples/python/HelloWorld.py|2 ++
 scripting/examples/python/pythonSamples/TableSample.py |2 ++
 scripting/source/pyprov/mailmerge.py   |2 ++
 4 files changed, 8 insertions(+)

New commits:
commit a7d67762f116ca85181b4ae4053141ea68e6d6f8
Author: Miklos Vajna 
Date:   Tue Jan 23 14:57:30 2018 +0100

scripting: add missing vim modelines to python files

Change-Id: Iedc3a8ab37deeb7a686fa709afb0cf350f815ec6
Reviewed-on: https://gerrit.libreoffice.org/48418
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins 

diff --git a/scripting/examples/python/Capitalise.py 
b/scripting/examples/python/Capitalise.py
index 3c5366589ef9..05e82a37ad32 100644
--- a/scripting/examples/python/Capitalise.py
+++ b/scripting/examples/python/Capitalise.py
@@ -76,3 +76,5 @@ def capitalisePython( ):
 # lists the scripts, that shall be visible inside OOo. Can be omitted, if
 # all functions shall be visible, however here getNewString shall be suppressed
 g_exportedScripts = capitalisePython,
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/scripting/examples/python/HelloWorld.py 
b/scripting/examples/python/HelloWorld.py
index 4cad8a8549ea..8c3c9a8141d2 100644
--- a/scripting/examples/python/HelloWorld.py
+++ b/scripting/examples/python/HelloWorld.py
@@ -34,3 +34,5 @@ def HelloWorldPython( ):
 #and set the string
 tRange.String = "Hello World (in Python)"
 return None
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/scripting/examples/python/pythonSamples/TableSample.py 
b/scripting/examples/python/pythonSamples/TableSample.py
index 12ea326343cc..a92c862c2674 100644
--- a/scripting/examples/python/pythonSamples/TableSample.py
+++ b/scripting/examples/python/pythonSamples/TableSample.py
@@ -112,3 +112,5 @@ def createTable():
 text.insertString( cursor, " That's all for now !!" , 0 )
 
 g_exportedScripts = createTable,
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/scripting/source/pyprov/mailmerge.py 
b/scripting/source/pyprov/mailmerge.py
index 6034a74f1b03..ca18c7b17227 100644
--- a/scripting/source/pyprov/mailmerge.py
+++ b/scripting/source/pyprov/mailmerge.py
@@ -528,3 +528,5 @@ g_ImplementationHelper.addImplementation( \
 g_ImplementationHelper.addImplementation( \
PyMailMessage, g_messageImplName,
("com.sun.star.mail.MailMessage",),)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2014-10-14 Thread Noel Grandin
 scripting/examples/java/debugger/DebugRunner.java |2 +-
 scripting/examples/java/debugger/OOBeanShellDebugger.java |2 +-
 scripting/examples/java/debugger/OORhinoDebugger.java |2 +-
 scripting/examples/java/debugger/OOScriptDebugger.java|2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 3f43627ac63b3131e7f621ecb53f5246224fd55d
Author: Noel Grandin 
Date:   Tue Oct 14 09:48:41 2014 +0200

fix import location of XScriptContext

Change-Id: I3b0ec540ed37e40f59210b7fb563196aee63d1ea

diff --git a/scripting/examples/java/debugger/DebugRunner.java 
b/scripting/examples/java/debugger/DebugRunner.java
index 8e6c143..a3b4869 100644
--- a/scripting/examples/java/debugger/DebugRunner.java
+++ b/scripting/examples/java/debugger/DebugRunner.java
@@ -26,7 +26,7 @@ import java.net.URLDecoder;
 
 import com.sun.star.uno.XComponentContext;
 import com.sun.star.script.framework.provider.PathUtils;
-import com.sun.star.script.framework.runtime.XScriptContext;
+import com.sun.star.script.provider.XScriptContext;
 
 public class DebugRunner {
 
diff --git a/scripting/examples/java/debugger/OOBeanShellDebugger.java 
b/scripting/examples/java/debugger/OOBeanShellDebugger.java
index 23811fd..68a5087 100644
--- a/scripting/examples/java/debugger/OOBeanShellDebugger.java
+++ b/scripting/examples/java/debugger/OOBeanShellDebugger.java
@@ -47,7 +47,7 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
-import drafts.com.sun.star.script.framework.runtime.XScriptContext;
+import com.sun.star.script.provider.XScriptContext;
 import bsh.Interpreter;
 
 public class OOBeanShellDebugger implements OOScriptDebugger, ActionListener,
diff --git a/scripting/examples/java/debugger/OORhinoDebugger.java 
b/scripting/examples/java/debugger/OORhinoDebugger.java
index f0d7aee..5144637 100644
--- a/scripting/examples/java/debugger/OORhinoDebugger.java
+++ b/scripting/examples/java/debugger/OORhinoDebugger.java
@@ -27,7 +27,7 @@ import org.mozilla.javascript.ImporterTopLevel;
 import org.mozilla.javascript.tools.debugger.Main;
 import org.mozilla.javascript.tools.debugger.ScopeProvider;
 
-import drafts.com.sun.star.script.framework.runtime.XScriptContext;
+import com.sun.star.script.provider.XScriptContext;
 
 public class OORhinoDebugger implements OOScriptDebugger {
 
diff --git a/scripting/examples/java/debugger/OOScriptDebugger.java 
b/scripting/examples/java/debugger/OOScriptDebugger.java
index 929936d..61fdbe7 100644
--- a/scripting/examples/java/debugger/OOScriptDebugger.java
+++ b/scripting/examples/java/debugger/OOScriptDebugger.java
@@ -19,7 +19,7 @@
 package org.libreoffice.example.java_scripts;
 
 import java.io.InputStream;
-import drafts.com.sun.star.script.framework.runtime.XScriptContext;
+import com.sun.star.script.provider.XScriptContext;
 
 public interface OOScriptDebugger {
 public void go(XScriptContext ctxt, String filename);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples scripting/java scripting/workben

2014-10-02 Thread Robert Antoni Buj i Gelonch
 scripting/examples/java/HelloWorld/HelloWorld.java 
   |   16 
 scripting/examples/java/Highlight/HighlightText.java   
   |   89 -
 scripting/examples/java/MemoryUsage/MemoryUsage.java   
   |   55 
 scripting/examples/java/Newsgroup/MimeConfiguration.java   
   |  170 +-
 scripting/examples/java/Newsgroup/NewsGroup.java   
   |   12 
 scripting/examples/java/Newsgroup/OfficeAttachment.java
   |  228 +--
 scripting/examples/java/Newsgroup/PostNewsgroup.java   
   |  560 -
 scripting/examples/java/Newsgroup/Sender.java  
   |   96 -
 scripting/examples/java/Newsgroup/StatusWindow.java
   |  128 --
 scripting/examples/java/Newsgroup/SubscribedNewsgroups.java
   |  267 +---
 scripting/examples/java/debugger/DebugRunner.java  
   |   24 
 scripting/examples/java/debugger/OOBeanShellDebugger.java  
   |   71 -
 scripting/examples/java/debugger/OORhinoDebugger.java  
   |   40 
 scripting/examples/java/selector/ScriptSelector.java   
   |  242 +--
 
scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java
   |  460 +++
 scripting/java/com/sun/star/script/framework/browse/DialogFactory.java 
   |  135 --
 scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java  
   |  215 +--
 scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java 
   |   19 
 scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java
   |  154 +-
 scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java  
   |  187 +--
 
scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java
 |   99 -
 scripting/java/com/sun/star/script/framework/container/Parcel.java 
   |  265 ++--
 scripting/java/com/sun/star/script/framework/container/ParcelContainer.java
   |  616 --
 scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java   
   |   87 -
 scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java
   |3 
 scripting/java/com/sun/star/script/framework/container/ScriptEntry.java
   |   29 
 scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java 
   |  317 ++---
 scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java
   |  418 +++---
 scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java   
   |   40 
 scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java  
   |  143 +-
 scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java  
   |   78 -
 scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java   
   |   38 
 scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java  
   |  156 +-
 scripting/java/com/sun/star/script/framework/io/XStorageHelper.java
   |  207 +--
 scripting/java/com/sun/star/script/framework/log/LogUtils.java 
   |   44 
 scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java  
   |   23 
 scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java 
   |   28 
 
scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java
 |9 
 scripting/java/com/sun/star/script/framework/provider/PathUtils.java   
   |   59 
 scripting/java/com/sun/star/script/framework/provider/ScriptContext.java   
   |   68 -
 scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java
   |5 
 scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java  
   |  549 
 scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java 
   |6 
 
scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java
  

[Libreoffice-commits] core.git: scripting/examples

2013-02-17 Thread Julien Nabet
 scripting/examples/java/HelloWorld/parcel-descriptor.xml |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 54d91caf7b3519ee44e299a8174b7ec28fa6a6ed
Author: Julien Nabet 
Date:   Sun Feb 17 17:56:56 2013 +0100

Fix typo

Change-Id: Id5aff315b1d52ac5a869a17b3a654c2d1e670b08

diff --git a/scripting/examples/java/HelloWorld/parcel-descriptor.xml 
b/scripting/examples/java/HelloWorld/parcel-descriptor.xml
index 926a797..57e2e04 100644
--- a/scripting/examples/java/HelloWorld/parcel-descriptor.xml
+++ b/scripting/examples/java/HelloWorld/parcel-descriptor.xml
@@ -21,7 +21,7 @@
 
 
 
-Prints "Helo World".
+Prints "Hello World".
 
 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: scripting/examples

2013-02-17 Thread Xisco Fauli
 scripting/examples/python/HelloWorld.py |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

New commits:
commit 270967f340670189e42939d9432e28e8259feefc
Author: Xisco Fauli 
Date:   Sun Feb 17 14:59:45 2013 +0100

fdo#60670: Create a new document in case there's none

Change-Id: I7e03481beb1d4e60601fd93d787bc7354495e41f

diff --git a/scripting/examples/python/HelloWorld.py 
b/scripting/examples/python/HelloWorld.py
index 48e7786..4cad8a8 100644
--- a/scripting/examples/python/HelloWorld.py
+++ b/scripting/examples/python/HelloWorld.py
@@ -21,7 +21,12 @@
 def HelloWorldPython( ):
 """Prints the string 'Hello World(in Python)' into the current document"""
 #get the doc from the scripting context which is made available to all scripts
-model = XSCRIPTCONTEXT.getDocument()
+desktop = XSCRIPTCONTEXT.getDesktop()
+model = desktop.getCurrentComponent()
+#check whether there's already an opened document. Otherwise, create a new one
+if not hasattr(model, "Text"):
+model = desktop.loadComponentFromURL(
+"private:factory/swriter","_blank", 0, () )
 #get the XText interface
 text = model.Text
 #create an XTextRange at the end of the document
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits