- Undocumented Matlab - https://undocumentedmatlab.com -
copyobj behavior change in HG2
Posted By Yair Altman On May 13, 2015 | No Comments
As a followup to last-week’s post on class-object and generic data copies, I would like to welcome back guest blogger Robert Cumming, who developed a commercial Matlab GUI framework [1]. Today, Robert will highlight a behavior change of Matlab’s copyobj function in HG2.
One of the latest features that was introduced to the GUI Toolbox was the ability to undock or copy panels [2], that would be displayed in a standalone figure window, but remain connected to the underlying class object:
copyobj(___,’legacy’) copies object callback properties and object application data. This behavior is consistent with versions of copyobj before MATLAB® release R2014b.
So, instead of re-running the original code to create the second object to populate the callbacks, we can simply use the new ‘legacy’ option to copy all the callbacks and ApplicationData:
copyobj(hPanel, hNewParent, 'legacy')
Note: for some reason, this new ‘legacy’ option is mentioned in both the doc page and the above-mentioned HG2 code-transition page, but not in the often used help section (help copyobj). There is also no link to the relevant HG2 code-transition page in either the help section or the doc page. I find it unfortunate that for such a backward-incompatible behavior change, MathWorks has not seen fit to document the information more prominently.
Other things to note (this is probably not an exhaustive list…) when you are using copyobj:
hFig= figure;
ax = axes;
uic = uicontextmenu ('parent', hFig);
uim = uimenu('label','My Label', 'parent',uic);
ax.UIContextMenu = uic;
copyChildren = copyobj (ax, hFig, 'legacy');
hFig2 = figure;
copyChildren.Parent = hFig2;
Another note on undocked copies – you will need to manage your callbacks appropriately so that the callbacks manage whether they are being run by the original figure or in a new undocked figure.
Categories: Guest bloggers, GUI, Handle graphics, Low risk of breaking in future versions, Stock Matlab function
Article printed from Undocumented Matlab: https://undocumentedmatlab.com
URL to article: https://undocumentedmatlab.com/articles/copyobj-behavior-change-in-hg2
URLs in this post:
[1] Matlab GUI framework: https://sites.google.com/site/matpihome/matlab-gui-framework
[2] undock or copy panels: https://sites.google.com/site/matpihome/matlab-gui-framework/matlab-undock-uipanel
[3] Matlab’s documentation for HG2 code transition: http://mathworks.com/help/matlab/graphics_transition/why-are-callbacks-not-copied.html
[4] Property value change listeners : https://undocumentedmatlab.com/articles/property-value-change-listeners
[5] Handle Graphics Behavior : https://undocumentedmatlab.com/articles/handle-graphics-behavior
[6] Undocumented scatter plot behavior : https://undocumentedmatlab.com/articles/undocumented-scatter-plot-behavior
[7] xlsread functionality change in R2012a : https://undocumentedmatlab.com/articles/xlsread-functionality-change-in-r2012a
[8] uicontextmenu performance : https://undocumentedmatlab.com/articles/uicontextmenu-performance
[9] Performance: accessing handle properties : https://undocumentedmatlab.com/articles/performance-accessing-handle-properties
Click here to print.
Copyright © Yair Altman - Undocumented Matlab. All rights reserved.