unloading the gocui toolkit works

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-22 12:25:50 -05:00
parent 535f15f741
commit 37dee72c32
5 changed files with 29 additions and 5 deletions

View File

@ -146,7 +146,7 @@ attempts to locate the .so file
`func ShowDebugValues()` `func ShowDebugValues()`
### func [StandardExit](/main.go#L153) ### func [StandardExit](/main.go#L169)
`func StandardExit()` `func StandardExit()`
@ -187,7 +187,7 @@ var Config GuiConfig
The Node is a binary tree. This is how all GUI elements are stored The Node is a binary tree. This is how all GUI elements are stored
simply the name and the size of whatever GUI element exists simply the name and the size of whatever GUI element exists
#### func [New](/main.go#L126) #### func [New](/main.go#L142)
`func New() *Node` `func New() *Node`

18
main.go
View File

@ -112,13 +112,29 @@ func (n *Node) doUserEvent(a toolkit.Action) {
} }
func (n *Node) LoadToolkit(name string) *Node { func (n *Node) LoadToolkit(name string) *Node {
log(logInfo, "Start() Main(f) for name =", name) log(logInfo, "LoadToolkit() for name =", name)
if (FindPlugin(name) == nil) { if (FindPlugin(name) == nil) {
return n return n
} }
return n return n
} }
func (n *Node) CloseToolkit(name string) bool {
log(logInfo, "CloseToolkit() for name =", name)
for _, aplug := range allPlugins {
log(debugGui, "CloseToolkit() found", aplug.name)
if (aplug.name == name) {
log(debugNow, "CloseToolkit() sending close", name)
var a toolkit.Action
a.ActionType = toolkit.CloseToolkit
aplug.pluginChan <- a
sleep(.5)
return true
}
}
return false
}
// There should only be one of these per application // There should only be one of these per application
// This is due to restrictions by being cross platform // This is due to restrictions by being cross platform
// some toolkit's on some operating systems don't support more than one // some toolkit's on some operating systems don't support more than one

View File

@ -83,5 +83,6 @@ func main() {
log("This is a test log entry") log("This is a test log entry")
MouseMain() MouseMain()
log(true, "MouseMain() closed")
me.baseGui.Close() me.baseGui.Close()
} }

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"os"
// if you include more than just this import // if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27) // then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
@ -38,6 +39,11 @@ func action(a *toolkit.Action) {
w.AddText(a.S) w.AddText(a.S)
case toolkit.Move: case toolkit.Move:
log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name) log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
case toolkit.CloseToolkit:
log(logNow, "attempting to close the plugin and release stdout and stderr")
me.baseGui.Close()
// defer outf.Close()
setOutput(os.Stdout)
default: default:
log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name) log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name)
} }

View File

@ -109,7 +109,6 @@ const (
const ( const (
Add ActionType = iota Add ActionType = iota
User // the user did something (mouse, keyboard, etc)
Delete Delete
Get Get
Set Set
@ -127,7 +126,9 @@ const (
Append Append
Move Move
Dump Dump
Quit User // the user did something (mouse, keyboard, etc)
InitToolkit // initializes the toolkit
CloseToolkit // closes the toolkit
) )
func (s WidgetType) String() string { func (s WidgetType) String() string {