Skip to content

Commit

Permalink
Fixing issues with read/writing bool properties (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
DasAmpharos authored May 15, 2024
1 parent bda393b commit 2e6e759
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions eon_timer/settings/other/update_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Final

from eon_timer.util.injector import component
from eon_timer.util.properties.property import ListProperty, Property
from eon_timer.util.properties.property import Property, BoolProperty
from eon_timer.util.properties.settings import Settings


@component()
class UpdateSettingsModel(Settings):
check_on_startup: Final = Property(True)
check_on_startup: Final = BoolProperty(True)
acknowledged: Final = Property('')

@property
Expand Down
4 changes: 2 additions & 2 deletions eon_timer/settings/other/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from eon_timer.settings.other.update_model import UpdateSettingsModel
from eon_timer.util.injector import component
from eon_timer.util.properties import bindings
from eon_timer.util.properties.property import Property
from eon_timer.util.properties.property import BoolProperty
from eon_timer.util.pyside.form import FormWidget
from eon_timer.util.pyside.name_service import NameService

Expand All @@ -21,7 +21,7 @@ def __init__(self,
name_service: NameService):
FormWidget.__init__(self, name_service)
self.update_settings: Final = update_settings
self.check_on_startup: Final = Property(self.update_settings.check_on_startup.get())
self.check_on_startup: Final = BoolProperty(self.update_settings.check_on_startup.get())
self.__init_components()

def __init_components(self):
Expand Down
4 changes: 2 additions & 2 deletions eon_timer/settings/theme/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from eon_timer.theme.theme_manager import ThemeManager
from eon_timer.util.injector import component
from eon_timer.util.properties.property import Property
from eon_timer.util.properties.property import Property, BoolProperty
from eon_timer.util.properties.settings import Settings


@component()
class ThemeSettingsModel(Settings):
theme = Property(ThemeManager.DEFAULT_THEME)
element_name_tooltip = Property(False)
element_name_tooltip = BoolProperty(False)

def __init__(self,
settings: QSettings,
Expand Down
4 changes: 2 additions & 2 deletions eon_timer/settings/theme/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from eon_timer.theme.theme_manager import ThemeManager
from eon_timer.util.injector import component
from eon_timer.util.properties import bindings
from eon_timer.util.properties.property import Property
from eon_timer.util.properties.property import Property, BoolProperty
from eon_timer.util.properties.property_change import PropertyChangeEvent
from eon_timer.util.pyside.file_selector_widget import FileSelectorWidget
from eon_timer.util.pyside.name_service import NameService
Expand All @@ -29,7 +29,7 @@ def __init__(self,
self.name_service: Final = name_service

self.theme: Final = Property(model.theme.get())
self.element_name_tooltip: Final = Property(model.element_name_tooltip.get())
self.element_name_tooltip: Final = BoolProperty(model.element_name_tooltip.get())

self.__theme_field: Final = QComboBox()
self.__import_theme_field: Final = FileSelectorWidget()
Expand Down
4 changes: 2 additions & 2 deletions eon_timer/settings/timer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from eon_timer.util.enum import EnhancedEnum
from eon_timer.util.injector import component
from eon_timer.util.properties.property import EnumProperty, FloatProperty, IntProperty, Property
from eon_timer.util.properties.property import EnumProperty, FloatProperty, IntProperty, BoolProperty
from eon_timer.util.properties.settings import Settings

GBA_FPS: Final = 59.7275
Expand Down Expand Up @@ -52,7 +52,7 @@ def framerate(self) -> float | None:
class TimerSettingsModel(Settings):
console = EnumProperty(Console.NDS_SLOT1)
custom_framerate = FloatProperty(60.0)
precision_calibration = Property(False)
precision_calibration = BoolProperty(False)
refresh_interval = IntProperty(8)

@property
Expand Down
4 changes: 2 additions & 2 deletions eon_timer/settings/timer/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from eon_timer.util.const import INT_MAX
from eon_timer.util.injector import component
from eon_timer.util.properties import bindings
from eon_timer.util.properties.property import FloatProperty, Property
from eon_timer.util.properties.property import FloatProperty, Property, BoolProperty
from eon_timer.util.properties.property_change import PropertyChangeEvent
from eon_timer.util.pyside import EnumComboBox
from eon_timer.util.pyside.form import FormWidget
Expand All @@ -28,7 +28,7 @@ def __init__(self,
super().__init__(name_service)
self.console: Final = Property(model.console.get())
self.custom_framerate: Final = FloatProperty(model.custom_framerate.get())
self.precision_calibration: Final = Property(model.precision_calibration.get())
self.precision_calibration: Final = BoolProperty(model.precision_calibration.get())
self.refresh_interval: Final = Property(model.refresh_interval.get())
self.model: Final = model
self.__init_components()
Expand Down
4 changes: 2 additions & 2 deletions eon_timer/util/properties/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from eon_timer.util.enum import EnhancedEnum
from eon_timer.util.pyside import EnumComboBox
from .property import Property, PropertyChangeEvent
from .property import Property, PropertyChangeEvent, BoolProperty

T = TypeVar('T')
EnhancedEnumT = TypeVar('EnhancedEnumT', bound=EnhancedEnum)
Expand Down Expand Up @@ -48,7 +48,7 @@ def on_property_changed(event: PropertyChangeEvent[EnhancedEnumT]) -> None:


def bind_checkbox(checkbox: QCheckBox,
p_property: Property[bool]) -> None:
p_property: BoolProperty) -> None:
def on_property_changed(event: PropertyChangeEvent[bool]) -> None:
if event.new_value != checkbox.isChecked():
checkbox.setChecked(event.new_value)
Expand Down
5 changes: 5 additions & 0 deletions eon_timer/util/properties/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def transient(self) -> bool:
return self._transient


class BoolProperty(Property[bool]):
def _read(self, settings: QSettings, name: str):
return settings.value(name, self._initial_value, bool)


class IntProperty(Property[int]):
def read(self, settings: QSettings, name: str):
self._value = settings.value(name, self._initial_value, int)
Expand Down

0 comments on commit 2e6e759

Please sign in to comment.