mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
SF patch #701494: more apply removals
This commit is contained in:
parent
50c61d5a6c
commit
ff41c48a77
23 changed files with 2437 additions and 2449 deletions
|
@ -72,7 +72,7 @@ def Node(*args):
|
|||
kind = args[0]
|
||||
if nodes.has_key(kind):
|
||||
try:
|
||||
return apply(nodes[kind], args[1:])
|
||||
return nodes[kind](*args[1:])
|
||||
except TypeError:
|
||||
print nodes[kind], len(args), args
|
||||
raise
|
||||
|
|
|
@ -41,7 +41,7 @@ def wrapper(func, *rest):
|
|||
except:
|
||||
pass
|
||||
|
||||
res = apply(func, (stdscr,) + rest)
|
||||
res = func(stdscr, *rest)
|
||||
except:
|
||||
# In the event of an error, restore the terminal
|
||||
# to a sane state.
|
||||
|
|
|
@ -55,7 +55,7 @@ class CanvasItem:
|
|||
def coords(self, pts = ()):
|
||||
flat = ()
|
||||
for x, y in pts: flat = flat + (x, y)
|
||||
return apply(self.canvas.coords, (self.id,) + flat)
|
||||
return self.canvas.coords(self.id, *flat)
|
||||
def dchars(self, first, last=None):
|
||||
self.canvas.dchars(self.id, first, last)
|
||||
def dtag(self, ttd):
|
||||
|
@ -84,40 +84,40 @@ class CanvasItem:
|
|||
|
||||
class Arc(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'arc') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'arc', *args, **kw)
|
||||
|
||||
class Bitmap(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'bitmap') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'bitmap', *args, **kw)
|
||||
|
||||
class ImageItem(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'image') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'image', *args, **kw)
|
||||
|
||||
class Line(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'line') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'line', *args, **kw)
|
||||
|
||||
class Oval(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'oval') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'oval', *args, **kw)
|
||||
|
||||
class Polygon(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'polygon') + args,kw)
|
||||
CanvasItem.__init__(self, canvas, 'polygon', *args, **kw)
|
||||
|
||||
class Rectangle(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'rectangle')+args,kw)
|
||||
CanvasItem.__init__(self, canvas, 'rectangle', *args, **kw)
|
||||
|
||||
# XXX "Text" is taken by the Text widget...
|
||||
class CanvasText(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'text') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'text', *args, **kw)
|
||||
|
||||
class Window(CanvasItem):
|
||||
def __init__(self, canvas, *args, **kw):
|
||||
apply(CanvasItem.__init__, (self, canvas, 'window') + args, kw)
|
||||
CanvasItem.__init__(self, canvas, 'window', *args, **kw)
|
||||
|
||||
class Group:
|
||||
def __init__(self, canvas, tag=None):
|
||||
|
|
|
@ -15,11 +15,11 @@ class Dialog(Widget):
|
|||
self.widgetName = '__dialog__'
|
||||
Widget._setup(self, master, cnf)
|
||||
self.num = self.tk.getint(
|
||||
apply(self.tk.call,
|
||||
('tk_dialog', self._w,
|
||||
cnf['title'], cnf['text'],
|
||||
cnf['bitmap'], cnf['default'])
|
||||
+ cnf['strings']))
|
||||
self.tk.call(
|
||||
'tk_dialog', self._w,
|
||||
cnf['title'], cnf['text'],
|
||||
cnf['bitmap'], cnf['default'],
|
||||
*cnf['strings']))
|
||||
try: Widget.destroy(self)
|
||||
except TclError: pass
|
||||
def destroy(self): pass
|
||||
|
|
|
@ -24,11 +24,11 @@ class ScrolledText(Text):
|
|||
if type(k) == ClassType or k == 'name':
|
||||
fcnf[k] = cnf[k]
|
||||
del cnf[k]
|
||||
self.frame = apply(Frame, (master,), fcnf)
|
||||
self.frame = Frame(master, **fcnf)
|
||||
self.vbar = Scrollbar(self.frame, name='vbar')
|
||||
self.vbar.pack(side=RIGHT, fill=Y)
|
||||
cnf['name'] = 'text'
|
||||
apply(Text.__init__, (self, self.frame), cnf)
|
||||
Text.__init__(self, self.frame, **cnf)
|
||||
self.pack(side=LEFT, fill=BOTH, expand=1)
|
||||
self['yscrollcommand'] = self.vbar.set
|
||||
self.vbar['command'] = self.yview
|
||||
|
|
|
@ -222,7 +222,7 @@ class Form:
|
|||
See Tix documentation for complete details"""
|
||||
|
||||
def config(self, cnf={}, **kw):
|
||||
apply(self.tk.call, ('tixForm', self._w) + self._options(cnf, kw))
|
||||
self.tk.call('tixForm', self._w, *self._options(cnf, kw))
|
||||
|
||||
form = config
|
||||
|
||||
|
@ -304,7 +304,7 @@ class TixWidget(Tkinter.Widget):
|
|||
# If widgetName is None, this is a dummy creation call where the
|
||||
# corresponding Tk widget has already been created by Tix
|
||||
if widgetName:
|
||||
apply(self.tk.call, (widgetName, self._w) + extra)
|
||||
self.tk.call(widgetName, self._w, *extra)
|
||||
|
||||
# Non-static options - to be done via a 'config' command
|
||||
if cnf:
|
||||
|
@ -474,8 +474,8 @@ class DisplayStyle:
|
|||
elif not master and kw.has_key('refwindow'): master= kw['refwindow']
|
||||
elif not master: raise RuntimeError, "Too early to create display style: no root window"
|
||||
self.tk = master.tk
|
||||
self.stylename = apply(self.tk.call, ('tixDisplayStyle', itemtype) +
|
||||
self._options(cnf,kw) )
|
||||
self.stylename = self.tk.call('tixDisplayStyle', itemtype,
|
||||
*self._options(cnf,kw) )
|
||||
|
||||
def __str__(self):
|
||||
return self.stylename
|
||||
|
@ -499,8 +499,8 @@ class DisplayStyle:
|
|||
def config(self, cnf={}, **kw):
|
||||
return _lst2dict(
|
||||
self.tk.split(
|
||||
apply(self.tk.call,
|
||||
(self.stylename, 'configure') + self._options(cnf,kw))))
|
||||
self.tk.call(
|
||||
self.stylename, 'configure', *self._options(cnf,kw))))
|
||||
|
||||
def __getitem__(self,key):
|
||||
return self.tk.call(self.stylename, 'cget', '-%s'%key)
|
||||
|
@ -532,8 +532,7 @@ class Balloon(TixWidget):
|
|||
def bind_widget(self, widget, cnf={}, **kw):
|
||||
"""Bind balloon widget to another.
|
||||
One balloon widget may be bound to several widgets at the same time"""
|
||||
apply(self.tk.call,
|
||||
(self._w, 'bind', widget._w) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'bind', widget._w, *self._options(cnf, kw))
|
||||
|
||||
def unbind_widget(self, widget):
|
||||
self.tk.call(self._w, 'unbind', widget._w)
|
||||
|
@ -549,8 +548,7 @@ class ButtonBox(TixWidget):
|
|||
def add(self, name, cnf={}, **kw):
|
||||
"""Add a button with given name to box."""
|
||||
|
||||
btn = apply(self.tk.call,
|
||||
(self._w, 'add', name) + self._options(cnf, kw))
|
||||
btn = self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
|
||||
self.subwidget_list[name] = _dummyButton(self, name)
|
||||
return btn
|
||||
|
||||
|
@ -862,14 +860,13 @@ class HList(TixWidget):
|
|||
['columns', 'options'], cnf, kw)
|
||||
|
||||
def add(self, entry, cnf={}, **kw):
|
||||
return apply(self.tk.call,
|
||||
(self._w, 'add', entry) + self._options(cnf, kw))
|
||||
return self.tk.call(self._w, 'add', entry, *self._options(cnf, kw))
|
||||
|
||||
def add_child(self, parent=None, cnf={}, **kw):
|
||||
if not parent:
|
||||
parent = ''
|
||||
return apply(self.tk.call,
|
||||
(self._w, 'addchild', parent) + self._options(cnf, kw))
|
||||
return self.tk.call(
|
||||
self._w, 'addchild', parent, *self._options(cnf, kw))
|
||||
|
||||
def anchor_set(self, entry):
|
||||
self.tk.call(self._w, 'anchor', 'set', entry)
|
||||
|
@ -909,16 +906,15 @@ class HList(TixWidget):
|
|||
self.tk.call(self._w, 'dropsite', 'clear')
|
||||
|
||||
def header_create(self, col, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'header', 'create', col) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'header', 'create', col, *self._options(cnf, kw))
|
||||
|
||||
def header_configure(self, col, cnf={}, **kw):
|
||||
if cnf is None:
|
||||
return _lst2dict(
|
||||
self.tk.split(
|
||||
self.tk.call(self._w, 'header', 'configure', col)))
|
||||
apply(self.tk.call, (self._w, 'header', 'configure', col)
|
||||
+ self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'header', 'configure', col,
|
||||
*self._options(cnf, kw))
|
||||
|
||||
def header_cget(self, col, opt):
|
||||
return self.tk.call(self._w, 'header', 'cget', col, opt)
|
||||
|
@ -936,16 +932,16 @@ class HList(TixWidget):
|
|||
self.tk.call(self._w, 'hide', 'entry', entry)
|
||||
|
||||
def indicator_create(self, entry, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'indicator', 'create', entry) + self._options(cnf, kw))
|
||||
self.tk.call(
|
||||
self._w, 'indicator', 'create', entry, *self._options(cnf, kw))
|
||||
|
||||
def indicator_configure(self, entry, cnf={}, **kw):
|
||||
if cnf is None:
|
||||
return _lst2dict(
|
||||
self.tk.split(
|
||||
self.tk.call(self._w, 'indicator', 'configure', entry)))
|
||||
apply(self.tk.call,
|
||||
(self._w, 'indicator', 'configure', entry) + self._options(cnf, kw))
|
||||
self.tk.call(
|
||||
self._w, 'indicator', 'configure', entry, *self._options(cnf, kw))
|
||||
|
||||
def indicator_cget(self, entry, opt):
|
||||
return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
|
||||
|
@ -996,12 +992,12 @@ class HList(TixWidget):
|
|||
return _lst2dict(
|
||||
self.tk.split(
|
||||
self.tk.call(self._w, 'item', 'configure', entry, col)))
|
||||
apply(self.tk.call, (self._w, 'item', 'configure', entry, col) +
|
||||
self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'item', 'configure', entry, col,
|
||||
*self._options(cnf, kw))
|
||||
|
||||
def item_create(self, entry, col, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'item', 'create', entry, col) + self._options(cnf, kw))
|
||||
self.tk.call(
|
||||
self._w, 'item', 'create', entry, col, *self._options(cnf, kw))
|
||||
|
||||
def item_exists(self, entry, col):
|
||||
return self.tk.call(self._w, 'item', 'exists', entry, col)
|
||||
|
@ -1016,8 +1012,7 @@ class HList(TixWidget):
|
|||
self.tk.call(self._w, 'see', entry)
|
||||
|
||||
def selection_clear(self, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'selection', 'clear') + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
|
||||
|
||||
def selection_includes(self, entry):
|
||||
return self.tk.call(self._w, 'selection', 'includes', entry)
|
||||
|
@ -1029,10 +1024,10 @@ class HList(TixWidget):
|
|||
return self.tk.call(self._w, 'show', 'entry', entry)
|
||||
|
||||
def xview(self, *args):
|
||||
apply(self.tk.call, (self._w, 'xview') + args)
|
||||
self.tk.call(self._w, 'xview', *args)
|
||||
|
||||
def yview(self, *args):
|
||||
apply(self.tk.call, (self._w, 'yview') + args)
|
||||
self.tk.call(self._w, 'yview', *args)
|
||||
|
||||
class InputOnly(TixWidget):
|
||||
"""InputOnly - Invisible widget. Unix only.
|
||||
|
@ -1093,8 +1088,7 @@ class ListNoteBook(TixWidget):
|
|||
self.subwidget_list['shlist'] = _dummyScrolledHList(self, 'shlist')
|
||||
|
||||
def add(self, name, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'add', name) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
|
||||
self.subwidget_list[name] = TixSubWidget(self, name)
|
||||
return self.subwidget_list[name]
|
||||
|
||||
|
@ -1135,8 +1129,7 @@ class NoteBook(TixWidget):
|
|||
destroy_physically=0)
|
||||
|
||||
def add(self, name, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'add', name) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
|
||||
self.subwidget_list[name] = TixSubWidget(self, name)
|
||||
return self.subwidget_list[name]
|
||||
|
||||
|
@ -1180,12 +1173,10 @@ class OptionMenu(TixWidget):
|
|||
self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
|
||||
|
||||
def add_command(self, name, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'add', 'command', name) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'add', 'command', name, *self._options(cnf, kw))
|
||||
|
||||
def add_separator(self, name, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'add', 'separator', name) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'add', 'separator', name, *self._options(cnf, kw))
|
||||
|
||||
def delete(self, name):
|
||||
self.tk.call(self._w, 'delete', name)
|
||||
|
@ -1212,8 +1203,7 @@ class PanedWindow(TixWidget):
|
|||
|
||||
# add delete forget panecget paneconfigure panes setsize
|
||||
def add(self, name, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'add', name) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
|
||||
self.subwidget_list[name] = TixSubWidget(self, name,
|
||||
check_intermediate=0)
|
||||
return self.subwidget_list[name]
|
||||
|
@ -1234,8 +1224,7 @@ class PanedWindow(TixWidget):
|
|||
return _lst2dict(
|
||||
self.tk.split(
|
||||
self.tk.call(self._w, 'paneconfigure', entry)))
|
||||
apply(self.tk.call,
|
||||
(self._w, 'paneconfigure', entry) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
|
||||
|
||||
def panes(self):
|
||||
names = self.tk.call(self._w, 'panes')
|
||||
|
@ -1361,8 +1350,7 @@ class Select(TixWidget):
|
|||
self.subwidget_list['label'] = _dummyLabel(self, 'label')
|
||||
|
||||
def add(self, name, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'add', name) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
|
||||
self.subwidget_list[name] = _dummyButton(self, name)
|
||||
return self.subwidget_list[name]
|
||||
|
||||
|
@ -1458,8 +1446,7 @@ class TList(TixWidget):
|
|||
self.tk.call(self._w, 'dropsite', 'clear')
|
||||
|
||||
def insert(self, index, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'insert', index) + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'insert', index, *self._options(cnf, kw))
|
||||
|
||||
def info_active(self):
|
||||
return self.tk.call(self._w, 'info', 'active')
|
||||
|
@ -1493,8 +1480,7 @@ class TList(TixWidget):
|
|||
self.tk.call(self._w, 'see', index)
|
||||
|
||||
def selection_clear(self, cnf={}, **kw):
|
||||
apply(self.tk.call,
|
||||
(self._w, 'selection', 'clear') + self._options(cnf, kw))
|
||||
self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
|
||||
|
||||
def selection_includes(self, index):
|
||||
return self.tk.call(self._w, 'selection', 'includes', index)
|
||||
|
@ -1503,10 +1489,10 @@ class TList(TixWidget):
|
|||
self.tk.call(self._w, 'selection', 'set', first, last)
|
||||
|
||||
def xview(self, *args):
|
||||
apply(self.tk.call, (self._w, 'xview') + args)
|
||||
self.tk.call(self._w, 'xview', *args)
|
||||
|
||||
def yview(self, *args):
|
||||
apply(self.tk.call, (self._w, 'yview') + args)
|
||||
self.tk.call(self._w, 'yview', *args)
|
||||
|
||||
class Tree(TixWidget):
|
||||
"""Tree - The tixTree widget can be used to display hierachical
|
||||
|
|
|
@ -444,7 +444,7 @@ class Misc:
|
|||
tmp = []
|
||||
def callit(func=func, args=args, self=self, tmp=tmp):
|
||||
try:
|
||||
apply(func, args)
|
||||
func(*args)
|
||||
finally:
|
||||
try:
|
||||
self.deletecommand(tmp[0])
|
||||
|
@ -459,7 +459,7 @@ class Misc:
|
|||
|
||||
Return an identifier to cancel the scheduling with
|
||||
after_cancel."""
|
||||
return apply(self.after, ('idle', func) + args)
|
||||
return self.after('idle', func, *args)
|
||||
def after_cancel(self, id):
|
||||
"""Cancel scheduling of function identified with ID.
|
||||
|
||||
|
@ -1182,7 +1182,7 @@ class Misc:
|
|||
args = args + (column, row)
|
||||
if col2 is not None and row2 is not None:
|
||||
args = args + (col2, row2)
|
||||
return self._getints(apply(self.tk.call, args)) or None
|
||||
return self._getints(self.tk.call(*args)) or None
|
||||
|
||||
bbox = grid_bbox
|
||||
def _grid_configure(self, command, index, cnf, kw):
|
||||
|
@ -1324,8 +1324,8 @@ class CallWrapper:
|
|||
"""Apply first function SUBST to arguments, than FUNC."""
|
||||
try:
|
||||
if self.subst:
|
||||
args = apply(self.subst, args)
|
||||
return apply(self.func, args)
|
||||
args = self.subst(*args)
|
||||
return self.func(*args)
|
||||
except SystemExit, msg:
|
||||
raise SystemExit, msg
|
||||
except:
|
||||
|
@ -2028,10 +2028,9 @@ class Canvas(Widget):
|
|||
args = args[:-1]
|
||||
else:
|
||||
cnf = {}
|
||||
return getint(apply(
|
||||
self.tk.call,
|
||||
(self._w, 'create', itemType)
|
||||
+ args + self._options(cnf, kw)))
|
||||
return getint(self.tk.call(
|
||||
self._w, 'create', itemType,
|
||||
*(args + self._options(cnf, kw))))
|
||||
def create_arc(self, *args, **kw):
|
||||
"""Create arc shaped region with coordinates x1,y1,x2,y2."""
|
||||
return self._create('arc', args, kw)
|
||||
|
@ -2862,9 +2861,9 @@ class Text(Widget):
|
|||
return self._configure(('image', 'configure', index), cnf, kw)
|
||||
def image_create(self, index, cnf={}, **kw):
|
||||
"""Create an embedded image at INDEX."""
|
||||
return apply(self.tk.call,
|
||||
(self._w, "image", "create", index)
|
||||
+ self._options(cnf, kw))
|
||||
return self.tk.call(
|
||||
self._w, "image", "create", index,
|
||||
*self._options(cnf, kw))
|
||||
def image_names(self):
|
||||
"""Return all names of embedded images in this widget."""
|
||||
return self.tk.call(self._w, "image", "names")
|
||||
|
@ -3050,7 +3049,7 @@ class _setit:
|
|||
def __call__(self, *args):
|
||||
self.__var.set(self.__value)
|
||||
if self.__callback:
|
||||
apply(self.__callback, (self.__value,)+args)
|
||||
self.__callback(self.__value, *args)
|
||||
|
||||
class OptionMenu(Menubutton):
|
||||
"""OptionMenu which allows the user to select a value from a menu."""
|
||||
|
@ -3156,7 +3155,7 @@ class PhotoImage(Image):
|
|||
|
||||
Valid resource names: data, format, file, gamma, height, palette,
|
||||
width."""
|
||||
apply(Image.__init__, (self, 'photo', name, cnf, master), kw)
|
||||
Image.__init__(self, 'photo', name, cnf, master, **kw)
|
||||
def blank(self):
|
||||
"""Display a transparent image."""
|
||||
self.tk.call(self.name, 'blank')
|
||||
|
@ -3215,7 +3214,7 @@ class BitmapImage(Image):
|
|||
"""Create a bitmap with NAME.
|
||||
|
||||
Valid resource names: background, data, file, foreground, maskdata, maskfile."""
|
||||
apply(Image.__init__, (self, 'bitmap', name, cnf, master), kw)
|
||||
Image.__init__(self, 'bitmap', name, cnf, master, **kw)
|
||||
|
||||
def image_names(): return _default_root.tk.call('image', 'names')
|
||||
def image_types(): return _default_root.tk.call('image', 'types')
|
||||
|
|
|
@ -63,7 +63,7 @@ def askcolor(color = None, **options):
|
|||
options = options.copy()
|
||||
options["initialcolor"] = color
|
||||
|
||||
return apply(Chooser, (), options).show()
|
||||
return Chooser(**options).show()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
|
|
@ -49,7 +49,7 @@ class Dialog:
|
|||
|
||||
try:
|
||||
|
||||
s = apply(w.tk.call, (self.command,) + w._options(self.options))
|
||||
s = w.tk.call(self.command, *w._options(self.options))
|
||||
|
||||
s = self._fixresult(w, s)
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ class Font:
|
|||
if not name:
|
||||
name = "font" + str(id(self))
|
||||
self.name = name
|
||||
apply(root.tk.call, ("font", "create", name) + font)
|
||||
root.tk.call("font", "create", name, *font)
|
||||
# backlinks!
|
||||
self._root = root
|
||||
self._split = root.tk.splitlist
|
||||
|
@ -90,7 +90,7 @@ class Font:
|
|||
|
||||
def copy(self):
|
||||
"Return a distinct copy of the current font"
|
||||
return apply(Font, (self._root,), self.actual())
|
||||
return Font(self._root, **self.actual())
|
||||
|
||||
def actual(self, option=None):
|
||||
"Return actual font attributes"
|
||||
|
@ -108,8 +108,8 @@ class Font:
|
|||
def config(self, **options):
|
||||
"Modify font attributes"
|
||||
if options:
|
||||
apply(self._call, ("font", "config", self.name) +
|
||||
self._set(options))
|
||||
self._call("font", "config", self.name,
|
||||
*self._set(options))
|
||||
else:
|
||||
return self._mkdict(
|
||||
self._split(self._call("font", "config", self.name))
|
||||
|
|
|
@ -72,37 +72,37 @@ def _show(title=None, message=None, icon=None, type=None, **options):
|
|||
if type: options["type"] = type
|
||||
if title: options["title"] = title
|
||||
if message: options["message"] = message
|
||||
return apply(Message, (), options).show()
|
||||
return Message(**options).show()
|
||||
|
||||
def showinfo(title=None, message=None, **options):
|
||||
"Show an info message"
|
||||
return apply(_show, (title, message, INFO, OK), options)
|
||||
return _show(title, message, INFO, OK, **options)
|
||||
|
||||
def showwarning(title=None, message=None, **options):
|
||||
"Show a warning message"
|
||||
return apply(_show, (title, message, WARNING, OK), options)
|
||||
return _show(title, message, WARNING, OK, **options)
|
||||
|
||||
def showerror(title=None, message=None, **options):
|
||||
"Show an error message"
|
||||
return apply(_show, (title, message, ERROR, OK), options)
|
||||
return _show(title, message, ERROR, OK, **options)
|
||||
|
||||
def askquestion(title=None, message=None, **options):
|
||||
"Ask a question"
|
||||
return apply(_show, (title, message, QUESTION, YESNO), options)
|
||||
return _show(title, message, QUESTION, YESNO, **options)
|
||||
|
||||
def askokcancel(title=None, message=None, **options):
|
||||
"Ask if operation should proceed; return true if the answer is ok"
|
||||
s = apply(_show, (title, message, QUESTION, OKCANCEL), options)
|
||||
s = _show(title, message, QUESTION, OKCANCEL, **options)
|
||||
return s == OK
|
||||
|
||||
def askyesno(title=None, message=None, **options):
|
||||
"Ask a question; return true if the answer is yes"
|
||||
s = apply(_show, (title, message, QUESTION, YESNO), options)
|
||||
s = _show(title, message, QUESTION, YESNO, **options)
|
||||
return s == YES
|
||||
|
||||
def askretrycancel(title=None, message=None, **options):
|
||||
"Ask if operation should be retried; return true if the answer is yes"
|
||||
s = apply(_show, (title, message, WARNING, RETRYCANCEL), options)
|
||||
s = _show(title, message, WARNING, RETRYCANCEL, **options)
|
||||
return s == RETRY
|
||||
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ def askinteger(title, prompt, **kw):
|
|||
|
||||
Return value is an integer
|
||||
'''
|
||||
d = apply(_QueryInteger, (title, prompt), kw)
|
||||
d = _QueryInteger(title, prompt, **kw)
|
||||
return d.result
|
||||
|
||||
class _QueryFloat(_QueryDialog):
|
||||
|
@ -268,7 +268,7 @@ def askfloat(title, prompt, **kw):
|
|||
|
||||
Return value is a float
|
||||
'''
|
||||
d = apply(_QueryFloat, (title, prompt), kw)
|
||||
d = _QueryFloat(title, prompt, **kw)
|
||||
return d.result
|
||||
|
||||
class _QueryString(_QueryDialog):
|
||||
|
@ -300,7 +300,7 @@ def askstring(title, prompt, **kw):
|
|||
|
||||
Return value is a string
|
||||
'''
|
||||
d = apply(_QueryString, (title, prompt), kw)
|
||||
d = _QueryString(title, prompt, **kw)
|
||||
return d.result
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -354,11 +354,11 @@ def right(angle): _getpen().right(angle)
|
|||
def up(): _getpen().up()
|
||||
def down(): _getpen().down()
|
||||
def width(width): _getpen().width(width)
|
||||
def color(*args): apply(_getpen().color, args)
|
||||
def color(*args): _getpen().color(*args)
|
||||
def write(arg, move=0): _getpen().write(arg, move)
|
||||
def fill(flag): _getpen().fill(flag)
|
||||
def circle(radius, extent=None): _getpen().circle(radius, extent)
|
||||
def goto(*args): apply(_getpen().goto, args)
|
||||
def goto(*args): _getpen().goto(*args)
|
||||
def heading(): return _getpen().heading()
|
||||
def setheading(angle): _getpen().setheading(angle)
|
||||
def position(): return _getpen().position()
|
||||
|
|
|
@ -4,94 +4,94 @@ import struct
|
|||
Error = 'MediaDescr.Error'
|
||||
|
||||
class _MediaDescriptionCodec:
|
||||
def __init__(self, trunc, size, names, fmt):
|
||||
self.trunc = trunc
|
||||
self.size = size
|
||||
self.names = names
|
||||
self.fmt = fmt
|
||||
def __init__(self, trunc, size, names, fmt):
|
||||
self.trunc = trunc
|
||||
self.size = size
|
||||
self.names = names
|
||||
self.fmt = fmt
|
||||
|
||||
def decode(self, data):
|
||||
if self.trunc:
|
||||
data = data[:self.size]
|
||||
values = struct.unpack(self.fmt, data)
|
||||
if len(values) != len(self.names):
|
||||
raise Error, ('Format length does not match number of names', descr)
|
||||
rv = {}
|
||||
for i in range(len(values)):
|
||||
name = self.names[i]
|
||||
value = values[i]
|
||||
if type(name) == type(()):
|
||||
name, cod, dec = name
|
||||
value = dec(value)
|
||||
rv[name] = value
|
||||
return rv
|
||||
def decode(self, data):
|
||||
if self.trunc:
|
||||
data = data[:self.size]
|
||||
values = struct.unpack(self.fmt, data)
|
||||
if len(values) != len(self.names):
|
||||
raise Error, ('Format length does not match number of names', descr)
|
||||
rv = {}
|
||||
for i in range(len(values)):
|
||||
name = self.names[i]
|
||||
value = values[i]
|
||||
if type(name) == type(()):
|
||||
name, cod, dec = name
|
||||
value = dec(value)
|
||||
rv[name] = value
|
||||
return rv
|
||||
|
||||
def encode(dict):
|
||||
list = [self.fmt]
|
||||
for name in self.names:
|
||||
if type(name) == type(()):
|
||||
name, cod, dec = name
|
||||
else:
|
||||
cod = dec = None
|
||||
value = dict[name]
|
||||
if cod:
|
||||
value = cod(value)
|
||||
list.append(value)
|
||||
rv = apply(struct.pack, tuple(list))
|
||||
return rv
|
||||
def encode(dict):
|
||||
list = [self.fmt]
|
||||
for name in self.names:
|
||||
if type(name) == type(()):
|
||||
name, cod, dec = name
|
||||
else:
|
||||
cod = dec = None
|
||||
value = dict[name]
|
||||
if cod:
|
||||
value = cod(value)
|
||||
list.append(value)
|
||||
rv = struct.pack(*list)
|
||||
return rv
|
||||
|
||||
# Helper functions
|
||||
def _tofixed(float):
|
||||
hi = int(float)
|
||||
lo = int(float*0x10000) & 0xffff
|
||||
return (hi<<16)|lo
|
||||
hi = int(float)
|
||||
lo = int(float*0x10000) & 0xffff
|
||||
return (hi<<16)|lo
|
||||
|
||||
def _fromfixed(fixed):
|
||||
hi = (fixed >> 16) & 0xffff
|
||||
lo = (fixed & 0xffff)
|
||||
return hi + (lo / float(0x10000))
|
||||
hi = (fixed >> 16) & 0xffff
|
||||
lo = (fixed & 0xffff)
|
||||
return hi + (lo / float(0x10000))
|
||||
|
||||
def _tostr31(str):
|
||||
return chr(len(str)) + str + '\0'*(31-len(str))
|
||||
return chr(len(str)) + str + '\0'*(31-len(str))
|
||||
|
||||
def _fromstr31(str31):
|
||||
return str31[1:1+ord(str31[0])]
|
||||
return str31[1:1+ord(str31[0])]
|
||||
|
||||
SampleDescription = _MediaDescriptionCodec(
|
||||
1, # May be longer, truncate
|
||||
16, # size
|
||||
('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex'), # Attributes
|
||||
"l4slhh" # Format
|
||||
1, # May be longer, truncate
|
||||
16, # size
|
||||
('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex'), # Attributes
|
||||
"l4slhh" # Format
|
||||
)
|
||||
|
||||
SoundDescription = _MediaDescriptionCodec(
|
||||
1,
|
||||
36,
|
||||
('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex',
|
||||
'version', 'revlevel', 'vendor', 'numChannels', 'sampleSize',
|
||||
'compressionID', 'packetSize', ('sampleRate', _tofixed, _fromfixed)),
|
||||
"l4slhhhh4shhhhl" # Format
|
||||
1,
|
||||
36,
|
||||
('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex',
|
||||
'version', 'revlevel', 'vendor', 'numChannels', 'sampleSize',
|
||||
'compressionID', 'packetSize', ('sampleRate', _tofixed, _fromfixed)),
|
||||
"l4slhhhh4shhhhl" # Format
|
||||
)
|
||||
|
||||
SoundDescriptionV1 = _MediaDescriptionCodec(
|
||||
1,
|
||||
52,
|
||||
('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex',
|
||||
'version', 'revlevel', 'vendor', 'numChannels', 'sampleSize',
|
||||
'compressionID', 'packetSize', ('sampleRate', _tofixed, _fromfixed), 'samplesPerPacket',
|
||||
'bytesPerPacket', 'bytesPerFrame', 'bytesPerSample'),
|
||||
"l4slhhhh4shhhhlllll" # Format
|
||||
1,
|
||||
52,
|
||||
('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex',
|
||||
'version', 'revlevel', 'vendor', 'numChannels', 'sampleSize',
|
||||
'compressionID', 'packetSize', ('sampleRate', _tofixed, _fromfixed), 'samplesPerPacket',
|
||||
'bytesPerPacket', 'bytesPerFrame', 'bytesPerSample'),
|
||||
"l4slhhhh4shhhhlllll" # Format
|
||||
)
|
||||
|
||||
ImageDescription = _MediaDescriptionCodec(
|
||||
1, # May be longer, truncate
|
||||
86, # size
|
||||
('idSize', 'cType', 'resvd1', 'resvd2', 'dataRefIndex', 'version',
|
||||
'revisionLevel', 'vendor', 'temporalQuality', 'spatialQuality',
|
||||
'width', 'height', ('hRes', _tofixed, _fromfixed), ('vRes', _tofixed, _fromfixed),
|
||||
'dataSize', 'frameCount', ('name', _tostr31, _fromstr31),
|
||||
'depth', 'clutID'),
|
||||
'l4slhhhh4sllhhlllh32shh',
|
||||
1, # May be longer, truncate
|
||||
86, # size
|
||||
('idSize', 'cType', 'resvd1', 'resvd2', 'dataRefIndex', 'version',
|
||||
'revisionLevel', 'vendor', 'temporalQuality', 'spatialQuality',
|
||||
'width', 'height', ('hRes', _tofixed, _fromfixed), ('vRes', _tofixed, _fromfixed),
|
||||
'dataSize', 'frameCount', ('name', _tostr31, _fromstr31),
|
||||
'depth', 'clutID'),
|
||||
'l4slhhhh4sllhhlllh32shh',
|
||||
)
|
||||
|
||||
# XXXX Others, like TextDescription and such, remain to be done.
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,9 @@
|
|||
"""MiniAEFrame - A minimal AppleEvent Application framework.
|
||||
|
||||
There are two classes:
|
||||
AEServer -- a mixin class offering nice AE handling.
|
||||
MiniApplication -- a very minimal alternative to FrameWork.py,
|
||||
only suitable for the simplest of AppleEvent servers.
|
||||
AEServer -- a mixin class offering nice AE handling.
|
||||
MiniApplication -- a very minimal alternative to FrameWork.py,
|
||||
only suitable for the simplest of AppleEvent servers.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
@ -21,179 +21,179 @@ from Carbon import Qd
|
|||
import aetools
|
||||
import EasyDialogs
|
||||
|
||||
kHighLevelEvent = 23 # Not defined anywhere for Python yet?
|
||||
kHighLevelEvent = 23 # Not defined anywhere for Python yet?
|
||||
|
||||
|
||||
class MiniApplication:
|
||||
|
||||
"""A minimal FrameWork.Application-like class"""
|
||||
"""A minimal FrameWork.Application-like class"""
|
||||
|
||||
def __init__(self):
|
||||
self.quitting = 0
|
||||
# Initialize menu
|
||||
self.appleid = 1
|
||||
self.quitid = 2
|
||||
Menu.ClearMenuBar()
|
||||
self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
|
||||
applemenu.AppendMenu("%s;(-" % self.getaboutmenutext())
|
||||
if MacOS.runtimemodel == 'ppc':
|
||||
applemenu.AppendResMenu('DRVR')
|
||||
applemenu.InsertMenu(0)
|
||||
self.quitmenu = Menu.NewMenu(self.quitid, "File")
|
||||
self.quitmenu.AppendMenu("Quit")
|
||||
self.quitmenu.SetItemCmd(1, ord("Q"))
|
||||
self.quitmenu.InsertMenu(0)
|
||||
Menu.DrawMenuBar()
|
||||
def __init__(self):
|
||||
self.quitting = 0
|
||||
# Initialize menu
|
||||
self.appleid = 1
|
||||
self.quitid = 2
|
||||
Menu.ClearMenuBar()
|
||||
self.applemenu = applemenu = Menu.NewMenu(self.appleid, "\024")
|
||||
applemenu.AppendMenu("%s;(-" % self.getaboutmenutext())
|
||||
if MacOS.runtimemodel == 'ppc':
|
||||
applemenu.AppendResMenu('DRVR')
|
||||
applemenu.InsertMenu(0)
|
||||
self.quitmenu = Menu.NewMenu(self.quitid, "File")
|
||||
self.quitmenu.AppendMenu("Quit")
|
||||
self.quitmenu.SetItemCmd(1, ord("Q"))
|
||||
self.quitmenu.InsertMenu(0)
|
||||
Menu.DrawMenuBar()
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def mainloop(self, mask = everyEvent, timeout = 60*60):
|
||||
while not self.quitting:
|
||||
self.dooneevent(mask, timeout)
|
||||
def mainloop(self, mask = everyEvent, timeout = 60*60):
|
||||
while not self.quitting:
|
||||
self.dooneevent(mask, timeout)
|
||||
|
||||
def _quit(self):
|
||||
self.quitting = 1
|
||||
def _quit(self):
|
||||
self.quitting = 1
|
||||
|
||||
def dooneevent(self, mask = everyEvent, timeout = 60*60):
|
||||
got, event = Evt.WaitNextEvent(mask, timeout)
|
||||
if got:
|
||||
self.lowlevelhandler(event)
|
||||
def dooneevent(self, mask = everyEvent, timeout = 60*60):
|
||||
got, event = Evt.WaitNextEvent(mask, timeout)
|
||||
if got:
|
||||
self.lowlevelhandler(event)
|
||||
|
||||
def lowlevelhandler(self, event):
|
||||
what, message, when, where, modifiers = event
|
||||
h, v = where
|
||||
if what == kHighLevelEvent:
|
||||
msg = "High Level Event: %s %s" % \
|
||||
(`code(message)`, `code(h | (v<<16))`)
|
||||
try:
|
||||
AE.AEProcessAppleEvent(event)
|
||||
except AE.Error, err:
|
||||
print 'AE error: ', err
|
||||
print 'in', msg
|
||||
traceback.print_exc()
|
||||
return
|
||||
elif what == keyDown:
|
||||
c = chr(message & charCodeMask)
|
||||
if modifiers & cmdKey:
|
||||
if c == '.':
|
||||
raise KeyboardInterrupt, "Command-period"
|
||||
if c == 'q':
|
||||
if hasattr(MacOS, 'OutputSeen'):
|
||||
MacOS.OutputSeen()
|
||||
self.quitting = 1
|
||||
return
|
||||
elif what == mouseDown:
|
||||
partcode, window = Win.FindWindow(where)
|
||||
if partcode == inMenuBar:
|
||||
result = Menu.MenuSelect(where)
|
||||
id = (result>>16) & 0xffff # Hi word
|
||||
item = result & 0xffff # Lo word
|
||||
if id == self.appleid:
|
||||
if item == 1:
|
||||
EasyDialogs.Message(self.getabouttext())
|
||||
elif item > 1 and hasattr(Menu, 'OpenDeskAcc'):
|
||||
name = self.applemenu.GetMenuItemText(item)
|
||||
Menu.OpenDeskAcc(name)
|
||||
elif id == self.quitid and item == 1:
|
||||
if hasattr(MacOS, 'OutputSeen'):
|
||||
MacOS.OutputSeen()
|
||||
self.quitting = 1
|
||||
Menu.HiliteMenu(0)
|
||||
return
|
||||
# Anything not handled is passed to Python/SIOUX
|
||||
if hasattr(MacOS, 'HandleEvent'):
|
||||
MacOS.HandleEvent(event)
|
||||
else:
|
||||
print "Unhandled event:", event
|
||||
def lowlevelhandler(self, event):
|
||||
what, message, when, where, modifiers = event
|
||||
h, v = where
|
||||
if what == kHighLevelEvent:
|
||||
msg = "High Level Event: %s %s" % \
|
||||
(`code(message)`, `code(h | (v<<16))`)
|
||||
try:
|
||||
AE.AEProcessAppleEvent(event)
|
||||
except AE.Error, err:
|
||||
print 'AE error: ', err
|
||||
print 'in', msg
|
||||
traceback.print_exc()
|
||||
return
|
||||
elif what == keyDown:
|
||||
c = chr(message & charCodeMask)
|
||||
if modifiers & cmdKey:
|
||||
if c == '.':
|
||||
raise KeyboardInterrupt, "Command-period"
|
||||
if c == 'q':
|
||||
if hasattr(MacOS, 'OutputSeen'):
|
||||
MacOS.OutputSeen()
|
||||
self.quitting = 1
|
||||
return
|
||||
elif what == mouseDown:
|
||||
partcode, window = Win.FindWindow(where)
|
||||
if partcode == inMenuBar:
|
||||
result = Menu.MenuSelect(where)
|
||||
id = (result>>16) & 0xffff # Hi word
|
||||
item = result & 0xffff # Lo word
|
||||
if id == self.appleid:
|
||||
if item == 1:
|
||||
EasyDialogs.Message(self.getabouttext())
|
||||
elif item > 1 and hasattr(Menu, 'OpenDeskAcc'):
|
||||
name = self.applemenu.GetMenuItemText(item)
|
||||
Menu.OpenDeskAcc(name)
|
||||
elif id == self.quitid and item == 1:
|
||||
if hasattr(MacOS, 'OutputSeen'):
|
||||
MacOS.OutputSeen()
|
||||
self.quitting = 1
|
||||
Menu.HiliteMenu(0)
|
||||
return
|
||||
# Anything not handled is passed to Python/SIOUX
|
||||
if hasattr(MacOS, 'HandleEvent'):
|
||||
MacOS.HandleEvent(event)
|
||||
else:
|
||||
print "Unhandled event:", event
|
||||
|
||||
def getabouttext(self):
|
||||
return self.__class__.__name__
|
||||
def getabouttext(self):
|
||||
return self.__class__.__name__
|
||||
|
||||
def getaboutmenutext(self):
|
||||
return "About %s\311" % self.__class__.__name__
|
||||
def getaboutmenutext(self):
|
||||
return "About %s\311" % self.__class__.__name__
|
||||
|
||||
|
||||
class AEServer:
|
||||
|
||||
def __init__(self):
|
||||
self.ae_handlers = {}
|
||||
def __init__(self):
|
||||
self.ae_handlers = {}
|
||||
|
||||
def installaehandler(self, classe, type, callback):
|
||||
AE.AEInstallEventHandler(classe, type, self.callback_wrapper)
|
||||
self.ae_handlers[(classe, type)] = callback
|
||||
def installaehandler(self, classe, type, callback):
|
||||
AE.AEInstallEventHandler(classe, type, self.callback_wrapper)
|
||||
self.ae_handlers[(classe, type)] = callback
|
||||
|
||||
def close(self):
|
||||
for classe, type in self.ae_handlers.keys():
|
||||
AE.AERemoveEventHandler(classe, type)
|
||||
def close(self):
|
||||
for classe, type in self.ae_handlers.keys():
|
||||
AE.AERemoveEventHandler(classe, type)
|
||||
|
||||
def callback_wrapper(self, _request, _reply):
|
||||
_parameters, _attributes = aetools.unpackevent(_request)
|
||||
_class = _attributes['evcl'].type
|
||||
_type = _attributes['evid'].type
|
||||
def callback_wrapper(self, _request, _reply):
|
||||
_parameters, _attributes = aetools.unpackevent(_request)
|
||||
_class = _attributes['evcl'].type
|
||||
_type = _attributes['evid'].type
|
||||
|
||||
if self.ae_handlers.has_key((_class, _type)):
|
||||
_function = self.ae_handlers[(_class, _type)]
|
||||
elif self.ae_handlers.has_key((_class, '****')):
|
||||
_function = self.ae_handlers[(_class, '****')]
|
||||
elif self.ae_handlers.has_key(('****', '****')):
|
||||
_function = self.ae_handlers[('****', '****')]
|
||||
else:
|
||||
raise 'Cannot happen: AE callback without handler', (_class, _type)
|
||||
if self.ae_handlers.has_key((_class, _type)):
|
||||
_function = self.ae_handlers[(_class, _type)]
|
||||
elif self.ae_handlers.has_key((_class, '****')):
|
||||
_function = self.ae_handlers[(_class, '****')]
|
||||
elif self.ae_handlers.has_key(('****', '****')):
|
||||
_function = self.ae_handlers[('****', '****')]
|
||||
else:
|
||||
raise 'Cannot happen: AE callback without handler', (_class, _type)
|
||||
|
||||
# XXXX Do key-to-name mapping here
|
||||
# XXXX Do key-to-name mapping here
|
||||
|
||||
_parameters['_attributes'] = _attributes
|
||||
_parameters['_class'] = _class
|
||||
_parameters['_type'] = _type
|
||||
if _parameters.has_key('----'):
|
||||
_object = _parameters['----']
|
||||
del _parameters['----']
|
||||
# The try/except that used to be here can mask programmer errors.
|
||||
# Let the program crash, the programmer can always add a **args
|
||||
# to the formal parameter list.
|
||||
rv = apply(_function, (_object,), _parameters)
|
||||
else:
|
||||
#Same try/except comment as above
|
||||
rv = apply(_function, (), _parameters)
|
||||
_parameters['_attributes'] = _attributes
|
||||
_parameters['_class'] = _class
|
||||
_parameters['_type'] = _type
|
||||
if _parameters.has_key('----'):
|
||||
_object = _parameters['----']
|
||||
del _parameters['----']
|
||||
# The try/except that used to be here can mask programmer errors.
|
||||
# Let the program crash, the programmer can always add a **args
|
||||
# to the formal parameter list.
|
||||
rv = _function(_object, **_parameters)
|
||||
else:
|
||||
#Same try/except comment as above
|
||||
rv = _function(**_parameters)
|
||||
|
||||
if rv == None:
|
||||
aetools.packevent(_reply, {})
|
||||
else:
|
||||
aetools.packevent(_reply, {'----':rv})
|
||||
if rv == None:
|
||||
aetools.packevent(_reply, {})
|
||||
else:
|
||||
aetools.packevent(_reply, {'----':rv})
|
||||
|
||||
|
||||
def code(x):
|
||||
"Convert a long int to the 4-character code it really is"
|
||||
s = ''
|
||||
for i in range(4):
|
||||
x, c = divmod(x, 256)
|
||||
s = chr(c) + s
|
||||
return s
|
||||
"Convert a long int to the 4-character code it really is"
|
||||
s = ''
|
||||
for i in range(4):
|
||||
x, c = divmod(x, 256)
|
||||
s = chr(c) + s
|
||||
return s
|
||||
|
||||
class _Test(AEServer, MiniApplication):
|
||||
"""Mini test application, handles required events"""
|
||||
"""Mini test application, handles required events"""
|
||||
|
||||
def __init__(self):
|
||||
MiniApplication.__init__(self)
|
||||
AEServer.__init__(self)
|
||||
self.installaehandler('aevt', 'oapp', self.open_app)
|
||||
self.installaehandler('aevt', 'quit', self.quit)
|
||||
self.installaehandler('****', '****', self.other)
|
||||
self.mainloop()
|
||||
def __init__(self):
|
||||
MiniApplication.__init__(self)
|
||||
AEServer.__init__(self)
|
||||
self.installaehandler('aevt', 'oapp', self.open_app)
|
||||
self.installaehandler('aevt', 'quit', self.quit)
|
||||
self.installaehandler('****', '****', self.other)
|
||||
self.mainloop()
|
||||
|
||||
def quit(self, **args):
|
||||
self._quit()
|
||||
def quit(self, **args):
|
||||
self._quit()
|
||||
|
||||
def open_app(self, **args):
|
||||
pass
|
||||
def open_app(self, **args):
|
||||
pass
|
||||
|
||||
def other(self, _object=None, _class=None, _type=None, **args):
|
||||
print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
|
||||
def other(self, _object=None, _class=None, _type=None, **args):
|
||||
print 'AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
_Test()
|
||||
_Test()
|
||||
|
|
|
@ -12,103 +12,103 @@ import aetools
|
|||
|
||||
class ArgvCollector:
|
||||
|
||||
"""A minimal FrameWork.Application-like class"""
|
||||
"""A minimal FrameWork.Application-like class"""
|
||||
|
||||
def __init__(self):
|
||||
self.quitting = 0
|
||||
self.ae_handlers = {}
|
||||
# Remove the funny -psn_xxx_xxx argument
|
||||
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
|
||||
del sys.argv[1]
|
||||
self.installaehandler('aevt', 'oapp', self.open_app)
|
||||
self.installaehandler('aevt', 'odoc', self.open_file)
|
||||
def __init__(self):
|
||||
self.quitting = 0
|
||||
self.ae_handlers = {}
|
||||
# Remove the funny -psn_xxx_xxx argument
|
||||
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
|
||||
del sys.argv[1]
|
||||
self.installaehandler('aevt', 'oapp', self.open_app)
|
||||
self.installaehandler('aevt', 'odoc', self.open_file)
|
||||
|
||||
def installaehandler(self, classe, type, callback):
|
||||
AE.AEInstallEventHandler(classe, type, self.callback_wrapper)
|
||||
self.ae_handlers[(classe, type)] = callback
|
||||
def installaehandler(self, classe, type, callback):
|
||||
AE.AEInstallEventHandler(classe, type, self.callback_wrapper)
|
||||
self.ae_handlers[(classe, type)] = callback
|
||||
|
||||
def close(self):
|
||||
for classe, type in self.ae_handlers.keys():
|
||||
AE.AERemoveEventHandler(classe, type)
|
||||
def close(self):
|
||||
for classe, type in self.ae_handlers.keys():
|
||||
AE.AERemoveEventHandler(classe, type)
|
||||
|
||||
def mainloop(self, mask = highLevelEventMask, timeout = 1*60):
|
||||
stoptime = Evt.TickCount() + timeout
|
||||
while not self.quitting and Evt.TickCount() < stoptime:
|
||||
self.dooneevent(mask, timeout)
|
||||
self.close()
|
||||
def mainloop(self, mask = highLevelEventMask, timeout = 1*60):
|
||||
stoptime = Evt.TickCount() + timeout
|
||||
while not self.quitting and Evt.TickCount() < stoptime:
|
||||
self.dooneevent(mask, timeout)
|
||||
self.close()
|
||||
|
||||
def _quit(self):
|
||||
self.quitting = 1
|
||||
def _quit(self):
|
||||
self.quitting = 1
|
||||
|
||||
def dooneevent(self, mask = highLevelEventMask, timeout = 1*60):
|
||||
got, event = Evt.WaitNextEvent(mask, timeout)
|
||||
if got:
|
||||
self.lowlevelhandler(event)
|
||||
def dooneevent(self, mask = highLevelEventMask, timeout = 1*60):
|
||||
got, event = Evt.WaitNextEvent(mask, timeout)
|
||||
if got:
|
||||
self.lowlevelhandler(event)
|
||||
|
||||
def lowlevelhandler(self, event):
|
||||
what, message, when, where, modifiers = event
|
||||
h, v = where
|
||||
if what == kHighLevelEvent:
|
||||
try:
|
||||
AE.AEProcessAppleEvent(event)
|
||||
except AE.Error, err:
|
||||
msg = "High Level Event: %s %s" % \
|
||||
(`hex(message)`, `hex(h | (v<<16))`)
|
||||
print 'AE error: ', err
|
||||
print 'in', msg
|
||||
traceback.print_exc()
|
||||
return
|
||||
else:
|
||||
print "Unhandled event:", event
|
||||
def lowlevelhandler(self, event):
|
||||
what, message, when, where, modifiers = event
|
||||
h, v = where
|
||||
if what == kHighLevelEvent:
|
||||
try:
|
||||
AE.AEProcessAppleEvent(event)
|
||||
except AE.Error, err:
|
||||
msg = "High Level Event: %s %s" % \
|
||||
(`hex(message)`, `hex(h | (v<<16))`)
|
||||
print 'AE error: ', err
|
||||
print 'in', msg
|
||||
traceback.print_exc()
|
||||
return
|
||||
else:
|
||||
print "Unhandled event:", event
|
||||
|
||||
def callback_wrapper(self, _request, _reply):
|
||||
_parameters, _attributes = aetools.unpackevent(_request)
|
||||
_class = _attributes['evcl'].type
|
||||
_type = _attributes['evid'].type
|
||||
def callback_wrapper(self, _request, _reply):
|
||||
_parameters, _attributes = aetools.unpackevent(_request)
|
||||
_class = _attributes['evcl'].type
|
||||
_type = _attributes['evid'].type
|
||||
|
||||
if self.ae_handlers.has_key((_class, _type)):
|
||||
_function = self.ae_handlers[(_class, _type)]
|
||||
elif self.ae_handlers.has_key((_class, '****')):
|
||||
_function = self.ae_handlers[(_class, '****')]
|
||||
elif self.ae_handlers.has_key(('****', '****')):
|
||||
_function = self.ae_handlers[('****', '****')]
|
||||
else:
|
||||
raise 'Cannot happen: AE callback without handler', (_class, _type)
|
||||
if self.ae_handlers.has_key((_class, _type)):
|
||||
_function = self.ae_handlers[(_class, _type)]
|
||||
elif self.ae_handlers.has_key((_class, '****')):
|
||||
_function = self.ae_handlers[(_class, '****')]
|
||||
elif self.ae_handlers.has_key(('****', '****')):
|
||||
_function = self.ae_handlers[('****', '****')]
|
||||
else:
|
||||
raise 'Cannot happen: AE callback without handler', (_class, _type)
|
||||
|
||||
# XXXX Do key-to-name mapping here
|
||||
# XXXX Do key-to-name mapping here
|
||||
|
||||
_parameters['_attributes'] = _attributes
|
||||
_parameters['_class'] = _class
|
||||
_parameters['_type'] = _type
|
||||
if _parameters.has_key('----'):
|
||||
_object = _parameters['----']
|
||||
del _parameters['----']
|
||||
# The try/except that used to be here can mask programmer errors.
|
||||
# Let the program crash, the programmer can always add a **args
|
||||
# to the formal parameter list.
|
||||
rv = apply(_function, (_object,), _parameters)
|
||||
else:
|
||||
#Same try/except comment as above
|
||||
rv = apply(_function, (), _parameters)
|
||||
_parameters['_attributes'] = _attributes
|
||||
_parameters['_class'] = _class
|
||||
_parameters['_type'] = _type
|
||||
if _parameters.has_key('----'):
|
||||
_object = _parameters['----']
|
||||
del _parameters['----']
|
||||
# The try/except that used to be here can mask programmer errors.
|
||||
# Let the program crash, the programmer can always add a **args
|
||||
# to the formal parameter list.
|
||||
rv = _function(_object, **_parameters)
|
||||
else:
|
||||
#Same try/except comment as above
|
||||
rv = _function(**_parameters)
|
||||
|
||||
if rv == None:
|
||||
aetools.packevent(_reply, {})
|
||||
else:
|
||||
aetools.packevent(_reply, {'----':rv})
|
||||
if rv == None:
|
||||
aetools.packevent(_reply, {})
|
||||
else:
|
||||
aetools.packevent(_reply, {'----':rv})
|
||||
|
||||
def open_app(self, **args):
|
||||
self._quit()
|
||||
def open_app(self, **args):
|
||||
self._quit()
|
||||
|
||||
def open_file(self, _object=None, **args):
|
||||
for alias in _object:
|
||||
fsr = alias.FSResolveAlias(None)[0]
|
||||
pathname = fsr.as_pathname()
|
||||
sys.argv.append(pathname)
|
||||
self._quit()
|
||||
def open_file(self, _object=None, **args):
|
||||
for alias in _object:
|
||||
fsr = alias.FSResolveAlias(None)[0]
|
||||
pathname = fsr.as_pathname()
|
||||
sys.argv.append(pathname)
|
||||
self._quit()
|
||||
|
||||
def other(self, _object=None, _class=None, _type=None, **args):
|
||||
print 'Ignore AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
|
||||
def other(self, _object=None, _class=None, _type=None, **args):
|
||||
print 'Ignore AppleEvent', (_class, _type), 'for', _object, 'Other args:', args
|
||||
|
||||
if __name__ == '__main__':
|
||||
ArgvCollector().mainloop()
|
||||
print "sys.argv=", sys.argv
|
||||
ArgvCollector().mainloop()
|
||||
print "sys.argv=", sys.argv
|
||||
|
|
|
@ -29,7 +29,7 @@ INSTALLATION
|
|||
|
||||
Put this file in your Python path, and create a file named {Python}:sitecustomize.py
|
||||
that contains:
|
||||
import icopen
|
||||
import icopen
|
||||
|
||||
(If {Python}:sitecustomizer.py already exists, just add the 'import' line to it.)
|
||||
|
||||
|
@ -42,18 +42,18 @@ import __builtin__
|
|||
_builtin_open = globals().get('_builtin_open', __builtin__.open)
|
||||
|
||||
def _open_with_typer(*args):
|
||||
file = apply(_builtin_open, args)
|
||||
filename = args[0]
|
||||
mode = 'r'
|
||||
if args[1:]:
|
||||
mode = args[1]
|
||||
if mode[0] == 'w':
|
||||
from ic import error, settypecreator
|
||||
try:
|
||||
settypecreator(filename)
|
||||
except error:
|
||||
pass
|
||||
return file
|
||||
file = _builtin_open(*args)
|
||||
filename = args[0]
|
||||
mode = 'r'
|
||||
if args[1:]:
|
||||
mode = args[1]
|
||||
if mode[0] == 'w':
|
||||
from ic import error, settypecreator
|
||||
try:
|
||||
settypecreator(filename)
|
||||
except error:
|
||||
pass
|
||||
return file
|
||||
|
||||
__builtin__.open = _open_with_typer
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ def timefunc(n, func, *args, **kw):
|
|||
t0 = time.clock()
|
||||
try:
|
||||
for i in range(n):
|
||||
result = apply(func, args, kw)
|
||||
result = func(*args, **kw)
|
||||
return result
|
||||
finally:
|
||||
t1 = time.clock()
|
||||
|
|
|
@ -26,7 +26,7 @@ def window_funcs(stdscr):
|
|||
for meth in [stdscr.addch, stdscr.addstr]:
|
||||
for args in [('a'), ('a', curses.A_BOLD),
|
||||
(4,4, 'a'), (5,5, 'a', curses.A_BOLD)]:
|
||||
apply(meth, args)
|
||||
meth(*args)
|
||||
|
||||
for meth in [stdscr.box, stdscr.clear, stdscr.clrtobot,
|
||||
stdscr.clrtoeol, stdscr.cursyncup, stdscr.delch,
|
||||
|
|
|
@ -1902,7 +1902,7 @@ def _get_StringIO():
|
|||
return StringIO()
|
||||
|
||||
def _do_pulldom_parse(func, args, kwargs):
|
||||
events = apply(func, args, kwargs)
|
||||
events = func(*args, **kwargs)
|
||||
toktype, rootNode = events.getEvent()
|
||||
events.expandNode(rootNode)
|
||||
events.clear()
|
||||
|
|
|
@ -112,7 +112,10 @@ PyDoc_STRVAR(apply_doc,
|
|||
\n\
|
||||
Call a callable object with positional arguments taken from the tuple args,\n\
|
||||
and keyword arguments taken from the optional dictionary kwargs.\n\
|
||||
Note that classes are callable, as are instances with a __call__() method.");
|
||||
Note that classes are callable, as are instances with a __call__() method.\n\
|
||||
\n\
|
||||
Deprecated since release 2.3. Instead, use the extended call syntax:\n\
|
||||
function(*args, **keywords).");
|
||||
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue