Add file HUD_run_me, to be run by GuiAutoImport

GuiAutoImport: run HUD_run_me instead of HUD_main
HUD_main: Add HUD_removed() function, called by HUD when an individual HUD is closed, eliminates polling them every update; use 'in' operator instead of has_key
HUD: clean up code that deals with lack of font descriptor in config, and notification of what font was selected
HUD: clean up unnecessary use of keys() functions, and 'in' vs has_key
HUD: restore previous definition of reposition_windows(), although i can't make it error at will anymore
Tables: cleanup with keys() and in operator
fpdb: no longer raise an error on duplicate tab, since we currently depend on that, it's not an error, right?
This commit is contained in:
eblade 2009-01-06 05:18:45 -05:00
parent 0f90d8a899
commit fb9d7c0af2
6 changed files with 111 additions and 46 deletions

View File

@ -128,12 +128,12 @@ class GuiAutoImport (threading.Thread):
widget.set_label(u'Stop Autoimport')
if self.pipe_to_hud is None:
if os.name == 'nt':
command = "python HUD_main.py" + " %s" % (self.database)
command = "python HUD_run_me.py" + " %s" % (self.database)
bs = 0 # windows is not happy with line buffing here
self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE,
universal_newlines=True)
else:
command = self.config.execution_path('HUD_main.py')
command = self.config.execution_path('HUD_run_me.py')
bs = 1
self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
universal_newlines=True)

View File

@ -36,9 +36,6 @@ import time
import string
import re
errorfile = open('HUD-error.txt', 'w', 0)
sys.stderr = errorfile
# pyGTK modules
import pygtk
import gtk
@ -61,11 +58,11 @@ def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit()
def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_connection, config, stat_dict):
global hud_dict
global eb
global hud_dict, eb
def idle_func():
global hud_dict
global eb
global hud_dict, eb
gtk.gdk.threads_enter()
try:
newlabel = gtk.Label(table_name)
@ -97,10 +94,19 @@ def update_HUD(new_hand_id, table_name, config, stat_dict):
finally:
gtk.gdk.threads_leave()
gobject.idle_add(idle_func)
def HUD_removed(tablename):
global hud_dict, eb
if tablename in hud_dict and hud_dict[tablename].deleted:
eb.remove(hud_dict[tablename].tablehudlabel)
del(hud_dict[tablename])
return False
return True
def read_stdin(): # This is the thread function
global hud_dict
global eb
global hud_dict, eb
db_connection = Database.Database(config, db_name, 'temp')
tourny_finder = re.compile('(\d+) (\d+)')
@ -112,10 +118,9 @@ def read_stdin(): # This is the thread function
destroy()
# delete hud_dict entries for any HUD destroyed since last iteration
for h in hud_dict.keys():
if hud_dict[h].deleted:
eb.remove(hud_dict[h].tablehudlabel)
del(hud_dict[h])
# for h in hud_dict:
# HUD_removed(h)
# removing this function, we shouldn't need it anymore, since the hud should notify us anyway, right?
# get basic info about the new hand from the db
(table_name, max, poker_game) = db_connection.get_table_name(new_hand_id)
@ -131,14 +136,14 @@ def read_stdin(): # This is the thread function
stat_dict = db_connection.get_stats_from_hand(new_hand_id)
# if a hud for this CASH table exists, just update it
if hud_dict.has_key(table_name):
if table_name in hud_dict:
# update the data for the aux_windows
for aw in hud_dict[table_name].aux_windows:
aw.update_data(new_hand_id, db_connection)
update_HUD(new_hand_id, table_name, config, stat_dict)
# if a hud for this TOURNAMENT table exists, just update it
elif hud_dict.has_key(tour_number):
elif tour_number in hud_dict:
update_HUD(new_hand_id, tour_number, config, stat_dict)
# otherwise create a new hud

