How to display text at the bottom of the text slider, like a tooltip?

Hi!

I would like to make an extension on LibreOffice on python. I need to display some sentences at the bottom of the text slider. Like the image (I make it):

I also would like to coloured the box of a sentence.
If you need more details ( https://ask.libreoffice.org/t/make-a-autocompletion-with-python/68717/7 )

I use Ubuntu 20.04, LibreOffice 6.

Thank you for your answer

That design says “listbox” to me. Would Python - Tkinter Listbox be any help? I suppose that you have a list of typical first words for the quotes entries, that you then search a list with all possible lines for matching items, and then you add those items to the listbox.

I know one easy popup window in Basic, but I don’t know how to recalculate the position X,Y from ViewCursor to the PopupWindow coordinates.

Sub showPopup
	dim oDoc as object, oWindow as object, oVCur as object
	dim aRect as new com.sun.star.awt.Rectangle, oPopup as object, n&, c&
	oDoc=ThisComponent
	oWindow=oDoc.CurrentController.Frame.ComponentWindow
	oVCur=oDoc.CurrentController.ViewCursor 'view cursor

	aRect=CreateUnoStruct("com.sun.star.awt.Rectangle")
	aRect.X=100 'oVCur.Position.X -> i don't know how to recalculate the coordinates from the ViewCursor
	aRect.Y=100 'oVCur.Position.Y
	oPopup=CreateUnoService("stardiv.vcl.PopupMenu") 'or com.sun.star.awt.PopupMenu
	c=1
	oPopup.insertItem(c, "no hello world, it is not so good place for witty living!", 0, c)
	oPopup.setCommand(c, "item" & c)
	c=2
	oPopup.insertItem(c, "it is possible to say bye bye, but what to do thenceforward?", 0, c)
	oPopup.setCommand(c, "item" & c)	

	n=oPopup.execute(oWindow, aRect, com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT)
	if n>0 then
		msgbox oPopup.getCommand(n)
	end if
End Sub
1 Like

Andrew Pitonyak’s macro document section 7.17. Where is the Display Cursor? gives a routine called PrintCursorLocation that determines cursor coordinates. I added the following line at the end of the routine:

Call showPopup(dXCursor * 100, dYCursor * 100)

This calls the routine posted by @KamilLanda after making the following changes:

Sub showPopup(x, y)
	...
	aRect.X = x
	aRect.Y = y

The result is a popup window shown by the viewcursor. Here is how it looks on my machine.

Clipboard01

If you are not familiar with how to transfer LibreOffice Basic code into a Python macro, see for example Transfer from Basic to Python - Apache OpenOffice Wiki.

If you have never written a Python macro before, get the APSO extension and follow the tutorial at Interface-oriented programming in OpenOffice / LibreOffice : automate your office tasks with Python Macros. Note however that APSO is designed for macro writing and not for building extensions. Specifically, it hides directories that may be needed for creating extensions.