forked from wonder-sk/postgis_manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgCreateIndex.py
54 lines (36 loc) · 1.33 KB
/
DlgCreateIndex.py
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
from ui.DlgCreateIndex_ui import Ui_DlgCreateIndex
from DlgDbError import DlgDbError
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import postgis_utils
class DlgCreateIndex(QDialog, Ui_DlgCreateIndex):
def __init__(self, parent=None, db=None, table=None, schema=None):
QDialog.__init__(self, parent)
self.db = db
self.table = table
self.schema = schema
self.setupUi(self)
b = QPushButton("&Create")
self.buttonBox.addButton(b, QDialogButtonBox.ActionRole)
self.connect(b, SIGNAL("clicked()"), self.createIndex)
self.connect(self.cboColumn, SIGNAL("currentIndexChanged(int)"), self.columnChanged)
self.populateColumns()
def populateColumns(self):
self.cboColumn.clear()
for field in self.db.get_table_fields(self.table, self.schema):
self.cboColumn.addItem(field.name)
def columnChanged(self):
self.editName.setText("idx_%s_%s" % (self.table, self.cboColumn.currentText()))
def createIndex(self):
column = unicode(self.cboColumn.currentText())
name = unicode(self.editName.text())
if not name:
QMessageBox.critical(self, "error", "Please enter some name for the index")
return
# now create the index
try:
self.db.create_index(self.table, name, column, self.schema)
except postgis_utils.DbError, e:
DlgDbError.showError(e, self)
return
self.accept()