Bug 149983 - ScriptForge Dialog service not returning after EndExecute call in Python
Summary: ScriptForge Dialog service not returning after EndExecute call in Python
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.3.1.3 release
Hardware: All All
: medium normal
Assignee: Jean-Pierre Ledure
URL:
Whiteboard: target:7.5.0 target:7.4.0.2 target:7.3.6
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2022-07-13 17:58 UTC by Rafael Lima
Modified: 2024-02-08 12:20 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Sample file with scripts (12.55 KB, application/vnd.oasis.opendocument.spreadsheet)
2022-07-13 17:58 UTC, Rafael Lima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Lima 2022-07-13 17:58:11 UTC
Created attachment 181255 [details]
Sample file with scripts

I have a Basic dialog with a "Close" button in it.

Using the SF Dialog service in Basic to display the dialog and then close it using a callback function also written in Basic works as expected. Below is the code in Basic that processes the event:

Sub CloseDialog_Basic(oEvent)
    btnControl = CreateScriptService("DialogEvent", oEvent)
    myDialog = btnControl.Parent
    myDialog.EndExecute()
End Sub

However the equivalent code in Python does not work. It seems the code never exits the EndExecute() call.

def btn_close_click(event=None):
    btn_control = CreateScriptService("DialogEvent", event)
    my_dialog = btn_control.Parent
    my_dialog.EndExecute(0)

There seems to be something holding the interpreter after the EndExecute call.

I attached a file with the scripts in Basic and Python for testing.

System info:

Version: 7.3.4.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 12; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: pt-BR
Ubuntu package version: 1:7.3.4-0ubuntu0.22.04.1
Calc: threaded
Comment 1 Jean-Pierre Ledure 2022-07-14 13:53:21 UTC
The bug is confirmed in master and 7.4 branches.

The EndExecute() is not executed when next conditions are met:
- the dialog is opened in modal mode from a Python user script (Execute)
- the control event closing the dialog (EndExecute) is also run from a Python user script
(when one or both of them is/are a Basic script, there is no issue).

The root cause is that
- both runs make use of the CallByName Basic native function
- the Execute() is suspended until the closure of the dialog => the CallByName is also suspended
- it seems that during its execution, the CallByName function locks the concerned object instance for exclusive use. Instead of running EndExecute, CallByName immediately cancels the running process.

The bug can be fixed by forcing a hardcoded call to the methods in the Dialog service which may potentially be called while the dialog is open, bypassing the generic CallByName method:
   Activate
   Center
   EndExecute
   Resize
Comment 2 Commit Notification 2022-07-16 07:50:22 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/91a1662c66e5e988d36012533fceab9221607282

ScriptForge - tdf#149983 dialog.EndExecute() failure

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2022-07-16 13:15:48 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/b56cf8b8c97215a3422532e9a98bef3110fab7c1

ScriptForge - tdf#149983 dialog.EndExecute() failure

It will be available in 7.4.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Rafael Lima 2022-07-16 13:31:01 UTC
I tested the patch with the sample document and both dialogs (Basic and Python) close as expected.

Setting this as FIXED.
Comment 5 Commit Notification 2022-07-21 12:54:23 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/cd8ab93d9b84ed34d18334e07e1e11bd1728e161

ScriptForge - tdf#149983 dialog.Execute() failure

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Commit Notification 2022-07-21 14:20:59 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/d1e09ee551b18eedb46c2bb4bc5cd175b94bcd93

ScriptForge - tdf#149983 dialog.Execute() failure

It will be available in 7.4.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Commit Notification 2022-08-12 15:31:00 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/356bb47cb404eb54d1aea4ae7ab72c13e5f904ea

ScriptForge - tdf#149983 dialog.EndExecute() failure

It will be available in 7.3.6.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.