func trViewInitList(m, tv sparta.Widget) { l, err := localDB.List(jdh.Trees, new(jdh.Values)) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", cmd.ErrStr(err)) return } data := &trList{} for { phy := &jdh.Phylogeny{} if err := l.Scan(phy); err != nil { if err == io.EOF { break } fmt.Fprintf(os.Stderr, "%s\n", cmd.ErrStr(err)) return } if (len(phy.Id) == 0) || (len(phy.Root) == 0) { continue } data.phyLs = append(data.phyLs, phy) } if len(data.phyLs) == 0 { return } m.SetProperty(sparta.Data, data) trViewInitTree(m, tv) }
func txEdInitList(m, l sparta.Widget, data *txList, i int, syns bool) { if data == nil { data = newTxList(nil, localDB, syns) } else { d := newTxList(data.desc[i], data.db, syns) if len(d.desc) == 0 { if l.Property(sparta.Name).(string) == "validList" { data.sels = []int{i} } else { sel := false for _, s := range data.sels { if s == i { sel = true break } } if !sel { data.sels = append(data.sels, i) } } } else { data = d } } if l.Property(sparta.Name).(string) == "taxonList" { m.SetProperty(sparta.Data, data) } l.SetProperty(widget.ListList, data) }
func trViewMouse(tv sparta.Widget, e interface{}) bool { dt := tv.Property(sparta.Data) if dt == nil { return true } data := dt.(*trData) ev := e.(sparta.MouseEvent) switch ev.Button { case sparta.MouseRight: if !setFlag { return true } if data.sel == nil { return true } sel := trViewNearestNode(ev.Loc, data.node) if sel == nil { return true } x, y, pos := data.x, data.y, data.pos p := tv.Property(sparta.Parent).(sparta.Widget) d := p.Property(sparta.Data).(*trList) if sel == data.sel { vals := new(jdh.Values) vals.Add(jdh.NodCollapse, sel.id) localDB.Exec(jdh.Delete, jdh.Nodes, vals) localDB.Exec(jdh.Commit, "", nil) } else if !sel.isValidSis(data.sel) { return true } else { vals := new(jdh.Values) vals.Add(jdh.KeyId, data.sel.id) vals.Add(jdh.NodSister, sel.id) localDB.Exec(jdh.Set, jdh.Nodes, vals) localDB.Exec(jdh.Commit, "", nil) } rect := tv.Property(sparta.Geometry).(image.Rectangle) data = setTree(d.phyLs[d.pos], rect) data.x, data.y, data.pos = x, y, pos tv.SetProperty(sparta.Data, data) data.putOnScreen() tv.Update() case sparta.MouseLeft: data.sel = trViewNearestNode(ev.Loc, data.node) tv.Update() case -sparta.MouseWheel: data.pos.Y -= 5 data.putOnScreen() tv.Update() case sparta.MouseWheel: data.pos.Y += 5 data.putOnScreen() tv.Update() } return true }
func txEdSetCaption(m sparta.Widget) { d := m.Property(sparta.Data) if d == nil { m.SetProperty(sparta.Caption, "no data") return } dt := d.(*txList) title := fmt.Sprintf("%s: %s [id: %s]", cmd.Name, dt.tax.Name, dt.tax.Id) m.SetProperty(sparta.Caption, title) }
func txNavComm(m sparta.Widget, e interface{}) bool { d := m.Property(sparta.Data) if d == nil { return true } data := d.(*txList) ev := e.(sparta.CommandEvent) switch ev.Source.Property(sparta.Name).(string) { case "taxonList": if ev.Value < 0 { i := -ev.Value - 1 if i >= len(data.desc) { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) ev.Source.SetProperty(widget.ListList, nil) tx := wnd["info"] tx.SetProperty(sparta.Data, nil) tx.Update() sparta.Block(nil) go txNavInitList(m, ev.Source, data.db, data, i) break } if data.IsSel(ev.Value) { data.sels = nil } else { data.sels = []int{ev.Value} } tx := wnd["info"] tx.SetProperty(sparta.Data, nil) tx.Update() ev.Source.Update() sparta.Block(nil) go func() { txNavInfo(tx, data) sparta.Unblock(nil) }() case "upTax": if data.tax.Id == "0" { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) l := wnd["taxonList"] l.SetProperty(widget.ListList, nil) tx := wnd["info"] tx.SetProperty(sparta.Data, nil) sparta.Block(nil) go txNavAncList(m, l, data.db, data.tax) } return true }
func trViewInitTree(m, tv sparta.Widget) { d := m.Property(sparta.Data).(*trList) if d.pos >= len(d.phyLs) { return } title := fmt.Sprintf("%s: %s [id: %s]", cmd.Name, d.phyLs[d.pos].Name, d.phyLs[d.pos].Id) m.SetProperty(sparta.Caption, title) rect := tv.Property(sparta.Geometry).(image.Rectangle) curTree := setTree(d.phyLs[d.pos], rect) curTree.putOnScreen() tv.SetProperty(sparta.Data, curTree) tv.Update() }
func txNavInfo(tx sparta.Widget, data *txList) { if len(data.sels) == 0 { tx.SetProperty(sparta.Data, nil) } else { pair := &txTaxAnc{ tax: data.desc[data.sels[0]], anc: data.tax, } if data.tax.Id == "0" { pair.anc = nil } tx.SetProperty(sparta.Data, pair) } tx.Update() }
func txEdUpdateList(m, l sparta.Widget, data *txList, syns bool) { if data == nil { data = newTxList(nil, localDB, syns) } else { d := newTxList(data.tax, data.db, syns) if len(d.desc) == 0 { txEdAncList(m, l, data.tax, syns) return } data = d } if l.Property(sparta.Name).(string) == "taxonList" { m.SetProperty(sparta.Data, data) } l.SetProperty(widget.ListList, data) }
func txEdAncList(m, l sparta.Widget, tax *jdh.Taxon, syns bool) { var p *jdh.Taxon if len(tax.Parent) > 0 { p = taxon(cmd, localDB, tax.Parent) if len(p.Id) == 0 { p = nil } } data := newTxList(p, localDB, syns) for i, d := range data.desc { if d.Id == tax.Id { data.sels = []int{i} break } } if l.Property(sparta.Name).(string) == "taxonList" { m.SetProperty(sparta.Data, data) } l.SetProperty(widget.ListList, data) }
func spNavInitTaxList(m, l sparta.Widget, db jdh.DB, data *txList, i int) { if data == nil { data = newTxList(nil, db, true) } else { d := newTxList(data.desc[i], data.db, true) if len(d.desc) == 0 { data.sels = []int{i} } else { data = d } } title := fmt.Sprintf("%s: %s [id: %s]", cmd.Name, data.tax.Name, data.tax.Id) m.SetProperty(sparta.Caption, title) m.SetProperty(sparta.Data, data) l.SetProperty(widget.ListList, data) }
func spNavAncList(m, l sparta.Widget, db jdh.DB, tax *jdh.Taxon) { var p *jdh.Taxon if len(tax.Parent) > 0 { p = taxon(cmd, db, tax.Parent) if len(p.Id) == 0 { p = nil } } data := newTxList(p, db, true) title := fmt.Sprintf("%s: %s [id: %s]", cmd.Name, data.tax.Name, data.tax.Id) m.SetProperty(sparta.Caption, title) m.SetProperty(sparta.Data, data) for i, d := range data.desc { if d.Id == tax.Id { data.sels = []int{i} break } } l.SetProperty(widget.ListList, data) }
func spNavInfo(tx sparta.Widget, db jdh.DB, spe *jdh.Specimen, tax *jdh.Taxon) { if spe == nil { tx.SetProperty(sparta.Data, nil) tx.Update() return } if spe.Taxon != tax.Id { tx.SetProperty(sparta.Data, nil) tx.Update() return } info := &spInfo{ tax: tax, spe: spe, } if len(spe.Dataset) > 0 { info.set = dataset(cmd, db, spe.Dataset) } tx.SetProperty(sparta.Data, info) tx.Update() }
func txEdComm(m sparta.Widget, e interface{}) bool { ev := e.(sparta.CommandEvent) switch ev.Source.Property(sparta.Name).(string) { case "move": frWg := wnd["taxonList"] d := frWg.Property(widget.ListList) if d == nil { break } frLs := d.(*txList) if (len(frLs.sels) == 0) && (frLs.tax.Id == "0") { break } toWg := wnd["validList"] d = toWg.Property(widget.ListList) if d == nil { break } toLs := d.(*txList) var to *jdh.Taxon if len(toLs.sels) == 0 { to = toLs.tax } else { to = toLs.desc[toLs.sels[0]] } if (len(frLs.sels) == 0) && (frLs.tax.Id == to.Id) { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) frWg.SetProperty(widget.ListList, nil) toWg.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { if len(frLs.sels) == 0 { txEdMove(frLs.tax, to) } else { for _, s := range frLs.sels { from := frLs.desc[s] txEdMove(from, to) } } localDB.Exec(jdh.Commit, "", nil) txEdUpdateList(m, frWg, frLs, true) txEdUpdateList(m, toWg, toLs, false) txEdSetCaption(m) sparta.Unblock(nil) }() case "syn": frWg := wnd["taxonList"] d := frWg.Property(widget.ListList) if d == nil { break } frLs := d.(*txList) if (len(frLs.sels) == 0) && (frLs.tax.Id == "0") { break } toWg := wnd["validList"] d = toWg.Property(widget.ListList) if d == nil { break } toLs := d.(*txList) var to *jdh.Taxon if len(toLs.sels) == 0 { to = toLs.tax } else { to = toLs.desc[toLs.sels[0]] } if to.Id == "0" { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) frWg.SetProperty(widget.ListList, nil) toWg.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { if len(frLs.sels) == 0 { txEdSyn(frLs.tax, to) } else { for _, s := range frLs.sels { from := frLs.desc[s] txEdSyn(from, to) } } localDB.Exec(jdh.Commit, "", nil) txEdUpdateList(m, frWg, frLs, true) txEdUpdateList(m, toWg, toLs, false) txEdSetCaption(m) sparta.Unblock(nil) }() case "taxonList": d := ev.Source.Property(widget.ListList) if d == nil { break } data := d.(*txList) if ev.Value < 0 { i := -ev.Value - 1 if i >= len(data.desc) { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) ev.Source.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { txEdInitList(m, ev.Source, data, i, true) txEdSetCaption(m) sparta.Unblock(nil) }() break } sel := true for j, s := range data.sels { if s == ev.Value { sel = false data.sels[j] = data.sels[len(data.sels)-1] data.sels = data.sels[:len(data.sels)-1] break } } if sel { data.sels = append(data.sels, ev.Value) } ev.Source.Update() break case "upTax": l := wnd["taxonList"] d := l.Property(widget.ListList) if d == nil { break } data := d.(*txList) if data.tax.Id == "0" { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) l.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { txEdAncList(m, l, data.tax, true) txEdSetCaption(m) sparta.Unblock(nil) }() case "upVal": l := wnd["validList"] d := l.Property(widget.ListList) if d == nil { break } data := d.(*txList) if data.tax.Id == "0" { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) l.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { txEdAncList(m, l, data.tax, false) txEdSetCaption(m) sparta.Unblock(nil) }() case "val": frWg := wnd["taxonList"] d := frWg.Property(widget.ListList) if d == nil { break } frLs := d.(*txList) if len(frLs.sels) == 0 { if frLs.tax.Id == "0" { break } if frLs.tax.IsValid { break } } toWg := wnd["validList"] d = toWg.Property(widget.ListList) if d == nil { break } toLs := d.(*txList) title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) frWg.SetProperty(widget.ListList, nil) toWg.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { if len(frLs.sels) == 0 { txEdVal(frLs.tax) } else { for _, s := range frLs.sels { from := frLs.desc[s] txEdVal(from) } } localDB.Exec(jdh.Commit, "", nil) txEdUpdateList(m, frWg, frLs, true) txEdUpdateList(m, toWg, toLs, false) txEdSetCaption(m) sparta.Unblock(nil) }() case "validList": d := ev.Source.Property(widget.ListList) if d == nil { break } data := d.(*txList) if ev.Value < 0 { i := -ev.Value - 1 if i >= len(data.desc) { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) ev.Source.SetProperty(widget.ListList, nil) sparta.Block(nil) go func() { txEdInitList(m, ev.Source, data, i, false) txEdSetCaption(m) sparta.Unblock(nil) }() break } if data.IsSel(ev.Value) { data.sels = nil } else { data.sels = []int{ev.Value} } ev.Source.Update() } return true }
func trViewKey(tv sparta.Widget, e interface{}) bool { dt := tv.Property(sparta.Data) if dt == nil { return true } data := dt.(*trData) rect := tv.Property(sparta.Geometry).(image.Rectangle) ev := e.(sparta.KeyEvent) switch ev.Key { case sparta.KeyDown: data.pos.Y -= 5 case sparta.KeyUp: data.pos.Y += 5 case sparta.KeyLeft: data.pos.X -= 5 case sparta.KeyRight: data.pos.X += 5 case sparta.KeyHome: data.pos = image.Pt(0, 0) case sparta.KeyPageUp: data.pos.Y += rect.Dy() - sparta.HeightUnit case sparta.KeyPageDown: data.pos.Y -= rect.Dy() - sparta.HeightUnit case ' ', sparta.KeyReturn: p := tv.Property(sparta.Parent).(sparta.Widget) d := p.Property(sparta.Data).(*trList) if (d.pos + 1) >= len(d.phyLs) { return false } d.pos++ title := fmt.Sprintf("%s: please wait", cmd.Name) p.SetProperty(sparta.Caption, title) tv.SetProperty(sparta.Data, nil) go trViewInitTree(p, tv) case sparta.KeyBackSpace: p := tv.Property(sparta.Parent).(sparta.Widget) d := p.Property(sparta.Data).(*trList) if (d.pos - 1) < 0 { return false } d.pos-- tv.SetProperty(sparta.Data, nil) title := fmt.Sprintf("%s: please wait", cmd.Name) p.SetProperty(sparta.Caption, title) go trViewInitTree(p, tv) case '+': data.y = data.y * 5 / 4 case '-': data.y = data.y * 4 / 5 case '*': data.x = data.x * 5 / 4 case '/': data.x = data.x * 4 / 5 case '#': root := data.node[0] data.y = float32(rect.Dy()-10) / float32(root.terms+2) data.x = float32(rect.Dx()-10-(sparta.WidthUnit*32)) / float32(root.level) case '=': data.y = float32(sparta.HeightUnit) data.x = float32(sparta.WidthUnit * 2) case '>': if !data.aln { return false } data.aln = false case '<': if data.aln { return false } data.aln = true default: return true } data.putOnScreen() tv.Update() return false }
func spNavComm(m sparta.Widget, e interface{}) bool { ev := e.(sparta.CommandEvent) switch ev.Source.Property(sparta.Name).(string) { case "speList": d := ev.Source.Property(widget.ListList) if d == nil { break } data := d.(*spList) i := ev.Value if ev.Value < 0 { i = -ev.Value - 1 } tx := wnd["info"] if data.IsSel(i) { data.sel = -1 tx.SetProperty(sparta.Data, nil) tx.Update() ev.Source.Update() break } data.sel = i tx.SetProperty(sparta.Data, nil) tx.Update() ev.Source.Update() sparta.Block(nil) go func() { spNavInfo(tx, data.db, data.spe[i], data.tax) sparta.Unblock(nil) }() case "taxonList": d := ev.Source.Property(widget.ListList) if d == nil { break } data := d.(*txList) s := wnd["speList"] tx := wnd["info"] if ev.Value < 0 { i := -ev.Value - 1 if i >= len(data.desc) { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) ev.Source.SetProperty(widget.ListList, nil) s.SetProperty(widget.ListList, nil) tx.SetProperty(sparta.Data, nil) tx.Update() sparta.Block(nil) go func() { spNavInitTaxList(m, ev.Source, data.db, data, i) sparta.Unblock(nil) }() break } if data.IsSel(ev.Value) { data.sels = nil tx.SetProperty(sparta.Data, nil) tx.Update() s.SetProperty(widget.ListList, nil) } else { data.sels = []int{ev.Value} tx.SetProperty(sparta.Data, nil) tx.Update() sparta.Block(nil) go func() { spNavInitSpeList(m, s) sparta.Unblock(nil) }() } ev.Source.Update() case "upTax": l := wnd["taxonList"] s := wnd["speList"] tx := wnd["info"] d := l.Property(widget.ListList) if d == nil { break } data := d.(*txList) if data.tax.Id == "0" { break } title := fmt.Sprintf("%s: please wait", cmd.Name) m.SetProperty(sparta.Caption, title) l.SetProperty(widget.ListList, nil) s.SetProperty(widget.ListList, nil) tx.SetProperty(sparta.Data, nil) tx.Update() sparta.Block(nil) go func() { spNavAncList(m, l, data.db, data.tax) spNavInitSpeList(m, s) sparta.Unblock(nil) }() } return true }