Expanded my entry in contributors.txt.
[fpdb-dooglus.git] / pyfpdb / Hello.py
blobcfb31cf9abf606a5a9f7ff74055628ca18ba9c62
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """Hello.py
5 Hello World demostration for Aux_Window.
6 """
7 # Copyright 2009-2011, Ray E. Barker
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ########################################################################
25 # to do
26 # add another class that demonstrates querying the db
28 # Standard Library modules
29 import sys
31 # pyGTK modules
32 import pygtk
33 import gtk
34 import gobject
35 import L10n
36 _ = L10n.get_translation()
38 # FreePokerTools modules
39 from Mucked import Aux_Window
40 from Mucked import Seat_Window
41 from Mucked import Aux_Seats
43 class Hello(Aux_Window):
44 """A 'Hello World' Aux_Window demo."""
45 def create(self):
46 print _("creating Hello")
47 # This demo simply creates a label in a window.
48 self.container = gtk.Window()
49 self.container.add(gtk.Label(_("Hello World")))
50 # and shows it. There is no functionality.
51 self.container.show_all()
53 class Hello_plus(Aux_Window):
54 """A slightly more complex 'Hello World demo."""
55 def __init__(self, hud, config, params):
56 """Initialize a new aux_window object."""
57 # Initialize the aux_window object. Do not interact with the gui
58 # in this function.
59 self.hud = hud # hud object that this aux window supports
60 self.config = config # configuration object for this aux window to use
61 self.params = params # hash aux params from config
63 self.hands_played = 0 # initialize the hands played counter
65 # get the site we are playing from the HUD
66 self.site = hud.site
67 print _("site ="), hud.site # print it to the terminal, to make sure
69 # now get our screen name for that site from the configuration
70 # wrap it in a try/except in case screen name isn't set up in the config file
71 try:
72 site_params = self.config.get_site_parameters(self.hud.site)
73 self.hero = site_params['screen_name']
74 except:
75 self.hero = _('YOUR NAME HERE')
76 print "hero =", self.hero
79 def create(self):
80 """Creates the gui."""
81 self.container = gtk.Window() # create a gtk window for our container
82 self.label = gtk.Label("") # create a blank label to write in update_gui
83 self.container.add(self.label) # add it to our container
84 self.container.show_all() # show the container and its contents
86 def update_data(self, new_hand_id, db_connection):
87 """Increment the hands.played attribute."""
88 # This function will be called from the main program, in a thread separate from
89 # the gui. Therefore complex calculations can be done without slowing down the
90 # HUD. Long-running calculations will delay the appearance or updating of the HUD.
91 # This function should NOT interact with the gui--that will cause unpredictable
92 # results on some systems.
94 # This long running calculation is incrementing the number of hands played.
95 self.hands_played = self.hands_played + 1
97 def update_gui(self, new_hand_id):
98 """Update the aux_window gui."""
99 # This function runs inside the gui thread and should only be used for
100 # interacting with the gui. Long-running calculations should not be done
101 # in this function--they will prevent HUD interaction until they are
102 # complete.
104 # Here, we just update the label in our aux_window from the number of
105 # hands played that was updated in the "update_data()" function.
106 self.label.set_text(_("Hello %s\nYou have played %d hands\n on %s.") % (self.hero, self.hands_played, self.site))
108 class Hello_Seats(Aux_Seats):
109 """A 'Hello World' Seat_Window demo."""
111 def create_contents(self, container, i):
112 container.label = gtk.Label("empty")
113 container.add(container.label)
114 container.show_all()
116 def update_contents(self, container, i):
117 if i == "common": return
118 id = self.get_id_from_seat(i)
119 if id == None:
120 container.label.set_text("empty")
121 else:
122 container.label.set_text("player = %s" % self.hud.stat_dict[id]['screen_name'])