本文整理汇总了Python中srctools.Property.append方法的典型用法代码示例。如果您正苦于以下问题:Python Property.append方法的具体用法?Python Property.append怎么用?Python Property.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类srctools.Property
的用法示例。
在下文中一共展示了Property.append方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_curr_settings
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import append [as 别名]
def get_curr_settings() -> Property:
"""Return a property tree defining the current options."""
props = Property('', [])
for opt_id, opt_func in option_handler.items():
opt_prop = opt_func() # type: Property
opt_prop.name = opt_id.title()
props.append(opt_prop)
return props
示例2: save
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import append [as 别名]
def save(self, ignore_readonly=False):
"""Save the palette file into the specified location.
If ignore_readonly is true, this will ignore the `prevent_overwrite`
property of the palette (allowing resaving those properties over old
versions). Otherwise those palettes always create a new file.
"""
LOGGER.info('Saving "{}"!', self.name)
props = Property(None, [
Property('Name', self.name),
Property('TransName', self.trans_name),
Property('ReadOnly', srctools.bool_as_int(self.prevent_overwrite)),
Property('Items', [
Property(item_id, str(subitem))
for item_id, subitem in self.pos
])
])
# If default, don't include in the palette file.
# Remove the translated name, in case it's not going to write
# properly to the file.
if self.trans_name:
props['Name'] = ''
else:
del props['TransName']
if not self.prevent_overwrite:
del props['ReadOnly']
if self.settings is not None:
self.settings.name = 'Settings'
props.append(self.settings.copy())
# We need to write a new file, determine a valid path.
# Use a hash to ensure it's a valid path (without '-' if negative)
# If a conflict occurs, add ' ' and hash again to get a different
# value.
if self.filename is None or (self.prevent_overwrite and not ignore_readonly):
hash_src = self.name
while True:
hash_filename = str(abs(hash(hash_src))) + PAL_EXT
if os.path.isfile(hash_filename):
# Add a random character to iterate the hash.
hash_src += chr(random.randrange(0x10ffff))
else:
file = open(os.path.join(PAL_DIR, hash_filename), 'w', encoding='utf8')
self.filename = os.path.join(PAL_DIR, hash_filename)
break
else:
file = open(os.path.join(PAL_DIR, self.filename), 'w', encoding='utf8')
with file:
for line in props.export():
file.write(line)
示例3: _parse_block
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import append [as 别名]
def _parse_block(tok: Tokenizer, name: str) -> Property:
"""Parse a block into a block of properties."""
prop = Property(name, [])
for token, param_name in tok:
# End of our block
if token is Tok.BRACE_CLOSE:
return prop
elif token is Tok.NEWLINE:
continue
elif token is not Tok.STRING:
raise tok.error(token)
token, param_value = tok()
if token is Tok.STRING:
# We have the value.
pass
elif token is Tok.NEWLINE:
# Name by itself: '%compilenodraw' etc...
# We need to check there's a newline after that - for subblocks.
token, ignored = tok()
while token is Tok.NEWLINE:
token, ignored = tok()
if token is Tok.BRACE_OPEN:
prop.append(Material._parse_block(tok, param_name))
continue
elif token is Tok.NEWLINE:
pass
elif token is Tok.BRACE_CLOSE:
# End of us after single name.
prop.append(Property(param_name, ''))
break
else:
raise tok.error(token)
else:
raise tok.error(token)
prop.append(Property(param_name, param_value))
raise tok.error('EOF without closed block!')
示例4: save_load_itemvar
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import append [as 别名]
def save_load_itemvar(prop: Property=None) -> Optional[Property]:
"""Save or load item variables into the palette."""
if prop is None:
prop = Property('', [])
for group in CONFIG_ORDER:
conf = Property(group.id, [])
for widget in group.widgets: # ItemVariant special case.
if widget.values is not None:
conf.append(Property(widget.id, widget.values.get()))
for widget in group.multi_widgets:
conf.append(Property(widget.id, [
Property(str(tim_val), var.get())
for tim_val, var in
widget.values
]))
prop.append(conf)
return prop
else:
# Loading.
for group in CONFIG_ORDER:
conf = prop.find_key(group.id, [])
for widget in group.widgets:
if widget.values is not None: # ItemVariants
try:
widget.values.set(conf[widget.id])
except LookupError:
pass
for widget in group.multi_widgets:
time_conf = conf.find_key(widget.id, [])
for tim_val, var in widget.values:
try:
var.set(time_conf[str(tim_val)])
except LookupError:
pass
return None
示例5: build_instance_data
# 需要导入模块: from srctools import Property [as 别名]
# 或者: from srctools.Property import append [as 别名]
def build_instance_data(editoritems: Property):
"""Build a property tree listing all of the instances for each item.
as well as another listing the input and output commands.
VBSP uses this to reduce duplication in VBSP_config files.
This additionally strips custom instance definitions from the original
list.
"""
instance_locs = Property("AllInstances", [])
cust_inst = Property("CustInstances", [])
commands = Property("Connections", [])
item_classes = Property("ItemClasses", [])
root_block = Property(None, [instance_locs, item_classes, cust_inst, commands])
for item in editoritems.find_all("Item"):
instance_block = Property(item["Type"], [])
instance_locs.append(instance_block)
comm_block = Property(item["Type"], [])
for inst_block in item.find_all("Exporting", "instances"):
for inst in inst_block.value[:]: # type: Property
if inst.name.isdigit():
# Direct Portal 2 value
instance_block.append(Property("Instance", inst["Name"]))
else:
# It's a custom definition, remove from editoritems
inst_block.value.remove(inst)
# Allow the name to start with 'bee2_' also to match
# the <> definitions - it's ignored though.
name = inst.name
if name[:5] == "bee2_":
name = name[5:]
cust_inst.set_key(
(item["type"], name),
# Allow using either the normal block format,
# or just providing the file - we don't use the
# other values.
inst["name"] if inst.has_children() else inst.value,
)
# Look in the Inputs and Outputs blocks to find the io definitions.
# Copy them to property names like 'Input_Activate'.
for io_type in ("Inputs", "Outputs"):
for block in item.find_all("Exporting", io_type, CONN_NORM):
for io_prop in block:
comm_block[io_type[:-1] + "_" + io_prop.real_name] = io_prop.value
# The funnel item type is special, having the additional input type.
# Handle that specially.
if item["type"] == "item_tbeam":
for block in item.find_all("Exporting", "Inputs", CONN_FUNNEL):
for io_prop in block:
comm_block["TBEAM_" + io_prop.real_name] = io_prop.value
# Fizzlers don't work correctly with outputs. This is a signal to
# conditions.fizzler, but it must be removed in editoritems.
if item["ItemClass", ""].casefold() == "itembarrierhazard":
for block in item.find_all("Exporting", "Outputs"):
if CONN_NORM in block:
del block[CONN_NORM]
# Record the itemClass for each item type.
item_classes[item["type"]] = item["ItemClass", "ItemBase"]
# Only add the block if the item actually has IO.
if comm_block.value:
commands.append(comm_block)
return root_block.export()