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.

progressbar.py 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/usr/bin/env python
  2. """***********************************************************************
  3. ** $Id: progressbar.py,v 1.1 2003/06/10 14:51:24 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 pdb
  12. import sys
  13. from python_tqt.qt import *
  14. FALSE = 0
  15. TRUE = 1
  16. class ProgressBar( TQButtonGroup ):
  17. # Constructor
  18. # Creates child widgets of the ProgressBar widget
  19. def __init__( self, parent=None, name=None ):
  20. TQButtonGroup.__init__( self, 0, TQt.Horizontal, "Progress Bar", parent, name )
  21. self.timer = TQTimer()
  22. self.setMargin( 10 )
  23. toplayout = TQGridLayout( self.layout(), 2, 2, 5)
  24. self.setRadioButtonExclusive( TRUE )
  25. # insert three radiobuttons which the user can use
  26. # to set the speed of the progress and two pushbuttons
  27. # to start/pause/continue and reset the progress
  28. self.slow = TQRadioButton( "&Slow", self )
  29. self.normal = TQRadioButton( "&Normal", self )
  30. self.fast = TQRadioButton( "&Fast", self )
  31. vb1 = TQVBoxLayout( )
  32. toplayout.addLayout( vb1, 0, 0 )
  33. vb1.addWidget( self.slow )
  34. vb1.addWidget( self.normal )
  35. vb1.addWidget( self.fast )
  36. # two push buttons, one for start, for for reset.
  37. self.start = TQPushButton( "&Start", self )
  38. self.reset = TQPushButton( "&Reset", self )
  39. vb2 = TQVBoxLayout()
  40. toplayout.addLayout( vb2, 0, 1 )
  41. vb2.addWidget( self.start )
  42. vb2.addWidget( self.reset )
  43. # Create the progressbar
  44. self.progress = TQProgressBar( 100, self )
  45. #self.progress.setStyle( TQMotifStyle() )
  46. toplayout.addMultiCellWidget( self.progress, 1, 1, 0, 1 )
  47. # connect the clicked() SIGNALs of the pushbuttons to SLOTs
  48. self.connect( self.start, SIGNAL("clicked()"), self.slotStart )
  49. self.connect( self.reset, SIGNAL("clicked()"), self.slotReset )
  50. # connect the timeout() SIGNAL of the progress-timer to a SLOT
  51. self.connect( self.timer, SIGNAL("timeout()"), self.slotTimeout )
  52. # Let's start with normal speed...
  53. self.normal.setChecked( TRUE )
  54. # some contraints
  55. self.start.setFixedWidth( 80 )
  56. self.setMinimumWidth( 300 )
  57. # SLOT slotStart
  58. # This SLOT is called if the user clicks start/pause/continue button
  59. def slotStart( self ):
  60. # If the progress bar is at the beginning...
  61. if self.progress.progress() == -1 :
  62. # ...set according to the checked speed-radiobutton the
  63. # the number of steps which are needed to complete the process
  64. if self.slow.isChecked():
  65. self.progress.setTotalSteps( 10000 )
  66. elif self.normal.isChecked() :
  67. self.progress.setTotalSteps( 1000 )
  68. else :
  69. self.progress.setTotalSteps( 50 )
  70. # disable the speed-radiobuttons
  71. self.slow.setEnabled( FALSE )
  72. self.normal.setEnabled( FALSE )
  73. self.fast.setEnabled( FALSE )
  74. # If the progress is not running...
  75. if not self.timer.isActive() :
  76. # ...start the timer (and so the progress) with a interval of 1 ms...
  77. self.timer.start( 1 )
  78. # ...and rename the start/pause/continue button to Pause
  79. self.start.setText( "&Pause" )
  80. else : # if the prgress is running...
  81. # ...stop the timer (and so the prgress)...
  82. self.timer.stop()
  83. # ...and rename the start/pause/continue button to Continue
  84. self.start.setText( "&Continue" )
  85. # SLOT slotReset
  86. # This SLOT is called when the user clicks the reset button
  87. def slotReset( self ):
  88. # stop the timer and progress
  89. self.timer.stop()
  90. # rename the start/pause/continue button to Start...
  91. self.start.setText( "&Start" )
  92. # ...and enable this button
  93. self.start.setEnabled( TRUE )
  94. # enable the speed-radiobuttons
  95. self.slow.setEnabled( TRUE )
  96. self.normal.setEnabled( TRUE )
  97. self.fast.setEnabled( TRUE )
  98. # reset the progressbar
  99. self.progress.reset()
  100. # SLOT slotTimeout
  101. # This SLOT is called each ms when the timer is
  102. # active (== progress is running)
  103. def slotTimeout( self ):
  104. p = self.progress.progress()
  105. # If the progress is complete...
  106. if p == self.progress.totalSteps() :
  107. # ...rename the start/pause/continue button to Start...
  108. self.start.setText( "&Start" )
  109. # ...and disable it...
  110. self.start.setEnabled( FALSE )
  111. # ...and return
  112. return
  113. # If the process is not complete increase it
  114. p += 1
  115. self.progress.setProgress( p )
  116. #TQPushButton *start, *pause, *reset;
  117. def main( args ):
  118. a = TQApplication( args )
  119. progressbar = ProgressBar()
  120. progressbar.setCaption("TQt Example - ProgressBar")
  121. a.setMainWidget(progressbar)
  122. progressbar.show()
  123. a.exec_loop()
  124. if __name__=="__main__":
  125. main(sys.argv)