[Qgis-developer] Plug in problem- can't receive the signal
Chang, Elizabeth
Elizabeth.Chang at noblis.org
Tue Nov 4 12:24:50 EST 2008
Hi,
I'm trying to build a plug in that connects to a postgis database and
run queries. On the UI, there is an input box where you type your query
and an output box where the results are displayed. When you press the
"query" button, the query is executed.
At the point when you press "query", I verified a signal is emitted by
putting in print statements among the "emit" signal lines. But the print
messages I put in the functions that is supposed to be called when the
signal is emitted never run. More specifically, getManualQuery or
executeManualQuery below never runs. I can't seem to figure out what I'm
doing wrong. I compared to the imagemap plug-in and everything seems to
follow the same format.
Thanks so much.
***********************************************************
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from mainwindow import Ui_MainWindow
from PostGISdialog import PostGISdialog
import psycopg
import resources
# Our main class for the plugin
class NoblisPostGISManager:
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/NoblisPostGISManager/icon.png"), \
"Start", self.iface.getMainWindow())
QObject.connect(self.action, SIGNAL("activated()"), self.run)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginMenu("&Noblis PostGIS Manager", self.action)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("&Noblis PostGIS Manager",self.action)
self.iface.removeToolBarIcon(self.action)
def run(self):
con = psycopg.connect("dbname=gis user=echang
host=beren.tsf.noblis.org")
curs = con.cursor()
self.PostGISdialog= PostGISdialog()
QObject.connect(self.PostGISdialog,
SIGNAL("getManualInputQuery(QString)"), self.getManualQuery)
QObject.connect(self.PostGISdialog,
SIGNAL("onManualQueryButtonClick()"), self.executeManualQuery)
QObject.connect(self.PostGISdialog,
SIGNAL("onManualOutputBoxPopulate(QString)"), self.writeManualOutput)
self.dialogue=PostGISdialog()
self.dialogue.show()
def getManualQuery(self, query):
QMessageBox.information(None, "Diagnostic Message", "here",0,0,0)
self.manualquerystring=query
QMessageBox.information(None, "Diagnostic Message", "in
getManualQuery",0,0,0)
def executeManualQuery(self):
QMessageBox.information(None, "Diagnostic Message",
self.manualquerystring,0,0,0)
curs.execute(self.manualquerystring)
con.commit()
def writeManualOutput(self,QString):
rows=curs.fetchall()
self.PostGISdialog.printManualOutput(rows)
************************************************************************
**********
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from mainwindow import Ui_MainWindow
# create the dialog for PostGIS
class PostGISdialog(QDialog):
def __init__(self):
QDialog.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def on_ExitpushButton_clicked(self):
self.done(0)
@pyqtSignature("on_QuerypushButton_clicked()")
def on_QuerypushButton_clicked(self):
#self.emit(SIGNAL("getManualInputQuery(QString)"),
self.InputTextEdit.toPlainText() )
self.emit(SIGNAL("getManualInputQuery(QString)"),"DELETE FROM
Cities_all_test1 where name=\'Butte\'")
self.emit(SIGNAL("onManualQueryButtonClick()"))
def printManualOutput(self,rows):
#self.OutputtextBrowser.insertPlainText(str(rows))
self.OutputtextBrowser.append(str(rows))
- Elizabeth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20081104/2951bb1a/attachment.html
More information about the Qgis-developer
mailing list