Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why python function not work in custom function in QGIS 3.0? #27162

Closed
qgib opened this issue Jul 4, 2018 · 3 comments
Closed

Why python function not work in custom function in QGIS 3.0? #27162

qgib opened this issue Jul 4, 2018 · 3 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers

Comments

@qgib
Copy link
Contributor

qgib commented Jul 4, 2018

Author Name: dany Lefeuvre (dany Lefeuvre)
Original Redmine Issue: 19334
Affected QGIS version: 3.2
Redmine category:unknown


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

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

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:

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

why?

@qgib
Copy link
Contributor Author

qgib commented Jul 5, 2018

Author Name: dany Lefeuvre (dany Lefeuvre)


oups error in tittle this is for qgis 3.2

@qgib
Copy link
Contributor Author

qgib commented Sep 25, 2018

Author Name: Jürgen Fischer (@jef-n)


  • description was changed from in QGIS atlas I use a custom function to find the first file containing texts :

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
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:

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
why? to in QGIS atlas I use a custom function to find the first file containing texts :

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

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:

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

why?

@qgib qgib added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label May 25, 2019
@alexbruy alexbruy added the Feedback Waiting on the submitter for answers label Jan 18, 2020
@alexbruy
Copy link
Contributor

If this is a question, it should be asked in the mailing list.

@gioman gioman closed this as completed Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers
Projects
None yet
Development

No branches or pull requests

3 participants