I'm still trying to write a python plugin to create an input file for an urban climate model out of three shape files. Now I stumbeled into another problem, that I think is an easy one, but I just can't see whats wrong. I wrote a little function to get me the path and file name of the current project file (as I want the result file of my calculations to be called like the project file by default).
def projectfilepathname():
# function to extract the file path and name of the current project file
qgis.mainWindow().statusBar().showMessage("Getting project name and path")
prjfi = QFileInfo(QgsProject.instance().fileName())
path_name = []
if prjfi:
path_name.append(str(prjfi.absolutePath()))
filename = str(prjfi.fileName())
if filename.count(".") > 0:
path_name.append(filename.split(".")[0])
else:
path_name.append(filename)
path_name.append(prjfi.fileName())
else:
path_name.append(r'C:\Users')
path_name.append(r'test')
return path_name
I call the function by
currentprofile = self.projectfilepathname
but that doesn't seem to work. At least I get an error for the next line
currentprofile_dir = currentprofile[1]
telling me 'instancemethod' object has no attribute 'getitem'. Maybe I'm wrong, but I have the impression that the function is not called, but its name is saved to currentprofile. Whats wrong?