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.

checklists.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python
  2. # vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
  3. # Copyright (C) 2002 Oleksandr Yakovlyev (yshurik) <yshurik@thekompany.com>
  4. import sys
  5. from python_tqt.qt import *
  6. TRUE = 1
  7. FALSE = 0
  8. class CheckLists(TQWidget):
  9. def __init__(self, *args):
  10. apply( TQWidget.__init__, (self, ) + args )
  11. lay = TQHBoxLayout(self)
  12. lay.setMargin(5)
  13. vbox1 = TQVBoxLayout(lay)
  14. vbox1.setMargin(5)
  15. # First child: a Label
  16. vbox1.addWidget(TQLabel("Check some items!", self))
  17. # Second child: the ListView
  18. self.lv1 = TQListView(self)
  19. vbox1.addWidget(self.lv1)
  20. self.lv1.addColumn("Items")
  21. self.lv1.setRootIsDecorated(TRUE)
  22. # create a list with 4 ListViewItems which will be parent items of other ListViewItems
  23. parentList = []
  24. parentList.append( TQListViewItem( self.lv1, "Parent Item 1" ) )
  25. parentList.append( TQListViewItem( self.lv1, "Parent Item 2" ) )
  26. parentList.append( TQListViewItem( self.lv1, "Parent Item 3" ) )
  27. parentList.append( TQListViewItem( self.lv1, "Parent Item 4" ) )
  28. num = 0
  29. self.childList1 = []
  30. # go through the list of parent items...
  31. for i in range(4):
  32. it = parentList[i]
  33. it.setOpen( TRUE )
  34. # ...and create 5 checkable child ListViewItems for each parent item
  35. for j in range(5):
  36. ci = TQCheckListItem( it, TQString("%1. Child of Parent %2").arg( j ).arg( i ), TQCheckListItem.CheckBox )
  37. self.childList1.append(ci)
  38. # Create another widget for layouting
  39. tmp1 = TQVBoxLayout( lay )
  40. tmp1.setMargin( 5 )
  41. # create a pushbutton
  42. copy1 = TQPushButton( " -> ", self )
  43. tmp1.addWidget( copy1 )
  44. copy1.setMaximumWidth( copy1.sizeHint().width() );
  45. # connect the SIGNAL clicked() of the pushbutton with the SLOT copy1to2()
  46. self.connect( copy1, SIGNAL('clicked()'), self.copy1to2 )
  47. # another widget for layouting
  48. vbox2 = TQVBoxLayout( lay )
  49. vbox2.setMargin( 5 )
  50. # and another label
  51. vbox2.addWidget( TQLabel( "Check one item!", self ) )
  52. # create the second listview
  53. self.lv2 = TQListView( self )
  54. vbox2.addWidget( self.lv2 )
  55. self.lv2.addColumn( "Items" )
  56. self.lv2.setRootIsDecorated( TRUE )
  57. # another widget needed for layouting only
  58. tmp2 = TQVBoxLayout( lay )
  59. tmp2.setMargin( 5 )
  60. # create another pushbutton...
  61. copy2 = TQPushButton( " -> ", self )
  62. lay.addWidget( copy2 )
  63. copy2.setMaximumWidth( copy2.sizeHint().width() )
  64. # ...and connect its clicked() SIGNAL to the copy2to3() SLOT
  65. self.connect( copy2, SIGNAL('clicked()'), self.copy2to3 )
  66. tmp3 = TQVBoxLayout( lay )
  67. tmp3.setMargin( 5 )
  68. # and create a label which will be at the right of the window
  69. self.label = TQLabel( "No Item yet...", self )
  70. tmp3.addWidget( self.label )
  71. def copy1to2(self):
  72. self.lv2.clear()
  73. # Insert first a controller Item into the second ListView. Always if Radio-ListViewItems
  74. # are inserted into a Listview, the parent item of these MUST be a controller Item!
  75. item = TQCheckListItem( self.lv2, "Controller", TQCheckListItem.Controller )
  76. item.setOpen( TRUE )
  77. self.listChild2 = []
  78. for it in self.childList1:
  79. # ...check state of childs, and...
  80. if it.parent() != None:
  81. # ...if the item is checked...
  82. if it.isOn():
  83. # ...insert a Radio-ListViewItem with the same text into the second ListView
  84. ri = TQCheckListItem(item , it.text(0), TQCheckListItem.RadioButton)
  85. self.listChild2.append(ri)
  86. if item.firstChild() != None:
  87. item.firstChild().setOn(TRUE)
  88. def copy2to3(self):
  89. self.label.setText( "No Item checked" )
  90. # iterate through the second ListView...
  91. for it in self.listChild2:
  92. # ...check state of childs, and...
  93. if it.parent() != None:
  94. # ...if the item is checked...
  95. if it.isOn():
  96. # ...set the text of the item to the label
  97. self.label.setText( it.text( 0 ) )
  98. a = TQApplication(sys.argv)
  99. checkLists = CheckLists()
  100. checkLists.resize(700, 400)
  101. checkLists.setCaption("PyTQt example - CheckLists")
  102. a.setMainWidget(checkLists)
  103. checkLists.show()
  104. a.exec_loop()