Yet another GUI Builder for Octave

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Yet another GUI Builder for Octave

marcalexandre
Hi all,

I really like Octave but I think it is short of one thing that seems to me very important, a GUI Builder like GUIDE for Matlab.
Of course it is possible to manually code the script to generate the GUI but it is going to be very tedious when the GUI has many elements.

I've got an idea to automatically generate that script, and I have successfully implemented it.

The idea is, in a first approach, to use a generic GUI Builder, Glade, and parse the glade file to generate the equivalent m-file, in the same way like GUIDE.
The parsing of the glade file consists in extracting all the widgets used and their properties (Style, Tag, Position, Callbacks, etc.) and make a correspondence with the different GUI objects already available in Octave (uicontrol, uipanel, axes, etc.). For example :
- Glade : GtkButton / Octave : uicontrol('Style', 'pushbutton')
- Glade : GtkEntry / Octave : uicontrol('Style', 'edit')
- Glade : GtkLabel / Octave : uicontrol('Style', 'text')
- Glade : GtkDrawingArea / Octave : axes(...)

For the callbacks, there are also similarities between available Octave Callbacks and Glade Callbacks.

I have already successfully convert some simple glade files to m-files. Then you just have to code the callback functions. You can find below, screenshots representing the GUI in Glade and its automatically-generated equivalent Octave GUI as well as the generated code (test3.m for writing callbacks and test3_gui.m for GUI creation).

What do you think about that ? Is there already something similar ? Is someone interested in ? I will be happy to share the code and ideas if needed.

test3.m
test3_gui.m
Glade_GUI.png
Octave_GUI.png
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

LachlanA
Marc,

