File: PmwLogicalFont.py.html

package info (click to toggle)
python-pmw 0.6.2-0.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,652 kB
  • ctags: 2,716
  • sloc: python: 10,720; makefile: 44; sh: 24
file content (206 lines) | stat: -rw-r--r-- 11,350 bytes parent folder | download
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE HTML PUBLIC "-//Netscape_Microsoft//DTD HTML 3.0//EN">
<HTML>

<!-- This file generated using the Python HTMLgen module. -->
<HEAD>
  <META NAME="GENERATOR" CONTENT="HTMLgen 1.1">
        <TITLE>PmwLogicalFont.py</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<PRE>
import Tkinter
import string

<STRONG>def initialise</STRONG>(root, size=None, fontScheme = None):
  global _fontSize
  if size is not None:
    _fontSize = size

  if fontScheme == <FONT COLOR="#009900">'pmw1'</FONT>:
      defaultFont = logicalfont(<FONT COLOR="#009900">'Helvetica'</FONT>)
      menuFont =    logicalfont(<FONT COLOR="#009900">'Helvetica'</FONT>, weight=<FONT COLOR="#009900">'bold'</FONT>, slant=<FONT COLOR="#009900">'italic'</FONT>)
      scaleFont =   logicalfont(<FONT COLOR="#009900">'Helvetica'</FONT>, slant=<FONT COLOR="#009900">'italic'</FONT>)
      root.option_add(<FONT COLOR="#009900">'*Font'</FONT>,            defaultFont,  <FONT COLOR="#009900">'userDefault'</FONT>)
      root.option_add(<FONT COLOR="#009900">'*Menu*Font'</FONT>,       menuFont,     <FONT COLOR="#009900">'userDefault'</FONT>)
      root.option_add(<FONT COLOR="#009900">'*Menubutton*Font'</FONT>, menuFont,     <FONT COLOR="#009900">'userDefault'</FONT>)
      root.option_add(<FONT COLOR="#009900">'*Scale.*Font'</FONT>,     scaleFont,    <FONT COLOR="#009900">'userDefault'</FONT>)

  balloonFont = logicalfont(<FONT COLOR="#009900">'Helvetica'</FONT>, -6, pixel = <FONT COLOR="#009900">'12'</FONT>)
  if not fontexists(root, balloonFont):
      balloonFont = logicalfont(<FONT COLOR="#009900">'Helvetica'</FONT>, -2)
  root.option_add(<FONT COLOR="#009900">'*Balloon.*Font'</FONT>, balloonFont, <FONT COLOR="#009900">'userDefault'</FONT>)

<STRONG>def fontexists</STRONG>(widget, fontName):
    test = Tkinter.Label(widget)
    exists = 1
    try:
	test.configure(font = fontName)
    except Tkinter.TclError:
	exists = 0
    test.destroy()
    return exists

maxfontwidthcache = {}
<STRONG>def maxfontwidth</STRONG>(widget, fontName):
    if not maxfontwidthcache.has_key(fontName):
	test = Tkinter.Text(widget)
	test.tag_configure(<FONT COLOR="#009900">'FONTTAG'</FONT>, font=fontName)
	test.insert(<FONT COLOR="#009900">'end'</FONT>, <FONT COLOR="#009900">'W'</FONT>, (<FONT COLOR="#009900">'FONTTAG'</FONT>))
	maxfontwidthcache[fontName] = test.dlineinfo(<FONT COLOR="#009900">'1.0'</FONT>)[2]
	test.destroy()

    return maxfontwidthcache[fontName]

<STRONG>def logicalfont</STRONG>(name=<FONT COLOR="#009900">'Helvetica'</FONT>, sizeIncr = 0, **kw):
  if not fontInfo.has_key(name):
    raise ValueError, <FONT COLOR="#009900">'font %s does not exist'</FONT> % name

  rtn = []
  for field in _fontFields:
    if kw.has_key(field):
      logicalValue = kw[field]
    elif fontInfo[name].has_key(field):
      logicalValue = fontInfo[name][field]
    else:
      logicalValue = <FONT COLOR="#009900">'*'</FONT>

    if propertyAliases[name].has_key((field, logicalValue)):
      realValue = propertyAliases[name][(field, logicalValue)]
    elif propertyAliases[name].has_key((field, None)):
      realValue = propertyAliases[name][(field, None)]
    elif propertyAliases[None].has_key((field, logicalValue)):
      realValue = propertyAliases[None][(field, logicalValue)]
    elif propertyAliases[None].has_key((field, None)):
      realValue = propertyAliases[None][(field, None)]
    else:
      realValue = logicalValue

    if field == <FONT COLOR="#009900">'size'</FONT>:
      if realValue == <FONT COLOR="#009900">'*'</FONT>:
	  realValue = _fontSize
      realValue = str((realValue + sizeIncr) * 10)

    rtn.append(realValue)

  return string.join(rtn, <FONT COLOR="#009900">'-'</FONT>)

