paulo-fernando-silva / vscOctaveDebugger

MIT License
35 stars 4 forks source link

debug with qt graphic toolkit windows #24

Closed HendrikDo closed 3 years ago

HendrikDo commented 4 years ago

Hi, first of all, thanks for providing this extension. :)

I like to use the qt toolkit for ploting an advanced figure with buttons and sliders. It's possible to start the octave-cli with qt, when using "octave-gui --no-gui" as cmd command. https://octave.org/doc/v4.4.0/Command-Line-Options.html Therefor I've tried the same with your tool:

"octave": "C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui --no-gui" Error Message: Could not connect to 'C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui --no-gui'! Check path.

only using "octave-gui" "octave": "C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui" Error Message: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

I've also tried to modify the Runtime.js to add this command parameter: code snipped from Runtime.js: start(program, workingDirectory) { this._program = program; this.addFolder(path_1.dirname(program)); this.cwd(workingDirectory); // This is just like a deferred sync command. // The program executes and then echoes the terminator tag. const terminator = this.echo(Runtime.TERMINATOR); this.execute(${fsutils_1.functionFromPath(program+" --no-gui")};${terminator}); Error Message: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Is there an option to add command parameters? Or are there other methods to solve this issue? Greetings

paulo-fernando-silva commented 4 years ago

Hi Hendrik, do you need to run octave-gui to use QT plotting? What are the octave commands that generate the plots? I'm trying to understand if the two are dependent. Can you post a trivial sample program that exemplifies this use case? Cheers.

HendrikDo commented 4 years ago

Hello Paulo, yes indeed only the octave-gui has the Qt plotting included. You can check which toolkits are provided with the octave command: available_graphics_toolkits().

I'm pretty sure this example isn't trivial any more, but unfortunately you need certain parts of it to get the programm running. My actual project is very similar to this one. https://wiki.octave.org/Uicontrols -> Code: demo_uicontrol.m small sample: m191126_demo_short.zip

## 20.03.2017 Andreas Weber <andy@josoansi.de>
## Demo which has the aim to show all available GUI elements.
## Useful since Octave 4.0

close all
clear h

graphics_toolkit qt

h.ax = axes ("position", [0.05 0.42 0.5 0.5]);
h.fcn = @(x) polyval([-0.1 0.5 3 0], x);

function update_plot (obj, init = false)

  ## gcbo holds the handle of the control
  h = guidata (obj);
  replot = false;
  recalc = false;
  switch (gcbo)
    case {h.noise_slider}
      recalc = true;
  endswitch

  if (recalc || init)
    x = linspace (-4, 9);
    noise = get (h.noise_slider, "value");
    set (h.noise_label, "string", sprintf ("Noise: %.1f%%", noise * 100));
    y = h.fcn (x) + 5 * noise * randn (size (x));
    if (init)
      h.plot = plot (x, y, "b");
      guidata (obj, h);
    else
      set (h.plot, "ydata", y);
    endif
  endif

endfunction

## noise
h.noise_label = uicontrol ("style", "text",
                           "units", "normalized",
                           "string", "Noise:",
                           "horizontalalignment", "left",
                           "position", [0.05 0.3 0.35 0.08]);

h.noise_slider = uicontrol ("style", "slider",
                            "units", "normalized",
                            "string", "slider",
                            "callback", @update_plot,
                            "value", 0.4,
                            "position", [0.05 0.25 0.35 0.06]);

set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
paulo-fernando-silva commented 4 years ago

Thanks for the sample. So it seems to run for me but I have to use a special octave-gui apparently. I ran it by adding the following to launch.json: { "type": "OctaveDebugger", "request": "launch", "name": "debug qt gui", "program": "${workspaceFolder}/octave-gui-demo/m191126_demo_short.m" "octave": "/opt/local/libexec/octave/5.1.0/exec/x86_64-apple-darwin17.x.x/octave-gui" } Check the attached image. The point here is that this octave-gui apparently runs in cli mode. I imagine that's the same as you're trying to do with C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui. Not sure why it's not working though. Did you try to run that command from a command line to see if it works. I wondering if the working directory could influence it. Maybe it's an issue with the PATH, or the lack of it.

