Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40f9b7b

Browse files
author
Just van Rossum
committed
First Checked In.
1 parent f59a89b commit 40f9b7b

28 files changed

Lines changed: 8612 additions & 0 deletions

Mac/Tools/IDE/BuildIDE.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
import os
3+
import buildtools
4+
import Res
5+
import py_resource
6+
7+
buildtools.DEBUG=1
8+
9+
template = buildtools.findtemplate()
10+
11+
ide_home = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")
12+
13+
mainfilename = os.path.join(ide_home, "PythonIDE.py")
14+
dstfilename = os.path.join(sys.exec_prefix, "Python IDE")
15+
16+
buildtools.process(template, mainfilename, dstfilename, 1)
17+
18+
targetref = Res.OpenResFile(dstfilename)
19+
Res.UseResFile(targetref)
20+
21+
files = os.listdir(ide_home)
22+
23+
files = filter(lambda x: x[-3:] == '.py' and x not in ("BuildIDE.py", "PythonIDE.py"), files)
24+
25+
for name in files:
26+
print "adding", name
27+
fullpath = os.path.join(ide_home, name)
28+
id, name = py_resource.frompyfile(fullpath, name[:-3], preload=1,
29+
ispackage=0)
30+
31+
wresref = Res.OpenResFile(os.path.join(ide_home, "Widgets.rsrc"))
32+
buildtools.copyres(wresref, targetref, [], 0)