<STRONG>def logicalfontnames</STRONG>():
  return fontInfo.keys()

_fontSize = 14

_fontFields = (
  <FONT COLOR="#009900">'registry'</FONT>, <FONT COLOR="#009900">'foundry'</FONT>, <FONT COLOR="#009900">'family'</FONT>, <FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'slant'</FONT>, <FONT COLOR="#009900">'width'</FONT>, <FONT COLOR="#009900">'style'</FONT>,
  <FONT COLOR="#009900">'pixel'</FONT>, <FONT COLOR="#009900">'size'</FONT>, <FONT COLOR="#009900">'xres'</FONT>, <FONT COLOR="#009900">'yres'</FONT>, <FONT COLOR="#009900">'spacing'</FONT>, <FONT COLOR="#009900">'avgwidth'</FONT>, <FONT COLOR="#009900">'charset'</FONT>, <FONT COLOR="#009900">'encoding'</FONT>)

<FONT COLOR="#DD0000"># &lt;propertyAliases&gt; defines other names for which property values may</FONT>
<FONT COLOR="#DD0000"># be known by.  This is required because italics in adobe-helvetica</FONT>
# are specified by <FONT COLOR="#009900">'o'</FONT>, while other fonts use <FONT COLOR="#009900">'i'</FONT>.

propertyAliases = {}

propertyAliases[None] = {
  (<FONT COLOR="#009900">'slant'</FONT>, <FONT COLOR="#009900">'italic'</FONT>) : <FONT COLOR="#009900">'i'</FONT>,
  (<FONT COLOR="#009900">'slant'</FONT>, <FONT COLOR="#009900">'normal'</FONT>) : <FONT COLOR="#009900">'r'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'light'</FONT>) : <FONT COLOR="#009900">'normal'</FONT>,
  (<FONT COLOR="#009900">'width'</FONT>, <FONT COLOR="#009900">'wide'</FONT>) : <FONT COLOR="#009900">'normal'</FONT>,
  (<FONT COLOR="#009900">'width'</FONT>, <FONT COLOR="#009900">'condensed'</FONT>) : <FONT COLOR="#009900">'normal'</FONT>,
}

# <fontInfo> describes a <FONT COLOR="#009900">'logical'</FONT> font, giving the default values of
<FONT COLOR="#DD0000"># some of its properties.</FONT>

fontInfo = {}

fontInfo[<FONT COLOR="#009900">'Helvetica'</FONT>] = {
  <FONT COLOR="#009900">'foundry'</FONT> : <FONT COLOR="#009900">'adobe'</FONT>,
  <FONT COLOR="#009900">'family'</FONT> : <FONT COLOR="#009900">'helvetica'</FONT>,
  <FONT COLOR="#009900">'registry'</FONT> : <FONT COLOR="#009900">''</FONT>,
  <FONT COLOR="#009900">'charset'</FONT> : <FONT COLOR="#009900">'iso8859'</FONT>,
  <FONT COLOR="#009900">'encoding'</FONT> : <FONT COLOR="#009900">'1'</FONT>,
  <FONT COLOR="#009900">'spacing'</FONT> : <FONT COLOR="#009900">'p'</FONT>,
  <FONT COLOR="#009900">'slant'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'width'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'weight'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
}

propertyAliases[<FONT COLOR="#009900">'Helvetica'</FONT>] = {
  (<FONT COLOR="#009900">'slant'</FONT>, <FONT COLOR="#009900">'italic'</FONT>) : <FONT COLOR="#009900">'o'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'normal'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'light'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
}

