[Qgis-user] newbie QGIS, pyQT and python question

karsten vennemann karsten at terragis.net
Fri Apr 1 18:40:38 PDT 2011


Hi,
 
I am working on my first QGIS plug-in wohoo . 
	But honestly this is my first ever stab at OO code in python using pyQT. I have  <http://pastebin.com/dWT5eezP> http://pastebin.com/dWT5eezP (for code highlighting - or see end of message below trace back)
The line 
self.inputConfig()
throws his error : argument 1 has unexpected type 'instance' .See traceback below. There I am trying to open a file selection dialogue window ....
 
Ay idea what it excepts instead of self ? Any python gurus ?
 
Thanks
Karsten
 
________________________________________________________________________________________________
 
Traceback (most recent call last):
  File "D:/OSGeo4W/apps/qgis/./python/plugins\StreamEditCustomForm\streameditcustomform.py", line 72, in run
    self.inputConfig()
  File "D:/OSGeo4W/apps/qgis/./python/plugins\StreamEditCustomForm\streameditcustomform.py", line 54, in inputConfig
    filename = QFileDialog.getOpenFileName(self, 'Open File', '.')
TypeError: QFileDialog.getOpenFileName(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 1 has unexpected type 'instance'

Python version:
2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
________________________________________________________________________________________________
 
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
# Initialize Qt resources from file resources.py
import resources
# Import the code for the dialog
from streameditcustomformdialog import StreamEditCustomFormDialog
 
class StreamEditCustomForm:
 
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
 
    def initGui(self):
        # Create action that will start plugin configuration
        self.action = QAction(QIcon(":/plugins/streameditcustomform/icon.png"), \
            "Stream Edit Custom Form", self.iface.mainWindow())
        # connect the action to the run method
        QObject.connect(self.action, SIGNAL("triggered()"), self.run)
 
        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.action)
        self.iface.addPluginToMenu("&Stream Edit Custom Form", self.action)
 
    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginMenu("&Stream Edit Custom Form",self.action)
        self.iface.removeToolBarIcon(self.action)
        
        
    def inputConfig(self):
            filename = QFileDialog.getOpenFileName(self, 'Open File', '.')
            fname = open(filename)
            data = fname.read()
            self.textEdit.setText(data)
            fname.close()         
 
    # run method that performs all the real work
    def run(self):
 
        # create and show the dialog
        dlg = StreamEditCustomFormDialog()
        # show the dialog
        dlg.show()
        result = dlg.exec_()    
        # See if OK was pressed
        if result == 1:
            # do something useful (delete the line containing pass and
            # substitute with your code
            self.inputConfig()
            pass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20110401/3ceea76a/attachment.html>


More information about the Qgis-user mailing list