Skip to content

Commit

Permalink
Configure current life as float instead of integer
Browse files Browse the repository at this point in the history
  • Loading branch information
Yutsuten committed Apr 22, 2024
1 parent ea33da5 commit 58e28df
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ def spin_box(self, sb_name: str, label_text: str, val_range: list[int],
self._layout.addWidget(spin_box, self._row, 2, 1, 2)
self._row += 1

def double_spin_box(self, sb_name: str, label_text: str, val_range: list[float],
tooltip: Optional[str]=None) -> None:
"""Creates a double spin box in the current row of the form.
Args:
sb_name: The name of the spin box. Not visible by the user.
label_text: A text that describes what is the spin box for.
val_range: A list of two floats that are the range.
tooltip: The tooltip to be shown.
"""
label = self._qt.QLabel(label_text)
double_spin_box = self._qt.QDoubleSpinBox(self.widget)
double_spin_box.setRange(val_range[0], val_range[1])
double_spin_box.setDecimals(1)
if tooltip is not None:
label.setToolTip(tooltip)
double_spin_box.setToolTip(tooltip)

double_spin_box.get_value = double_spin_box.value
double_spin_box.set_value = double_spin_box.setValue

setattr(self.widget, sb_name, double_spin_box)
self._layout.addWidget(label, self._row, 0)
self._layout.addWidget(double_spin_box, self._row, 2, 1, 2)
self._row += 1

def color_select(self, cs_name: str, label_text: str, tooltip: Optional[str]=None) -> None:
"""Creates a color select in the current row of the form.
Expand Down Expand Up @@ -573,16 +599,16 @@ def generate_form() -> Any:
seconds for the life bar go from full to empty.''')
tab.spin_box('recoverInput', 'Recover', [0, 1000], '''Time in seconds \
that is recovered after answering a card.''')
tab.spin_box('currentValueInput', 'Current life', [0, 10000],
'Current life, in seconds.')
tab.double_spin_box('currentValueInput', 'Current life', [0, 10000],
'Current life, in seconds.')
tab.fill_space()
return tab.widget

def load_data(widget: Any, conf: dict[str, Any]) -> None:
widget.enable.set_value(conf['enable'])
widget.maxLifeInput.set_value(conf['maxLife'])
widget.recoverInput.set_value(conf['recover'])
widget.currentValueInput.set_value(int(life))
widget.currentValueInput.set_value(life)

tab = generate_form()
load_data(tab, conf)
Expand Down

0 comments on commit 58e28df

Please sign in to comment.