[Qgis-user] Open File Dialog Plugin Error

Suryo Miles suryomiles666 at gmail.com
Thu Nov 28 07:48:49 PST 2013


I tried to make plugin open file dialog in QGIS Dofour 2.0.1

I write my code like this (attachment) and try to run it in QGIS plugin,
but nothing happened ( the GUI show up but when i try to click the button,
nothing happened, even a error message is not pop up) since its not show a
error message i dont know what to do

Can someone help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20131128/93dc8075/attachment.html>
-------------- next part --------------
# 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_rc
# Import the code for the dialog
from latihdialog import latihDialog
import os.path


class latih:

    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value("locale/userLocale")[0:2]
        localePath = os.path.join(self.plugin_dir, 'i18n', 'latih_{}.qm'.format(locale))

        if os.path.exists(localePath):
            self.translator = QTranslator()
            self.translator.load(localePath)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Create the dialog (after translation) and keep reference
        self.dlg = latihDialog()

    def initGui(self):
        # Create action that will start plugin configuration
        self.action = QAction(
            QIcon(":/plugins/latih/icon.png"),
            u"ini latihan", self.iface.mainWindow())
        # connect the action to the run method
        self.action.triggered.connect(self.run)

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.action)
        self.iface.addPluginToMenu(u"&latih", self.action)

    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginMenu(u"&latih", self.action)
        self.iface.removeToolBarIcon(self.action)

    # run method that performs all the real work
    def run(self):

        # show the dialog
        self.dlg.show()
		
		#connect
       
        QObject.connect(self.dlg.ui.btnCari,SIGNAL("accepted()"),self.cari)

    def cari(self):
	    #membuka dialog
        #connect
       
        QObject.connect(self.dlg.ui.btnCari,SIGNAL("accepted()"),self.cari)

    def cari(self):
	    #open dialog
        filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
        fname = open(filename)
        data = fname.read()
        self.textEdit.setText(data)
        fname.close() 
		
		#Show in Line Edit
        if namafile:
            self.lineEdit.delete(0, END)
            self.lineEdit.insert(END, namafile)
             
            # call isidata
            self.isiDataFile(namafile)
	
	def isiDataFile(self, nmfile):
	    #open file with read mode
		teksFile = open(nmfile, 'r').read()
		
		#show text in TextView
		self.txtFile.delete('1.0', END)
		self.txtFile.insert('1.0', teksFile)
	
        # Run the dialog event loop
        result = self.dlg.exec_()
        # See if OK was pressed
        if result == 1:
            # do something useful (delete the line containing pass and
            # substitute with your code)
            pass


More information about the Qgis-user mailing list