Skip to content

Commit

Permalink
Merge branch 'n-decimals'
Browse files Browse the repository at this point in the history
  • Loading branch information
truenicoco committed Jun 10, 2020
2 parents 0103627 + f197f34 commit d7cb6b3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
27 changes: 25 additions & 2 deletions hh_creator/dialog.py
Expand Up @@ -28,6 +28,7 @@ class NewHandDialog(QtWidgets.QDialog, AutoUI):
"Currency": Field(str, True),
"Variant": Field(str, False, "comboBox", "CurrentText"),
"CurrencyPosition": Field(str, False, "comboBox", "CurrentText"),
"Decimals": Field(int, True),
}

N_CARDS = {"Texas": 2, "Omaha": 4}
Expand All @@ -51,6 +52,13 @@ def __init__(self, *a, **kw):
self.open_instead = False
self.update_ok()

def _auto_decimals(self):
sb = self.get_field_value("SB", Decimal())
ante = self.get_field_value("Ante", Decimal())
self._get_widget("Decimals").setText(
str(max(-sb.as_tuple().exponent, -ante.as_tuple().exponent, 1))
)

def _auto_sb(self):
self._get_widget("SB").setText(str(self.get_field_value("BB") / 2))

Expand All @@ -70,7 +78,7 @@ def get_field_value(self, field_name, default=None):
text = widget.currentText()

if (
field_name != "SB"
field_name not in ("SB", "Decimals")
and field.checkable
and not self._get_checkbox(field_name).isChecked()
):
Expand All @@ -87,6 +95,8 @@ def get_n_cards(self):

@pyqtSlot(str)
def on_lineEditSB_textEdited(self, value):
if not self.widgets["checkBoxDecimals"].isChecked():
self._auto_decimals()
self.update_ok()

@pyqtSlot(bool)
Expand All @@ -95,10 +105,18 @@ def on_checkBoxSB_toggled(self, checked):
self._auto_sb()
self.update_ok()

@pyqtSlot(bool)
def on_checkBoxDecimals_toggled(self, checked):
if not checked:
self._auto_decimals()
self.update_ok()

@pyqtSlot(str)
def on_lineEditBB_textEdited(self, value):
if not self.widgets["checkBoxSB"].isChecked():
self._auto_sb()
if not self.widgets["checkBoxDecimals"].isChecked():
self._auto_decimals()
self.update_ok()

@pyqtSlot(str)
Expand All @@ -113,6 +131,7 @@ def on_checkBoxStraddle_toggled(self, checked):

@pyqtSlot(str)
def on_lineEditAnte_textEdited(self, value):
self._auto_decimals()
self.update_ok()

@pyqtSlot(bool)
Expand All @@ -136,6 +155,7 @@ def update_ok(self):
straddle = self.get_field_value("Straddle", default=0)
ante = self.get_field_value("Ante", default=0)
players = self.get_field_value("Players", default=0)
decimals = self.get_field_value("Decimals", default=0)

sb_ok = 0 <= sb <= bb
bb_ok = 0 < bb
Expand All @@ -145,8 +165,11 @@ def update_ok(self):
)
ante_ok = not self._get_checkbox("Ante").isChecked() or 0 < ante
players_ok = 2 <= players <= 10
decimals_ok = decimals >= 0

self.ok_button.setEnabled(all((sb_ok, bb_ok, straddle_ok, ante_ok, players_ok)))
self.ok_button.setEnabled(
all((sb_ok, bb_ok, straddle_ok, ante_ok, players_ok, decimals_ok))
)


class NameDialog(QtWidgets.QDialog, AutoUI):
Expand Down
10 changes: 6 additions & 4 deletions hh_creator/main_window.py
Expand Up @@ -127,7 +127,7 @@ def on_actionNew_triggered(self):
if code:
sb = dialog.get_field_value("SB")
ante = dialog.get_field_value("Ante")
n_digits = max(-sb.as_tuple().exponent, -ante.as_tuple().exponent, 1)
n_digits = dialog.get_field_value("Decimals")

log.debug(f"Will use {n_digits} digits for display rounding")
TextItem.n_decimals = n_digits
Expand Down Expand Up @@ -207,8 +207,6 @@ def on_pushButtonNext_clicked(self):
pseudo_actions_remaining = self.replay_action_cursor != len(
self.hand_history.editable_actions()
)
# if hand_history.last_action is not None:
# hand_history.current_street = hand_history.last_action.street
self.scene.sync_with_hh(
hand_history, update_board=pseudo_actions_remaining
)
Expand Down Expand Up @@ -383,6 +381,7 @@ def hide_cards_before_showdown(self):

def save_hh(self, filename):
hh_dict = self.hand_history.to_dict()
hh_dict["n_decimals"] = TextItem.n_decimals
hh_dict["player_names"] = [
p.name_item.content for p in self.scene.get_active_players_after_button()
]
Expand All @@ -409,9 +408,12 @@ def load_hh(self, filename):
self.hand_history = HandHistory.from_dict(hh_dict)
self.scene.load_dict(hh_dict, self.hand_history)
self.widgets["checkBoxEditMode"].setChecked(False)
# Compat with previous HH format that didn't include n_decimals
sb = self.hand_history.small_blind
ante = self.hand_history.ante
n_digits = max(-sb.as_tuple().exponent, -ante.as_tuple().exponent, 1)
n_digits = hh_dict.get(
"n_decimals", max(-sb.as_tuple().exponent, -ante.as_tuple().exponent, 1)
)
TextItem.n_decimals = n_digits
self.pushButtonStart.clicked.emit()

Expand Down
2 changes: 2 additions & 0 deletions hh_creator/resource/default.ini
Expand Up @@ -12,6 +12,8 @@ currencyposition = après
currency = €
variant = Texas
default_stack_in_bb = 100
decimals_checked = False
decimals = 1

[behavior]
replay_start_with_blinds_posted = True
Expand Down
25 changes: 23 additions & 2 deletions hh_creator/resource/ui/NewHandDialog.ui
Expand Up @@ -85,14 +85,14 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Variante</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QComboBox" name="comboBoxVariant">
<item>
<property name="text">
Expand Down Expand Up @@ -179,6 +179,27 @@
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Décimales</string>
</property>
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEditDecimals"/>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDecimals">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit d7cb6b3

Please sign in to comment.