2021-10-06 08:36:28 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-06 10:43:58 -05:00
|
|
|
import (
|
2023-03-12 08:47:16 -05:00
|
|
|
// "embed"
|
2023-03-29 23:03:04 -05:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2021-10-06 10:43:58 -05:00
|
|
|
)
|
2021-10-06 08:36:28 -05:00
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// Windows doesn't support plugins. How can I keep andlabs and only compile it on windows?
|
|
|
|
// https://forum.heroiclabs.com/t/setting-up-goland-to-compile-plugins-on-windows/594/5
|
|
|
|
// import toolkit "git.wit.org/wit/gui/toolkit/andlabs"
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
const Xaxis = 0 // stack things horizontally
|
|
|
|
const Yaxis = 1 // stack things vertically
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
/*
|
|
|
|
// TODO: 2023/03/03 rethink how to get a plugin or figure out how
|
|
|
|
// golang packages can include a binary. Pull from /usr/go/go-gui/ ?
|
|
|
|
// may this plugin work when all other plugins fail
|
|
|
|
|
|
|
|
// if this is in the plugin, the packages can't work with go.mod builds
|
|
|
|
# don't do this in the plugin // go:embed /usr/lib/go-gui/toolkit/gocui.so
|
|
|
|
# don't do this in the plugin var res embed.FS
|
|
|
|
*/
|
2022-11-13 08:53:03 -06:00
|
|
|
|
2022-10-20 06:55:42 -05:00
|
|
|
func init() {
|
2023-03-01 11:35:36 -06:00
|
|
|
log("init() has been run")
|
2022-10-20 06:55:42 -05:00
|
|
|
|
|
|
|
Config.counter = 0
|
|
|
|
Config.prefix = "wit"
|
2023-03-01 11:35:36 -06:00
|
|
|
Config.Width = 640
|
|
|
|
Config.Height = 480
|
2022-10-20 06:55:42 -05:00
|
|
|
|
2022-11-06 12:59:24 -06:00
|
|
|
// Populates the top of the binary tree
|
2023-03-29 23:03:04 -05:00
|
|
|
Config.rootNode = addNode("guiBinaryTree")
|
|
|
|
Config.rootNode.WidgetType = toolkit.Root
|
2023-03-01 11:35:36 -06:00
|
|
|
|
2023-03-03 14:41:38 -06:00
|
|
|
// used to pass debugging flags to the toolkit plugins
|
2023-03-29 23:03:04 -05:00
|
|
|
Config.flag = Config.rootNode.New("flag", 0, nil)
|
|
|
|
Config.flag.WidgetType = toolkit.Flag
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func doGuiChan() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-Config.ActionCh1:
|
|
|
|
log(true, "CHANNEL ACTION 1 !!!!!")
|
|
|
|
return
|
|
|
|
case <-Config.ActionCh2:
|
|
|
|
log(true, "CHANNEL ACTION 2 !!!!!")
|
|
|
|
return
|
|
|
|
default:
|
2023-03-03 14:41:38 -06:00
|
|
|
log(true, "doGuiChan() nothing")
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
2023-03-03 14:41:38 -06:00
|
|
|
log(true, "doGuiChan() for()")
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
func InitPlugins(names []string) {
|
|
|
|
log(debugGui, "Starting gui.Init()")
|
2022-11-13 08:53:03 -06:00
|
|
|
|
|
|
|
for _, aplug := range allPlugins {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugGui, "LoadToolkit() already loaded toolkit plugin =", aplug.name)
|
2023-02-25 14:05:25 -06:00
|
|
|
for _, name := range names {
|
|
|
|
if (name == aplug.name) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
// try to load each plugin in the order passed to this function
|
|
|
|
for _, name := range names {
|
|
|
|
if (LoadToolkit(name)) {
|
|
|
|
// aplug.InitOk = true
|
|
|
|
// aplug.Init()
|
|
|
|
return
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
// the program didn't specify a plugin. Try to load one
|
|
|
|
// TODO: detect the OS & user preferences to load the best one
|
|
|
|
// TODO: commented out Init() on 02/26/2023 because I'm not sure how to run it correctly
|
|
|
|
if (LoadToolkit("andlabs")) {
|
|
|
|
// aplug.InitOk = true
|
|
|
|
// aplug.Init()
|
|
|
|
return
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
2022-11-06 19:57:20 -06:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
if (LoadToolkit("gocui")) {
|
|
|
|
// aplug.InitOk = true
|
|
|
|
// aplug.Init()
|
|
|
|
return
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
|
|
|
|
// Should die here? TODO: need a Node to call StandardExit
|
|
|
|
// StandardExit("golang wit/gui could not load a plugin TODO: do something to STDOUT (?)")
|
2022-10-20 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
func Start() *Node {
|
|
|
|
log(logInfo, "Start() Main(f)")
|
|
|
|
f := func() {
|
|
|
|
}
|
|
|
|
go Main(f)
|
|
|
|
sleep(1)
|
|
|
|
return Config.rootNode
|
|
|
|
}
|
|
|
|
|
|
|
|
func StartS(name string) *Node {
|
|
|
|
log(logInfo, "Start() Main(f) for name =", name)
|
|
|
|
if (LoadToolkit(name) == false) {
|
|
|
|
return Config.rootNode
|
|
|
|
}
|
|
|
|
// will this really work on mswindows & macos?
|
|
|
|
f := func() {
|
|
|
|
}
|
|
|
|
go Main(f)
|
|
|
|
sleep(1) // temp hack until chan communication is setup
|
|
|
|
return Config.rootNode
|
|
|
|
}
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// This should not pass a function
|
2021-10-06 08:36:28 -05:00
|
|
|
func Main(f func()) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "Starting gui.Main() (using gtk via andlabs/ui)")
|
|
|
|
|
|
|
|
InitPlugins([]string{"andlabs", "gocui"})
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
for _, aplug := range allPlugins {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "gui.Node.NewButton() toolkit plugin =", aplug.name)
|
2022-11-13 08:53:03 -06:00
|
|
|
if (aplug.MainOk) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "gui.Node.Main() Already Ran Main()", aplug.name)
|
2022-11-13 08:53:03 -06:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (aplug.Main == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "gui.Node.Main() Main == nil", aplug.name)
|
2022-11-13 08:53:03 -06:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
aplug.MainOk = true
|
|
|
|
aplug.Main(f)
|
|
|
|
}
|
2021-10-06 08:36:28 -05:00
|
|
|
}
|
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
/*
|
|
|
|
This is deprecated and will be implemented more correctly with waitgroups
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
// This should never be exposed(?)
|
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
// Other goroutines must use this to access the GUI
|
2021-10-06 08:36:28 -05:00
|
|
|
//
|
|
|
|
// You can not acess / process the GUI thread directly from
|
2021-10-06 10:43:58 -05:00
|
|
|
// other goroutines. This is due to the nature of how
|
2021-10-06 08:36:28 -05:00
|
|
|
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
|
2022-10-20 06:55:42 -05:00
|
|
|
// For example: gui.Queue(NewWindow())
|
2022-11-14 14:30:28 -06:00
|
|
|
func Queue(f func()) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "Sending function to gui.Main() (using gtk via andlabs/ui)")
|
2022-11-13 08:53:03 -06:00
|
|
|
// toolkit.Queue(f)
|
|
|
|
for _, aplug := range allPlugins {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "gui.Node.NewButton() toolkit plugin =", aplug.name)
|
2022-11-13 08:53:03 -06:00
|
|
|
if (aplug.Queue == nil) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
aplug.Queue(f)
|
|
|
|
}
|
2021-10-06 08:36:28 -05:00
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
*/
|
2022-11-06 12:59:24 -06:00
|
|
|
|
|
|
|
// The window is destroyed but the application does not quit
|
2023-03-01 11:35:36 -06:00
|
|
|
func (n *Node) StandardClose() {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugGui, "wit/gui Standard Window Close. name =", n.Name)
|
2023-03-01 11:35:36 -06:00
|
|
|
log(debugGui, "wit/gui Standard Window Close. n.Custom exit =", n.Custom)
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// The window is destroyed and the application exits
|
|
|
|
// TODO: properly exit the plugin since Quit() doesn't do it
|
2023-03-01 11:35:36 -06:00
|
|
|
func StandardExit() {
|
|
|
|
log("wit/gui Standard Window Exit. running os.Exit()")
|
|
|
|
log("gui.Node.StandardExit() attempt to exit each toolkit plugin")
|
2022-11-13 08:53:03 -06:00
|
|
|
for i, aplug := range allPlugins {
|
2023-03-01 11:35:36 -06:00
|
|
|
log("gui.Node.NewButton()", i, aplug)
|
2022-11-13 08:53:03 -06:00
|
|
|
if (aplug.Quit != nil) {
|
|
|
|
aplug.Quit()
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
exit(0)
|
2022-11-06 12:59:24 -06:00
|
|
|
}
|