Bug 127009 - "Selection" property is empty when selecting a slide in Slides pane using PyUNO
Summary: "Selection" property is empty when selecting a slide in Slides pane using PyUNO
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
6.2.5.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-18 13:37 UTC by Konstantin Kharlamov
Modified: 2024-06-19 08:40 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Connect to LO server, and print `CurrentComponent.CurrentSelection` (584 bytes, text/x-python)
2019-08-18 13:37 UTC, Konstantin Kharlamov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kharlamov 2019-08-18 13:37:59 UTC
Created attachment 153473 [details]
Connect to LO server, and print `CurrentComponent.CurrentSelection`

I need to programmatically focus a slide in Slides pane, so I could copy the slide. However, it seems like selection of the slide does not influence the Selection property.

# Steps to reproduce

1. Run `soffice --impress --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"`, and dismiss "Select a Template" window.
2. There should be a pane titled "Slides" on the left with a single slide. Click it. (note, how Edit → Copy menu was grayed out before, and became available afterwards, which means you succeeded in selecting the slide)
3. Execute attached `test.py` script, which prints the currently selected object.

## Expected

Something different from `None`

## Actual

It prints:

    None


# Additional information

For background see also:
    https://ask.libreoffice.org/en/question/205218/uno-how-to-focus-a-slide/
    https://ask.libreoffice.org/en/question/204747/uno-copy-a-slide-between-2-impress-documents/
Comment 1 Buovjaga 2019-12-06 15:07:17 UTC
I get
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    print(desktop.CurrentComponent.CurrentSelection)
__main__.RuntimeException: Binary URP bridge disposed during call

