diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py old mode 100644 new mode 100755 index 2af44b7d..81645694 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -32,6 +32,13 @@ import shutil import xml.dom.minidom from xml.dom.minidom import Node +def fix_tf(x): + if x == "1" or x == 1 or string.lower(x) == "true" or string.lower(x) == "t": + return True + if x == "0" or x == 0 or string.lower(x) == "false" or string.lower(x) == "f": + return False + return False + class Layout: def __init__(self, node): @@ -205,9 +212,18 @@ class Import: self.interval = node.getAttribute("interval") self.callFpdbHud = node.getAttribute("callFpdbHud") self.hhArchiveBase = node.getAttribute("hhArchiveBase") + if node.hasAttribute("saveActions"): + self.saveActions = fix_tf(node.getAttribute("saveActions")) + else: + self.saveActions = True + if node.hasAttribute("fastStoreHudCache"): + self.fastStoreHudCache = fix_tf(node.getAttribute("fastStoreHudCache")) + else: + self.fastStoreHudCache = False def __str__(self): - return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s" % (self.interval, self.callFpdbHud, self.hhArchiveBase) + return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s\n saveActions = %s\n fastStoreHudCache = %s\n" \ + % (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.saveActions) class Tv: def __init__(self, node): @@ -391,9 +407,14 @@ class Config: return layout_node def get_location_node(self, layout_node, seat): - for location_node in layout_node.getElementsByTagName("location"): - if int( location_node.getAttribute("seat") ) == int( seat ): - return location_node + if seat == "common": + for location_node in layout_node.getElementsByTagName("location"): + if location_node.hasAttribute("common"): + return location_node + else: + for location_node in layout_node.getElementsByTagName("location"): + if int( location_node.getAttribute("seat") ) == int( seat ): + return location_node def save(self, file = None): if not file == None: @@ -420,29 +441,42 @@ class Config: def edit_aux_layout(self, aux_name, max, width = None, height = None, locations = None): aux_node = self.get_aux_node(aux_name) layout_node = self.get_layout_node(aux_node, max) - if layout_node == None: return - for i in range(1, max + 1): + if layout_node == None: + print "aux node not found" + return + print "editing locations =", locations + for (i, pos) in locations.iteritems(): location_node = self.get_location_node(layout_node, i) - location_node.setAttribute("x", str( locations[i-1][0] )) - location_node.setAttribute("y", str( locations[i-1][1] )) - self.aux_windows[aux_name].layout[max].location[i] = ( locations[i-1][0], locations[i-1][1] ) + location_node.setAttribute("x", str( locations[i][0] )) + location_node.setAttribute("y", str( locations[i][1] )) + if i == "common": + self.aux_windows[aux_name].layout[max].common = ( locations[i][0], locations[i][1] ) + else: + self.aux_windows[aux_name].layout[max].location[i] = ( locations[i][0], locations[i][1] ) def get_db_parameters(self, name = None): if name == None: name = 'fpdb' db = {} - try: - db['db-databaseName'] = name - db['db-host'] = self.supported_databases[name].db_ip - db['db-user'] = self.supported_databases[name].db_user - db['db-password'] = self.supported_databases[name].db_pass - db['db-server'] = self.supported_databases[name].db_server - if string.lower(self.supported_databases[name].db_server) == 'mysql': - db['db-backend'] = 2 - elif string.lower(self.supported_databases[name].db_server) == 'postgresql': - db['db-backend'] = 3 - else: db['db-backend'] = None # this is big trouble - except: - pass + try: db['db-databaseName'] = name + except: pass + + try: db['db-host'] = self.supported_databases[name].db_ip + except: pass + + try: db['db-user'] = self.supported_databases[name].db_user + except: pass + + try: db['db-password'] = self.supported_databases[name].db_pass + except: pass + + try: db['db-server'] = self.supported_databases[name].db_server + except: pass + + if string.lower(self.supported_databases[name].db_server) == 'mysql': + db['db-backend'] = 2 + elif string.lower(self.supported_databases[name].db_server) == 'postgresql': + db['db-backend'] = 3 + else: db['db-backend'] = None # this is big trouble return db def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None, @@ -464,26 +498,32 @@ class Config: def get_tv_parameters(self): tv = {} - try: - tv['combinedStealFold'] = self.tv.combinedStealFold - tv['combined2B3B'] = self.tv.combined2B3B - tv['combinedPostflop'] = self.tv.combinedPostflop - except: # Default tv parameters - tv['combinedStealFold'] = True - tv['combined2B3B'] = True - tv['combinedPostflop'] = True + try: tv['combinedStealFold'] = self.tv.combinedStealFold + except: tv['combinedStealFold'] = True + + try: tv['combined2B3B'] = self.tv.combined2B3B + except: tv['combined2B3B'] = True + + try: tv['combinedPostflop'] = self.tv.combinedPostflop + except: tv['combinedPostflop'] = True return tv def get_import_parameters(self): imp = {} - try: - imp['callFpdbHud'] = self.imp.callFpdbHud - imp['interval'] = self.imp.interval - imp['hhArchiveBase'] = self.imp.hhArchiveBase - except: # Default params - imp['callFpdbHud'] = True - imp['interval'] = 10 - imp['hhArchiveBase'] = "~/.fpdb/HandHistories/" + try: imp['callFpdbHud'] = self.imp.callFpdbHud + except: imp['callFpdbHud'] = True + + try: imp['interval'] = self.imp.interval + except: imp['interval'] = 10 + + try: imp['hhArchiveBase'] = self.imp.hhArchiveBase + except: imp['hhArchiveBase'] = "~/.fpdb/HandHistories/" + + try: imp['saveActions'] = self.imp.saveActions + except: imp['saveActions'] = True + + try: imp['fastStoreHudCache'] = self.imp.fastStoreHudCache + except: imp['fastStoreHudCache'] = True return imp def get_default_paths(self, site = "PokerStars"): @@ -689,9 +729,9 @@ if __name__== "__main__": print c.get_aux_parameters(mw) print "mucked locations =", c.get_aux_locations('mucked', 9) - c.edit_aux_layout('mucked', 9, locations = [(487, 113), (555, 469), (572, 276), (522, 345), - (333, 354), (217, 341), (150, 273), (150, 169), (230, 115)]) - print "mucked locations =", c.get_aux_locations('mucked', 9) +# c.edit_aux_layout('mucked', 9, locations = [(487, 113), (555, 469), (572, 276), (522, 345), +# (333, 354), (217, 341), (150, 273), (150, 169), (230, 115)]) +# print "mucked locations =", c.get_aux_locations('mucked', 9) for site in c.supported_sites.keys(): print "site = ", site, diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index 6105e443..509c9f61 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -213,7 +213,7 @@ if __name__ == '__main__': parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="Input file in quiet mode", metavar="FILE") parser.add_option("-q", "--quiet", action="store_false", dest="gui", default=True, help="don't start gui") - + parser.add_option("-x", "--convert", dest="filtername", help="Conversion filter", default="passthrough") (options, sys.argv) = parser.parse_args() config = Configuration.Config() @@ -240,7 +240,7 @@ if __name__ == '__main__': importer = fpdb_import.Importer(False,settings, config) importer.setDropIndexes("auto") importer.setFailOnError(True) - importer.addImportFile(options.filename) + importer.addImportFile(options.filename, filter=options.filtername) importer.setCallHud(False) importer.runImport() importer.clearFileList() diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 666cf836..30a72096 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -123,7 +123,7 @@ class HUD_main(object): gtk.gdk.threads_enter() try: self.hud_dict[table_name].update(new_hand_id, config) - map(lambda aw: aw.update_gui(new_hand_id), self.hud_dict[table_name].aux_windows) + [aw.update_gui(new_hand_id) for aw in self.hud_dict[table_name].aux_windows] return False finally: gtk.gdk.threads_leave() @@ -172,8 +172,7 @@ class HUD_main(object): if temp_key in self.hud_dict: self.hud_dict[temp_key].stat_dict = stat_dict self.hud_dict[temp_key].cards = cards - for aw in self.hud_dict[temp_key].aux_windows: - aw.update_data(new_hand_id, self.db_connection) + [aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows] self.update_HUD(new_hand_id, temp_key, self.config) # Or create a new HUD diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 7f560ebc..45068c17 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -504,7 +504,15 @@ Card ranks will be uppercased if self.shown: print >>fh, _("*** SHOW DOWN ***") for name in self.shown: - print >>fh, _("%s shows [%s] (a hand...)" % (name, " ".join(self.holecards[name]['PREFLOP']))) + # TODO: legacy importer can't handle only one holecard here, make sure there are 2 for holdem, 4 for omaha + # TOOD: If HoldHand subclass supports more than omahahi, omahahilo, holdem, add them here + numOfHoleCardsNeeded = None + if self.gametype['category'] in ('omahahi','omahahilo'): + numOfHoleCardsNeeded = 4 + elif self.gametype['category'] in ('holdem'): + numOfHoleCardsNeeded = 2 + if len(self.holecards[name]['PREFLOP']) == numOfHoleCardsNeeded: + print >>fh, _("%s shows [%s] (a hand...)" % (name, " ".join(self.holecards[name]['PREFLOP']))) # Current PS format has the lines: # Uncalled bet ($111.25) returned to s0rrow diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index f47d93e9..20750b96 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -196,12 +196,12 @@ class Hud: s.window.destroy() self.stat_windows = {} # also kill any aux windows - map(lambda m: m.destroy(), self.aux_windows) + [aux.destroy() for aux in self.aux_windows] self.aux_windows = [] def reposition_windows(self, *args): - if self.stat_windows and len(self.stat_windows > 0): - map(lambda x: x.window.move(x.x, x.y), self.stat_windows) + if self.stat_windows != {} and len(self.stat_windows) > 0: + map(lambda x: x.window.move(x.x, x.y), self.stat_windows.itervalues()) return True def debug_stat_windows(self, *args): @@ -216,6 +216,10 @@ class Hud: new_loc = (loc[0] - self.table.x, loc[1] - self.table.y) new_layout[self.stat_windows[sw].adj - 1] = new_loc self.config.edit_layout(self.table.site, self.max, locations = new_layout) +# ask each aux to save its layout back to the config object + [aux.save_layout() for aux in self.aux_windows] +# save the config object back to the file + print "saving new xml file" self.config.save() def adj_seats(self, hand, config): @@ -346,6 +350,8 @@ class Hud: style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE) style |= win32con.WS_CLIPCHILDREN win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style) + break + window.set_title(real_name) class Stat_Window: @@ -570,6 +576,7 @@ class Popup_window: style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE) style |= win32con.WS_CLIPCHILDREN win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style) + break window.set_title(real_name) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 90af4b8f..1d7e9597 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -49,6 +49,9 @@ class Aux_Window: def create(self, *parms): pass + def save_layout(self, *args): + pass + def destroy(self): self.container.destroy() @@ -312,12 +315,13 @@ class Flop_Mucked(Aux_Window): def __init__(self, hud, config, params): self.hud = hud # hud object that this aux window supports self.config = config # configuration object for this aux window to use - self.params = params # hash aux params from config + self.params = params # dict aux params from config + self.positions = {} # dict of window positions + self.displayed_cards = False self.card_images = self.get_card_images() def create(self): - - adj = self.hud.adj_seats(0, self.config) + self.adj = self.hud.adj_seats(0, self.config) loc = self.config.get_aux_locations(self.params['name'], int(self.hud.max)) self.m_windows = {} # windows to put the card images in @@ -328,7 +332,7 @@ class Flop_Mucked(Aux_Window): if i == 'common': (x, y) = self.params['layout'][self.hud.max].common else: - (x, y) = loc[adj[i]] + (x, y) = loc[self.adj[i]] self.m_windows[i] = gtk.Window() self.m_windows[i].set_decorated(False) self.m_windows[i].set_property("skip-taskbar-hint", True) @@ -340,6 +344,7 @@ class Flop_Mucked(Aux_Window): self.seen_cards[i] = gtk.image_new_from_pixbuf(self.card_images[('B', 'H')]) self.eb[i].add(self.seen_cards[i]) self.m_windows[i].move(int(x) + self.hud.table.x, int(y) + self.hud.table.y) + self.positions[i] = (int(x) + self.hud.table.x, int(y) + self.hud.table.y) self.m_windows[i].set_opacity(float(self.params['opacity'])) self.m_windows[i].show_all() self.m_windows[i].hide() @@ -350,11 +355,9 @@ class Flop_Mucked(Aux_Window): def update_gui(self, new_hand_id): """Prepare and show the mucked cards.""" - pos = {} - for i, w in self.m_windows.iteritems(): - pos[i] = w.get_position() # I hate this. I don't know why I have to save position and then move back - self.hide_mucked_cards() - displayed_cards = False + if self.displayed_cards: + self.hide_mucked_cards() + self.displayed_cards = False for (i, cards) in self.hud.cards.iteritems(): if self.has_cards(cards): # scratch is a working pixbuf, used to assemble the image @@ -370,11 +373,12 @@ class Flop_Mucked(Aux_Window): x = x + int(self.params['card_wd']) self.seen_cards[i].set_from_pixbuf(scratch) # self.m_windows[i].show_all() - self.m_windows[i].move(pos[i][0], pos[i][1]) # here is where I move back + self.m_windows[i].resize(1,1) self.m_windows[i].present() - displayed_cards = True + self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back + self.displayed_cards = True - if displayed_cards and float(self.params['timeout']) > 0: + if self.displayed_cards and float(self.params['timeout']) > 0: gobject.timeout_add(int(1000*float(self.params['timeout'])), self.hide_mucked_cards) def destroy(self): @@ -385,8 +389,10 @@ class Flop_Mucked(Aux_Window): def hide_mucked_cards(self): """Hide the mucked card windows.""" # this is the callback from the timeout - for w in self.m_windows.values(): + for (i, w) in self.m_windows.iteritems(): + self.positions[i] = w.get_position() w.hide() + self.displayed_cards = False return False # this tells the system to NOT run this timeout again def button_press_cb(self, widget, event, *args): @@ -403,17 +409,16 @@ class Flop_Mucked(Aux_Window): def save_layout(self, *args): """Save new layout back to the aux element in the config file.""" -# similar to same method in stat_windows - new_layout = [(0, 0)] * self.hud.max - for (i, w) in self.m_windows.iteritems(): - (x, y) = w.get_position() - new_loc = (x - self.hud.table.x, y - self.hud.table.y) - if i != "common": - new_layout[self.hud.stat_windows[int(i)].adj - 1] = new_loc + new_locs = {} + print "adj =", self.adj + for (i, pos) in self.positions.iteritems(): + if i != 'common': + new_locs[self.adj[int(i)]] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) else: - pass - self.config.edit_layout(self.table.site, self.max, locations = new_layout) - self.config.save() + new_locs[i] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) + print "old locations =", self.params['layout'][self.hud.max] + print "saving locations =", new_locs + self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs) if __name__== "__main__": diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index b7322a1b..8b905005 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -24,9 +24,9 @@ from HandHistoryConverter import * # PokerStars HH Format class PokerStars(HandHistoryConverter): - + # Static regexes - re_GameInfo = re.compile("PokerStars Game #(?P[0-9]+):\s+(HORSE)? \(?(?PHold\'em|Razz|7 Card Stud|Omaha Hi/Lo|Badugi) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)", re.MULTILINE) + re_GameInfo = re.compile("PokerStars Game #(?P[0-9]+):\s+(HORSE)? \(?(?PHold\'em|Razz|7 Card Stud|Omaha|Omaha Hi/Lo|Badugi) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)", re.MULTILINE) re_SplitHands = re.compile('\n\n+') re_HandInfo = re.compile("^Table \'(?P[- a-zA-Z]+)\'(?P.+?$)?", re.MULTILINE) re_Button = re.compile('Seat #(?P