2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
import (
|
2023-03-03 14:41:38 -06:00
|
|
|
"embed"
|
2023-04-06 19:48:24 -05:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
"github.com/andlabs/ui"
|
2022-11-06 12:59:24 -06:00
|
|
|
// the _ means we only need this for the init()
|
2022-10-20 06:55:42 -05:00
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
)
|
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
//go:embed resources
|
|
|
|
var res embed.FS
|
2023-04-08 00:28:33 -05:00
|
|
|
|
|
|
|
// this is the channel we get requests to make widgets
|
2023-04-07 18:16:16 -05:00
|
|
|
var pluginChan chan toolkit.Action
|
|
|
|
|
|
|
|
func catchActionChannel() {
|
|
|
|
log(logNow, "makeCallback() START")
|
|
|
|
for {
|
|
|
|
log(logNow, "makeCallback() for loop")
|
|
|
|
select {
|
|
|
|
case a := <-pluginChan:
|
|
|
|
log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
|
|
|
|
// go Action(a)
|
|
|
|
if (a.WidgetType == toolkit.Window) {
|
|
|
|
log(logNow, "makeCallback() WINDOW START")
|
|
|
|
go ui.Main( func() {
|
2023-04-08 11:06:50 -05:00
|
|
|
log(logNow, "ui.Main() WINDOW START DOING NOTHING")
|
|
|
|
newWindow(&a)
|
2023-04-07 18:16:16 -05:00
|
|
|
log(logNow, "ui.Main() WINDOW END")
|
|
|
|
})
|
|
|
|
sleep(.5)
|
|
|
|
log(logNow, "makeCallback() WINDOW END")
|
|
|
|
} else {
|
|
|
|
log(logNow, "makeCallback() STUFF")
|
2023-04-08 11:06:50 -05:00
|
|
|
rawAction(a)
|
2023-04-07 18:16:16 -05:00
|
|
|
log(logNow, "makeCallback() STUFF END")
|
|
|
|
}
|
2023-04-07 21:22:51 -05:00
|
|
|
// sleep(.1)
|
2023-04-07 18:16:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-03 14:41:38 -06:00
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func Main(f func()) {
|
2023-04-07 18:16:16 -05:00
|
|
|
log(debugNow, "gui.Main() START (using gtk via andlabs/ui)")
|
|
|
|
f() // support the old way. deprecate this
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
2023-04-06 19:48:24 -05:00
|
|
|
// this sets the channel to send user events back from the plugin
|
|
|
|
func Callback(guiCallback chan toolkit.Action) {
|
|
|
|
callback = guiCallback
|
|
|
|
}
|
|
|
|
|
2023-04-07 22:12:18 -05:00
|
|
|
func PluginChannel() chan toolkit.Action {
|
|
|
|
return pluginChan
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
// 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.)
|
|
|
|
//
|
|
|
|
// For example: Queue(NewWindow())
|
|
|
|
//
|
|
|
|
func Queue(f func()) {
|
2023-04-07 18:16:16 -05:00
|
|
|
log(logNow, "Sending function to ui.QueueMain()")
|
|
|
|
log(logNow, "using gui.Queue() in this plugin DOES BREAK. TODO: solve this with channels")
|
2023-02-25 14:05:25 -06:00
|
|
|
ui.QueueMain(f)
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
|
2022-11-14 14:30:28 -06:00
|
|
|
func Init() {
|
2023-04-07 18:16:16 -05:00
|
|
|
log(logNow, "Init() START")
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Init()")
|
2023-03-12 08:47:16 -05:00
|
|
|
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
|
|
|
|
// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
|
|
|
|
setDefaultBehavior(true)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
// mapWidgets = make(map[*andlabsT]*toolkit.Widget)
|
|
|
|
// mapToolkits = make(map[*toolkit.Widget]*andlabsT)
|
|
|
|
|
|
|
|
andlabs = make(map[int]*andlabsT)
|
2023-04-07 18:16:16 -05:00
|
|
|
pluginChan = make(chan toolkit.Action)
|
|
|
|
|
|
|
|
log(logNow, "Init() ui.Main() start")
|
|
|
|
go catchActionChannel()
|
|
|
|
/*
|
|
|
|
ui.Main( func() {
|
|
|
|
log(logNow, "gui.Main() IN (using gtk via andlabs/ui)")
|
|
|
|
var a toolkit.Action
|
|
|
|
a.Name = "jcarr"
|
|
|
|
a.Width = 640
|
|
|
|
a.Height = 480
|
|
|
|
a.WidgetId = 0
|
|
|
|
newWindow(&a)
|
|
|
|
// time.Sleep(1 * time.Second)
|
|
|
|
// NewWindow2("helloworld2", 200, 100)
|
|
|
|
log(logNow, "gui.Main() EXIT (using gtk via andlabs/ui)")
|
|
|
|
})
|
|
|
|
*/
|
|
|
|
log(logNow, "Init() END")
|
2022-11-14 14:30:28 -06:00
|
|
|
}
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// TODO: properly exit the plugin since Quit() doesn't do it
|
2022-11-14 14:30:28 -06:00
|
|
|
func Quit() {
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugToolkit, "Quit() TODO: close the toolkit cleanly")
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|