From 4ee2f0f82f99a865e765309eda367d5fc016674b Mon Sep 17 00:00:00 2001 From: Alain Romedenne Date: Thu, 15 Apr 2021 11:47:57 +0200 Subject: sf_basic py2bas bridge It includes Basic functions rework in order to - share content, - correct Basic keywords argument names tdf#141474 - accommodate Python lowercased arguments. Change-Id: If59a82444a8e001b02d085f5e10e0053666f8485 Reviewed-on: https://gerrit.libreoffice.org/c/help/+/114008 Tested-by: Jenkins Reviewed-by: Alain Romedenne --- source/text/sbasic/python/python_programming.xhp | 4 +- source/text/sbasic/shared/03/sf_basic.xhp | 480 +++++++++++++++++++++++ source/text/sbasic/shared/03010101.xhp | 8 +- source/text/sbasic/shared/03010201.xhp | 14 +- source/text/sbasic/shared/03010305.xhp | 8 +- source/text/sbasic/shared/03030102.xhp | 40 +- source/text/sbasic/shared/03030120.xhp | 9 +- source/text/sbasic/shared/03120301.xhp | 53 +-- 8 files changed, 557 insertions(+), 59 deletions(-) create mode 100644 source/text/sbasic/shared/03/sf_basic.xhp (limited to 'source') diff --git a/source/text/sbasic/python/python_programming.xhp b/source/text/sbasic/python/python_programming.xhp index 5efa8df15c..96deb86064 100644 --- a/source/text/sbasic/python/python_programming.xhp +++ b/source/text/sbasic/python/python_programming.xhp @@ -11,14 +11,16 @@ Python : Programming with Python - /text/sbasic/python/python_programming.xhp + /text/sbasic/python/python_programming.xhp Python;Programming XSCRIPTCONTEXT;Python + XSCRIPTCONTEXT;getComponentContext() uno.py + uno.py;getComponentContext()

Programming with Python Scripts

diff --git a/source/text/sbasic/shared/03/sf_basic.xhp b/source/text/sbasic/shared/03/sf_basic.xhp new file mode 100644 index 0000000000..9ebae2bec6 --- /dev/null +++ b/source/text/sbasic/shared/03/sf_basic.xhp @@ -0,0 +1,480 @@ + + + + + + ScriptForge.Basic service + /text/sbasic/shared/03/sf_basic.xhp + + + +
+ + Basic service + +
+
+

ScriptForge.Basic service

+ The ScriptForge.Basic service proposes a collection of %PRODUCTNAME Basic methods to be executed in a Python context. Basic service methods reproduce the exact syntax and behaviour of Basic builtin functions. + + +
+ Typical example: + + svc.MsgBox('This has to be displayed in a message box') + + ScriptForge.Basic service is limited to Python scripts. +

Service invocation

+ Before using the Basic service, import the CreateScriptService() method from the scriptforge module: + + from scriptforge import CreateScriptService + svc = CreateScriptService("Basic") + +

Properties

+ + + Name + ReadOnly + Type + Description + + + + MB_OK, MB_OKCANCEL, MB_RETRYCANCEL, MB_YESNO, MB_YESNOCANCEL + + + Yes + + + integer + + + Values: 0, 1, 5, 4, 3 + + + + + MB_ICONEXCLAMATION, MB_ICONINFORMATION, MB_ICONQUESTION, MB_ICONSTOP + + + Yes + + + integer + + + Values: 48, 64, 32, 16
+
+
+ + + MB_ABORTRETRYIGNORE, MB_DEFBUTTON1, MB_DEFBUTTON2, MB_DEFBUTTON3 + + + Yes + + + integer + + + Values: 2, 128, 256, 512 + + + + + IDABORT, IDCANCEL, IDIGNORE, IDNO, IDOK, IDRETRY, IDYES + + + Yes + + + integer + + + Values: 3, 2, 5, 7, 1, 4, 6
Constants indicating MsgBox selected button.
+
+
+ + + StarDesktop + + + Yes + + + UNO
object
+
+ + StarDesktop object represents LibreOfficeDev Start Center. + +
+
+ + + List of Methods in the Basic Service + + + + + ConvertFromUrl
+ ConvertToUrl
+ CreateUnoService
+ DateAdd
+ DateDiff
+ DatePart +
+
+ + + DateValue
+ Format
+ GetDefaultContext
+ GetGuiType
+ GetPathSeparator
+ GetSystemTicks
+
+
+ + + InputBox
+ MsgBox
+ Now
+ RGB
+ Xray +
+
+
+
+
+ ConvertFromUrl ------------------------------------------------------------------------- + + Basic service;ConvertFromUrl + +

