Skip to content

Commit 14edcda

Browse files
Merge pull request #505 from AndreWohnsland/dev
Hide virgin and alcohol option in case of single ingredient
2 parents 94dd862 + b92c5ae commit 14edcda

File tree

18 files changed

+116
-143
lines changed

18 files changed

+116
-143
lines changed

src/config/config_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ def __init__(self) -> None:
518518
self.old_ingredient: list[str] = []
519519
self.selected_team = "No Team"
520520
self.team_member_name: str | None = None
521-
self.alcohol_factor: float = 1.0
522521
self.is_v1 = False
523522
self.restricted_mode_active = False
524523
self.cocktail_status = CocktailStatus()

src/dialog_handler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,6 @@ def adjust_mainwindow(self, w: Ui_MainWindow) -> None:
770770
ui_element.setText(self._choose_language(text_name))
771771

772772
def adjust_cocktail_selection_screen(self, w: Ui_CocktailSelection) -> None:
773-
window = "cocktail_selection"
774-
w.virgin_checkbox.setText(self._choose_language("activate_virgin", window))
775773
w.button_back.setText(self._choose_language("back"))
776774

777775
def adjust_available_windows(self, w: Ui_available) -> None:

src/language.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ ui:
455455
prepare_button:
456456
en: ' Prepare {amount} {unit}'
457457
de: ' {amount} {unit} Zubereiten'
458-
activate_virgin:
459-
en: 'Virgin (no alcohol)'
460-
de: 'Virgin (kein Alkohol)'
461458

462459
##### AVAILABLE WINDOW #####
463460
# all values for available window

src/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def virgin_machineadds(self) -> list[Ingredient]:
137137
@property
138138
def is_virgin(self) -> bool:
139139
"""Returns if the cocktail is virgin."""
140-
return self.adjusted_alcohol == 0
140+
# single ingredient cocktails will not be considered virgin, because they are an ingredient (wrapper)
141+
return self.adjusted_alcohol == 0 and len(self.ingredients) > 1
141142

142143
def current_price(
143144
self,

src/ui/icons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def set_cocktail_selection_icons(self, w: Ui_CocktailSelection) -> None:
145145
(w.prepare_button, _COCKTAIL_ICON, False),
146146
(w.increase_alcohol, _SKULL, True),
147147
(w.decrease_alcohol, _EASY, True),
148+
(w.virgin_toggle, _VIRGIN_ICON, True),
148149
]:
149150
fa_icon: QIcon = qta.icon(icon, color=self.color.background)
150151
self.set_icon(ui_element, fa_icon, no_text)

src/ui/setup_cocktail_selection.py

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
from PyQt6.QtWidgets import QDialog, QLabel, QPushButton, QSizePolicy
77

88
from src.config.config_manager import CONFIG as cfg
9-
from src.config.config_manager import shared
109
from src.database_commander import DB_COMMANDER
1110
from src.dialog_handler import UI_LANGUAGE
1211
from src.display_controller import DP_CONTROLLER
1312
from src.image_utils import find_cocktail_image
1413
from src.models import Cocktail, Ingredient
15-
from src.ui.creation_utils import LARGE_FONT, create_button, create_label, set_strike_through, set_underline
14+
from src.ui.creation_utils import LARGE_FONT, create_button, create_label, set_underline
1615
from src.ui.icons import IconSetter
1716
from src.ui.shared import qt_prepare_flow
1817
from src.ui_elements import Ui_CocktailSelection
@@ -44,11 +43,28 @@ def __init__(self, mainscreen: MainScreen, cocktail: Cocktail) -> None:
4443

4544
UI_LANGUAGE.adjust_cocktail_selection_screen(self)
4645
self.clear_recipe_data_maker()
47-
# Also resets the alcohol factor
48-
self.reset_alcohol_factor()
4946
DP_CONTROLLER.set_display_settings(self, False)
5047
self._connect_elements()
5148

49+
@property
50+
def can_change_virgin(self) -> bool:
51+
"""Return if the cocktail can have a virgin option."""
52+
return self.cocktail.virgin_available and not self.cocktail.only_virgin
53+
54+
@property
55+
def alcohol_factor(self) -> float:
56+
if self.virgin_toggle.isChecked():
57+
return 0.0
58+
if self.increase_alcohol.isChecked():
59+
return 1.3
60+
if self.decrease_alcohol.isChecked():
61+
return 0.7
62+
return 1.0
63+
64+
@property
65+
def is_virgin(self) -> bool:
66+
return self.virgin_toggle.isChecked()
67+
5268
def _set_image(self) -> None:
5369
"""Set the image of the cocktail."""
5470
image_path = find_cocktail_image(self.cocktail)
@@ -60,10 +76,8 @@ def _connect_elements(self) -> None:
6076
self.button_back.clicked.connect(self.mainscreen.switch_to_cocktail_list)
6177
self.increase_alcohol.clicked.connect(self._higher_alcohol)
6278
self.decrease_alcohol.clicked.connect(self._lower_alcohol)
63-
if cfg.payment_enabled:
64-
self.decrease_alcohol.hide()
65-
self.increase_alcohol.hide()
66-
self.virgin_checkbox.stateChanged.connect(self.update_cocktail_data)
79+
self.virgin_toggle.clicked.connect(self._toggle_virgin)
80+
self._apply_button_visibility()
6781
self.adjust_maker_label_size_cocktaildata()
6882

