[Solved] Position of Dialog Window (pixels/map appfonts)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
LukeBB
Posts: 30
Joined: Wed Oct 26, 2016 10:35 pm

[Solved] Position of Dialog Window (pixels/map appfonts)

Post by LukeBB »

My goal: to display the dialog window at a reasonable place on a monitor. I would like to detect the currently active Libre Office window and display the dialog window in the middle of it (using Python). Or some other method not to display the window in some random corner, other monitor etc. but reasonably on the place where the user is currently working.

To find current position and dimensions of the current active Libre Office window in pixels is not a problem:

Code: Select all

from com.sun.star.awt import PosSize
active_window = self.desktop.getCurrentFrame().getContainerWindow()
pos_size = active_window.getPosSize()
x_current_lo_window = pos_size.X
y_current_lo_window = pos_size.Y
width_current_lo_window = pos_size.Width
height_current_lo_window = pos_size.Height
But to display the dialog window at X and Y pixels is a problem, because we can not use pixels but we have to use "Map AppFont" units.

This: https://wiki.openoffice.org/wiki/Docume ... Properties says: "PositionX, PositionY...they use the Map AppFont unit. Map AppFont units are device and resolution independent. One Map AppFont unit is equal to one eighth of the average character (Systemfont) height and one quarter of the average character width. The dialog editor also uses Map AppFont units, and sets their values automatically."

My code to display the windows is:

Code: Select all

dialog_model = self.smgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
dialog_model.PositionX = 200
dialog_model.PositionY = 200
...but I do not want to display the window at some weird Map AppFonts unit but pixels. And it must work on various different computers, not just mine. On my personal computer 1 x Mapp AppFont = 1.99 pixels. 1 Map AppFont = 1.6 pixels. I need a general function to display the dialog on X and Y in pixels. Or a function to find, how much is 1 Map AppFont on the current PC. Or at least a function to get this "Systemfont" average dimenstions so I can do some math. Please, would anyone know how to place my dialog window as I want?
Last edited by LukeBB on Fri Sep 01, 2023 5:18 pm, edited 1 time in total.
LibreOffice 7.5.5.2 on Linux Mint 21
JeJe
Volunteer
Posts: 3127
Joined: Wed Mar 09, 2016 2:40 pm

Re: Position of Dialog Window (pixels/map appfonts)

Post by JeJe »

Is easy, setpossize is in pixels.

Code: Select all

active_window.setPosSize 100,100,500,500,15
https://www.openoffice.org/api/docs/com ... setPosSize
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JPL
Volunteer
Posts: 133
Joined: Fri Mar 30, 2012 3:14 pm

Re: Position of Dialog Window (pixels/map appfonts)

Post by JPL »

Kubuntu 22.04 / LibO 24.2
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
JeJe
Volunteer
Posts: 3127
Joined: Wed Mar 09, 2016 2:40 pm

Re: Position of Dialog Window (pixels/map appfonts)

Post by JeJe »

The map appfont is not relevant.

The link mentioning that is talking about positioning controls.

Note: If setpossize doesn't quite give what you want its because its not the position of the border/titlebar - but the inner window excluding those.

Edit:

if you want to adjust for those compare

Code: Select all

.ContainerWindow.accessiblecontext.LocationOnScreen
with

Code: Select all

.ContainerWindow.accessiblecontext.location
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
LukeBB
Posts: 30
Joined: Wed Oct 26, 2016 10:35 pm

Re: Position of Dialog Window (pixels/map appfonts)

Post by LukeBB »

Thank you so much Jeje! This is solved. The solution to convert pixels to Map AppFont is here and works perfectly well:

Code: Select all

    def pixels_xy_to_mapappfont(self, desktop, x, y):
        active_window = desktop.getCurrentFrame().getContainerWindow()
        mapappfont_coordinates = active_window.convertPointToLogic(Point(x, y), MeasureUnit.APPFONT)
        x = mapappfont_coordinates.X
        y = mapappfont_coordinates.Y
        return x, y
LibreOffice 7.5.5.2 on Linux Mint 21
JeJe
Volunteer
Posts: 3127
Joined: Wed Mar 09, 2016 2:40 pm

Re: Position of Dialog Window (pixels/map appfonts)

Post by JeJe »

I think you mean JPL then. It looks like he's solved your problem and I didn't.

You edit the thread heading by putting [solved] at the front if you're happy.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
LukeBB
Posts: 30
Joined: Wed Oct 26, 2016 10:35 pm

Re: [Solved] Position of Dialog Window (pixels/map appfonts)

Post by LukeBB »

Oh sorry, JPL solved it :-) Thank you both!!
LibreOffice 7.5.5.2 on Linux Mint 21
Post Reply