ConvertFromUrl

+ Returns a system path file name for the given file: URL. +

+ svc.ConvertFromUrl(url: str): str +

+ url: An absolute file: URL. +

+ A system path file name. +

+ + filename = svc.ConvertFromUrl( "file:///C:/Program%20Files%20(x86)/LibreOffice/News.txt") + svc.MsgBox(filename) + +
+
+ ConvertToUrl --------------------------------------------------------------------------- + + Basic service;ConvertToUrl + +

ConvertToUrl

+ Returns a file: URL for the given system path. +

+ svc.ConvertToUrl(systempath: str): str +

+ systempath: A system file name as a string. +

+ A file: URL as a string. +

+ + url = svc.ConvertToUrl( 'C:\Program Files(x86)\LibreOffice\News.txt') + svc.MsgBox(url) + +
+
+ CreateUnoService ----------------------------------------------------------------------- + + Basic service;CreateUnoService + +

CreateUnoService

+ Instantiates a UNO service with the ProcessServiceManager. +

+ svc.CreateUnoService(servicename: str): uno +

+ servicename : A fully qualified service name such as "com.sun.star.ui.dialogs.FilePicker" or 'com.sun.star.sheet.FunctionAccess'. +

+ + dsk = svc.CreateUnoService('com.sun.star.frame.Desktop') + +
+
+ DateAdd -------------------------------------------------------------------------------- + + Basic service;DateAdd + +

DateAdd

+ Adds a date or time interval to a given date/time a number of times and returns the resulting date. +

+ svc.DateAdd(interval: str, number: num, date: datetime): datetime +

+ interval: A string expression from the following table, specifying the date or time interval. + + number: A numerical expression specifying how often the interval value will be added when positive or subtracted when negative. + date: A given datetime.datetime value, the interval value will be added number times to this date/time value. +

+ A datetime.datetime value. +

+ + dt = datetime.datetime(2004, 1, 31) + dt = svc.DateAdd("m", 1, dt) + print(dt) + +
+
+ DateDiff ------------------------------------------------------------------------------- + + Basic service;DateDiff + +

DateDiff

+ Returns the number of date or time intervals between two given date/time values. +

+ svc.DateDiff(interval: str, date1: datetime, date2: datetime, firstdayofweek = 1, firstweekofyear = 1): int +

+ interval: A string expression specifying the date interval, as detailed in above DateAdd method. + date1, date2: The two datetime.datetime values to be compared. + +

+ A number. +

+ + date1 = datetime.datetime(2005,1, 1) + date2 = datetime.datetime(2005,12,31) + diffDays = svc.DateDiff('d', date1, date2) + print(diffDays) + +
+
+ DatePart ------------------------------------------------------------------------------- + + Basic service;DatePart + +

DatePart

+ The DatePart function returns a specified part of a date. +

+ svc.DatePart(interval: str, date: datetime, firstdayofweek = 1, firstweekofyear = 1): int +

+ interval: A string expression specifying the date interval, as detailed in above DateAdd method. + date: The date/time from which the result is calculated. + firstdayofweek, firstweekofyear: optional parameters that respectively specify the starting day of a week and the starting week of a year, as detailed in above DateDiff method. +

+ The extracted part for the given date/time. +