6983
def set_cocktail(self, cocktail: Cocktail) -> None:
@@ -98,11 +112,7 @@ def _scale_cocktail(self, amount: int | None = None) -> None:
98112
# overwrite the amount if the cocktail has a fixed volume
99113
if cfg.MAKER_USE_RECIPE_VOLUME:
100114
amount = self.cocktail.amount
101-
factor = shared.alcohol_factor * (cfg.MAKER_ALCOHOL_FACTOR / 100) # remember this is percent
102-
is_virgin = self.virgin_checkbox.isChecked()
103-
if is_virgin:
104-
factor = 0
105-
self.cocktail.scale_cocktail(amount, factor)
115+
self.cocktail.scale_cocktail(amount, self.alcohol_factor * (cfg.MAKER_ALCOHOL_FACTOR / 100))
106116

107117
def update_cocktail_data(self) -> None:
108118
"""Update the cocktail data in the selection view."""
@@ -112,14 +122,15 @@ def update_cocktail_data(self) -> None:
112122
self.prepare_button.setText(
113123
UI_LANGUAGE.get_translation("prepare_button", "cocktail_selection", amount=amount, unit=cfg.EXP_MAKER_UNIT)
114124
)
115-
virgin_prefix = "Virgin " if self.cocktail.is_virgin else ""
125+
virgin_prefix = "Virgin " if self.is_virgin else ""
116126
self.LAlkoholname.setText(f"{virgin_prefix}{self.cocktail.name}")
117127
display_volume = self._decide_rounding(amount * cfg.EXP_MAKER_FACTOR, 20)
118128
self.LMenge.setText(f"{display_volume} {cfg.EXP_MAKER_UNIT}")
119129
self.LAlkoholgehalt.setText(f"{self.cocktail.adjusted_alcohol:.1f}%")
120130
display_data = self.cocktail.machineadds
121131
hand = self.cocktail.handadds
122-
self._apply_virgin_setting()
132+
self._apply_button_visibility()
133+
self._update_volume_button_labels()
123134
if hand:
124135
display_data.extend([Ingredient(-1, "", 0, 0, 0, False, 100, 100), *hand])
125136
fields_ingredient = self.get_labels_maker_ingredients()
@@ -150,18 +161,18 @@ def update_cocktail_data(self) -> None:
150161
ingredient_name = ing.name
151162
field_ingredient.setText(f"{ingredient_name} ")
152163

153-
def _apply_virgin_setting(self) -> None:
154-
# hide the strong/weak buttons, since they are not needed
155-
show_alcohol_buttons = not self.cocktail.only_virgin and not cfg.payment_enabled
164+
def _apply_button_visibility(self) -> None:
165+
"""Hide or show the toggle buttons for alcohol and virgin mode, depending on the cocktail and config."""
166+
is_single_ingredient_recipe = len(self.cocktail.ingredients) == 1
167+
# hide the strong/weak buttons, when they are not needed or possible
168+
show_alcohol_buttons = (
169+
not is_single_ingredient_recipe and not self.cocktail.only_virgin and not cfg.payment_enabled
170+
)
156171
self.increase_alcohol.setVisible(show_alcohol_buttons)
157172
self.decrease_alcohol.setVisible(show_alcohol_buttons)
158-
can_change_virgin = self.cocktail.virgin_available and not self.cocktail.only_virgin
159-
self.virgin_checkbox.setEnabled(can_change_virgin)
160-
# Styles does not work on strikeout, so we use internal qt things
161-
# To be precise, they do work at start, but does not support dynamic changes
162-
set_strike_through(self.virgin_checkbox, not can_change_virgin)
173+
self.LAlkoholgehalt.setVisible(not is_single_ingredient_recipe)
174+
self.virgin_toggle.setVisible(self.can_change_virgin)
163175
# Update button labels if payment is active (price may change with virgin mode)
164-
self._update_volume_button_labels()
165176

166177
def _decide_rounding(self, val: float, threshold: int = 8) -> int | float:
167178
"""Return the right rounding for numbers displayed to the user."""
@@ -175,18 +186,11 @@ def clear_recipe_data_maker(self) -> None:
175186
self.LAlkoholgehalt.setText("")
176187
self.LAlkoholname.setText(UI_LANGUAGE.get_cocktail_dummy())
177188
self.LMenge.setText("")
178-
self.virgin_checkbox.setChecked(self.cocktail.only_virgin)
189+
self.virgin_toggle.setChecked(self.cocktail.only_virgin)
179190
for field_ingredient, field_volume in zip(self.get_labels_maker_ingredients(), self.get_labels_maker_volume()):
180191
field_ingredient.setText("")
181192
field_volume.setText("")
182193

