trap toolkit panics

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-30 03:17:15 -06:00
parent 00a0184918
commit 21836a8001
6 changed files with 44 additions and 21 deletions

View File

@ -103,7 +103,7 @@ func (w *guiWidget) doWidgetClick() {
case widget.Window: case widget.Window:
log.Log(NOW, "doWidgetClick() START on window", w.String()) log.Log(NOW, "doWidgetClick() START on window", w.String())
if me.currentWindow == w.node { if me.currentWindow == w.node {
if ! w.active { if !w.active {
return return
} }
} }

View File

@ -41,13 +41,13 @@ var superLightGrey gocui.Attribute = gocui.GetColor("#55AAFF") // super light gr
// Normal Text On mouseover // Normal Text On mouseover
// //
// Widget Frame Text background Text background // Widget Frame Text background Text background
var colorWindow colorT = colorT { var colorWindow colorT = colorT{
frame: none, frame: none,
fg: gocui.ColorBlue, fg: gocui.ColorBlue,
bg: none, bg: none,
selFg: none, selFg: none,
selBg: powdererBlue, selBg: powdererBlue,
name: "normal window", name: "normal window",
} }
var colorActiveW colorT = colorT{none, none, powdererBlue, none, powdererBlue, "active window"} var colorActiveW colorT = colorT{none, none, powdererBlue, none, powdererBlue, "active window"}
@ -58,13 +58,13 @@ var colorButton colorT = colorT{gocui.ColorGreen, none, gocui.ColorWhite, gocui.
var colorLabel colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal label"} var colorLabel colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal label"}
var colorGroup colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal group"} var colorGroup colorT = colorT{none, none, superLightGrey, none, superLightGrey, "normal group"}
var colorDisabled colorT = colorT { var colorDisabled colorT = colorT{
frame: superLightGrey, frame: superLightGrey,
fg: superLightGrey, fg: superLightGrey,
bg: superLightGrey, bg: superLightGrey,
selFg: gocui.ColorBlack, selFg: gocui.ColorBlack,
selBg: gocui.ColorBlack, selBg: gocui.ColorBlack,
name: "disabled widget", name: "disabled widget",
} }
// widget debugging colors. these widgets aren't displayed unless you are debugging // widget debugging colors. these widgets aren't displayed unless you are debugging

19
main.go
View File

@ -6,6 +6,7 @@ package main
import ( import (
"os" "os"
"runtime/debug"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
@ -30,7 +31,7 @@ func init() {
log.Log(NOW, "Init() start pluginChan") log.Log(NOW, "Init() start pluginChan")
// go catchActionChannel() // go catchActionChannel()
log.Sleep(.1) // probably not needed, but in here for now under development log.Sleep(.1) // probably not needed, but in here for now under development
go main() go mainGogui()
log.Sleep(.1) // probably not needed, but in here for now under development log.Sleep(.1) // probably not needed, but in here for now under development
} }
@ -58,6 +59,19 @@ func standardExit() {
var outf *os.File var outf *os.File
func main() { func main() {
}
func mainGogui() {
defer func() {
if r := recover(); r != nil {
log.Warn("YAHOOOO Recovered in guiMain application:", r)
log.Warn("Recovered from panic:", r)
log.Warn("Stack trace:")
debug.PrintStack()
me.myTree.SendToolkitPanic()
return
}
}()
var err error var err error
log.Log(INFO, "main() start Init()") log.Log(INFO, "main() start Init()")
@ -75,7 +89,4 @@ func main() {
ferr, _ := os.OpenFile("/tmp/witgui.err", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664) ferr, _ := os.OpenFile("/tmp/witgui.err", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
os.Stderr = ferr os.Stderr = ferr
gocuiMain() gocuiMain()
log.Log(NOW, "MouseMain() closed")
standardExit()
} }

24
size.go
View File

@ -22,7 +22,9 @@ func (tk *guiWidget) Size() (int, int) {
var maxH int = 0 var maxH int = 0
var maxW int = 0 var maxW int = 0
for _, child := range tk.children { for _, child := range tk.children {
if tk.hidden { continue } if tk.hidden {
continue
}
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
maxW += sizeW maxW += sizeW
if sizeH > maxH { if sizeH > maxH {
@ -41,7 +43,9 @@ func (tk *guiWidget) Size() (int, int) {
maxH := tk.gocuiSize.Height() maxH := tk.gocuiSize.Height()
for _, child := range tk.children { for _, child := range tk.children {
if tk.hidden { continue } if tk.hidden {
continue
}
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
// increment straight down // increment straight down
@ -59,11 +63,15 @@ func (tk *guiWidget) Size() (int, int) {
} }
func (w *guiWidget) sizeGrid() (int, int) { func (w *guiWidget) sizeGrid() (int, int) {
if w.hidden { return 0, 0 } if w.hidden {
return 0, 0
}
// first compute the max sizes of the rows and columns // first compute the max sizes of the rows and columns
for _, child := range w.children { for _, child := range w.children {
if w.hidden { continue } if w.hidden {
continue
}
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
// set the child's realWidth, and grid offset // set the child's realWidth, and grid offset
@ -91,12 +99,16 @@ func (w *guiWidget) sizeBox() (int, int) {
if w.WidgetType != widget.Box { if w.WidgetType != widget.Box {
return 0, 0 return 0, 0
} }
if w.hidden { return 0, 0 } if w.hidden {
return 0, 0
}
var maxW int = 0 var maxW int = 0
var maxH int = 0 var maxH int = 0
for _, child := range w.children { for _, child := range w.children {
if w.hidden {continue} if w.hidden {
continue
}
sizeW, sizeH := child.Size() sizeW, sizeH := child.Size()
if child.direction == widget.Horizontal { if child.direction == widget.Horizontal {
maxW += sizeW maxW += sizeW

View File

@ -151,7 +151,7 @@ type guiWidget struct {
active bool active bool
enable bool enable bool
defaultColor *colorT // store the color to go back to defaultColor *colorT // store the color to go back to
hidden bool hidden bool

2
tab.go
View File

@ -66,7 +66,7 @@ func (w *guiWidget) redoWindows(nextW int, nextH int) {
child.showView() child.showView()
sizeW := child.gocuiSize.Width() sizeW := child.gocuiSize.Width()
nextW += sizeW + 4 nextW += sizeW + 4
child.redoWindows(startW + 3, startH + 2) child.redoWindows(startW+3, startH+2)
} }
} }