Skip to content
This repository was archived by the owner on Nov 25, 2018. It is now read-only.

Commit fa6d7c4

Browse files
committed
Add baseline support for UI object conversion
See: #6
1 parent 04e4d71 commit fa6d7c4

File tree

2 files changed

+61
-19
lines changed

2 files changed

+61
-19
lines changed

Readme.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,26 @@ MLAPP2CLASSDEF assumes that the targeted `*.mlapp` file is a GUI created by MATL
4040

4141
Structure of the packaged `*.mlapp` file is assumed to be a constant (e.g. `~\matlab\document.xml` is the path to the class definition XML)
4242

43-
Replacement of App Designer specific GUI elements with their "regular" MATLAB equivalents is a work in progress. See the below table for a description of UI element support.
43+
Replacement of App Designer specific GUI elements with their "regular" MATLAB equivalents is a work in progress. See the below table for a description of UI element support. Conversion does not take into account object properties introduced in R2016a.
4444

4545
UI Element | App Designer Function | "Regular" MATLAB Function | Conversion Supported | Caveats
46-
:-----------: | :-------------------: | :----------------------------------: | :------------------: | :-----:
47-
Figure | `uifigure` | `figure` | No | N/A
48-
Axes | `uiaxes` | `axes` | No | N/A
49-
Button | `uibutton` | `uicontrol('Style', 'pushbutton')` | No | N/A
50-
Checkbox | `uicheckbox` | `uicontrol('Style', 'checkbox')` | No | N/A
51-
Edit Box | `uieditfield` | `uicontrol('Style', 'edit')` | No | N/A
52-
Text Label | `uilabel` | `uicontrol('Style', 'text')` | No | N/A
53-
List Box | `uilistbox` | `uicontrol('Style', 'listbox')` | No | N/A
54-
Radio Button | `uiradiobutton` | `uicontrol('Style', 'radiobutton')` | No | N/A
55-
Slider | `uislider` | `uicontrol('Style', 'slider')` | No | N/A
56-
Toggle Button | `uitogglebutton` | `uicontrol('Style', 'togglebutton')` | No | N/A
46+
:------------ | :-------------------- | :----------------------------------- | :------------------: | :------
47+
Figure | `uifigure` | `figure` | Yes | Does not modify any input parameters
48+
Axes | `uiaxes` | `axes` | Yes | Does not modify any input parameters
49+
Button | `uibutton` | `uicontrol('Style', 'pushbutton')` | Yes | Modifies inputs, assumes only App Designer input is parent object
50+
Checkbox | `uicheckbox` | `uicontrol('Style', 'checkbox')` | Yes | Modifies inputs, assumes only App Designer input is parent object
51+
Edit Box | `uieditfield` | `uicontrol('Style', 'edit')` | Yes | Modifies inputs, assumes only App Designer input is parent object
52+
Text Label | `uilabel` | `uicontrol('Style', 'text')` | Yes | Modifies inputs, assumes only App Designer input is parent object
53+
List Box | `uilistbox` | `uicontrol('Style', 'listbox')` | Yes | Modifies inputs, assumes only App Designer input is parent object
54+
Radio Button | `uiradiobutton` | `uicontrol('Style', 'radiobutton')` | Yes | Modifies inputs, assumes only App Designer input is parent object
55+
Slider | `uislider` | `uicontrol('Style', 'slider')` | Yes | Modifies inputs, assumes only App Designer input is parent object
56+
Toggle Button | `uitogglebutton` | `uicontrol('Style', 'togglebutton')` | Yes | Modifies inputs, assumes only App Designer input is parent object
5757
Spinner | `uispinner` | N/A | No | N/A
5858
Text Area | `uitextarea` | N/A | No | N/A
5959
Gauge | `uigauge` | N/A | No | N/A
6060
Knob | `uiknob` | N/A | No | N/A
6161
Lamp | `uilamp` | N/A | No | N/A
6262
Switch | `uiswitch` | N/A | No | N/A
6363
UI Alert | `uialert` | N/A | No | N/A
64+
65+
Converted GUIs will likely still require MATLAB R2014b and newer. MATLAB's App Designer heavily utilizes the dot notation for accessing properties of UI elements rather than using `set` and `get`. See [Graphics Handles Are Now Objects, Not Doubles](http://www.mathworks.com/help/matlab/graphics_transition/graphics-handles-are-now-objects-not-doubles.html) for more information.

mlapp2classdef.m

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,52 @@ function writemfile(mymcode, pathname, appname)
238238

239239
function [regexdict] = genregexdict()
240240
% Build structure of regular expressions to swap function calls
241-
regexdict.Figure.expression = 'uifigure';
242-
regexdict.Figure.replace = 'figure';
243241

244-
regexdict.Axes.expression = 'uiaxes';
245-
regexdict.Axes.replace = 'axes';
246-
247-
regexdict.Axes.expression = 'uiaxes';
248-
regexdict.Axes.replace = 'axes';
242+
% Replace uifigure with figure, make no changes to function inputs
243+
regexdict.figureObj.expression = 'uifigure';
244+
regexdict.figureObj.replace = 'figure';
245+
246+
% Replace uiaxes with axes, make no changes to function inputs
247+
regexdict.axesObj.expression = 'uiaxes';
248+
regexdict.axesObj.replace = 'axes';
249+
250+
% Replace uibutton with pushbutton uicontrol, assume only UIfunction input
251+
% is the parent object
252+
regexdict.pushbuttonObj.expression = '(uibutton)\((.*)\)';
253+
regexdict.pushbuttonObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''pushbutton'')';
254+
255+
% Replace uicheckbox with checkbox uicontrol, assume only UIfunction input
256+
% is the parent object
257+
regexdict.checkboxObj.expression = '(uicheckbox)\((.*)\)';
258+
regexdict.checkboxObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''checkbox'')';
259+
260+
% Replace uieditfield with edit uicontrol, assume only UIfunction input is
261+
% the parent object
262+
regexdict.editboxObj.expression = '(uieditfield)\((.*)\)';
263+
regexdict.editboxObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''edit'')';
264+
265+
% Replace uilabel with text uicontrol, assume only UIfunction input is the
266+
% parent object
267+
regexdict.textObj.expression = '(uilabel)\((.*)\)';
268+
regexdict.textObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''text'')';
269+
270+
% Replace uilistbox with listbox uicontrol, assume only UIfunction input
271+
% is the parent object
272+
regexdict.listboxObj.expression = '(uilistbox)\((.*)\)';
273+
regexdict.listboxObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''listbox'')';
274+
275+
% Replace uiradiobutton with radiobutton uicontrol, assume only UIfunction
276+
% input is the parent object
277+
regexdict.radiobuttonObj.expression = '(uiradiobutton)\((.*)\)';
278+
regexdict.radiobuttonObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''radiobutton'')';
279+
280+
% Replace uislider with slider uicontrol, assume only UIfunction input is
281+
% the parent object
282+
regexdict.siderObj.expression = '(uislider)\((.*)\)';
283+
regexdict.sliderObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''slider'')';
284+
285+
% Replace uitogglebutton with pushbutton uicontrol, assume only UIfunction
286+
% input is the parent object
287+
regexdict.togglebuttonObj.expression = '(uitogglebutton)\((.*)\)';
288+
regexdict.togglebuttonObj.replace = 'uicontrol(''Parent'', $2, ''Style'', ''togglebutton'')';
249289
end

0 commit comments

Comments
 (0)