Comments on: AppDesigner’s mlapp file format https://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format Charting Matlab's unsupported hidden underbelly Sun, 03 Jul 2022 14:46:57 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Bradley Stiritzhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-506997 Mon, 04 Nov 2019 23:13:40 +0000 https://undocumentedmatlab.com/?p=6613#comment-506997 It’s great to see that Yair and others are digging into the internals of AppDesigner. It seems to have a lot of promise. At the same time, AppDesigner is still often unstable and unusable, as of R2019b. I just posted on the running Mathworks Answers thread about this–

https://www.mathworks.com/matlabcentral/answers/279042-app-designer-s-editor-is-slow-and-gets-stuck-alot

Question for anyone who has studied the internals– have you also experienced problems in AppDesigner, and then gained any insights whatsoever via your sleuthing? Do you have any clues or hypotheses about what could be going wrong for so many users?

Surely, after all these years of hard work, the AppDesigner team should have worked out most of the minor bugs..?

]]>
By: Antonio Martinezhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-488521 Tue, 30 Jul 2019 15:07:01 +0000 https://undocumentedmatlab.com/?p=6613#comment-488521 By the way, these are the relevant MATLAB files if someone wants so keep reverse engineering this thing

• C:\Program Files\MATLAB\R2018b\toolbox\matlab\appdesigner\appdesigner\+appdesigner\+internal\+model\AppModel.m
• C:\Program Files\MATLAB\R2018b\toolbox\matlab\appdesigner\appdesigner\+appdesigner\+internal\+codegeneration\+model\CodeModel.m
• C:\Program Files\MATLAB\R2018b\toolbox\matlab\appdesigner\appdesigner\+appdesigner\+internal\+serialization\MLAPPSerializer.m
• C:\Program Files\MATLAB\R2018b\toolbox\matlab\appdesigner\appdesigner\+appdesigner\+internal\+serialization\FileWriter.m

]]>
By: Antonio Martinezhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-488520 Tue, 30 Jul 2019 15:06:06 +0000 https://undocumentedmatlab.com/?p=6613#comment-488520 So, I don’t know if anyone is still reading this comment section but I tried digging a bit more into how MLAPP files are generated, following up Oleg’s contribution.

My conclusion is that, as far as I have been able to reach without basically fully reverse engineering AppDesigner’s inner workings, there is no way to use the methods available in appdesigner.internal such as FileWriter() to generate MLAPP files from the class definition in text format in an M file.

Here’s what I found.

• In newer versions of MATLAB the MLAPP file is organized in pretty much the same way but the appdesigner/appModel.mat file has a different organization. Now the AppData field is deprecated but kept for compatibility, and the data it contained is replace by two new fields ‘code’ and ‘components’. The ‘code’ struct stores the code from the app in separated sections (EditableSectionCode which is the part that contains the methods and properties, Callbacks, StartupCallback, etc), and components stores the UIFigure and the group hierarchy (I have no idea what this is, is generated by the AppModel method getGroupHierarchy() and is way to deep for me too understand already). The groups hierarchy was previusly stored inside appData.metadata.

AppModel: probably the parent for all apps created in AppDesigner is the class appdesigner.internal.model.AppModel . The AppModel contains the save() method, and has the properties Metadata and CodeModel among others. CodeModel is generated from the class appdesigner.internal.codegeneration.model.CodeModel, and contains the different sections of the code.

FileWriter(): as Oleg’s pointed correctly, appdesigner.internal.serialization.FileWriter() is a class that can generate and write to MLAPP files. It has 4 methods (writeMATLABCodeText, writeAppDesignerData, writeAppMetadata, writeAppScreenshot) that have to be called to succesfully contruct an MLAPP file, and can be called from the command line, which would allow using them to generate MLAPP files from its components. The problem is, this components can only be accessed by AppDesigner itself, which renders this methods useless.

Hypothesis for MLAPP file saving: my hypothesis is that when an app is saved, the save() method in the AppModel class is called, which in turn calls the AppModel method writeAppToFile(), which creates an appdesigner.internal.serialization.MLAPPSerializer instance. The AppModel’s method setDataOnSerializer() copies all the required information to MLAPPSerializer, including the code sections, the metadata, group hierarchy, etc. Then, MLAPPSerializer creates a fileWriter instance, divides the different objects received from AppModel and passes them to the relevant fileWriter methods to generate the MLAPP file.

