Bug 395186

Summary: Document.selection() returns None when selection created by Action is still processing.
Product: [Applications] krita Reporter: SirPigeonz <GBirdboy>
Component: ScriptingAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: andrew.crouthamel
Priority: NOR Keywords: investigated, triaged
Version First Reported In: 4.0.3   
Target Milestone: ---   
Platform: Appimage   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: File for testing

Description SirPigeonz 2018-06-09 19:53:45 UTC
Created attachment 113176 [details]
File for testing

When I try to create selection from Action for example 'selectopaque' and then fetch it with s = doc.selection() most of the time I will get s == None.
If I run the same code again when selection already exists doc.selection() returns actual selection.

Steps:
1 Open Attached test file
2 Select layer with green circle
3 Run this script in Scripter

from krita import *

k = Krita.instance()
d = k.activeDocument()

def test_selection():
    k.action('selectopaque').trigger()

    s = d.selection()
    if s == None:
        print("Yes...")
    else:
        print("No O_O")

    s.invert()
    d.setSelection(s)
    d.refreshProjection() 	

test_selection()
#test_selection()

Result:
Krita will creates selection from the green circle.
Scripter throws: AttributeError: 'NoneType' object has no attribute 'invert'

Expected result:
Krita creates selection from the green circle and inverts this selection.

4 Remove selection from the Image
5 Uncomment last line of the script so test_selection() will be run 2 times in a row.
6 Run script again

Result:
As expected. Inverted selection from green circle.
Comment 1 SirPigeonz 2018-06-09 20:03:19 UTC
I think that action is not able to create selection in time and doc.selection() is not aware that Image is middle of operation and is not waiting for it to finish.
Comment 2 Andrew Crouthamel 2018-10-02 16:04:36 UTC
Hi, I tested this on the latest git master.

When I run follow your instructions the script provides the following error, and ends up providing a selection of the green circle, but not an inverted one.

==== Warning: Script not saved! ====
Yes...

**********************
AttributeError: 'NoneType' object has no attribute 'invert'

In file: <string>
In function: test_selection at line: 15. Line with error:

**********************

Could you test again on the latest version and report back with the behavior?
Comment 3 Bug Janitor Service 2018-11-12 16:00:14 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 4 Bug Janitor Service 2018-11-27 04:46:37 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!