Screen Shot 2019-11-27 at 13 46 55
HendrikDo commented 4 years ago

Morning Paulo, you're right the C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui is not working in command line, seems to be a problem with the QtCore.dll My bad, sorry...

Qtcrash

for Win i have to use the octave.vbs to open the GUI version of Octave

pathvbs cmd octave vbs --no-gui

So i've changed my script accordingly .

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "OctaveDebugger",
            "request": "launch",
            "name": "Plot Test",
            "program": "m191126_demo_short",
            "octave": "C:/Octave/Octave-5.1.0.0/octave.vbs",
            "sourceFolder": "${workspaceFolder}"
        }
    ]
}

Now Visual Studio Code keeps loading and loading, nothing seems to happen...

loading

I've tried to modify the octave.vbs starting Line 59...

' check args to see if told to run gui or command line
' and build other args to use
GUI_MODE=0
AllArgs = ""

For command line this change is working and the octave.vbs command is starting the octave-gui --no-gui version, but VSC is still loading, no change here. octave.vbs.zip

paulo-fernando-silva commented 4 years ago

I don't have time to test it on windows right now. Maybe this weekend. But maybe this will help. Try setting "octave": "C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui" again and before running VSCode try to create an environment variable like "QT_PLUGIN_PATH"="C:/Octave/Octave-5.1.0.0/mingw64/qt5/plugins" in your environment variables via the system environment variables editing in "control panel." It might also help to add "PATH"="C:/Octave/Octave-5.1.0.0/mingw64/bin":(...more here...) there too. Then when you run C:/Octave/Octave-5.1.0.0/mingw64/bin/octave-gui via the run command on windows it should run octave and give you a shell interface. If it works then you should be able to run it in vsc too. If not then try to add the options "logFilename": "${workspaceFolder}/log", "verbose": true" to your launch command. That should print the log to both a file and the console. But I imagine that the issue is that vsc is not able to communicate with the octave process its I/O is being sent to this octave.vbs instead of the octave-gui.exe directly. So you would likely need to redirect stdin/out from the vbs to the exe if you really want to launch the exe via the vbs.

HendrikDo commented 4 years ago

I believe you don't need to give it a try on windows.

qtplot

I've added the following to system environment variables:

"QT_PLUGIN_PATH"="C:/Octave/Octave-5.1.0.0/mingw64/qt5/plugins"

"PATH"="C:/Octave/Octave-5.1.0.0/mingw64/bin"

systemenviromentvariables

and now it's starting with Qt.

One more question, is the slider working for you? Normally the callback function is recalculation the whole plot after using the slider...

h.noise_slider = uicontrol ("style", "slider",
                            "units", "normalized",
                            "string", "slider",
                            "callback", @update_plot,
                            "value", 0.4,
                            "position", [0.05 0.25 0.35 0.06]);

demo with normal Octave GUI: slider

paulo-fernando-silva commented 4 years ago

You might want to add the following code to the end of your file just for debugging:

while true
  pause (1000/60);
end
print("Quitting...");

The point is that if the code runs to the end, vscOctaveDebugger will terminate octave-gui as part of its cleanup. So you can't exit while you're debugging. But you also can't pause execution or else the GUI will not update. So, as a workaround for debugging you can add that loop. It updates the UI 60 times a second. You can remove it when you're done with the debugging. Or you can add a button that changes a boolean variable that controls the loop if you want to get fancy.

HendrikDo commented 4 years ago

Jupp, using the loop for refresh is working well. In my opinion this matter is solved, therefore I will close this issue. Thanks for helping me Paulo. :)

paulo-fernando-silva commented 4 years ago

Great, I'm glad it works for you. I'm opening the bug again because because the loop is just a workaround and I want to fix the issue. When I have time I'm planning to debug octave-gui and try to figure out what might be going wrong.

paulo-fernando-silva commented 3 years ago

I'm still not sure why qt seems to block on I/O. Maybe the rendering thread also handles I/O. I would have to check the actual implementation on octave-gui, but I don't really have time right now so I'm closing this bug for now. 😕