1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| # -*- coding: utf-8 -*-
import psycopg2
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import SIGNAL, Qt
con = None
class MainWindow(QtGui.QTableWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
layout = QtGui.QVBoxLayout()
self.table_widget = QtGui.QTableWidget() # Créer la table
self.connect(self.table_widget,SIGNAL('cellClicked(int, int)'), self.returnIndex) # Return la ligne
self.sridData() # Lance le remplissage
layout.addWidget(self.table_widget)
self.setLayout(layout)
def sridData(self): ##REMPLISSAGE
try:
conn = psycopg2.connect("dbname='postgis_21_sample' user='postgres' host='localhost' password='postgresql'")
except:
print "I am unable to connect to the database"
cur = conn.cursor()
self.data= cur.execute("SELECT srtext, srid FROM spatial_ref_sys;")
data = cur.fetchall()
lignes = len(data)
columns = len(data[0])
i = 0
j = 0
self.table_widget.setRowCount(lignes)
self.table_widget.setColumnCount(columns)
self.table_widget.setHorizontalHeaderLabels(['Label sird', 'srid'])
#self.table_widget.setColumnWidth(1, 80)
self.table_widget.horizontalHeader().setResizeMode(0, QHeaderView.Stretch)
for i in range(lignes):
for j in range(columns):
item = QtGui.QTableWidgetItem(data[i][j])
self.tabledata = self.table_widget.setItem(i, j, item)
#self.table_widget.sortByColumn(0, QtCore.Qt.AscendingOrder) # permet de choisir l'ordre d'affichage
def returnIndex(self,row,column):
row =row +1
try:
conn = psycopg2.connect("dbname='postgis_21_sample' user='postgres' host='localhost' password='postgresql'")
except:
print "I am unable to connect to the database"
cur = conn.cursor()
self.data= cur.execute("SELECT srid FROM spatial_ref_sys;")
srid = cur.fetchall()
srid = srid[row]
print row, srid
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
wnd = MainWindow()
wnd.resize(900, 500)
wnd.show()
sys.exit(app.exec_()) |
Partager