fontInfo[<FONT COLOR="#009900">'Times'</FONT>] = {
  <FONT COLOR="#009900">'foundry'</FONT> : <FONT COLOR="#009900">'adobe'</FONT>,
  <FONT COLOR="#009900">'family'</FONT> : <FONT COLOR="#009900">'times'</FONT>,
  <FONT COLOR="#009900">'registry'</FONT> : <FONT COLOR="#009900">''</FONT>,
  <FONT COLOR="#009900">'charset'</FONT> : <FONT COLOR="#009900">'iso8859'</FONT>,
  <FONT COLOR="#009900">'encoding'</FONT> : <FONT COLOR="#009900">'1'</FONT>,
  <FONT COLOR="#009900">'spacing'</FONT> : <FONT COLOR="#009900">'p'</FONT>,
  <FONT COLOR="#009900">'slant'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'width'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'weight'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
}

propertyAliases[<FONT COLOR="#009900">'Times'</FONT>] = {
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'normal'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'light'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
}

fontInfo[<FONT COLOR="#009900">'Fixed'</FONT>] = {
  <FONT COLOR="#009900">'foundry'</FONT> : <FONT COLOR="#009900">'misc'</FONT>,
  <FONT COLOR="#009900">'family'</FONT> : <FONT COLOR="#009900">'fixed'</FONT>,
  <FONT COLOR="#009900">'registry'</FONT> : <FONT COLOR="#009900">''</FONT>,
  <FONT COLOR="#009900">'charset'</FONT> : <FONT COLOR="#009900">'iso8859'</FONT>,
  <FONT COLOR="#009900">'encoding'</FONT> : <FONT COLOR="#009900">'1'</FONT>,
  <FONT COLOR="#009900">'spacing'</FONT> : <FONT COLOR="#009900">'c'</FONT>,
  <FONT COLOR="#009900">'slant'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'width'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'weight'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
}

propertyAliases[<FONT COLOR="#009900">'Fixed'</FONT>] = {
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'normal'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'light'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'style'</FONT>, None) : <FONT COLOR="#009900">''</FONT>,
  (<FONT COLOR="#009900">'width'</FONT>, <FONT COLOR="#009900">'condensed'</FONT>) : <FONT COLOR="#009900">'semicondensed'</FONT>,
}

fontInfo[<FONT COLOR="#009900">'Courier'</FONT>] = {
  <FONT COLOR="#009900">'foundry'</FONT> : <FONT COLOR="#009900">'adobe'</FONT>,
  <FONT COLOR="#009900">'family'</FONT> : <FONT COLOR="#009900">'courier'</FONT>,
  <FONT COLOR="#009900">'registry'</FONT> : <FONT COLOR="#009900">''</FONT>,
  <FONT COLOR="#009900">'charset'</FONT> : <FONT COLOR="#009900">'iso8859'</FONT>,
  <FONT COLOR="#009900">'encoding'</FONT> : <FONT COLOR="#009900">'1'</FONT>,
  <FONT COLOR="#009900">'spacing'</FONT> : <FONT COLOR="#009900">'m'</FONT>,
  <FONT COLOR="#009900">'slant'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'width'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'weight'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
}

propertyAliases[<FONT COLOR="#009900">'Courier'</FONT>] = {
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'normal'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'light'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'style'</FONT>, None) : <FONT COLOR="#009900">''</FONT>,
}

fontInfo[<FONT COLOR="#009900">'Typewriter'</FONT>] = {
  <FONT COLOR="#009900">'foundry'</FONT> : <FONT COLOR="#009900">'b&amp;h'</FONT>,
  <FONT COLOR="#009900">'family'</FONT> : <FONT COLOR="#009900">'lucidatypewriter'</FONT>,
  <FONT COLOR="#009900">'registry'</FONT> : <FONT COLOR="#009900">''</FONT>,
  <FONT COLOR="#009900">'charset'</FONT> : <FONT COLOR="#009900">'iso8859'</FONT>,
  <FONT COLOR="#009900">'encoding'</FONT> : <FONT COLOR="#009900">'1'</FONT>,
  <FONT COLOR="#009900">'spacing'</FONT> : <FONT COLOR="#009900">'m'</FONT>,
  <FONT COLOR="#009900">'slant'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'width'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
  <FONT COLOR="#009900">'weight'</FONT> : <FONT COLOR="#009900">'normal'</FONT>,
}

propertyAliases[<FONT COLOR="#009900">'Typewriter'</FONT>] = {
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'normal'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
  (<FONT COLOR="#009900">'weight'</FONT>, <FONT COLOR="#009900">'light'</FONT>) : <FONT COLOR="#009900">'medium'</FONT>,
}

</PRE>

 </BODY> </HTML>