Cleanup UI code
This commit is contained in:
131
main.go
131
main.go
@ -49,29 +49,31 @@ var (
|
||||
func main() {
|
||||
mainApp = widgets.NewQApplication(len(os.Args), os.Args)
|
||||
|
||||
vboxLayout := widgets.NewQVBoxLayout()
|
||||
statusLayout := widgets.NewQFormLayout(nil)
|
||||
|
||||
// Setup all UI Elements
|
||||
batteryLevel = widgets.NewQLabel(nil, 0)
|
||||
batteryLevel.SetFixedWidth(30)
|
||||
batteryRange = widgets.NewQLabel(nil, 0)
|
||||
chargingState = widgets.NewQLabel(nil, 0)
|
||||
minutesToFull = widgets.NewQLabel(nil, 0)
|
||||
fastChargerInd = widgets.NewQLabel(nil, 0)
|
||||
batteryHeaterInd = widgets.NewQLabel(nil, 0)
|
||||
|
||||
chargeDoorOpenInd = widgets.NewQLabel(nil, 0)
|
||||
insideTemp = widgets.NewQLabel(nil, 0)
|
||||
insideTemp.SetFixedWidth(25)
|
||||
outsideTemp = widgets.NewQLabel(nil, 0)
|
||||
outsideTemp.SetFixedWidth(25)
|
||||
currentChargeLabel := widgets.NewQLabel(nil, 0)
|
||||
currentRangeLabel := widgets.NewQLabel(nil, 0)
|
||||
insideTempLabel := widgets.NewQLabel(nil, 0)
|
||||
outsideTempLabel := widgets.NewQLabel(nil, 0)
|
||||
climateEnabledLabel := widgets.NewQLabel(nil, 0)
|
||||
climateSettingLabel := widgets.NewQLabel(nil, 0)
|
||||
doorLockLabel := widgets.NewQLabel(nil, 0)
|
||||
sentryModeLabel := widgets.NewQLabel(nil, 0)
|
||||
chargingStateLabel := widgets.NewQLabel(nil, 0)
|
||||
|
||||
tempSetting = widgets.NewQLineEdit(nil)
|
||||
tempSetting.SetFixedWidth(25)
|
||||
|
||||
climateOn = widgets.NewQCheckBox(nil)
|
||||
lockedDoors = widgets.NewQCheckBox(nil)
|
||||
sentryMode = widgets.NewQCheckBox(nil)
|
||||
|
||||
startStopCharge = widgets.NewQCheckBox(nil)
|
||||
|
||||
honk = widgets.NewQPushButton(nil)
|
||||
@ -79,19 +81,54 @@ func main() {
|
||||
trunk = widgets.NewQPushButton(nil)
|
||||
frunk = widgets.NewQPushButton(nil)
|
||||
|
||||
currentChargeLabel := widgets.NewQLabel(nil, 0)
|
||||
currentChargeLabel.SetText("Current Charge: ")
|
||||
currentRangeLabel := widgets.NewQLabel(nil, 0)
|
||||
currentRangeLabel.SetText("Current Range: ")
|
||||
vboxLayout := widgets.NewQVBoxLayout()
|
||||
statusLayout := widgets.NewQFormLayout(nil)
|
||||
chargeHbox := widgets.NewQHBoxLayout()
|
||||
tempHbox := widgets.NewQHBoxLayout()
|
||||
climateHbox := widgets.NewQHBoxLayout()
|
||||
securityHbox := widgets.NewQHBoxLayout()
|
||||
actionHbox := widgets.NewQHBoxLayout()
|
||||
|
||||
// Set Values for everything
|
||||
setValues()
|
||||
|
||||
// Some adjustments
|
||||
batteryLevel.SetFixedWidth(30)
|
||||
insideTemp.SetFixedWidth(25)
|
||||
outsideTemp.SetFixedWidth(25)
|
||||
tempSetting.SetFixedWidth(25)
|
||||
|
||||
currentChargeLabel.SetText("Current Charge: ")
|
||||
currentRangeLabel.SetText("Current Range: ")
|
||||
insideTempLabel.SetText("Inside Temp: ")
|
||||
outsideTempLabel.SetText("Outside Temp: ")
|
||||
climateEnabledLabel.SetText("Climate On: ")
|
||||
climateSettingLabel.SetText("Climate Setting: ")
|
||||
doorLockLabel.SetText("Lock Doors: ")
|
||||
sentryModeLabel.SetText("Sentry Mode: ")
|
||||
chargingStateLabel.SetText("Charging: ")
|
||||
honk.SetText("Honk")
|
||||
flashLights.SetText("Flash")
|
||||
trunk.SetText("Trunk")
|
||||
frunk.SetText("Frunk")
|
||||
|
||||
// Connect Controls
|
||||
honk.ConnectClicked(honkHorn)
|
||||
flashLights.ConnectClicked(flash)
|
||||
trunk.ConnectClicked(openTrunk)
|
||||
frunk.ConnectClicked(openFrunk)
|
||||
lockedDoors.ConnectStateChanged(lockDoors)
|
||||
sentryMode.ConnectStateChanged(sentryModeEnable)
|
||||
startStopCharge.ConnectStateChanged(enableCharging)
|
||||
climateOn.ConnectStateChanged(enableClimate)
|
||||
|
||||
// Setup Layout for first row, Current Charge
|
||||
chargeHbox.AddWidget(batteryLevel, 0, 0)
|
||||
chargeHbox.AddItem(widgets.NewQSpacerItem(5, 2, widgets.QSizePolicy__Expanding, widgets.QSizePolicy__Expanding))
|
||||
chargeHbox.AddWidget(currentRangeLabel, 0, 0)
|
||||
chargeHbox.AddWidget(batteryRange, 0, 0)
|
||||
statusLayout.AddRow2(currentChargeLabel, chargeHbox)
|
||||
|
||||
setValues()
|
||||
statusLayout.AddRow3("Charging State: ", chargingState)
|
||||
// Charging State has its own section and is handled differently based on if it is present or not
|
||||
if chargeStats.ChargingState != "Disconnected" {
|
||||
statusLayout.AddRow3("Minutes to Full: ", minutesToFull)
|
||||
if chargeStats.FastChargerPresent {
|
||||
@ -100,41 +137,22 @@ func main() {
|
||||
if chargeStats.BatteryHeaterOn {
|
||||
statusLayout.AddRow3("Battey Heater: ", batteryHeaterInd)
|
||||
}
|
||||
statusLayout.AddRow3(" ", nil)
|
||||
}
|
||||
statusLayout.AddRow3("Charge Port: ", chargeDoorOpenInd)
|
||||
|
||||
insideTempLabel := widgets.NewQLabel(nil, 0)
|
||||
outsideTempLabel := widgets.NewQLabel(nil, 0)
|
||||
|
||||
insideTempLabel.SetText("Inside Temp: ")
|
||||
outsideTempLabel.SetText("Outside Temp: ")
|
||||
tempHbox := widgets.NewQHBoxLayout()
|
||||
// Temperature section (NOT CLIMATE CONTROL)
|
||||
tempHbox.AddWidget(insideTemp, 0, 0)
|
||||
tempHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
tempHbox.AddWidget(outsideTempLabel, 0, 0)
|
||||
tempHbox.AddWidget(outsideTemp, 0, 0)
|
||||
statusLayout.AddRow2(insideTempLabel, tempHbox)
|
||||
|
||||
climateEnabledLabel := widgets.NewQLabel(nil, 0)
|
||||
climateEnabledLabel.SetText("Climate On: ")
|
||||
climateSettingLabel := widgets.NewQLabel(nil, 0)
|
||||
climateSettingLabel.SetText("Climate Setting: ")
|
||||
|
||||
climateHbox := widgets.NewQHBoxLayout()
|
||||
// Climate Control Section
|
||||
climateHbox.AddWidget(climateOn, 0, 0)
|
||||
climateHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
climateHbox.AddWidget(climateSettingLabel, 0, 0)
|
||||
climateHbox.AddWidget(tempSetting, 0, 0)
|
||||
statusLayout.AddRow2(climateEnabledLabel, climateHbox)
|
||||
|
||||
doorLockLabel := widgets.NewQLabel(nil, 0)
|
||||
sentryModeLabel := widgets.NewQLabel(nil, 0)
|
||||
chargingStateLabel := widgets.NewQLabel(nil, 0)
|
||||
|
||||
doorLockLabel.SetText("Lock Doors: ")
|
||||
sentryModeLabel.SetText("Sentry Mode: ")
|
||||
chargingStateLabel.SetText("Charging: ")
|
||||
securityHbox := widgets.NewQHBoxLayout()
|
||||
// Security Section (Lock/Unlock doors & start/stop charge. Also enable Sentry Mode)
|
||||
securityHbox.AddWidget(lockedDoors, 0, 0)
|
||||
securityHbox.AddItem(widgets.NewQSpacerItem(10, 10, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
securityHbox.AddWidget(sentryModeLabel, 0, 0)
|
||||
@ -145,41 +163,26 @@ func main() {
|
||||
securityHbox.AddWidget(startStopCharge, 0, 0)
|
||||
}
|
||||
|
||||
lockedDoors.ConnectStateChanged(lockDoors)
|
||||
sentryMode.ConnectStateChanged(sentryModeEnable)
|
||||
startStopCharge.ConnectStateChanged(enableCharging)
|
||||
climateOn.ConnectStateChanged(enableClimate)
|
||||
statusLayout.AddRow2(doorLockLabel, securityHbox)
|
||||
|
||||
honk = widgets.NewQPushButton(nil)
|
||||
flashLights = widgets.NewQPushButton(nil)
|
||||
trunk = widgets.NewQPushButton(nil)
|
||||
frunk = widgets.NewQPushButton(nil)
|
||||
|
||||
honk.ConnectClicked(honkHorn)
|
||||
honk.SetText("Honk")
|
||||
flashLights.ConnectClicked(flash)
|
||||
flashLights.SetText("Flash")
|
||||
trunk.ConnectClicked(openTrunk)
|
||||
trunk.SetText("Trunk")
|
||||
frunk.ConnectClicked(openFrunk)
|
||||
frunk.SetText("Frunk")
|
||||
|
||||
actionHbox := widgets.NewQHBoxLayout()
|
||||
// Action Buttons
|
||||
actionHbox.AddWidget(honk, 0, 0)
|
||||
actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
|
||||
actionHbox.AddWidget(flashLights, 0, 0)
|
||||
actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
|
||||
actionHbox.AddWidget(trunk, 0, 0)
|
||||
actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
|
||||
actionHbox.AddWidget(frunk, 0, 0)
|
||||
actionHbox.AddItem(widgets.NewQSpacerItem(2, 2, widgets.QSizePolicy__Fixed, widgets.QSizePolicy__Fixed))
|
||||
|
||||
// Put all Sections Together, note ChargingState (top) is already handled
|
||||
statusLayout.AddRow2(currentChargeLabel, chargeHbox)
|
||||
statusLayout.AddRow3("Charging State: ", chargingState)
|
||||
statusLayout.AddRow3("Charge Port: ", chargeDoorOpenInd)
|
||||
statusLayout.AddRow3(" ", nil)
|
||||
statusLayout.AddRow2(insideTempLabel, tempHbox)
|
||||
statusLayout.AddRow2(climateEnabledLabel, climateHbox)
|
||||
statusLayout.AddRow3(" ", nil)
|
||||
statusLayout.AddRow2(doorLockLabel, securityHbox)
|
||||
statusLayout.AddRow6(actionHbox)
|
||||
|
||||
vboxLayout.AddItem(statusLayout)
|
||||
|
||||
window = widgets.NewQMainWindow(nil, 0)
|
||||
|
||||
Reference in New Issue
Block a user