use a hash for list of textures

This commit is contained in:
Jon Dowland 2008-01-29 22:09:18 +00:00
parent 041489d0b4
commit 8ed2e1638c

View file

@ -22,7 +22,7 @@ class HellowWorldGTK:
def parse_texture_file(self,fname): def parse_texture_file(self,fname):
texture1 = file(fname, "r").read() texture1 = file(fname, "r").read()
self.textures = [] self.textures = {}
textures = self.textures textures = self.textures
current = None current = None
for line in texture1.split("\n"): for line in texture1.split("\n"):
@ -34,7 +34,7 @@ class HellowWorldGTK:
else: else:
line = line.split() line = line.split()
current = Texture(line[0],line[1],line[2]) current = Texture(line[0],line[1],line[2])
textures.append(current) textures[line[0]] = current
def __init__(self): def __init__(self):
self.gladefile = "cleanroom.glade" self.gladefile = "cleanroom.glade"
@ -45,8 +45,8 @@ class HellowWorldGTK:
self.parse_texture_file("combined.txt") self.parse_texture_file("combined.txt")
lhs = self.wTree.get_widget("texture_list") lhs = self.wTree.get_widget("texture_list")
treestore = gtk.TreeStore(str) treestore = gtk.TreeStore(str)
for texture in self.textures: for name in self.textures.keys():
treestore.append(None, [ texture.name ]) treestore.append(None, [ name ])
column = gtk.TreeViewColumn('Texture name ') column = gtk.TreeViewColumn('Texture name ')
lhs.set_model(treestore) lhs.set_model(treestore)
lhs.append_column(column) lhs.append_column(column)
@ -57,13 +57,13 @@ class HellowWorldGTK:
# set the progress bar up # set the progress bar up
# by default we've "done" all the 1-patch textures # by default we've "done" all the 1-patch textures
bar = self.wTree.get_widget("progressbar1") bar = self.wTree.get_widget("progressbar1")
done = len(filter(lambda x: len(x.patches) > 1, self.textures)) done = len(filter(lambda x: len(x.patches) > 1, self.textures.values()))
bar.set_fraction(float(done) / len(self.textures)) bar.set_fraction(float(done) / len(self.textures))
bar.set_text("%d/%d" % (done, len(self.textures))) bar.set_text("%d/%d" % (done, len(self.textures)))
# parse the example texture, fetch the width,height; # parse the example texture, fetch the width,height;
# create Patch objects and stuff them into a list # create Patch objects and stuff them into a list
texture = filter(lambda x: x.name == "COMPUTE2", self.textures)[0] texture = self.textures["COMPUTE2"]
# read the patches into pixbufs # read the patches into pixbufs
# a horrid hack to get them client->server side # a horrid hack to get them client->server side