Bug report #13693

Unable to open a python script from the python editor

Added by Alessandro Frigeri about 9 years ago. Updated about 7 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:PyQGIS Console
Affected QGIS version:master Regression?:No
Operating System:GNU/Linux Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:21723

Description

Hello,

on 2.12.0-Lyon, trying to load a python script via GUI (Python console -> show editor -> open file), I do not get the file selection window but this error:

An error has occured while executing Python code: 

TypeError: QFileDialog.getOpenFileNames(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 3 has unexpected type 'QDir' 
Traceback (most recent call last):
  File "/usr/share/qgis/python/console/console.py", line 639, in openScriptFile
    self, openFileTr, lastDirPath, "Script file (*.py)")
TypeError: QFileDialog.getOpenFileNames(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 3 has unexpected type 'QDir'

Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2] 
QGIS version: 2.12.0-Lyon Lyon, exported 

Python Path:
/usr/share/qgis/python/plugins/processing
/home/alf/.qgis2/python/plugins/postgis_geoprocessing
/usr/share/qgis/python
/home/alf/.qgis2/python
/home/alf/.qgis2/python/plugins
/usr/share/qgis/python/plugins
/usr/local/lib/python2.7/dist-packages/GDAL-1.10.1-py2.7-linux-x86_64.egg
/home/alf/opt/crism
/opt/madagascar-1.2/lib/python2.7/dist-packages
/opt/madagascar-1.2/lib
/home/alf/gitwrk/lib/python/radalf
/home/alf/gitwrk/work/lib/python
/home/alf/gitwrk/crism
/home/alf/gitwrk/sillyolimpics/sillyolympics
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/home/alf/.local/lib/python2.7/site-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/Numeric
/usr/lib/python2.7/dist-packages/PILcompat
/usr/lib/python2.7/dist-packages/gst-0.10
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.7
/usr/lib/python2.7/dist-packages/ubuntu-sso-client
/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode
/home/alf/.qgis2//python
/home/alf/.qgis2/python/plugins
/usr/share/qgis/python/plugins/fTools/tools

OTHER INFO
running:
QGIS version 2.12.0-Lyon
QGIS code revision exported
Compiled against Qt 4.8.6
Running against Qt 4.8.6
Compiled against GDAL/OGR 1.11.2
Running against GDAL/OGR 1.11.2
Compiled against GEOS 3.4.2-CAPI-1.8.2
Running against GEOS 3.4.2-CAPI-1.8.2 r3921
PostgreSQL Client Version 9.3.4
SpatiaLite Version 4.1.1
QWT Version 5.2.3
PROJ.4 Version 480
QScintilla2 Version 2.8.1

hope it helps,

best

Alessandro

Associated revisions

Revision c866dcce
Added by Salvatore Larosa about 9 years ago

[pyqgis-console] fixes #13693: fix default value in settings for the last used directory when opening a script file

History

#1 Updated by Salvatore Larosa about 9 years ago

  • Status changed from Open to Closed

#2 Updated by Salvatore Larosa about 9 years ago

I don't know why this was not happening before, anyway c866dcc fixes the problem.

as workaround you can run the following in the console:

from PyQt4.QtCore import QSettings, QDir
settings = QSettings()
settings.setValue("pythonConsole/lastDirPath", QDir.homePath())

#3 Updated by Alessandro Frigeri about 9 years ago

Salvatore, the workaround above fixed permanently the problem. thanks! alessandro

#4 Updated by Remi Lemoy about 9 years ago

Hello,
I have the same problem (on Mac OS 10.11.1 with Qgis 2.12.0 from kyngchaos), but the workaround does not work for me, it just changes the error to a quite similar one:

2015-11-03T11:13:37 1 Traceback (most recent call last):
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/console/console.py", line 639, in openScriptFile
self, openFileTr, lastDirPath, "Script file (*.py)")
TypeError: QFileDialog.getOpenFileNames(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 3 has unexpected type 'QPyNullVariant'

Is there another workaround?
Best,

Rémi

#5 Updated by Salvatore Larosa about 9 years ago

Hi Remi,
I edited the above comment which should to work for you as well #13693-2

#6 Updated by Remi Lemoy about 9 years ago

Thank you Salvatore!! It works indeed.
Best,
Rémi

#7 Updated by Jürgen Fischer about 7 years ago

  • Description updated (diff)

Also available in: Atom PDF