diff options
author | aneejit1 <aneejit1@gmail.com> | 2022-07-28 15:46:19 +0000 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2022-07-31 16:41:03 +0200 |
commit | 4978511ebb7e8d31dab64485d1ac87b6e004be81 (patch) | |
tree | a2da3161f070116baa15de7276c5c0c9ac855e8f /examples/SQL/dbconnect.py | |
parent | 5916692cf4c4df4f808e346c9bda1604960a0ff3 (diff) | |
download | pytqt-4978511ebb7e8d31dab64485d1ac87b6e004be81.tar.gz pytqt-4978511ebb7e8d31dab64485d1ac87b6e004be81.zip |
Remove Qt V2 support and example files
Build files for pyuic2 have been removed along with the examples for
version 2 of Qt and the build/configure scripts have been amended
accordingly. The "examples3" directory has been renamed to just
"examples".
Signed-off-by: aneejit1 <aneejit1@gmail.com>
(cherry picked from commit e602246539fd7435aaeb440fcb7f852c92c8426b)
Diffstat (limited to 'examples/SQL/dbconnect.py')
-rwxr-xr-x | examples/SQL/dbconnect.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/examples/SQL/dbconnect.py b/examples/SQL/dbconnect.py new file mode 100755 index 0000000..d1c1baf --- /dev/null +++ b/examples/SQL/dbconnect.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +import sys +from python_tqt.qt import * +from python_tqt.qtsql import * + +from frmconnect import frmConnect +from dbpar import * + +TRUE = 1 +FALSE = 0 + +def createConnection(): + driver = DB_DRIVER + # all qt examples use TQSqlDatabase::addDatabase, but + # this never returns NULL in my experience + drivers = list(map(str, TQSqlDatabase.drivers())) + if driver in drivers: + dlg = dbConnect(driver) + #TODO: make connection parameters accessible + return dlg.exec_loop() + else: + TQMessageBox.warning(None, "Database Error", + "<%s> database driver not found!\n\n" + "Please make sure, that this database adaptor\n" + "is available in your TQt installation.\n" % + (driver), TQMessageBox.Abort | TQMessageBox.Escape) + return FALSE + +class dbConnect(frmConnect): + def __init__(self, driver, parent = None): + frmConnect.__init__(self, parent) + self.hostnames = DB_HOSTNAMES + self.hostname = DB_HOSTNAMES[0] + self.databases = DB_DATABASES + self.database = DB_DATABASES[0] + self.username = DB_USERNAME + self.password = DB_PASSWORD + self.dbdriver = driver + + self.txtName.setText(self.username) + self.txtPasswd.setText(self.password) + list(map(self.cmbServer.insertItem, self.hostnames)) + list(map(self.cmbDatabase.insertItem, self.databases)) + self.connect(self.buttonHelp, SIGNAL("clicked()"), + self.buttonHelp_clicked) + + def accept(self): + self.hostname = self.cmbServer.currentText() + self.database = self.cmbDatabase.currentText() + self.username = self.txtName.text() + self.password = self.txtPasswd.text() + db = TQSqlDatabase.addDatabase(self.dbdriver) + if db: + db.setHostName(self.hostname) + db.setDatabaseName(self.database) + db.setUserName(self.username) + db.setPassword(self.password) + if db.open(): + frmConnect.accept(self) + else: + TQMessageBox.warning(self, "Database Error", + "Cannot open %s database on %s!\n\n%s\n%s\n" % + (self.database, self.hostname, + db.lastError().driverText(), + db.lastError().databaseText()), " Ooops ") + + + def buttonHelp_clicked(self): + TQMessageBox.information(self, "About Connecting", + "Here you specify userid, password, host and database\n" + "for the PyTQt sql examples. If you encounter any problems,\n" + "please read the README file in this folder before posting.\n\n" + "Thanks,\nHans-Peter Jansen <hpj@urpla.net>\n") + + +if __name__ == "__main__": + app = TQApplication(sys.argv) + if createConnection(): + print("ok") + else: + print("cancel") |