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() gtk.gdk.threads_enter()
try: try:
self.hud_dict[table_name].update(new_hand_id, config) self.hud_dict[table_name].update(new_hand_id, config)
for m in self.hud_dict[table_name].aux_windows: map(lambda aw: aw.update_gui(new_hand_id), self.hud_dict[table_name].aux_windows)
m.update_gui(new_hand_id)
return False return False
finally: finally:
gtk.gdk.threads_leave() gtk.gdk.threads_leave()

View File

@ -193,13 +193,11 @@ class Hud:
s.window.destroy() s.window.destroy()
self.stat_windows = {} self.stat_windows = {}
# also kill any aux windows # also kill any aux windows
for m in self.aux_windows: map(lambda m: m.destroy(), self.aux_windows)
m.destroy()
self.aux_windows = [] self.aux_windows = []
def reposition_windows(self, *args): def reposition_windows(self, *args):
for w in self.stat_windows: map(lambda x: x.window.move(x.x, x.y), self.stat_windows)
self.stat_windows[w].window.move(self.stat_windows[w].x, self.stat_windows[w].y)
return True return True
def debug_stat_windows(self, *args): def debug_stat_windows(self, *args):
@ -239,7 +237,7 @@ class Hud:
return adj return adj
def get_actual_seat(self, name): 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: if self.stat_dict[key]['screen_name'] == name:
return self.stat_dict[key]['seat'] return self.stat_dict[key]['seat']
sys.stderr.write("Error finding actual seat.\n") sys.stderr.write("Error finding actual seat.\n")
@ -369,8 +367,7 @@ class Stat_Window:
self.popups.remove(popup) self.popups.remove(popup)
def kill_popups(self): def kill_popups(self):
for x in self.popups: map(lambda x: x.window.destroy(), self.popups)
self.popups[x].window.destroy()
self.popups = { } self.popups = { }
def relocate(self, x, y): def relocate(self, x, y):
@ -406,35 +403,38 @@ class Stat_Window:
self.e_box = [] self.e_box = []
self.frame = [] self.frame = []
self.label = [] self.label = []
usegtkframes = self.useframes
e_box = self.e_box
label = self.label
for r in xrange(self.game.rows): for r in xrange(self.game.rows):
if self.useframes: if usegtkframes:
self.frame.append([]) self.frame.append([])
self.e_box.append([]) e_box.append([])
self.label.append([]) label.append([])
for c in xrange(self.game.cols): for c in xrange(self.game.cols):
if self.useframes: if usegtkframes:
self.frame[r].append( gtk.Frame() ) 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) 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_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
Stats.do_tip(self.e_box[r][c], 'stuff') Stats.do_tip(e_box[r][c], 'stuff')
if self.useframes: if usegtkframes:
self.grid.attach(self.frame[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0) 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: else:
self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0) self.grid.attach(e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
self.label[r].append( gtk.Label('xxx') ) label[r].append( gtk.Label('xxx') )
if self.useframes: if usegtkframes:
self.frame[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) self.frame[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.label[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) 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_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
self.e_box[r][c].add(self.label[r][c]) e_box[r][c].add(self.label[r][c])
self.e_box[r][c].connect("button_press_event", self.button_press_cb) e_box[r][c].connect("button_press_event", self.button_press_cb)
self.label[r][c].modify_font(font) label[r][c].modify_font(font)
self.window.set_opacity(parent.colors['hudopacity']) 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 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]) self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
for dir in self.addToDirList: self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList)
self.addImportDirectory(dir, True, self.addToDirList[dir][0], self.addToDirList[dir][1])
for file in self.removeFromFileList: for file in self.removeFromFileList:
if file in self.filelist: if file in self.filelist:
@ -294,7 +293,7 @@ class Importer:
partial=0 #counter partial=0 #counter
errors=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): if (len(self.lines[i])<2):
endpos=i endpos=i
hand=self.lines[startpos:endpos] hand=self.lines[startpos:endpos]