Bug 443248 - Notifier class not properly initialized
Summary: Notifier class not properly initialized
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (show other bugs)
Version: 5.0.0-beta1
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-03 07:48 UTC by grum999
Modified: 2021-10-03 09:57 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description grum999 2021-10-03 07:48:27 UTC
SUMMARY

In setup() method of a plugin called at Krita's startup:

"""
    def setup(self):
        def windowCreated():
            print('windowCreated!')

        print("Notifier active: ", Krita.instance().notifier().active())
        Krita.instance().notifier().windowCreated.connect(windowCreated)
"""

In terminal we have:
"""
Notifier active: False
windowCreated!
"""

That's not consistent: if notifier is not active, signal should not be emitted in window is created.

An explicit call to """Krita.instance().notifier().setActive(False)""" fix the problem.


STEPS TO REPRODUCE
1. Create a basic plugin
2. Edit setup() method to connect a signal for "windowCreated"
3. Execute Krita

OBSERVED RESULT
Even if notifier indicate it's not active, notifier signals are emitted


EXPECTED RESULT
The notifier should be properly initialized.

There's 2 possibilities:
1) set the default value to True 
2) set the default value to False and force signal to be blocked


Personaly, I prefer the first solution because my plugins consider that by default notifier is active (and that's currently the case, signals are emitted by default) and if notifier is deactivated by default, this implies to update all plugins that use signals and consider that it's active by default..


ADDITIONAL INFORMATION

Looking:
https://invent.kde.org/graphics/krita/-/blob/master/libs/libkis/Notifier.cpp#L16

The variable is set to false by default
"""
struct Notifier::Private {
    Private() {}
    bool active {false};
};
"""


But looking:
https://invent.kde.org/graphics/krita/-/blob/master/libs/libkis/Notifier.cpp#L50

We can see that to activate/deactivate notifier signal, there's a call to 'blockSignals'
"""
void Notifier::setActive(bool value)
{
    d->active = value;
    blockSignals(!value);
}
"""


So whatever the solution is choosed (1 or 2), it might be better to force a call to blockSignals() when class is initialized, to be sure that activation status is consistent with defined value



Grum999
Comment 1 Halla Rempt 2021-10-03 09:57:35 UTC
Git commit 1fda121446e70ca0598065f2ccc3f87b9c966f50 by Halla Rempt.
Committed on 03/10/2021 at 09:57.
Pushed by rempt into branch 'krita/5.0'.

Notifier: set the default value to "true"
(cherry picked from commit 830d8e31eb53eafd164d13a6e7085d824005ce3d)

M  +3    -1    libs/libkis/Notifier.cpp

https://invent.kde.org/graphics/krita/commit/1fda121446e70ca0598065f2ccc3f87b9c966f50
Comment 2 Halla Rempt 2021-10-03 09:57:53 UTC
Git commit 83c00a8588d4323a1054cce312786263c2bd2a2e by Halla Rempt.
Committed on 03/10/2021 at 09:57.
Pushed by rempt into branch 'master'.

Notifier: set the default value to "true"
(cherry picked from commit 830d8e31eb53eafd164d13a6e7085d824005ce3d)

M  +3    -1    libs/libkis/Notifier.cpp

https://invent.kde.org/graphics/krita/commit/83c00a8588d4323a1054cce312786263c2bd2a2e