summaryrefslogtreecommitdiff
path: root/setText.go
blob: 71bde54b152626b9ff4e6f5a38434f596d5128c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main

import (
	"go.wit.com/log"
	"go.wit.com/toolkits/tree"
	"go.wit.com/widget"
)

func realSetText(n *tree.Node, name string) {
	// name := widget.GetString(a.Value)
	var tk *guiWidget
	tk = n.TK.(*guiWidget)

	log.Log(ANDLABS, "setText() START with text =", name, n.WidgetType)
	if tk == nil {
		log.Log(ERROR, "setText error. tk == nil", n.GetProgName(), n.WidgetId)
		return
	}

	switch n.WidgetType {
	case widget.Window:
		log.Log(ANDLABS, "setText() Attempt to set the title to", name)
		tk.uiWindow.SetTitle(name)
	case widget.Tab:
	case widget.Group:
		tk.uiGroup.SetTitle(name)
	case widget.Checkbox:
		tk.uiCheckbox.SetText(name)
	case widget.Textbox:
		log.Log(ANDLABS, "setText() on Textbox START with text =", name)
		if tk.uiEntry != nil {
			tk.uiEntry.SetText(name)
		}
		if tk.uiMultilineEntry != nil {
			tk.uiMultilineEntry.SetText(name)
		}
	case widget.Label:
		tk.uiLabel.SetText(name)
	case widget.Button:
		tk.uiButton.SetText(name)
	case widget.Slider:
		log.Log(ERROR, "setText() on slider unknown", n.GetProgName())
	case widget.Spinner:
		log.Log(ERROR, "setText() on spinner unknown", n.GetProgName())
	case widget.Dropdown:
		var orig int
		var i int = -1
		var s string
		orig = tk.uiCombobox.Selected()
		log.Log(ANDLABS, "try to set the Dropdown to", name, "from", orig)
		// try to find the string
		for i, s = range tk.val {
			log.Log(ANDLABS, "i, s", i, s)
			if name == s {
				tk.uiCombobox.SetSelected(i)
				log.Log(ANDLABS, "setText() Dropdown worked.", name)
				return
			}
		}
		log.Log(ERROR, "setText() Dropdown did not find:", name)
		// if i == -1, then there are not any things in the menu to select
		if i == -1 {
			return
		}
		// if the string was never set, then set the dropdown to the last thing added to the menu
		if orig == -1 {
			tk.uiCombobox.SetSelected(i)
		}
	case widget.Combobox:
		tk.uiEditableCombobox.SetText(name)
	default:
		log.Log(ERROR, "plugin Send() Don't know how to setText on", n.WidgetType, "yet")
	}
	log.Log(ANDLABS, "setText() END with name =")
}