0.2.0 Refactored pallette. /JL

This commit is contained in:
2022-12-17 23:16:03 +01:00
parent ee92757cd6
commit abb43aada8
5 changed files with 1526 additions and 1216 deletions
+34 -25
View File
@@ -33,7 +33,7 @@ func CreateBeadsGroup(mw *MyMainWindow) {
gb.SetTitle("Beads") gb.SetTitle("Beads")
gb.SetLayout(walk.NewVBoxLayout()) gb.SetLayout(walk.NewVBoxLayout())
btn, _ := walk.NewPushButton(gb) btn, _ := walk.NewPushButton(gb)
btn.SetText("Select all colors") btn.SetText("Select all colors")
btn.Clicked().Attach(func() { btn.Clicked().Attach(func() {
for _, bead := range mw.beads { for _, bead := range mw.beads {
bead.Checkbox.SetChecked(true) bead.Checkbox.SetChecked(true)
@@ -45,34 +45,43 @@ func CreateBeadsGroup(mw *MyMainWindow) {
} }
func LoadBeads(mw *MyMainWindow) { func LoadBeads(mw *MyMainWindow) {
for _, brand := range mw.pallette.Brands.Brand { var located bool
for _, brand := range mw.pallette.Brand {
if brand.BrandName == mw.brand_combo.Text() { if brand.BrandName == mw.brand_combo.Text() {
log.Println("Loading beads for brand: " + brand.BrandName + " ...") log.Println("Loading beads for brand: " + brand.BrandName + " ...")
for _, series := range brand.Series.Serie { log.Println("Loading beads for serie: " + mw.serie_combo.Text() + " ...")
if series.SerieName == mw.serie_combo.Text() { for _, bead := range brand.Colors {
log.Println("Loading beads for serie: " + series.SerieName + " ...") for _, serie := range bead.Series.Serie {
for _, bead := range series.Beads.Color { if serie == mw.serie_combo.Text() {
log.Println("Loading bead: " + bead.ColorName + " ...") located = true
if !bead.Disabled { }
bc := NewBeadColor(mw, bead.ColorName, bead.ColorIndex, bead.OnHand, bead.Red, bead.Green, bead.Blue) }
bc.Brand = brand.BrandName if located {
bc.Series = series.SerieName log.Println("Loading bead: " + bead.ColorName + " ...")
bc.Weight = series.Weight if !bead.Disabled {
bc.Name = bead.ColorName bc := NewBeadColor(mw, bead.ColorName, bead.ColorIndex, bead.OnHand, bead.Red, bead.Green, bead.Blue)
bc.ColorID = bead.ColorIndex for _, series := range brand.Series {
bc.Red = bead.Red if series.Serie == mw.serie_combo.Text() {
bc.Green = bead.Green bc.Series = series.Serie
bc.Blue = bead.Blue bc.Weight = series.Weight
bc.inStock = bead.InStock
mw.beads = append(mw.beads, bc)
if bead.OnHand <= 200 {
bc.warning.SetVisible(true)
bc.info.SetVisible(false)
} else {
bc.warning.SetVisible(false)
bc.info.SetVisible(true)
} }
} }
bc.Brand = brand.BrandName
bc.Name = bead.ColorName
bc.ColorID = bead.ColorIndex
bc.Red = bead.Red
bc.Green = bead.Green
bc.Blue = bead.Blue
bc.inStock = bead.InStock
mw.beads = append(mw.beads, bc)
if bead.OnHand <= 200 {
bc.warning.SetVisible(true)
bc.info.SetVisible(false)
} else {
bc.warning.SetVisible(false)
bc.info.SetVisible(true)
}
} }
} }
} }
+1 -1
View File
@@ -40,7 +40,7 @@ func CreateDefaultConfig() {
Config.AddSection("pallette") Config.AddSection("pallette")
Config.Set("pallette", "brand", "Hama") Config.Set("pallette", "brand", "Hama")
Config.Set("pallette", "serie", "Midi") Config.Set("pallette", "serie", "Midi")
Config.Set("pallette", "pegboard", "Large 29x29") Config.Set("pallette", "pegboard", "Square 29x29")
Config.AddSection("canvas") Config.AddSection("canvas")
Config.Set("canvas", "scale", "100") Config.Set("canvas", "scale", "100")
Config.Set("canvas", "showgrid", "true") Config.Set("canvas", "showgrid", "true")
+1 -1
View File
@@ -30,7 +30,7 @@ type MyMainWindow struct {
const ( const (
AppName string = "BeadImager" AppName string = "BeadImager"
Version string = "0.1.3" Version string = "0.2.0"
CopyRight string = "©2022 Jan Lerking" CopyRight string = "©2022 Jan Lerking"
STD_MESS string = "Ready" STD_MESS string = "Ready"
LogFile string = "BeadImager.log" LogFile string = "BeadImager.log"
+47 -58
View File
@@ -11,70 +11,54 @@ import (
type ( type (
Pallette struct { Pallette struct {
XMLName xml.Name `xml:"pallette"` XMLName xml.Name `xml:"pallette"`
Brands Brandsstruct `xml:"brands"`
}
Brandsstruct struct {
XMLName xml.Name `xml:"brands"`
Brand []Brandstruct `xml:"brand"` Brand []Brandstruct `xml:"brand"`
} }
Brandstruct struct { Brandstruct struct {
XMLName xml.Name `xml:"brand"` BrandName string `xml:"name,attr"`
BrandName string `xml:"brandname"` Series []Seriestruct `xml:"serie"`
Series Seriesstruct `xml:"series"` Pegboards []Pegboardstruct `xml:"pegboard"`
} Colors []Colorstruct `xml:"color"`
Seriesstruct struct {
XMLName xml.Name `xml:"series"`
Serie []Seriestruct `xml:"serie"`
} }
Seriestruct struct { Seriestruct struct {
XMLName xml.Name `xml:"serie"` Serie string `xml:"name,attr"`
SerieName string `xml:"seriename"` Weight int `xml:"weightPerThousand"`
Weight int `xml:"weightPerThousand"`
Pegboards Pegboardsstruct `xml:"pegboards"`
Beads Beadsstruct `xml:"beads"`
}
Pegboardsstruct struct {
XMLName xml.Name `xml:"pegboards"`
Pegboard []Pegboardstruct `xml:"pegboard"`
} }
Pegboardstruct struct { Pegboardstruct struct {
XMLName xml.Name `xml:"pegboard"` Serie string `xml:"serie,attr"`
Type string `xml:"type"` Type string `xml:"type"`
Width string `xml:"width"` Size string `xml:"size"`
Height string `xml:"height"`
}
Beadsstruct struct {
XMLName xml.Name `xml:"beads"`
Color []Colorstruct `xml:"color"`
} }
Colorstruct struct { Colorstruct struct {
XMLName xml.Name `xml:"color"` Series struct {
ColorIndex int `xml:"colorIndex,attr"` XMLName xml.Name `xml:"series"`
ColorName string `xml:"colorname"` Serie []string `xml:"serie"`
ProductCode string `xml:"productCode"` }
Brand string `xml:"brand"` ColorIndex int `xml:"colorIndex,attr"`
Red byte `xml:"red"` ColorName string `xml:"colorname"`
Green byte `xml:"green"` ProductCode string `xml:"productCode"`
Blue byte `xml:"blue"` Brand string `xml:"brand"`
IsPearl bool `xml:"isPearl"` Red byte `xml:"red"`
IsTranslucent bool `xml:"isTranslucent"` Green byte `xml:"green"`
IsNeutral bool `xml:"isNeutral"` Blue byte `xml:"blue"`
IsGrayscale bool `xml:"isGrayscale"` IsPearl bool `xml:"isPearl"`
Disabled bool `xml:"disabled"` IsTranslucent bool `xml:"isTranslucent"`
InStock bool `xml:"inStock"` IsNeutral bool `xml:"isNeutral"`
OnHand int `xml:"onHand"` IsGrayscale bool `xml:"isGrayscale"`
Disabled bool `xml:"disabled"`
InStock bool `xml:"inStock"`
OnHand int `xml:"onHand"`
} }
) )
var (
serie_triggered bool = false
)
func CreatePalletteGroup(mw *MyMainWindow) *walk.GroupBox { func CreatePalletteGroup(mw *MyMainWindow) *walk.GroupBox {
mw.leftPanel, _ = walk.NewComposite(mw.content) mw.leftPanel, _ = walk.NewComposite(mw.content)
vb := walk.NewVBoxLayout() vb := walk.NewVBoxLayout()
@@ -102,6 +86,13 @@ func CreatePalletteGroup(mw *MyMainWindow) *walk.GroupBox {
mw.serie_combo, _ = walk.NewComboBox(comp) mw.serie_combo, _ = walk.NewComboBox(comp)
mw.serie_combo.SetModel(CreateSeriesList(mw)) mw.serie_combo.SetModel(CreateSeriesList(mw))
mw.serie_combo.SetText(ConfigSerie) mw.serie_combo.SetText(ConfigSerie)
mw.serie_combo.CurrentIndexChanged().Attach(func() {
if !serie_triggered {
mw.colors.Children().Clear()
LoadBeads(mw)
serie_triggered = true
}
})
comp, _ = walk.NewComposite(pallette_group) comp, _ = walk.NewComposite(pallette_group)
comp.SetLayout(walk.NewHBoxLayout()) comp.SetLayout(walk.NewHBoxLayout())
comp.Layout().SetMargins(walk.Margins{0, 0, 0, 0}) comp.Layout().SetMargins(walk.Margins{0, 0, 0, 0})
@@ -115,13 +106,11 @@ func CreatePalletteGroup(mw *MyMainWindow) *walk.GroupBox {
func CreatePegboardsList(mw *MyMainWindow) []string { func CreatePegboardsList(mw *MyMainWindow) []string {
pegboards := make([]string, 0) pegboards := make([]string, 0)
for _, brand := range mw.pallette.Brands.Brand { for _, brand := range mw.pallette.Brand {
if brand.BrandName == mw.brand_combo.Text() { if brand.BrandName == mw.brand_combo.Text() {
for _, serie := range brand.Series.Serie { for _, pegboard := range brand.Pegboards {
if serie.SerieName == mw.serie_combo.Text() { if pegboard.Serie == mw.serie_combo.Text() {
for _, pegboard := range serie.Pegboards.Pegboard { pegboards = append(pegboards, pegboard.Type)
pegboards = append(pegboards, pegboard.Type)
}
} }
} }
} }
@@ -131,10 +120,10 @@ func CreatePegboardsList(mw *MyMainWindow) []string {
func CreateSeriesList(mw *MyMainWindow) []string { func CreateSeriesList(mw *MyMainWindow) []string {
series := make([]string, 0) series := make([]string, 0)
for _, brand := range mw.pallette.Brands.Brand { for _, brand := range mw.pallette.Brand {
if brand.BrandName == mw.brand_combo.Text() { if brand.BrandName == mw.brand_combo.Text() {
for _, serie := range brand.Series.Serie { for _, serie := range brand.Series {
series = append(series, serie.SerieName) series = append(series, serie.Serie)
} }
} }
} }
@@ -143,7 +132,7 @@ func CreateSeriesList(mw *MyMainWindow) []string {
func CreateBrandsList(mw *MyMainWindow) []string { func CreateBrandsList(mw *MyMainWindow) []string {
brands := make([]string, 0) brands := make([]string, 0)
for _, brand := range mw.pallette.Brands.Brand { for _, brand := range mw.pallette.Brand {
brands = append(brands, brand.BrandName) brands = append(brands, brand.BrandName)
} }
return brands return brands
+1443 -1131
View File
File diff suppressed because it is too large Load Diff