use some lambda map/filter calls where they make sense instead of for loops

localize some variables in the HUD update function
This commit is contained in:
eblade 2009-03-08 16:28:09 -04:00
parent 1b6337365f
commit 635d59b25d
3 changed files with 30 additions and 32 deletions

View File

@ -123,8 +123,7 @@ class HUD_main(object):
gtk.gdk.threads_enter()
try:
self.hud_dict[table_name].update(new_hand_id, config)
for m in self.hud_dict[table_name].aux_windows:
m.update_gui(new_hand_id)
map(lambda aw: aw.update_gui(new_hand_id), self.hud_dict[table_name].aux_windows)
return False
finally:
gtk.gdk.threads_leave()

View File

@ -191,15 +191,13 @@ class Hud:
for s in self.stat_windows.itervalues():
s.kill_popups()
s.window.destroy()
self.stat_windows = {}
self.stat_windows = {}
# also kill any aux windows
for m in self.aux_windows:
m.destroy()
map(lambda m: m.destroy(), self.aux_windows)
self.aux_windows = []
def reposition_windows(self, *args):
for w in self.stat_windows:
self.stat_windows[w].window.move(self.stat_windows[w].x, self.stat_windows[w].y)
map(lambda x: x.window.move(x.x, x.y), self.stat_windows)
return True
def debug_stat_windows(self, *args):
@ -239,7 +237,7 @@ class Hud:
return adj
def get_actual_seat(self, name):
for key in self.stat_dict.keys():
for key in self.stat_dict:
if self.stat_dict[key]['screen_name'] == name:
return self.stat_dict[key]['seat']
sys.stderr.write("Error finding actual seat.\n")
@ -369,8 +367,7 @@ class Stat_Window:
self.popups.remove(popup)
def kill_popups(self):
for x in self.popups:
self.popups[x].window.destroy()
map(lambda x: x.window.destroy(), self.popups)
self.popups = { }
def relocate(self, x, y):
@ -406,35 +403,38 @@ class Stat_Window:
self.e_box = []
self.frame = []
self.label = []
usegtkframes = self.useframes
e_box = self.e_box
label = self.label
for r in xrange(self.game.rows):
if self.useframes:
if usegtkframes:
self.frame.append([])
self.e_box.append([])
self.label.append([])
e_box.append([])
label.append([])
for c in xrange(self.game.cols):
if self.useframes:
if usegtkframes:
self.frame[r].append( gtk.Frame() )
self.e_box[r].append( gtk.EventBox() )
e_box[r].append( gtk.EventBox() )
self.e_box[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.e_box[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
e_box[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
e_box[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
Stats.do_tip(self.e_box[r][c], 'stuff')
if self.useframes:
Stats.do_tip(e_box[r][c], 'stuff')
if usegtkframes:
self.grid.attach(self.frame[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
self.frame[r][c].add(self.e_box[r][c])
self.frame[r][c].add(e_box[r][c])
else:
self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
self.label[r].append( gtk.Label('xxx') )
self.grid.attach(e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
label[r].append( gtk.Label('xxx') )
if self.useframes:
if usegtkframes:
self.frame[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.label[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.label[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
label[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
label[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
self.e_box[r][c].add(self.label[r][c])
self.e_box[r][c].connect("button_press_event", self.button_press_cb)
self.label[r][c].modify_font(font)
e_box[r][c].add(self.label[r][c])
e_box[r][c].connect("button_press_event", self.button_press_cb)
label[r][c].modify_font(font)
self.window.set_opacity(parent.colors['hudopacity'])

View File

@ -202,8 +202,7 @@ class Importer:
if (time() - stat_info.st_mtime) < 60 or os.path.isdir(file): # TODO: figure out a way to dispatch this to the seperate thread so our main window doesn't lock up on initial import
self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
for dir in self.addToDirList:
self.addImportDirectory(dir, True, self.addToDirList[dir][0], self.addToDirList[dir][1])
self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList)
for file in self.removeFromFileList:
if file in self.filelist:
@ -294,7 +293,7 @@ class Importer:
partial=0 #counter
errors=0 #counter
for i in range (len(self.lines)): #main loop, iterates through the lines of a file and calls the appropriate parser method
for i in xrange (len(self.lines)): #main loop, iterates through the lines of a file and calls the appropriate parser method
if (len(self.lines[i])<2):
endpos=i
hand=self.lines[startpos:endpos]