Bug 398740 - Updating fileLayer path from script result in invalid path
Summary: Updating fileLayer path from script result in invalid path
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Unclassified
Component: Scripting (show other bugs)
Version: 4.1.1
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-17 03:10 UTC by tkp
Modified: 2018-09-24 07:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
file layers setProperties test files (540.67 KB, application/zip)
2018-09-17 03:10 UTC, tkp
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tkp 2018-09-17 03:10:44 UTC
Created attachment 115026 [details]
file layers setProperties test files

Hi,


1. Original potential bug using 4.0.4
-------------------------------------

fileLayer.setProperties() seem to prepend the old filename without extension before the new path.

  # display nodes current path :
  print("node path : ",node.path())
  # node path : /home/user/file-layers-setProperties/file-layers/file-layer-1.png

  # update file layer path :
  node.setProperties(node.path().replace("file-layer-1", "file-layer-2"), "None")
  print("node path : ",node.path())
  # node path :  file-layer-1/../file-layers-setProperties/file-layers/file-layer-2.png

  # Expected : file-layers/file-layer-2.png
  #       or : /home/user/file-layers-setProperties/file-layers/file-layer-2.png


2. Evolution using krita 4.1.1 (error message)
----------------------------------------------

Was using a trick based on previous observations to update the path using 4.0.4 (see attached script/file), but Krita 4.1.1 now displays an additional error :

  Krita has encountered an internal error:
  SAFE ASSERT (krita): "QFile::exists(path())" in file /home/appimage/workspace/Krita_Stable_Appimage_Build/krita/libs/ui/kis_file_layer.cpp, line 80
  Please report a bug to developers!
  
  Press Ignore to try to continue.
  Press Abort to see developers information (all unsaved data will be lost)

In the attached zip, a test file, test script and dummy filelayers. Using 4.0.4, no error message is displayed. On both versions, the layer is updated after save/reload.

To reproduce on my setup :

1. Open filelayer-setProperties-411.kra
2. Tools > Scripting > Scripter : run test.py
3. should print explanation about the trick and update the path
4. create-delete an empty layer if krita didn't detect the edit
5. save file : Krita displays an error message, click "Ignore"
6. close and re-open the file : the layer should be updated (red)

- tested not using the trick under 4.1.1 but the setProperties behaviour is the same as in 4.0.4
- tested placing the fileLayer source files next to the .kra vs in a subfolder, but doesn't seem to help


Am I misusing the method / arguments ?
Anyone able to reproduce ?

Bonus question : is there an function to force-reload a fileLayer source file from python ? For now it seem required to save/close/reopen to display the new one.


Thanks for any clues, have a nice day !
Comment 1 Dmitry Kazakov 2018-09-17 07:26:13 UTC
Git commit 2b555ade3e2c84a177c590ab660bdfc1ff042584 by Dmitry Kazakov.
Committed on 17/09/2018 at 07:25.
Pushed by dkazakov into branch 'master'.

Fix setting file path of the file layer through python API

M  +23   -11   libs/libkis/FileLayer.cpp
M  +1    -1    libs/libkis/FileLayer.h

https://commits.kde.org/krita/2b555ade3e2c84a177c590ab660bdfc1ff042584
Comment 2 Dmitry Kazakov 2018-09-17 07:31:54 UTC
Hi, tkp!

The bug should be fixed now! Please check if it is really fixed for you in tomorrow's nightly builds:

https://binary-factory.kde.org/job/Krita_Nightly_Appimage_Build/

Answer to a bonus question:

just calling 

fileLayer->setProperties(fileLayer->path(), fileLayer->scalinfMethod()) 

should work for you. Though I'll try to add a separate resetCache() API for that.
Comment 3 Dmitry Kazakov 2018-09-17 08:03:28 UTC
Git commit 2617256482d43cb8c133281e434662279931ff8e by Dmitry Kazakov.
Committed on 17/09/2018 at 08:03.
Pushed by dkazakov into branch 'master'.

Add resetCache() Python API to FileLayer

That is a simple method to reload the image from disk

M  +6    -0    libs/libkis/FileLayer.cpp
M  +5    -0    libs/libkis/FileLayer.h
M  +1    -0    plugins/extensions/pykrita/sip/krita/FileLayer.sip

https://commits.kde.org/krita/2617256482d43cb8c133281e434662279931ff8e
Comment 4 tkp 2018-09-17 08:20:20 UTC
Hi Dmitry,

thanks a lot for your quick fix and advice, will check with the nightly build tomorrow !
Comment 5 tkp 2018-09-17 17:56:27 UTC
It is fixed on my system too, and after using setProperties the file layer image is automatically reloaded. Awesome ! Thanks again Dmitry !
Comment 6 Halla Rempt 2018-09-24 07:17:06 UTC
Git commit a4ddedcce316c09e03a578f19018a0442c944af4 by Boudewijn Rempt, on behalf of Dmitry Kazakov.
Committed on 24/09/2018 at 06:57.
Pushed by rempt into branch 'krita/4.1'.

Fix setting file path of the file layer through python API

M  +23   -11   libs/libkis/FileLayer.cpp
M  +1    -1    libs/libkis/FileLayer.h

https://commits.kde.org/krita/a4ddedcce316c09e03a578f19018a0442c944af4
Comment 7 Halla Rempt 2018-09-24 07:17:06 UTC
Git commit 01e31f1be148d01c27b2082ff1a38c55c7d1131f by Boudewijn Rempt, on behalf of Dmitry Kazakov.
Committed on 24/09/2018 at 06:57.
Pushed by rempt into branch 'krita/4.1'.

Add resetCache() Python API to FileLayer

That is a simple method to reload the image from disk

M  +6    -0    libs/libkis/FileLayer.cpp
M  +5    -0    libs/libkis/FileLayer.h
M  +1    -0    plugins/extensions/pykrita/sip/krita/FileLayer.sip

https://commits.kde.org/krita/01e31f1be148d01c27b2082ff1a38c55c7d1131f