def __init__(self, *args, **kwargs):
# Set by the subclass in create_preorder/create_postorder
self.w = None # the wx.Window, if any, being created
self.sized = None # the wx.Sizer or wx.Window which the parent Entity must put in its component sizer
self._events = []
self._queue = []
if _zparent is not None:
_zparent._queue.append(self)
# Set attributes in accordance with the rules for the class set out in 'props', the list of allowed
# __init__ arguments, and 'positional', the subset that can be passed as positional parameters.
if len(args) > len(self.positional):
raise TypeError("%s takes positional arguments %s, %d more given" % (self, self.positional, len(args)-len(self.positional)))
if 'kwargs' in self.props:
self.kwargs = {}
for k,v in dict(self._defaults, **kwargs).items():
if k in self.props:
setattr(self, k, v)
else:
if k.startswith('EVT_') and isinstance(self, Window):
self._events.append((k, v))
elif 'kwargs' in self.props:
self.kwargs[k] = v
else:
raise TypeError("%s does not have a writable '%s' attribute" % (type(self), k))
for argname,arg in zip(self.positional, args):
if argname in kwargs:
raise TypeError("%s passed both by keyword and as positional argument %d" % (argname,self.positional.index(argname)+1))
assert argname in self.props
setattr(self, argname, arg)
# Hierarchy management:
self._entered = False # has __enter__/__exit__, which sets .w and .sized, been done yet?
self.zparent = _zparent # above Entity
self.zchildren = [] # Entity's nested below
if self.zparent is not None:
self.zparent.zchildren.append(self)
if self.parent is None and self.zparent is None:
assert isinstance(self, (TopLevelWindow,TopLevelMenu)), '%s does not have a parent' % (self,)
评论列表
文章目录