]> SALOME platform Git repositories - tools/eficas.git/blob - Pmw/Pmw_1_2/lib/PmwLogicalFont.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Pmw / Pmw_1_2 / lib / PmwLogicalFont.py
1 import os
2 import string
3
4 def _font_initialise(root, size=None, fontScheme = None):
5     global _fontSize
6     if size is not None:
7         _fontSize = size
8
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')
18
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')
24         else:
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')
34
35 def logicalfont(name='Helvetica', sizeIncr = 0, **kw):
36   if not _fontInfo.has_key(name):
37     raise ValueError, 'font %s does not exist' % name
38
39   rtn = []
40   for field in _fontFields:
41     if kw.has_key(field):
42       logicalValue = kw[field]
43     elif _fontInfo[name].has_key(field):
44       logicalValue = _fontInfo[name][field]
45     else:
46       logicalValue = '*'
47
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)]
56     else:
57       realValue = logicalValue
58
59     if field == 'size':
60       if realValue == '*':
61           realValue = _fontSize
62       realValue = str((realValue + sizeIncr) * 10)
63
64     rtn.append(realValue)
65
66   return string.join(rtn, '-')
67
68 def logicalfontnames():
69   return _fontInfo.keys()
70
71 if os.name == 'nt':
72     _fontSize = 16
73 else:
74     _fontSize = 14
75
76 _fontFields = (
77   'registry', 'foundry', 'family', 'weight', 'slant', 'width', 'style',
78   'pixel', 'size', 'xres', 'yres', 'spacing', 'avgwidth', 'charset', 'encoding')
79
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'.
83
84 _propertyAliases = {}
85
86 _propertyAliases[None] = {
87   ('slant', 'italic') : 'i',
88   ('slant', 'normal') : 'r',
89   ('weight', 'light') : 'normal',
90   ('width', 'wide') : 'normal',
91   ('width', 'condensed') : 'normal',
92 }
93
94 # <_fontInfo> describes a 'logical' font, giving the default values of
95 # some of its properties.
96
97 _fontInfo = {}
98
99 _fontInfo['Helvetica'] = {
100   'foundry' : 'adobe',
101   'family' : 'helvetica',
102   'registry' : '',
103   'charset' : 'iso8859',
104   'encoding' : '1',
105   'spacing' : 'p',
106   'slant' : 'normal',
107   'width' : 'normal',
108   'weight' : 'normal',
109 }
110
111 _propertyAliases['Helvetica'] = {
112   ('slant', 'italic') : 'o',
113   ('weight', 'normal') : 'medium',
114   ('weight', 'light') : 'medium',
115 }
116
117 _fontInfo['Times'] = {
118   'foundry' : 'adobe',
119   'family' : 'times',
120   'registry' : '',
121   'charset' : 'iso8859',
122   'encoding' : '1',
123   'spacing' : 'p',
124   'slant' : 'normal',
125   'width' : 'normal',
126   'weight' : 'normal',
127 }
128
129 _propertyAliases['Times'] = {
130   ('weight', 'normal') : 'medium',
131   ('weight', 'light') : 'medium',
132 }
133
134 _fontInfo['Fixed'] = {
135   'foundry' : 'misc',
136   'family' : 'fixed',
137   'registry' : '',
138   'charset' : 'iso8859',
139   'encoding' : '1',
140   'spacing' : 'c',
141   'slant' : 'normal',
142   'width' : 'normal',
143   'weight' : 'normal',
144 }
145
146 _propertyAliases['Fixed'] = {
147   ('weight', 'normal') : 'medium',
148   ('weight', 'light') : 'medium',
149   ('style', None) : '',
150   ('width', 'condensed') : 'semicondensed',
151 }
152
153 _fontInfo['Courier'] = {
154   'foundry' : 'adobe',
155   'family' : 'courier',
156   'registry' : '',
157   'charset' : 'iso8859',
158   'encoding' : '1',
159   'spacing' : 'm',
160   'slant' : 'normal',
161   'width' : 'normal',
162   'weight' : 'normal',
163 }
164
165 _propertyAliases['Courier'] = {
166   ('weight', 'normal') : 'medium',
167   ('weight', 'light') : 'medium',
168   ('style', None) : '',
169 }
170
171 _fontInfo['Typewriter'] = {
172   'foundry' : 'b&h',
173   'family' : 'lucidatypewriter',
174   'registry' : '',
175   'charset' : 'iso8859',
176   'encoding' : '1',
177   'spacing' : 'm',
178   'slant' : 'normal',
179   'width' : 'normal',
180   'weight' : 'normal',
181 }
182
183 _propertyAliases['Typewriter'] = {
184   ('weight', 'normal') : 'medium',
185   ('weight', 'light') : 'medium',
186 }
187
188 if os.name == 'nt':
189     # For some reason 'fixed' fonts on NT aren't.
190     _fontInfo['Fixed'] = _fontInfo['Courier']
191     _propertyAliases['Fixed'] = _propertyAliases['Courier']