summaryrefslogtreecommitdiff
path: root/toolkit/nocui/main.go
blob: a9577732b922c891a8386bda25543d0c16e38bd3 (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
package main

import (
	"sync"
	"git.wit.org/wit/gui/toolkit"
)

// this is the channel we get requests to make widgets
var pluginChan chan toolkit.Action

// the starting point of the binary tree
var rootNode *node

var muAction sync.Mutex

func catchActionChannel() {
	log(logNow, "catchActionChannel() START")
	for {
		log(logNow, "catchActionChannel() for loop")
	    	select {
		case a := <-pluginChan:
			log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
			log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
			muAction.Lock()
			doAction(&a)
			muAction.Unlock()
			log(logNow, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
		}
	}
}

// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
// other goroutines. This is due to the nature of how
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan toolkit.Action) {
	callback = guiCallback
}

func PluginChannel() chan toolkit.Action {
	return pluginChan
}

// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
	log(logNow, "Init() START")
	log(logInfo, "Init()")

	// andlabs = make(map[int]*andlabsT)
	pluginChan = make(chan toolkit.Action, 1)

	log(logNow, "Init() start channel reciever")
	go catchActionChannel()
	go simpleStdin()
	log(logNow, "Init() END")
}