Ejemplo n.º 1
0
func trViewExpose(tv sparta.Widget, e interface{}) bool {
	dt := tv.Property(sparta.Data)
	if dt == nil {
		return false
	}
	data := dt.(*trData)
	draw := tv.(*widget.Canvas)
	for _, n := range data.node {
		draw.Draw(n.ancLine)
		if n.level > 0 {
			draw.Draw(n.descLine)
		} else if len(n.name.Text) > 0 {
			draw.Draw(n.name)
		}
	}
	if n := data.sel; n != nil {
		rect := widget.Rectangle{
			Rect: image.Rect(n.pos.X-3, n.pos.Y-3, n.pos.X+3, n.pos.Y+3),
		}
		draw.Draw(rect)
		rect.Rect = image.Rect(n.pos.X-2, n.pos.Y-2, n.pos.X+2, n.pos.Y+2)
		rect.Fill = true
		draw.SetColor(sparta.Foreground, color.RGBA{G: 255})
		draw.Draw(rect)
	}
	return false
}
Ejemplo n.º 2
0
// TxKey gets keyboard events.
func txKey(tx sparta.Widget, e interface{}) bool {
	data := tx.Property(sparta.Data).(*pageData)
	ev := e.(sparta.KeyEvent)
	switch ev.Key {
	case sparta.KeyDown:
		if (data.pos + 1) < (len(poem) - data.page + 1) {
			data.pos++
		}
		tx.Update()
	case sparta.KeyUp:
		if (data.pos - 1) >= 0 {
			data.pos--
		}
		tx.Update()
	case sparta.KeyPageUp:
		if data.pos == 0 {
			break
		}
		data.pos -= data.page
		if data.pos < 0 {
			data.pos = 0
		}
		tx.Update()
	case sparta.KeyPageDown:
		if data.pos == (len(poem) - data.page) {
			break
		}
		data.pos += data.page
		if data.pos > (len(poem) - data.page + 1) {
			data.pos = len(poem) - data.page
		}
		tx.Update()
	}
	return true
}
Ejemplo n.º 3
0
// pgExpose draws the polygons.
func pgExpose(pg sparta.Widget, e interface{}) bool {
	data := pg.Property(sparta.Data).([]widget.Polygon)
	c := pg.(*widget.Canvas)
	c.Draw(data[0])
	c.Draw(data[1])
	return false
}
Ejemplo n.º 4
0
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)
}
Ejemplo n.º 5
0
func txNavInfoExpose(tx sparta.Widget, e interface{}) bool {
	d := tx.Property(sparta.Data)
	if d == nil {
		return false
	}
	data := d.(*txTaxAnc)
	c := tx.(*widget.Canvas)
	txt := widget.Text{}
	txt.Pos.X = 2
	txt.Pos.Y = 2
	txt.Text = "Id: " + data.tax.Id
	c.Draw(txt)
	txt.Pos.Y += sparta.HeightUnit
	txt.Text = data.tax.Name
	c.Draw(txt)
	txt.Pos.Y += sparta.HeightUnit
	txt.Text = data.tax.Authority
	c.Draw(txt)
	txt.Pos.Y += sparta.HeightUnit
	txt.Text = data.tax.Rank.String()
	c.Draw(txt)
	txt.Pos.Y += sparta.HeightUnit
	if data.tax.IsValid {
		txt.Text = "Valid"
		c.Draw(txt)
		if data.anc != nil {
			txt.Pos.Y += sparta.HeightUnit
			txt.Text = "Parent: " + data.anc.Name
			c.Draw(txt)

		}
	} else {
		txt.Text = "Synonym of " + data.anc.Name
		c.Draw(txt)

	}
	if len(data.tax.Extern) > 0 {
		txt.Pos.Y += sparta.HeightUnit
		txt.Text = "Extern ids:"
		c.Draw(txt)
		for _, e := range data.tax.Extern {
			txt.Pos.Y += sparta.HeightUnit
			txt.Text = "    " + e
			c.Draw(txt)
		}
	}
	if len(data.tax.Comment) > 0 {
		txt.Pos.Y += sparta.HeightUnit
		txt.Text = "Comments:"
		c.Draw(txt)
		cmt := strings.Split(data.tax.Comment, "\n")
		for _, e := range cmt {
			txt.Pos.Y += sparta.HeightUnit
			txt.Text = "  " + e
			c.Draw(txt)
		}
	}
	return false
}
Ejemplo n.º 6
0
// SendEvent sends an event to a widget.
func sendEvent(dest sparta.Widget, comm sparta.CommandEvent) {
	dwin := dest.Window().(*window)
	var id w32.HWND
	if comm.Source != nil {
		id = comm.Source.Window().(*window).id
	}
	w32.PostMessage(dwin.id, w32.WM_USER, uintptr(id), uintptr(comm.Value))
}
Ejemplo n.º 7
0
// SnConf sets the new values of the sine function points
func snConf(sn sparta.Widget, e interface{}) bool {
	ev := e.(sparta.ConfigureEvent)

	// Get data from the widget.
	data := sn.Property(sparta.Data).([]image.Point)
	sine(data, ev.Rect.Dx(), ev.Rect.Dy())
	return false
}
Ejemplo n.º 8
0
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()
}
Ejemplo n.º 9
0
func propagateWheel(w sparta.Widget, pt image.Point) sparta.Widget {
	rect := w.Property(sparta.Geometry).(image.Rectangle)
	childs := w.Property(sparta.Childs)
	if childs == nil {
		return w
	}
	for _, ch := range childs.([]sparta.Widget) {
		rect = ch.Property(sparta.Geometry).(image.Rectangle)
		if pt.In(rect) {
			return propagateWheel(ch, pt.Add(rect.Min))
		}
	}
	return w
}
Ejemplo n.º 10
0
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)
}
Ejemplo n.º 11
0
// ObExpose draws the objects.
func obExpose(ob sparta.Widget, e interface{}) bool {
	data := ob.Property(sparta.Data).(*objData)
	c := ob.(*widget.Canvas)
	// Set color sets a color temporalely for the following dawing
	// operations. Contrast this with the property sparta.Background
	// and sparta.Foreground.
	c.SetColor(sparta.Foreground, color.RGBA{255, 0, 0, 0})
	c.Draw(widget.Rectangle{Rect: data.arc.Rect})
	c.SetColor(sparta.Foreground, color.RGBA{0, 255, 0, 0})
	c.Draw(data.l1)
	c.Draw(data.l2)
	c.SetColor(sparta.Foreground, color.RGBA{0, 0, 255, 0})
	c.Draw(data.arc)
	return false
}
Ejemplo n.º 12
0
// SendEvent sends an event to the window.
func sendEvent(dest sparta.Widget, comm sparta.CommandEvent) {
	dwin := dest.Window().(*window)
	var id xgb.Id
	if comm.Source != nil {
		id = comm.Source.Window().(*window).id
	}
	event := make([]byte, 32)
	event[0] = xgb.ClientMessage // id of the event
	event[1] = 32                // format
	put32(event[4:], uint32(dwin.id))
	put32(event[8:], uint32(atomMsg))     // message type (client message)
	put32(event[12:], uint32(id))         // sender of the event
	put32(event[16:], uint32(comm.Value)) // value of the event
	xwin.SendEvent(false, dwin.id, 0, event)
}
Ejemplo n.º 13
0
// SnExpose draw the sine function.
func snExpose(sn sparta.Widget, e interface{}) bool {
	// get point data.
	data := sn.Property(sparta.Data).([]image.Point)
	// get widget geometry
	geo := sn.Property(sparta.Geometry).(image.Rectangle)

	c := sn.(*widget.Canvas)
	// The widget canvas ruses the function Draw to draw particular
	// objects, it depends on the data type to decide what to draw.
	// Here a line (the "x" axis), is draw.
	c.Draw([]image.Point{image.Pt(0, geo.Dy()/2), image.Pt(geo.Dx(), geo.Dy()/2)})
	// Then the sine function is draw.
	c.Draw(data)

	return false
}
Ejemplo n.º 14
0
func spNavInitSpeList(m, s sparta.Widget) {
	d := m.Property(sparta.Data)
	l := wnd["speList"]
	if d == nil {
		l.SetProperty(widget.ListList, nil)
		return
	}
	data := d.(*txList)
	if len(data.sels) == 0 {
		l.SetProperty(widget.ListList, nil)
		return
	}
	tax := data.desc[data.sels[0]]
	ls := newSpList(tax, data.db)
	l.SetProperty(widget.ListList, ls)
}
Ejemplo n.º 15
0
// TxExpose draws the poem.
func txExpose(tx sparta.Widget, e interface{}) bool {
	data := tx.Property(sparta.Data).(*pageData)
	rect := tx.Property(sparta.Geometry).(image.Rectangle)
	c := tx.(*widget.Canvas)

	// Text store the text to be drawing
	txt := widget.Text{}
	txt.Pos.X = 2
	for i, ln := range poem[data.pos:] {
		// The position of the text is the top-right corner of
		// the rectange that enclose the text.
		txt.Pos.Y = (i * sparta.HeightUnit) + 2
		if txt.Pos.Y > rect.Dy() {
			break
		}
		txt.Text = ln
		c.Draw(txt)
	}
	return false
}
Ejemplo n.º 16
0
func mConf(m sparta.Widget, e interface{}) bool {
	// the sparta.Childs property return the children of a widget.
	ch := m.Property(sparta.Childs).([]sparta.Widget)
	ev := e.(sparta.ConfigureEvent)
	for _, c := range ch {
		// We check the name propery of each widget and use it
		// to set the new geometry of each widget.
		switch nm := c.Property(sparta.Name).(string); nm {
		case "sine":
			c.SetProperty(sparta.Geometry, image.Rect(0, 0, ev.Rect.Dx()/2, ev.Rect.Dy()/2))
		case "polygon":
			c.SetProperty(sparta.Geometry, image.Rect(ev.Rect.Dx()/2, 0, ev.Rect.Dx(), ev.Rect.Dy()/2))
		case "objects":
			c.SetProperty(sparta.Geometry, image.Rect(0, ev.Rect.Dy()/2, ev.Rect.Dx()/2, ev.Rect.Dy()))
		case "poem":
			c.SetProperty(sparta.Geometry, image.Rect(ev.Rect.Dx()/2, ev.Rect.Dy()/2, ev.Rect.Dx(), ev.Rect.Dy()))
		}
	}
	return false
}
Ejemplo n.º 17
0
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)
}
Ejemplo n.º 18
0
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
}
Ejemplo n.º 19
0
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()
}
Ejemplo n.º 20
0
// NewWindow creates a new window and assigns it to a widget.
func newWindow(w sparta.Widget) {
	var win *window
	rect := w.Property(sparta.Geometry).(image.Rectangle)
	if p := w.Property(sparta.Parent); p != nil {
		pW := p.(sparta.Widget)
		pWin := pW.Window().(*window)
		win = &window{
			w:    w,
			back: pWin.back,
			fore: pWin.fore,
			pos:  rect.Min,
		}
		count := len(pW.Property(sparta.Childs).([]sparta.Widget))
		pW.SetProperty(sparta.Childs, w)
		win.id = w32.CreateWindowEx(0, stringToUTF16(childClass), nil,
			uint(w32.WS_CHILDWINDOW|w32.WS_VISIBLE),
			rect.Min.X, rect.Min.Y, rect.Dx(), rect.Dy(),
			pWin.id, w32.HMENU(count),
			w32.HINSTANCE(w32.GetWindowLong(pWin.id, w32.GWL_HINSTANCE)), nil)
		if win.id == 0 {
			log.Printf("w32: error: %v\n", getLastError())
			os.Exit(1)
		}
	} else {
		win = &window{
			w:    w,
			back: bkGround,
			fore: frGround,
		}
		win.id = w32.CreateWindowEx(uint(w32.WS_EX_CLIENTEDGE),
			stringToUTF16(baseClass), stringToUTF16(""),
			uint(w32.WS_OVERLAPPEDWINDOW),
			150, 150, rect.Dx()+extraX, rect.Dy()+extraY,
			0, 0, instance, nil)
		if win.id == 0 {
			log.Printf("w32: error: %v\n", getLastError())
			os.Exit(1)
		}
	}
	widgetTable[win.id] = w
	w.SetWindow(win)

	w32.ShowWindow(win.id, w32.SW_SHOWDEFAULT)
	if !w32.UpdateWindow(win.id) {
		log.Printf("w32: error: %v\n", getLastError())
		os.Exit(1)
	}
}
Ejemplo n.º 21
0
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)
}
Ejemplo n.º 22
0
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)
}
Ejemplo n.º 23
0
// TxMouse gets mouse events.
func txMouse(tx sparta.Widget, e interface{}) bool {
	data := tx.Property(sparta.Data).(*pageData)
	ev := e.(sparta.MouseEvent)
	switch ev.Button {
	case sparta.MouseLeft, -sparta.MouseWheel:
		if (data.pos + 1) < (len(poem) - data.page + 1) {
			data.pos++
		}
		tx.Update()
	case sparta.MouseRight, sparta.MouseWheel:
		if (data.pos - 1) >= 0 {
			data.pos--
		}
		tx.Update()
	}
	return true
}
Ejemplo n.º 24
0
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)
}
Ejemplo n.º 25
0
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)
}
Ejemplo n.º 26
0
// NewWindow creates a new window and assigns it to a widget.
func newWindow(w sparta.Widget) {
	s := xwin.DefaultScreen()
	pId := s.Root
	win := &window{
		id:   xwin.NewId(),
		w:    w,
		gc:   xwin.NewId(),
		back: s.WhitePixel,
		fore: s.BlackPixel,
	}
	if p := w.Property(sparta.Parent); p != nil {
		pw := p.(sparta.Widget)
		pWin := pw.Window().(*window)
		win.back = pWin.back
		win.fore = pWin.fore
		pId = pWin.id
		pw.SetProperty(sparta.Childs, w)
	}
	widgetTable[win.id] = w
	w.SetWindow(win)
	r := w.Property(sparta.Geometry).(image.Rectangle)
	xwin.CreateWindow(0, win.id, pId,
		int16(r.Min.X), int16(r.Min.Y), uint16(r.Dx()), uint16(r.Dy()), 0,
		xgb.WindowClassInputOutput, s.RootVisual, 0, nil)
	xwin.ChangeWindowAttributes(win.id, xgb.CWBackPixel|xgb.CWEventMask,
		[]uint32{
			win.back,
			allEventMask,
		})
	font := xwin.NewId()
	xwin.OpenFont(font, fixed)
	xwin.CreateGC(win.gc, win.id, xgb.GCBackground|xgb.GCForeground|xgb.GCFont,
		[]uint32{
			win.fore,
			win.back,
			uint32(font),
		})
	xwin.CloseFont(font)
	xwin.MapWindow(win.id)
	xwin.ChangeProperty(xgb.PropModeReplace, win.id, wmProtocols, atomType, 32, wmDelete)
}
Ejemplo n.º 27
0
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
}
Ejemplo n.º 28
0
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
}
Ejemplo n.º 29
0
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
}
Ejemplo n.º 30
0
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
}