本文整理汇总了Python中pyjamas.Factory.lookupClass方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.lookupClass方法的具体用法?Python Factory.lookupClass怎么用?Python Factory.lookupClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.Factory
的用法示例。
在下文中一共展示了Factory.lookupClass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addItem
# 需要导入模块: from pyjamas import Factory [as 别名]
# 或者: from pyjamas.Factory import lookupClass [as 别名]
def addItem(comp, props, childs, parentInstance, eventTarget):
klsname = comp['name']
modname = comp.get('module')
if modname is None:
modname = '.'.join(["pyjamas.ui", klsname])
kls = Factory.lookupClass('.'.join([modname, klsname]))
args = {}
wprops = {}
if props.has_key("common"):
wprops.update(props['common'])
if props.has_key("widget"):
wprops.update(props['widget'])
for n in kls._getProps():
name = n[ui.PROP_NAME]
if not wprops.has_key(name):
continue
fname = n[ui.PROP_FNAM]
if wprops[name] == '':
continue
args[fname] = wprops[name]
# create item with properties including weird ones
# which can't fit into the name value structure
item = kls(**args)
if hasattr(item, "_setWeirdProps"):
item._setWeirdProps(wprops, BuilderState(self, eventTarget))
tooltip = wprops.get('tooltip')
if tooltip is not None:
item.addMouseListener(TooltipListener(tooltip))
identifier = comp['id']
widget_order.append(identifier)
widgets_by_name[identifier] = klsname
widget_instances[identifier] = item
l = widgets_by_class.get(klsname, [])
l.append(identifier)
widgets_by_class[klsname] = l
#if parentInstance is not None:
# context = parentInstance.getIndexedChild(comp['index'])
# context.add(item.componentInstance)
for (index, child) in enumerate(childs):
if not child[0].has_key("type") or child[0]["type"] is None:
continue
childitem = addItem(child[0], child[1], child[2], item,
eventTarget)
if childitem is None:
continue
print "childitem", childitem
item.addIndexedItem(child[0]["index"], childitem)
if not "elements" in props:
props["elements"] = {}
if not index in props["elements"]:
props["elements"][index] = {}
elemprops = props['elements'][index]
print "elemprops", childitem, item, elemprops
item.setElementProperties(childitem, elemprops)
# add child (by name) to item
cname = child[0]["id"]
setattr(item, cname, childitem)
# make the event target the recipient of all events
if eventTarget is not None and props.has_key("events"):
added_already = []
#print props["events"]
for listener_name, listener_fn in props["events"].items():
if listener_name in added_already or not listener_fn:
continue
args = {}
args[listener_name] = listener_fn
fname = eventListeners[listener_name][0]
listener = MultiListener(eventTarget, **args)
setattr(item, "_%sListener" % fname, listener)
#print "add listener", listener_name, fname
listen_add_fn = getattr(item, fname)
listen_add_fn(listener)
return item