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.

fonts.py 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env python
  2. """**************************************************************************
  3. ** $Id: fonts.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. class Viewer( TQWidget ):
  14. def __init__( self ):
  15. TQWidget.__init__( self )
  16. self.setFontSubstitutions()
  17. #greeting_heb = TQString.fromUtf8( "\327\251\327\234\327\225\327\235" )
  18. greeting_heb = unicode( '\327\251\327\234\327\225\327\235','utf8' )
  19. #greeting_ru = TQString.fromUtf8( "\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" )
  20. greeting_ru = unicode('\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265','utf8' )
  21. greeting_en = "Hello"
  22. self.greetings = TQTextView( self, "textview" )
  23. self.greetings.setText( greeting_en + "\n" +
  24. greeting_ru + "\n" +
  25. greeting_heb )
  26. self.fontInfo = TQTextView( self, "fontinfo" )
  27. self.setDefault()
  28. self.defaultButton = TQPushButton( "Default", self, "pushbutton1" )
  29. self.defaultButton.setFont( TQFont( "times" ) )
  30. self.connect( self.defaultButton, SIGNAL("clicked()"), self.setDefault )
  31. self.sansSerifButton = TQPushButton( "Sans Serif", self, "pushbutton2" )
  32. self.sansSerifButton.setFont( TQFont( "Helvetica", 12 ) )
  33. self.connect( self.sansSerifButton, SIGNAL("clicked()"), self.setSansSerif )
  34. self.italicsButton = TQPushButton( "Italics", self, "pushbutton3" )
  35. self.italicsButton.setFont( TQFont( "lucida", 12, TQFont.Bold, True ) )
  36. self.connect( self.italicsButton, SIGNAL("clicked()"), self.setItalics )
  37. self.layout()
  38. def setDefault( self ):
  39. font = TQFont( "Bavaria" )
  40. font.setPointSize( 24 )
  41. font.setWeight( TQFont.Bold )
  42. font.setUnderline( True )
  43. self.greetings.setFont( font )
  44. self.showFontInfo( font )
  45. def setSansSerif( self ):
  46. font = TQFont( "Newyork", 18 )
  47. font.setStyleHint( TQFont.SansSerif )
  48. self.greetings.setFont( font )
  49. self.showFontInfo( font )
  50. def setItalics( self ):
  51. font = TQFont( "Tokyo" )
  52. font.setPointSize( 32 )
  53. font.setWeight( TQFont.Bold )
  54. font.setItalic( True )
  55. self.greetings.setFont( font )
  56. self.showFontInfo( font )
  57. def showFontInfo( self, font ):
  58. info = TQFontInfo( font )
  59. messageText = "Font requested: \"" + str(font.family()) + "\" " \
  60. + str(TQString.number( font.pointSize() )) + "pt<BR>" \
  61. + "Font used: \"" + str(info.family()) + "\" " \
  62. + str(TQString.number( info.pointSize() )) + "pt<P>"
  63. if not self.substitutes.isEmpty() :
  64. messageText += "The following substitutions exist for " + \
  65. str(font.family()) + ":<UL>"
  66. for i in self.substitutes :
  67. messageText += "<LI>\"" + str(i) + "\""
  68. messageText += "</UL>";
  69. else :
  70. messageText += "No substitutions exist for " + \
  71. str(font.family()) + "."
  72. self.fontInfo.setText( messageText )
  73. def setFontSubstitutions( self ):
  74. self.substitutes = TQStringList()
  75. self.substitutes.append( "Times" )
  76. self.substitutes.append( "Mincho" )
  77. self.substitutes.append( "Arabic Newspaper" )
  78. self.substitutes.append( "crox" )
  79. #TQFont.insertSubstitutions( "Bavaria", self.substitutes )
  80. TQFont.insertSubstitution( "Bavaria", "Times" )
  81. TQFont.insertSubstitution( "Tokyo", "Lucida" )
  82. # For those who prefer to use TQt Designer for creating GUIs
  83. # the following function might not be of particular interest:
  84. # all it does is creating the widget layout.
  85. def layout( self ):
  86. textViewContainer = TQHBoxLayout()
  87. textViewContainer.addWidget( self.greetings )
  88. textViewContainer.addWidget( self.fontInfo )
  89. buttonContainer = TQHBoxLayout()
  90. buttonContainer.addWidget( self.defaultButton )
  91. buttonContainer.addWidget( self.sansSerifButton )
  92. buttonContainer.addWidget( self.italicsButton )
  93. maxButtonHeight = self.defaultButton.height()
  94. if self.sansSerifButton.height() > maxButtonHeight :
  95. maxButtonHeight = self.sansSerifButton.height()
  96. if self.italicsButton.height() > maxButtonHeight :
  97. maxButtonHeight = self.italicsButton.height()
  98. self.defaultButton.setFixedHeight( maxButtonHeight )
  99. self.sansSerifButton.setFixedHeight( maxButtonHeight )
  100. self.italicsButton.setFixedHeight( maxButtonHeight )
  101. container = TQVBoxLayout( self )
  102. container.addLayout( textViewContainer )
  103. container.addLayout( buttonContainer )
  104. self.resize( 700, 250 )
  105. def main( args ):
  106. app = TQApplication(sys.argv) # application object
  107. textViewer = Viewer()
  108. textViewer.setCaption( "TQt Example - Simple TQFont Demo" )
  109. app.setMainWidget( textViewer )
  110. textViewer.show()
  111. app.exec_loop()
  112. if __name__=="__main__":
  113. main(sys.argv)