[英]Error in Python plugin for qgis
I'm following a tutorial for developing a plugin for qgis
, but I'm stuck in a error, when trying to insert a text in a textbox window. 我正在遵循为qgis
开发插件的qgis
,但是在尝试在文本框窗口中插入文本时遇到了错误。 The code is as demonstrated here 该代码是为证明这里
Class vector_selectbypointdialog.py: 类vector_selectbypointdialog.py:
from PyQt4 import QtCore, QtGui
from ui_vector_selectbypoint import Ui_vector_selectbypoint
# create the dialog for zoom to point
class vector_selectbypointDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_vector_selectbypoint()
self.ui.setupUi(self)
def setTextBrowser(self, output):
self.ui.txtFeedback.setText(output)
def clearTextBrowser(self):
self.ui.txtFeedback.clear()
Class vector_selectbypoint.py: 类vector_selectbypoint.py:
under init create the object like this: 在init下创建这样的对象:
# create our GUI dialog
self.dlg = vector_selectbypointDialog()
And the method that handles to insert the text: 以及用于插入文本的方法:
handleMouseDown(self, point, button):
self.dlg.clearTextBrowser()
self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )
The error is: 错误是:
handleMouseDown self.dlg.clearTextBrowser() AttributeError: 'vector_selectbypointdialog' object has no attribute 'clearTextBrowser' handleMouseDown self.dlg.clearTextBrowser()AttributeError:'vector_selectbypointdialog'对象没有属性'clearTextBrowser'
您确定要重命名PyQt文本浏览器窗口小部件txtFeedback吗?
I got the same problem and solved it : you probably have a mixing of tab and space characters in class vector_selectbypointDialog (clearTextBrowser becomes a subfunction in init()). 我遇到了同样的问题并解决了这个问题:在类vector_selectbypointDialog中,您可能混合了制表符和空格字符(clearTextBrowser成为init()中的子函数)。
Indent correctly your code in vector_selectbypointdialog.py and it will work ;-) 在vector_selectbypointdialog.py中正确缩进您的代码,它将起作用;-)
Yes, something is wrong in this example. 是的,这个例子有问题。
Instead of: 代替:
self.dlg.clearTextBrowser()
self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )
just use: 只需使用:
self.dlg.ui.txtFeedback.clear()
self.dlg.ui.txtFeedback.setText( str(point.x()) + " , " +str(point.y()) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.