52
pyfpdb/HUD_run_me.py Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env python
import sys
import os
import thread
import time
import string
import re
errorfile = open('HUD-error.txt', 'w', 0)
sys.stderr = errorfile
# pyGTK modules
import pygtk
import gtk
import gobject
# FreePokerTools modules
import Configuration
import Database
import Tables
import Hud
import HUD_main
def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit()
if __name__== "__main__":
sys.stderr.write("HUD_main starting\n")
try:
HUD_main.db_name = sys.argv[1]
except:
HUD_main.db_name = 'fpdb'
sys.stderr.write("Using db name = %s\n" % (HUD_main.db_name))
HUD_main.config = Configuration.Config()
gobject.threads_init() # this is required
thread.start_new_thread(HUD_main.read_stdin, ()) # starts the thread
HUD_main.main_window = gtk.Window()
HUD_main.main_window.connect("destroy", destroy)
HUD_main.eb = gtk.VBox()
label = gtk.Label('Closing this window will exit from the HUD.')
HUD_main.eb.add(label)
HUD_main.main_window.add(HUD_main.eb)
HUD_main.main_window.set_title("HUD Main Window")
HUD_main.main_window.show_all()
gtk.main()

View File

@ -61,13 +61,15 @@ class Hud:
self.stat_windows = {}
self.popup_windows = {}
self.aux_windows = []
(font, font_size) = config.get_default_font(self.table.site)
print "font = ", font, "size = ", font_size
if font == None or font_size == None:
self.font = pango.FontDescription("Sans 7")
else:
print "Setting font to ", font + " " + font_size
self.font = pango.FontDescription(font + " " + font_size)
if font == None:
font = "Sans"
if font_size == None:
font_size = "8"
print "Setting font to ", font + " " + font_size
self.font = pango.FontDescription(font + " " + font_size)
# do we need to add some sort of condition here for dealing with a request for a font that doesn't exist?
@ -122,6 +124,9 @@ class Hud:
self.main_window.show_all()
# TODO: fold all uses of this type of 'topify' code into a single function, if the differences between the versions don't
# create adverse effects?
if os.name == 'nt':
self.topify_window(self.main_window)
else:
@ -143,10 +148,10 @@ class Hud:
self.main_window.move(x, y)
adj = self.adj_seats(self.hand, self.config)
loc = self.config.get_locations(self.table.site, self.max)
for i in range(1, self.max + 1):
for i in range(1, self.max + 1):
(x, y) = loc[adj[i]]
if self.stat_windows.has_key(i):
self.stat_windows[i].relocate(x, y)
if i in self.stat_windows:
self.stat_windows[i].relocate(x, y)
return True
def on_button_press(self, widget, event):
@ -159,13 +164,15 @@ class Hud:
return False
def kill_hud(self, *args):
for k in self.stat_windows.keys():
for k in self.stat_windows:
self.stat_windows[k].window.destroy()
self.main_window.destroy()
self.deleted = True
HUD_main.HUD_removed(self.table.name)
def reposition_windows(self, *args):
self.update_table_position()
for w in self.stat_windows:
self.stat_windows[w].window.move(self.stat_windows[w].x, self.stat_windows[w].y)
return True
def debug_stat_windows(self, *args):
@ -213,7 +220,7 @@ class Hud:
# create the stat windows
for i in range(1, self.max + 1):
(x, y) = loc[adj[i]]
if self.stat_windows.has_key(i):
if i in self.stat_windows:
self.stat_windows[i].relocate(x, y)
else:
self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game],
@ -230,7 +237,7 @@ class Hud:
for i in range(0, config.supported_games[self.poker_game].rows + 1):
row_list = [''] * config.supported_games[self.poker_game].cols
self.stats.append(row_list)
for stat in config.supported_games[self.poker_game].stats.keys():
for stat in config.supported_games[self.poker_game].stats:
self.stats[config.supported_games[self.poker_game].stats[stat].row] \
[config.supported_games[self.poker_game].stats[stat].col] = \
config.supported_games[self.poker_game].stats[stat].stat_name
@ -246,7 +253,7 @@ class Hud:
def update(self, hand, config, stat_dict):
self.hand = hand # this is the last hand, so it is available later
self.update_table_position()
for s in stat_dict.keys():
for s in stat_dict:
try:
self.stat_windows[stat_dict[s]['seat']].player_id = stat_dict[s]['player_id']
except: # omg, we have more seats than stat windows .. damn poker sites with incorrect max seating info .. let's force 10 here
@ -267,7 +274,7 @@ class Hud:
self.stat_windows[stat_dict[s]['seat']].label[r][c].set_text(statstring)
if statstring != "xxx": # is there a way to tell if this particular stat window is visible already, or no?
self.stat_windows[stat_dict[s]['seat']].window.show_all()
self.reposition_windows()
# self.reposition_windows()
tip = stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \
number[3] + ", " + number[4]
Stats.do_tip(self.stat_windows[stat_dict[s]['seat']].e_box[r][c], tip)
@ -449,14 +456,14 @@ class Popup_window:
# figure out what popup format we're using
popup_format = "default"
for stat in stat_window.game.stats.keys():
for stat in stat_window.game.stats:
if stat_window.game.stats[stat].row == row and stat_window.game.stats[stat].col == col:
popup_format = stat_window.game.stats[stat].popup
break
# get the list of stats to be presented from the config
stat_list = []
for w in stat_window.parent.config.popup_windows.keys():
for w in stat_window.parent.config.popup_windows:
if w == popup_format:
stat_list = stat_window.parent.config.popup_windows[w].pu_stats
break

