mirror of https://github.com/python/cpython.git
tabnanny stuff
This commit is contained in:
parent
ce73acf5e6
commit
a16a509dfc
|
@ -18,54 +18,54 @@ def dialog(master, title, text, bitmap, default, *args):
|
|||
w.iconname('Dialog')
|
||||
|
||||
top = Frame(w, {'relief': 'raised', 'bd': 1,
|
||||
Pack: {'side': 'top', 'fill': 'both'}})
|
||||
Pack: {'side': 'top', 'fill': 'both'}})
|
||||
bot = Frame(w, {'relief': 'raised', 'bd': 1,
|
||||
Pack: {'side': 'bottom', 'fill': 'both'}})
|
||||
Pack: {'side': 'bottom', 'fill': 'both'}})
|
||||
|
||||
# 2. Fill the top part with the bitmap and message.
|
||||
|
||||
msg = Message(top,
|
||||
{'width': '3i',
|
||||
'text': text,
|
||||
'font': '-Adobe-Times-Medium-R-Normal-*-180-*',
|
||||
Pack: {'side': 'right', 'expand': 1,
|
||||
'fill': 'both',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
{'width': '3i',
|
||||
'text': text,
|
||||
'font': '-Adobe-Times-Medium-R-Normal-*-180-*',
|
||||
Pack: {'side': 'right', 'expand': 1,
|
||||
'fill': 'both',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
if bitmap:
|
||||
bm = Label(top, {'bitmap': bitmap,
|
||||
Pack: {'side': 'left',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
bm = Label(top, {'bitmap': bitmap,
|
||||
Pack: {'side': 'left',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
|
||||
# 3. Create a row of buttons at the bottom of the dialog.
|
||||
|
||||
buttons = []
|
||||
i = 0
|
||||
for but in args:
|
||||
b = Button(bot, {'text': but,
|
||||
'command': ('set', 'button', i)})
|
||||
buttons.append(b)
|
||||
if i == default:
|
||||
bd = Frame(bot, {'relief': 'sunken', 'bd': 1,
|
||||
Pack: {'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '2m'}})
|
||||
b.lift()
|
||||
b.pack ({'in': bd, 'side': 'left',
|
||||
'padx': '2m', 'pady': '2m',
|
||||
'ipadx': '2m', 'ipady': '1m'})
|
||||
else:
|
||||
b.pack ({'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '3m',
|
||||
'ipady': '2m', 'ipady': '1m'})
|
||||
i = i+1
|
||||
b = Button(bot, {'text': but,
|
||||
'command': ('set', 'button', i)})
|
||||
buttons.append(b)
|
||||
if i == default:
|
||||
bd = Frame(bot, {'relief': 'sunken', 'bd': 1,
|
||||
Pack: {'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '2m'}})
|
||||
b.lift()
|
||||
b.pack ({'in': bd, 'side': 'left',
|
||||
'padx': '2m', 'pady': '2m',
|
||||
'ipadx': '2m', 'ipady': '1m'})
|
||||
else:
|
||||
b.pack ({'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '3m',
|
||||
'ipady': '2m', 'ipady': '1m'})
|
||||
i = i+1
|
||||
|
||||
# 4. Set up a binding for <Return>, if there's a default,
|
||||
# set a grab, and claim the focus too.
|
||||
|
||||
if default >= 0:
|
||||
w.bind('<Return>',
|
||||
lambda e, b=buttons[default], i=default:
|
||||
(b.flash(),
|
||||
b.setvar('button', i)))
|
||||
w.bind('<Return>',
|
||||
lambda e, b=buttons[default], i=default:
|
||||
(b.flash(),
|
||||
b.setvar('button', i)))
|
||||
|
||||
oldFocus = w.tk.call('focus') # XXX
|
||||
w.grab_set()
|
||||
|
@ -89,69 +89,69 @@ def strdialog(master, title, text, bitmap, default, *args):
|
|||
w.iconname('Dialog')
|
||||
|
||||
top = Frame(w, {'relief': 'raised', 'bd': 1,
|
||||
Pack: {'side': 'top', 'fill': 'both'}})
|
||||
Pack: {'side': 'top', 'fill': 'both'}})
|
||||
if args:
|
||||
bot = Frame(w, {'relief': 'raised', 'bd': 1,
|
||||
Pack: {'side': 'bottom', 'fill': 'both'}})
|
||||
bot = Frame(w, {'relief': 'raised', 'bd': 1,
|
||||
Pack: {'side': 'bottom', 'fill': 'both'}})
|
||||
|
||||
# 2. Fill the top part with the bitmap, message and input field.
|
||||
|
||||
if bitmap:
|
||||
bm = Label(top, {'bitmap': bitmap,
|
||||
Pack: {'side': 'left',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
bm = Label(top, {'bitmap': bitmap,
|
||||
Pack: {'side': 'left',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
|
||||
msg = Message(top,
|
||||
{'width': '3i',
|
||||
'text': text,
|
||||
'font': '-Adobe-Times-Medium-R-Normal-*-180-*',
|
||||
Pack: {'side': 'left',
|
||||
'fill': 'both',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
{'width': '3i',
|
||||
'text': text,
|
||||
'font': '-Adobe-Times-Medium-R-Normal-*-180-*',
|
||||
Pack: {'side': 'left',
|
||||
'fill': 'both',
|
||||
'padx': '3m', 'pady': '3m'}})
|
||||
|
||||
field = Entry(top,
|
||||
{'relief':'sunken',
|
||||
Pack:{'side':'left',
|
||||
'fill':'x',
|
||||
'expand':1,
|
||||
'padx':'3m', 'pady':'3m'}})
|
||||
{'relief':'sunken',
|
||||
Pack:{'side':'left',
|
||||
'fill':'x',
|
||||
'expand':1,
|
||||
'padx':'3m', 'pady':'3m'}})
|
||||
# 3. Create a row of buttons at the bottom of the dialog.
|
||||
|
||||
buttons = []
|
||||
i = 0
|
||||
for but in args:
|
||||
b = Button(bot, {'text': but,
|
||||
'command': ('set', 'button', i)})
|
||||
buttons.append(b)
|
||||
if i == default:
|
||||
bd = Frame(bot, {'relief': 'sunken', 'bd': 1,
|
||||
Pack: {'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '2m'}})
|
||||
b.lift()
|
||||
b.pack ({'in': bd, 'side': 'left',
|
||||
'padx': '2m', 'pady': '2m',
|
||||
'ipadx': '2m', 'ipady': '1m'})
|
||||
else:
|
||||
b.pack ({'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '3m',
|
||||
'ipady': '2m', 'ipady': '1m'})
|
||||
i = i+1
|
||||
b = Button(bot, {'text': but,
|
||||
'command': ('set', 'button', i)})
|
||||
buttons.append(b)
|
||||
if i == default:
|
||||
bd = Frame(bot, {'relief': 'sunken', 'bd': 1,
|
||||
Pack: {'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '2m'}})
|
||||
b.lift()
|
||||
b.pack ({'in': bd, 'side': 'left',
|
||||
'padx': '2m', 'pady': '2m',
|
||||
'ipadx': '2m', 'ipady': '1m'})
|
||||
else:
|
||||
b.pack ({'side': 'left', 'expand': 1,
|
||||
'padx': '3m', 'pady': '3m',
|
||||
'ipady': '2m', 'ipady': '1m'})
|
||||
i = i+1
|
||||
|
||||
# 4. Set up a binding for <Return>, if there's a default,
|
||||
# set a grab, and claim the focus too.
|
||||
|
||||
if not args:
|
||||
w.bind('<Return>', lambda arg, top=top: top.setvar('button', 0))
|
||||
field.bind('<Return>', lambda arg, top=top: top.setvar('button', 0))
|
||||
w.bind('<Return>', lambda arg, top=top: top.setvar('button', 0))
|
||||
field.bind('<Return>', lambda arg, top=top: top.setvar('button', 0))
|
||||
elif default >= 0:
|
||||
w.bind('<Return>',
|
||||
lambda e, b=buttons[default], i=default:
|
||||
(b.flash(),
|
||||
b.setvar('button', i)))
|
||||
field.bind('<Return>',
|
||||
lambda e, b=buttons[default], i=default:
|
||||
(b.flash(),
|
||||
b.setvar('button', i)))
|
||||
w.bind('<Return>',
|
||||
lambda e, b=buttons[default], i=default:
|
||||
(b.flash(),
|
||||
b.setvar('button', i)))
|
||||
field.bind('<Return>',
|
||||
lambda e, b=buttons[default], i=default:
|
||||
(b.flash(),
|
||||
b.setvar('button', i)))
|
||||
|
||||
oldFocus = w.tk.call('focus') # XXX
|
||||
w.grab_set()
|
||||
|
@ -165,9 +165,9 @@ def strdialog(master, title, text, bitmap, default, *args):
|
|||
w.destroy()
|
||||
w.tk.call('focus', oldFocus) # XXX
|
||||
if args:
|
||||
return v, w.getint(w.getvar('button'))
|
||||
return v, w.getint(w.getvar('button'))
|
||||
else:
|
||||
return v
|
||||
return v
|
||||
|
||||
def message(str):
|
||||
i = dialog(mainWidget, 'Message', str, '', 0, 'OK')
|
||||
|
@ -184,7 +184,7 @@ def askstr(str):
|
|||
i = strdialog(mainWidget, 'Question', str, '', 0)
|
||||
return i
|
||||
|
||||
def askfile(str): # XXXX For now...
|
||||
def askfile(str): # XXXX For now...
|
||||
i = strdialog(mainWidget, 'Question', str, '', 0)
|
||||
return i
|
||||
|
||||
|
@ -192,30 +192,30 @@ def askfile(str): # XXXX For now...
|
|||
|
||||
def _go():
|
||||
i = dialog(mainWidget,
|
||||
'Not Responding',
|
||||
"The file server isn't responding right now; "
|
||||
"I'll keep trying.",
|
||||
'',
|
||||
-1,
|
||||
'OK')
|
||||
'Not Responding',
|
||||
"The file server isn't responding right now; "
|
||||
"I'll keep trying.",
|
||||
'',
|
||||
-1,
|
||||
'OK')
|
||||
print 'pressed button', i
|
||||
i = dialog(mainWidget,
|
||||
'File Modified',
|
||||
'File "tcl.h" has been modified since '
|
||||
'the last time it was saved. '
|
||||
'Do you want to save it before exiting the application?',
|
||||
'warning',
|
||||
0,
|
||||
'Save File',
|
||||
'Discard Changes',
|
||||
'Return To Editor')
|
||||
'File Modified',
|
||||
'File "tcl.h" has been modified since '
|
||||
'the last time it was saved. '
|
||||
'Do you want to save it before exiting the application?',
|
||||
'warning',
|
||||
0,
|
||||
'Save File',
|
||||
'Discard Changes',
|
||||
'Return To Editor')
|
||||
print 'pressed button', i
|
||||
print message('Test of message')
|
||||
print askyn('Test of yes/no')
|
||||
print askync('Test of yes/no/cancel')
|
||||
print askstr('Type a string:')
|
||||
print strdialog(mainWidget, 'Question', 'Another string:', '',
|
||||
0, 'Save', 'Save as text')
|
||||
0, 'Save', 'Save as text')
|
||||
|
||||
def _test():
|
||||
import sys
|
||||
|
@ -223,12 +223,12 @@ def _test():
|
|||
mainWidget = Frame()
|
||||
Pack.config(mainWidget)
|
||||
start = Button(mainWidget,
|
||||
{'text': 'Press Here To Start', 'command': _go})
|
||||
{'text': 'Press Here To Start', 'command': _go})
|
||||
start.pack()
|
||||
endit = Button(mainWidget,
|
||||
{'text': 'Exit',
|
||||
'command': 'exit',
|
||||
Pack: {'fill' : 'both'}})
|
||||
{'text': 'Exit',
|
||||
'command': 'exit',
|
||||
Pack: {'fill' : 'both'}})
|
||||
mainWidget.mainloop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
# Names of functions in the object-description struct.
|
||||
#
|
||||
FUNCLIST = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr',
|
||||
'tp_compare', 'tp_repr', 'tp_hash', 'tp_call', 'tp_str']
|
||||
'tp_compare', 'tp_repr', 'tp_hash', 'tp_call', 'tp_str']
|
||||
TYPELIST = ['tp_as_number', 'tp_as_sequence', 'tp_as_mapping', 'structure']
|
||||
|
||||
#
|
||||
|
@ -37,112 +37,112 @@
|
|||
#
|
||||
class writer:
|
||||
def __init__(self):
|
||||
self._subst = None
|
||||
self._subst = None
|
||||
|
||||
def makesubst(self):
|
||||
if not self._subst:
|
||||
if not self.__dict__.has_key('abbrev'):
|
||||
self.abbrev = self.name
|
||||
self.Abbrev = string.upper(self.abbrev[0])+self.abbrev[1:]
|
||||
subst = varsubst.Varsubst(self.__dict__)
|
||||
subst.useindent(1)
|
||||
self._subst = subst.subst
|
||||
if not self._subst:
|
||||
if not self.__dict__.has_key('abbrev'):
|
||||
self.abbrev = self.name
|
||||
self.Abbrev = string.upper(self.abbrev[0])+self.abbrev[1:]
|
||||
subst = varsubst.Varsubst(self.__dict__)
|
||||
subst.useindent(1)
|
||||
self._subst = subst.subst
|
||||
|
||||
def addcode(self, name, fp):
|
||||
ifp = self.opentemplate(name)
|
||||
self.makesubst()
|
||||
d = ifp.read()
|
||||
d = self._subst(d)
|
||||
fp.write(d)
|
||||
ifp = self.opentemplate(name)
|
||||
self.makesubst()
|
||||
d = ifp.read()
|
||||
d = self._subst(d)
|
||||
fp.write(d)
|
||||
|
||||
def opentemplate(self, name):
|
||||
for p in sys.path:
|
||||
fn = os.path.join(p, name)
|
||||
if os.path.exists(fn):
|
||||
return open(fn, 'r')
|
||||
fn = os.path.join(p, 'Templates')
|
||||
fn = os.path.join(fn, name)
|
||||
if os.path.exists(fn):
|
||||
return open(fn, 'r')
|
||||
raise error, 'Template '+name+' not found for '+self._type+' '+ \
|
||||
self.name
|
||||
|
||||
for p in sys.path:
|
||||
fn = os.path.join(p, name)
|
||||
if os.path.exists(fn):
|
||||
return open(fn, 'r')
|
||||
fn = os.path.join(p, 'Templates')
|
||||
fn = os.path.join(fn, name)
|
||||
if os.path.exists(fn):
|
||||
return open(fn, 'r')
|
||||
raise error, 'Template '+name+' not found for '+self._type+' '+ \
|
||||
self.name
|
||||
|
||||
class module(writer):
|
||||
_type = 'module'
|
||||
|
||||
def writecode(self, fp):
|
||||
self.addcode('copyright', fp)
|
||||
self.addcode('module_head', fp)
|
||||
for o in self.objects:
|
||||
o.writehead(fp)
|
||||
for o in self.objects:
|
||||
o.writebody(fp)
|
||||
new_ml = ''
|
||||
for fn in self.methodlist:
|
||||
self.method = fn
|
||||
self.addcode('module_method', fp)
|
||||
new_ml = new_ml + (
|
||||
'{"%s",\t(PyCFunction)%s_%s,\tMETH_VARARGS,\t%s_%s__doc__},\n'
|
||||
%(fn, self.abbrev, fn, self.abbrev, fn))
|
||||
self.methodlist = new_ml
|
||||
self.addcode('module_tail', fp)
|
||||
self.addcode('copyright', fp)
|
||||
self.addcode('module_head', fp)
|
||||
for o in self.objects:
|
||||
o.writehead(fp)
|
||||
for o in self.objects:
|
||||
o.writebody(fp)
|
||||
new_ml = ''
|
||||
for fn in self.methodlist:
|
||||
self.method = fn
|
||||
self.addcode('module_method', fp)
|
||||
new_ml = new_ml + (
|
||||
'{"%s",\t(PyCFunction)%s_%s,\tMETH_VARARGS,\t%s_%s__doc__},\n'
|
||||
%(fn, self.abbrev, fn, self.abbrev, fn))
|
||||
self.methodlist = new_ml
|
||||
self.addcode('module_tail', fp)
|
||||
|
||||
class object(writer):
|
||||
_type = 'object'
|
||||
def __init__(self):
|
||||
self.typelist = []
|
||||
self.methodlist = []
|
||||
self.funclist = ['new']
|
||||
writer.__init__(self)
|
||||
self.typelist = []
|
||||
self.methodlist = []
|
||||
self.funclist = ['new']
|
||||
writer.__init__(self)
|
||||
|
||||
def writecode(self, fp):
|
||||
self.addcode('copyright', fp)
|
||||
self.writehead(fp)
|
||||
self.writebody(fp)
|
||||
self.addcode('copyright', fp)
|
||||
self.writehead(fp)
|
||||
self.writebody(fp)
|
||||
|
||||
def writehead(self, fp):
|
||||
self.addcode('object_head', fp)
|
||||
self.addcode('object_head', fp)
|
||||
|
||||
def writebody(self, fp):
|
||||
new_ml = ''
|
||||
for fn in self.methodlist:
|
||||
self.method = fn
|
||||
self.addcode('object_method', fp)
|
||||
new_ml = new_ml + (
|
||||
'{"%s",\t(PyCFunction)%s_%s,\tMETH_VARARGS,\t%s_%s__doc__},\n'
|
||||
%(fn, self.abbrev, fn, self.abbrev, fn))
|
||||
self.methodlist = new_ml
|
||||
self.addcode('object_mlist', fp)
|
||||
new_ml = ''
|
||||
for fn in self.methodlist:
|
||||
self.method = fn
|
||||
self.addcode('object_method', fp)
|
||||
new_ml = new_ml + (
|
||||
'{"%s",\t(PyCFunction)%s_%s,\tMETH_VARARGS,\t%s_%s__doc__},\n'
|
||||
%(fn, self.abbrev, fn, self.abbrev, fn))
|
||||
self.methodlist = new_ml
|
||||
self.addcode('object_mlist', fp)
|
||||
|
||||
# Add getattr if we have methods
|
||||
if self.methodlist and not 'tp_getattr' in self.funclist:
|
||||
self.funclist.insert(0, 'tp_getattr')
|
||||
|
||||
for fn in FUNCLIST:
|
||||
setattr(self, fn, '0')
|
||||
# Add getattr if we have methods
|
||||
if self.methodlist and not 'tp_getattr' in self.funclist:
|
||||
self.funclist.insert(0, 'tp_getattr')
|
||||
|
||||
for fn in FUNCLIST:
|
||||
setattr(self, fn, '0')
|
||||
|
||||
#
|
||||
# Special case for structure-access objects: put getattr in the
|
||||
# list of functions but don't generate code for it directly,
|
||||
# the code is obtained from the object_structure template.
|
||||
# The same goes for setattr.
|
||||
#
|
||||
if 'structure' in self.typelist:
|
||||
if 'tp_getattr' in self.funclist:
|
||||
self.funclist.remove('tp_getattr')
|
||||
if 'tp_setattr' in self.funclist:
|
||||
self.funclist.remove('tp_setattr')
|
||||
self.tp_getattr = self.abbrev + '_getattr'
|
||||
self.tp_setattr = self.abbrev + '_setattr'
|
||||
for fn in self.funclist:
|
||||
self.addcode('object_'+fn, fp)
|
||||
setattr(self, fn, '%s_%s'%(self.abbrev, fn[3:]))
|
||||
for tn in TYPELIST:
|
||||
setattr(self, tn, '0')
|
||||
for tn in self.typelist:
|
||||
self.addcode('object_'+tn, fp)
|
||||
setattr(self, tn, '&%s_%s'%(self.abbrev, tn[3:]))
|
||||
self.addcode('object_tail', fp)
|
||||
#
|
||||
# Special case for structure-access objects: put getattr in the
|
||||
# list of functions but don't generate code for it directly,
|
||||
# the code is obtained from the object_structure template.
|
||||
# The same goes for setattr.
|
||||
#
|
||||
if 'structure' in self.typelist:
|
||||
if 'tp_getattr' in self.funclist:
|
||||
self.funclist.remove('tp_getattr')
|
||||
if 'tp_setattr' in self.funclist:
|
||||
self.funclist.remove('tp_setattr')
|
||||
self.tp_getattr = self.abbrev + '_getattr'
|
||||
self.tp_setattr = self.abbrev + '_setattr'
|
||||
for fn in self.funclist:
|
||||
self.addcode('object_'+fn, fp)
|
||||
setattr(self, fn, '%s_%s'%(self.abbrev, fn[3:]))
|
||||
for tn in TYPELIST:
|
||||
setattr(self, tn, '0')
|
||||
for tn in self.typelist:
|
||||
self.addcode('object_'+tn, fp)
|
||||
setattr(self, tn, '&%s_%s'%(self.abbrev, tn[3:]))
|
||||
self.addcode('object_tail', fp)
|
||||
|
||||
def write(fp, obj):
|
||||
obj.writecode(fp)
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
import sys, os
|
||||
if os.name <> 'mac':
|
||||
sys.path.append(os.path.join(os.environ['HOME'], 'src/python/Tools/modulator'))
|
||||
sys.path.append(os.path.join(os.environ['HOME'],
|
||||
'src/python/Tools/modulator'))
|
||||
|
||||
from Tkinter import *
|
||||
from Tkextra import *
|
||||
|
@ -33,347 +34,347 @@
|
|||
def checkid(str):
|
||||
if not str: return 0
|
||||
if not str[0] in string.letters+'_':
|
||||
return 0
|
||||
return 0
|
||||
for c in str[1:]:
|
||||
if not c in string.letters+string.digits+'_':
|
||||
return 0
|
||||
if not c in string.letters+string.digits+'_':
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def getlistlist(list):
|
||||
rv = []
|
||||
n = list.size()
|
||||
for i in range(n):
|
||||
rv.append(list.get(i))
|
||||
rv.append(list.get(i))
|
||||
return rv
|
||||
|
||||
class UI:
|
||||
def __init__(self):
|
||||
self.main = Frame()
|
||||
self.main.pack()
|
||||
self.main.master.title('Modulator: Module view')
|
||||
self.cmdframe = Frame(self.main, {'relief':'raised', 'bd':'0.5m',
|
||||
Pack:{'side':'top',
|
||||
'fill':'x'}})
|
||||
self.objframe = Frame(self.main, {Pack:{'side':'top', 'fill':'x',
|
||||
'expand':1}})
|
||||
self.main = Frame()
|
||||
self.main.pack()
|
||||
self.main.master.title('Modulator: Module view')
|
||||
self.cmdframe = Frame(self.main, {'relief':'raised', 'bd':'0.5m',
|
||||
Pack:{'side':'top',
|
||||
'fill':'x'}})
|
||||
self.objframe = Frame(self.main, {Pack:{'side':'top', 'fill':'x',
|
||||
'expand':1}})
|
||||
|
||||
|
||||
self.check_button = Button(self.cmdframe,
|
||||
{'text':'Check', 'command':self.cb_check,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.save_button = Button(self.cmdframe,
|
||||
{'text':'Save...', 'command':self.cb_save,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.code_button = Button(self.cmdframe,
|
||||
{'text':'Generate code...',
|
||||
'command':self.cb_gencode,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.quit_button = Button(self.cmdframe,
|
||||
{'text':'Quit',
|
||||
'command':self.cb_quit,
|
||||
Pack:{'side':'right', 'padx':'0.5m'}})
|
||||
self.check_button = Button(self.cmdframe,
|
||||
{'text':'Check', 'command':self.cb_check,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.save_button = Button(self.cmdframe,
|
||||
{'text':'Save...', 'command':self.cb_save,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.code_button = Button(self.cmdframe,
|
||||
{'text':'Generate code...',
|
||||
'command':self.cb_gencode,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.quit_button = Button(self.cmdframe,
|
||||
{'text':'Quit',
|
||||
'command':self.cb_quit,
|
||||
Pack:{'side':'right', 'padx':'0.5m'}})
|
||||
|
||||
self.module = UI_module(self)
|
||||
self.objects = []
|
||||
self.modified = 0
|
||||
self.module = UI_module(self)
|
||||
self.objects = []
|
||||
self.modified = 0
|
||||
|
||||
def run(self):
|
||||
self.main.mainloop()
|
||||
self.main.mainloop()
|
||||
|
||||
def cb_quit(self, *args):
|
||||
if self.modified:
|
||||
if not askyn('You have not saved\nAre you sure you want to quit?'):
|
||||
return
|
||||
sys.exit(0)
|
||||
if self.modified:
|
||||
if not askyn('You have not saved\nAre you sure you want to quit?'):
|
||||
return
|
||||
sys.exit(0)
|
||||
|
||||
def cb_check(self, *args):
|
||||
try:
|
||||
self.module.synchronize()
|
||||
for o in self.objects:
|
||||
o.synchronize()
|
||||
except oops:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.module.synchronize()
|
||||
for o in self.objects:
|
||||
o.synchronize()
|
||||
except oops:
|
||||
pass
|
||||
|
||||
def cb_save(self, *args):
|
||||
try:
|
||||
pycode = self.module.gencode('m', self.objects)
|
||||
except oops:
|
||||
return
|
||||
try:
|
||||
pycode = self.module.gencode('m', self.objects)
|
||||
except oops:
|
||||
return
|
||||
|
||||
fn = askfile('Python file name: ')
|
||||
if not fn:
|
||||
return
|
||||
fn = askfile('Python file name: ')
|
||||
if not fn:
|
||||
return
|
||||
|
||||
fp = open(fn, 'w')
|
||||
fp = open(fn, 'w')
|
||||
|
||||
fp.write(pycode)
|
||||
fp.close()
|
||||
fp.write(pycode)
|
||||
fp.close()
|
||||
|
||||
def cb_gencode(self, *args):
|
||||
try:
|
||||
pycode = self.module.gencode('m', self.objects)
|
||||
except oops:
|
||||
pass
|
||||
try:
|
||||
pycode = self.module.gencode('m', self.objects)
|
||||
except oops:
|
||||
pass
|
||||
|
||||
fn = askfile('C file name: ')
|
||||
if not fn:
|
||||
return
|
||||
fn = askfile('C file name: ')
|
||||
if not fn:
|
||||
return
|
||||
|
||||
fp = open(fn, 'w')
|
||||
fp = open(fn, 'w')
|
||||
|
||||
try:
|
||||
exec pycode
|
||||
except:
|
||||
message('An error occurred:-)')
|
||||
return
|
||||
genmodule.write(fp, m)
|
||||
fp.close()
|
||||
try:
|
||||
exec pycode
|
||||
except:
|
||||
message('An error occurred:-)')
|
||||
return
|
||||
genmodule.write(fp, m)
|
||||
fp.close()
|
||||
|
||||
class UI_module:
|
||||
def __init__(self, parent):
|
||||
self.parent = parent
|
||||
self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m',
|
||||
Pack:{'side':'top',
|
||||
'fill':'x'}})
|
||||
self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.parent = parent
|
||||
self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m',
|
||||
Pack:{'side':'top',
|
||||
'fill':'x'}})
|
||||
self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
|
||||
self.l1 = Label(self.f1, {'text':'Module:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.name_entry = Entry(self.f1, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.l1 = Label(self.f1, {'text':'Module:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.name_entry = Entry(self.f1, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
|
||||
self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2,
|
||||
Pack:{'side':'left', 'expand':1,
|
||||
'padx':'0.5m', 'fill':'both'}})
|
||||
self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2,
|
||||
Pack:{'side':'left', 'expand':1,
|
||||
'padx':'0.5m', 'fill':'both'}})
|
||||
|
||||
self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_entry = Entry(self.f3, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.method_entry.bind('<Return>', self.cb_method)
|
||||
self.delete_button = Button(self.f3, {'text':'Delete method',
|
||||
'command':self.cb_delmethod,
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_entry = Entry(self.f3, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.method_entry.bind('<Return>', self.cb_method)
|
||||
self.delete_button = Button(self.f3, {'text':'Delete method',
|
||||
'command':self.cb_delmethod,
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
|
||||
self.newobj_button = Button(self.f4, {'text':'new object',
|
||||
'command':self.cb_newobj,
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
|
||||
self.newobj_button = Button(self.f4, {'text':'new object',
|
||||
'command':self.cb_newobj,
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
|
||||
def cb_delmethod(self, *args):
|
||||
list = self.method_list.curselection()
|
||||
for i in list:
|
||||
self.method_list.delete(i)
|
||||
|
||||
list = self.method_list.curselection()
|
||||
for i in list:
|
||||
self.method_list.delete(i)
|
||||
|
||||
def cb_newobj(self, *arg):
|
||||
self.parent.objects.append(UI_object(self.parent))
|
||||
self.parent.objects.append(UI_object(self.parent))
|
||||
|
||||
def cb_method(self, *arg):
|
||||
name = self.method_entry.get()
|
||||
if not name:
|
||||
return
|
||||
self.method_entry.delete('0', 'end')
|
||||
self.method_list.insert('end', name)
|
||||
name = self.method_entry.get()
|
||||
if not name:
|
||||
return
|
||||
self.method_entry.delete('0', 'end')
|
||||
self.method_list.insert('end', name)
|
||||
|
||||
def synchronize(self):
|
||||
n = self.name_entry.get()
|
||||
if not n:
|
||||
message('Module name not set')
|
||||
raise oops
|
||||
if not checkid(n):
|
||||
message('Module name not an identifier:\n'+n)
|
||||
raise oops
|
||||
if not self.abbrev_entry.get():
|
||||
self.abbrev_entry.insert('end', n)
|
||||
m = getlistlist(self.method_list)
|
||||
for n in m:
|
||||
if not checkid(n):
|
||||
message('Method name not an identifier:\n'+n)
|
||||
raise oops
|
||||
|
||||
n = self.name_entry.get()
|
||||
if not n:
|
||||
message('Module name not set')
|
||||
raise oops
|
||||
if not checkid(n):
|
||||
message('Module name not an identifier:\n'+n)
|
||||
raise oops
|
||||
if not self.abbrev_entry.get():
|
||||
self.abbrev_entry.insert('end', n)
|
||||
m = getlistlist(self.method_list)
|
||||
for n in m:
|
||||
if not checkid(n):
|
||||
message('Method name not an identifier:\n'+n)
|
||||
raise oops
|
||||
|
||||
def gencode(self, name, objects):
|
||||
rv = ''
|
||||
self.synchronize()
|
||||
for o in objects:
|
||||
o.synchronize()
|
||||
onames = []
|
||||
for i in range(len(objects)):
|
||||
oname = 'o'+`i+1`
|
||||
rv = rv + objects[i].gencode(oname)
|
||||
onames.append(oname)
|
||||
rv = rv + (name+' = genmodule.module()\n')
|
||||
rv = rv + (name+'.name = '+`self.name_entry.get()`+'\n')
|
||||
rv = rv + (name+'.abbrev = '+`self.abbrev_entry.get()`+'\n')
|
||||
rv = rv + (name+'.methodlist = '+`getlistlist(self.method_list)`+'\n')
|
||||
rv = rv + (name+'.objects = ['+string.joinfields(onames, ',')+']\n')
|
||||
rv = rv + ('\n')
|
||||
return rv
|
||||
|
||||
rv = ''
|
||||
self.synchronize()
|
||||
for o in objects:
|
||||
o.synchronize()
|
||||
onames = []
|
||||
for i in range(len(objects)):
|
||||
oname = 'o'+`i+1`
|
||||
rv = rv + objects[i].gencode(oname)
|
||||
onames.append(oname)
|
||||
rv = rv + (name+' = genmodule.module()\n')
|
||||
rv = rv + (name+'.name = '+`self.name_entry.get()`+'\n')
|
||||
rv = rv + (name+'.abbrev = '+`self.abbrev_entry.get()`+'\n')
|
||||
rv = rv + (name+'.methodlist = '+`getlistlist(self.method_list)`+'\n')
|
||||
rv = rv + (name+'.objects = ['+string.joinfields(onames, ',')+']\n')
|
||||
rv = rv + ('\n')
|
||||
return rv
|
||||
|
||||
object_number = 0
|
||||
|
||||
class UI_object:
|
||||
def __init__(self, parent):
|
||||
global object_number
|
||||
global object_number
|
||||
|
||||
object_number = object_number + 1
|
||||
self.num = object_number
|
||||
self.vpref = 'o'+`self.num`+'_'
|
||||
self.frame = Toplevel(parent.objframe)
|
||||
# self.frame.pack()
|
||||
self.frame.title('Modulator: object view')
|
||||
# self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m',
|
||||
# Pack:{'side':'top',
|
||||
# 'fill':'x'}})
|
||||
self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
|
||||
object_number = object_number + 1
|
||||
self.num = object_number
|
||||
self.vpref = 'o'+`self.num`+'_'
|
||||
self.frame = Toplevel(parent.objframe)
|
||||
# self.frame.pack()
|
||||
self.frame.title('Modulator: object view')
|
||||
# self.frame = Frame(parent.objframe, {'relief':'raised', 'bd':'0.2m',
|
||||
# Pack:{'side':'top',
|
||||
# 'fill':'x'}})
|
||||
self.f1 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f2 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f3 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.f4 = Frame(self.frame, {Pack:{'side':'top', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
|
||||
|
||||
self.l1 = Label(self.f1, {'text':'Object:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.name_entry = Entry(self.f1, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.l1 = Label(self.f1, {'text':'Object:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.name_entry = Entry(self.f1, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.l2 = Label(self.f1, {'text':'Abbrev:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.abbrev_entry = Entry(self.f1, {'relief':'sunken', 'width':5,
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
|
||||
self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2,
|
||||
Pack:{'side':'left', 'expand':1,
|
||||
'padx':'0.5m', 'fill':'both'}})
|
||||
self.l3 = Label(self.f2, {'text':'Methods:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_list = ScrolledListbox(self.f2, {'relief':'sunken','bd':2,
|
||||
Pack:{'side':'left', 'expand':1,
|
||||
'padx':'0.5m', 'fill':'both'}})
|
||||
|
||||
self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_entry = Entry(self.f3, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.method_entry.bind('<Return>', self.cb_method)
|
||||
self.delete_button = Button(self.f3, {'text':'Delete method',
|
||||
'command':self.cb_delmethod,
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.l4 = Label(self.f3, {'text':'Add method:', Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.method_entry = Entry(self.f3, {'relief':'sunken',
|
||||
Pack:{'side':'left', 'padx':'0.5m', 'expand':1}})
|
||||
self.method_entry.bind('<Return>', self.cb_method)
|
||||
self.delete_button = Button(self.f3, {'text':'Delete method',
|
||||
'command':self.cb_delmethod,
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
|
||||
|
||||
self.l5 = Label(self.f4, {'text':'functions:',
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.f5 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m',
|
||||
'fill':'both'}})
|
||||
self.l6 = Label(self.f4, {'text':'Types:',
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.f6 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.funcs = {}
|
||||
for i in genmodule.FUNCLIST:
|
||||
vname = self.vpref+i
|
||||
self.f5.setvar(vname, 0)
|
||||
b = Checkbutton(self.f5, {'variable':vname, 'text':i,
|
||||
Pack:{'side':'top', 'pady':'0.5m',
|
||||
'anchor':'w','expand':1}})
|
||||
self.funcs[i] = b
|
||||
self.f5.setvar(self.vpref+'new', 1)
|
||||
self.l5 = Label(self.f4, {'text':'functions:',
|
||||
Pack:{'side':'left',
|
||||
'padx':'0.5m'}})
|
||||
self.f5 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m',
|
||||
'fill':'both'}})
|
||||
self.l6 = Label(self.f4, {'text':'Types:',
|
||||
Pack:{'side':'left', 'padx':'0.5m'}})
|
||||
self.f6 = Frame(self.f4, {Pack:{'side':'left', 'pady':'0.5m',
|
||||
'fill':'x'}})
|
||||
self.funcs = {}
|
||||
for i in genmodule.FUNCLIST:
|
||||
vname = self.vpref+i
|
||||
self.f5.setvar(vname, 0)
|
||||
b = Checkbutton(self.f5, {'variable':vname, 'text':i,
|
||||
Pack:{'side':'top', 'pady':'0.5m',
|
||||
'anchor':'w','expand':1}})
|
||||
self.funcs[i] = b
|
||||
self.f5.setvar(self.vpref+'new', 1)
|
||||
|
||||
self.types = {}
|
||||
for i in genmodule.TYPELIST:
|
||||
vname = self.vpref + i
|
||||
self.f6.setvar(vname, 0)
|
||||
b = Checkbutton(self.f6, {'variable':vname, 'text':i,
|
||||
Pack:{'side':'top', 'pady':'0.5m',
|
||||
'anchor':'w'}})
|
||||
self.types[i] = b
|
||||
|
||||
self.types = {}
|
||||
for i in genmodule.TYPELIST:
|
||||
vname = self.vpref + i
|
||||
self.f6.setvar(vname, 0)
|
||||
b = Checkbutton(self.f6, {'variable':vname, 'text':i,
|
||||
Pack:{'side':'top', 'pady':'0.5m',
|
||||
'anchor':'w'}})
|
||||
self.types[i] = b
|
||||
|
||||
def cb_method(self, *arg):
|
||||
name = self.method_entry.get()
|
||||
if not name:
|
||||
return
|
||||
self.method_entry.delete('0', 'end')
|
||||
self.method_list.insert('end', name)
|
||||
name = self.method_entry.get()
|
||||
if not name:
|
||||
return
|
||||
self.method_entry.delete('0', 'end')
|
||||
self.method_list.insert('end', name)
|
||||
|
||||
def cb_delmethod(self, *args):
|
||||
list = self.method_list.curselection()
|
||||
for i in list:
|
||||
self.method_list.delete(i)
|
||||
|
||||
list = self.method_list.curselection()
|
||||
for i in list:
|
||||
self.method_list.delete(i)
|
||||
|
||||
def synchronize(self):
|
||||
n = self.name_entry.get()
|
||||
if not n:
|
||||
message('Object name not set')
|
||||
raise oops
|
||||
if not self.abbrev_entry.get():
|
||||
self.abbrev_entry.insert('end', n)
|
||||
n = self.abbrev_entry.get()
|
||||
if not checkid(n):
|
||||
message('Abbreviation not an identifier:\n'+n)
|
||||
raise oops
|
||||
m = getlistlist(self.method_list)
|
||||
for n in m:
|
||||
if not checkid(n):
|
||||
message('Method name not an identifier:\n'+n)
|
||||
raise oops
|
||||
if m:
|
||||
self.f5.setvar(self.vpref+'tp_getattr', 1)
|
||||
pass
|
||||
|
||||
n = self.name_entry.get()
|
||||
if not n:
|
||||
message('Object name not set')
|
||||
raise oops
|
||||
if not self.abbrev_entry.get():
|
||||
self.abbrev_entry.insert('end', n)
|
||||
n = self.abbrev_entry.get()
|
||||
if not checkid(n):
|
||||
message('Abbreviation not an identifier:\n'+n)
|
||||
raise oops
|
||||
m = getlistlist(self.method_list)
|
||||
for n in m:
|
||||
if not checkid(n):
|
||||
message('Method name not an identifier:\n'+n)
|
||||
raise oops
|
||||
if m:
|
||||
self.f5.setvar(self.vpref+'tp_getattr', 1)
|
||||
pass
|
||||
|
||||
def gencode(self, name):
|
||||
rv = ''
|
||||
rv = rv + (name+' = genmodule.object()\n')
|
||||
rv = rv + (name+'.name = '+`self.name_entry.get()`+'\n')
|
||||
rv = rv + (name+'.abbrev = '+`self.abbrev_entry.get()`+'\n')
|
||||
rv = rv + (name+'.methodlist = '+`getlistlist(self.method_list)`+'\n')
|
||||
fl = []
|
||||
for fn in genmodule.FUNCLIST:
|
||||
vname = self.vpref + fn
|
||||
if self.f5.getvar(vname) == '1':
|
||||
fl.append(fn)
|
||||
rv = rv + (name+'.funclist = '+`fl`+'\n')
|
||||
rv = ''
|
||||
rv = rv + (name+' = genmodule.object()\n')
|
||||
rv = rv + (name+'.name = '+`self.name_entry.get()`+'\n')
|
||||
rv = rv + (name+'.abbrev = '+`self.abbrev_entry.get()`+'\n')
|
||||
rv = rv + (name+'.methodlist = '+`getlistlist(self.method_list)`+'\n')
|
||||
fl = []
|
||||
for fn in genmodule.FUNCLIST:
|
||||
vname = self.vpref + fn
|
||||
if self.f5.getvar(vname) == '1':
|
||||
fl.append(fn)
|
||||
rv = rv + (name+'.funclist = '+`fl`+'\n')
|
||||
|
||||
fl = []
|
||||
for fn in genmodule.TYPELIST:
|
||||
vname = self.vpref + fn
|
||||
if self.f5.getvar(vname) == '1':
|
||||
fl.append(fn)
|
||||
|
||||
rv = rv + (name+'.typelist = '+`fl`+'\n')
|
||||
fl = []
|
||||
for fn in genmodule.TYPELIST:
|
||||
vname = self.vpref + fn
|
||||
if self.f5.getvar(vname) == '1':
|
||||
fl.append(fn)
|
||||
|
||||
rv = rv + (name+'.typelist = '+`fl`+'\n')
|
||||
|
||||
rv = rv + ('\n')
|
||||
return rv
|
||||
|
||||
rv = rv + ('\n')
|
||||
return rv
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
ui = UI()
|
||||
ui.run()
|
||||
ui = UI()
|
||||
ui.run()
|
||||
elif len(sys.argv) == 2:
|
||||
fp = open(sys.argv[1])
|
||||
pycode = fp.read()
|
||||
try:
|
||||
exec pycode
|
||||
except:
|
||||
sys.stderr.write('An error occurred:-)\n')
|
||||
sys.exit(1)
|
||||
genmodule.write(sys.stdout, m)
|
||||
fp = open(sys.argv[1])
|
||||
pycode = fp.read()
|
||||
try:
|
||||
exec pycode
|
||||
except:
|
||||
sys.stderr.write('An error occurred:-)\n')
|
||||
sys.exit(1)
|
||||
genmodule.write(sys.stdout, m)
|
||||
else:
|
||||
sys.stderr.write('Usage: modulator [file]\n')
|
||||
sys.exit(1)
|
||||
|
||||
sys.stderr.write('Usage: modulator [file]\n')
|
||||
sys.exit(1)
|
||||
|
||||
main()
|
||||
|
|
|
@ -9,42 +9,42 @@
|
|||
|
||||
class Varsubst:
|
||||
def __init__(self, dict):
|
||||
self.dict = dict
|
||||
self.prog = regex.compile('\$[a-zA-Z0-9_]*\$')
|
||||
self.do_useindent = 0
|
||||
self.dict = dict
|
||||
self.prog = regex.compile('\$[a-zA-Z0-9_]*\$')
|
||||
self.do_useindent = 0
|
||||
|
||||
def useindent(self, onoff):
|
||||
self.do_useindent = onoff
|
||||
|
||||
self.do_useindent = onoff
|
||||
|
||||
def subst(self, str):
|
||||
rv = ''
|
||||
while 1:
|
||||
pos = self.prog.search(str)
|
||||
if pos < 0:
|
||||
return rv + str
|
||||
if pos:
|
||||
rv = rv + str[:pos]
|
||||
str = str[pos:]
|
||||
len = self.prog.match(str)
|
||||
if len == 2:
|
||||
# Escaped dollar
|
||||
rv = rv + '$'
|
||||
str = str[2:]
|
||||
continue
|
||||
name = str[1:len-1]
|
||||
str = str[len:]
|
||||
if not self.dict.has_key(name):
|
||||
raise error, 'No such variable: '+name
|
||||
value = self.dict[name]
|
||||
if self.do_useindent and '\n' in value:
|
||||
value = self._modindent(value, rv)
|
||||
rv = rv + value
|
||||
rv = ''
|
||||
while 1:
|
||||
pos = self.prog.search(str)
|
||||
if pos < 0:
|
||||
return rv + str
|
||||
if pos:
|
||||
rv = rv + str[:pos]
|
||||
str = str[pos:]
|
||||
len = self.prog.match(str)
|
||||
if len == 2:
|
||||
# Escaped dollar
|
||||
rv = rv + '$'
|
||||
str = str[2:]
|
||||
continue
|
||||
name = str[1:len-1]
|
||||
str = str[len:]
|
||||
if not self.dict.has_key(name):
|
||||
raise error, 'No such variable: '+name
|
||||
value = self.dict[name]
|
||||
if self.do_useindent and '\n' in value:
|
||||
value = self._modindent(value, rv)
|
||||
rv = rv + value
|
||||
|
||||
def _modindent(self, value, old):
|
||||
lastnl = string.rfind(old, '\n', 0) + 1
|
||||
lastnl = len(old) - lastnl
|
||||
sub = '\n' + (' '*lastnl)
|
||||
return regsub.gsub('\n', sub, value)
|
||||
lastnl = string.rfind(old, '\n', 0) + 1
|
||||
lastnl = len(old) - lastnl
|
||||
sub = '\n' + (' '*lastnl)
|
||||
return regsub.gsub('\n', sub, value)
|
||||
|
||||
def _test():
|
||||
import sys
|
||||
|
|
Loading…
Reference in New Issue