SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sqlcustom1.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python
  2. #****************************************************************************
  3. #** $Id: sqlcustom1.py,v 1.3 2002/07/06 13:35:41 phil Exp $
  4. #**
  5. #** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved.
  6. #**
  7. #** This file is part of an example program for PyTQt. This example
  8. #** program may be used, distributed and modified without limitation.
  9. #**
  10. #*****************************************************************************/
  11. import sys
  12. from python_tqt.qt import *
  13. from python_tqt.qtsql import *
  14. from dbconnect import createConnection
  15. TRUE = 1
  16. FALSE = 0
  17. class CustomEdit(TQLineEdit):
  18. def __init__(self, parent = None, name = None):
  19. TQLineEdit.__init__(self, parent, name)
  20. TQObject.connect(self, SIGNAL("textChanged(const TQString &)"),
  21. self.changed)
  22. def changed(self, line):
  23. self.setUpperLine(line)
  24. def setUpperLine(self, line):
  25. self.upperLineText = line.upper()
  26. self.setText(self.upperLineText)
  27. class FormDialog(TQDialog):
  28. def __init__(self):
  29. TQDialog.__init__(self)
  30. forenameLabel = TQLabel("Forename:", self)
  31. forenameEdit = CustomEdit(self)
  32. surnameLabel = TQLabel("Surname:", self)
  33. surnameEdit = CustomEdit(self)
  34. salaryLabel = TQLabel("Salary:", self)
  35. salaryEdit = TQLineEdit(self)
  36. salaryEdit.setAlignment(TQt.AlignRight)
  37. saveButton = TQPushButton("&Save", self)
  38. self.connect(saveButton, SIGNAL("clicked()"), self.save)
  39. grid = TQGridLayout(self)
  40. grid.addWidget(forenameLabel, 0, 0)
  41. grid.addWidget(forenameEdit, 0, 1)
  42. grid.addWidget(surnameLabel, 1, 0)
  43. grid.addWidget(surnameEdit, 1, 1)
  44. grid.addWidget(salaryLabel, 2, 0)
  45. grid.addWidget(salaryEdit, 2, 1)
  46. grid.addWidget(saveButton, 3, 0)
  47. grid.activate()
  48. self.staffCursor = TQSqlCursor("staff")
  49. self.staffCursor.setTrimmed("forename", TRUE)
  50. self.staffCursor.setTrimmed("surname", TRUE)
  51. self.idIndex = self.staffCursor.index("id")
  52. self.staffCursor.select(self.idIndex)
  53. self.staffCursor.first()
  54. self.propMap = TQSqlPropertyMap()
  55. self.propMap.insert(forenameEdit.className(), "upperLine")
  56. self.sqlForm = TQSqlForm()
  57. self.sqlForm.setRecord(self.staffCursor.primeUpdate())
  58. self.sqlForm.installPropertyMap(self.propMap)
  59. self.sqlForm.insert(forenameEdit, "forename")
  60. self.sqlForm.insert(surnameEdit, "surname")
  61. self.sqlForm.insert(salaryEdit, "salary")
  62. self.sqlForm.readFields()
  63. def save(self):
  64. self.sqlForm.writeFields()
  65. self.staffCursor.update()
  66. self.staffCursor.select(self.idIndex)
  67. self.staffCursor.first()
  68. if __name__=='__main__':
  69. app = TQApplication( sys.argv )
  70. if createConnection():
  71. formDialog = FormDialog()
  72. formDialog.show()
  73. app.setMainWidget(formDialog)
  74. app.exec_loop()