183-
def reset_alcohol_factor(self) -> None:
184-
"""Set the alcohol slider to default (100%) value."""
185-
if self.cocktail.only_virgin:
186-
shared.alcohol_factor = 0.0
187-
else:
188-
shared.alcohol_factor = 1.0
189-
190194
def adjust_maker_label_size_cocktaildata(self) -> None:
191195
"""Adjust the font size for larger screens."""
192196
# iterate over all size types and adjust size relative to window height
@@ -225,25 +229,22 @@ def get_labels_maker_ingredients(self) -> list[QLabel]:
225229
"""Return all maker label objects for ingredient name."""
226230
return [getattr(self, f"LZutat{x}") for x in range(1, 10)]
227231

228-
def _higher_alcohol(self, checked: bool) -> None:
232+
def _higher_alcohol(self, _: bool) -> None:
229233
"""Increases the alcohol factor."""
230234
self.decrease_alcohol.setChecked(False)
231-
if checked:
232-
self.adjust_alcohol(1.3)
233-
else:
234-
self.adjust_alcohol(1.0)
235+
self.virgin_toggle.setChecked(False)
236+
self.update_cocktail_data()
235237

236-
def _lower_alcohol(self, checked: bool) -> None:
238+
def _lower_alcohol(self, _: bool) -> None:
237239
"""Decreases the alcohol factor."""
238240
self.increase_alcohol.setChecked(False)
239-
if checked:
240-
self.adjust_alcohol(0.7)
241-
else:
242-
self.adjust_alcohol(1.0)
241+
self.virgin_toggle.setChecked(False)
242+
self.update_cocktail_data()
243243

244-
def adjust_alcohol(self, amount: float) -> None:
245-
"""Change the alcohol factor to the given value."""
246-
shared.alcohol_factor = amount
244+
def _toggle_virgin(self, _: bool) -> None:
245+
"""Toggle the virgin option."""
246+
self.decrease_alcohol.setChecked(False)
247+
self.increase_alcohol.setChecked(False)
247248
self.update_cocktail_data()
248249

249250
def _adjust_preparation_buttons(self) -> None:
@@ -298,7 +299,7 @@ def _update_volume_button_labels(self) -> None:
298299
volume_converted = self._decide_rounding(volume * cfg.EXP_MAKER_FACTOR, 20)
299300
label = f"{volume_converted}"
300301
if cfg.payment_enabled:
301-
multiplier = cfg.PAYMENT_VIRGIN_MULTIPLIER / 100 if self.virgin_checkbox.isChecked() else 1.0
302+
multiplier = cfg.PAYMENT_VIRGIN_MULTIPLIER / 100 if self.is_virgin else 1.0
302303
price = self.cocktail.current_price(cfg.PAYMENT_PRICE_ROUNDING, volume, price_multiplier=multiplier)
303304
price_str = f"{price}".rstrip("0").rstrip(".")
304305
label += f": {price_str}€"

src/ui/shared.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from src.config.config_manager import CONFIG as cfg
1111
from src.config.config_manager import Tab
12-
from src.config.config_manager import shared as global_shared
1312
from src.display_controller import DP_CONTROLLER
1413
from src.logger_handler import LoggerHandler
1514
from src.models import Cocktail, PrepareResult
@@ -66,10 +65,7 @@ def qt_prepare_flow(w: MainScreen, cocktail: Cocktail) -> tuple[bool, str]:
6665
DP_CONTROLLER.standard_box(message, close_time=60)
6766

6867
# Otherwise clean up the rest
69-
if w.cocktail_selection:
70-
w.cocktail_selection.virgin_checkbox.setChecked(False)
7168
bottles.set_fill_level_bars(w)
72-
global_shared.alcohol_factor = 1.0
7369
w.switch_to_cocktail_list()
7470
if cfg.cocktailberry_payment and cfg.PAYMENT_LOGOUT_AFTER_PREPARATION:
7571
NFCPaymentService().logout_user()

src/ui/styles/_elements.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ $picture-view-active-color: $secondary;
7878
padding: 5px 25px 5px 25px;
7979
}
8080

81-
#virgin_checkbox,
8281
*[cssClass~='big-checkbox'] {
8382
&.QCheckBox::indicator {
8483
width: 30px;

src/ui/styles/alien.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#informationLabel {
5454
padding: 5px 25px 5px 25px; }
5555

56-
#virgin_checkbox.QCheckBox::indicator,
5756
*[cssClass~='big-checkbox'].QCheckBox::indicator {
5857
width: 30px;
5958
height: 30px;

src/ui/styles/bavaria.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#informationLabel {
5454
padding: 5px 25px 5px 25px; }
5555

56-
#virgin_checkbox.QCheckBox::indicator,
5756
*[cssClass~='big-checkbox'].QCheckBox::indicator {
5857
width: 30px;
5958
height: 30px;

0 commit comments

Comments
 (0)