diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index d2504365..4e29dba1 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -169,6 +169,24 @@ class Popup: temp = temp + " " + stat return temp + "\n" +class Import: + def __init__(self, node): + self.interval = node.getAttribute("interval") + self.callFpdbHud = node.getAttribute("callFpdbHud") + + def __str__(self): + return " interval = %s\n callFpdbHud = %s\n" % (self.interval, self.callFpdbHud) + +class Tv: + def __init__(self, node): + self.combinedStealFold = node.getAttribute("combinedStealFold") + self.combined2B3B = node.getAttribute("combined2B3B") + self.combinedPostflop = node.getAttribute("combinedPostflop") + + def __str__(self): + return (" combinedStealFold = %s\n combined2B3B = %s\n combinedPostflop = %s\n" % + (self.combinedStealFold, self.combined2B3B, self.combinedPostflop) ) + class Config: def __init__(self, file = None): @@ -200,6 +218,7 @@ class Config: sys.stderr.write("No HUD_config_xml found. Exiting") sys.exit() try: + print "Reading configuration file %s\n" % (file) doc = xml.dom.minidom.parse(file) except: print "Error parsing %s. See error log file." % (file) @@ -221,26 +240,34 @@ class Config: site = Site(node = site_node) self.supported_sites[site.site_name] = site - s_games = doc.getElementsByTagName("supported_games") +# s_games = doc.getElementsByTagName("supported_games") for game_node in doc.getElementsByTagName("game"): game = Game(node = game_node) self.supported_games[game.game_name] = game - s_dbs = doc.getElementsByTagName("supported_databases") +# s_dbs = doc.getElementsByTagName("supported_databases") for db_node in doc.getElementsByTagName("database"): db = Database(node = db_node) self.supported_databases[db.db_name] = db - s_dbs = doc.getElementsByTagName("mucked_windows") +# s_dbs = doc.getElementsByTagName("mucked_windows") for mw_node in doc.getElementsByTagName("mw"): mw = Mucked(node = mw_node) self.mucked_windows[mw.name] = mw - s_dbs = doc.getElementsByTagName("popup_windows") +# s_dbs = doc.getElementsByTagName("popup_windows") for pu_node in doc.getElementsByTagName("pu"): pu = Popup(node = pu_node) self.popup_windows[pu.name] = pu + for imp_node in doc.getElementsByTagName("import"): + imp = Import(node = imp_node) + self.imp = imp + + for tv_node in doc.getElementsByTagName("tv"): + tv = Tv(node = tv_node) + self.tv = tv + def get_site_node(self, site): for site_node in self.doc.getElementsByTagName("site"): if site_node.getAttribute("site_name") == site: @@ -285,56 +312,94 @@ class Config: if name == None: name = 'fpdb' db = {} try: - db['databaseName'] = name - db['host'] = self.supported_databases[name].db_ip - db['user'] = self.supported_databases[name].db_user - db['password'] = self.supported_databases[name].db_pass - db['server'] = self.supported_databases[name].db_server + 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['backend'] = 2 + db['db-backend'] = 2 elif string.lower(self.supported_databases[name].db_server) == 'postgresql': - db['backend'] = 3 - else: db['backend'] = 0 # this is big trouble + db['db-backend'] = 3 + else: db['db-backend'] = None # this is big trouble except: pass return db + 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 + return tv + + def get_import_parameters(self): + imp = {} + try: + imp['imp-callFpdbHud'] = self.imp.callFpdbHud + imp['hud-defaultInterval'] = int(self.imp.interval) + except: # Default import parameters + imp['imp-callFpdbHud'] = True + imp['hud-defaultInterval'] = 10 + return imp + + def get_default_paths(self, site = "PokerStars"): + paths = {} + try: + paths['hud-defaultPath'] = os.path.expanduser(self.supported_sites[site].HH_path) + paths['bulkImport-defaultPath'] = os.path.expanduser(self.supported_sites[site].HH_path) + except: + paths['hud-defaultPath'] = "default" + paths['bulkImport-defaultPath'] = "default" + return paths + if __name__== "__main__": c = Config() print "\n----------- SUPPORTED SITES -----------" for s in c.supported_sites.keys(): print c.supported_sites[s] - print "----------- END SUPPORTED SITES -----------" print "\n----------- SUPPORTED GAMES -----------" for game in c.supported_games.keys(): print c.supported_games[game] - print "----------- END SUPPORTED GAMES -----------" print "\n----------- SUPPORTED DATABASES -----------" for db in c.supported_databases.keys(): print c.supported_databases[db] - print "----------- END SUPPORTED DATABASES -----------" print "\n----------- MUCKED WINDOW FORMATS -----------" for w in c.mucked_windows.keys(): print c.mucked_windows[w] - print "----------- END MUCKED WINDOW FORMATS -----------" - + print "\n----------- POPUP WINDOW FORMATS -----------" for w in c.popup_windows.keys(): print c.popup_windows[w] - print "----------- END MUCKED WINDOW FORMATS -----------" + print "\n----------- IMPORT -----------" + print c.imp + print "----------- END IMPORT -----------" + + print "\n----------- TABLE VIEW -----------" + print c.tv + print "----------- END TABLE VIEW -----------" + c.edit_layout("PokerStars", 6, locations=( (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6) )) c.save(file="testout.xml") - print c.get_db_parameters() \ No newline at end of file + print "db = ", c.get_db_parameters() + print "tv = ", c.get_tv_parameters() + print "imp = ", c.get_import_parameters() + print "paths = ", c.get_default_paths("PokerStars") diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index e4d145dd..7a6313cc 100644 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -27,10 +27,10 @@ import time import fpdb_import class GuiAutoImport (threading.Thread): - def browseClicked(self, widget, data): + def starsBrowseClicked(self, widget, data): """runs when user clicks browse on auto import tab""" - #print "start of GuiAutoImport.browseClicked" - current_path=self.pathTBuffer.get_text(self.pathTBuffer.get_start_iter(), self.pathTBuffer.get_end_iter()) + #print "start of GuiAutoImport.starsBrowseClicked" + current_path=self.starsDirPath.get_text() dia_chooser = gtk.FileChooserDialog(title="Please choose the path that you want to auto import", action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, @@ -42,11 +42,32 @@ class GuiAutoImport (threading.Thread): response = dia_chooser.run() if response == gtk.RESPONSE_OK: #print dia_chooser.get_filename(), 'selected' - self.pathTBuffer.set_text(dia_chooser.get_filename()) + self.starsDirPath.set_text(dia_chooser.get_filename()) elif response == gtk.RESPONSE_CANCEL: print 'Closed, no files selected' dia_chooser.destroy() - #end def GuiAutoImport.browseClicked + #end def GuiAutoImport.starsBrowseClicked + + def tiltBrowseClicked(self, widget, data): + """runs when user clicks browse on auto import tab""" + #print "start of GuiAutoImport.tiltBrowseClicked" + current_path=self.tiltDirPath.get_text() + + dia_chooser = gtk.FileChooserDialog(title="Please choose the path that you want to auto import", + action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, + buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) + #dia_chooser.set_current_folder(pathname) + dia_chooser.set_filename(current_path) + #dia_chooser.set_select_multiple(select_multiple) #not in tv, but want this in bulk import + + response = dia_chooser.run() + if response == gtk.RESPONSE_OK: + #print dia_chooser.get_filename(), 'selected' + self.tiltDirPath.set_text(dia_chooser.get_filename()) + elif response == gtk.RESPONSE_CANCEL: + print 'Closed, no files selected' + dia_chooser.destroy() + #end def GuiAutoImport.tiltBrowseClicked def do_import(self): """Callback for timer to do an import iteration.""" @@ -85,24 +106,27 @@ class GuiAutoImport (threading.Thread): # command = command + " %s" % (self.database) # print "command = ", command # self.pipe_to_hud = os.popen(command, 'w') - self.path=self.pathTBuffer.get_text(self.pathTBuffer.get_start_iter(), self.pathTBuffer.get_end_iter()) + self.starspath=self.starsDirPath.get_text() + self.tiltpath=self.tiltDirPath.get_text() -# Add directory to importer object and set the initial mtime reference. - self.importer.addImportDirectory(self.path, True) +# Add directory to importer object. + self.importer.addImportDirectory(self.starspath, True) + self.importer.addImportDirectory(self.tiltpath, True) self.do_import() - interval=int(self.intervalTBuffer.get_text(self.intervalTBuffer.get_start_iter(), self.intervalTBuffer.get_end_iter())) + interval=int(self.intervalEntry.get_text()) gobject.timeout_add(interval*1000, self.do_import) - #end def GuiAutoImport.browseClicked + #end def GuiAutoImport.startClicked def get_vbox(self): """returns the vbox of this thread""" return self.mainVBox #end def get_vbox - def __init__(self, settings, debug=True): + def __init__(self, settings, config, debug=True): """Constructor for GuiAutoImport""" self.settings=settings + self.config=config self.importer = fpdb_import.Importer(self,self.settings) self.importer.setCallHud(True) self.importer.setMinPrint(30) @@ -127,33 +151,45 @@ class GuiAutoImport (threading.Thread): self.settingsHBox.pack_start(self.intervalLabel) self.intervalLabel.show() - self.intervalTBuffer=gtk.TextBuffer() - self.intervalTBuffer.set_text(str(self.settings['hud-defaultInterval'])) - self.intervalTView=gtk.TextView(self.intervalTBuffer) - self.settingsHBox.pack_start(self.intervalTView) - self.intervalTView.show() - + self.intervalEntry=gtk.Entry() + self.intervalEntry.set_text(str(self.settings['hud-defaultInterval'])) + self.settingsHBox.pack_start(self.intervalEntry) + self.intervalEntry.show() self.pathHBox = gtk.HBox(False, 0) self.mainVBox.pack_start(self.pathHBox, False, True, 0) self.pathHBox.show() - self.pathLabel = gtk.Label("Path to auto-import:") - self.pathHBox.pack_start(self.pathLabel, False, False, 0) - self.pathLabel.show() - - self.pathTBuffer=gtk.TextBuffer() - self.pathTBuffer.set_text(self.settings['hud-defaultPath']) - self.pathTView=gtk.TextView(self.pathTBuffer) - self.pathHBox.pack_start(self.pathTView, False, True, 0) - self.pathTView.show() + self.pathStarsLabel = gtk.Label("Path to PokerStars auto-import:") + self.pathHBox.pack_start(self.pathStarsLabel, False, False, 0) + self.pathStarsLabel.show() + self.starsDirPath=gtk.Entry() + paths = self.config.get_default_paths("PokerStars") + self.starsDirPath.set_text(paths['hud-defaultPath']) + self.pathHBox.pack_start(self.starsDirPath, False, True, 0) + self.starsDirPath.show() + self.browseButton=gtk.Button("Browse...") - self.browseButton.connect("clicked", self.browseClicked, "Browse clicked") - self.pathHBox.pack_end(self.browseButton, False, False, 0) + self.browseButton.connect("clicked", self.starsBrowseClicked, "Browse clicked") + self.pathHBox.pack_start(self.browseButton, False, False, 0) self.browseButton.show() - + self.pathTiltLabel = gtk.Label("Path to Full Tilt auto-import:") + self.pathHBox.pack_start(self.pathTiltLabel, False, False, 0) + self.pathTiltLabel.show() + + self.tiltDirPath=gtk.Entry() + paths = self.config.get_default_paths("Full Tilt") + self.tiltDirPath.set_text(paths['hud-defaultPath']) + self.pathHBox.pack_start(self.tiltDirPath, False, True, 0) + self.tiltDirPath.show() + + self.browseButton=gtk.Button("Browse...") + self.browseButton.connect("clicked", self.tiltBrowseClicked, "Browse clicked") + self.pathHBox.pack_start(self.browseButton, False, False, 0) + self.browseButton.show() + self.startButton=gtk.Button("Start Autoimport") self.startButton.connect("clicked", self.startClicked, "start clicked") self.mainVBox.add(self.startButton) diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index 978f328d..ee5af2c6 100644 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -76,9 +76,10 @@ class GuiBulkImport (threading.Thread): print "todo: implement bulk import thread" #end def run - def __init__(self, db, settings): + def __init__(self, db, settings, config): self.db=db self.settings=settings + self.config=config self.importer = fpdb_import.Importer(self,self.settings) self.vbox=gtk.VBox(False,1) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 58c0cc31..7385e9fe 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -45,9 +45,9 @@ class GuiGraphViewer (threading.Thread): try: self.canvas.destroy() except AttributeError: pass - name=self.nameTBuffer.get_text(self.nameTBuffer.get_start_iter(), self.nameTBuffer.get_end_iter()) + name=self.nameEntry.get_text() - site=self.siteTBuffer.get_text(self.siteTBuffer.get_start_iter(), self.siteTBuffer.get_end_iter()) + site=self.siteEntry.get_text() if site=="PS": site=2 @@ -101,7 +101,7 @@ class GuiGraphViewer (threading.Thread): return line/100 #end of def getRingProfitGraph - def __init__(self, db, settings, querylist, debug=True): + def __init__(self, db, settings, querylist, config, debug=True): """Constructor for GraphViewer""" self.debug=debug #print "start of GraphViewer constructor" @@ -121,21 +121,22 @@ class GuiGraphViewer (threading.Thread): self.settingsHBox.pack_start(self.nameLabel) self.nameLabel.show() - self.nameTBuffer=gtk.TextBuffer() - self.nameTBuffer.set_text("name") - self.nameTView=gtk.TextView(self.nameTBuffer) - self.settingsHBox.pack_start(self.nameTView) - self.nameTView.show() + self.nameEntry=gtk.Entry() + self.nameEntry.set_text("name") + self.settingsHBox.pack_start(self.nameEntry) + self.nameEntry.show() self.siteLabel = gtk.Label("Site (PS or FTP):") self.settingsHBox.pack_start(self.siteLabel) self.siteLabel.show() - self.siteTBuffer=gtk.TextBuffer() - self.siteTBuffer.set_text("PS") - self.siteTView=gtk.TextView(self.siteTBuffer) - self.settingsHBox.pack_start(self.siteTView) - self.siteTView.show() + self.siteEntry=gtk.Entry() + self.siteEntry.set_text("PS") + self.settingsHBox.pack_start(self.siteEntry) + self.siteEntry.show() + + #Note: Assumes PokerStars is in the config + self.nameEntry.set_text(config.supported_sites["PokerStars"].screen_name) self.showButton=gtk.Button("Show/Refresh") self.showButton.connect("clicked", self.showClicked, "show clicked") diff --git a/pyfpdb/HUD_config.xml.example b/pyfpdb/HUD_config.xml.example index f5312c99..abdf7618 100644 --- a/pyfpdb/HUD_config.xml.example +++ b/pyfpdb/HUD_config.xml.example @@ -161,6 +161,9 @@ + + + diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py old mode 100755 new mode 100644 index 88e87104..8217deb5 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -36,7 +36,8 @@ Main for FreePokerTools HUD. import sys import os import thread -import Queue +import time +import string errorfile = open('HUD-error.txt', 'w', 0) sys.stderr = errorfile @@ -61,54 +62,61 @@ config = 0; def destroy(*args): # call back for terminating the main eventloop gtk.main_quit() -def process_new_hand(new_hand_id, db_name): -# there is a new hand_id to be processed -# read the hand_id from stdin and strip whitespace +def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_connection, config, stat_dict): + global hud_dict + def idle_func(): + global hud_dict + gtk.gdk.threads_enter() + try: + hud_dict[table_name] = Hud.Hud(table, max, poker_game, config, db_name) + hud_dict[table_name].create(new_hand_id, config) + hud_dict[table_name].update(new_hand_id, config, stat_dict) + return False + finally: + gtk.gdk.threads_leave + gobject.idle_add(idle_func) + +def update_HUD(new_hand_id, table_name, config, stat_dict): + global hud_dict + def idle_func(): + gtk.gdk.threads_enter() + try: + hud_dict[table_name].update(new_hand_id, config, stat_dict) + return False + finally: + gtk.gdk.threads_leave + gobject.idle_add(idle_func) + +def read_stdin(): # This is the thread function global hud_dict - for h in hud_dict.keys(): - if hud_dict[h].deleted: - del(hud_dict[h]) - - db_connection = Database.Database(config, db_name, 'temp') - (table_name, max, poker_game) = db_connection.get_table_name(new_hand_id) -# if a hud for this table exists, just update it - if hud_dict.has_key(table_name): - hud_dict[table_name].update(new_hand_id, db_connection, config) -# otherwise create a new hud - else: - tablewindow = Tables.discover_table_by_name(config, table_name) - if tablewindow == None: - sys.stderr.write("table name "+table_name+" not found\n") - else: - hud_dict[table_name] = Hud.Hud(tablewindow, max, poker_game, config, db_name) - hud_dict[table_name].create(new_hand_id, config) - hud_dict[table_name].update(new_hand_id, db_connection, config) - - db_connection.close_connection() - return(1) - -def check_stdin(db_name): - try: - hand_no = dataQueue.get(block=False) - process_new_hand(hand_no, db_name) - except: - pass - return True - -def read_stdin(source, condition, db_name): - new_hand_id = sys.stdin.readline() - if new_hand_id == "": - destroy() - process_new_hand(new_hand_id, db_name) - return True - -def producer(): # This is the thread function - while True: - hand_no = sys.stdin.readline() # reads stdin - if hand_no == "": + while True: # wait for a new hand number on stdin + new_hand_id = sys.stdin.readline() + new_hand_id = string.rstrip(new_hand_id) + if new_hand_id == "": # blank line means quit destroy() - dataQueue.put(hand_no) # and puts result on the queue + +# delete hud_dict entries for any HUD destroyed since last iteration + for h in hud_dict.keys(): + if hud_dict[h].deleted: + del(hud_dict[h]) + +# connect to the db and get basic info about the new hand + db_connection = Database.Database(config, db_name, 'temp') + (table_name, max, poker_game) = db_connection.get_table_name(new_hand_id) + stat_dict = db_connection.get_stats_from_hand(new_hand_id) + db_connection.close_connection() + +# if a hud for this table exists, just update it + if hud_dict.has_key(table_name): + update_HUD(new_hand_id, table_name, config, stat_dict) +# otherwise create a new hud + else: + tablewindow = Tables.discover_table_by_name(config, table_name) + if tablewindow == None: + sys.stderr.write("table name "+table_name+" not found\n") + else: + create_HUD(new_hand_id, tablewindow, db_name, table_name, max, poker_game, db_connection, config, stat_dict) if __name__== "__main__": sys.stderr.write("HUD_main starting\n") @@ -120,24 +128,18 @@ if __name__== "__main__": sys.stderr.write("Using db name = %s\n" % (db_name)) config = Configuration.Config() -# db_connection = Database.Database(config, 'fpdb', 'holdem') - if os.name == 'posix': - s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, read_stdin, db_name) - elif os.name == 'nt': - dataQueue = Queue.Queue() # shared global. infinite size - gobject.threads_init() # this is required - thread.start_new_thread(producer, ()) # starts the thread - gobject.timeout_add(1000, check_stdin, db_name) - else: - print "Sorry your operating system is not supported." - sys.exit() + gobject.threads_init() # this is required + thread.start_new_thread(read_stdin, ()) # starts the thread main_window = gtk.Window() main_window.connect("destroy", destroy) + eb = gtk.EventBox() label = gtk.Label('Closing this window will exit from the HUD.') - main_window.add(label) + eb.add(label) + main_window.add(eb) main_window.set_title("HUD Main Window") main_window.show_all() gtk.main() + diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 36fb8e8d..bf23a619 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -53,6 +53,7 @@ class Hud: self.max = max self.db_name = db_name self.deleted = False + self.stacked = True self.stat_windows = {} self.popup_windows = {} @@ -68,7 +69,8 @@ class Hud: #self.main_window.set_transient_for(parent.get_toplevel()) self.ebox = gtk.EventBox() - self.label = gtk.Label("Close this window to\nkill the HUD for\n %s" % (table.name)) + self.label = gtk.Label("Close this window to\nkill the HUD for\n %s\nMinimizing it hides stats." % + (table.name)) self.main_window.add(self.ebox) self.ebox.add(self.label) self.main_window.move(self.table.x, self.table.y) @@ -211,9 +213,8 @@ class Hud: # self.m = Mucked.Mucked(self.mucked_window, self.db_connection) # self.mucked_window.show_all() - def update(self, hand, db, config): + def update(self, hand, config, stat_dict): self.hand = hand # this is the last hand, so it is available later - stat_dict = db.get_stats_from_hand(hand) for s in stat_dict.keys(): self.stat_windows[stat_dict[s]['seat']].player_id = stat_dict[s]['player_id'] for r in range(0, config.supported_games[self.poker_game].rows): diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index 9cbcc384..e480d4c6 100644 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -64,7 +64,8 @@ def discover(c): tables = discover_nt(c) elif os.name == 'mac': tables = discover_mac(c) - else: tables = {} + else: + tables = {} return(tables) @@ -75,7 +76,8 @@ def discover_table_by_name(c, tablename): table = discover_nt_by_name(c, tablename) elif os.name == 'mac': table = discover_mac_by_name(c, tablename) - else: table = None + else: + table = None return(table) def discover_posix(c): @@ -211,7 +213,7 @@ def discover_nt_by_name(c, tablename): tw.x = int(x) + b_width tw.y = int(y) + tb_height tw.site = c.supported_sites[s].site_name - if not tw.site == "Unknown" and not tw.decoder == "Unknown": + if not tw.site == "Unknown" and not c.supported_sites[tw.site].decoder == "Unknown": eval("%s(tw)" % c.supported_sites[tw.site].decoder) else: tw.name = tablename @@ -291,9 +293,9 @@ def fulltilt_decode_table(tw): title_bits = re.split(' - ', tw.title) name = title_bits[0] tw.tournament = None - for pattern in [r' \(6 max\)', r' \(heads up\)', r' \(deep\)', - r' \(deep hu\)', r' \(deep 6\)', r' \(2\)', - r' \(edu\)', r' \(edu, 6 max\)', r' \(6\)' ]: + for pattern in [' (6 max)', ' (heads up)', ' (deep)', + ' (deep hu)', ' (deep 6)', ' (2)', + ' (edu)', ' (edu, 6 max)', ' (6)' ]: name = re.sub(pattern, '', name) # (tw.name, trash) = name.split(r' (', 1) tw.name = name.rstrip() diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 2a27f72b..134e6ea1 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -33,6 +33,7 @@ import GuiTableViewer import GuiAutoImport import GuiGraphViewer import FpdbSQLQueries +import Configuration class fpdb: def tab_clicked(self, widget, tab_name): @@ -236,91 +237,18 @@ class fpdb: return self.item_factory.get_widget("
") #end def get_menu - def load_default_profile(self): - """Loads the defaut profile""" - defaultpath=os.path.expanduser("~") - if not defaultpath.endswith(os.sep):#todo: check if this is needed in *nix, if not delete it - defaultpath+=(os.sep) - - if (os.sep=="\\"):#ie. if Windows use application data folder - defaultpath=os.environ["APPDATA"]+os.sep - else:#ie. if POSIX OS prefix fpdb with a . - defaultpath+="." - defaultpath+=("fpdb"+os.sep+"default.conf") - - if os.path.exists(defaultpath): - self.load_profile(defaultpath) - else: - self.diaSetupWizard(path=defaultpath) - #end def load_default_profile - - def load_profile(self, filename): - """Loads profile from the provided path name. also see load_default_profile""" - self.obtain_global_lock() - file=open(filename, "rU") - lines=file.readlines() - print "Opened and read profile file", filename - self.profile=filename - - self.settings={'db-host':"localhost", 'db-backend':2, 'db-databaseName':"fpdb", 'db-user':"fpdb"} + def load_profile(self): + """Loads profile from the provided path name.""" + self.settings = {} if (os.sep=="/"): self.settings['os']="linuxmac" else: self.settings['os']="windows" - self.settings['tv-combinedStealFold']=True - self.settings['tv-combined2B3B']=True - self.settings['imp-callFpdbHud']=True - - if self.settings['os']=="windows": - self.settings['bulkImport-defaultPath']="C:\\Program Files\\PokerStars\\HandHistory\\filename.txt" - self.settings['hud-defaultPath']="C:\\Program Files\\PokerStars\\HandHistory\\" - else: - self.settings['bulkImport-defaultPath'] = os.path.expanduser("~") + "/.wine/drive_c/Program Files/PokerStars/HandHistory/filename.txt" - self.settings['hud-defaultPath'] = os.path.expanduser("~")+"/.wine/drive_c/Program Files/PokerStars/HandHistory/" - - self.settings['hud-defaultInterval']=10 - - for i in range(len(lines)): - if lines[i].startswith("db-backend="): - self.settings['db-backend']=int(lines[i][11:-1]) - elif lines[i].startswith("db-host="): - self.settings['db-host']=lines[i][8:-1] - elif lines[i].startswith("db-databaseName="): - self.settings['db-databaseName']=lines[i][16:-1] - elif lines[i].startswith("db-user="): - self.settings['db-user']=lines[i][8:-1] - elif lines[i].startswith("db-password="): - self.settings['db-password']=lines[i][12:-1] - elif lines[i].startswith("imp-callFpdbHud="): - if lines[i].find("True")!=-1: - self.settings['imp-callFpdbHud']=True - else: - self.settings['imp-callFpdbHud']=False - elif lines[i].startswith("tv-combinedPostflop="): - if lines[i].find("True")!=-1: - self.settings['tv-combinedPostflop']=True - else: - self.settings['tv-combinedPostflop']=False - elif lines[i].startswith("tv-combinedStealFold="): - if lines[i].find("True")!=-1: - self.settings['tv-combinedStealFold']=True - else: - self.settings['tv-combinedStealFold']=False - elif lines[i].startswith("tv-combined2B3B="): - if lines[i].find("True")!=-1: - self.settings['tv-combined2B3B']=True - else: - self.settings['tv-combined2B3B']=False - elif lines[i].startswith("bulkImport-defaultPath="): - if lines[i][23:-1]!="default": - self.settings['bulkImport-defaultPath']=lines[i][23:-1] - elif lines[i].startswith("hud-defaultPath="): - if lines[i][15:-1]!="default": - self.settings['hud-defaultPath']=lines[i][16:-1] - elif lines[i].startswith("#"): - pass #comment - dont parse - else: - raise fpdb_simple.FpdbError("invalid line in profile file: "+lines[i]+" if you don't know what to do just remove it from "+filename) + + self.settings.update(self.config.get_db_parameters()) + self.settings.update(self.config.get_tv_parameters()) + self.settings.update(self.config.get_import_parameters()) + self.settings.update(self.config.get_default_paths()) if self.db!=None: self.db.disconnect() @@ -355,8 +283,7 @@ class fpdb: #end def not_implemented def obtain_global_lock(self): - #print "todo: implement obtain_global_lock (users: pls ignore this)" - pass + print "todo: implement obtain_global_lock (users: pls ignore this)" #end def obtain_global_lock def quit(self, widget, data): @@ -376,7 +303,7 @@ class fpdb: def tab_auto_import(self, widget, data): """opens the auto import tab""" - new_aimp_thread=GuiAutoImport.GuiAutoImport(self.settings) + new_aimp_thread=GuiAutoImport.GuiAutoImport(self.settings, self.config) self.threads.append(new_aimp_thread) aimp_tab=new_aimp_thread.get_vbox() self.add_and_display_tab(aimp_tab, "Auto Import") @@ -385,7 +312,7 @@ class fpdb: def tab_bulk_import(self, widget, data): """opens a tab for bulk importing""" #print "start of tab_bulk_import" - new_import_thread=GuiBulkImport.GuiBulkImport(self.db, self.settings) + new_import_thread=GuiBulkImport.GuiBulkImport(self.db, self.settings, self.config) self.threads.append(new_import_thread) bulk_tab=new_import_thread.get_vbox() self.add_and_display_tab(bulk_tab, "Bulk Import") @@ -412,7 +339,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") def tabGraphViewer(self, widget, data): """opens a graph viewer tab""" #print "start of tabGraphViewer" - new_gv_thread=GuiGraphViewer.GuiGraphViewer(self.db, self.settings,self.querydict) + new_gv_thread=GuiGraphViewer.GuiGraphViewer(self.db, self.settings, self.querydict, self.config) self.threads.append(new_gv_thread) gv_tab=new_gv_thread.get_vbox() self.add_and_display_tab(gv_tab, "Graphs") @@ -421,12 +348,13 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") def __init__(self): self.threads=[] self.db=None - self.load_default_profile() + self.config = Configuration.Config() + self.load_profile() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) - self.window.set_title("Free Poker DB - version: alpha8, p137") + self.window.set_title("Free Poker DB - version: alpha8+, p137 or higher") self.window.set_border_width(1) self.window.set_size_request(1020,400) self.window.set_resizable(True) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 860cb778..fb170240 100755 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -104,25 +104,27 @@ class Importer: #Add an individual file to filelist def addImportFile(self, filename): - #todo: test it is a valid file + #TODO: test it is a valid file self.filelist = self.filelist + [filename] #Remove duplicates self.filelist = list(set(self.filelist)) #Add a directory of files to filelist def addImportDirectory(self,dir,monitor = False): - #todo: test it is a valid directory - if monitor == True: - self.monitor = True - self.dirlist = self.dirlist + [dir] + if os.path.isdir(dir): + if monitor == True: + self.monitor = True + self.dirlist = self.dirlist + [dir] - for file in os.listdir(dir): - if os.path.isdir(file): - print "BulkImport is not recursive - please select the final directory in which the history files are" - else: - self.filelist = self.filelist + [os.path.join(dir, file)] - #Remove duplicates - self.filelist = list(set(self.filelist)) + for file in os.listdir(dir): + if os.path.isdir(file): + print "BulkImport is not recursive - please select the final directory in which the history files are" + else: + self.filelist = self.filelist + [os.path.join(dir, file)] + #Remove duplicates + self.filelist = list(set(self.filelist)) + else: + print "Warning: Attempted to add: '" + str(dir) + "' as an import directory" #Run full import on filelist def runImport(self): diff --git a/website/contact.php b/website/contact.php old mode 100644 new mode 100755 diff --git a/website/docs-abreviations.php b/website/docs-abreviations.php old mode 100644 new mode 100755 diff --git a/website/docs-benchmarks.php b/website/docs-benchmarks.php old mode 100644 new mode 100755 diff --git a/website/docs-git-instructions.php b/website/docs-git-instructions.php old mode 100644 new mode 100755 diff --git a/website/docs-hudHowTo.php b/website/docs-hudHowTo.php old mode 100644 new mode 100755 diff --git a/website/docs-install-gentoo.php b/website/docs-install-gentoo.php old mode 100644 new mode 100755 diff --git a/website/docs-install-windows.php b/website/docs-install-windows.php old mode 100644 new mode 100755 index 8141c294..341e2f15 --- a/website/docs-install-windows.php +++ b/website/docs-install-windows.php @@ -9,12 +9,17 @@ require 'sidebar.php';
+

Before You Begin

+

Most people should install using the Installer. These instructions have not been updated recently, but can serve as a guide to someone who knows what he is doing. Unless you have a special reason for installing manually, you really should be using the installer.

+ +

Vista Users

+

The installer does not install mysql properly on Microsoft Vista installations, due to the UAC. You should first install mysql using this how to (pdf). Then run the installer. The installer will detect the mysql installation and not reintstall.

+

Installing in Windows

-

These instructions were made with Windows XP. They should also work with Windows NT / 2000 / 2003 / Vista and 2008. Please report any differences to gmic at users.sourceforge.net. +

These instructions were made with Windows XP. They should also work with Windows NT / 2000 / 2003 and 2008. Please report any differences to gmic at users.sourceforge.net.

If you're still using Win3/95/98/ME then you should switch to GNU/Linux, *BSD or WinXP.

-

An Installer will be made at some point.

windows install guide screenshot diff --git a/website/docs-overview.php b/website/docs-overview.php old mode 100644 new mode 100755 diff --git a/website/docs-requirements.php b/website/docs-requirements.php old mode 100644 new mode 100755 diff --git a/website/docs-usage.php b/website/docs-usage.php old mode 100644 new mode 100755 diff --git a/website/docs.php b/website/docs.php old mode 100644 new mode 100755 diff --git a/website/features.php b/website/features.php old mode 100644 new mode 100755 diff --git a/website/footer.php b/website/footer.php old mode 100644 new mode 100755 diff --git a/website/header.php b/website/header.php old mode 100644 new mode 100755 diff --git a/website/index.php b/website/index.php old mode 100644 new mode 100755 diff --git a/website/license.php b/website/license.php old mode 100644 new mode 100755 diff --git a/website/screenshots.php b/website/screenshots.php old mode 100644 new mode 100755 diff --git a/website/sidebar.php b/website/sidebar.php old mode 100644 new mode 100755