def __init__(self, config, site, table_name = None, tournament = None, table_number = None): self.config = config self.site = site if tournament is not None and table_number is not None: self.tournament = int(tournament) self.table = int(table_number) self.name = "%s - %s" % (self.tournament, self.table) self.type = "tour" table_kwargs = dict(tournament = self.tournament, table_number = self.table) self.tableno_re = getTableNoRe(self.config, self.site, tournament = self.tournament) elif table_name is not None: self.name = table_name self.type = "cash" self.tournament = None table_kwargs = dict(table_name = table_name) else: return None self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs) self.find_table_parameters() geo = self.get_geometry() if geo is None: return None self.width = geo['width'] self.height = geo['height'] self.x = geo['x'] self.y = geo['y'] self.oldx = self.x # attn ray: remove these two lines and update Hud.py::update_table_position() self.oldy = self.y self.game = self.get_game()
def __init__(self, config, site, table_name=None, tournament=None, table_number=None): self.config = config self.site = site self.hud = None # fill in later self.gdkhandle = None self.number = None if tournament is not None and table_number is not None: self.tournament = int(tournament) self.table = int(table_number) self.name = "%s - %s" % (self.tournament, self.table) self.type = "tour" table_kwargs = dict(tournament=self.tournament, table_number=self.table) self.tableno_re = getTableNoRe(self.config, self.site, tournament=self.tournament) elif table_name is not None: self.name = table_name self.type = "cash" self.tournament = None table_kwargs = dict(table_name=table_name) else: return None self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs) trys = 0 while True: self.find_table_parameters() if self.number is not None: break trys += 1 if trys > 4: log.error(_("Can't find table %s") % table_name) return None geo = self.get_geometry() if geo is None: return None self.width = geo['width'] self.height = geo['height'] self.x = geo['x'] self.y = geo['y'] self.oldx = self.x # attn ray: remove these two lines and update Hud.py::update_table_position() self.oldy = self.y self.game = self.get_game()
def __init__(self, config, site, table_name=None, tournament=None, table_number=None): self.config = config self.site = site self.hud = None # fill in later self.gdkhandle = None self.number = None if tournament is not None and table_number is not None: self.tournament = int(tournament) self.table = int(table_number) self.name = "%s - %s" % (self.tournament, self.table) self.type = "tour" table_kwargs = dict(tournament=self.tournament, table_number=self.table) self.tableno_re = getTableNoRe(self.config, self.site, tournament=self.tournament) elif table_name is not None: self.name = table_name self.type = "cash" self.tournament = None table_kwargs = dict(table_name=table_name) else: return None self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs) # make a small delay otherwise Xtables.root.get_windows() # returns empty for unknown reasons sleep(0.1) self.find_table_parameters() if not self.number: log.error(_("Can't find table \"%s\" with search string \"%s\""), table_name, self.search_string) geo = self.get_geometry() if geo is None: return None self.width = geo['width'] self.height = geo['height'] self.x = geo['x'] self.y = geo['y'] self.oldx = self.x # attn ray: remove these two lines and update Hud.py::update_table_position() self.oldy = self.y self.game = self.get_game()
def __init__(self, config, site, table_name = None, tournament = None, table_number = None): self.config = config self.site = site self.hud = None # fill in later self.gdkhandle = None self.number = None if tournament is not None and table_number is not None: self.tournament = int(tournament) self.table = int(table_number) self.name = "%s - %s" % (self.tournament, self.table) self.type = "tour" table_kwargs = dict(tournament = self.tournament, table_number = self.table) self.tableno_re = getTableNoRe(self.config, self.site, tournament = self.tournament) elif table_name is not None: self.name = table_name self.type = "cash" self.tournament = None table_kwargs = dict(table_name = table_name) else: return None self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs) # make a small delay otherwise Xtables.root.get_windows() # returns empty for unknown reasons sleep(0.1) self.find_table_parameters() if not self.number: log.error(_("Can't find table %s") % table_name) geo = self.get_geometry() if geo is None: return None self.width = geo['width'] self.height = geo['height'] self.x = geo['x'] self.y = geo['y'] self.oldx = self.x # attn ray: remove these two lines and update Hud.py::update_table_position() self.oldy = self.y self.game = self.get_game()
return True print "enter table name to find: ", table_name = sys.stdin.readline() if "," in table_name: # tournament print "tournament" (tour_no, tab_no) = table_name.split(",", 1) tour_no = tour_no.rstrip() tab_no = tab_no.rstrip() type = "tour" table_kwargs = dict(tournament = tour_no, table_number = tab_no) else: # not a tournament print "cash game" table_name = table_name.rstrip() type = "cash" table_kwargs = dict(table_name = table_name) search_string = getTableTitleRe(config, "Full Tilt Poker", type, **table_kwargs) table = Tables.Table(search_string, **table_kwargs) table.gdk_handle = gtk.gdk.window_foreign_new(table.number) print "table =", table # print "game =", table.get_game() fake = fake_hud(table) print "fake =", fake # gobject.timeout_add(100, check_on_table, table, fake) print "calling main" gtk.main()
def read_stdin(self): # This is the thread function """Do all the non-gui heavy lifting for the HUD program.""" # This db connection is for the read_stdin thread only. It should not # be passed to HUDs for use in the gui thread. HUD objects should not # need their own access to the database, but should open their own # if it is required. self.db_connection = Database.Database(self.config) # get hero's screen names and player ids self.hero, self.hero_ids = {}, {} found = False while 1: # wait for a new hand number on stdin if len(self.last_hand_of_running_tables) != 0: new_hand_id = self.last_hand_of_running_tables.pop() else: new_hand_id = sys.stdin.readline() new_hand_id = string.rstrip(new_hand_id) t0 = time.time() t1 = t2 = t3 = t4 = t5 = t6 = t0 log.debug("Received hand no %s" % new_hand_id) if new_hand_id == "": # blank line means quit self.destroy() break # this thread is not always killed immediately with gtk.main_quit() if not found: for site in self.config.get_supported_sites(): result = self.db_connection.get_site_id(site) if result: site_id = result[0][0] self.hero[site_id] = self.config.supported_sites[site].screen_name self.hero_ids[site_id] = self.db_connection.get_player_id(self.config, site, self.hero[site_id]) if self.hero_ids[site_id] is not None: found = True else: self.hero_ids[site_id] = -1 # get basic info about the new hand from the db # if there is a db error, complain, skip hand, and proceed log.info("HUD_main.read_stdin: hand processing starting ...") try: (table_name, max, poker_game, type, site_id, site_name, num_seats, tour_number, tab_number) = \ self.db_connection.get_table_info(new_hand_id) except Exception: log.error("db error: skipping %s" % new_hand_id) continue t1 = time.time() if type == "tour": # hand is from a tournament temp_key = tour_number else: temp_key = table_name # Update an existing HUD if temp_key in self.hud_dict: # get stats using hud's specific params and get cards self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] , self.hud_dict[temp_key].hud_params['h_hud_days']) t2 = time.time() stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params ,self.hero_ids[site_id], num_seats) t3 = time.time() try: self.hud_dict[temp_key].stat_dict = stat_dict except KeyError: # HUD instance has been killed off, key is stale log.error('hud_dict[%s] was not found\n' % temp_key) log.error('will not send hand\n') # Unlocks table, copied from end of function self.db_connection.connection.rollback() return cards = self.db_connection.get_cards(new_hand_id) t4 = time.time() comm_cards = self.db_connection.get_common_cards(new_hand_id) t5 = time.time() if comm_cards != {}: # stud! cards['common'] = comm_cards['common'] self.hud_dict[temp_key].cards = cards [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 else: # get stats using default params--also get cards self.db_connection.init_hud_stat_vars( self.hud_params['hud_days'], self.hud_params['h_hud_days'] ) stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_params ,self.hero_ids[site_id], num_seats) cards = self.db_connection.get_cards(new_hand_id) comm_cards = self.db_connection.get_common_cards(new_hand_id) if comm_cards != {}: # stud! cards['common'] = comm_cards['common'] table_kwargs = dict(table_name = table_name, tournament = tour_number, table_number = tab_number) search_string = getTableTitleRe(self.config, site_name, type, **table_kwargs) # print "getTableTitleRe ", self.config, site_name, type, "=", search_string tablewindow = Tables.Table(search_string, **table_kwargs) if tablewindow is None: # If no client window is found on the screen, complain and continue if type == "tour": table_name = "%s %s" % (tour_number, tab_number) # log.error("HUD create: table name "+table_name+" not found, skipping.\n") log.error("HUD create: table name %s not found, skipping." % table_name) else: tablewindow.max = max tablewindow.site = site_name # Test that the table window still exists if hasattr(tablewindow, 'number'): self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards) else: log.error('Table "%s" no longer exists\n' % table_name) t6 = time.time() log.info("HUD_main.read_stdin: hand read in %4.3f seconds (%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f)" % (t6-t0,t1-t0,t2-t0,t3-t0,t4-t0,t5-t0,t6-t0)) self.db_connection.connection.rollback()
return True print _("enter table name to find: "), table_name = sys.stdin.readline() if "," in table_name: # tournament print "tournament" (tour_no, tab_no) = table_name.split(",", 1) tour_no = tour_no.rstrip() tab_no = tab_no.rstrip() type = "tour" table_kwargs = dict(tournament=tour_no, table_number=tab_no) else: # not a tournament print "cash game" table_name = table_name.rstrip() type = "cash" table_kwargs = dict(table_name=table_name) search_string = getTableTitleRe(config, "Full Tilt Poker", type, **table_kwargs) table = Tables.Table(search_string, **table_kwargs) table.gdk_handle = gtk.gdk.window_foreign_new(table.number) print "table =", table # print "game =", table.get_game() fake = fake_hud(table) print "fake =", fake # gobject.timeout_add(100, check_on_table, table, fake) print _("calling main") gtk.main()