Making dockable widgets (except command window) available in command-line version of Octave

I’d like to make (most of) the dockable widgets available when running Octave in command line mode[*]. I think this would be useful for people who prefer the CLI interface but may occasionally want to pop up the documentation browser, the code editor, or the variable editor. I imagine that the file, workspace, and history browser widgets could even be useful for some users.

The CLI version already allows Qt graphics windows to be opened, so it seems this should be a fairly easy change. I experimented with making the base_octave_qobject object own the documentation browser window when Octave doesn’t start the GUI (and thus doesn’t create a main_window object). But with these widgets built on top of QDockWidget it wasn’t quite as simple as I’d hoped. The octave_dock_widget class and the underlying QDockWidget seem to really want to be attached to a parent where they can be docked.

I’m sure we could create separate widgets for these windows that don’t use the dock widget. I tried another experiment writing a simple documentation widget simply derived from QWidget and it sort of worked, but would need layout and geometry hints to really work correctly. Since the existing dockable widgets alread have all of that, I’d rather avoid the duplication. And it just seems that it would be nice to have a single widget that has the option of being dockable. It would be even better if that could all be done in the octave_dock_widget class because then the problem could be solved once for all these windows. Any insight into doing that would be greatly appreciated.

[*] By “command-line mode”, I mean starting octave without the --gui flag, but still running the version linked with Qt libraries, not the octave-cli binary (that one doesn’t link with Qt).

Cannot comment on how to make it happen but just to say that it would be a great feature. I am someone who would prefer to use the CLI interface but with the code editor, so end up using the full GUI.

As a comparison point, I use Matlab with matlab -nodesktop but use the code editor edit and documentation browser doc. I don’t think there is a way to display the other widgets (variable editor, file and history browser) but that’s not something that appeals to me. From the CLI, you can start the GUI interface with desktop and when closing it, it returns to the CLI; not that I have ever used this.

I cannot provide any help either but encourage the effort. I am a cli user and I only start the GUI when I want to browse the html doc, so I would be very interested to have that feature.

Once the new command window widget is finished, we will also be able to start the full GUI interface from the command line and return to the CLI when it is closed.

See also this topic: I’ll try to make the changes described there optional with a configure switch (or, better, command line option) so I can push them but allow others to more easily experiment with them.

I’m attaching a (very) preliminary patch just as a proof of concept that allowing dock widgets to be launched as separate windows should be possible.

If I have some more time to work on this, I plan to do something like

  1. Store all dock widgets in a separate object that is owned by the base_octave_qobject object instead of the main_window object.
  2. Allow dock widgets stored in that object to be created on demand.
  3. Allow dock widgets to be adopted by the main_window object. The main_window object will simply acquire references to them.
  4. If the GUI is started from the command line after some of these dock widgets are created, then they will continue to exist (as undocked windows, of course) after the main_window object is closed.

Some care may be needed to disconnect signals when the dock widgets are adopted by the main_window object and then reconnect them when the main_window object is closed and deleted.

doc-browser-diffs.txt (10.4 KB)

In the current state of the patch, how are we supposed to test it?
It builds correctly for me but then I see no way to launch a GUI window from cli, e.g. doc still launches the info browser and edit still opens my external editor.

Sorry, I should have included more explanation. First you must start the GUI with the --experimental-terminal-widget even though you are not using the --gui. Then at the command line, you can use the function __event_manager_show_doc__ (). Pass an argument to select a particular function: __event_manager_show_doc__ ("svd"), for example.

I plan to do some more work on this feature in the next few days to enable more windows and to hook them up to the expected functions like doc, not just the __event_manager* internal functions.

I’ll also try to get some command-line editing features working with the new terminal widget option.

Thanks, the doc browsers opened as expected with those additional instructions.
Couple of issues I noticed when not using the GUI in conjunction with --experimental-terminal-widget:

  • Arrow keys print escape sequences in the terminal rather than moving the cursor (left/right) or browsing the history (up/down). I guess this is related to the lack of support for readline in this mode, at least none of the emacs keybindings I usually use seems to work.
  • If I hit Ctrl+D (to quit Octave) the prompt is printed indefinitely until I kill Octave.

After the following changeset, it is possible to open the doc browser, file browser, history browser, workspace viewer, and variable editor from the command line.

Opening the file editor will require a bit more work.

The doc browser works with the “doc” command and the variable editor works with openvar. The others require _event_manager* functions to open.

Using the new terminal widget is not required, but if you are using the new terminal widget, then you can start the desktop from the command line and any open widgets can be docked with the main window. If you close the main window, then any undocked widgets should remain available.

I’m sure there are a bunch of details that are not quite right yet, but these changes seemed like a good enough start to go ahead and push.

1 Like

Really great feature! Just compiled and tested, works perfectly for me :grin: :+1:

I noticed that when launching GUI widgets from the cli, their geometry is not saved/restored. I have posted a bug report :slight_smile: