Skip to content

Commit

Permalink
Improved to operate whenever the spinbox arrow button is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
stardino2 authored and gdinolee committed Jun 27, 2023
1 parent 810b4d8 commit 80f61a5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/common/common_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ def init_battery_ui(self):
self.spinboxBattery.setValue(self.level)
self.spinboxBattery.setMinimumSize(QSize(74, 27))
self.spinboxBattery.setMaximumSize(QSize(74, 27))
self.spinboxBattery.valueChanged.connect(
self.spin_value_changed)

self.horizontalSliderBattery.setRange(
int(BATTERY_MIN_VAL), int(BATTERY_MAX_VAL))
self.horizontalSliderBattery.setSingleStep(
self.get_slider_single_step(BATTERY_MIN_VAL, BATTERY_MAX_VAL))
self.get_slider_single_step(BATTERY_MIN_VAL, BATTERY_MAX_VAL)*10)
self.horizontalSliderBattery.setValue(int(self.level))
self.horizontalSliderBattery.sliderPressed.connect(
self.sliderPressed)
Expand All @@ -198,6 +200,11 @@ def valueChanged(self):
if self.level != level:
self.update_battery_sensor()

def spin_value_changed(self):
level = max(min(self.spinboxBattery.value(), BATTERY_MAX_VAL),
BATTERY_MIN_VAL)
self.horizontalSliderBattery.setValue(int(level))

def sliderPressed(self):
self.is_slider_pressed = True

Expand Down
15 changes: 12 additions & 3 deletions src/things/humidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,23 @@ def post_setup_window(self):
def get_ui_component_from_common_window(self, common_window):
# device specific ui component
self.horizontalSliderHumid = common_window.horizontalSliderHumid
self.labelSliderPercent = common_window.labelSliderPercent
self.doubleSpinBoxInput = common_window.doubleSpinBoxInput
self.textBrowserLog = common_window.textBrowserLog
self.labelStatePicture = common_window.labelDevicePicture

## Initialise UI Input Button ##
def init_spinbox(self):
self.doubleSpinBoxInput.installEventFilter(self)
self.doubleSpinBoxInput.valueChanged.connect(self.spin_value_changed)
self.doubleSpinBoxInput.setSingleStep(1)
self.doubleSpinBoxInput.setDecimals(2)


## Initialise UI Slider ##
def init_slider(self):
self.horizontalSliderHumid.setRange(HUMIDITY_MIN_VAL, HUMIDITY_MAX_VAL)
self.horizontalSliderHumid.setSingleStep(
self.common_window.get_slider_single_step(HUMIDITY_MIN_VAL, HUMIDITY_MAX_VAL))
self.horizontalSliderHumid.setSingleStep(1000)
self.horizontalSliderHumid.setPageStep(1000)
self.horizontalSliderHumid.setValue(self.level)
self.horizontalSliderHumid.sliderPressed.connect(
self.sliderPressed)
Expand All @@ -106,6 +109,12 @@ def init_slider(self):
self.horizontalSliderHumid.setStyleSheet(
Utils.get_ui_style_slider("COMMON"))

## Handle spin box
def spin_value_changed(self):
level = max(min(self.doubleSpinBoxInput.value(), HUMIDITY_MAX_VAL/100),
HUMIDITY_MIN_VAL/100)
self.horizontalSliderHumid.setValue(int(level*100))

## Handle slider events ##
def valueChanged(self):
if self.is_slider_pressed:
Expand Down
28 changes: 22 additions & 6 deletions src/things/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def post_setup_window(self):
self.common_window.add_autotest_event_handler(
self.autotest_event_handler)
self.init_dim_slider()
self.init_spinbox()
self.update_ui()

## Get UI component from Common window ##
Expand All @@ -111,25 +112,40 @@ def get_ui_component_from_common_window(self, common_window):
self.labelStatePicture = common_window.labelDevicePicture
self.stackedWidget = common_window.stackedWidget

## Initialise UI input button ##
def init_spinbox(self):
self.spinboxDimming.installEventFilter(self)
self.spinboxDimming.valueChanged.connect(self.spin_dim_value_changed)
self.spinboxDimming.setSingleStep(
self.common_window.get_slider_single_step(LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL))
self.spinboxDimming.setValue(self.dimming_level)
self.spinboxDimming.setRange(LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL)


## Initialise UI Slider for dimming functionality##
def init_dim_slider(self):
self.horizontalSliderDimming.setRange(
LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL)
self.spinboxDimming.setRange(
LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL)
self.horizontalSliderDimming.setSingleStep(
self.common_window.get_slider_single_step(LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL))
self.spinboxDimming.setSingleStep(
self.common_window.get_slider_single_step(LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL))
self.common_window.get_slider_single_step(LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL)*10)
self.horizontalSliderDimming.setPageStep(
self.common_window.get_slider_single_step(LIGHTBULB_DIM_MIN_VAL, LIGHTBULB_DIM_MAX_VAL)*10)
self.horizontalSliderDimming.setValue(self.dimming_level)
self.spinboxDimming.setValue(self.dimming_level)
self.horizontalSliderDimming.sliderReleased.connect(self.sliderReleased)
self.horizontalSliderDimming.valueChanged.connect(self.valueChanged)
self.horizontalSliderDimming.sliderPressed.connect(self.sliderPressed)
self.horizontalSliderDimming.setStyleSheet(
Utils.get_ui_style_slider("DIMMING"))
self.spinboxDimming.installEventFilter(self)


## Handle spin box dim
def spin_dim_value_changed(self):
level = max(min(self.spinboxDimming.value(), LIGHTBULB_DIM_MAX_VAL),
LIGHTBULB_DIM_MIN_VAL)
self.horizontalSliderDimming.setValue(int(level))


## Handle slider events for dimming ##
def valueChanged(self):
if self.is_slider_pressed:
Expand Down
19 changes: 13 additions & 6 deletions src/things/lightsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ def get_ui_component_from_common_window(self, common_window):
## Initialise UI input button ##
def init_spinbox(self):
self.spinBoxInput.installEventFilter(self)

self.spinBoxInput.setSingleStep(100)
self.spinBoxInput.valueChanged.connect(self.spin_value_changed)
self.spinBoxInput.setRange(LIGHTSENSOR_MIN_VAL, LIGHTSENSOR_MAX_VAL)
## Initialise UI slider ##
def init_slider(self):
self.horizontalSliderLightsensor.setRange(
MEASURED_VALUE_MIN, MEASURED_VALUE_MAX)
self.horizontalSliderLightsensor.setSingleStep(
self.common_window.get_slider_single_step(MEASURED_VALUE_MIN, MEASURED_VALUE_MAX))
self.horizontalSliderLightsensor.setRange(MEASURED_VALUE_MIN, MEASURED_VALUE_MAX)
self.horizontalSliderLightsensor.setSingleStep(1000)
self.horizontalSliderLightsensor.setPageStep(1000)
self.horizontalSliderLightsensor.setValue(self.measured_value)
self.horizontalSliderLightsensor.sliderPressed.connect(
self.sliderPressed)
Expand All @@ -121,7 +122,13 @@ def set_state(self):
self.labelStatePicture.setPixmap(Utils.get_icon_img(
Utils.get_icon_path('lightsensor_low.png'), 70, 70))


## Handle spin box
def spin_value_changed(self):
measured_value = Utils.findMeasuredValue(self.spinBoxInput.value())
illuminance = Utils.toIlluminance(measured_value)
self.spinBoxInput.setValue(illuminance)
self.horizontalSliderLightsensor.setValue(measured_value)

## Handle slider events ##
def sliderValueChanged(self):
if self.is_slider_pressed:
Expand Down
14 changes: 11 additions & 3 deletions src/things/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ def get_ui_component_from_common_window(self, common_window):
## Initialise UI input button ##
def init_spinbox(self):
self.doubleSpinBoxInput.installEventFilter(self)
self.doubleSpinBoxInput.valueChanged.connect(self.spin_value_changed)
self.doubleSpinBoxInput.setSingleStep(1)
self.doubleSpinBoxInput.setDecimals(2)

## Initialise UI slider ##
def init_slider(self):
self.horizontalSliderTemp.setRange(
int(TEMPERATURE_MIN_VAL*100), int(TEMPERATURE_MAX_VAL*100))
self.doubleSpinBoxInput.setDecimals(2)
self.horizontalSliderTemp.setSingleStep(
self.common_window.get_slider_single_step(TEMPERATURE_MIN_VAL, TEMPERATURE_MAX_VAL))
self.horizontalSliderTemp.setSingleStep(1000)
self.horizontalSliderTemp.setPageStep(1000)
self.horizontalSliderTemp.setValue(int(self.level*100))
self.horizontalSliderTemp.sliderPressed.connect(
self.sliderPressed)
Expand All @@ -107,6 +109,12 @@ def init_slider(self):
self.horizontalSliderTemp.setStyleSheet(
Utils.get_ui_style_slider("COMMON"))

## Handle spin box
def spin_value_changed(self):
level = max(min(self.doubleSpinBoxInput.value(), TEMPERATURE_MAX_VAL),
TEMPERATURE_MIN_VAL)
self.horizontalSliderTemp.setValue(int(level*100))

## Handle slider events ##
def valueChanged(self):
if self.is_slider_pressed:
Expand Down

0 comments on commit 80f61a5

Please sign in to comment.