0.0.27 Adding config file. /JL
This commit is contained in:
58
config.go
Normal file
58
config.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/bigkevmcd/go-configparser"
|
||||
)
|
||||
|
||||
var (
|
||||
Config *configparser.ConfigParser
|
||||
ConfigFile string = "BeadImager.conf"
|
||||
)
|
||||
|
||||
func ReadConfig() {
|
||||
log.Printf("Reading config file: %s\n", ConfigFile)
|
||||
Config, _ = configparser.Parse(UserPath + Sep + ConfigFile)
|
||||
ConfigBrand, _ = Config.Get("pallette", "brand")
|
||||
ConfigSerie, _ = Config.Get("pallette", "serie")
|
||||
ConfigPegboard, _ = Config.Get("pallette", "pegboard")
|
||||
ConfigScale, _ = Config.Get("canvas", "scale")
|
||||
ConfigShowGrid, _ = Config.Get("canvas", "showgrid")
|
||||
ConfogGridColor, _ = Config.Get("canvas", "gridcolor")
|
||||
ConfigShowBeads, _ = Config.Get("canvas", "showbeads")
|
||||
ConfigBackgroundColor, _ = Config.Get("canvas", "backgroundcolor")
|
||||
}
|
||||
|
||||
func CheckConfigFile() bool {
|
||||
log.Printf("Checking for config file: %s\n", ConfigFile)
|
||||
if _, err := os.Stat(UserPath + Sep + ConfigFile); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func CreateDefaultConfig() {
|
||||
log.Printf("Creating default config file: %s\n", ConfigFile)
|
||||
os.Create(UserPath + Sep + ConfigFile)
|
||||
Config = configparser.New()
|
||||
Config.AddSection("pallette")
|
||||
Config.Set("pallette", "brand", "Hama")
|
||||
Config.Set("pallette", "serie", "Midi")
|
||||
Config.Set("pallette", "pegboard", "Large 29x29")
|
||||
Config.AddSection("canvas")
|
||||
Config.Set("canvas", "scale", "100")
|
||||
Config.Set("canvas", "showgrid", "true")
|
||||
Config.Set("canvas", "gridcolor", "#00ff00")
|
||||
Config.Set("canvas", "showbeads", "false")
|
||||
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, "=")
|
||||
}
|
||||
1
go.mod
1
go.mod
@@ -6,6 +6,7 @@ require github.com/lxn/walk v0.0.0-20210112085537-c389da54e794
|
||||
|
||||
require (
|
||||
github.com/akavel/rsrc v0.10.2 // indirect
|
||||
github.com/bigkevmcd/go-configparser v0.0.0-20221013105652-718c0b41a604 // indirect
|
||||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,5 +1,7 @@
|
||||
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
|
||||
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||
github.com/bigkevmcd/go-configparser v0.0.0-20221013105652-718c0b41a604 h1:AOnJt6zGZgcaCc3Yi2WGjrTyjYAfoRzWN6QP8vPoDj4=
|
||||
github.com/bigkevmcd/go-configparser v0.0.0-20221013105652-718c0b41a604/go.mod h1:zqqfbfnDeSdRs1WihmMjSbhb2Ptw8Jbus831xoqiIec=
|
||||
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794 h1:NVRJ0Uy0SOFcXSKLsS65OmI1sgCCfiDUPj+cwnH7GZw=
|
||||
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ=
|
||||
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc=
|
||||
|
||||
23
main.go
23
main.go
@@ -28,7 +28,7 @@ type MyMainWindow struct {
|
||||
|
||||
const (
|
||||
AppName string = "BeadImager"
|
||||
Version string = "0.0.26"
|
||||
Version string = "0.0.27"
|
||||
CopyRight string = "©2022 Jan Lerking"
|
||||
STD_MESS string = "Ready"
|
||||
LogFile string = "BeadImager.log"
|
||||
@@ -36,7 +36,15 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
UserPath string
|
||||
UserPath string
|
||||
ConfigBrand string
|
||||
ConfigSerie string
|
||||
ConfigPegboard string
|
||||
ConfigScale string
|
||||
ConfigShowGrid string
|
||||
ConfogGridColor string
|
||||
ConfigShowBeads string
|
||||
ConfigBackgroundColor string
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -48,6 +56,16 @@ func main() {
|
||||
homeDir := currentUser.HomeDir
|
||||
UserPath = homeDir + Sep + "BeadImager"
|
||||
InitLogFile()
|
||||
if !CheckConfigFile() {
|
||||
CreateDefaultConfig()
|
||||
ReadConfig()
|
||||
log.Println("Config file created")
|
||||
} else {
|
||||
ReadConfig()
|
||||
log.Println("Brand: ", ConfigBrand)
|
||||
log.Println("Serie: ", ConfigSerie)
|
||||
log.Println("Pegboard: ", ConfigPegboard)
|
||||
}
|
||||
|
||||
walk.AppendToWalkInit(func() {
|
||||
walk.FocusEffect, _ = walk.NewBorderGlowEffect(walk.RGB(0, 63, 255))
|
||||
@@ -84,6 +102,7 @@ func main() {
|
||||
mw.serie_model = CreateSeriesList(mw)
|
||||
mw.serie_combo.SetModel(mw.serie_model)
|
||||
mw.serie_combo.SetEnabled(true)
|
||||
mw.brand_combo.SetText(ConfigBrand)
|
||||
}
|
||||
brand_trigged = true
|
||||
},
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<weightPerThousand>60</weightPerThousand>
|
||||
<pegboards>
|
||||
<pegboard>
|
||||
<type>Big 29x29</type>
|
||||
<type>Large 29x29</type>
|
||||
<width>29</width>
|
||||
<height>29</height>
|
||||
</pegboard>
|
||||
|
||||
Reference in New Issue
Block a user