Class GUI

class ooodev.gui.GUI[source]
SpecialWindows

alias of SpecialWindowsKind

ToolBarName

alias of ToolBarNameKind

class WindowInfo
__init__()
Return type:

None

component: XComponent | None
document_type: DocType
frame: XFrame | None
window_file_name: str
window_name: str
window_title: str
WindowSubtypes

alias of WindowSubtypeKind

ZoomEnum

alias of ZoomKind

classmethod activate(window)[source]

Activates window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

window (str | XComponent) – Window name as str or doc as XComponent

Return type:

None

Return type:

None

Parameters:

window (str | XComponent) –

classmethod add_item_to_toolbar(doc, toolbar_name, item_name, im_fnm)[source]

Add a user-defined icon and command to the start of the specified toolbar.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • doc (XComponent) – office document.

  • toolbar_name (str) – toolbar name.

  • item_name (str) – item name.

  • im_fnm (str) – image file path.

Return type:

None

static create_floating_frame(title, x, y, width, height)[source]

Create a floating XFrame at the given position and size.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • title (str) – Floating frame title.

  • x (int) – Frame x position.

  • y (int) – Frame y position.

  • width (int) – Frame width.

  • height (int) – Frame Height.

Raises:

MissingInterfaceError – If required interface can not be obtained.

Returns:

Floating frame.

Return type:

XFrame

classmethod get_active_window(obj)[source]
if hasattr(obj, “CurrentController”) and win.frame is None:

win.frame = obj.CurrentController.Frame obj (Any): doc like object

Method is Lo Instance Safe for use with multiple documents.

Returns:

Active window as string of found; Otherwise, an empty string.

Return type:

str

Parameters:

obj (Any) –

classmethod get_control_access(doc)[source]

Get control access from office document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – office document.

Raises:

MissingInterfaceError – If doc does not implement XControlAccess interface.

Returns:

control access.

Return type:

XControlAccess

static get_current_controller(doc: object)[source]
static get_current_controller(*args, **kwargs)

Gets controller from document.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (object) – office document

Raises:

MissingInterfaceError – If required interface is not present.

Returns:

controller

Return type:

XController

classmethod get_dpi(doc)[source]

Gets Dispatch provider interception.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – office document.

Raises:

MissingInterfaceError – if XDispatchProviderInterception interface instance is not obtained.

Returns:

Dispatch provider interception.

Return type:

XDispatchProviderInterception

classmethod get_frame(doc)[source]

Gets frame from doc.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – office document

Returns:

document frame.

Return type:

XFrame

classmethod get_layout_manager() com.sun.star.frame.XLayoutManager[source]
classmethod get_layout_manager(doc: com.sun.star.lang.XComponent) com.sun.star.frame.XLayoutManager
classmethod get_layout_manager(doc=None)

Gets layout manager

Parameters:

doc (XComponent) – office document

Raises:

Exception – If unable to get layout manager

Returns:

Layout manager

Return type:

XLayoutManager

classmethod get_menu_max_id(bar)[source]

Scan through the IDs used by all the items in this menubar, and return the largest ID encountered.

Parameters:

bar (XMenuBar) – Menu bar

Returns:

Largest menu bar id if found; Otherwise, -1

Return type:

int

classmethod get_menubar(lm)[source]

Get menu bar.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

lm (XLayoutManager) – layout manager

Raises:
Returns:

menu bar

Return type:

XMenuBar

static get_password(title, input_msg)[source]

Prompts for a password.

If inside of a Office window then an Office Dialog is displayed prompting for a password. If no Office window is available and attempt is made to create a tkinter dialog window for password input.

tkinter does not ship with integrated python in LibreOffice. For this reason it may not be possible to display a tkinter dialog. It will depend on how your virtual environment is set up. In most cases this will work on Linux but not on windows.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • title (str) – Title of input box

  • input_msg (str) – Message to display

Raises:

Exception if unable to build a dialog password input.

Returns:

password as string or empty string if password is not given.

Return type:

str

See also

Input

classmethod get_pos_size(doc)[source]

Gets window position and Size.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

doc (XComponent) – office document.

Returns:

Rectangle representing position and size.

Return type:

Rectangle

static get_screen_size()[source]

Get the work area as Rectangle.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Raises:

mEx.MissingInterfaceError – If XToolkit interface can not be obtained.

Returns:

Work Area.

Return type:

Rectangle

Note

Original java method used java to get area. Original method seemed to return effective size. (i.e. without Windows’ taskbar)

This implementation calls Toolkit.getWorkArea().

See also

Toolkit

classmethod get_selection_supplier(doc: object)[source]
classmethod get_selection_supplier(*args, **kwargs)

Gets selection supplier.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (object) – office document

Raises:
Returns:

Selection supplier

Return type:

XSelectionSupplier

classmethod get_title_bar()[source]

Gets title bar from top window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Returns:

