exec.Command block Msgbox[bug]
What happend?
exec.Command will block the message box display.
Code example
func loop() {
g.SingleWindow().Layout(
g.Button("sync").OnClick(click),
)
}
func click() {
cmd := exec.Command(cmdName, args...)
cmd.Start()
g.Msgbox("Info", "test")
cmd.Wait()
}
The message box will not display.
To Reproduce
- Run my demo
- will see the crash...
Version
(latest)
OS
linuxmint20.2
full code to reproduce:
package main
import (
"os/exec"
"github.com/AllenDang/giu"
g "github.com/AllenDang/giu"
)
func loop() {
g.SingleWindow().Layout(
g.Button("sync").OnClick(click),
)
}
func click() {
cmd := exec.Command("ls")
cmd.Start()
g.Msgbox("Info", "test")
cmd.Wait()
}
func main() {
wnd := giu.NewMasterWindow("msgbox click [issue 500]", 640, 480, 0)
wnd.Run(loop)
}
- @93Alliance how do you understand the panic message below (the panic produced by code above)?
panic: Msgbox is not prepared. Invoke giu.PrepareMsgbox in the end of the layout.
you must call giu.PrepareMsgbox() in order to use msgbox at all. 2. You cannot call cmd.Wait as it will pause the main goroutine (so also rendering the whole app) as long as command is beeing executed. You may want to use goroutines
func click() {
cmd := exec.Command("ls")
cmd.Start()
if err := cmd.Wait(); err != nil {
g.Msgbox("Info", "test")
}
}
- I have already called giu.PrepareMsgbox() in order to use msgbox at all.
- When cmd.wait () returns an error, I call msgbox and it will not work.
Well so let me test again
well, so the following code works for me:
package main
import (
"os/exec"
"github.com/AllenDang/giu"
g "github.com/AllenDang/giu"
)
var shouldCommandFail bool
func loop() {
g.SingleWindow().Layout(
g.Row(
g.Checkbox("Value of exit code: ", &shouldCommandFail),
),
g.Button("sync").OnClick(click),
g.PrepareMsgbox(),
)
}
func click() {
var commandStr string
// just a bash commands, "false" and "true" will set exit code (${?}) to 0-true or 1-false
if shouldCommandFail {
commandStr = "false"
} else {
commandStr = "true"
}
cmd := exec.Command(commandStr)
if err := cmd.Start(); err != nil {
g.Msgbox("Error starting command", err.Error())
}
if err := cmd.Wait(); err != nil {
g.Msgbox("Error executing command", err.Error())
}
}
func main() {
wnd := giu.NewMasterWindow("msgbox click [issue 500]", 640, 480, 0)
wnd.Run(loop)
}
NOTE you may want to run "click" function in goroutine in order not to pause main thread
something like that:
package main
import (
"os"
"os/exec"
"github.com/AllenDang/giu"
g "github.com/AllenDang/giu"
)
var (
shouldCommandFail bool
isButtonLocked bool
)
func loop() {
g.SingleWindow().Layout(
g.Row(
g.Checkbox("Value of exit code: ", &shouldCommandFail),
),
g.Button("sync").Disabled(isButtonLocked).OnClick(
func() {
go click()
}),
g.PrepareMsgbox(),
)
}
func click() {
cmd := exec.Command("ping", "google.com")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
isButtonLocked = true
if err := cmd.Start(); err != nil {
g.Msgbox("Error starting command", err.Error())
}
if err := cmd.Wait(); err != nil {
g.Msgbox("Error executing command", err.Error())
}
isButtonLocked = false
}
func main() {
wnd := giu.NewMasterWindow("msgbox click [issue 500]", 640, 480, 0)
wnd.Run(loop)
}
thank you for your help!
no problem! In case of any other issues, feel free to ping me again :-)
no problem! In case of any other issues, feel free to ping me again :-)
I have a new issues.
imgui.StyleColorsLight()
imgui.StyleColorsDark()
imgui.StyleColorsClassic()
I can't set default style. May i get your help?
@93Alliance I'm able to set these styles. Just put imgui.StyleColors...() call before wnd.Run call:
package main
import (
g "github.com/AllenDang/giu"
"github.com/AllenDang/imgui-go"
)
var content string
func loop() {
g.SingleWindow().Layout(
g.Label("Hello world from giu"),
g.InputTextMultiline(&content).Size(g.Auto, g.Auto),
)
}
func main() {
wnd := g.NewMasterWindow("Hello world", 400, 200, 0)
imgui.StyleColorsLight()
wnd.Run(loop)
}
But the light style is different from the other styles. For example, i can call imgui.StyleColorsDefault() method.
What do you mean by"Style color light is different"? Imo it # would fine - app turns white
@93Alliance any updates? Maybe you should open a new issue for styles problem
Due to longer inactivity and a full demo code posted above I think it could be closed. Feel free to ping me for any details!