I’m afraid there is literally no way to correctly generate the data scructures that are necessary to reconstruct an MLAPP file from the plain code without putting a ton of hours into untangling all the logic behind AppDesigner. Maybe someone can use this information to take on that task in the future.

]]>
By: Tomhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-423415 Tue, 17 Apr 2018 13:43:15 +0000 https://undocumentedmatlab.com/?p=6613#comment-423415 Thanks for this tutorial. You saved me a ton of work. After Matlab crashed and corrupted my .mlapp file, I was able to unzip the .mlapp file and get to my GUI code and recreate my GUI. Without this, I would be months behind recreating the GUI and rewriting all the code. This website was a lifesaver. Thank you very much.

]]>
By: Oleghttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-403438 Tue, 21 Mar 2017 15:01:21 +0000 https://undocumentedmatlab.com/?p=6613#comment-403438 The following methods load the data:

lf      = appdesigner.internal.serialization.AppLoadingFactory.instance();
 
appData = lf.getAppData('C:\Users\ok1011\Documents\github\carv-realtime-matlab\src\utilities\+carv\+plot\turn.mlapp')
 
  AppData with properties:
 
                   UIFigure: [1×1 Figure]
                   CodeData: [1×1 appdesigner.internal.codegeneration.model.CodeData]
                   Metadata: [1×1 appdesigner.internal.serialization.app.AppMetadata]
                 ToolboxVer: '2016b'
                FullVersion: '9.1.0.441655 (R2016b)'
    MinimumSupportedVersion: 'R2016b'

Or using the file reader, which allows to read Matlab code directly:

fid     = appdesigner.internal.serialization.FileReader('C:\Users\ok1011\Documents\github\carv-realtime-matlab\src\utilities\+carv\+plot\turn.mlapp');
appData = fid.readAppDesignerData();
mcode   = fid.readMATLABCodeText();

The appdesigner.internal.serialization.FileWriter() class allows to write code to the .mlapp file.

]]>
By: Terry Brennanhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-390204 Fri, 07 Oct 2016 15:15:24 +0000 https://undocumentedmatlab.com/?p=6613#comment-390204 Why not use class inheritance to achieve your goals? As for working programmatically, one of the things I like about the app designer is that the resulting mlapp file defines a class so I can derive other classes from the gui-created class and work programmatically without the visual interface on the derived class. One can add components, modify properties etc. One can even declare methods and/or properties in the mlapp to be Abstract within the appdesigner. This allows the creation of a base class from which customizations can be derived.

For example if I have a working appGUI.mlapp I can create

classdef myAppGUI < appGUI
   properties
      NewButton matlab.ui.control.Button
   end
   methods
      function A = myAppGUI
         % A = A@appGUI; <-- usually not necessary
         A.NewButton = uibutton(A.UIFigure);
         A.NewButton.Position = [20 20 100 22];
      end
   end
end

To assist you in recalling component names, etc, while programming the derived class you can have an instance of the base class (if it is not Abstract) in the workspace

>> Base = appGUI;

to interrogate its methods and properties. This is almost as good as having the appGUI code.

Of course, this approach should not become obsolete, unless the MathWorks does something dumb like making mlapp classes Sealed.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-385904 Wed, 17 Aug 2016 18:40:51 +0000 https://undocumentedmatlab.com/?p=6613#comment-385904 Thanks for this – I believe that a guest post about your experience with customizing uifigures using CSS would be highly appreciated by readers. Care to give it a shot? Send me an email to discuss the technical details

]]>
By: Dev-iLhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-385902 Wed, 17 Aug 2016 18:34:46 +0000 https://undocumentedmatlab.com/?p=6613#comment-385902 I’d like to point out one of the things we found while making the tool that Sam had mentioned: .mlapp -> .m conversion can very easily be done using the built-in function type (docs). The earliest MATLAB version where it worked (out of those we collectively had access to) was 2014b.
Regarding the customization of .mlapp figures – the fact they’re webpages might actually be beneficial for customization, as UI elements can now be customized using CSS. I have explored this a bit and made a small demonstration after reading your “Customizing uifigures part 1” post. (Thanks!)

]]>
By: Samhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-385896 Wed, 17 Aug 2016 17:23:41 +0000 https://undocumentedmatlab.com/?p=6613#comment-385896 Forgot the GH link: https://github.com/StackOverflowMATLABchat/mlapp2classdef

]]>
By: Samhttps://undocumentedmatlab.com/blog_old/appdesigner-mlapp-file-format#comment-385893 Wed, 17 Aug 2016 17:19:48 +0000 https://undocumentedmatlab.com/?p=6613#comment-385893 Though not quite the same as what you’re envisioning, there’s a proof of concept implementation of *.mlapp -> *.m classdef on FEX (http://www.mathworks.com/matlabcentral/fileexchange/56237-mlapp2classdef).

It’s a pretty basic thing thrown together so I could use AppDesigner’s layout tools and get a programmatic GUI out of it, which is my preferred GUI medium. It also attempts to strip the new UI elements out in favor of the “traditional” ones so I could work with older versions of MATLAB.

]]>