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
|
#!/usr/bin/env python
"""**************************************************************************
** $Id: fonts.py,v 1.1 2003/07/01 14:18:37 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 *
class Viewer( TQWidget ):
def __init__( self ):
TQWidget.__init__( self )
self.setFontSubstitutions()
greeting_heb = TQString.fromUtf8( b"\327\251\327\234\327\225\327\235" )
greeting_ru = TQString.fromUtf8( b"\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" )
greeting_en = "Hello"
self.greetings = TQTextView( self, "textview" )
self.greetings.setText( greeting_en + "\n" +
greeting_ru + "\n" +
greeting_heb )
self.fontInfo = TQTextView( self, "fontinfo" )
self.setDefault()
self.defaultButton = TQPushButton( "Default", self, "pushbutton1" )
self.defaultButton.setFont( TQFont( "times" ) )
self.connect( self.defaultButton, SIGNAL("clicked()"), self.setDefault )
self.sansSerifButton = TQPushButton( "Sans Serif", self, "pushbutton2" )
self.sansSerifButton.setFont( TQFont( "Helvetica", 12 ) )
self.connect( self.sansSerifButton, SIGNAL("clicked()"), self.setSansSerif )
self.italicsButton = TQPushButton( "Italics", self, "pushbutton3" )
self.italicsButton.setFont( TQFont( "lucida", 12, TQFont.Bold, True ) )
self.connect( self.italicsButton, SIGNAL("clicked()"), self.setItalics )
self.layout()
def setDefault( self ):
font = TQFont( "Bavaria" )
font.setPointSize( 24 )
font.setWeight( TQFont.Bold )
font.setUnderline( True )
self.greetings.setFont( font )
self.showFontInfo( font )
def setSansSerif( self ):
font = TQFont( "Newyork", 18 )
font.setStyleHint( TQFont.SansSerif )
self.greetings.setFont( font )
self.showFontInfo( font )
def setItalics( self ):
font = TQFont( "Tokyo" )
font.setPointSize( 32 )
font.setWeight( TQFont.Bold )
font.setItalic( True )
self.greetings.setFont( font )
self.showFontInfo( font )
def showFontInfo( self, font ):
info = TQFontInfo( font )
messageText = "Font requested: \"" + str(font.family()) + "\" " \
+ str(TQString.number( font.pointSize() )) + "pt<BR>" \
+ "Font used: \"" + str(info.family()) + "\" " \
+ str(TQString.number( info.pointSize() )) + "pt<P>"
if not self.substitutes.isEmpty() :
messageText += "The following substitutions exist for " + \
str(font.family()) + ":<UL>"
for i in self.substitutes :
messageText += "<LI>\"" + str(i) + "\""
messageText += "</UL>";
else :
messageText += "No substitutions exist for " + \
str(font.family()) + "."
self.fontInfo.setText( messageText )
def setFontSubstitutions( self ):
self.substitutes = TQStringList()
self.substitutes.append( "Times" )
self.substitutes.append( "Mincho" )
self.substitutes.append( "Arabic Newspaper" )
self.substitutes.append( "crox" )
#TQFont.insertSubstitutions( "Bavaria", self.substitutes )
TQFont.insertSubstitution( "Bavaria", "Times" )
TQFont.insertSubstitution( "Tokyo", "Lucida" )
# For those who prefer to use TQt Designer for creating GUIs
# the following function might not be of particular interest:
# all it does is creating the widget layout.
def layout( self ):
textViewContainer = TQHBoxLayout()
textViewContainer.addWidget( self.greetings )
textViewContainer.addWidget( self.fontInfo )
buttonContainer = TQHBoxLayout()
buttonContainer.addWidget( self.defaultButton )
buttonContainer.addWidget( self.sansSerifButton )
buttonContainer.addWidget( self.italicsButton )
maxButtonHeight = self.defaultButton.height()
if self.sansSerifButton.height() > maxButtonHeight :
maxButtonHeight = self.sansSerifButton.height()
if self.italicsButton.height() > maxButtonHeight :
maxButtonHeight = self.italicsButton.height()
self.defaultButton.setFixedHeight( maxButtonHeight )
self.sansSerifButton.setFixedHeight( maxButtonHeight )
self.italicsButton.setFixedHeight( maxButtonHeight )
container = TQVBoxLayout( self )
container.addLayout( textViewContainer )
container.addLayout( buttonContainer )
self.resize( 700, 250 )
def main( args ):
app = TQApplication(sys.argv) # application object
textViewer = Viewer()
textViewer.setCaption( "TQt Example - Simple TQFont Demo" )
app.setMainWidget( textViewer )
textViewer.show()
app.exec_loop()
if __name__=="__main__":
main(sys.argv)
|