Add 'Currencies' filter to the ring player stats viewer.
[fpdb-dooglus.git] / pyfpdb / GuiStove.py
blobf738e67f45015cbb4377b1125437398db5b5c684
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2011 Steffen Schaumburg
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 import L10n
19 _ = L10n.get_translation()
21 import pygtk
22 pygtk.require('2.0')
23 import gtk
24 import os
25 import sys
27 import Charset
28 import Stove
30 DEBUG = False
32 class GuiStove():
34 def __init__(self, config, parent, debug=True):
35 """Constructor for GuiStove"""
36 self.stove = Stove.Stove()
37 self.ev = None
38 self.boardtext = ""
39 self.herorange = ""
40 self.villainrange = ""
41 self.conf = config
42 self.parent = parent
44 self.mainHBox = gtk.HBox(False, 0)
46 # hierarchy: self.mainHBox / self.notebook
48 self.notebook = gtk.Notebook()
49 self.notebook.set_tab_pos(gtk.POS_TOP)
50 self.notebook.set_show_tabs(True)
51 self.notebook.set_show_border(True)
53 self.createFlopTab()
54 self.createStudTab()
55 self.createDrawTab()
58 self.mainHBox.add(self.notebook)
60 self.mainHBox.show_all()
62 if DEBUG == False:
63 warning_string = _("Stove is a GUI mockup of a EV calculation page, and completely non functional.") + "\n "
64 warning_string += _("Unless you are interested in developing this feature, please ignore this page.") + "\n "
65 warning_string += _("If you are interested in developing the code further see GuiStove.py and Stove.py.") + "\n "
66 warning_string += _("Thank you")
67 self.warning_box(warning_string)
70 def warning_box(self, str, diatitle=_("FPDB WARNING")):
71 diaWarning = gtk.Dialog(title=diatitle, parent=self.parent, flags=gtk.DIALOG_DESTROY_WITH_PARENT, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK))
73 label = gtk.Label(str)
74 diaWarning.vbox.add(label)
75 label.show()
77 response = diaWarning.run()
78 diaWarning.destroy()
79 return response
82 def get_active_text(combobox):
83 model = combobox.get_model()
84 active = combobox.get_active()
85 if active < 0:
86 return None
87 return model[active][0]
89 def create_combo_box(self, strings):
90 combobox = gtk.combo_box_new_text()
91 for label in strings:
92 combobox.append_text(label)
93 combobox.set_active(0)
94 return combobox
96 def createDrawTab(self):
97 tab_title = _("Draw")
98 label = gtk.Label(tab_title)
100 ddbox = gtk.VBox(False, 0)
101 self.notebook.append_page(ddbox, label)
103 def createStudTab(self):
104 tab_title = _("Stud")
105 label = gtk.Label(tab_title)
107 ddbox = gtk.VBox(False, 0)
108 self.notebook.append_page(ddbox, label)
110 def createFlopTab(self):
111 # hierarchy: hbox / ddbox / ddhbox / Label + flop_games_cb | label + players_cb
112 # / gamehbox / in_frame / table /
113 # / out_frame
115 tab_title = _("Flop")
116 label = gtk.Label(tab_title)
118 ddbox = gtk.VBox(False, 0)
119 self.notebook.append_page(ddbox, label)
121 ddhbox = gtk.HBox(False, 0)
122 gamehbox = gtk.HBox(False, 0)
124 ddbox.add(ddhbox)
125 ddbox.add(gamehbox)
127 # Combo boxes in the top row
129 games = [ "Holdem", "Omaha", "Omaha 8", ]
130 players = [ "2", "3", "4", "5", "6", "7", "8", "9", "10" ]
131 flop_games_cb = self.create_combo_box(games)
132 players_cb = self.create_combo_box(players)
134 label = gtk.Label(_("Gametype")+":")
135 ddhbox.add(label)
136 ddhbox.add(flop_games_cb)
137 label = gtk.Label(_("Players")+":")
138 ddhbox.add(label)
139 ddhbox.add(players_cb)
141 # Frames for Stove input and output
143 in_frame = gtk.Frame(_("Input:"))
144 out_frame = gtk.Frame(_("Output:"))
146 gamehbox.add(in_frame)
147 gamehbox.add(out_frame)
149 self.outstring = """
150 No board given. Using Monte-Carlo simulation...
151 Enumerated 2053443 possible plays.
152 Your hand: (Ad Ac)
153 Against the range: {
154 AhAd, AhAs, AdAs, KhKd, KhKs,
155 KhKc, KdKs, KdKc, KsKc, QhQd,
156 QhQs, QhQc, QdQs, QdQc, QsQc,
157 JhJd, JhJs, JhJc, JdJs, JdJc,
158 JsJc
161 Win Lose Tie
162 69.91% 15.83% 14.26%
165 self.outputlabel = gtk.Label(self.outstring)
166 out_frame.add(self.outputlabel)
168 # Input Frame
169 table = gtk.Table(4, 5, True)
170 label = gtk.Label(_("Board:"))
171 board = gtk.Entry()
172 board.connect("changed", self.set_board_flop, board)
174 btn1 = gtk.Button()
175 btn1.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
176 #btn.connect('clicked', self._some_function, arg)
177 table.attach(label, 0, 1, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
178 table.attach(board, 1, 2, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
179 table.attach(btn1, 2, 3, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
182 label = gtk.Label(_("Player1:"))
183 board = gtk.Entry()
184 board.connect("changed", self.set_hero_cards_flop, board)
185 btn2 = gtk.Button()
186 btn2.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
187 #btn.connect('clicked', self._some_function, arg)
188 btn3 = gtk.Button()
189 btn3.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
190 #btn.connect('clicked', self._some_function, arg)
191 table.attach(label, 0, 1, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
192 table.attach(board, 1, 2, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
193 table.attach(btn2, 2, 3, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
194 table.attach(btn3, 3, 4, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
197 label = gtk.Label(_("Player2:"))
198 board = gtk.Entry()
199 board.connect("changed", self.set_villain_cards_flop, board)
200 btn4 = gtk.Button()
201 btn4.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
202 #btn.connect('clicked', self._some_function, arg)
203 btn5 = gtk.Button()
204 btn5.set_image(gtk.image_new_from_stock(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON))
205 #btn.connect('clicked', self._some_function, arg)
206 table.attach(label, 0, 1, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
207 table.attach(board, 1, 2, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
208 table.attach(btn4, 2, 3, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
209 table.attach(btn5, 3, 4, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
211 btn6 = gtk.Button(_("Results"))
212 btn6.connect("pressed", self.update_flop_output_pane, btn6)
213 table.attach(btn6, 0, 1, 3, 4, xoptions=gtk.SHRINK, yoptions=gtk.SHRINK)
215 in_frame.add(table)
217 def set_output_label(self, string):
218 self.outputlabel.set_text(string)
220 def set_board_flop(self, caller, widget):
221 print (_("DEBUG:") + " " + _("called") + " set_board_flop: '%s' '%s'" % (caller ,widget))
222 self.boardtext = widget.get_text()
224 def set_hero_cards_flop(self, caller, widget):
225 print (_("DEBUG:") + " " + _("called") + " set_hero_cards_flop")
226 self.herorange = widget.get_text()
228 def set_villain_cards_flop(self, caller, widget):
229 print (_("DEBUG:") + " " + _("called") + " set_villain_cards_flop")
230 self.villainrange = widget.get_text()
232 def update_flop_output_pane(self, caller, widget):
233 print (_("DEBUG:") + " " + _("called") + " update_flop_output_pane")
234 self.stove.set_board_string(self.boardtext)
235 self.stove.set_hero_cards_string(self.herorange)
236 self.stove.set_villain_range_string(self.villainrange)
237 print (_("DEBUG:") + ("odds_for_range"))
238 self.ev = Stove.odds_for_range(self.stove)
239 print (_("DEBUG:") + " " + ("set_output_label"))
240 self.set_output_label(self.ev.output)
244 def get_vbox(self):
245 """returns the vbox of this thread"""
246 return self.mainHBox
247 #end def get_vbox