title bar text if found; Otherwise, Empty string.

Return type:

str

classmethod get_toobar_resource(cls, name)[source]

Get toolbar resource for name.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

name (ToolBarName| str) – Name of toolbar resource

Returns:

A formatted resource string such as private:resource/toolbar/zoombar

Return type:

str

Deprecated since version 0.11.0: Use get_toolbar_resource() instead.

classmethod get_toolbar_resource(name)[source]

Get toolbar resource for name.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

name (ToolBarName| str) – Name of toolbar resource.

Returns:

A formatted resource string such as private:resource/toolbar/zoombar

Return type:

str

static get_top_window()[source]

Gets top window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Raises:
Returns:

top window

Return type:

XTopWindow

static get_ui_config_manager(doc)[source]

Gets ui config manager.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – office document.

Raises:
Returns:

ui config manager.

Return type:

XUIConfigurationManager

static get_ui_config_manager_doc(doc)[source]

Gets ui config manager base upon doc type reported by Info.doc_type_service().

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

doc (XComponent) – office document.

Raises:
  • MissingInterfaceError – If XModel interface can not be obtained.

  • MissingInterfaceError – If XUIConfigurationManagerSupplier interface can not be obtained.

  • Exception – If unable to get XUIConfigurationManager from XUIConfigurationManagerSupplier instance.

Returns:

ui config manager.

Return type:

XUIConfigurationManager

static get_ui_element_type_str(t)[source]

Converts constant value to element type string.

UIElementType determines the type of a user interface element which is controlled by a layout manager.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

t (int) – UIElementType constant Value from 0 to 8

Raises:
  • TypeError – If t is not a int

  • ValueError – If t is not a valid UIElementType constant.

Returns:

element type string

Return type:

str

static get_uii(doc)[source]

Gets user input interception.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

doc (XComponent) – office document.

Raises:

MissingInterfaceError – If doc does not implement XUserInputInterception interface.

Returns:

user input interception.

Return type:

XUserInputInterception

classmethod get_window() com.sun.star.awt.XWindow[source]
classmethod get_window(doc: com.sun.star.lang.XComponent) com.sun.star.awt.XWindow
classmethod get_window(doc=None)

Gets window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

doc (XComponent) – Office document.

Returns:

window instance.

Return type:

XWindow

classmethod get_window_handle() int | None[source]
classmethod get_window_handle(doc: com.sun.star.lang.XComponent) int | None
classmethod get_window_handle(doc=None)

Gets handle to a window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

doc (XComponent) – document to get window handle for.

Returns:

handle as int on success; Otherwise, None.

Return type:

int | None

Note

This method was part of original java lib but was only set to work with windows. An attempt is made to support Linux and Mac; However, not tested at this point.

Use this method at your own risk.

classmethod get_window_idenity(cls, obj)[source]

Gets Identity Info for window of an object

Parameters:

obj (Any) – object that implements XComponent

Returns:

Window Info

Return type:

GUI.Window

Deprecated since version 0.11.0: Use get_window_identity() instead.

classmethod get_window_identity(obj)[source]

Gets Identity Info for window of an object.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

obj (Any) – object that implements XComponent.

Returns:

Window Info.

Return type:

GUI.Window

static hide_except(lm, ui_elms, show_elms)[source]

Hide all of ui_elms, except ones in show_elms; delete any strings that match in show_elms.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • lm (XLayoutManager) – Layout Manager

  • ui_elms (Iterable[XUIElement]) – Elements

  • show_elms (Sequence[str]) – elements to show

Return type:

None

classmethod hide_memu_bar(cls, doc=None)[source]

Hides the main menu bar

Parameters:

doc (XComponent) – doc (XComponent): office document

Return type:

None

Deprecated since version 0.9.0: Use hide_menu_bar() instead.

Return type:

None

Parameters:

doc (XComponent | None) –

classmethod hide_menu_bar() None[source]
classmethod hide_menu_bar(doc: com.sun.star.lang.XComponent) None
classmethod hide_menu_bar(doc=None)

Hides the main menu bar

Parameters:

doc (XComponent) – doc (XComponent): office document

Return type:

None

classmethod maximize(odoc)[source]

Maximizes Office window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

odoc (XComponent) – Office document.

Return type:

None

Return type:

None

Parameters:

odoc (XComponent) –

classmethod minimize(odoc)[source]

Minimizes Office window.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

odoc (XComponent) – Office document

Return type:

None

Return type:

None

Parameters:

odoc (XComponent) –

classmethod printAllUICommands(doc)[source]

Prints all ui commands to console.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:

doc (XComponent) – office document.

Return type:

None

static print_rect(r)[source]

Prints a rectangle to the console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:

r (Rectangle) – Rectangle to print

Return type:

None

