From 757fa041058cf24e1392c3aa6bbe572d81f4438f Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 20 Dec 2022 00:51:59 +0100 Subject: [PATCH] 0.3.0 Saving config on changes. /JL --- config.go | 28 +++++++++++++++++++++------- main.go | 2 +- properties.go | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index e644041..44add33 100644 --- a/config.go +++ b/config.go @@ -12,6 +12,27 @@ var ( ConfigFile string = "BeadImager.conf" ) +func SetConfigShowBeads(s string) { + log.Printf("Setting showbeads to: %s\n", s) + Config, _ := configparser.Parse(UserPath + Sep + ConfigFile) + Config.Set("canvas", "showbeads", s) + Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") +} + +func SetConfigShowGrid(s string) { + log.Printf("Setting showgrid to: %s\n", s) + Config, _ := configparser.Parse(UserPath + Sep + ConfigFile) + Config.Set("canvas", "showgrid", s) + Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") +} + +func SetConfigScale(s string) { + log.Printf("Setting scale to: %s\n", s) + Config, _ := configparser.Parse(UserPath + Sep + ConfigFile) + Config.Set("canvas", "scale", s) + Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") +} + func ReadConfig() { log.Printf("Reading config file: %s\n", ConfigFile) Config, _ = configparser.Parse(UserPath + Sep + ConfigFile) @@ -49,10 +70,3 @@ func CreateDefaultConfig() { Config.Set("canvas", "backgroundcolor", "#ffffff") Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") } - -func SetConfigScale(s string) { - log.Printf("Setting scale to: %s\n", s) - Config, _ := configparser.Parse(UserPath + Sep + ConfigFile) - Config.Set("canvas", "scale", s) - Config.SaveWithDelimiter(UserPath+Sep+ConfigFile, "=") -} diff --git a/main.go b/main.go index b15e805..0d1307e 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ type MyMainWindow struct { const ( AppName string = "BeadImager" - Version string = "0.2.5" + Version string = "0.3.0" CopyRight string = "©2022 Jan Lerking" STD_MESS string = "Ready" LogFile string = "BeadImager.log" diff --git a/properties.go b/properties.go index 7ef4073..f0fdc72 100644 --- a/properties.go +++ b/properties.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "strconv" @@ -104,6 +105,7 @@ func CreateScaleProperties(mw *MyMainWindow) { nn := float64(slider.Value()) log.Println("Setting scale number edit value to: ", nn) sc.SetValue(nn) + SetConfigScale(fmt.Sprintf("%0.0f", nn)) }) sc.SetDecimals(0) sc.SetRange(10, 200) @@ -114,6 +116,7 @@ func CreateScaleProperties(mw *MyMainWindow) { nn := float64(sc.Value()) log.Println("Setting scale slider value to: ", nn) slider.SetValue(int(nn)) + SetConfigScale(fmt.Sprintf("%0.0f", nn)) }) log.Println("Setting background color...") bg, _ := walk.NewSolidColorBrush(walk.RGB(255, 255, 255)) @@ -146,6 +149,14 @@ func CreateCanvasProperties(mw *MyMainWindow) { case "false": cb.SetChecked(false) } + cb.CheckedChanged().Attach(func() { + log.Println("Grid checkbox changed") + if cb.Checked() { + SetConfigShowGrid("false") + } else { + SetConfigShowGrid("true") + } + }) log.Println("Grid checkbox created") walk.NewHSpacer(grcom) log.Println("Creating grid color button") @@ -163,6 +174,14 @@ func CreateCanvasProperties(mw *MyMainWindow) { case "false": cb.SetChecked(false) } + cb.CheckedChanged().Attach(func() { + log.Println("Grid checkbox changed") + if !cb.Checked() { + SetConfigShowBeads("false") + } else { + SetConfigShowBeads("true") + } + }) log.Println("Pixels checkbox created") log.Println("Creating canvas background color button") grcolb, _ = walk.NewPushButton(mw.properties.propCanvas.property)