66from PyQt6 .QtWidgets import QDialog , QLabel , QPushButton , QSizePolicy
77
88from src .config .config_manager import CONFIG as cfg
9- from src .config .config_manager import shared
109from src .database_commander import DB_COMMANDER
1110from src .dialog_handler import UI_LANGUAGE
1211from src .display_controller import DP_CONTROLLER
1312from src .image_utils import find_cocktail_image
1413from 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
1615from src .ui .icons import IconSetter
1716from src .ui .shared import qt_prepare_flow
1817from 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 } €"
0 commit comments