Mac/Tools/IDE/FontSettings.py

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
"""usage:
2+
newsettings = FontDialog(('Chicago', 0, 12, (0, 0, 0))) # font name or id, style flags, size, color (color is ignored)
3+
if newsettings:
4+
fontsettings, tabsettings = newsettings
5+
font, style, size, color = fontsettings # 'font' is always the font name, not the id number
6+
# do something
7+
"""
8+
9+
import W
10+
import PyEdit
11+
import TextEdit
12+
import Qd
13+
import string
14+
import types
15+
import sys
16+
import MacOS
17+
if hasattr(MacOS, "SysBeep"):
18+
SysBeep = MacOS.SysBeep
19+
else:
20+
def SysBeep(*args):
21+
pass
22+
23+
_stylenames = ["Plain", "Bold", "Italic", "Underline", "Outline", "Shadow", "Condensed", "Extended"]
24+
25+
26+
class _FontDialog:
27+
28+
#def __del__(self):
29+
# print "doei!"
30+
31+
def __init__(self, fontsettings, tabsettings):
32+
leftmargin = 60
33+
leftmargin2 = leftmargin - 16
34+
self.w = W.ModalDialog((440, 180), 'Font settings')
35+
self.w.fonttitle = W.TextBox((10, 12, leftmargin2, 14), "Font:", TextEdit.teJustRight)
36+
self.w.pop = W.FontMenu((leftmargin, 10, 16, 16), self.setfont)
37+
self.w.fontname = W.TextBox((leftmargin + 20, 12, 150, 14))
38+
self.w.sizetitle = W.TextBox((10, 38, leftmargin2, 14), "Size:", TextEdit.teJustRight)
39+
self.w.sizeedit = W.EditText((leftmargin, 35, 40, 20), "", self.checksize)
40+
styletop = 64
41+
self.w.styletitle = W.TextBox((10, styletop + 2, leftmargin2, 14), "Style:", TextEdit.teJustRight)
42+
for i in range(len(_stylenames)):
43+
top = styletop + (i % 4) * 20
44+
left = leftmargin + 80 * (i > 3) - 2
45+
if i:
46+
self.w[i] = W.CheckBox((left, top, 76, 16), _stylenames[i], self.dostyle)
47+
else:
48+
self.w[i] = W.CheckBox((left, top, 70, 16), _stylenames[i], self.doplain)
49+
50+
if tabsettings:
51+
self.lasttab, self.tabmode = tabsettings
52+
self.w.tabsizetitle = W.TextBox((10, -26, leftmargin2, 14), "Tabsize:", TextEdit.teJustRight)
53+
self.w.tabsizeedit = W.EditText((leftmargin, -29, 40, 20), "", self.checktab)
54+
self.w.tabsizeedit.set(`self.lasttab`)
55+
radiobuttons = []
56+
self.w.tabsizechars = W.RadioButton((leftmargin + 48, -26, 55, 14), "Spaces",
57+
radiobuttons, self.toggletabmode)
58+
self.w.tabsizepixels = W.RadioButton((leftmargin + 110, -26, 55, 14), "Pixels",
59+
radiobuttons, self.toggletabmode)
60+
if self.tabmode:
61+
self.w.tabsizechars.set(1)
62+
else:
63+
self.w.tabsizepixels.set(1)
64+
else:
65+
self.tabmode = None
66+
67+
self.w.cancelbutton = W.Button((-180, -26, 80, 16), "Cancel", self.cancel)
68+
self.w.donebutton = W.Button((-90, -26, 80, 16), "Done", self.done)
69+
70+
sampletext = "Sample text."
71+
self.w.sample = W.EditText((230, 10, -10, 130), sampletext,
72+
fontsettings = fontsettings, tabsettings = tabsettings)
73+
74+
self.w.setdefaultbutton(self.w.donebutton)
75+
self.w.bind('cmd.', self.w.cancelbutton.push)
76+
self.w.bind('cmdw', self.w.donebutton.push)
77+
self.lastsize = fontsettings[2]
78+
self._rv = None
79+
self.set(fontsettings)
80+
self.w.open()
81+
82+
def toggletabmode(self, onoff):
83+
if self.w.tabsizechars.get():
84+
tabmode = 1
85+
else:
86+
tabmode = 0
87+
if self.tabmode <> tabmode:
88+
port = self.w.wid.GetWindowPort()
89+
(font, style, size, color), (tabsize, dummy) = self.get()
90+
savesettings = W.GetPortFontSettings(port)
91+
W.SetPortFontSettings(port, (font, style, size))
92+
spacewidth = Qd.StringWidth(' ')
93+
W.SetPortFontSettings(port, savesettings)
94+
if tabmode:
95+
# convert pixels to spaces
96+
self.lasttab = int(round(float(tabsize) / spacewidth))
97+
else:
98+
# convert spaces to pixels
99+
self.lasttab = spacewidth * tabsize
100+
self.w.tabsizeedit.set(`self.lasttab`)
101+
self.tabmode = tabmode
102+
self.doit()
103+
104+
def set(self, fontsettings):
105+
font, style, size, color = fontsettings
106+
if type(font) <> types.StringType:
107+
import Res
108+
res = Res.GetResource('FOND', font)
109+
font = res.GetResInfo()[2]
110+
self.w.fontname.set(font)
111+
self.w.sizeedit.set(str(size))
112+
if style:
113+
for i in range(1, len(_stylenames)):
114+
self.w[i].set(style & 0x01)
115+
style = style >> 1
116+
else:
117+
self.w[0].set(1)
118+
119+
def get(self):
120+
font = self.w.fontname.get()
121+
style = 0
122+
if not self.w[0].get():
123+
flag = 0x01
124+
for i in range(1, len(_stylenames)):
125+
if self.w[i].get():
126+
style = style | flag
127+
flag = flag << 1
128+
size = self.lastsize
129+
if self.tabmode is None:
130+
return (font, style, size, (0, 0, 0)), (32, 0)
131+
else:
132+
return (font, style, size, (0, 0, 0)), (self.lasttab, self.tabmode)
133+
134+
def doit(self):
135+
if self.w[0].get():
136+
style = 0
137+
else:
138+
style = 0
139+
for i in range(1, len(_stylenames)):
140+
if self.w[i].get():
141+
style = style | 2 ** (i - 1)
142+
#self.w.sample.set(`style`)
143+
fontsettings, tabsettings = self.get()
144+
self.w.sample.setfontsettings(fontsettings)
145+
self.w.sample.settabsettings(tabsettings)
146+
147+
def checktab(self):
148+
tabsize = self.w.tabsizeedit.get()
149+
if not tabsize:
150+
return
151+
try:
152+
tabsize = string.atoi(tabsize)
153+
except (ValueError, OverflowError):
154+
good = 0
155+
sys.exc_traceback = None
156+
else:
157+
good = 1 <= tabsize <= 500
158+
if good:
159+
if self.lasttab <> tabsize:
160+
self.lasttab = tabsize
161+
self.doit()
162+
else:
163+
SysBeep(0)
164+
self.w.tabsizeedit.set(`self.lasttab`)
165+
self.w.tabsizeedit.selectall()
166+
167+
def checksize(self):
168+
size = self.w.sizeedit.get()
169+
if not size:
170+
return
171+
try:
172+
size = string.atoi(size)
173+
except (ValueError, OverflowError):
174+
good = 0
175+
sys.exc_traceback = None
176+
else:
177+
good = 1 <= size <= 500
178+
if good:
179+
if self.lastsize <> size:
180+
self.lastsize = size
181+
self.doit()
182+
else:
183+
SysBeep(0)
184+
self.w.sizeedit.set(`self.lastsize`)
185+
self.w.sizeedit.selectall()
186+
187+
def doplain(self):
188+
for i in range(1, len(_stylenames)):
189+
self.w[i].set(0)
190+
self.w[0].set(1)
191+
self.doit()
192+
193+
def dostyle(self):
194+
for i in range(1, len(_stylenames)):
195+
if self.w[i].get():
196+
self.w[0].set(0)
197+
break
198+
else:
199+
self.w[0].set(1)
200+
self.doit()
201+
202+
def close(self):
203+
self.w.close()
204+
del self.w
205+
206+
def cancel(self):
207+
self.close()
208+
209+
def done(self):
210+
self._rv = self.get()
211+
self.close()
212+
213+
def setfont(self, fontname):
214+
self.w.fontname.set(fontname)
215+
self.doit()
216+
217+
218+
def FontDialog(fontsettings, tabsettings = (32, 0)):
219+
fd = _FontDialog(fontsettings, tabsettings)
220+
return fd._rv
221+
222+
def test():
223+
print FontDialog(('Zapata-Light', 0, 25, (0, 0, 0)))

