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.

richtext.py 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python
  2. """**************************************************************************
  3. ** $Id: richtext.py,v 1.1 2003/07/01 14:18:37 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. sayings = [
  14. "<b>Saying 1:</b><br>"
  15. "<hr><br><br>"
  16. "<big>Evil is that which one believes of others. It is a sin to believe evil "
  17. "of others, but it is seldom a mistake.</big><br><br>"
  18. "<center><i>-- H.L. Mencken</i></center>",
  19. "<b>Saying 2:</b><br>"
  20. "<hr><br><br>"
  21. "<big>A well-used door needs no oil on its hinges.<br>"
  22. "A swift-flowing steam does not grow stagnant.<br>"
  23. "Neither sound nor thoughts can travel through a vacuum.<br>"
  24. "Software rots if not used.<br><br>"
  25. "These are great mysteries.</big><br><br>"
  26. "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>",
  27. "<b>Saying 3:</b><br>"
  28. "<hr><br><br>"
  29. "<big>Show business is just like high school, except you get paid.</big><br><br>"
  30. "<center><i>-- Martin Mull</i></center>",
  31. "<b>Saying 4:</b><br>"
  32. "<hr><br><br>"
  33. "<big><b>The Least Successful Executions</b><br>"
  34. "<twocolumn><p> History has furnished us with two executioners worthy of attention. "
  35. "The first performed in Sydney in Australia. In 1803 three attempts were "
  36. "made to hang a Mr. Joseph Samuels. On the first two of these the rope "
  37. "snapped, while on the third Mr. Samuels just hung there peacefully until he "
  38. "and everyone else got bored. Since he had proved unsusceptible to capital "
  39. "punishment, he was reprieved.</p>"
  40. "<p> The most important British executioner was Mr. James Berry who "
  41. "tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each "
  42. "occasion failed to get the trap door open.<!p>"
  43. "<p> In recognition of this achievement, the Home Secretary commuted "
  44. "Lee's sentence to \"life\" imprisonment. He was released in 1917, emigrated "
  45. "to America and lived until 1933.</p></twocolumn></big><br><br>"
  46. "<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>",
  47. "<b>Saying 5:</b><br>"
  48. "<hr><br><br>"
  49. "<big>If you can, help others. If you can't, at least don't hurt others.</big><br><br>"
  50. "<center><i>-- the Dalai Lama</i></center>",
  51. "<b>Saying 6:</b><br>"
  52. "<hr><br><br>"
  53. "<big>Television has brought back murder into the home -- where it belongs.</big><br><br>"
  54. "<center><i>-- Alfred Hitchcock</i></center>",
  55. "<b>Saying 7:</b><br>"
  56. "<hr><br><br>"
  57. "<big>I don't know who my grandfather was; I am much more concerned to know "
  58. "what his grandson will be.</big><br><br>"
  59. "<center><i>-- Abraham Lincoln</i></center>",
  60. 0
  61. ]
  62. class MyRichText( TQVBox ):
  63. def __init__( self, parent = None, name = None ):
  64. TQVBox.__init__( self, parent, name )
  65. self.setMargin( 5 )
  66. self.view = TQTextView( self )
  67. #self.view.setText( "This is a <b>Test</b> with <i>italic</i> <u>stuff</u>" )
  68. paper = TQBrush()
  69. paper.setPixmap( TQPixmap( "marble.png" ) )
  70. if paper.pixmap() != 0 :
  71. self.view.setPaper( paper )
  72. else :
  73. self.view.setPaper( white )
  74. self.view.setText( sayings[0] )
  75. self.view.setMinimumSize( 450, 250 )
  76. buttons = TQHBox( self )
  77. buttons.setMargin( 5 )
  78. self.bClose = TQPushButton( "&Close", buttons )
  79. self.bPrev = TQPushButton( "<< &Prev", buttons )
  80. self.bNext = TQPushButton( "&Next >>", buttons )
  81. self.bPrev.setEnabled( False )
  82. self.connect( self.bClose, SIGNAL("clicked()"), tqApp, SLOT("quit()") )
  83. self.connect( self.bPrev, SIGNAL("clicked()"), self.prev )
  84. self.connect( self.bNext, SIGNAL("clicked()"), self.next )
  85. self.num = 0
  86. def prev( self ):
  87. if self.num <= 0 :
  88. return
  89. self.num -= 1
  90. self.view.setText( sayings[self.num] )
  91. if self.num == 0 :
  92. self.bPrev.setEnabled( False )
  93. self.bNext.setEnabled( True )
  94. def next( self ):
  95. self.num += 1
  96. if not sayings[self.num]:
  97. return
  98. self.view.setText( sayings[self.num] )
  99. if not sayings[self.num + 1]:
  100. self.bNext.setEnabled( False )
  101. self.bPrev.setEnabled( True )
  102. def main( args ):
  103. a = TQApplication(sys.argv) # application object
  104. richtext = MyRichText()
  105. richtext.resize( 450, 350 );
  106. richtext.setCaption( "TQt Example - Richtext" )
  107. a.setMainWidget( richtext )
  108. richtext.show()
  109. a.exec_loop()
  110. if __name__=="__main__":
  111. main(sys.argv)