giu icon indicating copy to clipboard operation
giu copied to clipboard

exec.Command block Msgbox[bug]

Open 93Alliance opened this issue 3 years ago • 12 comments

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

  1. Run my demo
  2. will see the crash...

Version

(latest)

OS

linuxmint20.2

93Alliance avatar Apr 19 '22 12:04 93Alliance

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)
}
  1. @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

gucio321 avatar Apr 19 '22 16:04 gucio321

func click() {
	cmd := exec.Command("ls")
	cmd.Start()
	if err := cmd.Wait(); err != nil {
            g.Msgbox("Info", "test")
        }
}
  1. I have already called giu.PrepareMsgbox() in order to use msgbox at all.
  2. When cmd.wait () returns an error, I call msgbox and it will not work.

93Alliance avatar Apr 20 '22 00:04 93Alliance

Well so let me test again

gucio321 avatar Apr 20 '22 05:04 gucio321

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

gucio321 avatar Apr 20 '22 06:04 gucio321

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)
}

gucio321 avatar Apr 20 '22 06:04 gucio321

thank you for your help!

93Alliance avatar Apr 20 '22 07:04 93Alliance

no problem! In case of any other issues, feel free to ping me again :-)

gucio321 avatar Apr 20 '22 08:04 gucio321

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 avatar Apr 21 '22 07:04 93Alliance

@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)
}

gucio321 avatar Apr 26 '22 14:04 gucio321

But the light style is different from the other styles. For example, i can call imgui.StyleColorsDefault() method.

93Alliance avatar Apr 27 '22 00:04 93Alliance

What do you mean by"Style color light is different"? Imo it # would fine - app turns white

gucio321 avatar May 03 '22 16:05 gucio321

@93Alliance any updates? Maybe you should open a new issue for styles problem

gucio321 avatar Jul 08 '22 19:07 gucio321

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!

gucio321 avatar May 08 '23 13:05 gucio321