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.

lineedits.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/env python
  2. #****************************************************************************
  3. #** $Id: lineedits.py,v 1.1 2002/06/19 07:56:07 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. TRUE = 1
  14. FALSE = 0
  15. class LineEdits(TQGroupBox):
  16. def __init__(self, parent = None, name = None):
  17. TQGroupBox.__init__(self, 0, TQt.Horizontal, "Line Edits", parent, name)
  18. self.setMargin(10)
  19. box = TQVBoxLayout(self.layout())
  20. row1 = TQHBoxLayout(box)
  21. row1.setMargin(5)
  22. label = TQLabel("Echo Mode: ", self)
  23. row1.addWidget(label)
  24. combo1 = TQComboBox(FALSE, self)
  25. row1.addWidget(combo1)
  26. combo1.insertItem("Normal", -1)
  27. combo1.insertItem("Password", -1)
  28. combo1.insertItem("No Echo", -1)
  29. self.connect(combo1, SIGNAL("activated(int)"), self.slotEchoChanged)
  30. self.lined1 = TQLineEdit(self)
  31. box.addWidget(self.lined1)
  32. row2 = TQHBoxLayout(box)
  33. row2.setMargin(5)
  34. label = TQLabel("Validator: ", self)
  35. row2.addWidget(label)
  36. combo2 = TQComboBox(FALSE, self)
  37. row2.addWidget(combo2)
  38. combo2.insertItem("No Validator", -1)
  39. combo2.insertItem("Integer Validator", -1)
  40. combo2.insertItem("Double Validator", -1)
  41. self.connect(combo2, SIGNAL("activated(int)"), self.slotValidatorChanged)
  42. self.lined2 = TQLineEdit(self)
  43. box.addWidget(self.lined2)
  44. row3 = TQHBoxLayout(box)
  45. row3.setMargin(5)
  46. label = TQLabel("Alignment: ", self)
  47. row3.addWidget(label)
  48. combo3 = TQComboBox(FALSE, self)
  49. row3.addWidget(combo3)
  50. combo3.insertItem("Left", -1)
  51. combo3.insertItem("Centered", -1)
  52. combo3.insertItem("Right", -1)
  53. self.connect(combo3, SIGNAL("activated(int)"), self.slotAlignmentChanged)
  54. self.lined3 = TQLineEdit(self)
  55. box.addWidget(self.lined3)
  56. row4 = TQHBox(self)
  57. box.addWidget(row4)
  58. row4.setMargin(5)
  59. TQLabel("Read-Only: ", row4)
  60. combo4 = TQComboBox(FALSE, row4)
  61. combo4.insertItem("False", -1)
  62. combo4.insertItem("True", -1)
  63. self.connect(combo4, SIGNAL("activated(int)"), self.slotReadOnlyChanged)
  64. self.lined4 = TQLineEdit(self)
  65. box.addWidget(self.lined4)
  66. self.lined1.setFocus()
  67. def slotEchoChanged(self, i):
  68. if i == 0:
  69. self.lined1.setEchoMode(TQLineEdit.Normal)
  70. elif i == 1:
  71. self.lined1.setEchoMode(TQLineEdit.Password)
  72. elif i == 2:
  73. self.lined1.setEchoMode(TQLineEdit.NoEcho)
  74. self.lined1.setFocus()
  75. def slotValidatorChanged(self, i):
  76. if i == 0:
  77. self.lined2.setValidator(None)
  78. elif i == 1:
  79. self.lined2.setValidator(TQIntValidator(self.lined2))
  80. elif i == 2:
  81. self.lined2.setValidator(TQDoubleValidator(-999.0, 999.0, 2, self.lined2))
  82. self.lined2.setText("")
  83. self.lined2.setFocus()
  84. def slotAlignmentChanged(self, i):
  85. if i == 0:
  86. self.lined3.setAlignment(TQLineEdit.AlignLeft)
  87. elif i == 1:
  88. self.lined3.setAlignment(TQLineEdit.AlignCenter)
  89. elif i == 2:
  90. self.lined3.setAlignment(TQLineEdit.AlignRight)
  91. self.lined3.setFocus()
  92. def slotReadOnlyChanged(self, i):
  93. if i == 0:
  94. self.lined4.setReadOnly(FALSE)
  95. elif i == 1:
  96. self.lined4.setReadOnly(TRUE)
  97. self.lined4.setFocus()
  98. if __name__=='__main__':
  99. app = TQApplication( sys.argv )
  100. lineedits = LineEdits()
  101. lineedits.setCaption("Lineedits - PyTQt Example")
  102. lineedits.show()
  103. app.setMainWidget(lineedits)
  104. app.exec_loop()