Browse Source

Make non-recovering messages

ui_file
Gregory Rudolph 4 years ago
parent
commit
de934eed76
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 41
      main.go

41
main.go

@ -203,26 +203,26 @@ func setValues() {
vehicle = getVehicle("") vehicle = getVehicle("")
var err error var err error
if vehicle == nil { if vehicle == nil {
showDialogue("Unable to get vehicle") showDialogue(false, "Unable to get vehicle")
return return
} }
vehicleState, err = vehicle.VehicleState() vehicleState, err = vehicle.VehicleState()
if err != nil { if err != nil {
showDialogue("Unable to get Vehicle State") showDialogue(false, "Unable to get Vehicle State")
} }
chargeStats, err = vehicle.ChargeState() chargeStats, err = vehicle.ChargeState()
if err != nil { if err != nil {
showDialogue("Unable to get Vehicle Charge State") showDialogue(false, "Unable to get Vehicle Charge State")
} }
climateState, err = vehicle.ClimateState() climateState, err = vehicle.ClimateState()
if err != nil { if err != nil {
showDialogue("Unable to get Vehicle Climate") showDialogue(false, "Unable to get Vehicle Climate")
} }
guiSettings, err = vehicle.GuiSettings() guiSettings, err = vehicle.GuiSettings()
if err != nil { if err != nil {
showDialogue("Unable to get Gui Settings") showDialogue(false, "Unable to get Gui Settings")
} }
tempSettingVal := climateState.DriverTempSetting tempSettingVal := climateState.DriverTempSetting
insideTempVal := climateState.InsideTemp insideTempVal := climateState.InsideTemp
@ -271,7 +271,7 @@ func setValues() {
func enableClimate(i int) { func enableClimate(i int) {
temp, err := strconv.ParseFloat(tempSetting.Text(), 64) temp, err := strconv.ParseFloat(tempSetting.Text(), 64)
if err != nil { if err != nil {
showDialogue("Unable to parse temp setting\n%+v", err) showDialogue(true, "Unable to parse temp setting\n%+v", err)
} }
if guiSettings.GuiTemperatureUnits == "F" { if guiSettings.GuiTemperatureUnits == "F" {
temp = (temp - 32) * 5 / 9 temp = (temp - 32) * 5 / 9
@ -312,7 +312,7 @@ func enableCharging(i int) {
func honkHorn(c bool) { func honkHorn(c bool) {
err := vehicle.HonkHorn() err := vehicle.HonkHorn()
if err != nil { if err != nil {
showDialogue("There was an error honking the horn\n%+v", err) showDialogue(true, "There was an error honking the horn\n%+v", err)
fmt.Printf("%+v\n", err) fmt.Printf("%+v\n", err)
} }
go setValues() go setValues()
@ -320,7 +320,7 @@ func honkHorn(c bool) {
func flash(c bool) { func flash(c bool) {
err := vehicle.FlashLights() err := vehicle.FlashLights()
if err != nil { if err != nil {
showDialogue("There was an error flashing the lights\n%+v", err) showDialogue(true, "There was an error flashing the lights\n%+v", err)
fmt.Printf("%+v\n", err) fmt.Printf("%+v\n", err)
} }
go setValues() go setValues()
@ -328,7 +328,7 @@ func flash(c bool) {
func openTrunk(c bool) { func openTrunk(c bool) {
err := vehicle.OpenTrunk("rear") err := vehicle.OpenTrunk("rear")
if err != nil { if err != nil {
showDialogue("There was an error opening your trunk\n%+v", err) showDialogue(true, "There was an error opening your trunk\n%+v", err)
fmt.Printf("%+v\n", err) fmt.Printf("%+v\n", err)
} }
go setValues() go setValues()
@ -336,24 +336,30 @@ func openTrunk(c bool) {
func openFrunk(c bool) { func openFrunk(c bool) {
err := vehicle.OpenTrunk("front") err := vehicle.OpenTrunk("front")
if err != nil { if err != nil {
showDialogue("There was an error opening your frunk\n%+v", err) showDialogue(true, "There was an error opening your frunk\n%+v", err)
fmt.Printf("%+v\n", err) fmt.Printf("%+v\n", err)
} }
go setValues() go setValues()
} }
func showDialogue(msg string, a ...interface{}) { func showDialogue(recover bool, msg string, a ...interface{}) {
popup = true popup = true
dialogue := widgets.NewQDialog(nil, 0) dialogue := widgets.NewQDialog(nil, 0)
dialogue.SetWindowTitle("TeslaGo Alert") centralWidget := widgets.NewQWidget(dialogue, 0)
actionHBox := widgets.NewQHBoxLayout() actionHBox := widgets.NewQHBoxLayout()
formLayout := widgets.NewQFormLayout(nil) formLayout := widgets.NewQFormLayout(nil)
contBtn := widgets.NewQPushButton(nil) contBtn := widgets.NewQPushButton(nil)
quitBtn := widgets.NewQPushButton(nil) quitBtn := widgets.NewQPushButton(nil)
message := widgets.NewQLabel(nil, 0)
dialogue.SetWindowTitle("TeslaGo Alert")
dialogue.SetMinimumWidth(255)
dialogue.SetMinimumHeight(50 + (20 * (1 + strings.Count(msg, "\n"))))
contBtn.SetText("Continue") contBtn.SetText("Continue")
quitBtn.SetText("Quit") quitBtn.SetText("Quit")
message.SetText(fmt.Sprintf(msg, a...))
message.SetWordWrap(true)
contBtn.ConnectClicked(func(checked bool) { contBtn.ConnectClicked(func(checked bool) {
window.Show() window.Show()
@ -366,19 +372,14 @@ func showDialogue(msg string, a ...interface{}) {
mainApp.Quit() mainApp.Quit()
}) })
if recover {
actionHBox.AddWidget(contBtn, 0, 0) actionHBox.AddWidget(contBtn, 0, 0)
}
actionHBox.AddWidget(quitBtn, 0, 0) actionHBox.AddWidget(quitBtn, 0, 0)
message := widgets.NewQLabel(nil, 0)
message.SetText(fmt.Sprintf(msg, a...))
message.SetWordWrap(true)
formLayout.AddRow5(message) formLayout.AddRow5(message)
formLayout.AddRow6(actionHBox) formLayout.AddRow6(actionHBox)
centralWidget := widgets.NewQWidget(dialogue, 0)
centralWidget.SetLayout(formLayout) centralWidget.SetLayout(formLayout)
dialogue.SetMinimumWidth(255)
dialogue.SetMinimumHeight(50 + (20 * (1 + strings.Count(msg, "\n"))))
dialogue.Show() dialogue.Show()
} }

Loading…
Cancel
Save