Mac/Tools/IDE/MacPrefs.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import macfs
2+
import marshal
3+
import types
4+
5+
kOnSystemDisk = 0x8000
6+
7+
8+
class PrefObject:
9+
10+
def __init__(self, dict = None):
11+
if dict == None:
12+
self._prefsdict = {}
13+
else:
14+
self._prefsdict = dict
15+
16+
def __len__(self):
17+
return len(self._prefsdict)
18+
19+
def __delattr__(self, attr):
20+
if self._prefsdict.has_key(attr):
21+
del self._prefsdict[attr]
22+
else:
23+
raise AttributeError, 'delete non-existing instance attribute'
24+
25+
def __getattr__(self, attr):
26+
if attr == '__members__':
27+
keys = self._prefsdict.keys()
28+
keys.sort()
29+
return keys
30+
try:
31+
return self._prefsdict[attr]
32+
except KeyError:
33+
raise AttributeError, attr
34+
35+
def __setattr__(self, attr, value):
36+
if attr[0] <> '_':
37+
self._prefsdict[attr] = value
38+
else:
39+
self.__dict__[attr] = value
40+
41+
def getprefsdict(self):
42+
return self._prefsdict
43+
44+
45+
class PrefFile(PrefObject):
46+
47+
def __init__(self, path, creator = 'Pyth'):
48+
# Find the preferences folder and our prefs file, create if needed.
49+
self.__path = path
50+
self.__creator = creator
51+
self._prefsdict = {}
52+
try:
53+
prefdict = marshal.load(open(self.__path, 'rb'))
54+
except IOError:
55+
pass
56+
else:
57+
for key, value in prefdict.items():
58+
if type(value) == types.DictType:
59+
self._prefsdict[key] = PrefObject(value)
60+
else:
61+
self._prefsdict[key] = value
62+
63+
def save(self):
64+
prefdict = {}
65+
for key, value in self._prefsdict.items():
66+
if type(value) == types.InstanceType:
67+
prefdict[key] = value.getprefsdict()
68+
if not prefdict[key]:
69+
del prefdict[key]
70+
else:
71+
prefdict[key] = value
72+
marshal.dump(prefdict, open(self.__path, 'wb'))
73+
fss = macfs.FSSpec(self.__path)
74+
fss.SetCreatorType(self.__creator, 'pref')
75+
76+
def __getattr__(self, attr):
77+
if attr == '__members__':
78+
keys = self._prefsdict.keys()
79+
keys.sort()
80+
return keys
81+
try:
82+
return self._prefsdict[attr]
83+
except KeyError:
84+
if attr[0] <> '_':
85+
self._prefsdict[attr] = PrefObject()
86+
return self._prefsdict[attr]
87+
else:
88+
raise AttributeError, attr
89+
90+
91+
_prefscache = {}
92+
93+
def GetPrefs(prefname, creator = 'Pyth'):
94+
import macostools, os
95+
if _prefscache.has_key(prefname):
96+
return _prefscache[prefname]
97+
# Find the preferences folder and our prefs file, create if needed.
98+
vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0)
99+
prefsfolder_fss = macfs.FSSpec((vrefnum, dirid, ''))
100+
prefsfolder = prefsfolder_fss.as_pathname()
101+
path = os.path.join(prefsfolder, prefname)
102+
head, tail = os.path.split(path)
103+
# make sure the folder(s) exist
104+
macostools.mkdirs(head)
105+
106+
preffile = PrefFile(path, creator)
107+
_prefscache[prefname] = preffile
108+
return preffile

0 commit comments

Comments
 (0)