Bug report #19334

Updated by Jürgen Fischer over 5 years ago

in QGIS atlas I use a custom function to find the first file containing texts :

<pre>
import os, fnmatch
from PyQt5.QtCore import QFileInfo
from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def findphoto(nb, src1,src2,feature, parent):
lnb=0
val='NA'
filen = QFileInfo(QgsProject.instance().fileName())
Dir_report=filen.absolutePath()
for root, directories, filenames in os.walk(Dir_report):
for filename in filenames:
if fnmatch.fnmatch(filename, '*' +str(src1) + '*' + str(src2) + '*.jpg' ):
lnb=lnb+1
if lnb==nb:
val=os.path.join(root,filename)
break
return val
</pre>

In QGIS 2.18 it works fine (just change PyQt5 by PyQt4), in QGIS 3.2 it return "NA" value.

In QGIS 3.2 if I try in python mode, it works fine:

<pre>
import os, fnmatch
from PyQt5.QtCore import QFileInfo
from qgis.core import *
from qgis.gui import *

def findphoto(nb, src1,src2):
lnb=0
val='NA'
filen = QFileInfo(QgsProject.instance().fileName())
Dir_report=filen.absolutePath()
for root, directories, filenames in os.walk(Dir_report):
for filename in filenames:
if fnmatch.fnmatch(filename, '*' +str(src1) + '*' + str(src2) + '*.jpg' ):
lnb=lnb+1
if lnb==nb:
val=os.path.join(root,filename)
break
return val
</pre>

why?

Back