From 5ce3e1b6c32f59175c76e6dbadb871cba0068262 Mon Sep 17 00:00:00 2001 From: Rafael Lima Date: Fri, 12 Nov 2021 16:34:01 +0200 Subject: Create PopupMenu service documentation Change-Id: I511221e68e9504a5c9e5e6c00bb31047a6ccf11b Reviewed-on: https://gerrit.libreoffice.org/c/help/+/124982 Tested-by: Jenkins Reviewed-by: Rafael Lima --- AllLangHelp_sbasic.mk | 1 + source/auxiliary/sbasic.tree | 1 + source/text/sbasic/shared/03/lib_ScriptForge.xhp | 10 +- source/text/sbasic/shared/03/sf_popupmenu.xhp | 330 +++++++++++++++++++++++ 4 files changed, 339 insertions(+), 3 deletions(-) create mode 100644 source/text/sbasic/shared/03/sf_popupmenu.xhp diff --git a/AllLangHelp_sbasic.mk b/AllLangHelp_sbasic.mk index f154d1de63..d941abf42e 100644 --- a/AllLangHelp_sbasic.mk +++ b/AllLangHelp_sbasic.mk @@ -98,6 +98,7 @@ $(eval $(call gb_AllLangHelp_add_helpfiles,sbasic,\ helpcontent2/source/text/sbasic/shared/03/sf_l10n \ helpcontent2/source/text/sbasic/shared/03/sf_methods \ helpcontent2/source/text/sbasic/shared/03/sf_platform \ + helpcontent2/source/text/sbasic/shared/03/sf_popupmenu \ helpcontent2/source/text/sbasic/shared/03/sf_session \ helpcontent2/source/text/sbasic/shared/03/sf_services \ helpcontent2/source/text/sbasic/shared/03/sf_string \ diff --git a/source/auxiliary/sbasic.tree b/source/auxiliary/sbasic.tree index 562abdbda4..7b5675ca28 100644 --- a/source/auxiliary/sbasic.tree +++ b/source/auxiliary/sbasic.tree @@ -354,6 +354,7 @@ FormControl service L10N service Platform service + PopupMenu service Services service Session service String service diff --git a/source/text/sbasic/shared/03/lib_ScriptForge.xhp b/source/text/sbasic/shared/03/lib_ScriptForge.xhp index 17cbac0d8e..60a1026597 100644 --- a/source/text/sbasic/shared/03/lib_ScriptForge.xhp +++ b/source/text/sbasic/shared/03/lib_ScriptForge.xhp @@ -97,13 +97,14 @@ Dialog
DialogControl
- UI + Form
- Form
- FormControl

+ FormControl
+ PopupMenu
+ UI
@@ -175,6 +176,9 @@
+
+ +
diff --git a/source/text/sbasic/shared/03/sf_popupmenu.xhp b/source/text/sbasic/shared/03/sf_popupmenu.xhp new file mode 100644 index 0000000000..7c50ff0ad0 --- /dev/null +++ b/source/text/sbasic/shared/03/sf_popupmenu.xhp @@ -0,0 +1,330 @@ + + + + + + ScriptForge.PopupMenu service + /text/sbasic/shared/03/sf_popupmenu.xhp + + + +
+ + PopupMenu service + +
+
+

ScriptForge.PopupMenu service

+ The PopupMenu service can be used to create popup menus that can be associated with events or executed by scripts. This service provides the following capabilities: + + + Creation of popup menus with custom entries, checkboxes and radio buttons. + + + Decoration of menu items with icons and tooltips. + + +
+ +

Service invocation

