4 def _font_initialise(root, size=None, fontScheme = None):
9 if fontScheme in ('pmw1', 'pmw2'):
10 if os.name == 'posix':
11 defaultFont = logicalfont('Helvetica')
12 menuFont = logicalfont('Helvetica', weight='bold', slant='italic')
13 scaleFont = logicalfont('Helvetica', slant='italic')
14 root.option_add('*Font', defaultFont, 'userDefault')
15 root.option_add('*Menu*Font', menuFont, 'userDefault')
16 root.option_add('*Menubutton*Font', menuFont, 'userDefault')
17 root.option_add('*Scale.*Font', scaleFont, 'userDefault')
19 if fontScheme == 'pmw1':
20 balloonFont = logicalfont('Helvetica', -6, pixel = '12')
21 else: # fontScheme == 'pmw2'
22 balloonFont = logicalfont('Helvetica', -2)
23 root.option_add('*Balloon.*Font', balloonFont, 'userDefault')
25 defaultFont = logicalfont('Helvetica')
26 root.option_add('*Font', defaultFont, 'userDefault')
27 elif fontScheme == 'default':
28 defaultFont = ('Helvetica', '-%d' % (_fontSize,), 'bold')
29 entryFont = ('Helvetica', '-%d' % (_fontSize,))
30 textFont = ('Courier', '-%d' % (_fontSize,))
31 root.option_add('*Font', defaultFont, 'userDefault')
32 root.option_add('*Entry*Font', entryFont, 'userDefault')
33 root.option_add('*Text*Font', textFont, 'userDefault')
35 def logicalfont(name='Helvetica', sizeIncr = 0, **kw):
36 if not _fontInfo.has_key(name):
37 raise ValueError, 'font %s does not exist' % name
40 for field in _fontFields:
42 logicalValue = kw[field]
43 elif _fontInfo[name].has_key(field):
44 logicalValue = _fontInfo[name][field]
48 if _propertyAliases[name].has_key((field, logicalValue)):
49 realValue = _propertyAliases[name][(field, logicalValue)]
50 elif _propertyAliases[name].has_key((field, None)):
51 realValue = _propertyAliases[name][(field, None)]
52 elif _propertyAliases[None].has_key((field, logicalValue)):
53 realValue = _propertyAliases[None][(field, logicalValue)]
54 elif _propertyAliases[None].has_key((field, None)):
55 realValue = _propertyAliases[None][(field, None)]
57 realValue = logicalValue
62 realValue = str((realValue + sizeIncr) * 10)
66 return string.join(rtn, '-')
68 def logicalfontnames():
69 return _fontInfo.keys()
77 'registry', 'foundry', 'family', 'weight', 'slant', 'width', 'style',
78 'pixel', 'size', 'xres', 'yres', 'spacing', 'avgwidth', 'charset', 'encoding')
80 # <_propertyAliases> defines other names for which property values may
81 # be known by. This is required because italics in adobe-helvetica
82 # are specified by 'o', while other fonts use 'i'.
86 _propertyAliases[None] = {
87 ('slant', 'italic') : 'i',
88 ('slant', 'normal') : 'r',
89 ('weight', 'light') : 'normal',
90 ('width', 'wide') : 'normal',
91 ('width', 'condensed') : 'normal',
94 # <_fontInfo> describes a 'logical' font, giving the default values of
95 # some of its properties.
99 _fontInfo['Helvetica'] = {
101 'family' : 'helvetica',
103 'charset' : 'iso8859',
111 _propertyAliases['Helvetica'] = {
112 ('slant', 'italic') : 'o',
113 ('weight', 'normal') : 'medium',
114 ('weight', 'light') : 'medium',
117 _fontInfo['Times'] = {
121 'charset' : 'iso8859',
129 _propertyAliases['Times'] = {
130 ('weight', 'normal') : 'medium',
131 ('weight', 'light') : 'medium',
134 _fontInfo['Fixed'] = {
138 'charset' : 'iso8859',
146 _propertyAliases['Fixed'] = {
147 ('weight', 'normal') : 'medium',
148 ('weight', 'light') : 'medium',
149 ('style', None) : '',
150 ('width', 'condensed') : 'semicondensed',
153 _fontInfo['Courier'] = {
155 'family' : 'courier',
157 'charset' : 'iso8859',
165 _propertyAliases['Courier'] = {
166 ('weight', 'normal') : 'medium',
167 ('weight', 'light') : 'medium',
168 ('style', None) : '',
171 _fontInfo['Typewriter'] = {
173 'family' : 'lucidatypewriter',
175 'charset' : 'iso8859',
183 _propertyAliases['Typewriter'] = {
184 ('weight', 'normal') : 'medium',
185 ('weight', 'light') : 'medium',
189 # For some reason 'fixed' fonts on NT aren't.
190 _fontInfo['Fixed'] = _fontInfo['Courier']
191 _propertyAliases['Fixed'] = _propertyAliases['Courier']