Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on python plugins for QGIS. I have my QueryBuilder.py and postgis.py files. I connected it to database using Connection class and under def __init__(self, uri=None) in postgis.py file. I want to connect to database through QueryBuilder.py file.I imported postgis.py into QueryBuilder.py But how to call def __init__(self, uri=None) of postgis.py from QueryBuilder.py? I need to create instance of 'Connection' class in order to call def __init__(self, uri=None) method of postgis.py in QueryBuilder.py How do I go about it?

postgis.py file:

class Connection(DbConn.Connection):

@classmethod
def getTypeName(self):
    return 'postgis'

@classmethod
def getTypeNameString(self):
    return 'PostgreSQL'

@classmethod
def getProviderName(self):
    return 'postgres'

@classmethod
def getSettingsKey(self):
    return 'PostgreSQL'

@classmethod
def icon(self):
    return QIcon(":/icons/postgis_elephant.png")

@classmethod


def __init__(self, uri=None):

    DbConn.Connection.__init__(self, uri)

    #self.host = uri.host()
    #self.port = uri.port()
    #self.dbname = uri.database()
    #self.user = uri.username()
    #self.passwd = uri.password()



    self.host ='localhost' 
    self.port =5432 
    self.dbname ='ssss'
    self.user = 'j'
    self.passwd = 'jkj'


    if self.dbname == '' or self.dbname is None:
        self.dbname = self.user

    try:
        self.con = psycopg2.connect(self.con_info())
    except psycopg2.OperationalError, e:
        raise DbError(e)

    self.has_spatial = self.check_spatial()

    self.check_geometry_columns_table()

    # a counter to ensure that the cursor will be unique
    self.last_cursor_id = 0
               '''
               '''
if __name__ == "__main__":
window = Connection()

and QueryBuilder.py is:

import sys
import pdb

from PyQt4 import QtGui, QtCore
import psycopg2
import pprint


#from qgis.core import *
#from qgis.gui import *


import postgis

from DatabaseModel import TableItem, SchemaItem, DatabaseModel
import DbConnection

from ui.DlgQueryBuilder_ui import Ui_Dialog
from DlgDbError import DlgDbError

from QueryParser import QueryParser
from QueryManager import *

class DlgQueryBuilder(QDialog, Ui_Dialog):
    so on.....
share|improve this question
    
Can you post the relevant sections of your code in your question please. It's hard to understand how your code is written. –  Nathan W Feb 8 '12 at 10:02
    
ok sure........ –  Poonam Narvekar Feb 8 '12 at 10:24
add comment

1 Answer 1

up vote 1 down vote accepted

This should work:

in QueryBuilder.py

import postgis
conn = postgis.Connection()

or

from postgis import Connection
conn = Connection()
share|improve this answer
    
thanx a lot:).. –  Poonam Narvekar Feb 8 '12 at 12:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.