annotate Tools/modulator/modulator.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents c3a096bfbd6b
children c94f37054f19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 3443
diff changeset
1 #! /usr/bin/env python
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Modulator - Generate skeleton modules.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # The user fills out some forms with information about what the module
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # should support (methods, objects), names of these things, prefixes to
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # use for C code, whether the objects should also support access as numbers,
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # etc etc etc.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # When the user presses 'Generate code' we generate a complete skeleton
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 # module in C.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 # Alternatively, the selections made can be save to a python sourcefile and
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # this sourcefile can be passed on the command line (resulting in the same
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 # skeleton C code).
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 # Jack Jansen, CWI, October 1994.
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 import sys, os
3443
1ff12804ff2a A few missing casts (Richard Neitzel).
Guido van Rossum <guido@python.org>
parents: 3232
diff changeset
20 if os.name <> 'mac':
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
21 sys.path.append(os.path.join(os.environ['HOME'],
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
22 'src/python/Tools/modulator'))
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 from Tkinter import *
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 from Tkextra import *
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 from ScrolledListbox import ScrolledListbox
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 import sys
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 import genmodule
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 import string
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 oops = 'oops'
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
21561
847425d5bca8 Patches by Jens B. Jorgensen with small mods by me:
Jack Jansen <jack.jansen@cwi.nl>
parents: 18779
diff changeset
33 IDENTSTARTCHARS = string.letters + '_'
847425d5bca8 Patches by Jens B. Jorgensen with small mods by me:
Jack Jansen <jack.jansen@cwi.nl>
parents: 18779
diff changeset
34 IDENTCHARS = string.letters + string.digits + '_'
18779
44155121f02b Use string.ascii_letters instead of string.letters (SF bug #226706).
Fred Drake <fdrake@acm.org>
parents: 10224
diff changeset
35
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 # Check that string is a legal C identifier
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 def checkid(str):
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 if not str: return 0
18779
44155121f02b Use string.ascii_letters instead of string.letters (SF bug #226706).
Fred Drake <fdrake@acm.org>
parents: 10224
diff changeset
39 if not str[0] in IDENTSTARTCHARS:
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
40 return 0
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 for c in str[1:]:
18779
44155121f02b Use string.ascii_letters instead of string.letters (SF bug #226706).
Fred Drake <fdrake@acm.org>
parents: 10224
diff changeset
42 if not c in IDENTCHARS:
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
43 return 0
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 return 1
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 def getlistlist(list):
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 rv = []
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 n = list.size()
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 for i in range(n):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
50 rv.append(list.get(i))
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 return rv
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
52
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 class UI:
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 def __init__(self):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
55 self.main = Frame()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
56 self.main.pack()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
57 self.main.master.title('Modulator: Module view')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
58 self.cmdframe = Frame(self.main, {'relief':'raised', 'bd':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
59 Pack:{'side':'top',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
60 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
61 self.objframe = Frame(self.main, {Pack:{'side':'top', 'fill':'x',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
62 'expand':1}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
65 self.check_button = Button(self.cmdframe,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
66 {'text':'Check', 'command':self.cb_check,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
67 Pack:{'side':'left', 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
68 self.save_button = Button(self.cmdframe,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
69 {'text':'Save...', 'command':self.cb_save,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
70 Pack:{'side':'left', 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
71 self.code_button = Button(self.cmdframe,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
72 {'text':'Generate code...',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
73 'command':self.cb_gencode,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
74 Pack:{'side':'left', 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
75 self.quit_button = Button(self.cmdframe,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
76 {'text':'Quit',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
77 'command':self.cb_quit,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
78 Pack:{'side':'right', 'padx':'0.5m'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
80 self.module = UI_module(self)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
81 self.objects = []
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
82 self.modified = 0
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 def run(self):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
85 self.main.mainloop()
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 def cb_quit(self, *args):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
88 if self.modified:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
89 if not askyn('You have not saved\nAre you sure you want to quit?'):
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
90 return
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
91 sys.exit(0)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 def cb_check(self, *args):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
94 try:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
95 self.module.synchronize()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
96 for o in self.objects:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
97 o.synchronize()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
98 except oops:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
99 pass
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
100
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 def cb_save(self, *args):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
102 try:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
103 pycode = self.module.gencode('m', self.objects)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
104 except oops:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
105 return
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
107 fn = askfile('Python file name: ')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
108 if not fn:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
109 return
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
110
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
111 fp = open(fn, 'w')
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
113 fp.write(pycode)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
114 fp.close()
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 def cb_gencode(self, *args):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
117 try:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
118 pycode = self.module.gencode('m', self.objects)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
119 except oops:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
120 pass
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
122 fn = askfile('C file name: ')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
123 if not fn:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
124 return
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
126 fp = open(fn, 'w')
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
128 try:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
129 exec pycode
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
130 except:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
131 message('An error occurred:-)')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
132 return
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
133 genmodule.write(fp, m)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
134 fp.close()
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 class UI_module:
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 def __init__(self, parent):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
138 self.parent = parent
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
139 self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
140 Pack:{'side':'top',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
141 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
142 self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
143 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
144 self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
145 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
146 self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
147 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
148 self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
149 'fill':'x'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
151 self.l1 = Label(self.f1, {'text':'Module:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
152 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
153 self.name_entry = Entry(self.f1, {'relief':'sunken',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
154 Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
155 self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
156 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
157 self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
158 Pack:{'side':'left', 'padx':'0.5m'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
159
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
160 self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
161 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
162 self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
163 Pack:{'side':'left', 'expand':1,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
164 'padx':'0.5m', 'fill':'both'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
165
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
166 self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
167 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
168 self.method_entry = Entry(self.f3, {'relief':'sunken',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
169 Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
170 self.method_entry.bind('<Return>', self.cb_method)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
171 self.delete_button = Button(self.f3, {'text':'Delete method',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
172 'command':self.cb_delmethod,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
173 Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
174 'padx':'0.5m'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
176 self.newobj_button = Button(self.f4, {'text':'new object',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
177 'command':self.cb_newobj,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
178 Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
179 'padx':'0.5m'}})
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
180
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 def cb_delmethod(self, *args):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
182 list = self.method_list.curselection()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
183 for i in list:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
184 self.method_list.delete(i)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
185
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 def cb_newobj(self, *arg):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
187 self.parent.objects.append(UI_object(self.parent))
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
188
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 def cb_method(self, *arg):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
190 name = self.method_entry.get()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
191 if not name:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
192 return
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
193 self.method_entry.delete('0', 'end')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
194 self.method_list.insert('end', name)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
195
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 def synchronize(self):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
197 n = self.name_entry.get()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
198 if not n:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
199 message('Module name not set')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
200 raise oops
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
201 if not checkid(n):
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
202 message('Module name not an identifier:\n'+n)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
203 raise oops
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
204 if not self.abbrev_entry.get():
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
205 self.abbrev_entry.insert('end', n)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
206 m = getlistlist(self.method_list)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
207 for n in m:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
208 if not checkid(n):
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
209 message('Method name not an identifier:\n'+n)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
210 raise oops
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
211
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 def gencode(self, name, objects):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
213 rv = ''
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
214 self.synchronize()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
215 for o in objects:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
216 o.synchronize()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
217 onames = []
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
218 for i in range(len(objects)):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
219 oname = 'o%d' % (i+1)
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
220 rv = rv + objects[i].gencode(oname)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
221 onames.append(oname)
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
222 rv = rv + '%s = genmodule.module()\n' % (name,)
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
223 rv = rv + '%s.name = %r\n' % (name, self.name_entry.get())
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
224 rv = rv + '%s.abbrev = %r\n' % (name, self.abbrev_entry.get())
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
225 rv = rv + '%s.methodlist = %r\n' % (name, getlistlist(self.method_list))
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
226 rv = rv + '%s.objects = [%s]\n' % (name, ','.join(onames))
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
227 rv = rv + '\n'
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
228 return rv
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
229
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 object_number = 0
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 class UI_object:
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 def __init__(self, parent):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
234 global object_number
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
236 object_number = object_number + 1
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
237 self.num = object_number
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
238 self.vpref = 'o%r_' % self.num
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
239 self.frame = Toplevel(parent.objframe)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
240 # self.frame.pack()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
241 self.frame.title('Modulator: object view')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
242 # self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
243 # Pack:{'side':'top',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
244 # 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
245 self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
246 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
247 self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
248 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
249 self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
250 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
251 self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
252 'fill':'x'}})
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
253
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
254
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
255 self.l1 = Label(self.f1, {'text':'Object:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
256 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
257 self.name_entry = Entry(self.f1, {'relief':'sunken',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
258 Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
259 self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
260 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
261 self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
262 Pack:{'side':'left', 'padx':'0.5m'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
263
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
264 self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
265 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
266 self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
267 Pack:{'side':'left', 'expand':1,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
268 'padx':'0.5m', 'fill':'both'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
269
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
270 self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
271 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
272 self.method_entry = Entry(self.f3, {'relief':'sunken',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
273 Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
274 self.method_entry.bind('<Return>', self.cb_method)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
275 self.delete_button = Button(self.f3, {'text':'Delete method',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
276 'command':self.cb_delmethod,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
277 Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
278 'padx':'0.5m'}})
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
280
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
281 self.l5 = Label(self.f4, {'text':'functions:',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
282 Pack:{'side':'left',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
283 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
284 self.f5 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
285 'fill':'both'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
286 self.l6 = Label(self.f4, {'text':'Types:',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
287 Pack:{'side':'left', 'padx':'0.5m'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
288 self.f6 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
289 'fill':'x'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
290 self.funcs = {}
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
291 for i in genmodule.FUNCLIST:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
292 vname = self.vpref+i
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
293 self.f5.setvar(vname, 0)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
294 b = Checkbutton(self.f5, {'variable':vname, 'text':i,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
295 Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
296 'anchor':'w','expand':1}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
297 self.funcs[i] = b
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
298 self.f5.setvar(self.vpref+'new', 1)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
299
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
300 self.types = {}
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
301 for i in genmodule.TYPELIST:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
302 vname = self.vpref + i
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
303 self.f6.setvar(vname, 0)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
304 b = Checkbutton(self.f6, {'variable':vname, 'text':i,
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
305 Pack:{'side':'top', 'pady':'0.5m',
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
306 'anchor':'w'}})
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
307 self.types[i] = b
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
308
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 def cb_method(self, *arg):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
310 name = self.method_entry.get()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
311 if not name:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
312 return
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
313 self.method_entry.delete('0', 'end')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
314 self.method_list.insert('end', name)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
315
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 def cb_delmethod(self, *args):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
317 list = self.method_list.curselection()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
318 for i in list:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
319 self.method_list.delete(i)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
320
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 def synchronize(self):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
322 n = self.name_entry.get()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
323 if not n:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
324 message('Object name not set')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
325 raise oops
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
326 if not self.abbrev_entry.get():
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
327 self.abbrev_entry.insert('end', n)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
328 n = self.abbrev_entry.get()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
329 if not checkid(n):
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
330 message('Abbreviation not an identifier:\n'+n)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
331 raise oops
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
332 m = getlistlist(self.method_list)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
333 for n in m:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
334 if not checkid(n):
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
335 message('Method name not an identifier:\n'+n)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
336 raise oops
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
337 if m:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
338 self.f5.setvar(self.vpref+'tp_getattr', 1)
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
339 pass
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
340
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 def gencode(self, name):
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
342 rv = ''
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
343 rv = rv + '%s = genmodule.object()\n' % (name,)
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
344 rv = rv + '%s.name = %r\n' % (name, self.name_entry.get())
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
345 rv = rv + '%s.abbrev = %r\n' % (name, self.abbrev_entry.get())
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
346 rv = rv + '%s.methodlist = %r\n' % (name, getlistlist(self.method_list))
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
347 fl = []
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
348 for fn in genmodule.FUNCLIST:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
349 vname = self.vpref + fn
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
350 if self.f5.getvar(vname) == '1':
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
351 fl.append(fn)
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
352 rv = rv + '%s.funclist = %r\n' % (name, fl)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
353
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
354 fl = []
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
355 for fn in genmodule.TYPELIST:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
356 vname = self.vpref + fn
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
357 if self.f5.getvar(vname) == '1':
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
358 fl.append(fn)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
359
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
360 rv = rv + '%s.typelist = %r\n' % (name, fl)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
361
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
362 rv = rv + '\n'
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
363 return rv
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
364
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
365
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 def main():
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 if len(sys.argv) < 2:
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
368 ui = UI()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
369 ui.run()
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 elif len(sys.argv) == 2:
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
371 fp = open(sys.argv[1])
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
372 pycode = fp.read()
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
373 try:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
374 exec pycode
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
375 except:
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
376 sys.stderr.write('An error occurred:-)\n')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
377 sys.exit(1)
10224
df4a967a8146 Comment out confusing write call.
Guido van Rossum <guido@python.org>
parents: 7958
diff changeset
378 ##genmodule.write(sys.stdout, m)
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 else:
7958
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
380 sys.stderr.write('Usage: modulator [file]\n')
9e113aa3758d tabnanny stuff
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
381 sys.exit(1)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 31515
diff changeset
382
2466
322fc596f1c4 checkin of Jack's original version
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 main()