bugGNU Octave - Bugs: bug #44282, 'gui_mainfcn' undefined


bug #44282: 'gui_mainfcn' undefined

Submitted by:  Austin English <austin987>
Submitted on:  Tue 17 Feb 2015 03:47:27 AM UTC  
Category:  GUI Severity:  3 - Normal
Priority:  1 - Later Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Fri 13 Dec 2019 08:33:51 PM UTC, comment #14: 

Thanks again for your contribution.
I added a few comments and pushed your changeset here:

The guide figure from bug #57212 now opens without errors for me.

Marking as ready for test.

Markus Mützel <mmuetzel>
Project Member
Thu 12 Dec 2019 07:40:29 PM UTC, comment #13: 

Savannah seems to have issues lately. I can't download the patch: "No access to the file."

Markus Mützel <mmuetzel>
Project Member
Wed 11 Dec 2019 01:05:42 PM UTC, comment #12: 

I attach a changeset. As discussed, the manual is not updated and the new function is not listed explicitly in the NEWS file.

(file #48045)

Guillaume <gyom>
Tue 10 Dec 2019 12:25:04 PM UTC, comment #11: 

To be honest, I don't know the distinguishing features between files in scripts/plot/util and scripts/gui. Whichever folder you decide is good with me. The file can still be moved in the future if someone has a strong feeling about it.

You are right. Maybe we don't want to include its doc string in the manual.
Maybe the doc string should also be clearer about that this function is purely for compatibility with Matlab guide GUIs. Users shouldn't use it when they develop new code.

Markus Mützel <mmuetzel>
Project Member
Tue 10 Dec 2019 11:38:00 AM UTC, comment #10: 

On a second thought, perhaps it would be best in scripts/plot/util as it can be perceived as an helper function to openfig.

I will prepare a changeset but I wonder how much it should be advertised given that it's an undocumented function, implemented for the sake of compatibility with Matlab functions generated with Guide.

Guillaume <gyom>
Sun 08 Dec 2019 04:49:44 PM UTC, comment #9: 

I'm also undecided on where to best add that file. Maybe I'd slightly prefer scripts/gui...

Could you please prepare a complete changeset including commit message, adding the doc string to the manual, changes to the NEWS file, _unimplemented_.m, module.mk,...?

Markus Mützel <mmuetzel>
Project Member
Mon 18 Nov 2019 03:43:56 PM UTC, comment #8: 

I am also confused with the two comments - I would leave the code as it is and we can revisit it if someone provides an example with Matlab behavior.

I attach a new file with copyright. Not sure if the function should go in scripts/plot/util (openfig, hgload, struct2hdl) or in scripts/gui (gui*, ui*).

(file #47881)

Guillaume <gyom>
Mon 18 Nov 2019 12:03:39 PM UTC, comment #7: 

You are right. But there is also this comment in TestGUI_OpeningFcn in the file from bug #57212:

% UIWAIT makes TestGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);

To be honest, I don't know what to make out of these contradicting comments. If that function (with "uiwait") is executed before the figure is set to visible, it would remain invisible until it is closed (or uiresume is called), wouldn't it?
Also in that case, the handles might become invalid which we should probably check for, too.
It might also be that I misunderstand the sequence in which the functions are executed in that case...

Imho, it's ok to leave the documentation as short as it is right now.

We usually include a copyright holder for all files. Do you want to add your name?

Markus Mützel <mmuetzel>
Project Member
Mon 18 Nov 2019 10:41:53 AM UTC, comment #6: 

Thanks Markus, your link was useful and I also found an example of the use of gui_LayoutFcn here:


I open the figure as invisible first because of the comment saying that "OpeningFcn is executed just before the figure is made visible". Am I misunderstanding this part?

I attach an updated version of the file. I guess this function should be left undocumented in Octave so I don't know how much comment there should be.

(file #47880)

Guillaume <gyom>
Sat 16 Nov 2019 05:58:24 PM UTC, comment #5: 

Thanks for this contribution.
I don't think we need full feature compatibility before we add that function. A partial implementation is fine imho - especially taking into account that we would probably need a lot of user feedback to get everything right for this undocumented function.

One note:
Why do you open the figure invisible? Considering that gui_OpeningFcn may block with "uiwait", it might be too late to set "visible" to "on" in the current draft version.

Here a resource which might be useful:

Markus Mützel <mmuetzel>
Project Member
Thu 14 Nov 2019 12:01:18 PM UTC, comment #4: 

Using the example files from bug #57212 and another one of my own, here is an attempt at implementing gui_mainfcn.m:

function varargout = gui_mainfcn (gui_State, varargin)
  if (nargin == 1 || isempty (gui_State.gui_Callback))
    filename = file_in_loadpath ([gui_State.gui_Name ".fig"]);
    copies = ifelse (gui_State.gui_Singleton, "reuse", "new");
    H = openfig (filename, copies, "invisible");
    for i = 1:2:numel (varargin)
        set (H, varargin{i}, varargin{i+1});
    handles = guihandles (H);
    guidata (H, handles);
    feval (gui_State.gui_OpeningFcn, H, [], handles, varargin{:});
    set (H, "Visible", "on");
    handles = guidata (H);
    varargout{1} = feval (gui_State.gui_OutputFcn, H, [], handles);
    [varargout{1:nargout}] = feval (gui_State.gui_Callback, varargin{2:end});

I think it is already usable in many situations. Issues I am aware of are:

  • gui_LayoutFcn is not implemented.
  • if the GUIDE-generated function is called with ('Visible','off'), it will not be used.
  • unclear whether getappdata should be used (and where/how?).

Is there any chance this could be added to Octave 6 even if partially incomplete? Getting more feedbacks would allow to figure out the missing bits.

Guillaume <gyom>
Tue 12 Nov 2019 05:42:06 PM UTC, comment #3: 

It seems that GUIDE is now deprecated in Matlab:
so, good news, one less thing to worry about, and, bad news, there is now App Designer!
Implementing a compatible gui_mainfcn.m is a much more achievable goal.

Guillaume <gyom>
Fri 26 May 2017 07:28:18 PM UTC, comment #2: 

Duplicating the GUI generator would be a huge task.
Allowing Matlab-generated GUI code to run should be less so.
GUI programs are very useful in providing interactive control of models and presentations.

Morris Maynard <mozzis>
Tue 17 Feb 2015 03:44:21 PM UTC, comment #1: 

This function is apparently something that is used by GUIDE-generated GUIs.  I'm marking this as a feature request with a low priority.  Unless someone wants to take on the enormous task of providing GUIDE-like functionality for Octave, I think it is highly unlikely that it will be implemented any time soon.

John W. Eaton <jwe>
Project Administrator
Tue 17 Feb 2015 03:47:27 AM UTC, original submission:  


error: 'gui_mainfcn' undefined near line 42 column 5
error: called from:
error:   /home/austin/matlab/DATMeT.m at line 42, column 5


trying to run a matlab project, the code snippet:
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    gui_mainfcn(gui_State, varargin{:});

There are various reports online about this affecting others, e.g., http://octave.1599824.n4.nabble.com/gui-mainfcn-not-defined-error-td4647545.html, but I couldn't find a bug report for it.

I also checked out the source from mercurial, which also has the same issue.

Austin English <austin987>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #48045:  bug44282.diff added by gyom (3KiB - text/x-patch)
file #47881:  gui_mainfcn.m added by gyom (2KiB - text/x-matlab)
file #47880:  gui_mainfcn.m added by gyom (2KiB - text/x-matlab)


Depends on the following items: None found

   bug dependencies.


Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by gyom (Posted a comment)
  • -email is unavailable- added by gyom
  • -email is unavailable- added by mozzis (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by austin987 (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 15 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-01-04 rik5 StatusReady For Test => Fixed
        Open/ClosedOpen => Closed
    2019-12-13 mmuetzel StatusIn Progress => Ready For Test
    2019-12-11 gyom Attached File- => Added bug44282.diff, #48045
    2019-12-08 mmuetzel StatusConfirmed => In Progress
    2019-11-18 gyom Attached File- => Added gui_mainfcn.m, #47881
    2019-11-18 gyom Attached File- => Added gui_mainfcn.m, #47880
    2019-11-16 mmuetzel Dependencies- => bugs #57212 is dependent
    2019-11-14 rik5 Carbon-CopyRemoved 72865 => -
    2018-04-20 gyom Carbon-Copy- => Added gyom
    2015-11-25 rik5 StatusNone => Confirmed
    2015-02-17 jwe Priority5 - Normal => 1 - Later
        Item GroupMatlab Compatibility => Feature Request
        Release3.8.2 => dev
        Operating SystemGNU/Linux => Any

    Back to the top

    Powered by Savane 3.5