Ошибка в плагине Python для qgis

Я следую руководству по разработке плагина для qgis, но у меня возникает ошибка при попытке вставить текст в окно текстового поля. Код показан здесь

Класс 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()

Класс vector_selectbypoint.py:

в разделе init создайте объект следующим образом:

# create our GUI dialog
self.dlg = vector_selectbypointDialog()

И метод, который обрабатывает вставку текста:

handleMouseDown(self, point, button):
        self.dlg.clearTextBrowser()
        self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )

Ошибка:

handleMouseDown self.dlg.clearTextBrowser() AttributeError: объект 'vector_selectbypointdialog' не имеет атрибута 'clearTextBrowser'


person Alex    schedule 18.09.2013    source источник


Ответы (3)


Вы переименовали виджет текстового браузера PyQt в txtFeedback?

person user25976    schedule 18.04.2014
comment
Да. Проблема в clearTextBrowser, который существует в коде, но не обнаруживается в handleMouseDown. - person Eric H.; 12.05.2014

У меня возникла та же проблема, и я решил ее: у вас, вероятно, есть сочетание символов табуляции и пробела в классе vector_selectbypointDialog (clearTextBrowser становится подфункцией в init()).

Сделайте правильный отступ в вашем коде в vector_selectbypointdialog.py, и он будет работать ;-)

person Eric H.    schedule 12.05.2014

Да, в этом примере что-то не так.

Вместо:

    self.dlg.clearTextBrowser()
    self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )

просто используйте:

    self.dlg.ui.txtFeedback.clear()
    self.dlg.ui.txtFeedback.setText( str(point.x()) + " , " +str(point.y()) )
person Aleksandar    schedule 16.06.2014