How to edit code generated with App Designer?

I've started creating a UI using Matlab App Designer (with Matlab 2016b), and I'd like to edit certain parts of the auto-generated code. Let's say, for example, that you want to define your options for a drop down list from a cell passed by the user; or you just want to store them in your properties so that you can use them somewhere else in the code). Is there a way to edit the code (while avoiding the "trick" suggested here ), and not have each option being only entered in a "static" way in App Designer? Thanks.

Answers (3)

Can we at least re-arrange grayed our function blocks for readability?
As far as I am aware the greyed out parts of the automatic code are un-editable. Everything else is editable as normal, although in an editor with considerably less functionality than the main code editor. It is one of the main reasons I don't use the AppDesigner. Hopefully a few Matlab versions down the line it will be less inflexible more usable for non-simple GUIs

3 Comments

Thanks Adam, such a shame as it seemed like a good option for writing UI in Matlab, with the ease-of-use from the GUI and the flexibility from the code ...
Actually, another good reason to be able to edit the auto-generated code would be to fix the bugs in it ... For example correct the callback function comments when you change the name of it, or when you change the callback associated to a component.
Yes, I have had numerous reasons to wish to edit it, e.g. I do OOP all the time in my normal coding and I always call the object itself 'obj'. It can be called anything you like,but I've written probably > 1000 classes, always calling it obj. So being forced to call it 'app' is infuriating for me. It is a small thing maybe, but one of many and when it causes me to be constantly hitting silly errors because I forget and use 'obj' I just don't have time for that kind of inflexible dev environment.
There is a lot I like about it, but the things I don't are just too much.

Sign in to comment.

mafoEV which version of App Designer did you encounter the comment bug? Could you tell me a little more?

3 Comments

I couldn't find the version of App Designer, but I can give you the Matlab version I'm using: 9.1.0.441655 (R2016b).
The issue I've seen can be described as follows:
  • Create a button, called Button1, and its associated callback btnButton1Pushed; this creates the following code:
% Button pushed function: Button1
function btnButton1Pushed(app, event)
[...]
end
  • Create a second button, called Button2, and make its callback the same as Button1 (btnButton1Pushed); this will modify the code above to:
% Button pushed function: Button1, Button2
function btnButton1Pushed(app, event)
[...]
end
  • Now try to change the callback of Button2 to a new one (btnButton2Pushed), which ends up with the following code:
% Button pushed function: Button1, Button2
function btnButton1Pushed(app, event)
[...]
end
% Button pushed function: Button
function btnButton2Pushed(app, event)
[...]
end
It has the right behaviour, but the comments are now confusing ...
Hmm, let me look into this. The format of the comments should be English name of the callback (ie Button pushed or Value Changed): coma separated list of code names of components using this callback. From the sound of it, I would expect your generated code to be:
% Button pushed function: Button1
function btnButton1Pushed(app, event)
[...]
end
% Button pushed function: Button2
function btnButton2Pushed(app, event)
[...]
end
The comments update fine in R2019b. Though I agree some ability to organize greyed out code would be very useful for readability.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 6 Mar 2017

Commented:

on 27 Jan 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!