本文整理汇总了Python中color.Color.name方法的典型用法代码示例。如果您正苦于以下问题:Python Color.name方法的具体用法?Python Color.name怎么用?Python Color.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类color.Color
的用法示例。
在下文中一共展示了Color.name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from color import Color [as 别名]
# 或者: from color.Color import name [as 别名]
def load(self, filename):
"""
Load the palette from a file
The filename should be given as a the full path.
"""
self.colors = []
self.load_errors = []
self.filename = filename
try:
with open(filename) as f:
# Check that file is a palette file
if f.readline().strip() != 'GIMP Palette':
self.load_errors.append("Invalid file format.".format(filename))
return False
lineno = 0
for line in f:
lineno += 1
if line[0] == '#': continue
elif line[0:5] == 'Name:':
self.name = line[5:].strip()
elif line[0:8] == 'Columns:':
try:
self.columns = int(line[8:].strip())
except ValueError:
self.load_errors.append("Columns value (line {0}) must be integer. Using default value.".format(lineno))
self.columns = 0
else:
try:
r = int(line[0:3])
g = int(line[4:7])
b = int(line[8:11])
cname = line[12:].strip()
c = Color()
c.name = cname
c.set_rgb(r,g,b)
self.colors.append(c)
except: #XXX handle specific exceptions only
self.load_errors.append("Invalid color entry on line {0}. Skipping.\n".format(lineno))
self.emit('changed')
except IOError:
#if nonexistant filename is passed in, assume we want to save to that in the future
pass
return (len(self.load_errors) == 0)