classmethod print_u_is()[source]
classmethod print_u_is(doc: com.sun.star.lang.XComponent)
classmethod print_u_is(lm: com.sun.star.frame.XLayoutManager)
classmethod print_u_is(*args, **kwargs)

Print to console the resource names of every toolbar used by doc.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • lm (XLayoutManager) – Layout manager

  • doc (XComponent) – office document

Return type:

None

classmethod print_ui_cmds(ui_elem_name: str, config_man: com.sun.star.ui.XUIConfigurationManager)[source]
classmethod print_ui_cmds(ui_elem_name: str, doc: com.sun.star.lang.XComponent)
classmethod print_ui_cmds(*args, **kwargs)

Prints ui elements matching ui_elem_name to console.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • ui_elem_name (str) – Name of ui element.

  • config_man (XUIConfigurationManager) – configuration manager.

  • doc (XComponent) – office document.

Return type:

None

static set_look_feel()[source]

This method is not supported. Part of Original java lib.

Raises:

NotImplementedError – Not supported

Return type:

None

classmethod set_pos_size(doc, x, y, width, height)[source]

Sets window position and size.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • doc (XComponent) – office document.

  • x (int) – Window X position.

  • y (int) – Window Y Position.

  • width (int) – Window Width.

  • height (int) – Window Height.

Return type:

None

classmethod set_size_window(doc, width, height)[source]

Sets window size.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • doc (XComponent) – office document.

  • width (int) – Width of window.

  • height (int) – Height of window.

Return type:

None

classmethod set_visible()[source]
classmethod set_visible(visible: bool)
classmethod set_visible(visible: bool, doc: Any)
classmethod set_visible(*, doc: Any)
classmethod set_visible(*args, **kwargs)

Set window visibility.

Parameters:
  • visible (bool, optional) – If True window is set visible; Otherwise, window is set invisible. Default True.

  • doc (Any, optional) – office document. If omitted the current document is used form Lo.lo_component.

Return type:

None

classmethod show_menu_bar() None[source]
classmethod show_menu_bar(doc: com.sun.star.lang.XComponent) None
classmethod show_menu_bar(doc=None)

Shows the main menu bar.

Parameters:

doc (XComponent) – doc (XComponent): office document.

Return type:

None

Changed in version 0.9.0: Renamed from show_menu_bar to show_menu_bar

Return type:

None

Parameters:

doc (XComponent | None) –

classmethod show_message_box(title, message)[source]

Shows a message box.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • title (str) – Messagebox Title.

  • message (str) – Message to display.

Raises:

MissingInterfaceError – If required interface is not present.

Return type:

None

classmethod show_none(doc)[source]

Make all the toolbars invisible.

Method is Lo Instance Safe for use with multiple documents.

Raises:

Exception – if unable to get layout manager from doc

Parameters:

doc (XComponent) – office document.

Return type:

None

classmethod show_one(doc, show_elem)[source]

Leave only the single specified toolbar visible.

Method is Lo Instance Safe for use with multiple documents.

Parameters:
  • doc (XComponent) – office document.

  • show_elem (str) – name of element to show only.

Return type:

None

classmethod show_only(doc, show_elems)[source]

Leave only the specified toolbars visible.

Method is Lo Instance Safe for use with multiple documents.

Raises:

Exception – if unable to get layout manager from doc.

Parameters:
  • doc (XComponent) – office document.

  • show_elems (Iterable[str]) – Elements to show.

Return type:

None

static toggle_menu_bar()[source]

Toggles the main menu visibility.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

If the menu is visible then it is hidden. If it is hidden then it will be made visible.

Return type:

None

Note

Toggle is done dispatching command Menubar.

classmethod zoom(view)[source]
classmethod zoom(view, value)
classmethod zoom(*, value: int = 0)
classmethod zoom(view=ZoomKind.BY_VALUE, value=0)

Sets document zoom level.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • view (ZoomEnum) – Zoom value

  • value (int) – The amount to zoom. eg: 160 zooms 160% value has a min value of 1 and a max value of 3000. If value is out of range then 100% is used.

Return type:

None

classmethod zoom_value(value)[source]
classmethod zoom_value(value, view)
classmethod zoom_value(value, view=ZoomKind.BY_VALUE)

Sets document custom zoom.

Method NOT is Lo Instance Safe. Use Class LoContext when using with multiple document instances.

Parameters:
  • value (int) – The amount to zoom. eg: 160 zooms 160%

  • view (ZoomEnum) – Type of zoom. If view is not ZoomEnum.BY_VALUE then value is ignored. Defaults to ZoomEnum.BY_VALUE.

Return type:

None

FIND_BAR = 'private:resource/toolbar/findbar'
MENU_BAR = 'private:resource/menubar/menubar'
STANDARD_BAR = 'private:resource/toolbar/standardbar'
STATUS_BAR = 'private:resource/statusbar/statusbar'
TOOL_BAR = 'private:resource/toolbar/toolbar'