Generating GUIs from glade sounds like a great idea (although I'm not personally interested in using it).

It would be great if you could post the code as a patch on Savannah. [https://savannah.gnu.org/patch/?func=additem&group=octave].

One potential trouble will be with callbacks.  In Matlab, callbacks are typically handles to nested functions, so that they can access shared variables.  Octave currently can't take handles of nested functions.  I wrote a simple patch at [https://savannah.gnu.org/bugs/index.php?39257] that allows handles to be taken of nested functions.  It lets me make a simple GUI, but it is not stable enough to be put into production yet.  (It can crash Octave if the GUI terminates abnormally, such as by ^C or a code error.)

Cheers,
Lachlan
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

LachlanA
In reply to this post by marcalexandre
Marc,

I forgot to ask: Why did you use the subject "yet another..."?  If you know of existing GUI builders for Octave, why do you need to take this approach?

Cheers,
Lachlan
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

marcalexandre
Hi Lachlan,
First of all, thanks for your reply and your thoughts about my suggestion.

In fact, I know there is something called Octave-Gtk which also allow to make GUIs but it uses a complete different way and seems to be unmaintained right now.
With Octave-Gtk the user has to code its GUI using all the Gtk stuffs, which can be quite complicated.
The method I propose is, as you can see, very simple as the user just have to code its GUI with the Octave syntax.

I also don't understand your comment about the callbacks.
I have successfully coded callbacks with my GUI Builder and it worked great. I don't understand the problem you explained about shared variables. For me there is no problem with it. Did you get a look at the attached files ? Am I missing something ?

Cheers,

Marc Alexandre K.
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

John Swensen-3
In reply to this post by LachlanA

On Jul 13, 2016, at 7:17 PM, LachlanA <[hidden email]> wrote:

Marc,

Generating GUIs from glade sounds like a great idea (although I'm not
personally interested in using it).

It would be great if you could post the code as a patch on Savannah.
[https://savannah.gnu.org/patch/?func=additem&group=octave].

One potential trouble will be with callbacks.  In Matlab, callbacks are
typically handles to nested functions, so that they can access shared
variables.  Octave currently can't take handles of nested functions.  I
wrote a simple patch at [https://savannah.gnu.org/bugs/index.php?39257] that
allows handles to be taken of nested functions.  It lets me make a simple
GUI, but it is not stable enough to be put into production yet.  (It can
crash Octave if the GUI terminates abnormally, such as by ^C or a code
error.)

Cheers,
Lachlan


This may be a great GSoC project for next year. A while ago, I had been wondering what the actual file format of a Matlab .fig file actually is. Their GUI builder GUIDE only outputs a .fig file and an associated .m file. When researching this, I found a website that indicates that .fig file are really just .mat files that store the entire handle hierarchy for the figure

So, there would be 2 subtasks:
1) Get the .fig import/export as specialized .mat files working
2) Make a QT interface to layout GUIs and generate the associated .fig and .m files

It may be too much for one GSoC, but it might be possible to have one students on each of those subtasks.

John S.
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

John W. Eaton
Administrator
In reply to this post by marcalexandre
This looks great and I think there would be a lot of interest.

Maybe Glade could eventually be modified to work with Octave directly?
OTOH, parsing the output may work well enough that modifying Glade is
not necessary?

jwe


On 07/13/2016 10:54 AM, marcalexandre wrote:

> Hi all,
>
> I really like Octave but I think it is short of one thing that seems to me
> very important, a GUI Builder like GUIDE for Matlab.
> Of course it is possible to manually code the script to generate the GUI but
> it is going to be very tedious when the GUI has many elements.
>
> I've got an idea to automatically generate that script, and I have
> successfully implemented it.
>
> The idea is, in a first approach, to use a generic GUI Builder, Glade, and
> parse the glade file to generate the equivalent m-file, in the same way like
> GUIDE.
> The parsing of the glade file consists in extracting all the widgets used
> and their properties (Style, Tag, Position, Callbacks, etc.) and make a
> correspondence with the different GUI objects already available in Octave
> (uicontrol, uipanel, axes, etc.). For example :
> - Glade : GtkButton / Octave : uicontrol('Style', 'pushbutton')
> - Glade : GtkEntry / Octave : uicontrol('Style', 'edit')
> - Glade : GtkLabel / Octave : uicontrol('Style', 'text')
> - Glade : GtkDrawingArea / Octave : axes(...)
>
> For the callbacks, there are also similarities between available Octave
> Callbacks and Glade Callbacks.
>
> I have already successfully convert some simple glade files to m-files. Then
> you just have to code the callback functions. You can find below,
> screenshots representing the GUI in Glade and its automatically-generated
> equivalent Octave GUI as well as the generated code (test3.m for writing
> callbacks and test3_gui.m for GUI creation).
>
> What do you think about that ? Is there already something similar ? Is
> someone interested in ? I will be happy to share the code and ideas if
> needed.
>
> test3.m <http://octave.1599824.n4.nabble.com/file/n4678450/test3.m>
> test3_gui.m <http://octave.1599824.n4.nabble.com/file/n4678450/test3_gui.m>
> Glade_GUI.png
> <http://octave.1599824.n4.nabble.com/file/n4678450/Glade_GUI.png>
> Octave_GUI.png
> <http://octave.1599824.n4.nabble.com/file/n4678450/Octave_GUI.png>
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/Yet-another-GUI-Builder-for-Octave-tp4678450.html
> Sent from the Octave - Maintainers mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

Mike Miller-4
In reply to this post by marcalexandre
On Thu, Jul 14, 2016 at 06:18:56 -0700, marcalexandre wrote:

> Hi Lachlan,
> First of all, thanks for your reply and your thoughts about my suggestion.
>
> In fact, I know there is something called Octave-Gtk which also allow to
> make GUIs but it uses a complete different way and seems to be unmaintained
> right now.
> With Octave-Gtk the user has to code its GUI using all the Gtk stuffs, which
> can be quite complicated.
> The method I propose is, as you can see, very simple as the user just have
> to code its GUI with the Octave syntax.

Have you also looked at Qt's .ui file syntax? I wonder if something
similar could be done for GUIs made with Qt Creator (also an XML
format). I have used the pyuic tool before, for example, that parses .ui
files into Python (although directly using PyQt of course).

Not trying to put extra work on you, just another thought. Maybe a tool
could be written to import both .glade and .ui files and write .m files.

> I also don't understand your comment about the callbacks.
> I have successfully coded callbacks with my GUI Builder and it worked great.
> I don't understand the problem you explained about shared variables. For me
> there is no problem with it. Did you get a look at the attached files ? Am I
> missing something ?

Lachlan is talking about nested functions, which are different from
subfunctions. Your posted example uses subfunctions, or what Matlab
calls "local functions" (functions in the same .m file declared *after*
the endfunction). Handles to nested functions are currently not
implemented in Octave. So Lachlan's point is you would not currently be
able to do something like this

  function rungui ()
    x = 0;
    y = 0;

    gui_func (...)

    function callback1 ()
      x = x + 1;
    endfunction

    ...

  endfunction

Definitely an interesting start you have here. I think leveraging
existing GUI builders and mapping their outputs to Octave widget
functions is an excellent approach.

--
mike

Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

Andreas Weber-6
In reply to this post by marcalexandre
Am 13.07.2016 um 16:54 schrieb marcalexandre:
> The idea is, in a first approach, to use a generic GUI Builder, Glade, and
> parse the glade file to generate the equivalent m-file, in the same way like
> GUIDE.

Nice. Interesting approach. I also thought about creating a GUI builder
and was playing with the ui* function the last days
(http://www.zimagez.com/zimage/bildschirmfoto-10072016-222917.php).

My idea was to build the GUI-builder directly in Octave with ui*
functions so I'm able to move objects, change color, font and so on and
immediately see the change. And there wouldn't be a need for another
parser/converter.

Have you found documentation about Matlabs intermediate data structures?
John linked http://undocumentedmatlab.com/blog/fig-files-format

My point of building the GUI-builder within Octave was:
* using them extensively will uncover bugs and missing features
* platform independent (would also run on windoze, the typical user
might have problems installing glade on it)
* WYSIWYG

What do you think?

-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

nrjank
On Fri, Jul 15, 2016 at 6:28 AM, Andreas Weber <[hidden email]> wrote:
Am 13.07.2016 um 16:54 schrieb marcalexandre:
My point of building the GUI-builder within Octave was:
* using them extensively will uncover bugs and missing features
* platform independent (would also run on windoze, the typical user
might have problems installing glade on it)
* WYSIWYG

What do you think?

-- Andy



As a mostly-windows user I'd agree with this notion. Just lightly following the earlier discussion, I had assumed that the resulting product might look like an OF package or similar, or support such (like how symbolic has an embedded python version). 
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

marcalexandre
Wow,
I see a lot of interest for this project.
So first of all, sorry the my late response.

@John Eaton,
In fact, it's where I really want to go with this project. Modify Glade to directly support Octave as it is an open source GUI builder.
For the moment, I just took little time to see if the first idea was doable.
I think at the moment, I will continue to push this way, I mean parsing glade files (adding support of uipanels and uibuttongroups) as it is less complicated, before switching to modifying Glade. Being able to modify Glade could pave the way for something even greater, a block diagram environment for model-based design (as you can find in over non-free tools). But that's another story.

@John Swensen,
I also though about that but didn't find documents about .fig files. I got a look at the link you gave above and also loaded some .fig files and that sounds great.
I think the approach I adopt (*_gui.m for GUI creation and *.m for callbacks) is quite the same as the Matlab approach with the .fig file equivalent to the *_gui.m file). But I recognize that being able to read .fig files will definitely increase Matlab Compatibility even if the approach I used is also Matlab compatible. I am not a Qt expert so I would consider adding .fig files import/export. Great idea and very useful link through.

@Mike Miller,
Yes that could also be great. It will leave the user the freedom to use his preferred GUI Builder.
I didn't have a look at Qt ui syntax yet, but in that sens, the idea could be to create a kind of "correspondence table" associating Qt, Glade or whatever GUI Builder syntax keywords to the corresponding Octave ui* function.
Thanks also for your explanations about shared variables. I still think that for callbacks, we are not obliged to use nested functions. Sub-functions also work great. Am I wrong or missing something ?

@Andreas Weber, @NJank
I think the main complexity of this approach is that it's a lot of work to do to create the interface of the Builder, manage widgets drag & drop, get the position of the widget on the frame, etc. I am not an Octave expert, I mean I don't know how Octave really work deeply underhood, so maybe it's not so complicated as I think. Have you already got an idea about how to manage all these stuffs ?
Now regarding Glade, the main reason I chose it, is that it is available on all operating systems (Windows, Linux, Mac). Windows and Mac versions are not the newest ones, but work great. In fact, I use Glade for windows to test my idea. It is a very small software (~16 MB) and is installed very quickly on Win without any requirements.

---
If many people are interested in, maybe we could work together to define a right way to do it. Then create a project and work on it as, in my opinion, it could be a major addition to Octave and could increase compatibility with Matlab as well as attractiveness.
I will share the code no latter than the end of this week through the link given by Lachlan.

Cheers,

Marc Alexandre K.
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

Mike Miller-4
On Fri, Jul 15, 2016 at 09:35:24 -0700, marcalexandre wrote:
> Wow,
> I see a lot of interest for this project.

Yes, very good work, if I didn't say so before.

So do you have a code repository hosted somewhere yet for people to try
this out? Would you like help setting something up? I wonder if
developing it separately for a while might be better than posting a code
dump on the patch tracker. But no harm in doing either or both.

> @Mike Miller,
> Yes that could also be great. It will leave the user the freedom to use his
> preferred GUI Builder.
> I didn't have a look at Qt ui syntax yet, but in that sens, the idea could
> be to create a kind of "correspondence table" associating Qt, Glade or
> whatever GUI Builder syntax keywords to the corresponding Octave ui*
> function.

Yes exactly.

> Thanks also for your explanations about shared variables. I still think that
> for callbacks, we are not obliged to use nested functions. Sub-functions
> also work great. Am I wrong or missing something ?

No, you are not wrong. Lachlan's assertion was that nested functions are
commonly used in Matlab to implement such callbacks. I can't say wheher
that is true or not, but the scoping behavior with nested functions is
an advantage. With subfunctions the user might have to use global
workspace variables to share state.

I wouldn't consider the lack of handles to nested functions to be a
blocker.

> Now regarding Glade, the main reason I chose it, is that it is available on
> all operating systems (Windows, Linux, Mac). Windows and Mac versions are
> not the newest ones, but work great. In fact, I use Glade for windows to
> test my idea. It is a very small software (~16 MB) and is installed very
> quickly on Win without any requirements.

Qt Creator is also available on all of the above operating systems.

--
mike

Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

Patrick Noffke
In reply to this post by Andreas Weber-6


On Fri, Jul 15, 2016 at 5:28 AM, Andreas Weber <[hidden email]> wrote:
Am 13.07.2016 um 16:54 schrieb marcalexandre:
> The idea is, in a first approach, to use a generic GUI Builder, Glade, and
> parse the glade file to generate the equivalent m-file, in the same way like
> GUIDE.

Nice. Interesting approach. I also thought about creating a GUI builder
and was playing with the ui* function the last days
(http://www.zimagez.com/zimage/bildschirmfoto-10072016-222917.php).

My idea was to build the GUI-builder directly in Octave with ui*
functions so I'm able to move objects, change color, font and so on and
immediately see the change. And there wouldn't be a need for another
parser/converter.


It's possible the entire Qt Designer (the UI "builder" tool embedded in Qt Creator) is a plugin that you could embed within the Octave GUI.  I see in my Qt install there is a libDesigner shared library under the plugins directory:
~/Qt/Tools/QtCreator/lib/qtcreator/plugins/

The Designer would produce the .ui (XML) files.  Qt Creator has the ability to navigate to source code from the designer (i.e. go to a slot (and add one if it doesn't exist)).  Might be worth looking at how that is done for round-trip-editing .m files associated with a GUI file.

FWIW you can run the Qt Designer in stand-alone mode to strictly edit the .ui files.  I suspect in that case the Designer application is a very thin wrapper around the plugin.

Pat
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

LachlanA
In reply to this post by Mike Miller-4
Mike Miller-4 wrote
On Fri, Jul 15, 2016 at 09:35:24 -0700, marcalexandre wrote:
> I still think that
> for callbacks, we are not obliged to use nested functions. Sub-functions
> also work great. Am I wrong or missing something ?

No, you are not wrong. Lachlan's assertion was that nested functions are
commonly used in Matlab to implement such callbacks. I can't say whether
that is true or not, but the scoping behavior with nested functions is
an advantage.

I wouldn't consider the lack of handles to nested functions to be a
blocker.
My reason for saying that it is "common" is that I believe that GUIDE produces code that uses nested functions, and that the Matlab how-to uses them.  I agree that it is not necessary to use them, and the lack of handles is certainly not a blocker.  It was just a heads-up.

Cheers,
Lachlan
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

marcalexandre
Hello everyone.

Here is the code for the parser and GUI files generator.
There are just two Octave scripts :
 - parse_glade.m : parse glade file and return 2 structures, one for window properties and another one for the widgets found in the .glade file.
 - glade2m : the main file, call parse_glade() and write the corresponding Octave scripts accordingly.

For the moment, it uses the xmlread function from the Octave-forge IO package to read the glade file and access the different nodes.

It generate two files :
 - xxx_gui.m, for GUI creation.
 - xxx.m, the main file, calling xxx_gui() for GUI creation and where the user writes his callbacks functions.

I will publish soon a small document to explain how to correctly set the widgets in Glade.

@Mike Miller
I will continue to develop it to add more features, but anyone help or question would be greatly appreciated.
Regarding Qt, is it also open source ? I am not sure about this point. And it looks like something really big compare to Glade. As I said before, the real goal I want to attain is to modify an open source GUI Builder to make it directly compliant with Octave UI elements.

@Patrick Noffke
I will definitely have a look at it. Thanks.

@Lachlan
It's more clear now. I thought you said it was mandatory to do it that way. Sorry for the misunderstanding.
Reply | Threaded
Open this post in threaded view
|

Re: Yet another GUI Builder for Octave

tmacchant
----- Original Message -----

> From: marcalexandre 
> To: octave-maintainers> Cc:
> Date: 2016/7/18, Mon 07:46
> Subject: Re: Yet another GUI Builder for Octave
>
> Hello everyone.
>
> Here is the code for the parser and GUI files generator.
> <https://drive.google.com/folderview?id=0B6o7ilt-fzrhNXFEcjFlSzhnSlE&usp=sharing
>
> There are just two Octave scripts :
> - parse_glade.m : parse glade file and return 2 structures, one for window
> properties and another one for the widgets found in the .glade file.
> - glade2m : the main file, call parse_glade() and write the corresponding
> Octave scripts accordingly.
>
> For the moment, it uses the xmlread function from the Octave-forge IO
> package to read the glade file and access the different nodes.
>
> It generate two files :
> - xxx_gui.m, for GUI creation.
> - xxx.m, the main file, calling xxx_gui() for GUI creation and where the
> user writes his callbacks functions.
>
> I will publish soon a small document to explain how to correctly set the
> widgets in Glade.
>
> @Mike Miller
> I will continue to develop it to add more features, but anyone help or
> question would be greatly appreciated.
> Regarding Qt, is it also open source ? I am not sure about this point. 


I am not Mike. :)

There are open source QT (for open source use : GNU GPL[3] 3.0, with Qt special exception) 
and non-open source QT (for commercial use).
 
Octave uses of course open source licensed QT.

Tatsuro
>