Arch Linux 64-bit
Version: 6.5.0.0.alpha0+
Build ID: 7e403195e574be5174815a51cf5c42f06f76a87a
CPU threads: 8; OS: Linux 5.3; UI render: default; VCL: kf5; 
Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
Calc: threaded
Built on 1 December 2019
Comment 2 Konstantin Kharlamov 2019-12-08 19:01:41 UTC
(In reply to Buovjaga from comment #1)
> I get
> Traceback (most recent call last):
>   File "test.py", line 14, in <module>
>     print(desktop.CurrentComponent.CurrentSelection)
> __main__.RuntimeException: Binary URP bridge disposed during call
> 
> Arch Linux 64-bit
> Version: 6.5.0.0.alpha0+
> Build ID: 7e403195e574be5174815a51cf5c42f06f76a87a
> CPU threads: 8; OS: Linux 5.3; UI render: default; VCL: kf5; 
> Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
> Calc: threaded
> Built on 1 December 2019

Apparently, this is a separate regression in 6.5. I looked at the script, it's pretty short, and it doesn't seem to do anything invalid.

On 6.3.3 I currently have the script prints "None".
Comment 3 Xisco Faulí 2020-06-18 10:33:27 UTC
Hi Konstantin,
is this issue still reproducible with a daily build from http://dev-builds.libreoffice.org/daily/master/ ?
You can install it alongside the standard version.
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' if the bug is still present in the master build
Comment 4 Konstantin Kharlamov 2020-06-18 10:42:29 UTC
(In reply to Xisco Faulí from comment #3)
> Hi Konstantin,
> is this issue still reproducible with a daily build from
> http://dev-builds.libreoffice.org/daily/master/ ?
> You can install it alongside the standard version.
> I have set the bug's status to 'NEEDINFO'. Please change it back to
> 'UNCONFIRMED' if the bug is still present in the master build

Hi! Hmm, this would be a bit hard to test, because I'm on Arch and your link has no Archlinux package. I could unpack rpm or deb package, and then run the unpacked binary, will it work? I'm unsure as I'd guess it may use the system LO libraries instead of the unpacked ones. But if yes, I could try it.

I wonder, are you asking out of pure curiosity, or do you have some reason to believe it may have been fixed?
Comment 5 Buovjaga 2020-06-18 10:48:50 UTC
You could try an appimage of 7.0 beta: https://libreoffice.soluzioniopen.com/index.php/7-0-pre-releases/
You only set it to be executable and then run the file.
Comment 6 Konstantin Kharlamov 2020-06-18 11:01:29 UTC
(In reply to Buovjaga from comment #5)
> You could try an appimage of 7.0 beta:
> https://libreoffice.soluzioniopen.com/index.php/7-0-pre-releases/
> You only set it to be executable and then run the file.

Thanks! I tested it, I get the same output `Binary URP bridge disposed during call` as in comment 1. So I don't think we can check whether it's been fixed as there's still that.
Comment 7 Buovjaga 2020-06-18 12:11:50 UTC
Ok, I confirmed the printed None with older commits while I was bibisecting the regression. Regression filed as bug 134106
Comment 8 QA Administrators 2022-06-19 03:29:02 UTC Comment hidden (obsolete)
Comment 9 QA Administrators 2024-06-19 03:16:03 UTC Comment hidden (obsolete)
Comment 10 Konstantin Kharlamov 2024-06-19 04:18:32 UTC
So, I am trying to repro this again, and I'm getting the following error:

    Traceback (most recent call last):
      File "/tmp/test.py", line 1, in <module>
        import uno
      File "/usr/lib/python3.12/site-packages/uno.py", line 19, in <module>
        import pyuno
    ModuleNotFoundError: No module named 'pyuno'

Note: I am importing `uno`, however the error goes from the LibreOffice internals about "pyuno" instead.

I made a file search for a file named "pyuno"¹ in the sources and LO repo has none. I presume this is a new bug on the LO side…?

1: https://github.com/search?q=repo%3ALibreOffice%2Fcore+path%3A**%2Fpyuno*&type=code
Comment 11 Buovjaga 2024-06-19 08:10:34 UTC
(In reply to Konstantin Kharlamov from comment #10)
> So, I am trying to repro this again, and I'm getting the following error:
> 
>     Traceback (most recent call last):
>       File "/tmp/test.py", line 1, in <module>
>         import uno
>       File "/usr/lib/python3.12/site-packages/uno.py", line 19, in <module>
>         import pyuno
>     ModuleNotFoundError: No module named 'pyuno'
> 
> Note: I am importing `uno`, however the error goes from the LibreOffice
> internals about "pyuno" instead.
> 
> I made a file search for a file named "pyuno"¹ in the sources and LO repo
> has none. I presume this is a new bug on the LO side…?
> 
> 1:
> https://github.com/
> search?q=repo%3ALibreOffice%2Fcore+path%3A**%2Fpyuno*&type=code

Not a bug on LibreOffice's side. You seem to have installed uno.py via pip. Better to use what is shipped with LibreOffice.

This might help to check:
export PYTHONPATH=/usr/lib/libreoffice/program/:$PYTHONPATH

For me, nothing is printed with test.py with the original steps (uno is imported fine).

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: cfffcbc39b2c6794eaeddae5134fb59848a76d41
CPU threads: 8; OS: Linux 6.9; UI render: default; VCL: kf6 (cairo+wayland)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: CL threaded
Comment 12 Konstantin Kharlamov 2024-06-19 08:23:17 UTC
(In reply to Buovjaga from comment #11)
> (In reply to Konstantin Kharlamov from comment #10)
> > So, I am trying to repro this again, and I'm getting the following error:
> >
> >     Traceback (most recent call last):
> >       File "/tmp/test.py", line 1, in <module>
> >         import uno
> >       File "/usr/lib/python3.12/site-packages/uno.py", line 19, in <module>
> >         import pyuno
> >     ModuleNotFoundError: No module named 'pyuno'
> >
> > Note: I am importing `uno`, however the error goes from the LibreOffice
> > internals about "pyuno" instead.
> >
> > I made a file search for a file named "pyuno"¹ in the sources and LO repo
> > has none. I presume this is a new bug on the LO side…?
> >
> > 1:
> > https://github.com/
> > search?q=repo%3ALibreOffice%2Fcore+path%3A**%2Fpyuno*&type=code
>
> Not a bug on LibreOffice's side. You seem to have installed uno.py via pip.
> Better to use what is shipped with LibreOffice.

Checked: `uno.py` is the one shipped with LibreOffice

    λ pacman -Qo /usr/lib/python3.12/site-packages/uno.py
    /usr/lib/python3.12/site-packages/uno.py is owned by libreoffice-fresh 24.2.4-1
    λ pacman -Qo /usr/lib/libreoffice/program/* | grep -v libreoffice-fresh
    [… no output, i.e. everything's owned by libreoffice-fresh …]

> This might help to check:
> export PYTHONPATH=/usr/lib/libreoffice/program/:$PYTHONPATH

This indeed has helped. However, I had never had to use PYTHONPATH env. variable
AFAIR, so something's changed compared to how it worked before…

I just checked whether I rebooted the system after the last update, and I did, so
that's not it…

> For me, nothing is printed with test.py with the original steps (uno is
> imported fine).

With the `PYTHONPATH` workaround I get this error printed:

    λ python3 test.py
    Traceback (most recent call last):
      File "/tmp/test.py", line 13, in <module>
        desktop = connectToLO()
                  ^^^^^^^^^^^^^
      File "/tmp/test.py", line 11, in connectToLO
        return smgr.createInstanceWithContext( "com.sun.star.frame.Desktop", ctx)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    com.sun.star.uno.RuntimeException: Binary URP bridge disposed during call at /usr/src/debug/libreoffice-fresh/libreoffice-24.2.4.2/binaryurp/source/bridge.cxx:615
Comment 13 Buovjaga 2024-06-19 08:40:48 UTC
(In reply to Konstantin Kharlamov from comment #12)
> This indeed has helped. However, I had never had to use PYTHONPATH env.
> variable
> AFAIR, so something's changed compared to how it worked before…
> 
> I just checked whether I rebooted the system after the last update, and I
> did, so
> that's not it…

You might ask for help on some support channel/forum of your Linux distribution.