+ + The PopupMenu service can be instantiated in multiple ways. The example below creates a popup menu without associating it with a mouse or application event. + + Sub ShowPopup + GlobalScope.BasicLibraries.loadLibrary("ScriptForge") + Dim myPopup As Object + Set myPopup = CreateScriptService("SFWidgets.PopupMenu", , 300, 300) + myPopup.AddItem("Item ~A") + myPopup.AddItem("Item ~B") + vResponse = myPopup.Execute() + MsgBox("Selected item ID: " & vResponse) + myPopup.Dispose() + End Sub + + Running the Sub defined above will create a popup menu with two entries in the position X=300 and Y=300 on the screen. + The prefix SFWidgets can be suppressed while invoking the PopupMenu service. + The following example defines a Sub that can be associated with a mouse event: + + Sub MyPopupClick(Optional poMouseEvent as Object) + Dim myPopup As Object + Set myPopup = CreateScriptService("PopupMenu", poMouseEvent) + ' Populate popupmenu with items + Dim vResponse As Variant + vResponse = myPopup.Execute(False) + ' Do something based on vResponse + ' ... + myPopup.Dispose() + End Sub + + Use the Dispose method to free resources after executing the popup menu. + It is also possible to associate a popup menu with events triggered by %PRODUCTNAME applications, form and dialog controls. Events such as "Mouse button pressed" and "Mouse button released" are commonly associated with popup menus. + + Sub MyPopupClick(Optional poEvent as Object) + Dim myPopup As Object + Set myPopup = CreateScriptService("PopupMenu", poEvent) + ' ... + End Sub + + + + The examples above can be written in Python as follows: + + from scriptforge import CreateScriptService + + def show_popup(args=None): + my_popup = CreateScriptService("SFWidgets.PopupMenu", None, 300, 300) + bas = CreateScriptService("Basic") + my_popup.AddItem("Item ~A") + my_popup.AddItem("Item ~B") + response = my_popup.Execute() + bas.MsgBox(f"Selected item ID: {response}") + my_popup.Dispose() + + + def my_popup_click(poEvent=None): + my_popup = CreateScriptService("SFWidgets.PopupMenu", poEvent) + # Populate popupmenu with items + response = my_popup.Execute() + # Do something based on response + my_popup.Dispose() + + + + PopupService service;ShortcutCharacter + PopupService service;SubmenuCharacter + +

Properties

+ + + + Name + + + Readonly + + + Type + + + Description + + + + + SubmenuCharacter + + + No + + + String + + + Character or string that defines how menu items are nested. The default character is ">". + + + + + ShortcutCharacter + + + No + + + String + + + Character used to define the access key of a menu item. The default character is "~". + + +
+ +

Menu and Submenus

+ To create a popup menu with submenus, use the character defined in the SubmenuCharacter property while creating the menu entry to define where it will be placed. For instance, consider the following menu/submenu hierarchy. + + ' Item A + ' Item B > Item B.1 + ' Item B.2 + ' ------ (line separator) + ' Item C > Item C.1 > Item C.1.1 + ' Item C.1.2 + ' Item C > Item C.2 > Item C.2.1 + ' Item C.2.2 + + The code below uses the default submenu character ">" to create the menu/submenu hierarchy defined above: + + myPopup.AddItem("Item A") + myPopup.AddItem("Item B>Item B.1") + myPopup.AddItem("Item B>Item B.2") + myPopup.AddItem("---") + myPopup.AddItem("Item C>Item C.1>Item C.1.1") + myPopup.AddItem("Item C>Item C.1>Item C.1.2") + myPopup.AddItem("Item C>Item C.2>Item C.2.1") + myPopup.AddItem("Item C>Item C.2>Item C.2.2") + + The string "---" is used to define line separators in menus or submenus.. +

Using icons

+ Items in the popup menu can have icons, which are specified as arguments in the AddCheckBox, AddItem and AddRadioButton methods. + All icons available in %PRODUCTNAME can be used by specifying their path relative to the folder where icon files are located in the installation folder. Icons are located in the following folder: + INSTALLDIR/share/config + Use the InstallFolder property of the FileSystem service to determine where %PRODUCTNAME is installed in your system. + This folder contains a series of ZIP files containing the image files of each available icon set. The images inside these ZIP files are organized into folders. To use an icon, specify the icon file with the path to its location inside the ZIP file. + The example below uses the icon "sc_newdoc.svg" that is located inside the "cmd" folder. The forward slash "/" character is used as the path separator regardless of the operating system. + + myPopup.AddItem("Item A", Icon := "cmd/sc_newdoc.svg") + + All icon sets have the same internal structure. The actual icon displayed depends on the icon set currently in use. + +

