2008-08-19 00:53:25 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""Hud.py
|
|
|
|
|
|
|
|
Create and manage the hud overlays.
|
|
|
|
"""
|
|
|
|
# Copyright 2008, Ray E. Barker
|
|
|
|
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Standard Library modules
|
2008-09-15 22:31:55 +02:00
|
|
|
import os
|
2008-10-24 21:44:53 +02:00
|
|
|
import sys
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
# pyGTK modules
|
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
import gobject
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
# win32 modules -- only imported on windows systems
|
|
|
|
if os.name == 'nt':
|
|
|
|
import win32gui
|
|
|
|
import win32con
|
2008-10-26 10:34:36 +01:00
|
|
|
import win32api
|
2008-09-15 22:31:55 +02:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
# FreePokerTools modules
|
|
|
|
import Tables # needed for testing only
|
|
|
|
import Configuration
|
|
|
|
import Stats
|
|
|
|
import Mucked
|
|
|
|
import Database
|
2008-10-24 22:30:08 +02:00
|
|
|
import HUD_main
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
class Hud:
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
def __init__(self, table, max, poker_game, config, db_name):
|
2008-08-19 00:53:25 +02:00
|
|
|
self.table = table
|
|
|
|
self.config = config
|
|
|
|
self.poker_game = poker_game
|
|
|
|
self.max = max
|
2008-09-15 22:31:55 +02:00
|
|
|
self.db_name = db_name
|
|
|
|
self.deleted = False
|
2008-10-22 03:46:30 +02:00
|
|
|
self.stacked = True
|
2008-10-30 03:37:05 +01:00
|
|
|
self.colors = config.get_default_colors(self.table.site)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
self.stat_windows = {}
|
2008-09-15 22:31:55 +02:00
|
|
|
self.popup_windows = {}
|
2008-11-16 23:53:31 +01:00
|
|
|
self.aux_windows = []
|
2008-11-25 12:47:58 +01:00
|
|
|
self.font = pango.FontDescription("Sans 7")
|
2008-10-29 15:35:47 +01:00
|
|
|
|
|
|
|
# Set up a main window for this this instance of the HUD
|
|
|
|
self.main_window = gtk.Window()
|
2008-09-15 22:31:55 +02:00
|
|
|
# self.window.set_decorated(0)
|
|
|
|
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
|
2008-10-24 21:44:53 +02:00
|
|
|
self.main_window.set_title(table.name + " FPDBHUD")
|
2008-09-15 22:31:55 +02:00
|
|
|
self.main_window.connect("destroy", self.kill_hud)
|
2008-10-27 08:12:12 +01:00
|
|
|
self.main_window.set_decorated(False)
|
2008-11-11 10:36:44 +01:00
|
|
|
self.main_window.set_opacity(self.colors["hudopacity"])
|
2008-10-24 21:44:53 +02:00
|
|
|
#self.main_window.set_transient_for(parent.get_toplevel())
|
2008-09-15 22:31:55 +02:00
|
|
|
|
|
|
|
self.ebox = gtk.EventBox()
|
2008-11-11 10:36:44 +01:00
|
|
|
# self.label = gtk.Label("Right click to close HUD for %s\nor Save Stat Positions." % (table.name))
|
|
|
|
self.label = gtk.Label("FPDB Menu (Right Click)\nLeft-drag to move")
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-10-30 03:37:05 +01:00
|
|
|
self.label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudbgcolor']))
|
|
|
|
self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor']))
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.main_window.add(self.ebox)
|
|
|
|
self.ebox.add(self.label)
|
2008-10-30 03:37:05 +01:00
|
|
|
self.ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudbgcolor']))
|
|
|
|
self.ebox.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor']))
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.main_window.move(self.table.x, self.table.y)
|
|
|
|
|
|
|
|
# A popup window for the main window
|
|
|
|
self.menu = gtk.Menu()
|
|
|
|
self.item1 = gtk.MenuItem('Kill this HUD')
|
|
|
|
self.menu.append(self.item1)
|
|
|
|
self.item1.connect("activate", self.kill_hud)
|
|
|
|
self.item1.show()
|
2008-12-03 09:25:49 +01:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.item2 = gtk.MenuItem('Save Layout')
|
|
|
|
self.menu.append(self.item2)
|
|
|
|
self.item2.connect("activate", self.save_layout)
|
|
|
|
self.item2.show()
|
2008-12-03 09:25:49 +01:00
|
|
|
|
2008-11-07 18:22:37 +01:00
|
|
|
self.item3 = gtk.MenuItem('Reposition Stats')
|
|
|
|
self.menu.append(self.item3)
|
|
|
|
self.item3.connect("activate", self.reposition_windows)
|
|
|
|
self.item3.show()
|
2008-12-03 09:25:49 +01:00
|
|
|
|
|
|
|
self.item4 = gtk.MenuItem('Debug Stat Windows')
|
|
|
|
self.menu.append(self.item4)
|
|
|
|
self.item4.connect("activate", self.debug_stat_windows)
|
|
|
|
self.item4.show()
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.ebox.connect_object("button-press-event", self.on_button_press, self.menu)
|
|
|
|
|
|
|
|
self.main_window.show_all()
|
|
|
|
# set_keep_above(1) for windows
|
2008-10-26 10:34:36 +01:00
|
|
|
if os.name == 'nt':
|
|
|
|
self.topify_window(self.main_window)
|
2008-10-26 20:51:12 +01:00
|
|
|
else:
|
2008-10-27 17:56:09 +01:00
|
|
|
self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(self.table.number) # gets a gdk handle for poker client
|
|
|
|
self.main_window.gdkhandle = gtk.gdk.window_foreign_new(self.main_window.window.xid) # gets a gdk handle for the hud table window
|
2008-10-31 19:34:41 +01:00
|
|
|
self.main_window.gdkhandle.set_transient_for(self.main_window.parentgdkhandle) #
|
|
|
|
|
|
|
|
self.main_window.set_destroy_with_parent(True)
|
2008-10-26 10:34:36 +01:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
def on_button_press(self, widget, event):
|
2008-11-11 10:36:44 +01:00
|
|
|
if event.button == 1:
|
|
|
|
self.main_window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
|
|
|
|
return True
|
2008-09-15 22:31:55 +02:00
|
|
|
if event.button == 3:
|
|
|
|
widget.popup(None, None, None, event.button, event.time)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2008-11-10 11:58:55 +01:00
|
|
|
def kill_hud(self, *args):
|
2008-09-15 22:31:55 +02:00
|
|
|
for k in self.stat_windows.keys():
|
|
|
|
self.stat_windows[k].window.destroy()
|
|
|
|
self.main_window.destroy()
|
|
|
|
self.deleted = True
|
|
|
|
|
2008-11-10 11:58:55 +01:00
|
|
|
def reposition_windows(self, *args):
|
2008-11-07 18:22:37 +01:00
|
|
|
for w in self.stat_windows:
|
|
|
|
self.stat_windows[w].window.move(self.stat_windows[w].x,
|
|
|
|
self.stat_windows[w].y)
|
2008-12-03 09:25:49 +01:00
|
|
|
|
|
|
|
def debug_stat_windows(self, *args):
|
|
|
|
print self.table, "\n", self.main_window.window.get_transient_for()
|
|
|
|
for w in self.stat_windows:
|
|
|
|
print self.stat_windows[w].window.window.get_transient_for()
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
def save_layout(self, *args):
|
2008-11-12 16:28:48 +01:00
|
|
|
new_layout = [(0, 0)] * self.max
|
2008-10-26 20:51:12 +01:00
|
|
|
# todo: have the hud track the poker table's window position regularly, don't forget to update table.x and table.y.
|
2008-09-15 22:31:55 +02:00
|
|
|
for sw in self.stat_windows:
|
|
|
|
loc = self.stat_windows[sw].window.get_position()
|
|
|
|
new_loc = (loc[0] - self.table.x, loc[1] - self.table.y)
|
2008-11-12 16:28:48 +01:00
|
|
|
new_layout[self.stat_windows[sw].adj - 1] = new_loc
|
2008-10-04 22:43:50 +02:00
|
|
|
self.config.edit_layout(self.table.site, self.max, locations = new_layout)
|
2008-09-15 22:31:55 +02:00
|
|
|
self.config.save()
|
|
|
|
|
2008-10-10 02:50:12 +02:00
|
|
|
def adj_seats(self, hand, config):
|
|
|
|
adj = range(0, self.max + 1) # default seat adjustments = no adjustment
|
|
|
|
# does the user have a fav_seat?
|
|
|
|
try:
|
|
|
|
if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0:
|
|
|
|
fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
|
|
|
|
db_connection = Database.Database(config, self.db_name, 'temp')
|
|
|
|
actual_seat = db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
|
|
|
|
db_connection.close_connection()
|
|
|
|
for i in range(0, self.max + 1):
|
|
|
|
j = actual_seat + i
|
|
|
|
if j > self.max: j = j - self.max
|
|
|
|
adj[j] = fav_seat + i
|
|
|
|
if adj[j] > self.max: adj[j] = adj[j] - self.max
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return adj
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
def create(self, hand, config):
|
|
|
|
# update this hud, to the stats and players as of "hand"
|
|
|
|
# hand is the hand id of the most recent hand played at this table
|
|
|
|
#
|
|
|
|
# this method also manages the creating and destruction of stat
|
|
|
|
# windows via calls to the Stat_Window class
|
2008-10-10 02:50:12 +02:00
|
|
|
|
|
|
|
adj = self.adj_seats(hand, config)
|
2008-10-30 03:37:05 +01:00
|
|
|
loc = self.config.get_locations(self.table.site, self.max)
|
|
|
|
|
2008-10-10 02:50:12 +02:00
|
|
|
# create the stat windows
|
2008-10-24 21:44:53 +02:00
|
|
|
for i in range(1, self.max + 1):
|
2008-10-30 03:37:05 +01:00
|
|
|
(x, y) = loc[adj[i]]
|
2008-11-04 11:02:41 +01:00
|
|
|
if self.stat_windows.has_key(i):
|
|
|
|
self.stat_windows[i].relocate(x, y)
|
|
|
|
else:
|
|
|
|
self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game],
|
2008-09-15 22:31:55 +02:00
|
|
|
parent = self,
|
2008-08-19 00:53:25 +02:00
|
|
|
table = self.table,
|
|
|
|
x = x,
|
|
|
|
y = y,
|
|
|
|
seat = i,
|
2008-11-12 16:28:48 +01:00
|
|
|
adj = adj[i],
|
2008-08-19 00:53:25 +02:00
|
|
|
player_id = 'fake',
|
|
|
|
font = self.font)
|
|
|
|
|
2008-08-20 21:29:08 +02:00
|
|
|
self.stats = []
|
|
|
|
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)
|
2008-08-19 00:53:25 +02:00
|
|
|
for stat in config.supported_games[self.poker_game].stats.keys():
|
|
|
|
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
|
2008-11-16 23:53:31 +01:00
|
|
|
|
|
|
|
game_params = config.get_game_parameters(self.poker_game)
|
|
|
|
if not game_params['aux'] == "":
|
|
|
|
aux_params = config.get_aux_parameters(game_params['aux'])
|
|
|
|
self.aux_windows.append(eval("%s.%s(gtk.Window(), config, 'fpdb')" % (aux_params['module'], aux_params['class'])))
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-10-18 17:48:24 +02:00
|
|
|
def update(self, hand, config, stat_dict):
|
2008-09-15 22:31:55 +02:00
|
|
|
self.hand = hand # this is the last hand, so it is available later
|
2008-08-19 00:53:25 +02:00
|
|
|
for s in stat_dict.keys():
|
2008-11-04 11:02:41 +01:00
|
|
|
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
|
|
|
|
self.max = 10
|
|
|
|
self.create(hand, config)
|
|
|
|
self.stat_windows[stat_dict[s]['seat']].player_id = stat_dict[s]['player_id']
|
|
|
|
|
2008-08-20 21:29:08 +02:00
|
|
|
for r in range(0, config.supported_games[self.poker_game].rows):
|
|
|
|
for c in range(0, config.supported_games[self.poker_game].cols):
|
2008-10-31 19:34:41 +01:00
|
|
|
this_stat = config.supported_games[self.poker_game].stats[self.stats[r][c]]
|
2008-08-19 00:53:25 +02:00
|
|
|
number = Stats.do_stat(stat_dict, player = stat_dict[s]['player_id'], stat = self.stats[r][c])
|
2008-10-31 19:34:41 +01:00
|
|
|
statstring = this_stat.hudprefix + str(number[1]) + this_stat.hudsuffix
|
2008-11-25 12:47:58 +01:00
|
|
|
|
|
|
|
if this_stat.hudcolor != "":
|
|
|
|
self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor']))
|
|
|
|
self.stat_windows[stat_dict[s]['seat']].label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(this_stat.hudcolor))
|
|
|
|
|
2008-10-31 19:34:41 +01:00
|
|
|
self.stat_windows[stat_dict[s]['seat']].label[r][c].set_text(statstring)
|
2008-11-25 13:03:33 +01:00
|
|
|
if statstring != "xxx":
|
|
|
|
self.stat_windows[stat_dict[s]['seat']].window.show_all()
|
2008-08-19 00:53:25 +02:00
|
|
|
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)
|
2008-11-16 23:53:31 +01:00
|
|
|
# for m in self.aux_windows:
|
|
|
|
# m.update_data(hand)
|
|
|
|
# m.update_gui(hand)
|
2008-09-15 22:31:55 +02:00
|
|
|
|
|
|
|
def topify_window(self, window):
|
|
|
|
"""Set the specified gtk window to stayontop in MS Windows."""
|
|
|
|
|
|
|
|
def windowEnumerationHandler(hwnd, resultList):
|
|
|
|
'''Callback for win32gui.EnumWindows() to generate list of window handles.'''
|
|
|
|
resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
|
|
|
|
|
|
|
|
unique_name = 'unique name for finding this window'
|
|
|
|
real_name = window.get_title()
|
|
|
|
window.set_title(unique_name)
|
|
|
|
tl_windows = []
|
|
|
|
win32gui.EnumWindows(windowEnumerationHandler, tl_windows)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
for w in tl_windows:
|
|
|
|
if w[1] == unique_name:
|
2008-10-26 10:34:36 +01:00
|
|
|
#win32gui.ShowWindow(w[0], win32con.SW_HIDE)
|
2008-10-26 10:39:43 +01:00
|
|
|
window.parentgdkhandle = gtk.gdk.window_foreign_new(long(self.table.number))
|
|
|
|
self.main_window.gdkhandle = gtk.gdk.window_foreign_new(w[0])
|
|
|
|
self.main_window.gdkhandle.set_transient_for(window.parentgdkhandle)
|
2008-10-26 10:34:36 +01:00
|
|
|
#win32gui.ShowWindow(w[0], win32con.SW_SHOW)
|
|
|
|
|
|
|
|
style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE)
|
|
|
|
#style |= win32con.WS_EX_TOOLWINDOW
|
|
|
|
#style &= ~win32con.WS_EX_APPWINDOW
|
|
|
|
style |= win32con.WS_CLIPCHILDREN
|
|
|
|
win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style)
|
2008-10-24 21:44:53 +02:00
|
|
|
|
2008-10-26 10:34:36 +01:00
|
|
|
|
|
|
|
#win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
|
2008-10-24 21:44:53 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
# notify_id = (w[0],
|
|
|
|
# 0,
|
|
|
|
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
|
|
|
|
# win32con.WM_USER+20,
|
|
|
|
# 0,
|
|
|
|
# '')
|
|
|
|
# win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, notify_id)
|
|
|
|
#
|
|
|
|
window.set_title(real_name)
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
class Stat_Window:
|
|
|
|
|
|
|
|
def button_press_cb(self, widget, event, *args):
|
|
|
|
# This handles all callbacks from button presses on the event boxes in
|
|
|
|
# the stat windows. There is a bit of an ugly kludge to separate single-
|
|
|
|
# and double-clicks.
|
2008-11-10 11:58:55 +01:00
|
|
|
|
|
|
|
if event.button == 3: # right button event
|
2008-08-19 00:53:25 +02:00
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS: # left button single click
|
|
|
|
if self.sb_click > 0: return
|
2008-09-15 22:31:55 +02:00
|
|
|
self.sb_click = gobject.timeout_add(250, self.single_click, widget)
|
2008-08-19 00:53:25 +02:00
|
|
|
elif event.type == gtk.gdk._2BUTTON_PRESS: # left button double click
|
|
|
|
if self.sb_click > 0:
|
|
|
|
gobject.source_remove(self.sb_click)
|
|
|
|
self.sb_click = 0
|
|
|
|
self.double_click(widget, event, *args)
|
|
|
|
|
|
|
|
if event.button == 2: # middle button event
|
2008-11-25 14:52:59 +01:00
|
|
|
self.window.hide()
|
2008-09-15 22:31:55 +02:00
|
|
|
# print "middle button clicked"
|
|
|
|
pass
|
2008-11-10 11:58:55 +01:00
|
|
|
|
|
|
|
if event.button == 1: # left button event
|
|
|
|
if event.state & gtk.gdk.SHIFT_MASK:
|
|
|
|
self.window.begin_resize_drag(gtk.gdk.WINDOW_EDGE_SOUTH_EAST, event.button, int(event.x_root), int(event.y_root), event.time)
|
|
|
|
else:
|
|
|
|
self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
def single_click(self, widget):
|
2008-08-19 00:53:25 +02:00
|
|
|
# Callback from the timeout in the single-click finding part of the
|
|
|
|
# button press call back. This needs to be modified to get all the
|
|
|
|
# arguments from the call.
|
2008-09-15 22:31:55 +02:00
|
|
|
# print "left button clicked"
|
2008-08-19 00:53:25 +02:00
|
|
|
self.sb_click = 0
|
2008-09-15 22:31:55 +02:00
|
|
|
Popup_window(widget, self)
|
2008-08-19 00:53:25 +02:00
|
|
|
return False
|
|
|
|
|
2008-10-31 19:34:41 +01:00
|
|
|
def double_click(self, widget, event, *args):
|
2008-08-19 00:53:25 +02:00
|
|
|
self.toggle_decorated(widget)
|
|
|
|
|
|
|
|
def toggle_decorated(self, widget):
|
|
|
|
top = widget.get_toplevel()
|
|
|
|
(x, y) = top.get_position()
|
|
|
|
|
|
|
|
if top.get_decorated():
|
|
|
|
top.set_decorated(0)
|
|
|
|
top.move(x, y)
|
|
|
|
else:
|
|
|
|
top.set_decorated(1)
|
|
|
|
top.move(x, y)
|
2008-11-04 11:02:41 +01:00
|
|
|
|
|
|
|
def relocate(self, x, y):
|
|
|
|
self.x = x + self.table.x
|
|
|
|
self.y = y + self.table.y
|
|
|
|
self.window.move(self.x, self.y)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-11-12 16:28:48 +01:00
|
|
|
def __init__(self, parent, game, table, seat, adj, x, y, player_id, font):
|
2008-09-15 22:31:55 +02:00
|
|
|
self.parent = parent # Hud object that this stat window belongs to
|
|
|
|
self.game = game # Configuration object for the curren
|
|
|
|
self.table = table # Table object where this is going
|
2008-11-12 16:28:48 +01:00
|
|
|
self.seat = seat # seat number of his player
|
|
|
|
self.adj = adj # the adjusted seat number for this player
|
2008-09-15 22:31:55 +02:00
|
|
|
self.x = x + table.x # table.x and y are the location of the table
|
|
|
|
self.y = y + table.y # x and y are the location relative to table.x & y
|
|
|
|
self.player_id = player_id # looks like this isn't used ;)
|
|
|
|
self.sb_click = 0 # used to figure out button clicks
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
self.window = gtk.Window()
|
|
|
|
self.window.set_decorated(0)
|
|
|
|
self.window.set_gravity(gtk.gdk.GRAVITY_STATIC)
|
2008-10-28 12:30:22 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
self.window.set_title("%s" % seat)
|
2008-08-22 22:10:32 +02:00
|
|
|
self.window.set_property("skip-taskbar-hint", True)
|
2008-10-24 21:44:53 +02:00
|
|
|
self.window.set_transient_for(parent.main_window)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
self.grid = gtk.Table(rows = self.game.rows, columns = self.game.cols, homogeneous = False)
|
|
|
|
self.window.add(self.grid)
|
|
|
|
|
|
|
|
self.e_box = []
|
|
|
|
self.frame = []
|
|
|
|
self.label = []
|
|
|
|
for r in range(self.game.rows):
|
|
|
|
self.e_box.append([])
|
|
|
|
self.label.append([])
|
|
|
|
for c in range(self.game.cols):
|
|
|
|
self.e_box[r].append( gtk.EventBox() )
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-10-30 03:37:05 +01:00
|
|
|
self.e_box[r][c].modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudbgcolor']))
|
|
|
|
self.e_box[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudfgcolor']))
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
Stats.do_tip(self.e_box[r][c], 'farts')
|
2008-09-15 22:31:55 +02:00
|
|
|
self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
|
2008-08-19 00:53:25 +02:00
|
|
|
self.label[r].append( gtk.Label('xxx') )
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-10-30 03:37:05 +01:00
|
|
|
self.label[r][c].modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudbgcolor']))
|
|
|
|
self.label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudfgcolor']))
|
2008-10-27 11:29:39 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
self.e_box[r][c].add(self.label[r][c])
|
|
|
|
self.e_box[r][c].connect("button_press_event", self.button_press_cb)
|
2008-11-25 12:47:58 +01:00
|
|
|
font = pango.FontDescription("Sans 7")
|
2008-08-19 00:53:25 +02:00
|
|
|
self.label[r][c].modify_font(font)
|
2008-10-31 19:34:41 +01:00
|
|
|
|
2008-11-10 11:58:55 +01:00
|
|
|
self.window.set_opacity(parent.colors['hudopacity'])
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
self.window.move(self.x, self.y)
|
2008-12-03 19:35:19 +01:00
|
|
|
|
2008-11-25 13:03:33 +01:00
|
|
|
self.window.hide()
|
2008-09-15 22:31:55 +02:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
def destroy(*args): # call back for terminating the main eventloop
|
|
|
|
gtk.main_quit()
|
2008-09-15 22:31:55 +02:00
|
|
|
|
|
|
|
class Popup_window:
|
|
|
|
def __init__(self, parent, stat_window):
|
|
|
|
self.sb_click = 0
|
|
|
|
|
|
|
|
# create the popup window
|
|
|
|
self.window = gtk.Window()
|
|
|
|
self.window.set_decorated(0)
|
|
|
|
self.window.set_gravity(gtk.gdk.GRAVITY_STATIC)
|
2008-11-05 22:52:47 +01:00
|
|
|
# self.window.set_keep_above(1)
|
2008-09-15 22:31:55 +02:00
|
|
|
self.window.set_title("popup")
|
|
|
|
self.window.set_property("skip-taskbar-hint", True)
|
|
|
|
self.window.set_transient_for(parent.get_toplevel())
|
2008-10-24 21:44:53 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.ebox = gtk.EventBox()
|
|
|
|
self.ebox.connect("button_press_event", self.button_press_cb)
|
|
|
|
self.lab = gtk.Label("stuff\nstuff\nstuff")
|
|
|
|
|
|
|
|
# need an event box so we can respond to clicks
|
|
|
|
self.window.add(self.ebox)
|
|
|
|
self.ebox.add(self.lab)
|
2008-11-06 12:58:28 +01:00
|
|
|
|
|
|
|
self.ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(stat_window.parent.colors['hudbgcolor']))
|
|
|
|
self.ebox.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(stat_window.parent.colors['hudfgcolor']))
|
|
|
|
self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(stat_window.parent.colors['hudbgcolor']))
|
|
|
|
self.window.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(stat_window.parent.colors['hudfgcolor']))
|
|
|
|
self.lab.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(stat_window.parent.colors['hudbgcolor']))
|
|
|
|
self.lab.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(stat_window.parent.colors['hudfgcolor']))
|
|
|
|
|
2008-11-27 14:35:17 +01:00
|
|
|
# self.window.realize()
|
2008-09-15 22:31:55 +02:00
|
|
|
|
|
|
|
# figure out the row, col address of the click that activated the popup
|
|
|
|
row = 0
|
|
|
|
col = 0
|
|
|
|
for r in range(0, stat_window.game.rows):
|
|
|
|
for c in range(0, stat_window.game.cols):
|
|
|
|
if stat_window.e_box[r][c] == parent:
|
|
|
|
row = r
|
|
|
|
col = c
|
|
|
|
break
|
|
|
|
|
|
|
|
# figure out what popup format we're using
|
|
|
|
popup_format = "default"
|
|
|
|
for stat in stat_window.game.stats.keys():
|
|
|
|
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():
|
|
|
|
if w == popup_format:
|
|
|
|
stat_list = stat_window.parent.config.popup_windows[w].pu_stats
|
|
|
|
break
|
|
|
|
|
|
|
|
# get a database connection
|
|
|
|
db_connection = Database.Database(stat_window.parent.config, stat_window.parent.db_name, 'temp')
|
|
|
|
|
|
|
|
# calculate the stat_dict and then create the text for the pu
|
|
|
|
# stat_dict = db_connection.get_stats_from_hand(stat_window.parent.hand, stat_window.player_id)
|
|
|
|
stat_dict = db_connection.get_stats_from_hand(stat_window.parent.hand)
|
|
|
|
db_connection.close_connection()
|
|
|
|
|
|
|
|
pu_text = ""
|
|
|
|
for s in stat_list:
|
|
|
|
number = Stats.do_stat(stat_dict, player = int(stat_window.player_id), stat = s)
|
|
|
|
pu_text += number[3] + "\n"
|
|
|
|
|
|
|
|
self.lab.set_text(pu_text)
|
|
|
|
self.window.show_all()
|
2008-11-06 12:58:28 +01:00
|
|
|
|
2008-11-10 11:58:55 +01:00
|
|
|
self.window.set_transient_for(stat_window.window)
|
2008-11-06 12:58:28 +01:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
# set_keep_above(1) for windows
|
|
|
|
if os.name == 'nt': self.topify_window(self.window)
|
|
|
|
|
|
|
|
def button_press_cb(self, widget, event, *args):
|
|
|
|
# This handles all callbacks from button presses on the event boxes in
|
|
|
|
# the popup windows. There is a bit of an ugly kludge to separate single-
|
|
|
|
# and double-clicks. This is the same code as in the Stat_window class
|
|
|
|
if event.button == 1: # left button event
|
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS: # left button single click
|
|
|
|
if self.sb_click > 0: return
|
|
|
|
self.sb_click = gobject.timeout_add(250, self.single_click, widget)
|
|
|
|
elif event.type == gtk.gdk._2BUTTON_PRESS: # left button double click
|
|
|
|
if self.sb_click > 0:
|
|
|
|
gobject.source_remove(self.sb_click)
|
|
|
|
self.sb_click = 0
|
|
|
|
self.double_click(widget, event, *args)
|
|
|
|
|
|
|
|
if event.button == 2: # middle button event
|
|
|
|
pass
|
|
|
|
# print "middle button clicked"
|
|
|
|
|
|
|
|
if event.button == 3: # right button event
|
|
|
|
pass
|
|
|
|
# print "right button clicked"
|
|
|
|
|
|
|
|
def single_click(self, widget):
|
|
|
|
# Callback from the timeout in the single-click finding part of the
|
|
|
|
# button press call back. This needs to be modified to get all the
|
|
|
|
# arguments from the call.
|
|
|
|
self.sb_click = 0
|
|
|
|
self.window.destroy()
|
|
|
|
return False
|
|
|
|
|
|
|
|
def double_click(self, widget, event, *args):
|
|
|
|
self.toggle_decorated(widget)
|
|
|
|
|
|
|
|
def toggle_decorated(self, widget):
|
|
|
|
top = widget.get_toplevel()
|
|
|
|
(x, y) = top.get_position()
|
|
|
|
|
|
|
|
if top.get_decorated():
|
|
|
|
top.set_decorated(0)
|
|
|
|
top.move(x, y)
|
|
|
|
else:
|
|
|
|
top.set_decorated(1)
|
|
|
|
top.move(x, y)
|
|
|
|
|
|
|
|
def topify_window(self, window):
|
|
|
|
"""Set the specified gtk window to stayontop in MS Windows."""
|
|
|
|
|
|
|
|
def windowEnumerationHandler(hwnd, resultList):
|
|
|
|
'''Callback for win32gui.EnumWindows() to generate list of window handles.'''
|
|
|
|
resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
|
|
|
|
|
|
|
|
unique_name = 'unique name for finding this window'
|
|
|
|
real_name = window.get_title()
|
|
|
|
window.set_title(unique_name)
|
|
|
|
tl_windows = []
|
|
|
|
win32gui.EnumWindows(windowEnumerationHandler, tl_windows)
|
|
|
|
|
|
|
|
for w in tl_windows:
|
|
|
|
if w[1] == unique_name:
|
2008-10-24 21:44:53 +02:00
|
|
|
# win32gui.ShowWindow(w[0], win32con.SW_HIDE)
|
|
|
|
# style = win32gui.GetWindowLong(w[0], win32con.GWL_EXSTYLE)
|
|
|
|
# style |= win32con.WS_EX_TOOLWINDOW
|
|
|
|
# style &= ~win32con.WS_EX_APPWINDOW
|
|
|
|
# win32gui.SetWindowLong(w[0], win32con.GWL_EXSTYLE, style)
|
|
|
|
# win32gui.ShowWindow(w[0], win32con.SW_SHOW)
|
|
|
|
win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
# notify_id = (w[0],
|
|
|
|
# 0,
|
|
|
|
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
|
|
|
|
# win32con.WM_USER+20,
|
|
|
|
# 0,
|
|
|
|
# '')
|
|
|
|
# win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, notify_id)
|
|
|
|
#
|
|
|
|
window.set_title(real_name)
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
if __name__== "__main__":
|
|
|
|
main_window = gtk.Window()
|
|
|
|
main_window.connect("destroy", destroy)
|
|
|
|
label = gtk.Label('Fake main window, blah blah, blah\nblah, blah')
|
|
|
|
main_window.add(label)
|
|
|
|
main_window.show_all()
|
|
|
|
|
|
|
|
c = Configuration.Config()
|
2008-10-24 21:44:53 +02:00
|
|
|
#tables = Tables.discover(c)
|
2008-11-25 12:47:58 +01:00
|
|
|
t = Tables.discover_table_by_name(c, "Motorway")
|
2008-10-24 21:44:53 +02:00
|
|
|
if t is None:
|
|
|
|
print "Table not found."
|
2008-08-22 22:10:32 +02:00
|
|
|
db = Database.Database(c, 'fpdb', 'holdem')
|
|
|
|
|
2008-10-24 21:44:53 +02:00
|
|
|
# for t in tables:
|
|
|
|
win = Hud(t, 10, 'holdem', c, db)
|
|
|
|
win.create(1, c)
|
2008-08-19 00:53:25 +02:00
|
|
|
# t.get_details()
|
2008-10-24 21:44:53 +02:00
|
|
|
win.update(8300, db, c)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
gtk.main()
|