Open oskeng opened 4 years ago
In qgyf.py line 70-ish you should use cross-plattform syntax and adapt to different OS (windows):
if not self.proj.readEntry("QGYF", "dataPath")[0]:
# Plugin directory for cross-plattform use
home_folder = os.path.expanduser("~")
if os.name == 'nt':
self.proj.writeEntry('QGYF', 'dataPath', os.path.join(home_folder, 'AppData', 'Roaming', 'QGYF'))
elif os.name == 'posix':
self.proj.writeEntry('QGYF', 'dataPath', os.path.join(home_folder, '.local', 'share', 'QGYF'))
if not os.path.exists(self.proj.readEntry("QGYF", "dataPath")[0]):
os.makedirs(self.proj.readEntry("QGYF", "dataPath")[0])
Also, it's not really nice to have "\" in the code for paths, not even if "escaped".
Use the above os.path.join() function to build paths that work cross-plattform.
Using os.startfile() (around line 190) to open PDF file is not supported on anything except Windows. Use:
import webbrowser
try:
webbrowser.open(docPath)
except:
QMessageBox.warning(ExportDialog(), 'Ingen PDF läsare', 'Det ser ut att ingen PDF läsare finns installerat på datorn.')
I guess there's more cross-plattform issues to deal with as well...
When adding the plugin in QGIS, I get the below message. Reproduced on MACOSX with QGIS v. 3.4 and Python37.
Probably caused by calling os.getenv('APPDATA') (line 75 in qgyf.py) which returns appdata folder on Windows but null on unix.
Couldn't load plugin 'qgyf-master-oskeng' due to an error when calling its classFactory() method
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Traceback (most recent call last): File "/usr/lib/python3/dist-packages/qgis/utils.py", line 334, in _startPlugin plugins[packageName] = package.classFactory(iface) File "/home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgyf-master-oskeng/init.py", line 35, in classFactory return QGYF(iface) File "/home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgyf-master-oskeng/qgyf.py", line 75, in init self.proj.writeEntry("QGYF", "dataPath", os.getenv('APPDATA') + '/QGYF') TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Python version: 3.7.5 (default, Nov 20 2019, 09:21:52) [GCC 9.2.1 20191008] QGIS version: 3.12.1-București București, 121cc00ff0
Python Path: /usr/share/qgis/python /home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python /home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python/plugins /usr/share/qgis/python/plugins /usr/lib/python37.zip /usr/lib/python3.7 /usr/lib/python3.7/lib-dynload /usr/local/lib/python3.7/dist-packages /usr/lib/python3/dist-packages /home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python /home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python/plugins/QGYF/ui C:\Program Files\QGIS 3.4\apps\qgis\python C:\Program Files\QGIS 3.4\apps\qgis\python /home/oskeng/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgyf-master-oskeng/ui C:\Program Files\QGIS 3.4\apps\qgis\python