本文整理汇总了Python中group.Group.add方法的典型用法代码示例。如果您正苦于以下问题:Python Group.add方法的具体用法?Python Group.add怎么用?Python Group.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类group.Group
的用法示例。
在下文中一共展示了Group.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from group import Group [as 别名]
# 或者: from group.Group import add [as 别名]
class Game:
def __init__(self, world, datadir, configdir):
self.world = world
self.datadir = datadir
self.configdir = configdir
self.enemies = []
self.stage = Stage(self)
self.sprites = Group(self.stage)
self.screen = world.screen
# Visor de energia para el enemigo
self._create_player()
self.energy = Energy(10, 10, 100, 10)
self.energy.set_model(self.player.id)
self.stage.player = self.player
self.stage.load_level(1)
if VISIBLE_DEBUG:
# Visor de rendimiento
self.text = Text(world.font, world.fps, "FPS: %d")
def _create_player(self):
control = Control(0, self.configdir)
self.player = Player(self, control, self.sprites, self.datadir)
shadow_player = Shadow(self.player, self.datadir)
self.sprites.add([self.player, shadow_player])
def update(self):
self.stage.update()
self.sprites.update()
self.energy.update()
if VISIBLE_DEBUG:
self.text.update()
if DEBUG:
b1, b2, b3 = pygame.mouse.get_pressed()
if b1:
self.stage.do_camera_effect()
elif b2:
self.stage.do_camera_effect(10)
elif b3:
self.world.fps.slow()
def draw(self):
self.stage.draw(self.screen)
self.sprites.draw(self.screen)
self.screen.blit(self.energy.image, self.energy.rect)
if VISIBLE_DEBUG:
self.screen.blit(self.text.image, self.text.rect)
pygame.display.flip()
示例2: _set_value
# 需要导入模块: from group import Group [as 别名]
# 或者: from group.Group import add [as 别名]
def _set_value(self, record, value, default=False):
from group import Group
if not value or (len(value) and isinstance(value[0], (int, long))):
mode = 'list ids'
else:
mode = 'list values'
group = record.value.get(self.name)
fields = {}
if group is not None:
fields = group.fields.copy()
# Unconnect to prevent infinite loop
group.signal_unconnect(group)
group.destroy()
elif record.model_name == self.attrs['relation']:
fields = record.group.fields
if fields:
fields = dict((fname, field.attrs)
for fname, field in fields.iteritems())
if mode == 'list values' and len(value):
context = self.context_get(record)
field_names = set(f for v in value for f in v if f not in fields)
if field_names:
try:
fields.update(RPCExecute('model', self.attrs['relation'],
'fields_get', list(field_names),
main_iteration=False, context=context))
except RPCException:
return
parent_name = self.attrs.get('relation_field', '')
group = Group(self.attrs['relation'], fields,
parent=record, parent_name=parent_name,
child_name=self.name,
context=self.context,
parent_datetime_field=self.attrs.get('datetime_field'))
record.value[self.name] = group
if mode == 'list ids':
group.load(value)
else:
for vals in value:
new_record = record.value[self.name].new(default=False)
if default:
new_record.set_default(vals)
group.add(new_record)
else:
new_record.id *= -1 # Don't consider record as unsaved
new_record.set(vals)
group.append(new_record)
group.signal_connect(group, 'group-changed', self._group_changed)
group.signal_connect(group, 'group-list-changed',
self._group_list_changed)
group.signal_connect(group, 'group-cleared', self._group_cleared)
group.signal_connect(group, 'record-modified', self._record_modified)
return group
示例3: set_default
# 需要导入模块: from group import Group [as 别名]
# 或者: from group.Group import add [as 别名]
def set_default(self, record, value, modified=False):
from group import Group
# value is a list of id
if value and len(value) and isinstance(value[0], (int, long)):
return self.set(record, value, modified=modified)
group = record.value.get(self.name)
fields = {}
if group is not None:
fields = group.fields.copy()
# Unconnect to prevent infinite loop
group.signal_unconnect(group)
group.destroy()
elif record.model_name == self.attrs['relation']:
fields = record.group.fields
if fields:
fields = dict((fname, field.attrs)
for fname, field in fields.iteritems())
if value and len(value):
context = self.context_get(record)
field_names = []
for val in value:
for fieldname in val.keys():
if (fieldname not in field_names
and fieldname not in fields):
field_names.append(fieldname)
if field_names:
try:
fields.update(RPCExecute('model', self.attrs['relation'],
'fields_get', field_names, context=context))
except RPCException:
return False
parent_name = self.attrs.get('relation_field', '')
group = Group(self.attrs['relation'], fields,
parent=record, parent_name=parent_name, child_name=self.name,
context=self.context,
parent_datetime_field=self.attrs.get('datetime_field'))
if record.value.get(self.name):
group.record_deleted.extend(x for x in record.value[self.name]
if x.id >= 0)
group.record_deleted.extend(record.value[self.name].record_deleted)
group.record_removed.extend(record.value[self.name].record_removed)
record.value[self.name] = group
for vals in (value or []):
new_record = record.value[self.name].new(default=False)
new_record.set_default(vals, modified=modified)
group.add(new_record)
group.signal_connect(group, 'group-changed', self._group_changed)
group.signal_connect(group, 'group-list-changed',
self._group_list_changed)
group.signal_connect(group, 'group-cleared', self._group_cleared)
group.signal_connect(group, 'record-modified', self._record_modified)
return True