Bug 161843 - Python Macro Interface fails self-identity test.
Summary: Python Macro Interface fails self-identity test.
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.3.7.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-29 22:14 UTC by Tristin Alexander Schwartze
Modified: 2024-06-30 18:46 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tristin Alexander Schwartze 2024-06-29 22:14:03 UTC
Description:
Given the following test macro in python, False, not True is added to the text. 

_________________________________________

import uno
def test(*arg):
  """This is a test macro."""
  
  desktop  = XSCRIPTCONTEXT.getDesktop()
  document = XSCRIPTCONTEXT.getDocument()
  model = desktop.getCurrentComponent()
  text = model.Text
  model.Text.End.String = f"{text.Start == text.Start}"

_________________________________________

This is far from the only issue with the python interface/interface-documentation and I'd be very grateful a more general update, but this one is particularly bad. I'd guess the program is generating a new object on each request .getStart() probably and those objects have no way to compare to each other. 

Admittedly, I am on 7.3.7.2 release, so maybe I need to update.

Steps to Reproduce:
1. sudo apt-get update -y
2. sudo apt-get install -y libreoffice-script-provider-python
3. cd /usr/lib/libreoffice/share/Scripts/python/
4. sudo touch example.py
5. add code above to example.py
6. Open libreoffice, navigate to Tools>Macros>organize macros> python 
7. Run test
8. observe incorrect result.

Actual Results:
False is added to end of document

Expected Results:
True should be added to end of document


Reproducible: Always


User Profile Reset: No

Additional Info:
Compared the internal values, probably some sort of document position value, and determined if those values equaled then respond according to that.
Comment 1 Werner Tietz 2024-06-30 18:40:38 UTC
first: Don't do 3. 4. 5. in daily practise! never!! store youre python-code to:
~/.config/libreoffice/4/user/Scripts/python/…

youre »asking« twice for »text.Start« so there are 2 pointing to the same, you may avoid it by:

___________________
def test(*arg):
    """
    This is a test macro.
    keep sure you have some writer.odt in focus
    """
    document = XSCRIPTCONTEXT.getDocument()
    text_object = document.Text.Start
    document.Text.End.String = f"{text_object is text_object}"
__________________

Also note that object equality is checked with "is" and not with the "==" operator, and that you do not have to obtain the reference to the currently open document in focus in two different ways!

I would say: Not a Bug!