+ + print(svc.DatePart("ww", datetime.datetime(2005,12,31) + print(svc.DatePart('q', datetime.datetime(1999,12,30) + +
+
+ DateValue ------------------------------------------------------------------------------ + + Basic service;DateValue + +

DateValue

+ Computes a date value from a date string. +

+ svc.DateValue(date: str): datetime +

+ +

+ The computed date. +

+ + dt = svc.DateValue("23-02-2011") + print(dt) + +
+
+ Format --------------------------------------------------------------------------------- + + Basic service;Format + +

Format

+ Converts a number to a string, and then formats it according to the format that you specify. +

+ svc.Format(expression: any, format = ''): str + +

Formatting Codes

+ +

Predefined Formats

+ + +

+ + txt = svc.Format(6328.2, '##.##0.00') + print(txt) + +
+
+ GetDefaultContext ---------------------------------------------------------------------- + + Basic service;GetDefaultContext + +

GetDefaultContext

+ Returns the default context of the process service factory, if existent, else returns a null reference. + GetDefaultContext is an alternative to the getComponentContext() method available from XSCRIPTCONTEXT global variable or from uno.py module. +

+ svc.GetDefaultContext(): uno +

+ The default component context is used, when instantiating services via XMultiServiceFactory. See the Professional UNO chapter in the Developer's Guide on api.libreoffice.org for more information. +

+ + ctx = svc.GetDefaultContext() + +
+
+ GetGuiType ----------------------------------------------------------------------------- + + Basic service;GetGuiType + +

GetGuiType

+ Returns a numerical value that specifies the graphical user interface. This function is only provided for backward compatibility with previous versions. + Refer to system() method from platform Python module to identify the operating system. +

+ svc.GetGuiType(): int +

+ + n = svc.GetGuiType() + +
+
+ GetPathSeparator ---------------------------------------------------------------------- + + Basic service;GetPathSeparator + +

GetPathSeparator

+ Returns the operating system-dependent directory separator used to specify file paths. + Use os.pathsep from os Python module to identify the path separator. +

+ svc.GetPathSeparator(): str + + svc.GetPathSeparator(): str + +

+ + sep = svc.GetPathSeparator() + +
+
+ GetSystemTicks ------------------------------------------------------------------------- + + Basic service;GetSystemTicks + +

GetSystemTicks

+ Returns the number of system ticks provided by the operating system. You can use this function to optimize certain processes. Use this method to estimate time in milliseconds: +

+ svc.GetSystemTicks(): int +

+ + ticks_ini = svc.GetSystemTicks() + time.sleep(1) + ticks_end = svc.GetSystemTicks() + svc.MsgBox("{} - {} = {}".format(ticks_end, ticks_ini,ticks_end - ticks_ini)) + +
+
+ InputBox ------------------------------------------------------------------------------- + + Basic service;InputBox + +

InputBox

+

+ svc.InputBox(prompt: str, [title: str], [default: str], [xpostwips: int, ypostwips: int]): str +

+ +

+ string +

+
+ + txt = s.InputBox('Please enter a phrase:', "Dear user") + s.MsgBox(txt, MB_ICONINFORMATION, "Confirmation of phrase") + + For in-depth information please refer to Input/Output to Screen with Python on the Wiki. +
+
+
+ MsgBox -------------------------------------------------------------------------------- + + Basic service;MsgBox + +

MsgBox

+ Displays a dialog box containing a message and returns an optional value.
MB_xx constants help specify the dialog type, the number and type of buttons to display, plus the icon type. By adding their respective values they form bit patterns, that define the MsgBox dialog appearance.
+

+ svc.MsgBox(prompt: str, buttons = svc.MB_OK, [title: str])[: int] +

+ +

+ An optional integer as detailed in above IDxx properties. +

+ +
+
+ Now ------------------------------------------------------------------------------------ + + Basic service;Now + +

Now

+ Returns the current system date and time as a date/time value. +

+ svc.Now(): datetime +

+ + svc.MsgBox(svc.Now(), svc.MB_OK, "Now") + +
+
+ RGB ------------------------------------------------------------------------------------ + + Basic service;RGB + +

RGB

+ Returns an integer color value consisting of red, green, and blue components. +

+ svc.RGB(red:int, green: int, blue: int): int +

+ +

+ integer + +

+ + YELLOW = svc.RGB(255,255,0) + +
+
+ Xray ----------------------------------------------------------------------------------- + + Basic service;Xray + +

Xray

+ Inspect Uno objects or variables. +

+ svc.Xray(obj: any) +

+ obj: A variable or Uno object. +

+ + svc.Xray(svc.StarDesktop) + +
+ +
+ uno.fileUrlToSystemPath() method + uno.systemPathToFileUrl() method + Input/Output to Screen with Python on the wiki + XSCRIPTCONTEXT.getComponentContext() method + uno.getComponentContext() method + platform.system() method + os.pathsep() method +
+ +
\ No newline at end of file diff --git a/source/text/sbasic/shared/03010101.xhp b/source/text/sbasic/shared/03010101.xhp index c87987c709..02fd4e041d 100644 --- a/source/text/sbasic/shared/03010101.xhp +++ b/source/text/sbasic/shared/03010101.xhp @@ -42,9 +42,11 @@
- Prompt: String expression displayed as a message in the dialog box. Line breaks can be inserted with Chr$(13). - Title: String expression displayed in the title bar of the dialog. If omitted, the title bar displays the name of the respective application. - Buttons: Any integer expression that specifies the dialog type, as well as the number and type of buttons to display, and the icon type. Buttons represents a combination of bit patterns, that is, a combination of elements can be defined by adding their respective values: +
+ prompt: String expression displayed as a message in the dialog box. Line breaks can be inserted with Chr$(13). + title: String expression displayed in the title bar of the dialog. If omitted, the title bar displays the name of the respective application. + buttons: Any integer expression that specifies the dialog type, as well as the number and type of buttons to display, and the icon type. Buttons represents a combination of bit patterns, that is, a combination of elements can be defined by adding their respective values: +
diff --git a/source/text/sbasic/shared/03010201.xhp b/source/text/sbasic/shared/03010201.xhp index 5e7ee3543d..84ac21c5e4 100644 --- a/source/text/sbasic/shared/03010201.xhp +++ b/source/text/sbasic/shared/03010201.xhp @@ -44,12 +44,14 @@ - Prompt: String expression displayed as the message in the dialog box. - Title: String expression displayed in the title bar of the dialog box. - Default: String expression displayed in the text box as default if no other input is given. - xPosTwips: Integer expression that specifies the horizontal position of the dialog. The position is an absolute coordinate and does not refer to the window of the office application. - yPosTwips: Integer expression that specifies the vertical position of the dialog. The position is an absolute coordinate and does not refer to the window of the office application. -If xPosTwips and yPosTwips are omitted, the dialog is centered on the screen. The position is specified in twips. +
+ prompt: String expression displayed as the message in the dialog box. + title: String expression displayed in the title bar of the dialog box. + default: String expression displayed in the text box as default if no other input is given. + xpostwips: Integer expression that specifies the horizontal position of the dialog. The position is an absolute coordinate and does not refer to the window of the office application. + ypostwips: Integer expression that specifies the vertical position of the dialog. The position is an absolute coordinate and does not refer to the window of the office application. +If xpostwips and yPosTwips are omitted, the dialog is centered on the screen. The position is specified in twips. +
String diff --git a/source/text/sbasic/shared/03010305.xhp b/source/text/sbasic/shared/03010305.xhp index 337e079929..093ea3d7ce 100644 --- a/source/text/sbasic/shared/03010305.xhp +++ b/source/text/sbasic/shared/03010305.xhp @@ -46,10 +46,12 @@ Long Parameter: - Red: Any integer expression that represents the red component (0-255) of the composite color. - Green: Any integer expression that represents the green component (0-255) of the composite color. - Blue: Any integer expression that represents the blue component (0-255) of the composite color. +
+ red: Any integer expression that represents the red component (0-255) of the composite color. + green: Any integer expression that represents the green component (0-255) of the composite color. + blue: Any integer expression that represents the blue component (0-255) of the composite color. The color picker dialog helps computing red, green and blue components of a composite color. Changing the color of text and selecting Custom color displays the color picker dialog. +
diff --git a/source/text/sbasic/shared/03030102.xhp b/source/text/sbasic/shared/03030102.xhp index b8332eba19..664e122cf2 100644 --- a/source/text/sbasic/shared/03030102.xhp +++ b/source/text/sbasic/shared/03030102.xhp @@ -20,38 +20,42 @@ - -DateValue Function -/text/sbasic/shared/03030102.xhp + + DateValue Function + /text/sbasic/shared/03030102.xhp Sun Microsystems, Inc. +
-DateValue function - -DateValue Function -Returns a date value from a date string. The date string is a complete date in a single numeric value. You can also use this serial number to determine the difference between two dates. + DateValue function + +

DateValue Function

+ Returns a date value from a date string. The date string is a complete date in a single numeric value. You can also use this serial number to determine the difference between two dates.
-Syntax: + + -DateValue [(date)] + DateValue(date) -Return value: -Datei66764 -Parameters: - - Date: String expression that contains the date that you want to calculate. In contrast to the DateSerial function that passes years, months and days as separate numeric values, the DateValue function requests the date string to be according to either one of the date acceptance patterns defined for your locale setting (see %PRODUCTNAME - PreferencesTools - Options - Language Settings - Languages) or to ISO date format (momentarily, only the ISO format with hyphens, e.g. "2012-12-31" is accepted). + +
+ Date: String expression that contains the date that you want to calculate. In contrast to the DateSerial function that passes years, months and days as separate numeric values, the DateValue function requests the date string to be according to either one of the date acceptance patterns defined for your locale setting (see %PRODUCTNAME - PreferencesTools - Options - Language Settings - Languages) or to ISO date format (momentarily, only the ISO format with hyphens, e.g. "2012-12-31" is accepted). +
+ +The computed date.i66764 -Example: + -Sub ExampleDateValue - MsgBox DateValue("12/02/2011") -End Sub + Sub ExampleDateValue + MsgBox DateValue("23/02/2011") + End Sub +
diff --git a/source/text/sbasic/shared/03030120.xhp b/source/text/sbasic/shared/03030120.xhp index e1e8a2c894..04f6fd4dea 100644 --- a/source/text/sbasic/shared/03030120.xhp +++ b/source/text/sbasic/shared/03030120.xhp @@ -27,7 +27,6 @@ -
DateDiff function @@ -52,12 +51,12 @@
- firstDayOfWeek - An optional parameter that specifies the starting day of a week. + firstdayofweek: An optional parameter that specifies the starting day of a week.
- firstDayOfWeek value + firstdayofweek value Explanation @@ -129,12 +128,12 @@
- firstWeekOfYear - An optional parameter that specifies the starting week of a year. + firstweekofyear: An optional parameter that specifies the starting week of a year. - firstWeekOfYear value + firstweekofyear value Explanation diff --git a/source/text/sbasic/shared/03120301.xhp b/source/text/sbasic/shared/03120301.xhp index 018e8ccc91..507fd78ecc 100644 --- a/source/text/sbasic/shared/03120301.xhp +++ b/source/text/sbasic/shared/03120301.xhp @@ -35,51 +35,58 @@

Format Function

-Converts a number to a string, and then formats it according to the format that you specify. +Converts a numeric expression to a string, and then formats it according to the format that you specify. -Format (Number [, Format As String]) +Format(expression [, format As String]) As String - -String - +
- Number: Numeric expression that you want to convert to a formatted string. - Format: String that specifies the format code for the number. If Format is omitted, the Format function works like the Str function. + expression: Numeric expression that you want to convert to a formatted string. + format: String that specifies the format code for the number. If format is omitted, the Format function works like the %PRODUCTNAME Basic Str() function. + + +Text string. +

Formatting Codes

-The following list describes the codes that you can use for formatting a number: - 0: If Number has a digit at the position of the 0 in the format code, the digit is displayed, otherwise a zero is displayed. -If Number has fewer digits than the number of zeros in the format code, (on either side of the decimal), leading or trailing zeros are displayed. If the number has more digits to the left of the decimal separator than the amount of zeros in the format code, the additional digits are displayed without formatting. -Decimal places in the number are rounded according to the number of zeros that appear after the decimal separator in the Format code. - #: If Number contains a digit at the position of the # placeholder in the Format code, the digit is displayed, otherwise nothing is displayed at this position. -This symbol works like the 0, except that leading or trailing zeroes are not displayed if there are more # characters in the format code than digits in the number. Only the relevant digits of the number are displayed. +
+The following list describes the codes that you can use for formatting a numeric expression: + 0: If expression has a digit at the position of the 0 in the format code, the digit is displayed, otherwise a zero is displayed. +If expression has fewer digits than the number of zeros in the format code, (on either side of the decimal), leading or trailing zeros are displayed. If the expression has more digits to the left of the decimal separator than the amount of zeros in the format code, the additional digits are displayed without formatting. +Decimal places in the expression are rounded according to the number of zeros that appear after the decimal separator in the format code. + #: If expression contains a digit at the position of the # placeholder in the format code, the digit is displayed, otherwise nothing is displayed at this position. +This symbol works like the 0, except that leading or trailing zeroes are not displayed if there are more # characters in the format code than digits in the expression. Only the relevant digits of the expression are displayed. .: The decimal placeholder determines the number of decimal places to the left and right of the decimal separator. -If the format code contains only # placeholders to the left of this symbol, numbers less than 1 begin with a decimal separator. To always display a leading zero with fractional numbers, use 0 as a placeholder for the first digit to the left of the decimal separator. - %: Multiplies the number by 100 and inserts the percent sign (%) where the number appears in the format code. - E- E+ e- e+ : If the format code contains at least one digit placeholder (0 or #) to the right of the symbol E-, E+, e-, or e+, the number is formatted in the scientific or exponential format. The letter E or e is inserted between the number and the exponent. The number of placeholders for digits to the right of the symbol determines the number of digits in the exponent. +If the format code contains only # placeholders to the left of this symbol, numbers less than 1 begin with a decimal separator. To always display a leading zero with fractional numbers, use 0 as a placeholder for the first digit to the left of the decimal separator. + %: Multiplies the expressionby 100 and inserts the percent sign (%) where the expression appears in the format code. + E- E+ e- e+ : If the format code contains at least one digit placeholder (0 or #) to the right of the symbol E-, E+, e-, or e+, the expression is formatted in the scientific or exponential format. The letter E or e is inserted between the number and the exponent. The number of placeholders for digits to the right of the symbol determines the number of digits in the exponent. If the exponent is negative, a minus sign is displayed directly before an exponent with E-, E+, e-, e+. If the exponent is positive, a plus sign is only displayed before exponents with E+ or e+. -The thousands delimiter is displayed if the format code contains the delimiter enclosed by digit placeholders (0 or #). +The thousands delimiter is displayed if the format code contains the delimiter enclosed by digit placeholders (0 or #). The use of a period as a thousands and decimal separator is dependent on the regional setting. When you enter a number directly in Basic source code, always use a period as decimal delimiter. The actual character displayed as a decimal separator depends on the number format in your system settings. - - + $ ( ) space: A plus (+), minus (-), dollar ($), space, or brackets entered directly in the format code is displayed as a literal character. + - + $ ( ) space: A plus (+), minus (-), dollar ($), space, or brackets entered directly in the format code is displayed as a literal character. To display characters other than the ones listed here, you must precede it by a backslash (\), or enclose it in quotation marks (" "). -\ : The backslash displays the next character in the format code. -Characters in the format code that have a special meaning can only be displayed as literal characters if they are preceded by a backslash. The backslash itself is not displayed, unless you enter a double backslash (\\) in the format code. + \ : The backslash displays the next character in the format code. +Characters in the format code that have a special meaning can only be displayed as literal characters if they are preceded by a backslash. The backslash itself is not displayed, unless you enter a double backslash (\\) in the format code. Characters that must be preceded by a backslash in the format code in order to be displayed as literal characters are date- and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, /, :), numeric-formatting characters (#, 0, %, E, e, comma, period), and string-formatting characters (@, &, <, >, !). -You can also use the following predefined number formats. Except for "General Number", all of the predefined format codes return the number as a decimal number with two decimal places. -If you use predefined formats, the name of the format must be enclosed in quotation marks. +You can also use the following predefined number formats. Except for "General Number", all of the predefined format codes return the number as a decimal number with two decimal places. +If you use predefined formats, the name of the format must be enclosed in quotation marks. +

Predefined format

+
General Number: Numbers are displayed as entered. Currency: Inserts a dollar sign in front of the number and encloses negative numbers in brackets. Fixed: Displays at least one digit in front of the decimal separator. Standard: Displays numbers with a thousands separator. Percent: Multiplies the number by 100 and appends a percent sign to the number. Scientific: Displays numbers in scientific format (for example, 1.00E+03 for 1000). -A format code can be divided into three sections that are separated by semicolons. The first part defines the format for positive values, the second part for negative values, and the third part for zero. If you only specify one format code, it applies to all numbers. +A format code can be divided into three sections that are separated by semicolons. The first part defines the format for positive values, the second part for negative values, and the third part for zero. If you only specify one format code, it applies to all numbers. +
+ -- cgit