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.

listbox.py 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/usr/bin/env python
  2. """**************************************************************************
  3. ** $Id: listbox.py,v 1.1 2003/05/30 17:47:57 phil Exp $
  4. **
  5. ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
  6. **
  7. ** This file is part of an example program for TQt. This example
  8. ** program may be used, distributed and modified without limitation.
  9. **
  10. ***************************************************************************"""
  11. import sys
  12. from python_tqt.qt import *
  13. FALSE = 0
  14. TRUE = 1
  15. class ListBoxDemo( TQWidget ):
  16. def __init__( self, parent=None, name=None ):
  17. TQWidget.__init__( self, parent, name )
  18. b = FALSE
  19. g = TQGridLayout( self, 2, 2, 6 )
  20. g.addWidget( TQLabel( "<b>Configuration:</b>", self ), 0, 0 )
  21. g.addWidget( TQLabel( "<b>Result:</b>", self ), 0, 1 )
  22. self.l = TQListBox( self )
  23. g.addWidget( self.l, 1, 1 )
  24. self.l.setFocusPolicy( TQWidget.StrongFocus )
  25. v = TQVBoxLayout( )
  26. g.addLayout( v, 1, 0 )
  27. bg = TQButtonGroup( self, None )
  28. b = TQRadioButton( "Fixed number of columns,\n"
  29. "as many rows as needed.",
  30. self )
  31. bg.insert( b )
  32. v.addWidget( b )
  33. b.setChecked( TRUE )
  34. self.connect( b, SIGNAL("clicked()"), self.setNumCols )
  35. h = TQHBoxLayout()
  36. v.addLayout( h )
  37. h.addSpacing( 30 )
  38. h.addSpacing( 100 )
  39. h.addWidget( TQLabel( "Columns:", self ) )
  40. self.columns = TQSpinBox( self )
  41. h.addWidget( self.columns )
  42. v.addSpacing( 12 )
  43. b = TQRadioButton( "As many columns as fit on-screen,\n"
  44. "as many rows as needed.",
  45. self )
  46. bg.insert( b )
  47. v.addWidget( b )
  48. self.connect( b, SIGNAL("clicked()"), self.setColsByWidth )
  49. v.addSpacing( 12 )
  50. b = TQRadioButton( "Fixed number of rows,\n"
  51. "as many columns as needed.",
  52. self )
  53. bg.insert( b )
  54. v.addWidget( b )
  55. self.connect( b, SIGNAL("clicked()"), self.setNumRows )
  56. h = TQHBoxLayout()
  57. v.addLayout( h )
  58. h.addSpacing( 30 )
  59. h.addSpacing( 100 )
  60. h.addWidget( TQLabel( "Rows:", self ) )
  61. self.rows = TQSpinBox( self )
  62. self.rows.setEnabled( FALSE )
  63. h.addWidget( self.rows )
  64. v.addSpacing( 12 )
  65. b = TQRadioButton( "As many rows as fit on-screen,\n"
  66. "as many columns as needed.",
  67. self )
  68. bg.insert( b )
  69. v.addWidget( b )
  70. self.connect( b, SIGNAL("clicked()"), self.setRowsByHeight )
  71. v.addSpacing( 12 )
  72. cb = TQCheckBox( "Variable-height rows", self )
  73. cb.setChecked( TRUE )
  74. self.connect( cb, SIGNAL("toggled(bool)"), self.setVariableHeight )
  75. v.addWidget( cb )
  76. v.addSpacing( 6 )
  77. cb = TQCheckBox( "Variable-width columns", self )
  78. self.connect( cb, SIGNAL("toggled(bool)"), self.setVariableWidth )
  79. v.addWidget( cb )
  80. cb = TQCheckBox( "Extended-Selection", self )
  81. self.connect( cb, SIGNAL("toggled(bool)"), self.setMultiSelection )
  82. v.addWidget( cb )
  83. pb = TQPushButton( "Sort ascending", self )
  84. self.connect( pb, SIGNAL("clicked()"), self.sortAscending )
  85. v.addWidget( pb )
  86. pb = TQPushButton( "Sort descending", self )
  87. self.connect( pb, SIGNAL("clicked()"), self.sortDescending )
  88. v.addWidget( pb )
  89. v.addStretch( 100 )
  90. i = 0
  91. while i <= 2560:
  92. i+=1
  93. self.l.insertItem( str(TQString.fromLatin1( "Item " )) + str(TQString.number( i )), i )
  94. self.columns.setRange( 1, 256 )
  95. self.columns.setValue( 1 )
  96. self.rows.setRange( 1, 256 )
  97. self.rows.setValue( 256 )
  98. self.connect( self.columns, SIGNAL("valueChanged(int)"), self.setNumCols )
  99. self.connect( self.rows, SIGNAL("valueChanged(int)"), self.setNumRows )
  100. # slots
  101. def setNumCols( self ):
  102. self.columns.setEnabled( TRUE )
  103. self.rows.setEnabled( FALSE )
  104. self.l.setColumnMode( self.columns.value() )
  105. def setNumRows( self ):
  106. self.columns.setEnabled( FALSE )
  107. self.rows.setEnabled( TRUE )
  108. self.l.setRowMode( self.rows.value() )
  109. def setRowsByHeight( self ):
  110. self.columns.setEnabled( FALSE )
  111. self.rows.setEnabled( FALSE )
  112. self.l.setRowMode( TQListBox.FitToHeight )
  113. def setColsByWidth( self ):
  114. self.columns.setEnabled( FALSE )
  115. self.rows.setEnabled( FALSE )
  116. self.l.setColumnMode( TQListBox.FitToWidth )
  117. def setVariableWidth( self, b ):
  118. self.l.setVariableWidth( b )
  119. def setVariableHeight( self, b ):
  120. self.l.setVariableHeight( b )
  121. def setMultiSelection( self, b ):
  122. self.l.clearSelection()
  123. if b :
  124. self.l.setSelectionMode( TQListBox.Extended )
  125. else:
  126. self.l.setSelectionMode( TQListBox.Single )
  127. def sortAscending( self ):
  128. self.l.sort( TRUE )
  129. def sortDescending( self ):
  130. self.l.sort( FALSE )
  131. def main( args ):
  132. a = TQApplication( args )
  133. t = ListBoxDemo()
  134. t.setCaption( "TQt Example - Listbox" )
  135. a.setMainWidget( t )
  136. t.show()
  137. a.exec_loop()
  138. if __name__=="__main__":
  139. main(sys.argv)