Methods

+ + + List of Methods in the PopupMenu Service + + + + + AddCheckBox
+ AddItem +
+
+ + + AddRadioButton

+
+
+ + + Execute

+
+
+
+
+ +
+ AddCheckBox ----------------------------------------------------------------------------------------- + + PopupMenu service;AddCheckBox + +

AddCheckBox

+ Inserts a check box in the popup menu. Returns an integer value that identifies the inserted item. + + + svc.AddCheckBox(menuitem: str, opt name: str, opt status: bool, opt icon: str, opt tooltip: str): int + + + menuitem: Defines the text to be displayed in the menu. This argument also defines the hierarchy of the item inside the menu by using the submenu character. + name: String value to be returned when the item is clicked. By default, the last component of the menu hierarchy is used. + status: Defines whether the item is selected when the menu is created (Default = False). + icon: Path and name of the icon to be displayed without the leading path separator. The actual icon shown depends on the icon set being used. + tooltip: Text to be displayed as tooltip. + + + + myPopup.AddCheckBox("Option A", Status := True) + + + + myPopup.AddCheckBox("Option A", status=True) + +
+ +
+ AddItem ----------------------------------------------------------------------------------------- + + PopupMenu service;AddItem + +

AddItem

+ Inserts a menu entry in the popup menu. Returns an integer value that identifies the inserted item. + + + svc.AddItem(menuitem: str, opt name: str, opt icon: str, opt tooltip: str): int + + + menuitem: Defines the text to be displayed in the menu. This argument also defines the hierarchy of the item inside the menu by using the submenu character. + name: String value to be returned when the item is clicked. By default, the last component of the menu hierarcy is used. + icon: Path and name of the icon to be displayed without the leading path separator. The actual icon shown depends on the icon set being used. + tooltip: Text to be displayed as tooltip. + + + + myPopup.AddItem("Item A", Tooltip := "A descriptive message") + + + + myPopup.AddItem("Item A", tooltip = "A descriptive message") + +
+ +
+ AddRadioButton --------------------------------------------------------------------------------------- + + PopupMenu service;AddRadioButton + +

AddRadioButton

+ Inserts a radio button entry in the popup menu. Returns an integer value that identifies the inserted item. + + + svc.AddRadioButton(menuitem: str, opt name: str, opt status: str, opt icon: str, opt tooltip: str): int + + + menuitem: Defines the text to be displayed in the menu. This argument also defines the hierarchy of the item inside the menu by using the submenu character. + name: String value to be returned when the item is clicked. By default, the last component of the menu hierarcy is used. + status: Defines whether the item is selected when the menu is created (Default = False). + icon: Path and name of the icon to be displayed without the leading path separator. The actual icon shown depends on the icon set being used. + tooltip: Text to be displayed as tooltip. + + + + myPopup.AddRadioButton("Option A", Name := "A", Status := True) + + + + myPopup.AddRadioButton("Option A", name="A", status=True) + +
+ +
+ Execute --------------------------------------------------------------------------------------- + + PopupMenu service;Execute + +

Execute

+ Displays the popup menu and waits for a user action. Returns the item clicked by the user. + If the user clicks outside the popup menu ou presses the Esc key, then no item is selected. In such cases, the returned value depends on the returnid parameter. If returnid = True and no item is selected, then the value 0 (zero) is returned. Otherwise an empty string "" is returned. + + + svc.Execute(opt returnid: bool): any + + + returnid: If True the selected item ID is returned. If False the method returns the item's name (Default = True). + + In the examples below, a popup menu is created and the item's name is returned because the returnid argument is set to False. + + + myPopup.AddItem("Item A", Name := "A") + myPopup.AddItem("Item B", Name := "B") + Dim vResponse as Variant + vResponse = myPopup.Execute(False) + + + + myPopup.AddItem("Item A", name="A") + myPopup.AddItem("Item B", name="B") + response = myPopup.Execute(False) + +
+ + +
+ + +
+ +
-- cgit