[Qgis-user] Write and Save As with python in QGIS plugin
Salvatore Larosa
lrssvtml at gmail.com
Tue Dec 24 10:50:16 PST 2013
Hi,
On Tue, Dec 24, 2013 at 7:10 PM, Suryo Miles <suryomiles666 at gmail.com>wrote:
> I try to make plugin in QGIS and i want to make save as button but i got
> error message like this
>
> ""Traceback (most recent call last):
> File "C:\Users\Mr.Pakde/.qgis2/python/plugins\latih\latihdialog.py",
> line 69, in
>
> saveAs
> if not filename.isEmpty():
> AttributeError: 'unicode' object has no attribute 'isEmpty' ""
>
you just try to change:
if not filename.isEmpty():
to:
if filename:
that should help you!
An useful resource to read before to write python plugin is:
http://hub.qgis.org/wiki/quantum-gis/Python_plugin_API_changes_from_18_to_20
Merry Christmas,
-SL
>
> I write my code like this :
>
> cariButton = self.ui.btnCari
> QtCore.QObject.connect(cariButton,QtCore.SIGNAL('clicked()'),self.cari)
> saveButton = self.ui.btnSave
> QtCore.QObject.connect(saveButton,
> QtCore.SIGNAL('clicked()'),self.saveAs)
>
> def cari(self, event=None):
> #open dialog
> filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File',
> '*.xml')
>
> self.ui.lineFile.setText(filename)
> #panggil isi data
>
> self.isiDataFile(filename)
>
> def isiDataFile(self, nmfile):
> #buka dengan open mode baca
> teksFile = open(nmfile, 'r').read()
>
> self.ui.textFile.setText(teksFile)
>
> def _save(self, filename):
> f = open( filename, "w" )
> f.write( "%s" % self.lineFile.text() )
> f.close()
> def savefile(self):
> if self.filename:
> self._save( "%s" % self.filename )
> else:
> self.saveAs()
>
> def saveAs(self):
> filename = QtGui.QFileDialog(self).getSaveFileName()
> if not filename.isEmpty():
> _filename = "%s" % filename
> self._save( _filename )
> self.setFilename( _filename )
>
>
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
--
Salvatore Larosa
linkedIn: http://linkedin.com/in/larosasalvatore
twitter: @lrssvt
skype: s.larosa
IRC: lrssvt on freenode
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20131224/4463f27e/attachment.html>
More information about the Qgis-user
mailing list