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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
#!/usr/bin/env python
"""**************************************************************************
** $Id: listbox.py,v 1.1 2003/05/30 17:47:57 phil Exp $
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for TQt. This example
** program may be used, distributed and modified without limitation.
**
***************************************************************************"""
import sys
from PyTQt.tqt import *
FALSE = 0
TRUE = 1
class ListBoxDemo( TQWidget ):
def __init__( self, parent=None, name=None ):
TQWidget.__init__( self, parent, name )
b = FALSE
g = TQGridLayout( self, 2, 2, 6 )
g.addWidget( TQLabel( "<b>Configuration:</b>", self ), 0, 0 )
g.addWidget( TQLabel( "<b>Result:</b>", self ), 0, 1 )
self.l = TQListBox( self )
g.addWidget( self.l, 1, 1 )
self.l.setFocusPolicy( TQWidget.StrongFocus )
v = TQVBoxLayout( )
g.addLayout( v, 1, 0 )
bg = TQButtonGroup( self, None )
b = TQRadioButton( "Fixed number of columns,\n"
"as many rows as needed.",
self )
bg.insert( b )
v.addWidget( b )
b.setChecked( TRUE )
self.connect( b, SIGNAL("clicked()"), self.setNumCols )
h = TQHBoxLayout()
v.addLayout( h )
h.addSpacing( 30 )
h.addSpacing( 100 )
h.addWidget( TQLabel( "Columns:", self ) )
self.columns = TQSpinBox( self )
h.addWidget( self.columns )
v.addSpacing( 12 )
b = TQRadioButton( "As many columns as fit on-screen,\n"
"as many rows as needed.",
self )
bg.insert( b )
v.addWidget( b )
self.connect( b, SIGNAL("clicked()"), self.setColsByWidth )
v.addSpacing( 12 )
b = TQRadioButton( "Fixed number of rows,\n"
"as many columns as needed.",
self )
bg.insert( b )
v.addWidget( b )
self.connect( b, SIGNAL("clicked()"), self.setNumRows )
h = TQHBoxLayout()
v.addLayout( h )
h.addSpacing( 30 )
h.addSpacing( 100 )
h.addWidget( TQLabel( "Rows:", self ) )
self.rows = TQSpinBox( self )
self.rows.setEnabled( FALSE )
h.addWidget( self.rows )
v.addSpacing( 12 )
b = TQRadioButton( "As many rows as fit on-screen,\n"
"as many columns as needed.",
self )
bg.insert( b )
v.addWidget( b )
self.connect( b, SIGNAL("clicked()"), self.setRowsByHeight )
v.addSpacing( 12 )
cb = TQCheckBox( "Variable-height rows", self )
cb.setChecked( TRUE )
self.connect( cb, SIGNAL("toggled(bool)"), self.setVariableHeight )
v.addWidget( cb )
v.addSpacing( 6 )
cb = TQCheckBox( "Variable-width columns", self )
self.connect( cb, SIGNAL("toggled(bool)"), self.setVariableWidth )
v.addWidget( cb )
cb = TQCheckBox( "Extended-Selection", self )
self.connect( cb, SIGNAL("toggled(bool)"), self.setMultiSelection )
v.addWidget( cb )
pb = TQPushButton( "Sort ascending", self )
self.connect( pb, SIGNAL("clicked()"), self.sortAscending )
v.addWidget( pb )
pb = TQPushButton( "Sort descending", self )
self.connect( pb, SIGNAL("clicked()"), self.sortDescending )
v.addWidget( pb )
v.addStretch( 100 )
i = 0
while i <= 2560:
i+=1
self.l.insertItem( str(TQString.fromLatin1( "Item " )) + str(TQString.number( i )), i )
self.columns.setRange( 1, 256 )
self.columns.setValue( 1 )
self.rows.setRange( 1, 256 )
self.rows.setValue( 256 )
self.connect( self.columns, SIGNAL("valueChanged(int)"), self.setNumCols )
self.connect( self.rows, SIGNAL("valueChanged(int)"), self.setNumRows )
# slots
def setNumCols( self ):
self.columns.setEnabled( TRUE )
self.rows.setEnabled( FALSE )
self.l.setColumnMode( self.columns.value() )
def setNumRows( self ):
self.columns.setEnabled( FALSE )
self.rows.setEnabled( TRUE )
self.l.setRowMode( self.rows.value() )
def setRowsByHeight( self ):
self.columns.setEnabled( FALSE )
self.rows.setEnabled( FALSE )
self.l.setRowMode( TQListBox.FitToHeight )
def setColsByWidth( self ):
self.columns.setEnabled( FALSE )
self.rows.setEnabled( FALSE )
self.l.setColumnMode( TQListBox.FitToWidth )
def setVariableWidth( self, b ):
self.l.setVariableWidth( b )
def setVariableHeight( self, b ):
self.l.setVariableHeight( b )
def setMultiSelection( self, b ):
self.l.clearSelection()
if b :
self.l.setSelectionMode( TQListBox.Extended )
else:
self.l.setSelectionMode( TQListBox.Single )
def sortAscending( self ):
self.l.sort( TRUE )
def sortDescending( self ):
self.l.sort( FALSE )
def main( args ):
a = TQApplication( args )
t = ListBoxDemo()
t.setCaption( "TQt Example - Listbox" )
a.setMainWidget( t )
t.show()
a.exec_loop()
if __name__=="__main__":
main(sys.argv)
|