#--------------------------------------------------------------------- # # mac_noise - A QGIS plugin set to work with flight noise data # for the Metropolitan Airports Commission of Minneapolis, MN. # # Copyright (C) 2008 Aaron Racicot, Z-Pulley Inc. # Copyright (C) 2008 Metropolitan Airports Commission of Minneapolis # # EMAIL: aaronr (at) z-pulley.com # WEB : www.z-pulley.com # www.reprojected.com # #--------------------------------------------------------------------- # # licensed under the terms of GNU GPL 2 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # #--------------------------------------------------------------------- from PyQt4.QtCore import * from PyQt4.QtGui import * from qgis.core import * from qgis.gui import * # TODO wrap this with check for errors on import and notify the user gracefully if # they need to add psycopg2 import psycopg2 import psycopg2.extras import pdb from mac_dbconnection_ui import Ui_MacNewConnectionBase class MacNewConnectionBase(QDialog, Ui_MacNewConnectionBase): def __init__(self, iface, fl, plugin): QDialog.__init__(self, iface.mainWindow(), fl) self.setupUi(self) self.iface = iface self.plugin = plugin self.connect(self.cancelButton, SIGNAL("clicked()"), self.cancelBtn) self.connect(self.okButton, SIGNAL("clicked()"), self.ok) self.connect(self.testButton, SIGNAL("clicked()"), self.test) self.initUI() def initUI(self): self.nameLine.setText(self.plugin.name) self.hostLine.setText(self.plugin.host) self.databaseLine.setText(self.plugin.dbname) self.portLine.setText(self.plugin.port) self.usernameLine.setText(self.plugin.user) self.passwordLine.setText(self.plugin.passwd) self.tableLine.setText(self.plugin.table) self.schemaLine.setText(self.plugin.schema) self.geomLine.setText(self.plugin.geomcol) self.nameSave = self.plugin.name self.hostSave = self.plugin.host self.databaseSave = self.plugin.dbname self.portSave = self.plugin.port self.usernameSave = self.plugin.user self.passwordSave = self.plugin.passwd self.tableSave = self.plugin.table self.schemaSave = self.plugin.schema self.geomSave = self.plugin.geomcol def showEvent(self,event): print "Rec showEvent" QDialog.showEvent(self,event) self.initUI() def ok(self): print "ok pressed..." self.plugin.name = str(self.nameLine.text()) self.plugin.host = str(self.hostLine.text()) self.plugin.dbname = str(self.databaseLine.text()) self.plugin.port = str(self.portLine.text()) self.plugin.user = str(self.usernameLine.text()) self.plugin.passwd = str(self.passwordLine.text()) self.plugin.table = str(self.tableLine.text()) self.plugin.schema = str(self.schemaLine.text()) self.plugin.geomcol = str(self.geomLine.text()) success = self.plugin.querybuilder_gui.updateConnection() if success == False: # Revert back to old value as there was a problem... self.plugin.name = self.nameSave self.plugin.host = self.hostSave self.plugin.dbname = self.databaseSave self.plugin.port = self.portSave self.plugin.user = self.usernameSave self.plugin.passwd = self.passwordSave self.plugin.table = self.tableSave self.plugin.schema = self.schemaSave self.plugin.geomcol = self.geomSave else: self.close() def cancelBtn(self): # Reset it all back to the default... self.nameLine.setText(self.plugin.name) self.hostLine.setText(self.plugin.host) self.databaseLine.setText(self.plugin.dbname) self.portLine.setText(self.plugin.port) self.usernameLine.setText(self.plugin.user) self.passwordLine.setText(self.plugin.passwd) self.tableLine.setText(self.plugin.table) self.schemaLine.setText(self.plugin.schema) self.geomLine.setText(self.plugin.geomcol) self.close() def test(self): print "test pressed..." self.nameSave = self.plugin.name self.hostSave = self.plugin.host self.databaseSave = self.plugin.dbname self.portSave = self.plugin.port self.usernameSave = self.plugin.user self.passwordSave = self.plugin.passwd self.tableSave = self.plugin.table self.schemaSave = self.plugin.schema self.geomSave = self.plugin.geomcol self.plugin.name = str(self.nameLine.text()) self.plugin.host = str(self.hostLine.text()) self.plugin.dbname = str(self.databaseLine.text()) self.plugin.port = str(self.portLine.text()) self.plugin.user = str(self.usernameLine.text()) self.plugin.passwd = str(self.passwordLine.text()) self.plugin.table = str(self.tableLine.text()) self.plugin.schema = str(self.schemaLine.text()) self.plugin.geomcol = str(self.geomLine.text()) success = self.plugin.querybuilder_gui.testConnection() print "*******"+str(success) self.plugin.name = self.nameSave self.plugin.host = self.hostSave self.plugin.dbname = self.databaseSave self.plugin.port = self.portSave self.plugin.user = self.usernameSave self.plugin.passwd = self.passwordSave self.plugin.table = self.tableSave self.plugin.schema = self.schemaSave self.plugin.geomcol = self.geomSave if success == True: # pop up a warning about selecting a layer QMessageBox.information(self.iface.mainWindow(), "Success", "Database connection created with success...") else: # pop up a warning about selecting a layer QMessageBox.information(self.iface.mainWindow(), "Warning", "Database connection failed... please verify connection params")