View File

@ -58,15 +58,15 @@ import Configuration
class Table_Window:
def __init__(self, info = {}):
if info.has_key('number'): self.number = info['number']
if info.has_key('exe'): self.exe = info['exe']
if info.has_key('width'): self.width = info['width']
if info.has_key('height'): self.height = info['height']
if info.has_key('x'): self.x = info['x']
if info.has_key('y'): self.y = info['y']
if info.has_key('site'): self.site = info['site']
if info.has_key('title'): self.title = info['title']
if info.has_key('name'): self.name = info['name']
if 'number' in info: self.number = info['number']
if 'exe' in info: self.exe = info['exe']
if 'width' in info: self.width = info['width']
if 'height' in info: self.height = info['height']
if 'x' in info: self.x = info['x']
if 'y' in info: self.y = info['y']
if 'site' in info: self.site = info['site']
if 'title' in info: self.title = info['title']
if 'name' in info: self.name = info['name']
def __str__(self):
# __str__ method for testing
@ -225,7 +225,7 @@ def discover_nt_by_name(c, tablename):
"""Finds poker client window with the given table name."""
titles = {}
win32gui.EnumWindows(win_enum_handler, titles)
for hwnd in titles.keys():
for hwnd in titles:
if titles[hwnd].find(tablename) == -1: continue
if titles[hwnd].find("History for table:") > -1: continue
if titles[hwnd].find("HUD:") > -1: continue
@ -239,7 +239,7 @@ def discover_nt_tournament(c, tour_number, tab_number):
titles ={}
win32gui.EnumWindows(win_enum_handler, titles)
for hwnd in titles.keys():
for hwnd in titles:
if re.search(search_string, titles[hwnd]):
return decode_windows(c, titles[hwnd], hwnd)
return None

View File

@ -62,7 +62,8 @@ class fpdb:
#print "start of add_tab"
for i in self.tab_names: #todo: check this is valid
if i==new_tab_name:
raise fpdb_simple.FpdbError("duplicate tab_name not permitted")
return # we depend on this to not create duplicate tabs, there's no reason to raise an error here?
# raise fpdb_simple.FpdbError("duplicate tab_name not permitted")
self.tabs.append(new_tab)
self.tab_names.append(new_tab_name)